local sycee =SL:GetMetaValue("MONEY", 2)
if sycee<= next_cfg.value2 then
end
if GUI:Win_IsNotNull(ui.yuanbao) then
GUI:Text_setString(ui.yuanbao, ": " .. (next_cfg.value2 or 0))
end
我要想我的元宝小于所需要的元宝的时候ui.yuanbao显示红色,大于所需元
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-04-13 14:41:22 |
👁️ 阅读: 5
```lua
local sycee = SL:GetMetaValue("MONEY", 2)
if sycee <= next_cfg.value2 then
-- 元宝不足时显示红色
if GUI:Win_IsNotNull(ui.yuanbao) then
GUI:Text_setString(ui.yuanbao, ": " .. (next_cfg.value2 or 0))
GUI:Text_setColor(ui.yuanbao, "#ff0000") -- 红色
end
else
-- 元宝足够时显示绿色
if GUI:Win_IsNotNull(ui.yuanbao) then
GUI:Text_setString(ui.yuanbao, ": " .. (next_cfg.value2 or 0))
GUI:Text_setColor(ui.yuanbao, "#5ac83d") -- 绿色
end
end
```
**函数说明:**
- `SL:GetMetaValue("MONEY", 2)`:获取元宝数量
- `GUI:Win_IsNotNull(widget)`:判断控件是否不为空
- `GUI:Text_setString(text, str)`:设置文本内容
- `GUI:Text_setColor(text, color)`:设置文本颜色(颜色格式为十六进制)
**代码逻辑:**
1. 先获取当前元宝数量 `sycee`
2. 比较当前元宝与所需元宝 `next_cfg.value2`
3. 如果元宝不足(小于等于),设置文本为红色
4. 如果元宝足够(大于),设置文本为绿色
**注意:** 确保 `next_cfg.value2` 有值,使用 `or 0` 做了空值保护。
```lua
local sycee = SL:GetMetaValue("MONEY", 2)
if sycee <= next_cfg.value2 then
-- 元宝不足时显示红色
if GUI:Win_IsNotNull(ui.yuanbao) then
GUI:Text_setString(ui.yuanbao, ": " .. (next_cfg.value2 or 0))
GUI:Text_setColor(ui.yuanbao, "#ff0000") -- 红色
end
else
-- 元宝足够时显示绿色
if GUI:Win_IsNotNull(ui.yuanbao) then
GUI:Text_setString(ui.yuanbao, ": " .. (next_cfg.value2 or 0))
GUI:Text_setColor(ui.yuanbao, "#5ac83d") -- 绿色
end
end
```
**函数说明:**
- `SL:GetMetaValue("MONEY", 2)`:获取元宝数量
- `GUI:Win_IsNotNull(widget)`:判断控件是否不为空
- `GUI:Text_setString(text, str)`:设置文本内容
- `GUI:Text_setColor(text, color)`:设置文本颜色(颜色格式为十六进制)
**代码逻辑:**
1. 先获取当前元宝数量 `sycee`
2. 比较当前元宝与所需元宝 `next_cfg.value2`
3. 如果元宝不足(小于等于),设置文本为红色
4. 如果元宝足够(大于),设置文本为绿色
**注意:** 确保 `next_cfg.value2` 有值,使用 `or 0` 做了空值保护。
← 返回问答库