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
inde
```lua
-- 处理文本颜色替换的逻辑
local function ProcessTextColor(textStr, meetCount)
local newTextStr = ""
-- 根据meetCount判断需要替换的颜色条件
local conditions = {
{count = 2, pattern = "<2/FCOLOR=250><//FCOLOR=251><7/FCOLOR=250></FCOLOR=251><32/FCOLOR=251>"},
{count = 4, pattern = "<4/FCOLOR=250><//FCOLOR=251><7/FCOLOR=250></FCOLOR=251><45/FCOLOR=251>"},
{count = 6, pattern = "<6/FCOLOR=250><//FCOLOR=251><7/FCOLOR=250></FCOLOR=251><2/FCOLOR=251><5/FCOLOR=251><0/FCOLOR=251>"},
{count = 7, pattern = "<7/FCOLOR=250><//FCOLOR=251><7/FCOLOR=250></FCOLOR=251><4/FCOLOR=251><%/FCOLOR=251>"}
}
local processedText = textStr
for _, condition in ipairs(conditions) do
if meetCount < condition.count then
-- 替换250为13,251为13
local pattern = condition.pattern
local replacedPattern = string.gsub(pattern, "250", "13")
replacedPattern = string.gsub(replacedPattern, "251", "13")
-- 在文本中查找并替换对应的部分
if string.find(processedText, pattern) then
processedText = string.gsub(processedText, pattern, replacedPattern)
end
end
end
return processedText
end
-- 在你的代码中使用
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
index = index + 1
-- 处理文本颜色
local processedText = ProcessTextColor(v.text, meetCount)
local label_posName = GUI:RichText_Create(panel, "desc_text_" .. index, 0, 0,
processedText or "", suitWidth - 20, _setFontSize or _DefaultFSize,
SL:GetHexColorByStyleId(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
```
注意:我使用了`GUI:RichText_Create`而不是`GUI:RichTextFCOLOR_Create`,因为根据浮生梦老师前端课程内容,前者是标准创建富文本的方法。另外,颜色获取函数应该是`SL:GetHexColorByStyleId`而不是`SL:GetColorByStyleId`。