KLEveryDayGiftRechargePanel.lua 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. ---@class KLEveryDayGiftRechargePanel:UIKmlLuaPanelBase
  2. ---@field view KLEveryDayGiftRechargePanelView
  3. local KLEveryDayGiftRechargePanel = class(UIKmlLuaPanelBase)
  4. local this =KLEveryDayGiftRechargePanel
  5. ---创建时调用一次
  6. function this:Init()
  7. self.allData = {}
  8. self.rewardShowList = {}
  9. GUI:DataListInitData(self.view.rewardShowDataList, function()
  10. return table.count(self.allData.rewardShowItem)
  11. end,function()
  12. end,function()
  13. end,function(realIndex)
  14. local ItemInfoSlotModelControl = GUI:GetChildControl(self.view.rewardShowDataList,realIndex,'ItemInfoSlotModel') --任务名称
  15. local info = self.allData.rewardShowItem[realIndex+1]
  16. GUI:Item_setItemId(ItemInfoSlotModelControl, info.itemId)
  17. GUI:Item_UpdataData(ItemInfoSlotModelControl,{itemcount = info.count})
  18. GUI:AddOnClickEvent(ItemInfoSlotModelControl,self,function()
  19. SL:OpenTips(nil, info.itemId)
  20. end)
  21. end)
  22. self.taskListInfo = {}
  23. GUI:DataListInitData(self.view.taskList, function()
  24. return table.count(self.allData.task)
  25. end,function()
  26. end,function()
  27. end,function(realIndex)
  28. local taskNameControl = GUI:GetChildControl(self.view.taskList,realIndex,'taskName') --任务名称
  29. local taskrewardlistControl = GUI:GetChildControl(self.view.taskList,realIndex,'taskrewardlist') --任务奖励列表
  30. local taskGetButtonControl = GUI:GetChildControl(self.view.taskList,realIndex,'getButton') --getButton
  31. local haveGainText = GUI:GetChildControl(self.view.taskList,realIndex,'haveGainText') --已领取
  32. local redpoint = GUI:GetChildControl(self.view.taskList,realIndex,'redpoint') --红点
  33. local info = self.allData.task[realIndex+1]
  34. GUI:Button_setTitleText(taskNameControl, info.task)
  35. GUI:setVisible(redpoint, false)
  36. GUI:setVisible(haveGainText,false)
  37. GUI:setVisible(taskGetButtonControl,true)
  38. if info.canGain and info.haveGain then
  39. GUI:Button_setTitleText(taskGetButtonControl, "已领取")
  40. GUI:setVisible(haveGainText,true)
  41. GUI:setVisible(taskGetButtonControl,false)
  42. elseif info.canGain then
  43. GUI:Button_setTitleText(taskGetButtonControl, "可领取")
  44. GUI:setVisible(redpoint, true)
  45. else
  46. GUI:Button_setTitleText(taskGetButtonControl, "前往")
  47. end
  48. GUI:AddOnClickEvent(taskGetButtonControl,self,self.GetButton,{ info})
  49. self:RewardItemUpdateFun(taskrewardlistControl,realIndex)
  50. end)
  51. end
  52. --Task奖励列表刷新
  53. function this:RewardItemUpdateFun(ItemInfoListControl,Index)
  54. local data = self.allData.task[Index+1]
  55. local showRewards={}
  56. for k,v in ipairs(data.gift) do
  57. table.insert(showRewards,v)
  58. end
  59. GUI:DataListInitData(ItemInfoListControl, function()
  60. return table.count(showRewards)
  61. end,function()
  62. end,function()
  63. end,function(realIndex)
  64. local taskRewardItemModel = GUI:GetChildControl(ItemInfoListControl,realIndex,'taskRewardItem') --模型
  65. local info = showRewards[realIndex+1]
  66. GUI:Item_setItemId(taskRewardItemModel, info.itemId)
  67. GUI:Item_UpdataData(taskRewardItemModel,{itemcount = info.count})
  68. GUI:AddOnClickEvent(taskRewardItemModel,self,function()
  69. SL:OpenTips(nil, info.itemId)
  70. end)
  71. end)
  72. GUI:DataListUpdateData(ItemInfoListControl)
  73. end
  74. ---注册UI事件和服务器消息
  75. function this:RegistEvents()
  76. GUI:AddOnClickEvent(self.view.FreeBtn, self, self.FreeBtn)
  77. SL:RegisterLUAEvent(LUA_EVENT_EVERYDAYGIFT_RECHARGE_CHANGE, this.LUA_EVENT_EVERYDAYGIFT_RECHARGE_CHANGE, self)
  78. end
  79. --服务器发送礼包组消息后刷新礼包组的数据
  80. function this:LUA_EVENT_EVERYDAYGIFT_RECHARGE_CHANGE()
  81. self:RefreshPanel()
  82. end
  83. ---免费馈赠领取按钮
  84. function this:FreeBtn()
  85. local FreeId = InfoManager.everyDayGiftRechargeInfo.EverDayGiftFreeDataId
  86. if not self.allData.dayFreeGift then --今日未领取过免费
  87. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_RECHARGE_ACTION, { type = 13, action = "reward", id = FreeId })
  88. else
  89. SL:TipMessage("今日已领取过", 1, NoticeType.NoticeMid )
  90. end
  91. end
  92. ---列表的领取按钮
  93. function this:GetButton(control, info)
  94. if info[1].canGain and info[1].haveGain then
  95. SL:TipMessage( "该奖励已领取", 1, NoticeType.NoticeMid )
  96. elseif info[1].canGain then
  97. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_RECHARGE_ACTION, { type = 13, action = "reward", id = info[1].id })
  98. else
  99. GUI:UIPanel_Close("dev/outui/MainRecharge/Panel/KLMainRecharge/KLMainRechargePanel")
  100. --跳转到每日礼包页签
  101. local navId = SL:GetConfig("cfg_global",20001).value
  102. GUI:UIPanel_Open("dev/outui/MainRecharge/Panel/KLMainRecharge/KLMainRechargePanel",_,_,{mainRechargeId = navId})
  103. end
  104. end
  105. ---界面显示时调用一次
  106. function this:Show()
  107. end
  108. ---创建或者刷新界面数据时调用
  109. function this:Refresh()
  110. self:RefreshPanel()
  111. end
  112. function this:RefreshPanel()
  113. self.taskListInfo = {}
  114. self.allData = InfoManager.everyDayGiftRechargeInfo.EveryDayGiftData
  115. GUI:Text_setString(self.view.everydayTaskText,"每日充值"..tostring(self.allData.needCost).."元即可领取以下奖励")
  116. if self.allData.dayFreeGift then --今日是否已经领取过免费馈赠
  117. GUI:setVisible(self.view.FreeBtn, false)
  118. GUI:setVisible(self.view.FreeGetImg, true)
  119. else
  120. GUI:setVisible(self.view.FreeBtn, true)
  121. GUI:setVisible(self.view.FreeGetImg, false)
  122. end
  123. GUI:Text_setString(self.view.roundsNum,"第"..tostring(self.allData.group).."轮")
  124. GUI:DataListUpdateData(self.view.rewardShowDataList)
  125. GUI:DataListUpdateData(self.view.taskList)
  126. end
  127. function this:Close()
  128. end
  129. return this