源战役客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

141 行
4.0 KiB

  1. SocialityView = SocialityView or BaseClass(BaseView)
  2. function SocialityView:__init()
  3. self.base_file = "sociality"
  4. self.layout_file = "SocialityView"
  5. self.layer_name = "UI"
  6. self.destroy_imm = true
  7. self.use_background = true
  8. self.hide_maincancas = true
  9. self.change_scene_close = true
  10. self.open_wnd_anim = 0
  11. self.append_to_ctl_queue = true
  12. self.model = SocialityModel:getInstance()
  13. self.blur_activity_bg = true
  14. self.use_show_anim = true
  15. self.use_hide_anim = true
  16. self.sub_view_list = {}
  17. --预加载的Item
  18. self:AddPreLoadList("chat",{"chatItem"})
  19. --回调方法
  20. self.load_callback = function()
  21. self:LoadSuccess()
  22. self:AddEvent()
  23. self:RefreshRed()
  24. end
  25. self.open_callback = function()
  26. self:SwitchView(self.cur_index)
  27. self.tabWindowComponent:SetTabBarIndex(self.cur_index)
  28. self.model.sociality_is_open = true
  29. end
  30. self.close_callback = function()
  31. GlobalEventSystem:Fire(EventName.MAIN_VOICE_BIND)
  32. self.model.sociality_is_open = false
  33. -- --保存聊天记录
  34. -- CookieWrapper.Instance:WriteChatHistroy()
  35. end
  36. self.destroy_callback = function()
  37. self:Clear()
  38. end
  39. end
  40. function SocialityView:Open( index )
  41. self.cur_index = index or 1
  42. BaseView.Open(self)
  43. end
  44. function SocialityView:AddEvent( )
  45. local onRed = function ( )
  46. self:RefreshRed()
  47. end
  48. self.social_event_id = GlobalEventSystem:Bind(EventName.REFRESH_SOCIAL_RED_DOT, onRed)
  49. end
  50. function SocialityView:RefreshRed( )
  51. for i=1, 3 do
  52. if i==1 then --好友
  53. self.tabWindowComponent:ShowRedPoint(i, MainUIModel:getInstance():IsShowFriendRed())
  54. elseif i==3 then --邮件
  55. self.tabWindowComponent:ShowRedPoint(i, MainUIModel:getInstance():IsShowMailRed())
  56. elseif i==2 then --好友申请
  57. self.tabWindowComponent:ShowRedPoint(i, MainUIModel:getInstance():IsShowApplyRed())
  58. end
  59. end
  60. end
  61. function SocialityView:LoadSuccess()
  62. self.container = self:GetChild("container")
  63. local select_callback = function(index)
  64. self:SwitchView(index)
  65. end
  66. local close_callback = function()
  67. self:Close()
  68. end
  69. local menu_name_list = self.model:GetTabData()
  70. self.tabWindowComponent = UITabWindow.New(self.transform, menu_name_list, select_callback, close_callback, self.background_wnd,
  71. self.container,UITabWindow.SizeSmallHall,nil,nil,true)
  72. self.tabWindowComponent:SetBackgroundRes("default_bg_6")
  73. end
  74. function SocialityView:SwitchView( index )
  75. if index == 1 or index == 2 then
  76. if not GetModuleIsOpen(140) then
  77. Message.show(string.format("%d级开放", GetModuleOpenLevel(140)))
  78. self.tabWindowComponent:SetTabBarIndex(2)
  79. return
  80. end
  81. end
  82. self.tabWindowComponent:SetTabBarIndex(index)
  83. self.cur_index = index
  84. local sub_view = self.model:GetSocialSubView(index)
  85. if sub_view and not self.sub_view_list[index] then
  86. self.sub_view_list[index] = sub_view.New(self.container)
  87. --更新列表
  88. if index == 3 then
  89. self.sub_view_list[index]:ShowPanel()
  90. end
  91. end
  92. if self.last_index and self.sub_view_list[self.last_index] then
  93. self.sub_view_list[self.last_index]:SetVisible(false)
  94. end
  95. if self.sub_view_list[index] then
  96. self.sub_view_list[index]:SetVisible(true)
  97. end
  98. self.last_index = index
  99. local title_res
  100. if index == 1 then
  101. title_res ="好友"
  102. elseif index == 2 then
  103. title_res ="添加"
  104. elseif index == 3 then
  105. title_res ="邮件"
  106. end
  107. self.tabWindowComponent:SetTitleText(title_res)
  108. end
  109. function SocialityView:Clear( )
  110. for k,v in pairs(self.sub_view_list) do
  111. v:DeleteMe()
  112. end
  113. self.sub_view_list = {}
  114. if self.social_event_id then
  115. GlobalEventSystem:UnBind(self.social_event_id)
  116. self.social_event_id = nil
  117. end
  118. if self.tabWindowComponent then
  119. self.tabWindowComponent:DeleteMe()
  120. self.tabWindowComponent = nil
  121. end
  122. end