KLActivityTipPanel.lua 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. ---@class KLActivityTipPanel:UIKmlLuaPanelBase
  2. ---@field view KLActivityTipPanelView
  3. local KLActivityTipPanel = class(UIKmlLuaPanelBase)
  4. local this =KLActivityTipPanel
  5. ---创建时调用一次
  6. function this:Init()
  7. self.id2ActInfos = {}
  8. self.activityInfos = {} ---所有已开启的活动提示
  9. GUI:DataListInitData( self.view.ActivitiesDataList,function()
  10. return self:DataListItemCountFunc()
  11. end,function(realIndex)
  12. return self:DataListItemGetFunc(realIndex)
  13. end,nil, function(realIndex, kmlcontrol)
  14. return self:DataListItemUpdateFunc(realIndex, kmlcontrol)
  15. end, function(realIndex)
  16. return self:DataListItemSizeGetFunc(realIndex)
  17. end)
  18. end
  19. function this:DataListItemCountFunc()
  20. return #self.activityInfos
  21. end
  22. function this:DataListItemGetFunc()
  23. ---@type KLUISkillPageItem
  24. local item = GUI:UIPanel_Open("dev/ui/Preview/Item/KLActivityTip/KLActivityTipItem", self.view.ActivitiesDataList, self, nil, true)
  25. if not self.activityItems then
  26. self.activityItems = {}
  27. end
  28. local kmlCtrl = item.view.root
  29. self.activityItems[kmlCtrl] = item
  30. return kmlCtrl
  31. end
  32. function this:DataListItemUpdateFunc(realIndex, kmlcontrol)
  33. local item = self.activityItems[kmlcontrol]
  34. local luaIndex = realIndex + 1
  35. local info = self.activityInfos[luaIndex]
  36. item:UpdateUI(info)
  37. end
  38. ---@return Vector2
  39. function this:DataListItemSizeGetFunc()
  40. local x = 262
  41. local y = 75
  42. return Vector2(x, y)
  43. end
  44. ---创建或者刷新界面数据时调用
  45. function this:Refresh()
  46. end
  47. --刷新面板icon
  48. function this:RefreshUI()
  49. GUI:DataListUpdateData(self.view.ActivitiesDataList)
  50. end
  51. ---注册UI事件和服务器消息
  52. function this:RegistEvents()
  53. GUI:AddOnClickEvent(self.view.closeBtn,self,self.CloseBtnClick)
  54. GUI:AddOnClickEvent(self.view.ViewAllActivities,self,self.ShowAllActivePanel)
  55. GUI:AddOnClickEvent(self.view.ExpandArrow,self,self.ExpandArrowClick)
  56. GUI:AddOnClickEvent(self.view.ContractArrow,self,self.ContractArrowClick)
  57. ---服务器事件,活动数据改变
  58. SL:RegisterLUAEvent(Event.ActivityListChange,self.ActivityListChange,self)
  59. SL:RegisterLUAEvent(Event.AnnounceListChange,self.AnnounceListChange,self)
  60. ---外部开启关闭活动提示
  61. SL:RegisterLUAEvent(LUA_EVENT_ACTIVITYTIMETIPS_ADD,self.OutOpenActivityTimeTip,self)
  62. SL:RegisterLUAEvent(LUA_EVENT_ACTIVITYTIMETIPS_DEL,self.CloseActivityTimeTip,self)
  63. SL:RegisterLUAEvent(LUA_EVENT_ACTIVITYTIMETIPS_DELTYPE,self.CloseActivityTimeTipByType,self)
  64. SL:RegisterLUAEvent(LUA_EVENT_ACTIVITYTIMETIPS_DELALL,self.CloseActivityTimeTipAll,self)
  65. end
  66. function this:ActivityListChange()
  67. self:RefreshByMessage()
  68. if not self:TryRefreshActivityList() then
  69. --self:CloseBtnClick()
  70. return
  71. end
  72. end
  73. function this:AnnounceListChange()
  74. self:RefreshByAnnounceMessage()
  75. if not self:TryRefreshActivityList() then
  76. --self:CloseBtnClick()
  77. return
  78. end
  79. end
  80. -- 根据服务器消息刷新预告
  81. function this:RefreshByAnnounceMessage()
  82. local allAct = SL:GetAllActivityAnnounceData()
  83. if not RoleManager.meData or not allAct then
  84. return
  85. end
  86. local level = SL:GetMetaValue(EMetaVarGetKey.LEVEL)
  87. if not level then return end
  88. self.hasAnnounceShow = false
  89. self:DeleteByType(EListDataType.AnnounceList)
  90. --有需要显示的预告活动
  91. for _, v in pairs(allAct) do
  92. local t = {}
  93. t.activityId = v.activityId
  94. --local brief = SL:GetConfig("cfg_activity_rule",v.activityId)
  95. if brief and brief.open ~= EActivityRuleIsShowPop.NotShowInPop and brief.uiTextLevel <= level then
  96. t.activityIcon = brief.uiIcon
  97. t.activityName = "活动"..v.activityId --brief.titleIcon
  98. t.activityType = EListDataType.AnnounceList --预告
  99. t.activityEndTime = v.time
  100. local activityTime = t.activityEndTime - Time.GetServerTime();
  101. if brief.specialOpen and brief.specialOpen > 0 then
  102. t.specialOpen = brief.specialOpen --预告秒
  103. local specialOpenTime = brief.specialOpen * 1000
  104. if activityTime > 0 and activityTime <= specialOpenTime then
  105. if not self.id2ActInfos[t.activityId] then
  106. table.insert(self.activityInfos, t)
  107. self.id2ActInfos[t.activityId] = t
  108. end
  109. self.hasAnnounceShow = true
  110. end
  111. end
  112. end
  113. end
  114. end
  115. -- 根据服务器消息刷新活动
  116. function this:RefreshByMessage()
  117. local level = SL:GetMetaValue(EMetaVarGetKey.LEVEL)
  118. if not level or not SL:GetAllActivityData() then
  119. return
  120. end
  121. self.hasActivityToShow = false
  122. self:DeleteByType(EListDataType.ActivityList)
  123. end
  124. function this:TryRefreshActivityList()
  125. if #self.activityInfos == 0 then
  126. return false
  127. end
  128. table.sort(self.activityInfos, function(a, b)
  129. if a.activityType == b.activityType then
  130. return a.activityEndTime > b.activityEndTime
  131. else
  132. return a.activityType > b.activityType
  133. end
  134. end)
  135. return true
  136. end
  137. ---展开活动预告
  138. function this:ExpandArrowClick()
  139. GUI:setContentSize(self.view.background,257,330)
  140. GUI:setVisible(self.view.ViewAllActivities)
  141. GUI:setVisible(self.view.ExpandArrow,false)
  142. GUI:setVisible(self.view.ContractArrow,true)
  143. GUI:setContentSize(self.view.ActivitiesView,242,220)
  144. GUI:DataListUpdateData(self.view.ActivitiesDataList)
  145. end
  146. ---收缩活动预告
  147. function this:ContractArrowClick()
  148. GUI:setContentSize(self.view.background,257,130)
  149. GUI:setVisible(self.view.ViewAllActivities,false)
  150. GUI:setVisible(self.view.ExpandArrow)
  151. GUI:setVisible(self.view.ContractArrow,false)
  152. GUI:setContentSize(self.view.ActivitiesView,242,78)
  153. GUI:DataListUpdateData(self.view.ActivitiesDataList)
  154. end
  155. ---查看全天活动
  156. function this:ShowAllActivePanel()
  157. SL:Log('查看全天活动')
  158. ---GUI:UIPanel_Open("dev/ui/Preview/Panel/KLActivityTip/KLActivityTipPanel")
  159. end
  160. ---关闭活动预告
  161. function this:CloseBtnClick()
  162. GUI:UIPanel_Close("dev/ui/Preview/Panel/KLActivityTip/KLActivityTipPanel")
  163. end
  164. -------------------------外部添加删除提示--------------------------------------
  165. function this:OutOpenActivityTimeTip(_,data)
  166. if not RoleManager.meData then
  167. return
  168. end
  169. --local brief = SL:GetConfig("cfg_activity_rule",data.activityId)
  170. --开启条件不满足
  171. if not brief then return end
  172. if brief.open == EActivityRuleIsShowPop.NotShowInPop or brief.uiTextLevel > RoleManager.meData.Level then
  173. return
  174. end
  175. --进行活动需加战盟后才显示战盟boss,攻城战
  176. if (data.activityId == 32 or data.activityId == 33) and RoleManager.meData.roleExtInfo.unionId == 0 and data.activityType == EListDataType.ActivityList then
  177. return
  178. end
  179. --重复开启活动
  180. if self.id2ActInfos[data.activityId] then
  181. return
  182. end
  183. --倒计时是否满足
  184. local checktime = data.activityEndTime > 0 --self:CheckEndtime(data.activityType,data.activityEndTime,brief,data)
  185. if checktime then
  186. if not self.id2ActInfos[data.activityId] then
  187. table.insert(self.activityInfos, data)
  188. self.id2ActInfos[data.activityId] = data
  189. self:RefreshUI()
  190. end
  191. end
  192. end
  193. function this:CloseActivityTimeTipByType(_,type)
  194. self:DeleteByType(type)
  195. self:RefreshUI()
  196. end
  197. function this:CloseActivityTimeTip(_,id)
  198. self:DeleteByActiveId(id)
  199. self:RefreshUI()
  200. end
  201. function this:CloseActivityTimeTipAll()
  202. self:DeleteAllActive()
  203. self:RefreshUI()
  204. self:CloseBtnClick()
  205. end
  206. ---根据预告还是活动类型删除
  207. function this:DeleteByType(tp)
  208. for i = #self.activityInfos, 1, -1 do
  209. local v = self.activityInfos[i]
  210. if v.activityType == tp then
  211. if self.id2ActInfos[v.activityId] then
  212. self.id2ActInfos[v.activityId] = nil
  213. end
  214. table.remove(self.activityInfos, i)
  215. end
  216. end
  217. end
  218. ---根据活动id删除
  219. function this:DeleteByActiveId(id)
  220. for i = #self.activityInfos, 1, -1 do
  221. local v = self.activityInfos[i]
  222. if v.activityId == id then
  223. if self.id2ActInfos[v.activityId] then
  224. self.id2ActInfos[v.activityId] = nil
  225. end
  226. table.remove(self.activityInfos, i)
  227. end
  228. end
  229. end
  230. ---删除所有活动
  231. function this:DeleteAllActive()
  232. for i = #self.activityInfos, 1, -1 do
  233. local v = self.activityInfos[i]
  234. if self.id2ActInfos[v.activityId] then
  235. self.id2ActInfos[v.activityId] = nil
  236. end
  237. table.remove(self.activityInfos, i)
  238. end
  239. end
  240. function this:SetUIMapPoint(IsHave)
  241. if IsHave then
  242. self:SetPositionX(243)
  243. else
  244. self:SetPositionX(410)
  245. end
  246. end
  247. function this:SetPositionX(x)
  248. GUI:setPositionX(self.view.root,x)
  249. end
  250. function this:Close()
  251. end
  252. return this