KLMountPreferencePanel.lua 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. ---@class KLMountPreferencePanel:UIKmlLuaPanelBase
  2. ---@field view KLMountPreferencePanelView
  3. local KLMountPreferencePanel = class(UIKmlLuaPanelBase)
  4. local this = KLMountPreferencePanel
  5. function this:AsyncLoadUI()
  6. end
  7. ---创建时调用一次
  8. function this:Init()
  9. end
  10. ---注册UI事件和服务器消息
  11. function this:RegistEvents()
  12. GUI:AddOnClickEvent(self.view.CloseBtn, self, self.CloseBtnOnClick)
  13. GUI:AddOnClickEvent(self.view.BuyBtn, self, self.BuyBtnOnClick)
  14. GUI:AddOnClickEvent(self.view.TipsBtn, self, self.TipsBtnOnClick)
  15. SL:RegisterLUAEvent(LUA_EVENT_MOUNT_PRE_COUNT_RECHARGE_CHANGE, self.LUA_EVENT_MOUNT_PRE_COUNT_RECHARGE_CHANGE, self)
  16. end
  17. function this:TipsBtnOnClick()
  18. local PanelTbl = SL:GetConfig("cfg_recharge_singleItem", self.rechargeId)
  19. SL:OpenTips(nil, PanelTbl.item[1])
  20. end
  21. function this:LUA_EVENT_MOUNT_PRE_COUNT_RECHARGE_CHANGE(_, data)
  22. if data then
  23. local buycount, totalcount = InfoManager.countInfo:GetLimitAndTotalCountByRechargeId(tonumber(self.rechargeId))
  24. if buycount <= 0 then
  25. GUI:Button_setTitleText(self.view.BuyBtn, "已购买")
  26. local topPanel = GUI:GetUI("dev/ui/MainUI/Panel/KLUISystemTop/KLUISystemTopPanel")
  27. if topPanel then
  28. topPanel:Refresh()
  29. end
  30. end
  31. end
  32. end
  33. function this:BuyBtnOnClick()
  34. if InfoManager.mountPreferenceInfo.endTime - Time.GetServerTime() <= 0 then
  35. SL:TipMessage( SL:GetConfig('cfg_string', 477).text, 1, NoticeType.NoticeMid )
  36. return
  37. end
  38. if self.rechargeId then
  39. local rechargeTbl = SL:GetConfig("cfg_recharge", self.rechargeId)
  40. local buycount, totalcount = InfoManager.countInfo:GetLimitAndTotalCountByRechargeId(tonumber(self.rechargeId))
  41. if buycount > 0 then
  42. GUIUtil.SDKPay(rechargeTbl, 1)
  43. end
  44. end
  45. end
  46. function this:CloseBtnOnClick()
  47. GUI:UIPanel_Close("dev/outui/MountPreference/Panel/KLMountPreference/KLMountPreferencePanel")
  48. end
  49. ---界面显示时调用一次
  50. function this:Show()
  51. end
  52. ---创建或者刷新界面数据时调用
  53. function this:Refresh()
  54. self.rechargeId = InfoManager.mountPreferenceInfo.rechargeId
  55. local rechargeTbl = SL:GetConfig("cfg_recharge", self.rechargeId)
  56. local PanelTbl = SL:GetConfig("cfg_recharge_singleItem", self.rechargeId)
  57. self:ShowMountModel(PanelTbl.showItem[2], PanelTbl.showItem[1])
  58. GUI:Button_setTitleText(self.view.BuyBtn, rechargeTbl.amount .. "元购买")
  59. if PanelTbl then
  60. if PanelTbl.btn then
  61. GUI:Image_loadTexture(self.view.BuyBtn, PanelTbl.btn, "Atlas/QJ5_UIMountPreferencePanel.spriteatlas")
  62. end
  63. if PanelTbl.bg then
  64. GUI:Image_loadTexture(self.view.bg, PanelTbl.bg)
  65. end
  66. if PanelTbl.checkBtn then
  67. GUI:Image_loadTexture(self.view.TipsBtn, PanelTbl.checkBtn, "Atlas/QJ5_UIMountPreferencePanel.spriteatlas")
  68. end
  69. if PanelTbl.orgPrice then
  70. GUI:Text_setString(self.view.OriginalPriceText, "商城原价:" .. PanelTbl.orgPrice .. "元")
  71. end
  72. if PanelTbl.profit then
  73. GUI:Image_loadTexture(self.view.TopImage, PanelTbl.profit, "Atlas/QJ5_UIMountPreferencePanel.spriteatlas")
  74. end
  75. end
  76. self.countdown = InfoManager.mountPreferenceInfo.endTime
  77. self.timer = SL:Schedule(self.timer, 0, 1, self.countdown, function()
  78. local t = self.countdown - Time.GetServerTime()
  79. self:tick(t // 1000)
  80. end)
  81. end
  82. function this:tick(t)
  83. if t >= 0 then
  84. GUI:Text_setString(self.view.TimerText, "活动剩余时间:" .. GUIUtil.FormatTimeHMS(t))
  85. else
  86. GUI:Text_setString(self.view.TimerText, "活动已结束")
  87. end
  88. end
  89. function this:ShowMountModel(ItemId, type)
  90. local tbl = nil
  91. local path = ""
  92. local behaviour_tbl = nil
  93. if type == 1 then
  94. tbl = SL:GetConfig("cfg_mount", ItemId, "id")
  95. local mount_model_tbl = SL:GetConfig("cfg_mount_model", tbl.mountId, "id")
  96. behaviour_tbl = SL:GetConfigMultiKeys("cfg_mount_behaviour", tbl.motion, 1, "id", "state")
  97. path = mount_model_tbl.path
  98. else
  99. local itemTbl = SL:GetConfig("cfg_item", ItemId)
  100. tbl = SL:GetConfig("cfg_model_charactor", itemTbl.shape[1])
  101. local mount_model_tbl = SL:GetConfig("cfg_mount_model", tbl.mountId, "id")
  102. path = mount_model_tbl.path
  103. tbl.scale2 = 100
  104. end
  105. local data = {
  106. mscale = tbl.scale2 * 1.5 .. "," .. tbl.scale2 * 1.5 .. "," .. tbl.scale2 * 1.5,
  107. mrotate = "0,130,0",
  108. x = "40",
  109. y = "-65",
  110. z = "-1000",
  111. a = "00",
  112. src = path,
  113. ani = behaviour_tbl.name,
  114. }
  115. if self.cur_mount_model then
  116. GUI:Item_UpdataData(self.cur_mount_model, data)
  117. else
  118. self.cur_mount_model = GUI:Model_Create(self.view.ItemModel, data)
  119. end
  120. end
  121. function this:Close()
  122. if self.timer then
  123. SL:UnSchedule(self.timer)
  124. end
  125. self.timer = nil
  126. SL:ShowMainPanel()
  127. end
  128. return this