我需要创建一个物品框怎么创建
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-03-09 21:08:42 |
👁️ 阅读: 22
在996引擎中创建物品框可以使用`GUI:ItemShow_Create`函数。根据浮生梦老师前端课程内容,这里有几种创建方式:
## 1. 基本物品框创建
```lua
-- 先创建父节点
local parent = GUI:Win_Create("GMMain", 0, 0, 0, 0, false, false, true, false, false, false, 1)
-- 创建物品框
local itemBox = GUI:ItemShow_Create(parent, "item_box_1", 100, 200, {})
```
## 2. 完整物品框示例(包含图标、数量、特效等)
```lua
-- 创建父容器
local parent = GUI:Win_Create("GMMain", 0, 0, 0, 0, false, false, true, false, false, false, 1)
-- 创建物品框背景面板
local Panel_bg = GUI:Widget_Create(parent, "Panel_bg", 100, 100, 60, 60)
-- 创建特效层(分前后)
local Node_sfx_under = GUI:Node_Create(Panel_bg, "Node_sfx_under", 30, 30)
GUI:setAnchorPoint(Node_sfx_under, 0.50, 0.50)
-- 创建物品图标按钮
local Button_icon = GUI:Button_Create(Panel_bg, "Button_icon", 30, 30, "res/private/gui_edit/Button_Normal.png")
GUI:setContentSize(Button_icon, 50, 50)
GUI:setIgnoreContentAdaptWithSize(Button_icon, false)
GUI:Button_setTitleText(Button_icon, "")
GUI:setAnchorPoint(Button_icon, 0.50, 0.50)
-- 创建物品数量文本
local Text_count = GUI:Text_Create(Panel_bg, "Text_count", 57, 11, 15, "#ffffff", "1000")
GUI:setAnchorPoint(Text_count, 1.00, 0.50)
GUI:Text_enableOutline(Text_count, "#000000", 1)
-- 创建强化等级文本
local Text_star_lv = GUI:Text_Create(Panel_bg, "Text_star_lv", 4, 58, 18, "#efad21", "0")
GUI:setAnchorPoint(Text_star_lv, 0.00, 1.00)
GUI:Text_enableOutline(Text_star_lv, "#111111", 1)
-- 创建额外信息面板
local Panel_extra = GUI:Layout_Create(Panel_bg, "Panel_extra", 30, 30, 60, 60, false)
```
## 3. 物品放入框(可拖拽放置)
```lua
local parent = GUI:Win_Create("GMMain", 0, 0, 0, 0, false, false, true, false, false, false, 1)
-- 创建物品放入框
local itemBox = GUI:ItemBox_Create(parent, "item_box_1", 100, 200,
"res/public/1900000610.png", -- 底图
1, -- 放置框唯一ID
"*" -- 允许所有类型的物品放入
)
```
## 4. 物品框设置数据
```lua
-- 创建物品框并设置数据
local setData = {
itemId = 1001, -- 物品ID
count = 5, -- 数量
quality = 4, -- 品质
showCount = true, -- 显示数量
showQuality = true -- 显示品质边框
}
local itemBox = GUI:ItemShow_Create(parent, "item_box_2", 150, 250, setData)
```
## 函数参数说明:
- **GUI:ItemShow_Create(parent, ID, x, y, setData)**
- `parent`: 父节点对象
- `ID`: 唯一标识符
- `x, y`: 坐标位置
- `setData`: 物品配置数据表
- **GUI:ItemBox_Create(parent, ID, x, y, img, boxindex, stdmode)**
- `img`: 放置框底图资源路径
- `boxindex`: 放置框唯一ID
- `stdmode`: 允许的物品类型("*"所有、单个数字、多个用table)
## 使用建议:
1. 物品框通常需要设置锚点为中心点:`GUI:setAnchorPoint(widget, 0.5, 0.5)`
2. 图标按钮可以设置缩放效果:`GUI:Button_setZoomScale(button, -0.1)`
3. 记得检查节点是否为空:`if not GUI:Win_IsNull(widget) then ... end`
如果需要更复杂的物品框功能(如拖拽、特效、状态变化),可以参考开源layout中的Item类实现。
← 返回问答库