KLUILifetimeGiftPackageItem.lua 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. ---@class KLUILifetimeGiftPackageItem:UIKmlLuaPanelBase
  2. ---@field view KLUILifetimeGiftPackageItemView
  3. local KLUILifetimeGiftPackageItem = class(UIKmlLuaPanelBase)
  4. local this =KLUILifetimeGiftPackageItem
  5. ---创建时调用一次
  6. function this:Init()
  7. --道具奖励
  8. GUI:DataListInitData(self.view.itemContent,function()
  9. return self:ItemRewardItemCountFunc()
  10. end,function(realIndex)
  11. return self:ItemRewardItemGetFunc(realIndex)
  12. end,function(realIndex, kmlcontrol)
  13. return self:ItemRewardItemInitFunc(realIndex, kmlcontrol)
  14. end, function(realIndex, kmlcontrol)
  15. return self:ItemRewardItemUpdateFunc(realIndex, kmlcontrol)
  16. end)
  17. self.Item_Reward_all_item = {}
  18. end
  19. --region 道具奖励列表
  20. function this:ItemRewardItemCountFunc()
  21. return #self.allItemRewardData
  22. end
  23. function this:ItemRewardItemGetFunc(realIndex)
  24. local itemId = self.allItemRewardData[realIndex + 1][1]
  25. local itemCount = self.allItemRewardData[realIndex + 1][2]
  26. local item = GUI:Item_Create(self.view.itemContent,{
  27. width = 60,
  28. height = 60,
  29. itemid = itemId,
  30. --mfixsize = "80,80",
  31. tips = "1",
  32. itemcustomcount = itemCount,
  33. })
  34. GUI:AddOnClickEvent(item,self,function()
  35. SL:OpenTips(nil,itemId)
  36. end)
  37. self.Item_Reward_all_item[realIndex + 1] = item
  38. return item.kmlControl
  39. end
  40. function this:ItemRewardItemInitFunc(realIndex, kmlcontrol)
  41. end
  42. function this:ItemRewardItemUpdateFunc(realIndex, kmlcontrol)
  43. local itemId = self.allItemRewardData[realIndex + 1][1]
  44. local itemCount = self.allItemRewardData[realIndex + 1][2]
  45. local item = self.Item_Reward_all_item[realIndex + 1]
  46. GUI:Item_setItemId(item,itemId)
  47. GUI:Item_setItemCount(item,itemCount)
  48. GUI:AddOnClickEvent(item,self,function()
  49. SL:OpenTips(nil,itemId)
  50. end)
  51. end
  52. function this:RefreshItemList(Rewards)
  53. self.allItemRewardData = Rewards
  54. GUI:DataListUpdateData(self.view.itemContent)
  55. end
  56. --endregion 道具奖励列表
  57. ---注册UI事件和服务器消息
  58. function this:RegistEvents()
  59. GUI:AddOnClickEvent(self.view.buyBtn,self,self.buyBtn)
  60. end
  61. function this:buyBtn()
  62. if self.canBuy and self.args then
  63. GUIUtil.SDKPay(self.args.rechargeCfg,1)
  64. end
  65. end
  66. ---创建或者刷新界面数据时调用
  67. function this:Refresh()
  68. if self.args then
  69. GUI:Text_setString(self.view.titleText,self.args.rechargeCfg.name)
  70. GUI:Text_setString(self.view.DiscountText,string.format("%d%%",self.args.lifetimeCfg.rebate))
  71. local remainCount,totalCount = InfoManager.countInfo:GetLimitAndTotalCountByKey(self.args.rechargeCfg.Countkey)
  72. self.canBuy = remainCount > 0
  73. if self.canBuy then
  74. GUI:Text_setString(self.view.countText,string.format("终生限购次数:%d/%d",totalCount-remainCount,totalCount))
  75. GUI:Button_setTitleText(self.view.buyBtn,string.format("%d元",self.args.rechargeCfg.amount))
  76. --GUI:Button_setGrey(self.view.buyBtn,false)
  77. else
  78. GUI:Text_setString(self.view.countText,string.format("终生限购次数:%d/%d",totalCount-remainCount,totalCount))
  79. GUI:Button_setTitleText(self.view.buyBtn,"已购买")
  80. --GUI:Button_setGrey(self.view.buyBtn,true)
  81. end
  82. self:RefreshItemList(self.args.lifetimeCfg.Rewards)
  83. end
  84. end
  85. function this:RefreshItem(args)
  86. self.args = args
  87. self:Refresh()
  88. end
  89. function this:Close()
  90. self.canBuy = nil
  91. end
  92. return this