local TopIcon = {}
TopIcon.__cname = "TopIcon"
TopIcon.eventName = "图标配置"
TopIcon.IocnSaate = true
TopIcon.config = ssrRequireCsvCfg("cfg_top_icon")
TopIcon.time = 0
TopIcon.Switch = false
--顶部按钮配置
local top_but_cfg = {
["101"] = {wnd = ssrObjCfg.ChongZhiZhongXin},
["102"] = {wnd = ssrConstCfg.Box996},
["103"] = {wnd = ssrConstCfg.TradingBank},
["104"] = {wnd = ssrObjCfg.HuoDongDaTing}, --活动大厅
["105"] = {wnd = ssrObjCfg.FuLiDaTing}, --福利大厅
["106"] = {wnd = ssrObjCfg.YouXiGongLve}, --游戏攻略
["107"] = {wnd = ssrObjCfg.ShiJieDiTu}, --世界地图
["108"] = {wnd = ssrObjCfg.KuangBao}, --狂暴之力
["109"] = {wnd = ssrObjCfg.NiuMaQiYuLu}, --牛马奇遇录
["110"] = {wnd = ssrObjCfg.NiuMaNiXi}, --牛马逆袭
["111"] = {wnd = ssrObjCfg.NiuMaZanZhu}, --牛马赞助
["112"] = {wnd = ssrObjCfg.TeQuan}, --解绑特权
["113"] = {wnd = ssrObjCfg.ShouChong}, --首充
["114"] = {wnd = ssrObjCfg.MeiRiChongZhi}, --日冲图标
}
--右侧按钮配置
local right_icon_cfg = {
["btn_icon_1"] = {1, x = 0, y = 170, icon = "1900013012", wnd = ssrConstCfg.SkillSetting}, --技能
["btn_icon_2"] = {2, x = 70, y = 170, icon = "1900013014", wnd = ssrConstCfg.Team}, --组队
["btn_icon_3"] = {3, x = 140, y = 170, icon = "1900013013", wnd = ssrConstCfg.Guild}, --行会
["btn_icon_4"] = {4, x = 0, y = 90, icon = "1900013019", wnd = ssrConstCfg.Auction}, --拍卖行
--["btn_icon_5"] = {5, x = 70, y = 90, icon = "jiaoyihang", wnd = ssrConstCfg.TradingBank}, --交易行
--["btn_icon_6"] = {6, x = 140, y = 90, icon = "1900013015", wnd = ssrConstCfg.Trade}, --交易
--["btn_icon_7"] = {7, x = 0, y = 10, icon = "1900012583", wnd = ssrConstCfg.Friend}, --好友
["btn_icon_8"] = {8, x = 70, y = 90, icon = "1900013017", wnd = ssrConstCfg.Setting}, --设置
["btn_icon_9"] = {9, x = 140, y = 90, icon = "1900013018", wnd = ssrConstCfg.ExitToRole}, --退出
}
-----------------------------------------------------------------
-----------------------↓↓↓↓ 顶部功能按钮 ↓↓↓↓-----------------------
-----------------------------------------------------------------
local handle
if ssrConstCfg.client_type == 1 then
TopIcon.top_position_hide = {x=-60,y=-5}
TopIcon.top_position_show = {x=-720,y=-5}
else
TopIcon.top_position_hide = {x=-60,y=0}
TopIcon.top_position_show = {x=-750,y=0}
end
function TopIcon:setShowCopyBtn(bool)
local function visible()
if self.icon_is_show then
GUI:Timeline_EaseSineIn_MoveTo(self.top_layout, self.top_position_hide,0.1)
else
GUI:Timeline_EaseSineIn_MoveTo(self.top_layout, self.top_position_show,0.1)
end
end
if bool then
if self.icon_is_show then
GUI:Timeline_RotateTo(self.top_btn,180,0.1,visible)
else
GUI:Timeline_RotateTo(self.top_btn,0,0.1,visible)
end
else
visible()
end
end
--配置顶部Icon
function TopIcon:createTopIcon(data)
local Node_x,Node_y = 0,0
local state = SL:GetMetaValue("CURRENT_OPERMODE") -- 1为端游 2为手游
if state == 1 then
Node_x, Node_y = -150,0
else
Node_x, Node_y = -183,27
end
--点击按钮 查找对应界面 并打打开
local function Click(var)
var = tostring(var)
for key, value in pairs(top_but_cfg) do
if var == key then
if value.wnd ~= nil then
GUI:Win_CloseAll()
ssrUIManager:OPEN(value.wnd)
end
end
end
end
--绘制图标
local function AddIcon()
local TopIconNode_look = GUI:GetWindow( MainMiniMap._parent, "TopIconLayout")
if TopIconNode_look then
GUI:removeFromParent(TopIconNode_look) --将传入控件从父节点上移除
end
TopIconNode_look = GUI:Layout_Create(MainMiniMap._parent, "TopIconLayout", Node_x, Node_y, 550, 300)
self.TopIconNode_look = TopIconNode_look
local TopIconNode_1 = GUI:Layout_Create(TopIconNode_look, "TopIconNode_1", 0, 0, 550, 300)
local TopIconNode_2 = GUI:Layout_Create(TopIconNode_look, "TopIconNode_2", 0, 0, 550, 300)
GUI:setAnchorPoint(TopIconNode_1, 1, 1)
GUI:setAnchorPoint(TopIconNode_2, 1, 1)
self.TopIconNode_1 = TopIconNode_1
self.TopIconNode_2 = TopIconNode_2
if TopIconNode_1 then
for i, v in ipairs(data) do
if i >= 1 and i <= 6 then
local x,y = 0,0
for j, k in ipairs(self.config) do
if v == k.id then
x,y = 475+(1-i)*70, 230
--local buttonName = "Button"..k.id
--SL:Print("绘制"..k.ico)
local _Handle = GUI:Button_Create(TopIconNode_1, k.id , x, y, "res/custom/topIcon/".. k.ico .."")
GUI:addOnClickEvent(_Handle,function()
Click(k.id)
end)
if k.effect ~= nil then
local pos = GUI:getContentSize(_Handle)
local _EffectHandle = GUI:Effect_Create(_Handle, "effect"..i, pos.width/2,pos.height/2, 0, k.effect , 0, 0, 3, 1)
if _EffectHandle then
GUI:setScale(_EffectHandle, 1)
end
end
end
end
elseif i >= 7 then
local x,y = 0,0
for j, k in ipairs(self.config) do
if v == k.id then
x,y = 475+(1-i+5)*70, 160
--local buttonName = "Button"..k.id
--SL:Print("绘制"..k.ico)
local _Handle = GUI:Button_Create(TopIconNode_1, k.id , x, y, "res/custom/topIcon/".. k.ico .."")
GUI:addOnClickEvent(_Handle,function()
Click(k.id)
end)
if k.effect ~= nil then
local pos = GUI:getContentSize(_Handle)
local _EffectHandle = GUI:Effect_Create(_Handle, "effect"..i, pos.width/2 + k.effect[2],pos.height/2 + k.effect[3], 0, k.effect[1] , 0, 0, 3, 1)
if _EffectHandle then
GUI:setScale(_EffectHandle, k.effect[4])
end
end
end
end
end
end
end
local _Handle1 = GUI:Button_Create(TopIconNode_2, "101" , 475, 230, "res/custom/topIcon/001.png")
GUI:addOnClickEvent(_Handle1,function()
Click(101)
end)
local _Handle2 = GUI:Button_Create(TopIconNode_2, "107" , 410, 230, "res/custom/topIcon/008.png")
GUI:addOnClickEvent(_Handle2,function()
Click(107)
end)
GUI:runAction(TopIconNode_2, GUI:ActionScaleTo(0, 0.001)) --将第二个控件缩小
end
--设置缩放动画
-- 设置图标切换动画效果的内部函数
local function SetAnimation()
-- 获取当前操作模式:1为端游模式,2为手游模式
local Newstate = SL:GetMetaValue("CURRENT_OPERMODE") -- 1为端游 2为手游
-- 初始化新的位置坐标变量
local New_x, New_y = 0 ,0
-- 根据不同的操作模式设置不同的目标位置坐标
if Newstate == 1 then
-- 端游模式下的目标位置
New_x, New_y = -150,0
else
-- 手游模式下的目标位置(稍微偏移以适应手游界面)
New_x, New_y = -153,-3
end
-- 根据当前图标状态执行不同的动画效果
if self.IocnSaate then
-- 当前显示第一套图标时,对TopIconNode_1执行动画
GUI:runAction(self.TopIconNode_1,
GUI:ActionSequence( -- 创建动作序列
GUI:ActionMoveTo(0, 100, 200), -- 瞬间移动到中间位置(100,200)
GUI:ActionSpawn( -- 同时执行多个动作
GUI:ActionScaleTo(0, 1), -- 瞬间缩放到原始大小(1倍)
GUI:ActionEaseBackOut( -- 使用回弹缓动效果
GUI:ActionMoveTo(0.2, New_x+150, New_y) -- 0.2秒内移动到最终位置
)
)
))
else
-- 当前显示第二套图标时,对TopIconNode_2执行相同的动画
GUI:runAction(self.TopIconNode_2,
GUI:ActionSequence( -- 创建动作序列
GUI:ActionMoveTo(0, 100, 200), -- 瞬间移动到中间位置(100,200)
GUI:ActionSpawn( -- 同时执行多个动作
GUI:ActionScaleTo(0, 1), -- 瞬间缩放到原始大小(1倍)
GUI:ActionEaseBackOut( -- 使用回弹缓动效果
GUI:ActionMoveTo(0.2, New_x+150, New_y) -- 0.2秒内移动到最终位置
)
)
))
end
end
--绘制切换图标
-- 先移除已存在的切换按钮,避免重复创建
GUI:removeChildByName(MainMiniMap._parent,"Button_switch")
-- 创建图标切换按钮,位置相对于主图标位置偏移
-- Node_x-45: 水平向左偏移45像素
-- Node_y-107: 垂直向下偏移107像素
-- 使用"000.png"作为按钮图标
local Button_switch = GUI:Button_Create(MainMiniMap._parent, "Button_switch", Node_x-45, Node_y-107, "res/custom/topIcon/000.png")
-- 确保按钮创建成功后进行配置
if Button_switch then
-- 设置按钮的锚点为中心点(0.5, 0.5),便于旋转动画
GUI:setAnchorPoint(Button_switch, 0.5, 0.5)
-- 为切换按钮添加点击事件处理
GUI:addOnClickEvent(Button_switch, function()
-- 根据当前图标状态执行不同的切换逻辑
if self.IocnSaate then
-- 当前显示第一套图标,切换到第二套
self.IocnSaate = false
-- 按钮旋转180度,0.1秒完成,提供视觉反馈
GUI:Timeline_RotateTo(Button_switch,180,0.1)
-- 对第一套图标执行退出动画
GUI:runAction(self.TopIconNode_1,
GUI:ActionSequence( --多个动作顺序播放
GUI:ActionScaleTo(0.3, 0), --0.3秒缩放到0(消失效果)
GUI:CallFunc(SetAnimation) --调用SetAnimation函数执行进入动画
))
else
-- 当前显示第二套图标,切换到第一套
self.IocnSaate = true
-- 按钮旋转回0度,0.1秒完成
GUI:Timeline_RotateTo(Button_switch,0,0.1)
-- 对第二套图标执行退出动画
GUI:runAction(self.TopIconNode_2,
GUI:ActionSequence(
GUI:ActionScaleTo(0.3, 0), --0.3秒缩放到0(消失效果)
GUI:CallFunc(SetAnimation) --调用SetAnimation函数执行进入动画
))
end
end)
end
-- 调用AddIcon函数开始绘制图标
AddIcon()
end
--[[
@function AFKUpdate
@brief 更新AFK(挂机)按钮的显示状态
@note 根据当前挂机状态切换按钮图标和特效显示
]]
function TopIcon:AFKUpdate()
-- 检查当前是否处于挂机状态
if SL:GetMetaValue("BATTLE_IS_AFK") then
-- 挂机状态:加载激活状态的按钮图标
GUI:Button_loadTextureNormal(self.AFKbutton, "res/private/main/Skill/1900012709.png")
-- 显示挂机特效
if self.AFKeffect then
GUI:setVisible(self.AFKeffect, true)
end
else
-- 非挂机状态:加载默认状态的按钮图标
GUI:Button_loadTextureNormal(self.AFKbutton, "res/private/main/Skill/1900012708.png")
-- 隐藏挂机特效
if self.AFKeffect then
GUI:setVisible(self.AFKeffect, false)
end
end
end
--[[
@function StartAFK
@brief 切换AFK(挂机)状态
@note 根据当前状态启动或停止挂机功能
]]
function TopIcon:StartAFK()
-- 检查当前挂机状态并执行相反操作
if SL:GetMetaValue("BATTLE_IS_AFK") then
-- 当前正在挂机,执行停止挂机
SL:SetMetaValue("BATTLE_AFK_END")
else
-- 当前未挂机,执行开始挂机
SL:SetMetaValue("BATTLE_AFK_BEGIN")
end
end
--[[
@function createSkillBtn
@brief 创建技能按钮和功能按钮界面
@note 根据客户端类型(手游/端游)创建不同布局的UI按钮
]]
function TopIcon:createSkillBtn()
-- 手游模式 (client_type == 2)
if ssrConstCfg.client_type == 2 then
-- 获取右侧按钮容器(父节点109)
local parent = GUI:Win_FindParent(109)
if parent then
-- 清空容器中的所有子节点
GUI:removeAllChildren(parent)
-- 根据配置创建右侧图标按钮
for key, val in pairs(right_icon_cfg) do
handle = GUI:Button_Create(parent, key, val.x, val.y, "res/private/main/bottom/"..val.icon..".png")
GUI:addOnClickEvent(handle, function()
ssrUIManager:OPEN(val.wnd)
end)
end
end
-- 获取主要功能按钮容器(父节点107)
parent = GUI:Win_FindParent(107)
if parent then
GUI:removeAllChildren(parent)
-- 创建背包按钮
handle = GUI:Button_Create(parent, "10086",-65,60, "res/private/main/bottom/1900013011.png")
GUI:addOnClickEvent(handle, function()
ssrUIManager:OPEN(ssrConstCfg.Bag)
end)
-- 创建角色按钮
handle = GUI:Button_Create(parent, "1000",-135,60, "res/private/main/bottom/1900013010.png")
GUI:addOnClickEvent(handle, function()
ssrMessage:sendmsg(ssrNetMsgCfg.Public_Request,2)
end)
--------------- 挂机按钮组件 ------------------
-- 创建挂机按钮主体
self.AFKbutton = GUI:Button_Create(parent, "Button_AFK", -205, 60, "res/private/main/Skill/1900012708.png")
-- 创建挂机特效
self.AFKeffect = GUI:Effect_Create(parent, "effect_AFK", -211, 127, 0, 0)
-- 创建挂机按钮触摸区域
handle = GUI:Layout_Create(parent, "Layout_AFK", -205, 60, 60, 55, false)
-- 初始化挂机特效为隐藏状态
GUI:setVisible(self.AFKeffect,false)
-- 启用触摸事件
GUI:setTouchEnabled(handle,true)
GUI:setTouchEnabled(self.AFKbutton, true)
-- 设置按钮按下时的贴图
GUI:Button_loadTexturePressed(self.AFKbutton, "res/private/main/Skill/1900012709.png")
-- 为挂机按钮添加点击事件
GUI:addOnClickEvent(self.AFKbutton, function()
self:StartAFK()
end)
-- 为触摸区域添加点击事件
GUI:addOnClickEvent(handle, function()
self:StartAFK()
end)
-- 创建巡航按钮
handle = GUI:Button_Create(parent, "xh",-135,-4, "res/custom/XunHangGuaJi/icon_1.png")
GUI:addOnClickEvent(handle, function()
ssrMessage:sendmsg(ssrNetMsgCfg.XunHangGuaJi_OpenUI)
end)
-- 创建潜能按钮
local qianneng = GUI:Button_Create(parent, "qn",-205,-4, "res/private/main/Skill/btn_jxqn1.png")
self.qianneng = qianneng
GUI:addOnClickEvent(self.qianneng, function()
ssrMessage:sendmsg(ssrNetMsgCfg.JiXianQianNeng_Request)
end)
-- 创建宠物按钮
handle = GUI:Button_Create(parent, "zh",-205,-8, "res/custom/zdy/zyx_topbutton_11.png")
GUI:addOnClickEvent(handle, function()
ssrUIManager:OPEN(ssrConstCfg.Equip)
end)
-- 左上角任务相关按钮
-- 获取任务按钮容器(父节点110)
local taskParent = GUI:Win_FindParent(110)
if taskParent then
-- 检查是否已存在超级剧情按钮
local widgetObj = GUI:getChildByName(taskParent, "ChaoJiJuQing")
if not GUI:Win_IsNotNull(widgetObj) then
-- 创建超级剧情按钮
local Button = GUI:Button_Create(taskParent, "ChaoJiJuQing", 1.00, 0, "res/custom/public/task_right.png")
GUI:Button_loadTexturePressed(Button, "res/custom/public/task_right.png")
GUI:addOnClickEvent(Button, function()
ssrUIManager:OPEN(ssrObjCfg.ChaoJiJuQing, nil, true)
end)
-- 创建主线任务按钮
Button = GUI:Button_Create(taskParent, "ZhuXianRenWu", 101.00, 0, "res/custom/public/task_left.png")
GUI:Button_loadTexturePressed(Button, "res/custom/public/task_left.png")
GUI:addOnClickEvent(Button, function()
ssrMessage:sendmsg(ssrNetMsgCfg.ZhuXianRenWu_OpenUI)
end)
end
end
end
-- 端游模式 (client_type == 1)
elseif ssrConstCfg.client_type == 1 then
local parent = GUI:Win_FindParent(107)
if parent then
GUI:removeAllChildren(parent)
--------------- 挂机按钮组件(端游布局) ------------------
-- 创建挂机按钮(位置调整为端游适配)
self.AFKbutton = GUI:Button_Create(parent, "Button_AFK", -65, 10, "res/private/main/Skill/1900012708.png")
self.AFKeffect = GUI:Effect_Create(parent, "effect_AFK", -71, 77, 0, 0)
handle = GUI:Layout_Create(parent, "Layout_AFK", -65, 10, 60, 55, false)
GUI:setVisible(self.AFKeffect,false)
GUI:setTouchEnabled(handle,true)
GUI:setTouchEnabled(self.AFKbutton, true)
GUI:Button_loadTexturePressed(self.AFKbutton, "res/private/main/Skill/1900012709.png")
GUI:addOnClickEvent(self.AFKbutton, function()
self:StartAFK()
end)
GUI:addOnClickEvent(handle, function()
self:StartAFK()
end)
-- 注释掉的宠物按钮(备用代码)
--handle = GUI:Button_Create(parent, "zh",-65,150, "res/private/main/Skill/1900012709.png")
--GUI:addOnClickEvent(handle, function()
-- ssrMessage:sendmsg(ssrNetMsgCfg.XunHangGuaJi_OpenUI)
--end)
-- 创建巡航按钮(端游位置)
handle = GUI:Button_Create(parent, "xh",-65,80, "res/custom/XunHangGuaJi/icon_1.png")
GUI:addOnClickEvent(handle, function()
ssrMessage:sendmsg(ssrNetMsgCfg.XunHangGuaJi_OpenUI)
end)
-- 创建潜能按钮(端游位置)
local qianneng = GUI:Button_Create(parent, "qn",-65,-60, "res/private/main/Skill/btn_jxqn1.png")
self.qianneng = qianneng
GUI:addOnClickEvent(self.qianneng, function()
ssrMessage:sendmsg(ssrNetMsgCfg.JiXianQianNeng_Request)
end)
-- GM测试按钮(仅GM等级10可见)
local gmlevel = ssrDataPlayer:getGMLevel()
--SL:dump(gmlevel)
if gmlevel == 10 then
-- 创建测试按钮
handle = GUI:Button_Create(parent, "ceshi", -200.00, 10, "")
GUI:setContentSize(handle, 60, 36)
GUI:Button_setTitleText(handle, [[ ]])
GUI:Button_setTitleColor(handle, "#ffffff")
GUI:Button_setTitleFontSize(handle, 14)
GUI:Button_titleEnableOutline(handle, "#000000", 1)
GUI:addOnClickEvent(handle, function()
ssrUIManager:OPEN(ssrObjCfg.test)
end)
end
-- 左上角任务相关按钮(与手游相同)
--[[
@section 左上角任务相关按钮创建
@brief 在任务区域创建超级剧情和主线任务按钮
@note 使用防重复创建机制,确保按钮不会被重复添加
]]
-- 获取任务按钮的父容器(窗口ID: 110)
local taskParent = GUI:Win_FindParent(110)
if taskParent then
-- 检查是否已存在"ChaoJiJuQing"按钮,防止重复创建
local widgetObj = GUI:getChildByName(taskParent, "ChaoJiJuQing")
if not GUI:Win_IsNotNull(widgetObj) then
--[[
@button 超级剧情按钮
@position (1.00, 0) - 右侧位置
@icon task_right.png - 右箭头图标
]]
-- 创建超级剧情按钮
local Button = GUI:Button_Create(taskParent, "ChaoJiJuQing", 1.00, 0, "res/custom/public/task_right.png")
-- 设置按钮按下时的贴图(与正常状态相同)
GUI:Button_loadTexturePressed(Button, "res/custom/public/task_right.png")
-- 添加点击事件:打开超级剧情界面
GUI:addOnClickEvent(Button, function()
-- 第三个参数true表示强制打开
ssrUIManager:OPEN(ssrObjCfg.ChaoJiJuQing, nil, true)
end)
--[[
@button 主线任务按钮
@position (101.00, 0) - 左侧位置(相对于超级剧情按钮)
@icon task_left.png - 左箭头图标
]]
-- 创建主线任务按钮(复用Button变量)
Button = GUI:Button_Create(taskParent, "ZhuXianRenWu", 101.00, 0, "res/custom/public/task_left.png")
-- 设置按钮按下时的贴图
GUI:Button_loadTexturePressed(Button, "res/custom/public/task_left.png")
-- 添加点击事件:发送主线任务打开消息
GUI:addOnClickEvent(Button, function()
ssrMessage:sendmsg(ssrNetMsgCfg.ZhuXianRenWu_OpenUI)
end)
end
end
end
end
end
--------------------------- 注册事件 -----------------------------
function TopIcon:RegisterEvent()
--自动挂机
SL:RegisterLUAEvent(LUA_EVENT_AFKBEGIN, self.eventName, function()
self:AFKUpdate()
end)
--自动挂机结束
SL:RegisterLUAEvent(LUA_EVENT_AFKEND, self.eventName, function()
self:AFKUpdate()
end)
end
-------------------------网络消息---------------------------
--同步数据
function TopIcon:UpdateIcon(arg1,arg2,arg3,data)
if data[1] == 1 then
GUI:Button_loadTextureNormal(self.qianneng, "res/private/main/Skill/btn_jxqn2.png")
else
GUI:Button_loadTextureNormal(self.qianneng, "res/private/main/Skill/btn_jxqn1.png")
end
local itemText = GUI:Text_Create(self.qianneng, "qndjs", 15, 15, 18, "#FF0000", "倒计旄1�7")
GUI:Text_COUNTDOWN(itemText,30, function()
self.time = 0
GUI:removeAllChildren(self.qianneng)
end)
end
-- "<var>" = {
-- 1 = {
-- 1 = 101
-- 2 = 102
-- 3 = 103
-- 4 = 104
-- 5 = 105
-- 6 = 106
-- 7 = 107
-- 8 = 108
-- 9 = 109
-- 10 = 110
-- 11 = 111
-- 12 = 112
-- 13 = 113
-- }
--同步数据
function TopIcon:SyncResponse(arg1,arg2,arg3,data)
--SL:ScheduleOnce(function ()
-- self:createTopIcon()
--end, 1.5)
-- SL:dump(data)
self:createTopIcon(data[1])
--SL:ScheduleOnce(function ()
self:createSkillBtn()
--end, 1.5)
self:RegisterEvent()
--SL:dump(data)
--self.data = data
end
return TopIcon