bayuMIR/client/dev/GUILayout/game/tongyong/ShouChongOBJ.lua
2026-06-12 02:32:15 +08:00

97 lines
2.9 KiB
Lua

ShouChongOBJ = Up_BaseClassOBJ:new()
ShouChongOBJ.__cname = "ShouChongOBJ"
-- UI文件
ShouChongOBJ.UIfile = "game/Tongyong/ShouChongUI"
-- 配置文件
ShouChongOBJ.cfg = {}
ShouChongOBJ.other = nil
ShouChongOBJ.npcid = nil
function ShouChongOBJ:updata()
local cfg = self.cfg[1]
self.drop = cfg.gives
self:setDropShow()
local recharge_num = tonumber(SL:Get_MONEY(ssrConstCfg.Money["真实充值"])) or 0
if tonumber(SL:GetMetaValue("SERVER_VALUE", "{7}")) == 0 then
GUI:setVisible(self.ui.open_img, false)
GUI:setVisible(self.ui.up_btn, true)
GUI:addOnClickEvent(self.ui.up_btn, function()
ssrMessage:SubLink(self.__cname .. "_up", { npcid = self.npcid })
end)
if recharge_num >= cfg.money then
RedDotMgr.attachDot(self.ui.up_btn, { x = 130, y = 40 })
end
else
GUI:setVisible(self.ui.open_img, true)
GUI:setVisible(self.ui.up_btn, false)
--已开通:主动清掉上次可能贴过的红点
RedDotMgr.detachDot(self.ui.up_btn)
end
end
---* 注册事件
function ShouChongOBJ:EventBind()
local function ShouChongOBJ_Var_Reload(data)
if GUI:Win_IsNotNull(self._parent) then
if data.key == "{7}" then
self:updata()
end
end
end
SL:RegisterLUAEvent(LUA_EVENT_SERVER_VALUE_CHANGE, self.__cname, ShouChongOBJ_Var_Reload)
--关闭窗口
SL:RegisterLUAEvent(LUA_EVENT_CLOSEWIN, self.__cname, function(widgetName)
self:OnClose(widgetName)
end)
end
--关闭窗口
function ShouChongOBJ:OnClose(widgetName)
if widgetName == self.__cname then
self:UnRegisterEvent()
end
end
function ShouChongOBJ:UnRegisterEvent()
SL:UnRegisterLUAEvent(LUA_EVENT_SERVER_VALUE_CHANGE, self.__cname)
SL:UnRegisterLUAEvent(LUA_EVENT_CLOSEWIN, self.__cname)
end
--注册到全局红点系统:未领取首充且真实充值已达阈 → 顶部首充图标亮
--首充面板内部 up_btn 的红点由 ShouChongOBJ:updata 自己管,这里不重复挂
--target 返回 nil 表示不需要自己的可视节点,仅作为逻辑叶子节点供顶部图标聚合
if RedDotMgr and RedDotMgr.register then
RedDotMgr:register("FuLi_ShouChong", {
owner = "ShouChongOBJ",
parent = "TopIcon_ShouChong",
target = function() return nil end,
watchKeys = { "{7}" },
check = function()
local cfg = ShouChongOBJ.cfg and ShouChongOBJ.cfg[1]
if not cfg then
return false
end
--已领取 → 不亮
if tonumber(SL:GetMetaValue("SERVER_VALUE", "{7}") or 0) ~= 0 then
return false
end
--未领取且充值达阈 → 亮
local recharge_num = tonumber(SL:Get_MONEY(ssrConstCfg.Money["真实充值"])) or 0
return recharge_num >= (cfg.money or 0)
end,
})
end
return ShouChongOBJ