KLArcWeapActivityPanel.lua 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. ---@class KLArcWeapActivityPanel:UIKmlLuaPanelBase
  2. ---@field view KLArcWeapActivityPanelView
  3. local KLArcWeapActivityPanel = class(UIKmlLuaPanelBase)
  4. local this =KLArcWeapActivityPanel
  5. function this:AsyncLoadUI()
  6. end
  7. ---创建时调用一次
  8. function this:Init()
  9. self.showSmallList = {}
  10. GUI:DataListInitData(self.view.showInfoList, function()
  11. return self:GetAllShowGoods()
  12. end,function()
  13. end,function()
  14. end, function(realIndex)
  15. self:ItemUpdateFun(realIndex)
  16. end)
  17. end
  18. function this:GetAllShowGoods()
  19. return table.count(self.showSmallList)
  20. end
  21. function this:ItemUpdateFun(realIndex)
  22. local data = self.showSmallList[realIndex + 1]
  23. local item1 = GUI:GetChildControl(self.view.showInfoList, realIndex, 'item1')
  24. local txt_count1 = GUI:GetChildControl(self.view.showInfoList, realIndex, 'txt_count1')
  25. local img_jia1 = GUI:GetChildControl(self.view.showInfoList, realIndex, 'img_jia1')
  26. local item2 = GUI:GetChildControl(self.view.showInfoList, realIndex, 'item2')
  27. local txt_count2 = GUI:GetChildControl(self.view.showInfoList, realIndex, 'txt_count2')
  28. local img_jia2 = GUI:GetChildControl(self.view.showInfoList, realIndex, 'img_jia2')
  29. local item3 = GUI:GetChildControl(self.view.showInfoList, realIndex, 'item3')
  30. local txt_count3 = GUI:GetChildControl(self.view.showInfoList, realIndex, 'txt_count3')
  31. local item4 = GUI:GetChildControl(self.view.showInfoList, realIndex, 'item4')
  32. local txt_count4 = GUI:GetChildControl(self.view.showInfoList, realIndex, 'txt_count4')
  33. local btn_GoOrGet = GUI:GetChildControl(self.view.showInfoList, realIndex, 'btn_GoOrGet')
  34. local txt_alreadyGet = GUI:GetChildControl(self.view.showInfoList, realIndex, 'txt_alreadyGet')
  35. --获取所有消耗道具
  36. local reward = data.weapCdgData.angelWeaponTask
  37. local tmpReward = data.itemList
  38. local showReward = {}
  39. for _, v1 in pairs(reward) do
  40. local cfg = {}
  41. cfg.itemId = v1[1]
  42. cfg.needCount = v1[2]
  43. cfg.ownerCount = 0
  44. for k, v2 in pairs(tmpReward) do
  45. if v1[1] == tonumber(k) then
  46. cfg.ownerCount = v2
  47. end
  48. end
  49. table.insert(showReward,cfg)
  50. end
  51. item1.kmlControl:HideAllChilds()
  52. local itemData1 = showReward[1]
  53. local data1 = {width = "70",height = "70",itemid = itemData1.itemId,mfixsize = "70,70",itemcount = nil,bgtype = "0",raycast="1",}
  54. self.item1 = GUI:Item_Create(item1, data1)
  55. GUI:AddOnClickEvent(self.item1, self, function()
  56. SL:OpenTips(nil, itemData1.itemId)
  57. end)
  58. item4.kmlControl:HideAllChilds()
  59. local itemData4 = data.weapCdgData.angelWeaponReward[1] --奖励展示
  60. local data4 = {width = "70",height = "70",itemid = itemData4[1],mfixsize = "70,70",itemcount = nil,bgtype = "0",raycast="1",}
  61. self.item4 = GUI:Item_Create(item4, data4)
  62. GUI:AddOnClickEvent(self.item4, self, function()
  63. SL:OpenTips(nil, itemData4[1])
  64. end)
  65. local color1 = itemData1.ownerCount >= itemData1.needCount and EColor[EGradColor.green] or EColor[EGradColor.red]
  66. local str1 = string.format("<color=%s>%s</color>/%s", color1, itemData1.ownerCount, itemData1.needCount)
  67. GUI:Text_setString(txt_count1, str1)
  68. GUI:Text_setString(txt_count4, tostring(itemData4[2]))
  69. GUI:SetActive(img_jia1,false)
  70. GUI:SetActive(item2,false)
  71. GUI:SetActive(txt_count2,false)
  72. if table.count(showReward) >= 2 then
  73. GUI:SetActive(img_jia1,true)
  74. GUI:SetActive(item2,true)
  75. GUI:SetActive(txt_count2,true)
  76. item2.kmlControl:HideAllChilds()
  77. local itemData2 = showReward[2]
  78. local data2 = {width = "70",height = "70",itemid = itemData2.itemId,mfixsize = "70,70",itemcount = nil,bgtype = "0",raycast="1",}
  79. self.item2 = GUI:Item_Create(item2, data2)
  80. GUI:AddOnClickEvent(self.item2, self, function()
  81. SL:OpenTips(nil, itemData2.itemId)
  82. end)
  83. local color2 = itemData2.ownerCount >= itemData2.needCount and EColor[EGradColor.green] or EColor[EGradColor.red]
  84. local str2 = string.format("<color=%s>%s</color>/%s", color2, itemData2.ownerCount, itemData2.needCount)
  85. GUI:Text_setString(txt_count2, str2)
  86. end
  87. GUI:SetActive(img_jia2,false)
  88. GUI:SetActive(item3,false)
  89. GUI:SetActive(txt_count3,false)
  90. if table.count(showReward) >= 3 then
  91. GUI:SetActive(img_jia2,true)
  92. GUI:SetActive(item3,true)
  93. GUI:SetActive(txt_count3,true)
  94. item3.kmlControl:HideAllChilds()
  95. local itemData3 = showReward[3]
  96. local data3 = {width = "70",height = "70",itemid = itemData3.itemId,mfixsize = "70,70",itemcount = nil,bgtype = "0",raycast="1",}
  97. self.item3 = GUI:Item_Create(item3, data3)
  98. GUI:AddOnClickEvent(self.item3, self, function()
  99. SL:OpenTips(nil, itemData3.itemId)
  100. end)
  101. local color3 = itemData3.ownerCount >= itemData3.needCount and EColor[EGradColor.green] or EColor[EGradColor.red]
  102. local str3 = string.format("<color=%s>%s</color>/%s", color3, itemData3.ownerCount, itemData3.needCount)
  103. GUI:Text_setString(txt_count3, str3)
  104. end
  105. GUI:SetActive(btn_GoOrGet,false)
  106. GUI:SetActive(txt_alreadyGet,false)
  107. if data.giftState == E_RechargeState.CanGet then
  108. GUI:Button_setBright(btn_GoOrGet,true)
  109. GUI:SetActive(btn_GoOrGet,true)
  110. GUI:Button_setGrey(btn_GoOrGet,false)
  111. GUI:Button_setTitleText(btn_GoOrGet, "领取")
  112. elseif data.giftState == E_RechargeState.NotComplete then
  113. GUI:Button_setBright(btn_GoOrGet,false)
  114. GUI:SetActive(btn_GoOrGet,true)
  115. GUI:Button_setGrey(btn_GoOrGet,true)
  116. GUI:Button_setTitleText(btn_GoOrGet, "未达成")
  117. elseif data.giftState == E_RechargeState.AlreadyGet then
  118. GUI:SetActive(txt_alreadyGet,true)
  119. end
  120. GUI:AddOnClickEvent(btn_GoOrGet,self,self.GoOrGetOnClick,{giftState = data.giftState,cfgId = data.weapCdgData.id})
  121. end
  122. function this:GoOrGetOnClick(_,eventData)
  123. if eventData.giftState == E_RechargeState.CanGet then
  124. --请求领奖
  125. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_RECEIVE_ANGEL_WEAPON_REWARD, {taskId = eventData.cfgId})
  126. end
  127. end
  128. ---注册UI事件和服务器消息
  129. function this:RegistEvents()
  130. SL:RegisterLUAEvent(LUA_ARCWEAPON_ACTIVITY_CHANGE, self.RefreshPanelData, self)
  131. GUI:AddOnClickEvent(self.view.btn_getBigReward,self,self.OnClickGetBigReward)
  132. end
  133. function this:OnClickGetBigReward()
  134. local bigData = InfoManager.arcWeapActivityInfo.arcWeapBigGiftDataTbl[1]
  135. if bigData.giftState == E_RechargeState.CanGet then
  136. --请求领奖
  137. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_RECEIVE_ANGEL_WEAPON_REWARD, {taskId = bigData.id})
  138. end
  139. end
  140. function this:RefreshBigTask()
  141. self:ShowDJSFunc()
  142. local bigData = InfoManager.arcWeapActivityInfo.arcWeapBigGiftDataTbl[1]
  143. local itemId = bigData.weapCdgData.angelWeaponReward[1][1]
  144. local count = bigData.weapCdgData.angelWeaponReward[1][2]
  145. local data = { width = "70",height = "70",itemid = itemId,mfixsize = "70,70",itemcount = count,bgtype = "0",raycast="1",}
  146. if self.item then
  147. GUI:Item_UpdataData(self.item, data)
  148. else
  149. self.item = GUI:Item_Create(self.view.model, data)
  150. end
  151. GUI:AddOnClickEvent(self.item, self, function()
  152. SL:OpenTips(nil, itemId)
  153. end)
  154. local giftState = bigData.giftState
  155. if giftState == E_RechargeState.CanGet then
  156. GUI:Button_setBright(self.view.btn_getBigReward,true)
  157. GUI:Button_setGrey(self.view.btn_getBigReward,false)
  158. GUI:Button_setTitleText(self.view.btn_getBigReward, "领取")
  159. elseif giftState == E_RechargeState.NotComplete then
  160. GUI:Button_setBright(self.view.btn_getBigReward,false)
  161. GUI:Button_setGrey(self.view.btn_getBigReward,true)
  162. GUI:Button_setTitleText(self.view.btn_getBigReward, "未达成")
  163. elseif giftState == E_RechargeState.AlreadyGet then
  164. GUI:Button_setBright(self.view.btn_getBigReward,true)
  165. GUI:Button_setGrey(self.view.btn_getBigReward,true)
  166. GUI:Button_setTitleText(self.view.btn_getBigReward, "已领取")
  167. end
  168. end
  169. function this:ClearDJSFunc()
  170. if self.sectimer then
  171. SL:UnSchedule(self.sectimer)
  172. self.sectimer = nil
  173. end
  174. end
  175. function this:ShowDJSFunc()
  176. self:ClearDJSFunc()
  177. local taskGroup = InfoManager.arcWeapActivityInfo.arcWeapGroup
  178. local timeTbl = SL:GetConfigMultiKeys("cfg_activity_angelWeaponTime",taskGroup,"taskGroup")
  179. local endDay = string.split(timeTbl.condition,"&")
  180. endDay = string.split(endDay[2],"#")
  181. endDay = tonumber(endDay[2])
  182. local countdown = InfoManager.mainActivityInfo:ShowActivityDJSFunc(endDay,0)
  183. self.sectimer = SL:Schedule(self.sectimer, 0, 1, countdown, function()
  184. countdown = countdown - 1
  185. if countdown > 0 then
  186. GUI:SetActive(self.view.txt_showTime,true)
  187. GUI:Text_setString(self.view.txt_showTime, GUIUtil.FormatTimeDHM(countdown))
  188. else
  189. GUI:SetActive(self.view.txt_showTime,false)
  190. self:ClearDJSFunc()
  191. GUI:UIPanel_Close("dev/outui/MainActivity/Panel/KLMainActivity/KLMainActivityPanel")
  192. end
  193. end)
  194. end
  195. function this:RefreshPanelData()
  196. --刷新大奖任务
  197. self:RefreshBigTask()
  198. --刷新穿戴任务
  199. self.showSmallList = {}
  200. self.showSmallList = InfoManager.arcWeapActivityInfo.arcWeapSmallGiftDataTbl
  201. table.sort(self.showSmallList,function(a,b)
  202. if a.giftState == b.giftState then
  203. return a.weapCdgData.sortId < b.weapCdgData.sortId
  204. else
  205. return a.giftState < b.giftState
  206. end
  207. end)
  208. GUI:DataListUpdateData(self.view.showInfoList)
  209. end
  210. ---界面显示时调用一次
  211. function this:Show()
  212. end
  213. ---创建或者刷新界面数据时调用
  214. function this:Refresh()
  215. self:RefreshPanelData()
  216. end
  217. function this:Close()
  218. self:ClearDJSFunc()
  219. end
  220. return this