KLUIArchangelRewardItem.lua 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. ---@class KLUIArchangelRewardItem:UIKmlLuaPanelBase
  2. ---@field view KLUIArchangelRewardItemView
  3. ---@field data cfg_angleBenefitReward_column
  4. local KLUIArchangelRewardItem = class(UIKmlLuaPanelBase)
  5. local this = KLUIArchangelRewardItem
  6. ---创建时调用一次
  7. function this:Init()
  8. end
  9. function this:InitData(data)
  10. self.data = data
  11. self:RefreshUI()
  12. end
  13. function this:SetControlsHide()
  14. GUI:setVisible(self.view.TextTime, false)
  15. GUI:setVisible(self.view.icon, false)
  16. GUI:setVisible(self.view.remainCount, false)
  17. GUI:setVisible(self.view.getButton, false)
  18. GUI:setVisible(self.view.buyButton, false)
  19. GUI:setVisible(self.view.ClaimedText, false)
  20. GUI:setVisible(self.view.ClaimedIcon, false)
  21. end
  22. -- 已领取
  23. function this:SetControlsClaimed()
  24. GUI:setVisible(self.view.ClaimedText, true)
  25. GUI:setVisible(self.view.ClaimedIcon, true)
  26. GUI:setVisible(self.view.getButton, false)
  27. GUI:setVisible(self.view.buyButton, false)
  28. GUI:setVisible(self.view.remainCount, false)
  29. GUI:setVisible(self.view.icon, false)
  30. GUI:Image_loadTexture(self.view.ClaimedIcon, "img_kaifu_get", "Atlas/QJ5_Common.spriteatlas")
  31. end
  32. ---注册UI事件和服务器消息
  33. function this:RegistEvents()
  34. GUI:AddOnClickEvent(self.view.getButton, self, self.BtnGetOnClick)
  35. GUI:AddOnClickEvent(self.view.buyButton, self, self.BtnBuyOnClick)
  36. end
  37. function this:BtnGetOnClick()
  38. if self.data and self.data.id then
  39. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_RECEIVE_ANGLE_BENEFIT_REWARD, { order = self.data.id })
  40. end
  41. end
  42. function this:BtnBuyOnClick()
  43. if self.data and self.data.id then
  44. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_RECEIVE_ANGLE_BENEFIT_REWARD, { order = self.data.id })
  45. end
  46. end
  47. ---界面显示时调用一次
  48. function this:Show()
  49. end
  50. ---创建或者刷新界面数据时调用
  51. function this:Refresh()
  52. end
  53. function this:RefreshUI()
  54. self:SetControlsHide()
  55. local openDay = Utility.GetServerOpenDays() -- 开服天数0点刷新
  56. local count = self.data.limitNum - self.data.usenum -- 剩余全服数量
  57. if count < 0 then
  58. count = 0
  59. end
  60. local integral = self.data.curgoal -- 当前积分,从背包获取
  61. local maxInterag = self.data.rewardPoint[2]
  62. self:Refreshicon({ self.data.buyid, self.data.buynum })
  63. -- 限免时间内UI 显示
  64. local showTime = self.data.diffTime
  65. if showTime > 0 and count > 0 then
  66. local time = math.ceil(self.data.limitTime - openDay)
  67. if time > 1 or showTime/86400000 >= 1 then
  68. GUI:Text_setString(self.view.TextTime, "<color=#5DE367>" .. time .. "天后过期" .. "</color>") -- 过期时间
  69. else
  70. self:ShowTime(showTime)
  71. end
  72. GUI:setVisible(self.view.TextTime, true)
  73. if integral >= maxInterag and count > 0 then
  74. -- 积分满足
  75. GUI:setVisible(self.view.getButton, true)
  76. else
  77. if self.data.lastgetnumid > 0 then
  78. if self.data.reqid == self.data.lastgetnumid then
  79. GUI:setVisible(self.view.remainCount, true)
  80. end
  81. else
  82. GUI:setVisible(self.view.remainCount, true)
  83. end
  84. end
  85. else
  86. GUI:setVisible(self.view.icon, true)
  87. self:Refreshicon({ self.data.buyid, self.data.buynum })
  88. if self.data.lastbuyid > 0 then
  89. if self.data.reqid == self.data.lastbuyid then
  90. GUI:setVisible(self.view.buyButton, true)
  91. end
  92. else
  93. GUI:setVisible(self.view.buyButton, true)
  94. end
  95. end
  96. if integral >= maxInterag then
  97. GUI:Text_setString(self.view.Textcur, "<color=#5DE367>" .. maxInterag .. "</color>") -- 当前积分
  98. else
  99. GUI:Text_setString(self.view.Textcur, "<color=#FF5047>" .. maxInterag .. "</color>") -- 当前积分
  100. end
  101. ---- 剩余全服数量/总数量
  102. local str = "全服限量:" .. count .. "/" .. self.data.limitNum
  103. GUI:Text_setString(self.view.remainCount, str) -- 当前限免次数
  104. local reward = SL:GetRewardIdByCareer(self.data.reward)
  105. self:RefreshitemReward({ reward[1], reward[2] })
  106. if self.data.isGet then
  107. self:SetControlsClaimed()
  108. end
  109. end
  110. -- 最后一天倒计时
  111. function this:ShowTime(diff)
  112. self:SetCountDown(diff)
  113. end
  114. --- 开启倒计时
  115. ---@param time number @倒计时时间,毫秒
  116. function this:SetCountDown(time)
  117. self.countDown = time / 1000
  118. local txtTime = Time.FormatTimeDHMSFormColon(self.countDown)
  119. GUI:Text_setString(self.view.TextTime, "<color=#5DE367>" .. txtTime .. "后过期" .. "</color>") -- 过期时间
  120. self:StopRankTimer()
  121. self.countDownTimer = SL:Schedule(self.countDownTimer, 0, 1, -1, function()
  122. local time = Time.FormatTimeDHMSFormColon(self.countDown)
  123. GUI:Text_setString(self.view.TextTime, "<color=#5DE367>" .. time .. "后过期" .. "</color>") -- 过期时间
  124. if self.countDown <= 0 then
  125. self:RefreshUI()
  126. self:StopRankTimer()
  127. return
  128. end
  129. self.countDown = self.countDown - 1
  130. end)
  131. end
  132. function this:StopRankTimer()
  133. if self.countDownTimer then
  134. SL:UnSchedule(self.countDownTimer)
  135. self.countDownTimer = nil
  136. end
  137. end
  138. function this:Refreshcount(cfgid, count)
  139. local txt = ""
  140. if count then
  141. txt = tonumber(count) and Misc.GetSampleNumberString(count) or count
  142. end
  143. return txt
  144. end
  145. -- 创建花费icon
  146. function this:Refreshicon(data)
  147. local num = SL:GetBagItemCount(data[1]) or 0
  148. if data then
  149. local strcur = self:Refreshcount(data[1], data[2])
  150. if tonumber(num) < tonumber(data[2]) then
  151. strcur = "<color=#FF5047>" .. strcur .. "</color>"
  152. else
  153. strcur = "<color=#ECE8E8>" .. strcur .. "</color>"
  154. end
  155. GUI:Text_setString(self.view.numtext, strcur) -- 当前花费
  156. if not self.iconItem then
  157. self.iconItem = GUI:Item_Create(self.view.icon, {
  158. width = "50",
  159. height = "50",
  160. itemid = data[1],
  161. mfixsize = "20,20",
  162. tips = "1",
  163. bgtype = "0",
  164. itemcount = "",
  165. })
  166. else
  167. GUI:Item_UpdataData(self.iconItem, {
  168. itemid = data[1],
  169. })
  170. end
  171. GUI:setPositionY(self.iconItem, -7)
  172. end
  173. end
  174. --- 创建奖励itemReward
  175. function this:RefreshitemReward(data)
  176. if not self.rewardItem then
  177. self.rewardItem = GUI:Item_Create(self.view.itemReward, {
  178. width = "50",
  179. height = "50",
  180. itemid = data[1],
  181. mfixsize = "80,80",
  182. tips = "1",
  183. bgtype = "0",
  184. itemcustomcount = data[2],
  185. })
  186. else
  187. GUI:Item_UpdataData(self.rewardItem, {
  188. itemid = data[1],
  189. })
  190. end
  191. GUI:AddOnClickEvent(self.rewardItem, self, function()
  192. SL:OpenTips(nil, data[1])
  193. end)
  194. self:SetItemEffect(data[1])
  195. end
  196. -- 显示奖励特效
  197. function this:SetItemEffect(cfgId)
  198. ---Eff_Ui_kuang_hong02 奇迹5特效
  199. local sEffect = SL:GetConfig("cfg_item", cfgId, "id").sEffect
  200. local effect_id = sEffect == 0 and 30001 or sEffect
  201. if effect_id and effect_id ~= 0 then
  202. local effect_tbl = SL:GetConfig("cfg_model_effect", effect_id, "id")
  203. GUI:Model_setSrc(self.view.effect_model, effect_tbl.path)
  204. GUI:setVisible(self.view.effect_model, true)
  205. else
  206. GUI:setVisible(self.view.effect_model, false)
  207. end
  208. end
  209. function this:Close()
  210. self:StopRankTimer()
  211. end
  212. return this