KLNoobPlayerPackPanel.lua 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. ---@class KLNoobPlayerPackPanel:UIKmlLuaPanelBase
  2. ---@field view KLNoobPlayerPackPanelView
  3. local KLNoobPlayerPackPanel = class(UIKmlLuaPanelBase)
  4. local this =KLNoobPlayerPackPanel
  5. function this:AsyncLoadUI()
  6. end
  7. ---创建时调用一次
  8. function this:Init()
  9. self.itemInfoList = {}
  10. GUI:DataListInitData(self.view.PackItemList, function()
  11. return table.count(self.itemInfoList)
  12. end,function()
  13. end,function()
  14. end,function(realIndex)
  15. local discountControl = GUI:GetChildControl(self.view.PackItemList,realIndex,'discountImage') --左上角返利
  16. local discountTextControl = GUI:GetChildControl(self.view.PackItemList,realIndex,'discountText') --返利数值
  17. local ItemNameShowText = GUI:GetChildControl(self.view.PackItemList,realIndex,'ItemNameShowText') --礼包名称
  18. local limitBuyCountControl = GUI:GetChildControl(self.view.PackItemList,realIndex,'limitBuyCount') --限制次数
  19. local ItemInfoListControl = GUI:GetChildControl(self.view.PackItemList,realIndex,'ItemInfoList') --奖励列表
  20. local BuyBtnControl = GUI:GetChildControl(self.view.PackItemList,realIndex,'PackItemBuyBtn') --购买按钮
  21. local redpoint = GUI:GetChildControl(self.view.PackItemList,realIndex,'redpoint') --红点
  22. local info = self.itemInfoList[realIndex+1]
  23. local buycount = 0 --剩余次数
  24. local totalcount = 0
  25. buycount,totalcount = InfoManager.countInfo:GetLimitAndTotalCountByKey(info.Countkey)
  26. if info.Packagename and info.Packagename~=""then
  27. GUI:Text_setString(ItemNameShowText, info.Packagename)
  28. else
  29. GUI:Text_setString(ItemNameShowText, "免费礼包")
  30. end
  31. --返利
  32. if info.rebate and info.rebate>0 then
  33. GUI:setVisible(discountControl, true)
  34. GUI:Text_setString(discountTextControl, info.rebate.."%")
  35. else
  36. GUI:setVisible(discountControl, false)
  37. end
  38. GUI:setVisible(redpoint, false)
  39. GUI:AddOnClickEvent(BuyBtnControl, self, self.ItemBuyBtn, {info})
  40. if info.canBuy then
  41. if info.Price == 0 then
  42. GUI:Button_setTitleText(BuyBtnControl, "领取")
  43. GUI:setVisible(redpoint, true)
  44. else
  45. GUI:Button_setTitleText(BuyBtnControl, tostring(info.Price).."元")
  46. end
  47. else
  48. GUI:Button_setTitleText(BuyBtnControl, "已购买")
  49. end
  50. GUI:Text_setString(limitBuyCountControl, "限购次数:"..(totalcount-buycount).."/"..totalcount)
  51. self:ItemUpdateFun(ItemInfoListControl,realIndex)
  52. end)
  53. end
  54. function this:ItemUpdateFun(ItemInfoListControl,Index)
  55. local data = self.itemInfoList[Index + 1]
  56. local showRewards={}
  57. for k,v in ipairs(data.Rewards) do
  58. table.insert(showRewards,v)
  59. end
  60. GUI:DataListInitData(ItemInfoListControl, function()
  61. return table.count(showRewards)
  62. end,function()
  63. end,function()
  64. end,function(realIndex)
  65. local ItemInfoSlotModel = GUI:GetChildControl(ItemInfoListControl,realIndex,'ItemInfoSlotModel') --模型
  66. local ItemInfoSlotCount = GUI:GetChildControl(ItemInfoListControl,realIndex,'ItemInfoSlotCount') --数量
  67. local itemInfoTips = GUI:GetChildControl(ItemInfoListControl,realIndex,'itemInfoTips') --模型Tips
  68. local itemdata = showRewards[realIndex+1]
  69. GUI:setVisible(ItemInfoSlotModel, true)
  70. GUI:setVisible(itemInfoTips, true)
  71. GUI:setVisible(ItemInfoSlotCount, true)
  72. GUI:Item_setItemId(ItemInfoSlotModel, itemdata[1])
  73. if itemdata[1] == 10040001 or itemdata[1] == 10050001 then
  74. GUI:Model_setSrc(ItemInfoSlotModel, nil, nil, nil, nil, "24,24")
  75. end
  76. GUI:AddOnClickEvent(itemInfoTips,self,function()
  77. SL:OpenTips(nil, itemdata[1])
  78. end)
  79. GUI:Text_setString(ItemInfoSlotCount, tostring(itemdata[2]))
  80. end)
  81. GUI:DataListUpdateData(ItemInfoListControl)
  82. end
  83. ---注册UI事件和服务器消息
  84. function this:RegistEvents()
  85. SL:RegisterLUAEvent(LUA_EVENT_NOOBPACK_RECHARGE_CHANGE, this.LUA_EVENT_NOOBPACK_RECHARGE_CHANGE, self)
  86. end
  87. --服务器发送礼包组消息后刷新礼包组的数据
  88. function this:LUA_EVENT_NOOBPACK_RECHARGE_CHANGE()
  89. self:RefreshPanel()
  90. end
  91. ---列表的购买按钮
  92. function this:ItemBuyBtn(control, data)
  93. if data[1].canBuy then
  94. local tab = SL:GetConfig("cfg_recharge", tonumber(data[1].RechargeId))
  95. GUIUtil.SDKPay(tab,1)
  96. end
  97. end
  98. ---界面显示时调用一次
  99. function this:Show()
  100. end
  101. ---创建或者刷新界面数据时调用
  102. function this:Refresh()
  103. self:RefreshPanel()
  104. end
  105. function this:RefreshPanel()
  106. self.itemInfoList = {}
  107. local giftData = InfoManager.noobPackRechargeInfo.NoobPlayerPackData
  108. if not table.isNullOrEmpty(giftData) then
  109. for k,v in ipairs(giftData) do
  110. local buycount = 0 --剩余次数
  111. local totalcount = 0
  112. buycount,totalcount = InfoManager.countInfo:GetLimitAndTotalCountByKey(v.Countkey)
  113. if buycount < 1 then
  114. v.canBuy = false
  115. else
  116. v.canBuy = true
  117. end
  118. table.insert(self.itemInfoList, v)
  119. end
  120. end
  121. table.sort(self.itemInfoList,function (a,b)
  122. if a.canBuy == b.canBuy then
  123. return a.Price<b.Price
  124. elseif a.canBuy then
  125. return true
  126. else
  127. return false
  128. end
  129. end)
  130. GUI:DataListUpdateData(self.view.PackItemList)
  131. self:ShowDJHFunc()
  132. end
  133. function this:ClearDJHFunc()
  134. if self.sectimer then
  135. SL:UnSchedule(self.sectimer)
  136. self.sectimer = nil
  137. end
  138. end
  139. function this:ShowDJHFunc()
  140. self:ClearDJHFunc()
  141. local data = self.args
  142. local endDay = InfoManager.mainActivityInfo:GetActivityEndDay(data.mainRechargeData)
  143. local countdown = InfoManager.mainActivityInfo:ShowActivityDJSFunc(endDay,0)
  144. self.sectimer = SL:Schedule(self.sectimer, 0, 1, countdown, function()
  145. countdown = countdown - 1
  146. if countdown > 0 then
  147. GUI:SetActive(self.view.txt_showTime,true)
  148. GUI:Text_setString(self.view.txt_showTime, GUIUtil.FormatTimeDHM(countdown))
  149. else
  150. GUI:SetActive(self.view.txt_showTime,false)
  151. self:ClearDJHFunc()
  152. GUI:UIPanel_Close("dev/outui/MainRecharge/Panel/KLMainRecharge/KLMainRechargePanel")
  153. end
  154. end)
  155. end
  156. function this:Close()
  157. self:ClearDJHFunc()
  158. end
  159. return this