KLUIChatSmallPanel.lua 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. ---@class KLUIChatSmallPanel:UIKmlLuaPanelBase
  2. ---@field view KLUIChatSmallPanelView
  3. local KLUIChatSmallPanel = class(UIKmlLuaPanelBase)
  4. local this = KLUIChatSmallPanel
  5. ---创建时调用一次
  6. function this:Init()
  7. SL:SetCloseChatType({})
  8. if not SL:GetIsWebGL() then
  9. self.calculationUI = GUI:UIPanel_Open("dev/ui/Chat/Item/KLUIChatSmallItem/KLUIChatSmallItem",self.view.templateRoot,self,{})
  10. else
  11. GUI:UIPanel_Open("dev/ui/Chat/Item/KLUIChatSmallItem/KLUIChatSmallItem",self.view.templateRoot,self,{},nil,
  12. function (tempUI)
  13. self.calculationUI = tempUI
  14. end)
  15. end
  16. GUI:setPositionX(self.calculationUI.view.root,2000)
  17. GUI:setPositionY(self.calculationUI.view.root,2000)
  18. GUI:DataListInitData(self.view.chat_small_data_list,function()
  19. return self:ChatDataListItemCountFunc()
  20. end,function(realIndex)
  21. return self:ChatDataListItemGetFunc(realIndex)
  22. end,function(realIndex, kmlcontrol)
  23. return self:ChatDataListItemInitFunc(realIndex, kmlcontrol)
  24. end, function(realIndex, kmlcontrol)
  25. return self:ChatDataListItemUpdateFunc(realIndex, kmlcontrol)
  26. end, function(realIndex, kmlcontrol)
  27. return self:ChatDataItemSizeGetFunc(realIndex, kmlcontrol)
  28. end)
  29. self.chat_all_item = {}
  30. self:UpdateChanInfo()
  31. self.updateID = SL:Schedule(self.updateID,0,Time.deltaTime,-1,function()
  32. self:Update()
  33. end)
  34. end
  35. function this:Update()
  36. if not self.nextDoRevTime then
  37. return
  38. end
  39. if Time.time>self.nextDoRevTime then
  40. self.nextDoRevTime = nil
  41. self:UpdateChanInfo()
  42. end
  43. end
  44. ---创建或者刷新界面数据时调用
  45. function this:Refresh()
  46. end
  47. ---注册UI事件和服务器消息
  48. function this:RegistEvents()
  49. SL:RegisterLUAEvent(LUA_EVENT_CHAT_RECEIVE, self.ChatReceive, self)
  50. GUI:AddOnClickEvent(self.view.viewport_attach, self, self.OpenChatPanel)
  51. SL:RegisterLUAEvent(LUA_EVENT_CHAT_LINK_POS, self.ChatLinlk,self)
  52. SL:RegisterLUAEvent(Event.FriendChatReceiveEvent, self.FriendChatReceiveEvent, self)
  53. end
  54. function this:ClosePanel()
  55. SL:CloseChatUI()
  56. SL.ShowMainPanel()
  57. end
  58. function this:Close()
  59. SL:UnSchedule(self.updateID)
  60. end
  61. function this:UpdateChanInfo()
  62. self.chat_list = {}
  63. self.chat_list = SL:ChatInfo_GetChatInfo(EChatChannelType.ALL)
  64. self:RefreshData(self.chat_list)
  65. end
  66. function this:RefreshData(chat_list)
  67. self.chat_list = chat_list
  68. GUI:DataListUpdateData(self.view.chat_small_data_list)
  69. GUI:SetScrollView_scrollpos(self.view.chat_small_view,#self.chat_list-1)
  70. end
  71. function this:ChatReceive(_id,message)
  72. self.nextDoRevTime = Time.time+Time.deltaTime
  73. end
  74. function this:OpenChatPanel()
  75. SL:OpenChatUI()
  76. end
  77. function this:ChatDataListItemCountFunc()
  78. return #self.chat_list
  79. end
  80. function this:ChatDataListItemGetFunc(realIndex)
  81. local item = GUI:UIPanel_Open("dev/ui/Chat/Item/KLUIChatSmallItem/KLUIChatSmallItem",self.view.chat_small_data_list,self,{},true)
  82. self.chat_all_item[item.view.root] = item
  83. return item.view.root
  84. end
  85. function this:ChatDataListItemInitFunc(realIndex, kmlcontrol)
  86. end
  87. function this:ChatDataListItemUpdateFunc(realIndex, kmlcontrol)
  88. local data = self.chat_list[realIndex + 1]
  89. if not data.itemSizeSmall then
  90. local sss = {message=data,itemIndex=realIndex + 1}
  91. self.calculationUI:RefreshItem(sss)
  92. local xx,yy = GUI:getSizeDelta(self.calculationUI.view.root)
  93. data.itemSizeSmall = Vector2(xx, yy)
  94. end
  95. local mess = {message=data,itemIndex=realIndex + 1}
  96. self.chat_all_item[kmlcontrol]:RefreshItem(mess)
  97. end
  98. function this:ChatDataItemSizeGetFunc(realIndex)
  99. local data = self.chat_list[realIndex + 1]
  100. if not data.itemSizeSmall then
  101. local mess = {message=data,itemIndex=realIndex + 1}
  102. self.calculationUI:RefreshItem(mess)
  103. local xx,yy = GUI:getSizeDelta(self.calculationUI.view.root)
  104. data.itemSizeSmall = Vector2(xx, yy)
  105. end
  106. return data.itemSizeSmall
  107. end
  108. function this:ChatLinlk(id,params)
  109. local linkType = tonumber(params[2])
  110. local message = params[3]
  111. local player_id = nil
  112. if params.Length >= 5 then
  113. player_id = params[4]
  114. end
  115. --位置链接
  116. if linkType == 1 then
  117. local data = string.split(message,"#")
  118. local x = tonumber(data[1])
  119. local y = tonumber(data[2])
  120. local mapId = tonumber(data[3])
  121. local line = tonumber(data[4])
  122. local serverType = SL:GetConfig("cfg_map_info",mapId,"id").serverType
  123. if serverType == 2 then
  124. if not self:CrossServerStall() then
  125. return
  126. end
  127. end
  128. SL:Pathfinding(mapId, line, x, y)
  129. SL:CloseChatUI()
  130. GUI:UIPanel_Close("dev/ui/FriendSys/Panel/KLFriendMain/KLFriendMainPanel")
  131. SL.ShowMainPanel()
  132. --道具装备链接
  133. elseif linkType == 10 then
  134. local data = string.split(message,"#")
  135. local id = tonumber(data[1])
  136. local cfgId = tonumber(data[2])
  137. EquipFunc.otherRid = tostring(player_id)
  138. SL.Friend:ReqOtherRoleInfoMessage(player_id, 4)
  139. SL:OpenTips("chat", cfgId, id,nil,nil,{otherRid = player_id})
  140. elseif linkType == 3 then
  141. local data = string.split(message,"#")
  142. local teamId = tonumber(data[6])
  143. SL:RequestApplyAgree(teamId)
  144. end
  145. end
  146. function this:CrossServerStall()
  147. local mapid = SL:GetConfig("cfg_activity_rule",20001).mapid[1]
  148. local tab = SL:GetConfig("cfg_map_info",mapid)
  149. local message = ""
  150. self.level_lock = false
  151. self.strength_lock = false
  152. self.append_lock = false
  153. self.open_level = 0
  154. if tab.condition and #tab.condition>0 then
  155. local condition = tab.condition
  156. local level = condition[1]
  157. local strength_level = condition[2]
  158. local append_level = condition[3]
  159. local player_level = SL:GetMetaValue("LEVEL")
  160. local all_strength_level = EquipFunc.GetAllStrengthLevel()
  161. local all_append_level = EquipFunc.GetAllAppendLevel()
  162. if player_level < level then
  163. message = message .. "等级" .. level .. "级"
  164. self.level_lock = true
  165. self.open_level = level
  166. end
  167. if all_strength_level < strength_level then
  168. if not string.isNullOrEmpty(message) then
  169. message = message .. ","
  170. end
  171. message = message .. "强化总等级" .. strength_level
  172. self.strength_lock = true
  173. end
  174. if all_append_level < append_level then
  175. if not string.isNullOrEmpty(message) then
  176. message = message .. ","
  177. end
  178. message = message .. "追加总等级" .. append_level
  179. self.append_lock = true
  180. end
  181. if not string.isNullOrEmpty(message) then
  182. message = message .. "可进入"
  183. end
  184. end
  185. if self.level_lock then
  186. SL:TipMessage( self.open_level.."级开启,无法进入", 1, NoticeType.NoticeMid )
  187. return
  188. end
  189. if self.strength_lock then
  190. SL:TipMessage( SL:GetConfig('cfg_string',257).text,1, NoticeType.NoticeMid )--"全身强化等级不足,无法进入",
  191. return
  192. end
  193. if self.append_lock then
  194. SL:TipMessage(SL:GetConfig('cfg_string',257).text, 1, NoticeType.NoticeMid )--"全身追加等级不足,无法进入",
  195. return
  196. end
  197. --[[ if not self:IsHavePrivilege() then
  198. SL:TipMessage( SL:GetConfig('cfg_string',258).text, 1, NoticeType.NoticeLeftBottom )--"<color=#426ECC>月卡时间不足,无法使用地图传送功能</color>",
  199. return
  200. end]]
  201. return true
  202. end
  203. function this:IsHavePrivilege()
  204. if InfoManager.monthCardInfo.IsGetMonthCard or InfoManager.monthCardInfo.IsGetDailyCard then
  205. --有月卡或是日卡
  206. return true
  207. end
  208. return false
  209. end
  210. ---好友聊天信息变化
  211. function this:FriendChatReceiveEvent(_, _senderId)
  212. if SL:GetMetaValue(EMetaVarGetKey.UID) == _senderId then
  213. return
  214. end
  215. InfoManager.friend_senderId = _senderId
  216. SL:onLUAEvent(LUA_EVENT_BUBBLETIPS_ADD,{id=PopoverType.Tip_friends})
  217. end
  218. return this