KLRechargePushPanel.lua 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. ---@class KLRechargePushPanel:UIKmlLuaPanelBase
  2. ---@field view KLRechargePushPanelView
  3. local KLRechargePushPanel = class(UIKmlLuaPanelBase)
  4. local this = KLRechargePushPanel
  5. function this:AsyncLoadUI()
  6. end
  7. ---创建时调用一次
  8. function this:Init()
  9. self.curIndex = 1
  10. self.BtnList = {}
  11. end
  12. ---注册UI事件和服务器消息
  13. function this:RegistEvents()
  14. GUI:AddOnClickEvent(self.view.CloseBtn, self, self.CloseBtnOnClick)
  15. GUI:AddOnClickEvent(self.view.BuyBtn, self, self.BuyBtnOnClick)
  16. end
  17. function this:BuyBtnOnClick()
  18. if self.dataList then
  19. GUI:UIPanel_Close("dev/outui/Recharge/Panel/KLRechargePush/KLRechargePushPanel")
  20. local GiftTbl = SL:GetConfig("cfg_gift_preferential", self.dataList[self.curIndex].giftId)
  21. shortcutOutMgr.DO(GiftTbl.Jump)
  22. SL:HideMainPanel()
  23. end
  24. end
  25. function this:CloseBtnOnClick()
  26. local topPanel = GUI:GetUI("dev/ui/MainUI/Panel/KLUISystemTop/KLUISystemTopPanel")
  27. if topPanel then
  28. topPanel:Refresh()
  29. end
  30. GUI:UIPanel_Close("dev/outui/Recharge/Panel/KLRechargePush/KLRechargePushPanel")
  31. end
  32. ---界面显示时调用一次
  33. function this:Show()
  34. end
  35. ---创建或者刷新界面数据时调用
  36. function this:Refresh()
  37. if not InfoManager.rechargePushInfo:IsShowBtn() then
  38. GUI:UIPanel_Close("dev/outui/Recharge/Panel/KLRechargePush/KLRechargePushPanel")
  39. end
  40. self.ItemList = {}
  41. self.dataList = {}
  42. local infoList = InfoManager.rechargePushInfo.DataList
  43. for _, v in pairs(infoList) do
  44. if v.endTime >= Time.GetServerTime() then
  45. table.insert(self.dataList, v)
  46. end
  47. end
  48. local index = 1
  49. local pos = {
  50. { 384, 95 },
  51. { 379, 35 },
  52. { 374, -25 },
  53. { 368, -85 }
  54. }
  55. for _, v in pairs(self.BtnList) do
  56. GUI:UIPanel_Close(nil, v)
  57. end
  58. self.BtnList = {}
  59. for _, v in pairs(self.dataList) do
  60. if not self.BtnList[index] then
  61. self.BtnList[index] = GUI:UIPanel_Open("dev/outui/Recharge/Item/KLPushGiftBtn/KLPushGiftBtnItem", self.view.Bg, self, nil, true,function(tempUI)
  62. self.BtnList[index] = tempUI
  63. GUI:setPosition(self.BtnList[index].view.root, pos[index][1], pos[index][2])
  64. local GiftTbl = SL:GetConfig("cfg_gift_preferential", v.giftId)
  65. GUI:Text_setString(self.BtnList[index].view.BtnText, GiftTbl.name)
  66. GUI:AddOnClickEvent(self.BtnList[index].view.GiftBtn, self, self.ShowBtnOnClick, index)
  67. end)
  68. end
  69. index = index + 1
  70. end
  71. self:ShowBtnOnClick(_, 1)
  72. end
  73. function this:ShowBtnOnClick(_, index)
  74. if index then
  75. self:SetSelectImg(index)
  76. end
  77. end
  78. function this:SetSelectImg(index)
  79. for i, v in pairs(self.BtnList) do
  80. local GiftTbl = SL:GetConfig("cfg_gift_preferential", self.dataList[index].giftId)
  81. if i == index then
  82. self.curIndex = index
  83. GUI:Image_loadTexture(v.view.GiftBtn, "button_choosen", "Atlas/QJ5_RechargePushPanel.spriteatlas")
  84. self:ShowMountModel(GiftTbl)
  85. self:ShowItem(GiftTbl)
  86. GUI:Text_setString(self.view.BuyBtn, tostring(GiftTbl.buttonTips))
  87. self:UpDataBtnUI(GiftTbl.id)
  88. GUI:SetActive(v.view.Time, false)
  89. GUI:setPosition(v.view.BtnText, 0, 0)
  90. v:ShowTime(self.dataList[i].endTime)
  91. else
  92. v:ShowTime(self.dataList[i].endTime)
  93. GUI:SetActive(v.view.Time, true)
  94. GUI:setPosition(v.view.BtnText, 0, 10)
  95. GUI:Text_setString(self.view.BuyBtn, tostring(GiftTbl.buttonTips))
  96. GUI:Image_loadTexture(v.view.GiftBtn, "button_unchoosen", "Atlas/QJ5_RechargePushPanel.spriteatlas")
  97. end
  98. end
  99. end
  100. function this:UpDataBtnUI(rechargeId)
  101. local buycount, totalcount = InfoManager.countInfo:GetLimitAndTotalCountByRechargeId(rechargeId)
  102. if buycount <= 0 then
  103. GUI:Text_setString(self.view.BuyBtn, "已购买")
  104. end
  105. end
  106. function this:ShowItem(GiftTbl)
  107. local careerId = SL:GetMetaValue(EMetaVarGetKey.JOB)
  108. local index = 1
  109. for i, award in pairs(GiftTbl.item) do
  110. --首充道具
  111. if award[1] == nil or (careerId ~= nil and careerId == award[1]) then
  112. index = index + 1
  113. local itemId = award[2]
  114. local count = award[3]
  115. local data = {
  116. width = "80",
  117. height = "80",
  118. itemid = itemId,
  119. mfixsize = "80,80",
  120. mscale = "40,40,40",
  121. tips = "1",
  122. itemcustomcount = count
  123. }
  124. if self.ItemList[index] then
  125. GUI:Item_UpdataData(self.ItemList[index], data)
  126. else
  127. local item = GUI:Item_Create(self.view.gridview2, data)
  128. self.ItemList[index] = item
  129. end
  130. GUI:AddOnClickEvent(self.ItemList[index], self, function()
  131. SL:OpenTips(nil, itemId)
  132. end)
  133. end
  134. end
  135. end
  136. function this:ShowMountModel(Tbl)
  137. if not Tbl then
  138. return
  139. end
  140. local careerId = SL:GetMetaValue(EMetaVarGetKey.JOB)
  141. local scale = 1
  142. local mrotate = "0,0,0"
  143. local x = "0"
  144. local y = "0"
  145. local z = "0"
  146. local path = ""
  147. local ani = ""
  148. local rX = 1
  149. local rY = 0
  150. local rZ = 0
  151. for _, model1 in pairs(Tbl.model) do
  152. if tonumber(model1[2]) == careerId then
  153. path = model1[1]
  154. --GUI:Text_setString(self.view.ShowInfoText, tostring(model1[2]))
  155. end
  156. end
  157. for _, model2 in pairs(Tbl.modelCondition) do
  158. if tonumber(model2[5]) == careerId then
  159. x = model2[1]
  160. y = model2[2]
  161. z = model2[3]
  162. scale = tonumber(model2[4])
  163. end
  164. end
  165. for _, model3 in pairs(Tbl.modelRevolve) do
  166. if tonumber(model3[4]) == careerId then
  167. --mrotate = model3[1] .. "," .. model3[2] .. "," .. model3[3]
  168. rX = tonumber(model3[1])
  169. rY = tonumber(model3[2])
  170. rZ = tonumber(model3[3])
  171. end
  172. end
  173. if Tbl.modelBehavior then
  174. for _, model4 in pairs(Tbl.modelBehavior) do
  175. if tonumber(model4[2]) == careerId then
  176. ani = model4[1]
  177. end
  178. end
  179. end
  180. if Tbl.tips then
  181. for _, tip in pairs(Tbl.tips) do
  182. if tonumber(tip[2]) == careerId then
  183. GUI:Text_setString(self.view.Texts, tostring(tip[1]))
  184. end
  185. end
  186. end
  187. local data = {
  188. mscale = 1 .. "," .. 1 .. "," .. 1,
  189. mrotate = mrotate,
  190. x = x,
  191. y = y,
  192. z = z,
  193. a = "00",
  194. src = path,
  195. ani = ani,
  196. }
  197. if self.cur_mount_model then
  198. GUI:Item_UpdataData(self.cur_mount_model, data)
  199. else
  200. self.cur_mount_model = GUI:Model_Create(self.view.Item_model, data)
  201. end
  202. GUI:setScale(self.cur_mount_model, scale / 10)
  203. GUI:setRotationSkewX(self.cur_mount_model, rX)
  204. GUI:setRotationSkewY(self.cur_mount_model, rY)
  205. GUI:setRotation(self.cur_mount_model, rZ)
  206. end
  207. function this:Close()
  208. SL:ShowMainPanel()
  209. for _, v in pairs(self.BtnList) do
  210. GUI:UIPanel_Close(nil, v)
  211. end
  212. self.BtnList = {}
  213. end
  214. return this