YueKaOBJ = Up_BaseClassOBJ:new() YueKaOBJ.__cname = "YueKaOBJ" YueKaOBJ.cfg = { price = 680, days = 30, } function YueKaOBJ:main(arg1, arg2, arg3, data) local parent = GUI:Win_Create(self.__cname, 0, 0, 0, 0, false, false, true, false) if data and data.npcid then GUI:Win_BindNPC(parent, data.npcid) end GUI:LoadExport(parent, "game/A/YueKaUI") self._parent = parent self.ui = GUI:ui_delegate(parent) ssrUIManager:OpenAlgin(self) GUI:addOnClickEvent(self.ui.bg_close, function() GUI:Win_Close(self._parent) end) GUI:addOnClickEvent(self.ui.btn_close, function() GUI:Win_Close(self._parent) end) if data and data.cfg then self.cfg = data.cfg end self.expireTime = self:getExpireTime(data) self:EventBind() self:updata() end function YueKaOBJ:getExpireTime(data) if data then local value = data.expireTime or data.endTime or data.time if value then return tonumber(value) or 0 end end local serverValue = nil serverValue = SL:GetMetaValue("SERVER_VALUE", "HUMAN(INT_月卡)") return tonumber(serverValue) or 0 end function YueKaOBJ:getRemainDays() local expireTime = tonumber(self.expireTime or 0) or 0 local nowTime = os.time() if expireTime <= nowTime then return 0 end return math.ceil((expireTime - nowTime) / 86400) end function YueKaOBJ:updata() local remainDays = self:getRemainDays() local isOpen = remainDays > 0 GUI:Text_setString(self.ui.status_text, string.format("%d天", remainDays)) -- GUI:setVisible(self.ui.tag_open, isOpen) if GUI:Win_IsNotNull(self.ui.CostItem_1) then GUI:removeFromParent(self.ui.CostItem_1) end self.ui.CostItem_1 = GUI:CostItem_Create(self.ui.img_bg, "CostItem_1", 460, 118, { itemId = 2, itemCount = self.cfg.price, itemScale = 0.6, titleText = "元宝", fontSize = 16, simplenum = 1 }) GUI:setAnchorPoint(self.ui.CostItem_1, 0.00, 0.50) GUI:setTouchEnabled(self.ui.CostItem_1, true) GUI:addOnClickEvent(self.ui.buy_btn, function() ssrMessage:SubLink("YueKaOBJ_buy") end) RedDotMgr.detachDot(self.ui.buy_btn) local yuanbaoNum = tonumber(SL:Get_MONEY(ssrConstCfg.Money["元宝"])) or 0 if not isOpen and yuanbaoNum >= (tonumber(self.cfg.price) or 680) then RedDotMgr.attachDot(self.ui.buy_btn, { x = 168, y = 48 }) end end function YueKaOBJ:EventBind() local function YueKaOBJ_Var_Change(data) if GUI:Win_IsNotNull(self._parent) then if data and data.key == "HUMAN(INT_月卡)" then self.expireTime = self:getExpireTime() self:updata() end end end SL:RegisterLUAEvent(LUA_EVENT_SERVER_VALUE_CHANGE, self.__cname, YueKaOBJ_Var_Change) SL:RegisterLUAEvent(LUA_EVENT_CLOSEWIN, self.__cname, function(widgetName) self:OnClose(widgetName) end) end function YueKaOBJ:OnClose(widgetName) if widgetName == self.__cname then self:UnRegisterEvent() end end function YueKaOBJ:UnRegisterEvent() SL:UnRegisterLUAEvent(LUA_EVENT_SERVER_VALUE_CHANGE, self.__cname) SL:UnRegisterLUAEvent(LUA_EVENT_CLOSEWIN, self.__cname) end if RedDotMgr and RedDotMgr.register then RedDotMgr:register("YueKa_Open", { owner = "YueKaOBJ", parent = "TopIcon_YueKa", target = function() return nil end, watchKeys = { "HUMAN(INT_月卡)" }, check = function() local expireTime = 0 if SL and SL.GetMetaValue then expireTime = tonumber(SL:GetMetaValue("SERVER_VALUE", "HUMAN(INT_月卡)")) or 0 end if expireTime > os.time() then return false end local yuanbaoNum = tonumber(SL:Get_MONEY(ssrConstCfg.Money["元宝"])) or 0 return yuanbaoNum >= 680 end, }) end return YueKaOBJ