231 lines
6.7 KiB
Lua
231 lines
6.7 KiB
Lua
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 = {
|
||
|
||
[1] = {
|
||
icon = "a1",
|
||
wnd = ssrConstCfg.Box996,
|
||
name = "Box996",
|
||
}, -- 996盒子
|
||
[2] = {
|
||
icon = "a9",
|
||
wnd = ssrConstCfg.TradingBank,
|
||
name = "TradingBank",
|
||
}, -- 交易行
|
||
[3] = {
|
||
icon = "a2",
|
||
wnd = ssrConstCfg.StoreRecharge,
|
||
name = "StoreRecharge",
|
||
}, -- 充值中心
|
||
[4] = {
|
||
icon = "a4",
|
||
open = "KuangBaoOBJ_main",
|
||
name = "KuangBao",
|
||
}, -- 狂暴之力
|
||
[5] = {
|
||
icon = "a3",
|
||
open = "FuLiDaTingOBJ_main",
|
||
name = "FuLi",
|
||
}, -- 福利中心
|
||
[6] = {
|
||
icon = "6",
|
||
open = "ShouChongOBJ_main",
|
||
name = "ShouChong",
|
||
}, -- 首充
|
||
[7] = {
|
||
icon = "a6",
|
||
name = "Strategy",
|
||
client_open = "StrategyOBJ",
|
||
}, -- 游戏攻略
|
||
[8] = {
|
||
icon = "a7",
|
||
name = "Service",
|
||
}, -- 联系客服
|
||
[9] = {
|
||
icon = "a10",
|
||
open = "XianShiChongBangOBJ_main",
|
||
name = "XianShiChongBang",
|
||
}, -- 限时冲榜
|
||
[10] = {
|
||
icon = "a5",
|
||
open = "HuodongzhongxinOBJ_main",
|
||
name = "HuoDong",
|
||
}, -- 活动中心
|
||
|
||
}
|
||
|
||
|
||
|
||
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)
|
||
|
||
|
||
---* 绑定事件
|
||
self:EventBind()
|
||
self:createIcon()
|
||
end
|
||
end
|
||
end
|
||
|
||
|
||
--* 创建图标
|
||
function CreateTopIconOBJ:createIcon()
|
||
if GUI:Win_IsNull(self.ui.btn_switch) then
|
||
return
|
||
end
|
||
for i, v in ipairs(self.cfg) do
|
||
if v.icon then
|
||
local icon = string.format("icon_%s", i)
|
||
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)
|
||
|
||
--稳定红点 key:优先用 cfg.name,过渡期兼容下标
|
||
local redKey = "TopIcon_" .. (v.name or i)
|
||
|
||
GUI:addOnClickEvent(self.ui[icon], function()
|
||
if v.wnd then
|
||
ssrUIManager:OPEN(v.wnd, { redKey = redKey })
|
||
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)
|
||
SL:ScheduleOnce(function()
|
||
self:Action(self.ui[icon])
|
||
end, 0.1)
|
||
|
||
--注册到全局红点系统:作为聚合点,由子模块 register(parent=redKey) 决定亮灭
|
||
--偏移可在 cfg 中通过 redOffset = { x = ?, y = ? } 自定义;不设则取默认 {15,15}
|
||
if RedDotMgr and RedDotMgr.register then
|
||
local iconKey = icon
|
||
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)
|
||
|
||
GUI:addOnClickEvent(self.ui.top_btn, function()
|
||
local Visible_bool = GUI:getVisible(self.ui.btn_switch)
|
||
self:setShowCopyBtn(not Visible_bool)
|
||
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
|