根据浮生梦老师的前端课程内容,要在打印 `11111111111111111` 的地方同时打印装备名字,你可以修改 `ItemTips.ParseExAddAttr` 函数中的 `SL:print(11111111111111111)` 语句。
以下是修改后的代码示例:
```lua
function ItemTips.ParseExAddAttr(attr, needAttrList)
if not attr or string.len(attr) == "" then
return
end
local attrAlignment = SL:GetMetaValue("WINPLAYMODE") and tonumber(SL:GetMetaValue("GAME_DATA", "pc_tips_attr_alignment")) or 0
local attrCoefficient = SL:GetMetaValue("WINPLAYMODE") and -1 or 1
attrAlignment = math.ceil(attrAlignment / 3)
local attList = {}
local exList = {}
local strList = string.split(attr, ",")
for i, v in pairs(strList) do
local data = string.split(v, "=")
if tonumber(data[1]) and data[2] and tonumber(data[2]) then
table.insert(attList, {id = tonumber(data[1]), value = tonumber(data[2])})
end
end
if needAttrList then
return attList
end
local stringAtt = GUIFunction:GetAttDataShow(attList, nil, true)
local attrShow = {}
for id, v in pairs(stringAtt) do
v.id = id
local originId = getAttOriginId(id)
local attConfig = SL:GetMetaValue("ATTR_CONFIG", originId)
v.sort = attConfig and attConfig.sort or originId + 1000
v.excolor = attConfig.excolor
table.insert(attrShow, v)
end
table.sort(attrShow, function(a, b)
return a.sort < b.sort
end)
-- 修改这里:获取当前处理的装备数据并打印装备名字
local itemData = ItemTips._data and ItemTips._data.itemData
local equipName = itemData and itemData.Name or "未知装备"
SL:print("装备名字: " .. equipName .. " - 11111111111111111")
local strList = {}
if attrShow and next(attrShow) then
local titleName = ItemTips._showTitleList[3] and ItemTips._showTitleList[3].name or "[附加属性]:"
local titleColor = ItemTips._showTitleList[3] and ItemTips._showTitleList[3].color or 154
local titleStr = string.format("<font color='%s'>%s</font>", SL:GetHexColorByStyleId(titleColor), titleName)
table.insert(strList, {
str = titleStr
})
end
for _,v in pairs(attrShow) do
local name = string.gsub(v.name, " ", "")
name = string.gsub(name, " ", "")
local value = getAddShow(v.id, v.value) .. v.value
local nameLen, chineseLen = SL:GetUTF8ByteLen(name)
local newLen = math.max(attrAlignment - nameLen - chineseLen * attrCoefficient + SL:GetUTF8ByteLen(value), 0)
local lenStr = string.format("%%%ds", newLen)
value = string.format(lenStr, value)
local color = tonumber(v.excolor) or 250
local oneStr = string.format("<font color='%s'>%s</font>", SL:GetHexColorByStyleId(color), name .. value)
table.insert(strList, {
id = v.id,
str = oneStr
})
end
return strList
end
```
主要修改:
1. 通过 `ItemTips._data.itemData` 获取当前处理的装备数据
2. 从 `itemData.Name` 获取装备名字
3. 使用 `SL:print()` 同时打印装备名字和原来的数字
这样当解析附加属性时,会在控制台输出类似:"装备名字: 屠龙刀 - 11111111111111111" 的信息。