local attrDescs = GUIFunction:GetParseItemDesc(suitConfig.equipAttStr)
if attrDescs and attrDescs.desc and next(attrDescs.desc) then --这里不支持top bottom
for i, v in pairs(attrDescs.desc) do
if v.text then
index
根据浮生梦老师前端课程内容,你需要对富文本颜色进行条件替换。以下是实现逻辑:
```lua
local attrDescs = GUIFunction:GetParseItemDesc(suitConfig.equipAttStr)
if attrDescs and attrDescs.desc and next(attrDescs.desc) then
for i, v in pairs(attrDescs.desc) do
if v.text then
local text = v.text
-- 根据meetCount条件替换颜色值
if meetCount < 2 then
text = string.gsub(text, "FCOLOR=250", "FCOLOR=13")
text = string.gsub(text, "FCOLOR=251", "FCOLOR=13")
elseif meetCount < 4 then
text = string.gsub(text, "FCOLOR=250", "FCOLOR=13")
text = string.gsub(text, "FCOLOR=251", "FCOLOR=13")
elseif meetCount < 6 then
text = string.gsub(text, "FCOLOR=250", "FCOLOR=13")
text = string.gsub(text, "FCOLOR=251", "FCOLOR=13")
elseif meetCount < 7 then
text = string.gsub(text, "FCOLOR=250", "FCOLOR=13")
text = string.gsub(text, "FCOLOR=251", "FCOLOR=13")
end
v.text = text -- 更新文本内容
index = index + 1
local label_posName = GUI:RichTextFCOLOR_Create(panel, "desc_text_" .. index, 0, 0, v.text or "", suitWidth - 20, _setFontSize or _DefaultFSize, SL:GetColorByStyleId(255), vspace, nil, fontPath)
GUI:setAnchorPoint(label_posName, 0, 0)
GUI:setTag(label_posName, index)
local size = GUI:getContentSize(label_posName)
heights[index] = size.height + interval
richWidth = math.max(richWidth, size.width)
elseif v.res then
index = index + 1
local img = ItemTips.GetNodeImage(panel, v, index)
if img then
GUI:setTag(img, index)
local size = GUI:getContentSize(img)
heights[index] = size.height + interval
richWidth = math.max(richWidth, size.width)
end
end
end
end
```
**代码说明:**
1. 使用`string.gsub()`函数进行字符串替换
2. 根据`meetCount`的不同范围,将颜色值250和251替换为13
3. 替换后的文本赋值回`v.text`,确保后续创建富文本时使用更新后的内容
4. 保持原有的UI创建逻辑不变
注意:这里的条件判断有重叠,实际使用时可能需要根据具体业务逻辑调整条件范围。