if isMobile == 2 then
-- 手机端坐标调整
goldX, goldY = 84, 90
itemX, itemY = 20, 90
itemX2, itemY2 =-455, 280
itemX3, itemY3 =-255, 280
end
GUI:ItemShow_C
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-03-20 19:10:37 |
👁️ 阅读: 18
根据你的需求,我来帮你实现这个功能。你需要先获取等级和魔力值,然后在点击Button2时进行判断并更新ItemShow_3的显示。
```lua
-- 首先获取等级和魔力值
local u44 = SL:GetMetaValue("ACTOR_LEVEL", playerID) or 0 -- 获取等级
local magicValue = SL:GetMetaValue("MAGIC_VALUE", playerID) or 0 -- 获取魔力值
-- 默认gemid
local default_gemid = 50834
-- 创建ItemShow_3和ItemShow_4,默认隐藏
local itemShow3 = GUI:ItemShow_Create(ui.itemroom, "ItemShow_3", itemX2, itemY2, {
index = default_gemid,
count = 1,
look = true,
bgVisible = false,
})
GUI:setVisible(itemShow3, false) -- 初始隐藏
local itemShow4 = GUI:ItemShow_Create(ui.itemroom, "ItemShow_4", itemX3, itemY3, {
index = default_gemid + 1, -- 假设ItemShow_4的id是ItemShow_3的id+1
count = 1,
look = true,
bgVisible = false,
})
GUI:setVisible(itemShow4, false) -- 初始隐藏
-- 检查条件并显示ItemShow_3和ItemShow_4
if u44 >= 10 and magicValue >= 1000 then
-- 隐藏Effect_1
if GUI:Win_IsNotNull(ui.Effect_1) then
GUI:setVisible(ui.Effect_1, false)
end
-- 显示ItemShow_3和ItemShow_4
GUI:setVisible(itemShow3, true)
GUI:setVisible(itemShow4, true)
end
-- 为Button2添加点击事件
GUI:addOnClickEvent(ui.Button2, function()
-- 重新获取当前等级和魔力值
local current_u44 = SL:GetMetaValue("ACTOR_LEVEL", playerID) or 0
local current_magic = SL:GetMetaValue("MAGIC_VALUE", playerID) or 0
local new_gemid = default_gemid
-- 根据等级和魔力值条件判断新的gemid
if current_u44 >= 100 and current_magic >= 512000 then
new_gemid = 50843
elseif current_u44 >= 90 and current_magic >= 256000 then
new_gemid = 50842
elseif current_u44 >= 80 and current_magic >= 128000 then
new_gemid = 50841
elseif current_u44 >= 70 and current_magic >= 32000 then
new_gemid = 50840
elseif current_u44 >= 60 and current_magic >= 16000 then
new_gemid = 50839
elseif current_u44 >= 50 and current_magic >= 8000 then
new_gemid = 50838
elseif current_u44 >= 40 and current_magic >= 8000 then
new_gemid = 50837
elseif current_u44 >= 30 and current_magic >= 4000 then
new_gemid = 50836
elseif current_u44 >= 20 and current_magic >= 3000 then
new_gemid = 50835
else
new_gemid = default_gemid
end
-- 更新ItemShow_3的显示
if GUI:Win_IsNotNull(itemShow3) then
-- 重新创建ItemShow_3以更新显示
GUI:removeFromParent(itemShow3)
itemShow3 = GUI:ItemShow_Create(ui.itemroom, "ItemShow_3", itemX2, itemY2, {
index = new_gemid,
count = 1,
look = true,
bgVisible = false,
})
GUI:setVisible(itemShow3, true)
end
-- 更新ItemShow_4的显示(假设id为new_gemid+1)
if GUI:Win_IsNotNull(itemShow4) then
GUI:removeFromParent(itemShow4)
itemShow4 = GUI:ItemShow_Create(ui.itemroom, "ItemShow_4", itemX3, itemY3, {
index = new_gemid + 1,
count = 1,
look = true,
bgVisible = false,
})
GUI:setVisible(itemShow4, true)
end
SL:Print("Button2点击,当前等级:", current_u44, "魔力值:", current_magic, "更新gemid为:", new_gemid)
end)
```
**代码说明:**
1. **获取数据**:使用`SL:GetMetaValue`获取玩家的等级和魔力值
2. **初始显示逻辑**:当等级≥10且魔力值≥1000时,隐藏Effect_1,显示ItemShow_3和ItemShow_4
3. **Button2点击事件**:点击时重新获取当前数据,根据你的条件判断应该使用哪个gemid
4. **更新显示**:移除旧的ItemShow并重新创建以更新显示
**注意:**
- 你需要确保`playerID`变量已定义,或者使用`SL:GetMetaValue("ACTOR_ID")`获取当前玩家ID
- ItemShow_4的id我假设为ItemShow_3的id+1,你可以根据需要调整
- 如果Effect_1的路径不正确,请检查你的ui表中Effect_1的定义
这个实现完全基于你的需求,如果还有不明白的地方,随时问我!
← 返回问答库