local baodian = {}
function baodian.main(param1, param2, param3, param4)
lib:Require(param1, function(state)
if state then
if param1 then
baodian.parent = lib:openwin(param1, nil, true, param4) or {}
根据你的代码,问题在于缺少按钮点击事件的处理逻辑。你需要在 `upmain` 函数中为每个按钮添加点击事件,并在事件中根据条件切换图片。
以下是修改后的 `baodian.upmain` 函数:
```lua
function baodian.upmain()
if not baodian.parent or not baodian.parent._ui then
return
end
local ui = baodian.parent._ui
for i = 1, 2 do
local button = ui["Button_" .. i]
if button and not GUI:Win_IsNull(button) then
-- 为每个按钮添加点击事件
GUI:addOnClickEvent(button, function()
-- 点击按钮时,根据条件设置图片
if i == 1 then
-- 这里需要根据你的条件判断,例如检查某个状态
local isSelected = true -- 假设这是你的判断条件
if isSelected then
GUI:Button_loadTextureNormal(button, "res/yidalu/dengji tupo/bt1.png")
GUI:Button_loadTexturePressed(button, "res/yidalu/dengji tupo/bt1.png")
else
GUI:Button_loadTextureNormal(button, "res/yidalu/dengji tupo/bt.png")
GUI:Button_loadTexturePressed(button, "res/yidalu/dengji tupo/bt.png")
end
elseif i == 2 then
local isSelected = true -- 假设这是你的判断条件
if isSelected then
GUI:Button_loadTextureNormal(button, "res/yidalu/dengji tupo/bt3.png")
GUI:Button_loadTexturePressed(button, "res/yidalu/dengji tupo/bt3.png")
else
GUI:Button_loadTextureNormal(button, "res/yidalu/dengji tupo/bt2.png")
GUI:Button_loadTexturePressed(button, "res/yidalu/dengji tupo/bt2.png")
end
end
end)
-- 初始设置按钮图片
local normalPath = ""
local pressedPath = ""
if i == 1 then
normalPath = "res/yidalu/dengji tupo/bt.png"
pressedPath = "res/yidalu/dengji tupo/bt.png"
elseif i == 2 then
normalPath = "res/yidalu/dengji tupo/bt2.png"
pressedPath = "res/yidalu/dengji tupo/bt2.png"
end
if normalPath ~= "" then
GUI:Button_loadTextureNormal(button, normalPath)
end
if pressedPath ~= "" then
GUI:Button_loadTexturePressed(button, pressedPath)
end
GUI:setVisible(button, true)
end
end
end
```
**关键修改点:**
1. **添加点击事件**:使用 `GUI:addOnClickEvent` 为每个按钮注册点击事件
2. **条件判断**:在点击事件中,你需要根据实际业务逻辑来判断是否应该显示发光图片
3. **图片路径**:
- Button_1:选中时用 `bt1.png`,未选中时用 `bt.png`
- Button_2:选中时用 `bt3.png`,未选中时用 `bt2.png`
**需要注意:**
- 代码中的 `isSelected` 变量需要替换为你实际的判断条件
- 确保图片路径正确,资源文件存在于项目中
- 按钮的初始状态设置为未选中状态
如果你需要根据服务器数据或玩家状态来判断是否选中,可以在点击事件中使用 `SL:GetMetaValue` 获取相关数据。