自动巡航按钮想加到 快捷栏最后一个
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-06-07 22:13:06 |
👁️ 阅读: 6
要在快捷栏最后一个添加自动巡航按钮,可以按照以下步骤实现:
```lua
-- 1. 首先获取快捷栏面板
local Panel_quick = GUI:getChildByName(parentNode, "Panel_quick")
if GUI:Win_IsNull(Panel_quick) then
-- 如果快捷栏不存在,需要先创建
Panel_quick = GUI:Layout_Create(parentNode, "Panel_quick", 250, 150, 440, 55, false)
GUI:setAnchorPoint(Panel_quick, 0.50, 0.00)
GUI:setTouchEnabled(Panel_quick, false)
end
-- 2. 获取快捷栏中已有的按钮数量,确定新按钮位置
-- 假设快捷栏已有按钮存储在数组中
local quickButtons = {
{name = "Button_7", x = -56, y = 56},
{name = "Button_8", x = 38, y = 56},
{name = "Panel_quick_use_1", x = 97, y = 27}
}
-- 3. 计算最后一个按钮的位置(根据实际情况调整)
local lastButtonIndex = #quickButtons
local lastButton = quickButtons[lastButtonIndex]
local newButtonX = lastButton.x + 50 -- 向右偏移50像素
local newButtonY = lastButton.y
-- 4. 创建自动巡航按钮
local Button_auto_xunhang = GUI:Frames_Create(Panel_quick, "Button_auto_xunhang", newButtonX, newButtonY,
"res/custom/main/f3/", ".png", 1, 30, {count=30, speed=50, loop=-1, finishhide=0})
GUI:setAnchorPoint(Button_auto_xunhang, 0.50, 0.50)
GUI:setTouchEnabled(Button_auto_xunhang, true)
-- 5. 设置按钮点击事件
GUI:addOnClickEvent(Button_auto_xunhang, function()
-- 打开巡航界面
UIManager:OPEN(ObjCfg.Xunhang)
end)
-- 6. 如果需要特效,可以添加自动巡航特效节点
local nodeAutoXunhang = GUI:Node_Create(Panel_quick, "nodeAutoXunhang", newButtonX, newButtonY)
GUI:setVisible(nodeAutoXunhang, false)
GUI:Effect_Create(nodeAutoXunhang, "autoXunhangSfx", 24, -154, 0, 32781)
-- 7. 注册事件控制按钮显示/隐藏
SL:RegisterLUAEvent("AutoXunhangState", "MainProperty", function(bool)
GUI:setVisible(Button_auto_xunhang, bool)
end)
-- 8. 将新按钮添加到管理数组中
table.insert(quickButtons, {
name = "Button_auto_xunhang",
x = newButtonX,
y = newButtonY
})
```
**关键点说明:**
1. 使用`Frames_Create`创建帧动画按钮,与现有按钮风格一致
2. 按钮位置根据快捷栏中最后一个按钮的位置计算得出
3. 通过`addOnClickEvent`绑定巡航界面打开功能
4. 可以添加特效节点用于状态提示
5. 使用事件注册机制控制按钮的显示/隐藏状态
这样就能在快捷栏最后一个位置添加自动巡航按钮了。按钮的图片路径`res/custom/main/f3/`需要根据实际资源文件调整。
← 返回问答库