156 lines
4.2 KiB
Lua
156 lines
4.2 KiB
Lua
KuangBaoOBJ = {}
|
||
|
||
KuangBaoOBJ.__cname = "KuangBaoOBJ"
|
||
|
||
-- 配置文件
|
||
KuangBaoOBJ.cfg = {}
|
||
|
||
|
||
function KuangBaoOBJ: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/KuangBaoUI")
|
||
|
||
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:EventBind()
|
||
|
||
self:updata()
|
||
|
||
--本模块未继承 Up_BaseClassOBJ,手动通知红点重算(self.cfg 已填充)
|
||
if RedDotMgr and RedDotMgr.refreshByOwner then
|
||
RedDotMgr:refreshByOwner(self.__cname)
|
||
end
|
||
end
|
||
|
||
function KuangBaoOBJ:updata()
|
||
local yuanbao_num = tonumber(SL:Get_MONEY(ssrConstCfg.Money["元宝"])) or 0
|
||
|
||
|
||
|
||
if hk.checkcontion({ { "检测称号", self.cfg.title } }) then
|
||
GUI:setVisible(self.ui.Button, false)
|
||
GUI:setVisible(self.ui.y_open, true)
|
||
|
||
--已开通:主动清掉上次可能贴过的红点
|
||
RedDotMgr.detachDot(self.ui.Button)
|
||
else
|
||
GUI:setVisible(self.ui.Button, true)
|
||
GUI:setVisible(self.ui.y_open, false)
|
||
GUI:addOnClickEvent(self.ui.Button, function()
|
||
ssrMessage:SubLink("KuangBaoOBJ_up")
|
||
end)
|
||
|
||
if yuanbao_num >= 100 then
|
||
RedDotMgr.attachDot(self.ui.Button, { x = 200, y = 40 })
|
||
end
|
||
end
|
||
|
||
|
||
|
||
|
||
|
||
|
||
---* 绑定事件
|
||
self:EventBind()
|
||
|
||
self:reddot()
|
||
end
|
||
|
||
function KuangBaoOBJ:reddot()
|
||
if GUI:Win_IsNotNull(self.ui.button_red) then
|
||
GUI:removeFromParent(self.ui.button_red)
|
||
end
|
||
if hk.checkcontion(self.check) then
|
||
return
|
||
elseif hk.checkcontion(self.cfg.xh) then
|
||
local button_size = GUI:getContentSize(self.ui.Button)
|
||
self.ui.button_red = GUI:Image_Create(self.ui.Button, "button_red", button_size.width - 30,
|
||
button_size.height - 15, "res/public/btn_npcfh_04.png")
|
||
end
|
||
end
|
||
|
||
------------------------网络消息------------------------
|
||
|
||
|
||
|
||
------------------------注册事件------------------------
|
||
function KuangBaoOBJ:EventBind()
|
||
local function KuangBaoOBJ_titleReload(data)
|
||
if data.oper == 2 then
|
||
if GUI:Win_IsNotNull(self._parent) then
|
||
self:updata()
|
||
end
|
||
end
|
||
end
|
||
SL:RegisterLUAEvent(LUA_EVENT_TITLE_REFRESH, self.__cname, KuangBaoOBJ_titleReload)
|
||
|
||
--关闭窗口
|
||
SL:RegisterLUAEvent(LUA_EVENT_CLOSEWIN, self.__cname, function(widgetName)
|
||
self:OnClose(widgetName)
|
||
end)
|
||
end
|
||
|
||
--关闭窗口
|
||
function KuangBaoOBJ:OnClose(widgetName)
|
||
if widgetName == self.__cname then
|
||
self:UnRegisterEvent()
|
||
end
|
||
end
|
||
|
||
function KuangBaoOBJ:UnRegisterEvent()
|
||
SL:UnRegisterLUAEvent(LUA_EVENT_TITLE_REFRESH, self.__cname)
|
||
SL:UnRegisterLUAEvent(LUA_EVENT_CLOSEWIN, self.__cname)
|
||
end
|
||
|
||
--注册到全局红点系统:未获得狂暴称号 且 元宝满足开通阈 → 顶部狂暴图标亮
|
||
--watchTitle = true 明确声明需要称号变化(LUA_EVENT_TITLE_REFRESH)时重算
|
||
--target 返回 nil 表示仅作为逻辑叶子节点供顶部图标聚合
|
||
if RedDotMgr and RedDotMgr.register then
|
||
RedDotMgr:register("FuLi_KuangBao", {
|
||
owner = "KuangBaoOBJ",
|
||
parent = "TopIcon_KuangBao",
|
||
target = function() return nil end,
|
||
watchTitle = true,
|
||
check = function()
|
||
local cfg = KuangBaoOBJ.cfg
|
||
if not cfg or not cfg.title then
|
||
return false
|
||
end
|
||
--已获得称号 → 不亮
|
||
if hk.checkcontion({ { "检测称号", cfg.title } }) then
|
||
return false
|
||
end
|
||
--元宝达阈 → 亮
|
||
local yuanbao_num = tonumber(SL:Get_MONEY(ssrConstCfg.Money["元宝"])) or 0
|
||
return yuanbao_num >= 100
|
||
end,
|
||
})
|
||
end
|
||
|
||
return KuangBaoOBJ
|