KLDailyActivityItem.lua 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. ---@class KLDailyActivityItem:UIKmlLuaPanelBase
  2. ---@field view KLDailyActivityItemView
  3. local KLDailyActivityItem = class(UIKmlLuaPanelBase)
  4. local this =KLDailyActivityItem
  5. ---创建时调用一次
  6. function this:Init()
  7. --一个显示地图名字
  8. self.itemPool = TablePool()
  9. ----@type UIKmlLuaControl[]
  10. self.itemList = {}
  11. --一个显示怪物数量
  12. self.itemPool_2 = TablePool()
  13. ----@type UIKmlLuaControl[]
  14. self.itemList_2 = {}
  15. end
  16. ---创建或者刷新界面数据时调用
  17. function this:Refresh()
  18. --GUI:SetActive(self.view.btn_go,self.args)
  19. end
  20. ---注册UI事件和服务器消息
  21. function this:RegistEvents()
  22. GUI:AddOnClickEvent(self.view.btn_go,self,self.BtnGoOnClick)
  23. SL:RegisterLuaNetMsg(LuaMessageIdToClient.MONSTER_ATTACK_BOSS_INFO,self.MONSTER_ATTACK_BOSS_INFO,self)
  24. end
  25. ----怪物来袭
  26. function this:MONSTER_ATTACK_BOSS_INFO(_,message)
  27. local mapList = {}
  28. for k,v in pairs(message) do
  29. if not mapList[v.mapCfgId] then
  30. mapList[v.mapCfgId] = { }
  31. end
  32. table.insert(mapList[v.mapCfgId],v)
  33. end
  34. table.sort(mapList,function(a,b)
  35. if a < b then
  36. return true
  37. end
  38. return false
  39. end)
  40. self:RefreshMonsterInfo(mapList)
  41. end
  42. function this:BtnGoOnClick()
  43. local tbl = SL:GetConfig("cfg_activity_rule", self.data.id)
  44. ---狼魂要塞
  45. if self.data.id == EActivityType.WolfSoulFortress then
  46. ---@type cfg_rep_column
  47. local tempTbl = InfoManager.wolfSoulFortressInfo:GetCfgByOpenServerDay()
  48. local wolfSoulFortressInfo = InfoManager.activityPreviewInfo:GetActivityInfo(EActivityType.WolfSoulFortress)
  49. if not wolfSoulFortressInfo.open then
  50. SL:TipMessage(SL:GetConfig('cfg_string',250).text, 1, NoticeType.NoticeMid)--"活动未开启",
  51. return
  52. end
  53. ---没有公会
  54. if SL:MeData_GetUnionId() == 0 then
  55. SL:TipMessage(SL:GetConfig('cfg_string', 433).text, 1, NoticeType.NoticeMid )
  56. return
  57. end
  58. if tempTbl then
  59. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_ENTER_DUPLICATE, tempTbl.id)
  60. end
  61. elseif tbl.mapid and table.count(tbl.mapid) >0 and tbl.mapid[1] == 21000 then
  62. --进入跨服神之国度
  63. local cond, message = InfoManager.godsDescendInfo.CheckActivityConditionMapId(self.data.id)
  64. if cond then
  65. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_GOTO_CROSS_MAP,{})
  66. else
  67. SL:TipMessage(message, 1, NoticeType.NoticeMid)
  68. end
  69. elseif self.data.id == EActivityType.LoranSiege then--罗兰攻城战
  70. ---@type cfg_system_switch_column
  71. local systemCfg = SL:GetConfig("cfg_system_switch", 207)
  72. local isMeet = SL:GetMetaValue(EMetaVarGetKey.IS_OPEN_SYSTEMFUNCTION, systemCfg.systemName)
  73. if not isMeet then
  74. SL:TipMessage(SL:GetConfig('cfg_string',250).text, 1, NoticeType.NoticeMid)--"活动未开启",
  75. return
  76. end
  77. else
  78. GUI:UIPanel_Close("dev/outui/DailyGoal/Panel/KLDailyGoalMain/KLDailyGoalMainPanel")
  79. shortcutOutMgr.DO(self.data.panel)
  80. end
  81. end
  82. function this:Close()
  83. self:Recycle()
  84. if self.timer then
  85. --Timer.Stop(self.timer)
  86. SL:UnSchedule(self.timer)
  87. self.timer = nil
  88. end
  89. end
  90. ---更新数据
  91. ---@param data cfg_activity_rule_column 数据
  92. function this:UpdateData(data)
  93. self.data = data
  94. GUI:SetID(self.view.root,"daily_activity_item_" .. self.data.id)
  95. GUI:Text_setString(self.view.txt_title,data.name)
  96. GUI:Image_loadTexture(self.view.img_bg,data.uiBg,"Atlas/DailyGoal.spriteatlas")
  97. GUI:Text_setString(self.view.txt_rule_content,data.uiTextRule)
  98. GUI:Text_setString(self.view.txt_condition,self:format_time(data.uiTextSynopsis))
  99. --self.view.list_reward.kmlControl:HideAllChilds()
  100. GUI:RemoveAllChildren(self.view.list_reward)
  101. for _,v in ipairs(data.uiReward) do
  102. local item = GUI:Item_Create(self.view.list_reward,{
  103. width = "60",
  104. height = "60",
  105. itemid = v,
  106. tips = "1",
  107. mfixsize = "60,60",
  108. })
  109. local btn = GUI:Button_Create(item,{
  110. width = "60",
  111. height = "60",
  112. color="#00000000",
  113. raycast="1",
  114. id ="ben222"
  115. })
  116. GUI:AddOnClickEvent(btn,self,self.ItemOnClick,v)
  117. end
  118. local myLevel = SL:GetMetaValue(EMetaVarGetKey.LEVEL)
  119. GUI:SetActive(self.view.btn_go,self.args and myLevel >= data.level)
  120. if data.id == EActivityType.FieryDragon then
  121. local myLevel = SL:GetMetaValue(EMetaVarGetKey.LEVEL)
  122. GUI:SetActive(self.view.monsterInfoRoot,self.args and myLevel >= data.level)
  123. SL:SendLuaNetMsg(LuaMessageIdToSever.MONSTER_ATTACK_BOSS_INFO,10008)
  124. if not self.timer then
  125. --[[ self.timer = Timer.StartLoopForever(10,function()
  126. SL:SendLuaNetMsg(LuaMessageIdToSever.MONSTER_ATTACK_BOSS_INFO,10008)
  127. end, self)]]
  128. self.timer = SL:Schedule(self.timer,0,10,-1,function()
  129. SL:SendLuaNetMsg(LuaMessageIdToSever.MONSTER_ATTACK_BOSS_INFO,10008)
  130. end, self)
  131. end
  132. else
  133. GUI:SetActive(self.view.monsterInfoRoot,false)
  134. end
  135. end
  136. function this:RefreshMonsterInfo(message)
  137. self:Recycle()
  138. for k,v in pairs(message) do
  139. ---@type UIKmlLuaControl
  140. local item = self.itemPool:Pop()
  141. local item_2 = self.itemPool_2:Pop()
  142. ----@type cfg_map_info_column
  143. local mapCfg = SL:GetConfig("cfg_map_info",k)
  144. if not next(item) and not next(item_2) then
  145. item = GUI:Button_Create(self.view.monsterMapRoot,{
  146. id = "btn1",
  147. text = mapCfg.mapname,
  148. fontsize = "18",
  149. raycast = "1",
  150. color="#00000000",
  151. width="125",
  152. height = "18",
  153. textcolor =EColor[EGradColor.green]
  154. })
  155. GUI:AddOnClickEvent(item,self,function()
  156. SL:MapTransfer(tonumber(mapCfg.id),1)
  157. end)
  158. item_2 = GUI:Text_Create(self.view.monsterCountRoot,{
  159. text = string.format("剩余%s只",table.count(v)),
  160. ta = "01",
  161. fontsize = "18",
  162. src = ""
  163. })
  164. end
  165. --GUI:Text_setTextColor(item,EColor[EGradColor.green])
  166. GUI:Text_setTextColor(item_2,EColor[EGradColor.green])
  167. GUI:SetActive(item,true)
  168. GUI:SetActive(item_2,true)
  169. self.itemList[k] = item
  170. self.itemList_2[k] = item_2
  171. end
  172. end
  173. function this:Recycle()
  174. for _, v in pairs(self.itemList) do
  175. GUI:SetActive(v,false)
  176. self.itemPool:Push(v)
  177. end
  178. self.itemList = {}
  179. for _, v in pairs(self.itemList_2) do
  180. GUI:SetActive(v,false)
  181. self.itemPool_2:Push(v)
  182. end
  183. self.itemList_2 = {}
  184. end
  185. function this:ItemOnClick(_,b)
  186. SL:OpenTips(nil,b)
  187. end
  188. function this:format_time(input)
  189. -- 验证是否为有效时间范围格式,并选择性替换
  190. local pattern = "^%d%d:%d%d:%d%d%-%d%d:%d%d:%d%d$"
  191. -- 仅当完全匹配时间格式时才进行替换
  192. if input:match(pattern) then
  193. return input:gsub("(%d%d:%d%d):%d%d", "%1", 2) -- 替换两次确保安全
  194. else
  195. return input
  196. end
  197. end
  198. return this