123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- ---@class KLMountPreferencePanel:UIKmlLuaPanelBase
- ---@field view KLMountPreferencePanelView
- local KLMountPreferencePanel = class(UIKmlLuaPanelBase)
- local this = KLMountPreferencePanel
- function this:AsyncLoadUI()
- end
- ---创建时调用一次
- function this:Init()
- end
- ---注册UI事件和服务器消息
- function this:RegistEvents()
- GUI:AddOnClickEvent(self.view.CloseBtn, self, self.CloseBtnOnClick)
- GUI:AddOnClickEvent(self.view.BuyBtn, self, self.BuyBtnOnClick)
- GUI:AddOnClickEvent(self.view.TipsBtn, self, self.TipsBtnOnClick)
- SL:RegisterLUAEvent(LUA_EVENT_MOUNT_PRE_COUNT_RECHARGE_CHANGE, self.LUA_EVENT_MOUNT_PRE_COUNT_RECHARGE_CHANGE, self)
- end
- function this:TipsBtnOnClick()
- local PanelTbl = SL:GetConfig("cfg_recharge_singleItem", self.rechargeId)
- SL:OpenTips(nil, PanelTbl.item[1])
- end
- function this:LUA_EVENT_MOUNT_PRE_COUNT_RECHARGE_CHANGE(_, data)
- if data then
- local buycount, totalcount = InfoManager.countInfo:GetLimitAndTotalCountByRechargeId(tonumber(self.rechargeId))
- if buycount <= 0 then
- GUI:Button_setTitleText(self.view.BuyBtn, "已购买")
- local topPanel = GUI:GetUI("dev/ui/MainUI/Panel/KLUISystemTop/KLUISystemTopPanel")
- if topPanel then
- topPanel:Refresh()
- end
- end
- end
- end
- function this:BuyBtnOnClick()
- if InfoManager.mountPreferenceInfo.endTime - Time.GetServerTime() <= 0 then
- SL:TipMessage( SL:GetConfig('cfg_string', 477).text, 1, NoticeType.NoticeMid )
- return
- end
- if self.rechargeId then
- local rechargeTbl = SL:GetConfig("cfg_recharge", self.rechargeId)
- local buycount, totalcount = InfoManager.countInfo:GetLimitAndTotalCountByRechargeId(tonumber(self.rechargeId))
- if buycount > 0 then
- GUIUtil.SDKPay(rechargeTbl, 1)
- end
- end
- end
- function this:CloseBtnOnClick()
- GUI:UIPanel_Close("dev/outui/MountPreference/Panel/KLMountPreference/KLMountPreferencePanel")
- end
- ---界面显示时调用一次
- function this:Show()
- end
- ---创建或者刷新界面数据时调用
- function this:Refresh()
- self.rechargeId = InfoManager.mountPreferenceInfo.rechargeId
- local rechargeTbl = SL:GetConfig("cfg_recharge", self.rechargeId)
- local PanelTbl = SL:GetConfig("cfg_recharge_singleItem", self.rechargeId)
- self:ShowMountModel(PanelTbl.showItem[2], PanelTbl.showItem[1])
- GUI:Button_setTitleText(self.view.BuyBtn, rechargeTbl.amount .. "元购买")
- if PanelTbl then
- if PanelTbl.btn then
- GUI:Image_loadTexture(self.view.BuyBtn, PanelTbl.btn, "Atlas/QJ5_UIMountPreferencePanel.spriteatlas")
- end
- if PanelTbl.bg then
- GUI:Image_loadTexture(self.view.bg, PanelTbl.bg)
- end
- if PanelTbl.checkBtn then
- GUI:Image_loadTexture(self.view.TipsBtn, PanelTbl.checkBtn, "Atlas/QJ5_UIMountPreferencePanel.spriteatlas")
- end
- if PanelTbl.orgPrice then
- GUI:Text_setString(self.view.OriginalPriceText, "商城原价:" .. PanelTbl.orgPrice .. "元")
- end
- if PanelTbl.profit then
- GUI:Image_loadTexture(self.view.TopImage, PanelTbl.profit, "Atlas/QJ5_UIMountPreferencePanel.spriteatlas")
- end
- end
- self.countdown = InfoManager.mountPreferenceInfo.endTime
- self.timer = SL:Schedule(self.timer, 0, 1, self.countdown, function()
- local t = self.countdown - Time.GetServerTime()
- self:tick(t // 1000)
- end)
- end
- function this:tick(t)
- if t >= 0 then
- GUI:Text_setString(self.view.TimerText, "活动剩余时间:" .. GUIUtil.FormatTimeHMS(t))
- else
- GUI:Text_setString(self.view.TimerText, "活动已结束")
- end
- end
- function this:ShowMountModel(ItemId, type)
- local tbl = nil
- local path = ""
- local behaviour_tbl = nil
- if type == 1 then
- tbl = SL:GetConfig("cfg_mount", ItemId, "id")
- local mount_model_tbl = SL:GetConfig("cfg_mount_model", tbl.mountId, "id")
- behaviour_tbl = SL:GetConfigMultiKeys("cfg_mount_behaviour", tbl.motion, 1, "id", "state")
- path = mount_model_tbl.path
- else
- local itemTbl = SL:GetConfig("cfg_item", ItemId)
- tbl = SL:GetConfig("cfg_model_charactor", itemTbl.shape[1])
- local mount_model_tbl = SL:GetConfig("cfg_mount_model", tbl.mountId, "id")
- path = mount_model_tbl.path
- tbl.scale2 = 100
- end
- local data = {
- mscale = tbl.scale2 * 1.5 .. "," .. tbl.scale2 * 1.5 .. "," .. tbl.scale2 * 1.5,
- mrotate = "0,130,0",
- x = "40",
- y = "-65",
- z = "-1000",
- a = "00",
- src = path,
- ani = behaviour_tbl.name,
- }
- if self.cur_mount_model then
- GUI:Item_UpdataData(self.cur_mount_model, data)
- else
- self.cur_mount_model = GUI:Model_Create(self.view.ItemModel, data)
- end
- end
- function this:Close()
- if self.timer then
- SL:UnSchedule(self.timer)
- end
- self.timer = nil
- SL:ShowMainPanel()
- end
- return this
|