for i, v in pairs(attrDescs.desc) do
SL:print(v.text)
if v.text then
index = index + 1
local label_posName = GUI:RichTextFCOLOR_Create(panel, "desc_text_" .. index, 0, 0, v.text or "", suitWidth
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-04-07 16:58:23 |
👁️ 阅读: 0
根据浮生梦老师前端课程内容,你需要修改富文本颜色。从你的代码来看,`attrDescs.desc` 中的 `v.text` 包含富文本格式,当 `meetCount < 4` 时,需要将文本中所有 `FCOLOR=251` 替换为 `FCOLOR=13`。
你可以使用 `string.gsub` 函数进行全局替换。修改你的循环代码如下:
```lua
for i, v in pairs(attrDescs.desc) do
SL:print(v.text)
if v.text then
index = index + 1
-- 判断条件并替换颜色
local displayText = v.text
if meetCount < 4 then
displayText = string.gsub(displayText, "FCOLOR=251", "FCOLOR=13")
end
local label_posName = GUI:RichTextFCOLOR_Create(panel, "desc_text_" .. index, 0, 0, displayText 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
```
关键改动:
1. 在创建富文本控件前,先判断 `meetCount < 4` 条件
2. 使用 `string.gsub(displayText, "FCOLOR=251", "FCOLOR=13")` 将文本中所有 `FCOLOR=251` 替换为 `FCOLOR=13`
3. 使用替换后的 `displayText` 创建富文本控件
这样就能实现当套装满足数量不足4件时,将特定颜色代码从251改为13的效果。
根据浮生梦老师前端课程内容,你需要修改富文本颜色。从你的代码来看,`attrDescs.desc` 中的 `v.text` 包含富文本格式,当 `meetCount < 4` 时,需要将文本中所有 `FCOLOR=251` 替换为 `FCOLOR=13`。
你可以使用 `string.gsub` 函数进行全局替换。修改你的循环代码如下:
```lua
for i, v in pairs(attrDescs.desc) do
SL:print(v.text)
if v.text then
index = index + 1
-- 判断条件并替换颜色
local displayText = v.text
if meetCount < 4 then
displayText = string.gsub(displayText, "FCOLOR=251", "FCOLOR=13")
end
local label_posName = GUI:RichTextFCOLOR_Create(panel, "desc_text_" .. index, 0, 0, displayText 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
```
关键改动:
1. 在创建富文本控件前,先判断 `meetCount < 4` 条件
2. 使用 `string.gsub(displayText, "FCOLOR=251", "FCOLOR=13")` 将文本中所有 `FCOLOR=251` 替换为 `FCOLOR=13`
3. 使用替换后的 `displayText` 创建富文本控件
这样就能实现当套装满足数量不足4件时,将特定颜色代码从251改为13的效果。
← 返回问答库