local moshen = {}
function moshen.main(param1, param2, param3, param4)
lib:Require(param1, function(state)
if state then
if param1 then
moshen.parent = lib:openwin(param1, nil, true, param4) or {}
根据你的需求,需要在点击Button_2时根据U44等级和U45魔力值来动态控制Effect_1的显示隐藏,并更新ItemShow_3的显示ID。以下是修改后的代码:
```lua
-- 在Button_2的点击事件中添加逻辑
if GUI:Win_IsNotNull(ui.Button_2) then
GUI:addOnClickEvent(ui.Button_2, function()
SL:print("点击了第2个按钮")
GUI:delayTouchEnabled(ui.Button_2, 0.2)
-- 获取当前等级和魔力值
local currentLevel = tonumber(SL:GetMetaValue("SERVER_VALUE", "U44")) or 0
local currentMana = tonumber(SL:GetMetaValue("SERVER_VALUE", "U45")) or 0
-- 控制Effect_1的显示隐藏逻辑
if GUI:Win_IsNotNull(ui.Effect_1) then
if currentLevel >= 10 and currentMana >= 1000 then
GUI:setVisible(ui.Effect_1, false)
else
GUI:setVisible(ui.Effect_1, true)
end
end
-- 根据等级和魔力值确定要显示的物品ID
local targetItemId = 50834 -- 默认ID
if currentLevel >= 10 and currentMana >= 1000 then
targetItemId = 50834
-- 显示ItemShow_4
if GUI:Win_IsNotNull(ui.itemroom) then
GUI:ItemShow_Create(ui.itemroom, "ItemShow_4", itemX2, itemY2, {
index = targetItemId,
count = 1,
look = true,
bgVisible = false,
})
end
end
if currentLevel >= 20 and currentMana >= 3000 then
targetItemId = 50835
end
if currentLevel >= 30 and currentMana >= 4000 then
targetItemId = 50836
end
if currentLevel >= 40 and currentMana >= 8000 then
targetItemId = 50837
end
if currentLevel >= 50 and currentMana >= 8000 then
targetItemId = 50838
end
if currentLevel >= 60 and currentMana >= 16000 then
targetItemId = 50839
end
if currentLevel >= 70 and currentMana >= 32000 then
targetItemId = 50840
end
if currentLevel >= 80 and currentMana >= 128000 then
targetItemId = 50841
end
if currentLevel >= 90 and currentMana >= 256000 then
targetItemId = 50842
end
if currentLevel >= 100 and currentMana >= 512000 then
targetItemId = 50843
end
-- 更新ItemShow_3的显示
if GUI:Win_IsNotNull(ui.itemroom) then
-- 先移除旧的ItemShow_3
local oldItem = GUI:getChildByName(ui.itemroom, "ItemShow_3")
if oldItem and not GUI:Win_IsNull(oldItem) then
GUI:removeFromParent(oldItem)
end
-- 创建新的ItemShow_3
GUI:ItemShow_Create(ui.itemroom, "ItemShow_3", itemX2, itemY2, {
index = targetItemId,
count = 1,
look = true,
bgVisible = false,
})
end
-- 发送网络消息
local msg = {}
msg.Script = moshen.param1
local jsonstr = SL:JsonEncode(msg)
SL:SendLuaNetMsg(58003, moshen.param2, 1, 0, jsonstr)
end)
end
```
主要修改点:
1. **Effect_1控制**:当U44≥10且U45≥1000时隐藏Effect_1,否则显示
2. **ItemShow_4显示**:在满足第一个条件时,会创建ItemShow_4显示默认ID 50834
3. **ItemShow_3动态更新**:根据不同的等级和魔力值条件,更新ItemShow_3显示的物品ID
4. **坐标变量**:使用了你在代码中定义的itemX2, itemY2坐标变量
注意事项:
- 确保Effect_1和itemroom控件在UI中已正确创建
- 坐标变量itemX2, itemY2需要根据你的UI布局进行调整
- 每次点击Button_2都会重新判断条件并更新显示