1、优化HandleItemAttributesData函数接收数据判断是否以获取isPositive

2、切换到非物品收藏界面时,隐藏物品收藏的“已获得/未获得”状态文本
This commit is contained in:
尚美 2025-06-30 19:32:30 +08:00
parent 72dde2f2a2
commit 499701c5f0
2 changed files with 29 additions and 30 deletions

View File

@ -101,7 +101,6 @@ end
-- 处理物品属性数据的函数
function SM_Collections:HandleItemAttributesData(msg)
-- 按换行符分割每一行属性数据
local lines = {}
for line in msg:gmatch("[^\r\n]+") do
table.insert(lines, line)
@ -110,30 +109,26 @@ function SM_Collections:HandleItemAttributesData(msg)
local allAttributes = {}
-- 处理每一行属性数据
for _, line in ipairs(lines) do
-- 使用自定义的MessageSplit函数将每行按"|"分隔符拆分
local data = self:MessageSplit(line, "|")
-- 每3个元素为一组进行循环处理属性名、属性值、属性类型
for i = 1, #data, 3 do
if data[i] and data[i + 1] and data[i + 2] then
-- 创建属性对象
local attribute = {
Name = data[i], -- 属性名称
value = tonumber(data[i + 1]), -- 属性数值
valueType = data[i + 2], -- 属性类型(百分比/固定数值)
isPositive = tonumber(data[i + 1]) >= 0 -- 根据数值正负判断是否为正面属性
}
-- 输出每个属性的值
print("Name= " ..
attribute.Name .. ", value= " .. attribute.value .. ", valueType= " .. attribute.valueType)
-- 添加到属性数组
table.insert(allAttributes, attribute)
end
end
end
for _, line in ipairs(lines) do
local data = self:MessageSplit(line, "|")
-- 每4个元素为一组进行循环处理属性名、属性值、属性类型、是否正面
for i = 1, #data, 4 do
if data[i] and data[i + 1] and data[i + 2] and data[i + 3] then
local attribute = {
Name = data[i],
value = tonumber(data[i + 1]),
valueType = data[i + 2],
isPositive = data[i + 3] == "1" -- 使用服务端发送的标志
}
print("Name= " .. attribute.Name .. ", value= " .. attribute.value ..
", valueType= " .. attribute.valueType .. ", isPositive= " .. tostring(attribute.isPositive))
table.insert(allAttributes, attribute)
end
end
end
-- 检查是否存在待处理的回调函数
if self.pendingCallbacks and self.pendingCallbacks.item_attributes then
@ -146,6 +141,7 @@ function SM_Collections:HandleItemAttributesData(msg)
self.pendingCallbacks.item_attributes = nil
end
end
-- 处理小伙伴数据
function SM_Collections:HandleCompanionsData(msg)
local data = self:MessageSplit(msg, "|")

View File

@ -1,10 +1,11 @@
-- SM_UI_SplitPanel.lua
-- 迁移左右分栏、列表、滚动条、模型、物品网格、CreateSplitPanel、CreateListItems、CreateItemGrid等所有UI细节和逻辑
-- ...(此处插入完整实现,详见原始大文件)
-- 点击处理逻辑
function OnItemClick(button, itemData, itemType, panel)
-- 切换到非物品收藏界面时,隐藏物品收藏的“已获得/未获得”状态文本
if SM_Collections.MainFrame and SM_Collections.MainFrame.RightSidePanel and SM_Collections.MainFrame.RightSidePanel.statusText then
SM_Collections.MainFrame.RightSidePanel.statusText:Hide()
end
-- 设置按钮选中状态
if button then
-- 取消其他按钮的选中状态
@ -674,6 +675,7 @@ function SM_Collections:UpdateRightPanel(selectedItem, itemType)
end
end
-- 更新属性加成
function SM_Collections:UpdateAttributesForItem(item, parentFrame, itemType)
local children = { parentFrame:GetChildren() }
for _, child in ipairs(children) do
@ -720,6 +722,7 @@ function SM_Collections:UpdateAttributesForItem(item, parentFrame, itemType)
local valueText = button:CreateFontString(nil, "OVERLAY")
valueText:SetPoint("RIGHT", -5, 0)
valueText:SetFont("Fonts\\ZYKai_T.ttf", 10, "MONOCHROME")
print("isPositive= ", isPositive)
local formattedValue = isPositive and ("+ " .. AttributeValue) or ("- " .. AttributeValue)
valueText:SetText(formattedValue)
@ -1096,7 +1099,7 @@ function SM_Collections:RefreshCollectionStatus(itemType, itemID, isObtained)
if updatedButton and updatedButton.isSelected and self.MainFrame and self.MainFrame.RightSidePanel then
-- 更新状态文本
if self.MainFrame.RightSidePanel.statusText then
local statusText = isObtained and "|cFF00FF00已获得|r" or "|cFFFF0000未获得|r"
local statusText = isObtained and "|cFF00FF00已获得11111|r" or "|cFFFF0000未获得22222|r"
self.MainFrame.RightSidePanel.statusText:SetText(statusText)
end