local fentian = {}
function fentian.main(param1, param2, param3, param4)
lib:Require(param1, function(state)
if state then
if param1 then
fentian.parent = lib:openwin(param1, nil, true, param4) or {}
根据浮生梦老师前端课程内容,你需要在现有的 `fentian.upmain()` 函数中增加文本颜色设置逻辑。具体修改位置是在获取并处理 `T13` 的 `used_attr_list` 之后,设置文本字符串之前。
以下是需要添加的代码段:
```lua
-- 根据T13显示对应特效
for _, attr_id in ipairs(used_attr_list) do
local effect_name = "cur_attr_" .. attr_id
if not GUI:Win_IsNull(ui[effect_name]) then
GUI:setVisible(ui[effect_name], true)
end
end
-- 新增:根据T13改变对应文本颜色
local color_normal = "#9E8F4F" -- 普通颜色
local color_highlight = "#f7de39" -- 高亮颜色
-- 初始化所有文本为普通颜色
local text_mapping = {
["cur_attr_1"] = "Text_7",
["cur_attr_2"] = "Text_6",
["cur_attr_3"] = "Text_4",
["cur_attr_4"] = "Text_10",
["cur_attr_5"] = "Text_3",
["cur_attr_6"] = "Text_5",
["cur_attr_7"] = "Text_9",
["cur_attr_8"] = "Text_8"
}
-- 先设置所有文本为普通颜色
for _, text_name in pairs(text_mapping) do
if not GUI:Win_IsNull(ui[text_name]) then
GUI:Text_setTextColor(ui[text_name], color_normal)
end
end
-- 根据T13中的属性设置高亮颜色
for _, attr_id in ipairs(used_attr_list) do
local attr_key = "cur_attr_" .. attr_id
local text_name = text_mapping[attr_key]
if text_name and not GUI:Win_IsNull(ui[text_name]) then
GUI:Text_setTextColor(ui[text_name], color_highlight)
end
end
-- 以下是原有的文本设置代码
if not GUI:Win_IsNull(ui.Text_3) then
GUI:Text_setString(ui.Text_3, "生命值+" .. (cur_cfg.sur_attr_5 or 0))
end
```
这段代码做了以下几件事:
1. 定义了普通颜色和高亮颜色
2. 建立了属性ID到文本控件的映射关系
3. 先将所有相关文本设置为普通颜色
4. 根据`T13`中的属性ID,将对应的文本设置为高亮颜色
5. 最后继续执行原有的文本内容设置
注意:这段代码需要插入在原有的特效显示循环之后,文本内容设置之前。这样就能实现当`T13`中包含某个属性时,对应的文本显示为金色高亮效果。