KLGoldChallengePanel.lua 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. ---@class KLGoldChallengePanel:UIKmlLuaPanelBase
  2. ---@field view KLGoldChallengePanelView
  3. ---@field itemList KLGoldChallengeItem[]
  4. local KLGoldChallengePanel = class(UIKmlLuaPanelBase)
  5. local this = KLGoldChallengePanel
  6. ---创建时调用一次
  7. function this:Init()
  8. self.itemList = {}
  9. GUI:DataListInitData(self.view.items, function()
  10. return self:DataListItemCountFunc()
  11. end, function(realIndex)
  12. return self:DataListItemGetFunc(realIndex)
  13. end, function(realIndex, kmlcontrol)
  14. return self:DataListItemInitFunc(realIndex, kmlcontrol)
  15. end, function(realIndex, kmlcontrol)
  16. return self:DataListItemUpdateFunc(realIndex, kmlcontrol)
  17. end)
  18. end
  19. ---创建或者刷新界面数据时调用
  20. function this:Refresh()
  21. self.isCanRefresh = false
  22. SL:HideMainPanel()
  23. SL:SendLuaNetMsg(LuaMessageIdToSever.GET_GOLD_TASK_INFO)
  24. end
  25. function this:RefreshUI()
  26. GUI:DataListUpdateData(self.view.items)
  27. local challengeCountCfg = SL:GetConfig("cfg_global", 2001)
  28. if challengeCountCfg then
  29. local challengeCount = tonumber(challengeCountCfg.value)
  30. local colorStr = ""
  31. if table.count(InfoManager.goldChallengeTaskInfo.taskInfo.dailyrecord) >= challengeCount then
  32. colorStr = EColor[EGradColor.red]
  33. else
  34. colorStr = EColor[EGradColor.green]
  35. end
  36. local str = string.format("<color=%s>%s/%s</color>", colorStr, table.count(InfoManager.goldChallengeTaskInfo.taskInfo.dailyrecord), challengeCount)
  37. GUI:Text_setString(self.view.FinishCountText, str)
  38. else
  39. local str = string.format("<color=%s>%s/%s</color>", EColor[EGradColor.green], 0, 4)
  40. GUI:Text_setString(self.view.FinishCountText, str)
  41. end
  42. local costCfg = SL:GetConfig("cfg_global", 2004)
  43. if costCfg then
  44. costCfg = string.split(costCfg.value, "#")
  45. local costStr = "%s/%s"
  46. local costItemId = tonumber(costCfg[1])
  47. local costItemCount = tonumber(costCfg[2])
  48. costStr = string.format(costStr, tostring(SL:GetBagItemCount(costItemId)), costItemCount)
  49. GUI:Text_setString(self.view.costText, costStr)
  50. local item = GUI:Item_Create(self.view.costModel, {
  51. width = "30",
  52. height = "30",
  53. itemid = costItemId,
  54. mfixsize = "80,80",
  55. tips = "1",
  56. bgtype = "0",
  57. })
  58. GUI:AddOnClickEvent(item, self, function()
  59. SL:OpenTips(nil, costItemId)
  60. end)
  61. end
  62. self:LUA_EVENT_MONEYCHANGE()
  63. GUI:Button_setGrey(self.view.RefreshBtn, not self:GetIsCanRefresh())
  64. end
  65. ---注册UI事件和服务器消息
  66. function this:RegistEvents()
  67. GUI:AddOnClickEvent(self.view.CloseBtn, self, self.BtnCloseOnClick)
  68. GUI:AddOnClickEvent(self.view.RefreshBtn, self, self.BtnRefreshOnClick)
  69. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_GOLD_TASK_INFO, self.ResGoldTaskInfo, self)
  70. SL:RegisterLUAEvent(LUA_EVENT_MONEYCHANGE, self.LUA_EVENT_MONEYCHANGE, self)
  71. end
  72. function this:LUA_EVENT_MONEYCHANGE()
  73. local costCfg = SL:GetConfig("cfg_global", 2004)
  74. if costCfg then
  75. costCfg = string.split(costCfg.value, "#")
  76. local costStr = "<color=%s>%s</color>/%s"
  77. local costItemId = tonumber(costCfg[1])
  78. local costItemCount = tonumber(costCfg[2])
  79. local haveItemCount = SL:GetBagItemCount(costItemId)
  80. local colorStr = ""
  81. if haveItemCount >= costItemCount then
  82. colorStr = EColor[EGradColor.green]
  83. else
  84. colorStr = EColor[EGradColor.red]
  85. end
  86. costStr = string.format(costStr, colorStr,SL:GetSimpleNumber(haveItemCount,0),SL:GetSimpleNumber(costItemCount,0))
  87. GUI:Text_setString(self.view.costText, costStr)
  88. end
  89. GUI:Button_setGrey(self.view.RefreshBtn, not self:GetIsCanRefresh())
  90. end
  91. ---@param message {nowtaskpool:table,flushcount:number,nowtask:GoldChallengeTask,firstopen:boolean,dailyrecord:GoldChallengeTask,lastresettime:number}
  92. function this:ResGoldTaskInfo(_, message)
  93. InfoManager.goldChallengeTaskInfo.taskInfo = message
  94. if InfoManager.goldChallengeTaskInfo.taskInfo then
  95. InfoManager.goldChallengeTaskInfo.taskInfo.taskPool = {}
  96. for k, v in pairs(InfoManager.goldChallengeTaskInfo.taskInfo.nowtaskpool) do
  97. table.insert(InfoManager.goldChallengeTaskInfo.taskInfo.taskPool, { k = tonumber(k), v = v })
  98. end
  99. end
  100. self:RefreshUI()
  101. end
  102. ----刷新当前任务
  103. function this:BtnRefreshOnClick()
  104. if self:GetIsCanRefresh(true) then
  105. SL:SendLuaNetMsg(LuaMessageIdToSever.FLUSH_GOLD_TASK_POOL)
  106. end
  107. end
  108. ----@param isShowTips boolean 是否提示
  109. ---@return boolean
  110. function this:GetIsCanRefresh(isShowTips)
  111. if InfoManager.goldChallengeTaskInfo.taskInfo.nowtas then
  112. if isShowTips then
  113. SL:TipMessage(SL:GetConfig('cfg_string',245).text, 1, NoticeType.NoticeMid )--"任务已在进行中!",
  114. end
  115. return false
  116. end
  117. local costCfg = SL:GetConfig("cfg_global", 2004)
  118. if costCfg then
  119. costCfg = string.split(costCfg.value, "#")
  120. local costItemId = tonumber(costCfg[1])
  121. local costItemCount = tonumber(costCfg[2])
  122. local haveItemCount = SL:GetBagItemCount(costItemId)
  123. if haveItemCount < costItemCount then
  124. if isShowTips then
  125. SL:TipMessage( SL:GetConfig('cfg_string',246).text, 1, NoticeType.NoticeMid )--"道具不足,请补充道具!",
  126. end
  127. return false
  128. end
  129. else
  130. SL:TipMessage( SL:GetConfig('cfg_string',246).text,1, NoticeType.NoticeMid )--"道具不足,请补充道具!",
  131. return false
  132. end
  133. local challengeCountCfg = SL:GetConfig("cfg_global", 2001)
  134. if challengeCountCfg then
  135. local challengeCount = tonumber(challengeCountCfg.value)
  136. if #InfoManager.goldChallengeTaskInfo.taskInfo.dailyrecord >= challengeCount then
  137. if isShowTips then
  138. SL:TipMessage(SL:GetConfig('cfg_string',247).text, 1, NoticeType.NoticeMid )--"任务已完成!",
  139. end
  140. return false
  141. end
  142. else
  143. if isShowTips then
  144. SL:TipMessage( SL:GetConfig('cfg_string',247).text,1, NoticeType.NoticeMid )--"任务已完成!",
  145. end
  146. return false
  147. end
  148. return true
  149. end
  150. ----关闭界面
  151. function this:BtnCloseOnClick()
  152. GUI:UIPanel_Close("dev/outui/Activity/Panel/KLGoldChallenge/KLGoldChallengePanel")
  153. end
  154. function this:DataListItemCountFunc()
  155. return table.count(InfoManager.goldChallengeTaskInfo.taskInfo.nowtaskpool)
  156. end
  157. function this:DataListItemGetFunc(realIndex)
  158. ---@type KLGoldChallengeItem
  159. local tempItem = GUI:UIPanel_Open("dev/outui/Activity/Item/KLGoldChallenge/KLGoldChallengeItem", self.view.items, self, nil, true)
  160. local kmlcontrol = tempItem.view.root
  161. self.itemList[kmlcontrol] = tempItem
  162. return kmlcontrol
  163. end
  164. ---@param kmlcontrol UIKmlLuaControl
  165. function this:DataListItemInitFunc(realIndex, kmlcontrol)
  166. end
  167. function this:DataListItemUpdateFunc(realIndex, kmlcontrol)
  168. self.itemList[kmlcontrol]:InitData(realIndex + 1, InfoManager.goldChallengeTaskInfo.taskInfo.taskPool[realIndex + 1])
  169. self.itemList[kmlcontrol]:RefreshUI()
  170. end
  171. function this:Close()
  172. SL:ShowMainPanel()
  173. end
  174. return this