物品收藏,从服务端获取属性
This commit is contained in:
parent
5b57b5ec1f
commit
e2f19ffbf9
@ -340,7 +340,7 @@ function SM_ItemCollectionUI:UpdateAttributes(itemID, itemType)
|
||||
local attributeTitle = attributeFrame:CreateFontString(nil, "OVERLAY")
|
||||
attributeTitle:SetFont("Fonts\\ZYKai_T.ttf", 14, "OUTLINE")
|
||||
attributeTitle:SetPoint("TOP", 0, 0)
|
||||
attributeTitle:SetText("属性加成")
|
||||
attributeTitle:SetText("属性加成2")
|
||||
attributeTitle:SetTextColor(1, 0.82, 0)
|
||||
|
||||
rightSidePanel.AttributeBonusFrame = attributeFrame
|
||||
@ -375,79 +375,111 @@ function SM_ItemCollectionUI:UpdateAttributes(itemID, itemType)
|
||||
end
|
||||
rightSidePanel.attributesContainer:Show()
|
||||
|
||||
-- 模拟不同物品的不同属性加成
|
||||
local attributes = {}
|
||||
-- 隐藏可能存在的无属性提示文本
|
||||
if rightSidePanel.noAttributesText then
|
||||
rightSidePanel.noAttributesText:Hide()
|
||||
end
|
||||
|
||||
-- 根据物品ID的不同添加不同的属性(示例)
|
||||
if itemID % 2 == 0 then
|
||||
table.insert(attributes, { name = "火焰伤害", value = "+500", isPositive = true })
|
||||
-- 显示加载中提示
|
||||
if not rightSidePanel.loadingText then
|
||||
rightSidePanel.loadingText = rightSidePanel.attributesContainer:CreateFontString(nil, "OVERLAY")
|
||||
rightSidePanel.loadingText:SetFont("Fonts\\ZYKai_T.ttf", 12, "OUTLINE")
|
||||
rightSidePanel.loadingText:SetPoint("TOP", rightSidePanel.attributesContainer, "TOP", 0, -10)
|
||||
--rightSidePanel.loadingText:SetText("正在加载属性数据...")
|
||||
rightSidePanel.loadingText:SetTextColor(1, 0.82, 0)
|
||||
else
|
||||
table.insert(attributes, { name = "敏捷", value = "+20", isPositive = true })
|
||||
rightSidePanel.loadingText:Show()
|
||||
end
|
||||
|
||||
if itemID % 3 == 0 then
|
||||
table.insert(attributes, { name = "法术强度", value = "+200", isPositive = true })
|
||||
-- 确保DataManager存在
|
||||
if not SM_Collections.DataManager then
|
||||
print("[收藏系统] 错误: DataManager未初始化")
|
||||
if rightSidePanel.loadingText then
|
||||
rightSidePanel.loadingText:SetText("错误: 数据管理器未初始化")
|
||||
rightSidePanel.loadingText:SetTextColor(1, 0, 0)
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
if itemID % 5 == 0 then
|
||||
table.insert(attributes, { name = "冰霜抗性", value = "+75", isPositive = true })
|
||||
-- 确保GetAttributesForSpecificItem方法存在
|
||||
if not SM_Collections.DataManager.GetAttributesForSpecificItem then
|
||||
print("[收藏系统] 错误: GetAttributesForSpecificItem方法未找到")
|
||||
if rightSidePanel.loadingText then
|
||||
rightSidePanel.loadingText:SetText("错误: 属性获取方法未找到")
|
||||
rightSidePanel.loadingText:SetTextColor(1, 0, 0)
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
-- 根据物品类型添加特有的属性
|
||||
if itemType == "INVTYPE_HEAD" or itemType == "INVTYPE_CHEST" or itemType == "INVTYPE_LEGS" then
|
||||
table.insert(attributes, { name = "护甲", value = "+100", isPositive = true })
|
||||
elseif itemType == "INVTYPE_WEAPONMAINHAND" then
|
||||
table.insert(attributes, { name = "攻击强度", value = "+50", isPositive = true })
|
||||
elseif itemType == "INVTYPE_TRINKET" then
|
||||
table.insert(attributes, { name = "暴击率", value = "+2%", isPositive = true })
|
||||
end
|
||||
|
||||
-- 添加属性按钮,与其他收藏页面风格一致
|
||||
local buttonH = 150
|
||||
local buttonW = 20
|
||||
|
||||
for i, attribute in ipairs(attributes) do
|
||||
-- 创建带背景纹理的按钮
|
||||
local button = CreateFrame("Button", "SM_ItemCollectionAttributeButton" .. i, rightSidePanel.attributesContainer)
|
||||
button:SetSize(buttonH, buttonW)
|
||||
button:SetNormalTexture("Interface\\AddOns\\SM_CollectionSystem\\Textures\\AttributeuttonTexture")
|
||||
button:SetPoint("TOPLEFT", 0, -(i - 1) * buttonW)
|
||||
|
||||
-- 属性名称文本
|
||||
local nameText = button:CreateFontString(nil, "OVERLAY")
|
||||
nameText:SetPoint("LEFT", 10, 0)
|
||||
nameText:SetFont("Fonts\\ZYKai_T.ttf", 10, "MONOCHROME")
|
||||
nameText:SetText(attribute.name)
|
||||
|
||||
-- 根据物品是否已获得设置文本颜色
|
||||
if isObtained then
|
||||
nameText:SetTextColor(1, 1, 1) -- 白色
|
||||
else
|
||||
nameText:SetTextColor(0.5, 0.5, 0.5) -- 灰色
|
||||
-- 从服务端获取物品属性数据
|
||||
SM_Collections.DataManager:GetAttributesForSpecificItem(itemID, "item", function(attributes)
|
||||
-- 隐藏加载提示
|
||||
if rightSidePanel.loadingText then
|
||||
rightSidePanel.loadingText:Hide()
|
||||
end
|
||||
|
||||
-- 属性数值文本
|
||||
local valueText = button:CreateFontString(nil, "OVERLAY")
|
||||
valueText:SetPoint("RIGHT", -5, 0)
|
||||
valueText:SetFont("Fonts\\ZYKai_T.ttf", 10, "MONOCHROME")
|
||||
valueText:SetText(attribute.value)
|
||||
|
||||
-- 根据物品是否已获得设置文本颜色
|
||||
if isObtained then
|
||||
valueText:SetTextColor(0, 1, 0) -- 绿色
|
||||
else
|
||||
valueText:SetTextColor(0.5, 0.5, 0.5) -- 灰色
|
||||
if not attributes or #attributes == 0 then
|
||||
-- 如果没有属性数据,显示一个提示
|
||||
if not rightSidePanel.noAttributesText then
|
||||
rightSidePanel.noAttributesText = rightSidePanel.attributesContainer:CreateFontString(nil, "OVERLAY")
|
||||
rightSidePanel.noAttributesText:SetFont("Fonts\\ZYKai_T.ttf", 12, "OUTLINE")
|
||||
rightSidePanel.noAttributesText:SetPoint("TOP", rightSidePanel.attributesContainer, "TOP", 0, -10)
|
||||
rightSidePanel.noAttributesText:SetText("该物品没有属性加成")
|
||||
rightSidePanel.noAttributesText:SetTextColor(0.7, 0.7, 0.7)
|
||||
else
|
||||
rightSidePanel.noAttributesText:Show()
|
||||
rightSidePanel.noAttributesText:SetText("该物品没有属性加成")
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
button:Show()
|
||||
-- 显示从服务端获取的属性
|
||||
local buttonH = 150
|
||||
local buttonW = 20
|
||||
|
||||
-- 存储按钮引用
|
||||
table.insert(rightSidePanel.attributeButtons, button)
|
||||
for i, attribute in ipairs(attributes) do
|
||||
-- 创建带背景纹理的按钮
|
||||
local button = CreateFrame("Button", "SM_ItemCollectionAttributeButton" .. i, rightSidePanel.attributesContainer)
|
||||
button:SetSize(buttonH, buttonW)
|
||||
button:SetNormalTexture("Interface\\AddOns\\SM_CollectionSystem\\Textures\\AttributeuttonTexture")
|
||||
button:SetPoint("TOPLEFT", 0, -(i - 1) * buttonW)
|
||||
|
||||
-- 也将文本添加到文本数组中以便清理
|
||||
table.insert(rightSidePanel.attributeTexts, nameText)
|
||||
table.insert(rightSidePanel.attributeTexts, valueText)
|
||||
end
|
||||
-- 属性名称文本
|
||||
local nameText = button:CreateFontString(nil, "OVERLAY")
|
||||
nameText:SetPoint("LEFT", 30, 0)
|
||||
nameText:SetFont("Fonts\\ZYKai_T.ttf", 10, "MONOCHROME")
|
||||
nameText:SetText(attribute.Name or "")
|
||||
|
||||
-- 根据物品是否已获得设置文本颜色
|
||||
if isObtained then
|
||||
nameText:SetTextColor(1, 1, 1) -- 白色
|
||||
else
|
||||
nameText:SetTextColor(0.5, 0.5, 0.5) -- 灰色
|
||||
end
|
||||
|
||||
-- 属性数值文本
|
||||
local valueText = button:CreateFontString(nil, "OVERLAY")
|
||||
valueText:SetPoint("RIGHT", -5, 0)
|
||||
valueText:SetFont("Fonts\\ZYKai_T.ttf", 10, "MONOCHROME")
|
||||
valueText:SetText(attribute.value or "")
|
||||
|
||||
-- 根据物品是否已获得设置文本颜色
|
||||
if isObtained then
|
||||
valueText:SetTextColor(0, 1, 0) -- 绿色
|
||||
else
|
||||
valueText:SetTextColor(0.5, 0.5, 0.5) -- 灰色
|
||||
end
|
||||
|
||||
button:Show()
|
||||
|
||||
-- 存储按钮引用
|
||||
table.insert(rightSidePanel.attributeButtons, button)
|
||||
|
||||
-- 也将文本添加到文本数组中以便清理
|
||||
table.insert(rightSidePanel.attributeTexts, nameText)
|
||||
table.insert(rightSidePanel.attributeTexts, valueText)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
-- 处理按钮点击事件
|
||||
@ -1367,7 +1399,7 @@ function SM_ItemCollectionUI:ShowItemCollectionUI(parent)
|
||||
local attributeTitle = attributeFrame:CreateFontString(nil, "OVERLAY")
|
||||
attributeTitle:SetFont("Fonts\\ZYKai_T.ttf", 14, "OUTLINE")
|
||||
attributeTitle:SetPoint("TOP", 0, 0)
|
||||
attributeTitle:SetText("属性加成")
|
||||
attributeTitle:SetText("属性加成1")
|
||||
attributeTitle:SetTextColor(1, 0.82, 0)
|
||||
SM_Collections.MainFrame.RightSidePanel.AttributeBonusFrame = attributeFrame
|
||||
end
|
||||
|
||||
@ -404,7 +404,6 @@ function SM_Collections.ServerDataProvider:SendServerRequest(command, data, call
|
||||
--
|
||||
|
||||
-- 发送消息给服务端
|
||||
-- 尝试通过两种方式发送,增加成功机会
|
||||
SendAddonMessage("SM_C_COLLECTIONS_REQUEST", requestMessage, "GUILD")
|
||||
|
||||
-- 保存回调函数
|
||||
|
||||
@ -75,6 +75,7 @@ end
|
||||
|
||||
-- 处理属性数据
|
||||
function SM_Collections:HandleAttributesData(msg)
|
||||
print("[收藏系统] 处理属性数据:", msg)
|
||||
local data = self:MessageSplit(msg, "|")
|
||||
local attributes = {}
|
||||
for i = 1, #data, 3 do
|
||||
@ -98,29 +99,50 @@ function SM_Collections:HandleAttributesData(msg)
|
||||
end
|
||||
end
|
||||
|
||||
-- 处理物品属性数据
|
||||
-- 处理物品属性数据的函数
|
||||
function SM_Collections:HandleItemAttributesData(msg)
|
||||
local data = self:MessageSplit(msg, "|")
|
||||
local attributes = {}
|
||||
for i = 1, #data, 3 do
|
||||
if data[i] and data[i + 1] and data[i + 2] then
|
||||
table.insert(attributes, {
|
||||
Name = data[i],
|
||||
value = tonumber(data[i + 1]),
|
||||
isPositive = data[i + 2] == "1"
|
||||
})
|
||||
-- 按换行符分割每一行属性数据
|
||||
local lines = {}
|
||||
for line in msg:gmatch("[^\r\n]+") do
|
||||
table.insert(lines, line)
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
-- 检查是否存在待处理的回调函数
|
||||
if self.pendingCallbacks and self.pendingCallbacks.item_attributes then
|
||||
local response = {
|
||||
success = true,
|
||||
data = attributes
|
||||
data = allAttributes
|
||||
}
|
||||
|
||||
self.pendingCallbacks.item_attributes(response)
|
||||
self.pendingCallbacks.item_attributes = nil
|
||||
else
|
||||
--
|
||||
end
|
||||
end
|
||||
|
||||
@ -624,14 +646,19 @@ function SM_Collections_MessageEvent(self, event, prefix, msg, type, sender)
|
||||
if event == 'CHAT_MSG_WHISPER' or event == 'CHAT_MSG_ADDON' then
|
||||
if prefix == 'SM_S_COLLECTIONS_MOUNTS' then
|
||||
SM_Collections:HandleMountsData(msg) -- 坐骑
|
||||
|
||||
elseif prefix == 'SM_S_COLLECTIONS_COMPANIONS' then
|
||||
SM_Collections:HandleCompanionsData(msg) -- 小伙伴
|
||||
|
||||
elseif prefix == 'SM_S_COLLECTIONS_CARDS' then
|
||||
SM_Collections:HandleCardsData(msg) -- 卡牌
|
||||
|
||||
elseif prefix == 'SM_S_COLLECTIONS_ITEMS' then
|
||||
SM_Collections:HandleItemsData(msg) -- 物品
|
||||
|
||||
elseif prefix == 'SM_S_COLLECTIONS_ATTRIBUTES' then
|
||||
SM_Collections:HandleAttributesData(msg) -- 属性
|
||||
|
||||
elseif prefix == 'SM_S_COLLECTIONS_ITEM_ATTRIBUTES' then
|
||||
SM_Collections:HandleItemAttributesData(msg) -- 物品属性
|
||||
|
||||
|
||||
@ -123,7 +123,7 @@ function SM_Collections:CreateMainFrame()
|
||||
local AttributeBonusFrameText = AttributeBonusFrame:CreateFontString(nil, "OVERLAY")
|
||||
AttributeBonusFrameText:SetPoint("CENTER", 0, 0)
|
||||
AttributeBonusFrameText:SetFontObject(titleFont)
|
||||
AttributeBonusFrameText:SetText("属性加成")
|
||||
AttributeBonusFrameText:SetText("属性加成3")
|
||||
AttributeBonusFrameText:SetFont("Fonts\\ZYKai_T.ttf", 16, "MONOCHROME")
|
||||
AttributeBonusFrame:Hide()
|
||||
rightSidePanel.AttributeBonusFrame = AttributeBonusFrame
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user