快捷栏的命令
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-05-03 16:05:00 |
👁️ 阅读: 7
根据浮生梦老师前端课程内容,快捷栏相关的命令主要涉及初始化显示、创建单元格以及设置可见性等功能。
以下是几个关键的函数和用法:
**1. 初始化快捷栏显示数量**
这个函数用于计算并设置当前显示的快捷栏数量(最大6个):
```lua
function MainProperty.InitQuickUseShow()
local showNum = 0
if MainProperty._ui.Panel_quick and GUI:getVisible(MainProperty._ui.Panel_quick) then
for i = 1, 6 do
local layout = MainProperty._ui[string.format("Panel_quick_use_%s", i)]
if layout and GUI:getVisible(layout) then
showNum = showNum + 1
end
end
end
SL:SetMetaValue("QUICK_USE_NUM", showNum)
end
```
**2. 创建快捷栏单元格**
创建快捷栏的基本结构,包括背景和节点:
```lua
function MainProperty.CreateQuickUseCell(parent)
if not parent then
return
end
local Panel_cell = GUI:Layout_Create(parent, "Panel_cell", 0, 0, 52, 50)
GUI:setTouchEnabled(Panel_cell, true)
local Image_bg = GUI:Image_Create(Panel_cell, "Image_bg", 26, 25, "res/public/1900012391.png")
GUI:setAnchorPoint(Image_bg, 0.5, 0.5)
GUI:setContentSize(Image_bg, 49, 49)
local Node_item = GUI:Node_Create(Panel_cell, "Node_item", 26, 25)
local Panel_quick = GUI:Layout_Create(Panel_cell, "Panel_quick", 0, 0, 52, 50)
GUI:setTouchEnabled(Panel_quick, true)
GUI:setSwallowTouches(Panel_quick, false)
end
```
**3. 相关GUI函数说明**
- `GUI:getVisible(widget)` - 检查控件是否可见
- `GUI:setVisible(widget, value)` - 设置控件可见性
- `GUI:Layout_Create(parent, id, x, y, width, height)` - 创建布局控件
- `GUI:Image_Create(parent, id, x, y, imagePath)` - 创建图片控件
- `GUI:Node_Create(parent, id, x, y)` - 创建节点
- `GUI:setTouchEnabled(widget, enabled)` - 设置触摸启用
- `GUI:setSwallowTouches(widget, enabled)` - 设置是否吞噬触摸
- `GUI:setAnchorPoint(widget, x, y)` - 设置锚点
- `GUI:setContentSize(widget, width, height)` - 设置控件大小
**4. 元数据操作**
- `SL:SetMetaValue("QUICK_USE_NUM", value)` - 设置快捷栏数量到元数据
- `SL:GetMetaValue("GAME_DATA", "PCPropertyNotAdapet")` - 获取适配设置
这些命令主要用于管理游戏界面中的快捷栏布局和状态,包括创建单元格、控制显示数量以及与其他界面元素的适配处理。
← 返回问答库