KLFriendUIItem.lua 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. ---@class KLFriendUIItem:UIKmlLuaPanelBase
  2. ---@field view KLFriendUIItemView
  3. ---@field infoItems KLFriendInfoItem[]
  4. ---@field data FriendProto.FriendInfo[] @好友列表or黑名单列表
  5. ---@field friendMax number @好友上限数量
  6. ---@field blackMax number @黑名单上限数量
  7. ---@field chatPanel KLFriendChatItem
  8. local KLFriendUIItem = class(UIKmlLuaPanelBase)
  9. local this =KLFriendUIItem
  10. ---创建时调用一次
  11. function this:Init()
  12. self.infoItems = {}
  13. ---@type cfg_global_column
  14. local tbl = SL:GetConfig("cfg_global", 45)
  15. local split = string.split(tbl.value, "#")
  16. self.friendMax = tonumber(split[1])
  17. self.blackMax = tonumber(split[2])
  18. self.enemyLogList = {}
  19. GUI:DataListInitData(self.view.enemy_log_data_list,function()
  20. return self:EnemyLogDataListItemCountFunc()
  21. end,function(realIndex)
  22. return self:EnemyLogDataListItemGetFunc(realIndex)
  23. end,function(realIndex, kmlcontrol)
  24. return self:EnemyLogDataListItemInitFunc(realIndex, kmlcontrol)
  25. end, function(realIndex, kmlcontrol)
  26. return self:EnemyLogDataListItemUpdateFunc(realIndex, kmlcontrol)
  27. end)
  28. self.logItem = {}
  29. end
  30. function this:EnemyLogDataListItemCountFunc()
  31. return #self.enemyLogList
  32. end
  33. function this:EnemyLogDataListItemGetFunc(realIndex)
  34. local item = GUI:UIPanel_Open("dev/outui/FriendSys/Item/KLFriendEnemyLogText/KLFriendEnemyLogTextItem",
  35. self.view.enemy_log_data_list, self, {}, true)
  36. self.logItem[item.view.root] = item
  37. return item.view.root
  38. end
  39. function this:EnemyLogDataListItemInitFunc(realIndex, kmlcontrol)
  40. end
  41. function this:EnemyLogDataListItemUpdateFunc(realIndex, kmlcontrol)
  42. local data = self.enemyLogList[realIndex + 1]
  43. self.logItem[kmlcontrol]:SetLog(data)
  44. end
  45. ---创建或者刷新界面数据时调用
  46. function this:Refresh()
  47. end
  48. function this:SetType(type)
  49. if self.type and self.type == type then
  50. return false
  51. end
  52. self.type = type
  53. GUI:setVisible(self.view.BtnAdd, false)
  54. self:Recycle()
  55. return true
  56. end
  57. ---@param data FriendProto.FriendInfo[]
  58. function this:UpdateData(data)
  59. self.data = data
  60. local filePath = "dev/ui/FriendSys/Item/KLFriendInfo/KLFriendInfoItem"
  61. self:Recycle()
  62. local count = 0
  63. local firstFlag = true
  64. local is_select = false
  65. if InfoManager.friend_senderId then
  66. for _, v in pairs(self.data) do
  67. if v.rid == InfoManager.friend_senderId then
  68. is_select = true
  69. end
  70. end
  71. end
  72. for _, v in pairs(self.data) do
  73. ---@type KLFriendInfoItem
  74. GUI:UIPanel_Open(filePath, self.view.friend_layout, self, {info = v, toggleGroup = self.view.friend_layout, type=self.type}, true, function(item)
  75. GUI:SetToggleOnValueChange(item.view.KmlFriendListItem, self, self.OnClickPlayer, v)
  76. --默认选中
  77. if not is_select then
  78. if firstFlag then
  79. item:SetChoose()
  80. firstFlag = false
  81. end
  82. else
  83. if firstFlag and v.rid == InfoManager.friend_senderId then
  84. item:SetChoose()
  85. firstFlag = false
  86. end
  87. end
  88. end)
  89. count = count + 1
  90. end
  91. InfoManager.friend_senderId = nil
  92. GUI:setVisible(self.view.BtnAdd, self.type == EFriendRelation.Friend and count == 0)
  93. if count == 0 then
  94. GUI:setVisible(self.view.friend_line, false)
  95. GUI:Text_setString(self.view.friend_count, "")
  96. else
  97. GUI:setVisible(self.view.friend_line, true)
  98. GUI:Text_setString(self.view.friend_count, string.format("人数:%d/%d", count, self.type == EFriendRelation.Friend and self.friendMax or self.blackMax))
  99. end
  100. end
  101. ---@param eventData FriendProto.FriendInfo
  102. function this:OnClickPlayer(control, eventData, callBackData)
  103. if callBackData[1] then
  104. self.nowSelect = eventData
  105. GUI:setVisible(self.view.ChatContent, self.type == EFriendRelation.Friend)
  106. GUI:setVisible(self.view.BlackListContent, self.type == EFriendRelation.BlackList)
  107. GUI:setVisible(self.view.EnemyContent, self.type == EFriendRelation.Enemy)
  108. if self.type == EFriendRelation.Friend then
  109. if not self.chatPanel then
  110. GUI:UIPanel_Open("dev/ui/FriendSys/Item/KLFriendChat/KLFriendChatItem", self.view.ChatContent, self,nil,false, function(chatPanel)
  111. self.chatPanel = chatPanel
  112. chatPanel:SetFriend(eventData.rid)
  113. end)
  114. end
  115. --self.chatPanel:SetFriend(eventData.rid)
  116. else
  117. if self.chatPanel then
  118. GUI:UIPanel_Close(nil, self.chatPanel)
  119. self.chatPanel = nil
  120. end
  121. SL.Friend:ReqFriendLogsMessage(self.type, self.nowSelect.rid)
  122. end
  123. end
  124. end
  125. ---注册UI事件和服务器消息
  126. function this:RegistEvents()
  127. SL:RegisterLUAEvent(LUA_EVENT_FRIEND_LIST_CHANGE, self.FriendChange, self)
  128. GUI:AddOnClickEvent(self.view.BtnCancelForbid, self, self.RemoveForbid)
  129. SL:RegisterLuaNetMsg(MessageDef.ResFriendLogsMessage, self.ResFriendLogsMessage, self)
  130. GUI:AddOnClickEvent(self.view.BtnAdd, self, self.GoAddFriendPage)
  131. SL:RegisterLUAEvent(FRIEND_LIKE_ZERO_EVENT, self.FRIEND_LIKE_ZERO_EVENT, self)
  132. end
  133. function this:FRIEND_LIKE_ZERO_EVENT(id, type)
  134. if self.type == type then
  135. SL.Friend:ReqOpenFriendPanelMessage(type)
  136. end
  137. end
  138. function this:GoAddFriendPage()
  139. GUI:UIPanel_Open("dev/ui/FriendSys/Panel/KLFriendAdd/KLFriendAddPanel")
  140. end
  141. ---@param message FriendProto.FriendLogsRes
  142. function this:ResFriendLogsMessage(id, message)
  143. if message.type == EFriendRelation.BlackList then
  144. local res = ""
  145. for _, v in pairs(message.FriendLog) do
  146. local str = Time.FormatTimeYMDHMS(v.time//1000)
  147. res = res..string.format("在%s拉黑了他", str)
  148. end
  149. GUI:Text_setString(self.view.TextBlackInfo, res)
  150. elseif message.type == EFriendRelation.Enemy then
  151. self.enemyLogList = message.FriendLog
  152. GUI:DataListUpdateData(self.view.enemy_log_data_list)
  153. end
  154. end
  155. function this:RemoveForbid()
  156. if self.nowSelect then
  157. SL:DelBlackList(self.nowSelect.rid)
  158. end
  159. end
  160. --更新好友列表
  161. function this:FriendChange(_, type)
  162. if type == self.type then
  163. local friends = SL:GetFriendData(type)
  164. self:UpdateData(friends)
  165. end
  166. end
  167. function this:Recycle()
  168. GUI:UIPanel_Close("dev/ui/FriendSys/Item/KLFriendInfo/KLFriendInfoItem")
  169. GUI:setVisible(self.view.EnemyContent, false)
  170. GUI:setVisible(self.view.ChatContent, false)
  171. GUI:setVisible(self.view.BlackListContent, false)
  172. end
  173. function this:Close()
  174. end
  175. return this