CreateTopIconOBJ = {} CreateTopIconOBJ.__cname = "CreateTopIconOBJ" CreateTopIconOBJ.FindParent = 102 CreateTopIconOBJ.posX = ssrConstCfg.isWinMode == 2 and -600 or -750 CreateTopIconOBJ.posY = ssrConstCfg.isWinMode == 2 and -15 or -85 CreateTopIconOBJ.iconPath = "res/custom/top/" --* 开启跳动动画 CreateTopIconOBJ.openJump = true CreateTopIconOBJ.PCpos = { [0] = -600, [1] = -750, [2] = -800, [3] = -600, } CreateTopIconOBJ.cfg = {} CreateTopIconOBJ._redKeys = {} CreateTopIconOBJ.wndMap = { Box996 = ssrConstCfg.Box996, TradingBank = ssrConstCfg.TradingBank, StoreRecharge = ssrConstCfg.StoreRecharge, } function CreateTopIconOBJ:main() if MainMiniMap._ui then local parent = ssrConstCfg.isWinMode == 2 and MainMiniMap._ui["TOP_Node"] or GUI:Win_FindParent(102) if parent then GUI:removeAllChildren(parent) GUI:LoadExport(parent, "game/Tongyong/TopIconUI") self._parent = parent self.ui = GUI:ui_delegate(parent) GUI:setAnchorPoint(self.ui.Top_Node, 1.00, 0) GUI:setPosition(self.ui.Top_Node, self.posX, self.posY) GUI:addOnClickEvent(self.ui.top_btn, function() local Visible_bool = GUI:getVisible(self.ui.btn_switch) self:setShowCopyBtn(not Visible_bool) end) ---* 绑定事件 self:EventBind() self:createIcon() ssrMessage:SubLink(self.__cname .. "_refresh") end end end --* 创建图标 function CreateTopIconOBJ:createIcon() if not self.ui or GUI:Win_IsNull(self.ui.btn_switch) then return end self:clearIcon() for i, v in ipairs(self.cfg) do local icon = string.format("icon_%s", i) if v.icon then self.ui[icon] = GUI:Button_Create(self.ui.btn_switch, icon, 0, 0, string.format("%s/%s.png", self.iconPath, v.icon)) GUI:Win_SetParam(self.ui[icon], #self.cfg - i) elseif v.path then self.ui[icon] = GUI:Button_Create(self.ui.btn_switch, icon, 0, 0, v.path) GUI:Win_SetParam(self.ui[icon], #self.cfg - i) end if v.icon or v.path then --稳定红点 key:优先用 cfg.name,过渡期兼容下标 local redKey = "TopIcon_" .. (v.name or i) GUI:addOnClickEvent(self.ui[icon], function() if v.wnd then local wnd = type(v.wnd) == "string" and self.wndMap[v.wnd] or v.wnd if wnd then ssrUIManager:OPEN(wnd, { redKey = redKey }) end elseif v.open then Npc_dispatchex(nil, nil, nil, nil, SL:JsonEncode({ sync_obj = v.open, redKey = redKey, })) elseif v.client_open then if _G[v.client_open] and _G[v.client_open].main then _G[v.client_open]:main() end elseif v.link then ssrMessage:SubLink(v.link.link, v.link.cfg) end end) GUI:setOpacity(self.ui[icon], 0) local iconNode = self.ui[icon] SL:ScheduleOnce(function() if iconNode and GUI:Win_IsNotNull(iconNode) then self:Action(iconNode) end end, 0.1) --注册到全局红点系统:作为聚合点,由子模块 register(parent=redKey) 决定亮灭 --偏移可在 cfg 中通过 redOffset = { x = ?, y = ? } 自定义;不设则取默认 {15,15} if RedDotMgr and RedDotMgr.register then local iconKey = icon table.insert(self._redKeys, redKey) RedDotMgr:register(redKey, { target = function() return CreateTopIconOBJ.ui and CreateTopIconOBJ.ui[iconKey] end, offset = v.redOffset or { x = 25, y = 50 }, }) end end end GUI:UserUILayout(self.ui.btn_switch, { dir = 3, addDir = 2, interval = 0, gap = { x = 1 }, rownums = { 6, 2 }, sortfunc = function(lists) table.sort(lists, function(a, b) return GUI:Win_GetParam(a) > GUI:Win_GetParam(b) end) end }) local btn_pos = GUI:getContentSize(self.ui.top_btn) GUI:setPosition(self.ui.btn_switch, btn_pos.width - 40, btn_pos.height + 30) end function CreateTopIconOBJ:clearIcon() if RedDotMgr and RedDotMgr.unregister then for _, redKey in ipairs(self._redKeys or {}) do RedDotMgr:unregister(redKey) end end self._redKeys = {} if self.ui and GUI:Win_IsNotNull(self.ui.btn_switch) then GUI:removeAllChildren(self.ui.btn_switch) end end function CreateTopIconOBJ:refresh(arg1, arg2, arg3, data) self.cfg = data or {} if self.ui and GUI:Win_IsNotNull(self.ui.btn_switch) then self:createIcon() if RedDotMgr and RedDotMgr.refreshAll then RedDotMgr:refreshAll() end end end -- 设置顶部功能按钮的显示状态 -- @param bool: 是否显示 function CreateTopIconOBJ:setShowCopyBtn(bool) if bool then GUI:setVisible(self.ui.btn_switch, true) local all_icon = GUI:getChildren(self.ui.btn_switch) for i, v in ipairs(all_icon) do GUI:setOpacity(v, 0) SL:ScheduleOnce(function() self:Action(v) end, 0.1) end GUI:Timeline_RotateTo(self.ui.top_btn, 0, 0.1, nil) else GUI:setVisible(self.ui.btn_switch, false) GUI:Timeline_RotateTo(self.ui.top_btn, 180, 0.1, nil) end end --* 动画 function CreateTopIconOBJ:Action(parent) -- GUI:setVisible(self.ui.btn_switch, true) GUI:Timeline_FadeIn(parent, 0.5, function() -- if self.openJump then -- GUI:Timeline_Shake(parent, 0.5, 2, 2, nil) -- end end) end ---* PC端切换小地图调整顶部图标位置 function CreateTopIconOBJ:pcmoveTopIcon(status) if GUI:Win_IsNotNull(self.ui.Top_Node) then GUI:Timeline_StopAll(self.ui.Top_Node) local moveAction = GUI:ActionMoveTo(0.2, self.PCpos[status], -85) GUI:runAction(self.ui.Top_Node, moveAction) SL:ScheduleOnce(function() local parentPos = GUI:getPosition(self.ui.Top_Node) if parentPos.x ~= self.PCpos[status] then local moveAction = GUI:ActionMoveTo(0.2, self.PCpos[status], -85) GUI:runAction(self.ui.Top_Node, moveAction) end end, 0.2) end end ---* 注册事件 function CreateTopIconOBJ:EventBind() if ssrConstCfg.isWinMode == 1 then -- tab切换小地图 local function callback() local status = MainMiniMap.GetNextStatus() MainMiniMap.ChangeStatus(status) self:pcmoveTopIcon(status) end GUI:addKeyboardEvent("KEY_TAB", callback) end end return CreateTopIconOBJ