local moshenyuanli = {}
local config = {
[1] = {name = "暴击原力Lv1", level = 1, count = 2, type1 = "物品", name1 = "魔神修炼石", value1 = 10, type2 = "货币", name2 = "金币", value2 = 10000, cur_attr_1 = 1, cur_attr_2 = 1, cur_attr_3 = 1, cur_attr_4 = 30},
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-03-06 16:16:15 |
👁️ 阅读: 9
看了你的代码,问题可能出在 `GUI:ItemShow_Create` 的参数上。根据浮生梦老师前端课程内容,`GUI:ItemShow_Create` 函数用于显示物品,但在你的代码中可能存在以下问题:
1. **物品ID参数问题**:`GUI:ItemShow_Create` 的 `index` 参数可能不是直接使用物品ID
2. **显示位置问题**:两个物品显示位置可能重叠
让我帮你修改一下显示物品的代码:
```lua
-- 修改这部分代码:
-- 如果有下一级配置,显示下一级需要的物品
if upgradeConfig and not GUI:Win_IsNull(ui.itemroom) then
local itemCount = SL:GetMetaValue("ITEM_COUNT", 10853) or 0
local needItemCount = upgradeConfig.value1 or 0
local goldColor = 255
if itemCount < needItemCount then
goldColor = 58
end
-- 显示魔神修炼石
local itemShow1 = GUI:ItemShow_Create(ui.itemroom, "ItemShow_1", 445, 160, {
index = 10853, -- 魔神修炼石ID
count = needItemCount,
look = true,
bgVisible = false,
color = goldColor
})
-- 检查是否创建成功
if GUI:Win_IsNull(itemShow1) then
SL:print("魔神修炼石物品显示创建失败")
else
SL:print("魔神修炼石物品显示创建成功")
end
-- 检查金币是否足够
local needGold = upgradeConfig.value2 or 0
local currentGold = SL:GetMetaValue("ITEM_COUNT", 1) or 0
goldColor = 255
if currentGold < needGold then
goldColor = 58
end
-- 显示金币
local itemShow2 = GUI:ItemShow_Create(ui.itemroom, "ItemShow_2", 535, 160, {
index = 1, -- 金币ID
count = needGold,
look = true,
bgVisible = false,
color = goldColor
})
-- 检查是否创建成功
if GUI:Win_IsNull(itemShow2) then
SL:print("金币物品显示创建失败")
else
SL:print("金币物品显示创建成功")
end
-- 调试输出
SL:print("当前等级: " .. tostring(currentLevel))
SL:print("需要升级到的等级: " .. tostring(upgradeLevel))
SL:print("当前魔神修炼石数量: " .. tostring(itemCount))
SL:print("需要魔神修炼石: " .. tostring(needItemCount))
SL:print("当前金币数量: " .. tostring(currentGold))
SL:print("需要金币: " .. tostring(needGold))
end
```
主要问题可能是:
1. **物品显示位置**:确保 `ui.itemroom` 这个父控件是正确创建和可见的
2. **坐标位置**:两个物品的坐标 (445,160) 和 (535,160) 可能太接近导致重叠
建议你:
1. 检查 `ui.itemroom` 控件是否为空
2. 尝试调整坐标位置,比如改为 (400,160) 和 (500,160)
3. 在创建物品前先清空容器:`GUI:removeAllChildren(ui.itemroom)`
如果还是不行,可以尝试使用更简单的测试:
```lua
-- 测试代码
local testItem = GUI:ItemShow_Create(ui.itemroom, "test_item", 400, 200, {
index = 10853,
count = 10,
look = true,
bgVisible = true
})
```
这样能先确认物品显示功能是否正常。
← 返回问答库