UIFirstChargeInfo.lua 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. ---@class UIFirstChargeInfo
  2. UIFirstChargeInfo = class()
  3. local this = UIFirstChargeInfo
  4. ---首充挡位
  5. EFirstRechargeLevel = {
  6. one = 301,
  7. two = 302,
  8. three = 303,
  9. four = 304,
  10. five = 305,
  11. six = 306,
  12. }
  13. function this:Init()
  14. self:RegistMessages()
  15. self:Reset()
  16. end
  17. function this:Reset()
  18. self.FirstChargeInfo = nil
  19. end
  20. function this:RegistMessages()
  21. --SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_CURR_BIG_BANG_NUMBER,self.RES_CURR_BIG_BANG_NUMBER,self)
  22. SL:RegisterLUAEvent(LUA_EVENT_LEVELCHANGE, self.LUA_EVENT_LEVELCHANGE, self)
  23. SL:RegisterLUAEvent(LUA_EVENT_ROLE_LOGIN, self.EnterGame, self)
  24. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_RECHARGE_ACTION, self.RES_RECHARGE_ACTION, self)
  25. end
  26. function this:RES_RECHARGE_ACTION(_, message)
  27. if message.type == "3" then
  28. self:RES_FirstChargeGift_Info(_,message)
  29. end
  30. end
  31. function this:RES_FirstChargeGift_Info(_, message)
  32. if message then
  33. self.FirstChargeInfo = message
  34. SL:onLUAEvent(LUA_EVENT_RES_FIRST_CHARGE_GIFT_INFO, message)
  35. SL:RefreshPanelALLRedStateKmlByCondition("checkFirstCharge")
  36. end
  37. end
  38. function this:EnterGame()
  39. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_RECHARGE_ACTION, { type = 3, action = "panel" })
  40. end
  41. function this:LUA_EVENT_LEVELCHANGE(_,level, old)
  42. if level then
  43. local rechargeTbl = SL:GetConfig("cfg_first_charge", EFirstRechargeLevel.one)
  44. if rechargeTbl then
  45. local popUpsRule = rechargeTbl.popUpsRule
  46. local popUpsPicture=rechargeTbl.popUpsPicture
  47. for _, v in pairs(popUpsRule) do
  48. if tonumber(v[1]) == level then
  49. local PlayerPanel = GUI:GetUI("dev/ui/MainUI/Panel/KLUISystemTop/KLUISystemTopPanel")
  50. local findPanel
  51. if PlayerPanel and PlayerPanel.systemTemplateList then
  52. for i, systemItem in pairs(PlayerPanel.systemTemplateList) do
  53. if systemItem.args.id == 203 and GUI:getVisible(systemItem.view.root) then
  54. findPanel = systemItem
  55. end
  56. end
  57. end
  58. if findPanel then
  59. GUI:CloseAllUIWithoutMainUI()
  60. GUI:UIPanel_Open("dev/outui/FirstCharge/Panel/KLFirstChargeAD/KLFirstChargeADPanel", nil, nil, { count = tonumber(v[2]),popUpsPicture=popUpsPicture })
  61. end
  62. return
  63. end
  64. end
  65. end
  66. end
  67. end
  68. function this:ISRedDot()
  69. if not self.FirstChargeInfo then
  70. return false
  71. end
  72. local infoTbl = self:SortTable(self.FirstChargeInfo.data.rewards)
  73. for _, v in pairs(infoTbl) do
  74. if v.state == 1 then
  75. return true
  76. end
  77. end
  78. return false
  79. end
  80. ---是否购买了此挡位
  81. function this:IsBuyFirstCharge(cfgId)
  82. if not self.FirstChargeInfo then
  83. return false
  84. end
  85. local infoTbl = self:SortTable(self.FirstChargeInfo.data.rewards)
  86. for _, v in pairs(infoTbl) do
  87. if v.state == 1 and v.cfgId == cfgId then
  88. return true
  89. end
  90. end
  91. return false
  92. end
  93. ---是否领取了此挡位
  94. function this:IsGetAwardFirstCharge(cfgId)
  95. if not self.FirstChargeInfo then
  96. return false
  97. end
  98. local infoTbl = self:SortTable(self.FirstChargeInfo.data.rewards)
  99. for _, v in pairs(infoTbl) do
  100. if v.state == 2 and tonumber(v.cfgId) == cfgId then
  101. return true
  102. end
  103. end
  104. return false
  105. end
  106. function this:IsShowBtn()
  107. if not self.FirstChargeInfo then
  108. return true
  109. end
  110. if self:IsGetAwardFirstCharge(EFirstRechargeLevel.one) and self:IsGetAwardFirstCharge(EFirstRechargeLevel.two) and self:IsGetAwardFirstCharge(EFirstRechargeLevel.three) then
  111. return false
  112. end
  113. return true
  114. end
  115. function this:SortTable(Table)
  116. local temp = {}
  117. for i, v in pairs(Table) do
  118. local data = {
  119. cfgId = i,
  120. state = v
  121. }
  122. table.insert(temp, data)
  123. end
  124. table.sort(temp, function(a, b)
  125. return tonumber(a.cfgId) < tonumber(b.cfgId)
  126. end)
  127. return temp
  128. end