优化“物品收藏”中(颈部、戒指、饰品)对于已获得和未获得的状态,

This commit is contained in:
尚美 2025-06-16 02:10:23 +08:00
parent dbb4e1fbf4
commit 98579cd41a
4 changed files with 120 additions and 116 deletions

View File

@ -311,7 +311,6 @@ end
-- 处理按钮点击事件
function SM_ItemCollectionUI:HandleButtonClick(slot)
if not self.currentPanel then
return
end
@ -412,7 +411,26 @@ function SM_ItemCollectionUI:ShowItemPreview(slot, panel)
icon:SetPoint("CENTER", 0, 10)
icon:SetTexture(GetItemIcon(itemID))
icon:SetTexCoord(0.07, 0.93, 0.07, 0.93)
-- 检查物品是否已获得,设置灰度效果
local itemData = nil
if SM_CollectionsDB and SM_CollectionsDB.itemCache and SM_CollectionsDB.itemCache.items then
for _, item in ipairs(SM_CollectionsDB.itemCache.items) do
if tonumber(item.id) == tonumber(itemID) then
itemData = item
break
end
end
end
-- 如果物品未获得,设置灰度效果
if not (itemData and itemData.obtained) then
icon:SetDesaturated(true)
icon:SetVertexColor(0.5, 0.5, 0.5)
end
model.IconTexture = icon
model.itemData = itemData -- 保存物品数据以便后续使用
if model.TransmogStateTexture then model.TransmogStateTexture:Hide() end
table.insert(modelFrames, model)
model:Show()
@ -426,6 +444,7 @@ function SM_ItemCollectionUI:ShowItemPreview(slot, panel)
local currentItemID = itemID
local currentModel = model
model:SetScript("OnMouseDown", function(self)
SM_ItemCollectionUI:SelectModel(currentModel)
if SM_Collections.MainFrame and SM_Collections.MainFrame.RightSidePanel then
local itemName = GetItemInfo(currentItemID)
@ -433,8 +452,7 @@ function SM_ItemCollectionUI:ShowItemPreview(slot, panel)
SM_Collections.MainFrame.RightSidePanel.MountNama:SetText(itemName or "")
end
if SM_Collections.MainFrame.RightSidePanel.introText then
SM_Collections.MainFrame.RightSidePanel.introText:SetText("物品ID: " ..
currentItemID .. "\n类型: " .. slot.name)
SM_Collections.MainFrame.RightSidePanel.introText:SetText("物品ID: " .. currentItemID .. "\n类型: " .. slot.name)
end
SM_ItemCollectionUI:UpdateAttributes(currentItemID, slot.invType)
end
@ -445,13 +463,16 @@ function SM_ItemCollectionUI:ShowItemPreview(slot, panel)
self:SelectModel(firstModel)
local itemID = slot.items[startIdx]
local itemName = GetItemInfo(itemID)
if SM_Collections.MainFrame and SM_Collections.MainFrame.RightSidePanel then
if SM_Collections.MainFrame.RightSidePanel.MountNama then
SM_Collections.MainFrame.RightSidePanel.MountNama:SetText(itemName or "")
end
if SM_Collections.MainFrame.RightSidePanel.introText then
SM_Collections.MainFrame.RightSidePanel.introText:SetText("物品ID: " .. itemID .. "\n类型: " .. slot
.name)
.name)
end
self:UpdateAttributes(itemID, slot.invType)
end
@ -487,8 +508,25 @@ function SM_ItemCollectionUI:ShowItemPreview(slot, panel)
SM_Collections.MainFrame.RightSidePanel.MountNama:SetText(itemName or "")
end
if SM_Collections.MainFrame.RightSidePanel.introText then
SM_Collections.MainFrame.RightSidePanel.introText:SetText("物品ID: " ..
currentItemID .. "\n类型: " .. slot.name)
SM_Collections.MainFrame.RightSidePanel.introText:SetText("物品ID: " .. currentItemID .. "\n类型: " .. slot.name)
-- 获取物品的 obtained 状态
local itemData = nil
for _, item in ipairs(SM_CollectionsDB.itemCache and SM_CollectionsDB.itemCache.items or {}) do
if tonumber(item.id) == tonumber(currentItemID) then
itemData = item
break
end
end
-- 添加状态文本
if not SM_Collections.MainFrame.RightSidePanel.statusText then
SM_Collections.MainFrame.RightSidePanel.statusText = SM_Collections.MainFrame.RightSidePanel:CreateFontString(nil, "OVERLAY")
SM_Collections.MainFrame.RightSidePanel.statusText:SetFont("Fonts\\ZYKai_T.ttf", 14, "OUTLINE")
SM_Collections.MainFrame.RightSidePanel.statusText:SetPoint("TOP", SM_Collections.MainFrame.RightSidePanel.introText, "BOTTOM", 0, -10)
end
local statusText = itemData and itemData.obtained and "|cFF00FF00已获得|r" or "|cFFFF0000未获得|r"
SM_Collections.MainFrame.RightSidePanel.statusText:SetText(statusText)
SM_Collections.MainFrame.RightSidePanel.statusText:Show()
end
SM_ItemCollectionUI:UpdateAttributes(currentItemID, slot.invType)
end
@ -544,7 +582,7 @@ function SM_ItemCollectionUI:ShowItemPreview(slot, panel)
end
if SM_Collections.MainFrame.RightSidePanel.introText then
SM_Collections.MainFrame.RightSidePanel.introText:SetText("物品ID: " ..
currentItemID .. "\n类型: " .. slot.name)
currentItemID .. "\n类型: " .. slot.name)
end
SM_ItemCollectionUI:UpdateAttributes(currentItemID, slot.invType)
end
@ -589,13 +627,43 @@ function SM_ItemCollectionUI:ShowItemPreview(slot, panel)
end
if SM_Collections.MainFrame.RightSidePanel.introText then
SM_Collections.MainFrame.RightSidePanel.introText:SetText("物品ID: " .. itemID .. "\n类型: " .. slot
.name)
.name)
end
self:UpdateAttributes(itemID, slot.invType)
end
end
end
self:CreatePageButtons(panel, slot)
-- 在切换部位时更新物品状态显示
if #slot.items > 0 then
local startIdx = (self.currentPage - 1) * self.itemsPerPage + 1
local itemID = slot.items[startIdx]
if itemID then
-- 获取物品的 obtained 状态
local itemData = nil
if SM_CollectionsDB and SM_CollectionsDB.itemCache and SM_CollectionsDB.itemCache.items then
for _, item in ipairs(SM_CollectionsDB.itemCache.items) do
if tonumber(item.id) == tonumber(itemID) then
itemData = item
break
end
end
end
-- 添加或更新状态文本
if SM_Collections.MainFrame and SM_Collections.MainFrame.RightSidePanel then
if not SM_Collections.MainFrame.RightSidePanel.statusText then
SM_Collections.MainFrame.RightSidePanel.statusText = SM_Collections.MainFrame.RightSidePanel:CreateFontString(nil, "OVERLAY")
SM_Collections.MainFrame.RightSidePanel.statusText:SetFont("Fonts\\ZYKai_T.ttf", 14, "OUTLINE")
SM_Collections.MainFrame.RightSidePanel.statusText:SetPoint("TOP", SM_Collections.MainFrame.RightSidePanel.introText, "BOTTOM", 0, -10)
end
local statusText = itemData and itemData.obtained and "|cFF00FF00已获得|r" or "|cFFFF0000未获得|r"
SM_Collections.MainFrame.RightSidePanel.statusText:SetText(statusText)
SM_Collections.MainFrame.RightSidePanel.statusText:Show()
end
end
end
end
-- 创建分页按钮
@ -700,14 +768,14 @@ function SM_ItemCollectionUI:CreateButtons()
normalTexture:SetPoint("CENTER")
normalTexture:SetTexture(slot.icon) -- ICON_SLOTS 图标纹理
SetPortraitToTexture(normalTexture, slot.icon) -- 圆形肖像
btn.NormalTexture = normalTexture
btn.NormalTexture = normalTexture
-- 添加高光纹理(使用通用的高光效果)
local highlightTexture = btn:CreateTexture(nil, "HIGHLIGHT")
highlightTexture:SetSize(30, 30)
highlightTexture:SetPoint("CENTER", 0, 0)
highlightTexture:SetTexture("Interface\\AddOns\\SM_CollectionSystem\\Interface\\ContainerFrame\\Bags")
highlightTexture:SetTexCoord(0.1640625,0.3046875,0.6875,0.828125) -- 这是XML里的
highlightTexture:SetTexCoord(0.1640625, 0.3046875, 0.6875, 0.828125) -- 这是XML里的
highlightTexture:SetBlendMode("ADD")
-- 添加覆盖纹理
@ -818,7 +886,6 @@ function SM_ItemCollectionUI:CreateButtons()
-- 关键改动将slot对象存储在按钮上而不是依赖闭包
btn.slotData = slot
btn:SetScript("OnClick", function(self)
-- 播放点击音效
PlaySound("igSpellBookSpellIconPickup")

View File

@ -386,9 +386,9 @@ end
-- 发送服务端请求
function SM_Collections.ServerDataProvider:SendServerRequest(command, data, callback)
if SM_Collections.Config.Debug then
--
--
end
-- 确保pendingCallbacks表已初始化
if not SM_Collections.pendingCallbacks then
SM_Collections.pendingCallbacks = {}
@ -401,12 +401,12 @@ function SM_Collections.ServerDataProvider:SendServerRequest(command, data, call
requestMessage = command .. "|" .. data.itemType .. "|" .. data.itemId
end
--
--
-- 发送消息给服务端
-- 尝试通过两种方式发送,增加成功机会
SendAddonMessage("SM_C_COLLECTIONS_REQUEST", requestMessage, "GUILD")
-- 保存回调函数
if command == "GET_MOUNTS" then
SM_Collections.pendingCallbacks.mounts = callback
@ -428,7 +428,7 @@ function SM_Collections.ServerDataProvider:SendServerRequest(command, data, call
timeoutFrame.data = data
timeoutFrame.startTime = GetTime()
timeoutFrame.timeoutSeconds = SM_Collections.Config.ServerTimeout / 1000
timeoutFrame:SetScript("OnUpdate", function(self, elapsed)
if GetTime() - self.startTime >= self.timeoutSeconds then
local callbackKey
@ -447,9 +447,7 @@ function SM_Collections.ServerDataProvider:SendServerRequest(command, data, call
end
if SM_Collections.pendingCallbacks and SM_Collections.pendingCallbacks[callbackKey] then
if SM_Collections.Config.FallbackToLocal then
local localProvider = SM_Collections.LocalDataProvider:new()
if self.command == "GET_MOUNTS" then
localProvider:GetMounts(callback)
@ -465,7 +463,7 @@ function SM_Collections.ServerDataProvider:SendServerRequest(command, data, call
localProvider:GetAttributesForSpecificItem(self.data.itemId, self.data.itemType, callback)
end
else
callback({success = false, data = {}})
callback({ success = false, data = {} })
end
SM_Collections.pendingCallbacks[callbackKey] = nil
end
@ -586,6 +584,7 @@ SM_Collections.DataManager = {
for i, item in ipairs(SM_Collections.LocalDataProvider.cachedItems) do
if item.id == itemID then
item.obtained = isObtained
print("item.obtained111= ",item.obtained)
break
end
end

View File

@ -306,53 +306,6 @@ function SM_Collections:UpdateTabAppearance(selectedTab)
self.CurrentTab = selectedTab
end
-- 创建类型图标和文本
function SM_Collections:CreateTypeIcon(parent)
if parent.typeIcon then
return parent.typeIcon
end
-- 创建图标容器
local iconFrame = CreateFrame("Frame", nil, parent)
iconFrame:SetSize(40, 40)
iconFrame:SetPoint("TOP", 180, -10) -- 在模型上方
-- 创建图标
local icon = iconFrame:CreateTexture(nil, "ARTWORK")
icon:SetSize(32, 32)
icon:SetPoint("CENTER", 0, 0)
--SetPortraitToTexture(icon, "Interface\\Icons\\INV_Box_01") -- 圆形肖像
-- 创建高亮纹理
local highlight = iconFrame:CreateTexture(nil, "HIGHLIGHT")
highlight:SetSize(36, 36)
highlight:SetPoint("CENTER", 0, 0)
highlight:Hide()
-- 创建边框覆盖纹理
local border = iconFrame:CreateTexture(nil, "OVERLAY")
border:SetSize(38, 38)
border:SetPoint("CENTER", 0, 0)
border:SetTexture("Interface\\AddOns\\SM_CollectionSystem\\Textures\\Cir_Overlay")
--border:SetBlendMode("ADD")
-- 创建类型文字
local typeText = iconFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
typeText:SetPoint("RIGHT", iconFrame, "LEFT", -10, 0)
typeText:SetText("")
-- 存储引用
iconFrame.icon = icon
iconFrame.highlight = highlight
iconFrame.border = border
iconFrame.typeText = typeText
parent.typeIcon = iconFrame
return iconFrame
end
-- 更新左上角图标
function SM_Collections:UpdateCornerIcon(tabID)
if not self.MainFrame or not self.MainFrame.cornerIcon then return end

View File

@ -71,12 +71,12 @@ function OnItemClick(button, itemData, itemType, panel)
local creatureDisplayID = nil
-- 如果服务端已经提供了displayID优先使用它
if itemData.displayID and itemData.displayID > 0 then
print("服务端已经提供了displayID= ",itemData.displayID)
print("服务端已经提供了displayID= ", itemData.displayID)
creatureDisplayID = itemData.displayID
else
-- 否则从映射表中获取
creatureDisplayID = SM_Collections:GetCreatureDisplayID(itemData.id, itemType)
print("从映射表中获取")
print("从映射表中获取")
end
if panel and panel.model and creatureDisplayID and creatureDisplayID > 0 then
@ -370,7 +370,7 @@ function SM_Collections:CreateListItems(parent, data, itemType, model, nameText,
-- 存储物品数据和选中状态
button.itemData = item
button.isSelected = false
button.itemType = itemType -- 添加itemType属性用于推断面板类型
button.itemType = itemType -- 添加itemType属性用于推断面板类型
-- 添加"NEW"标记,如果这个项目是新获得的
if item.obtained and self.NewItems and self.NewItems[itemType] and self.NewItems[itemType][item.id] then
@ -379,7 +379,7 @@ function SM_Collections:CreateListItems(parent, data, itemType, model, nameText,
newTexture:SetPoint("TOPRIGHT", button, "TOPRIGHT", -5, -5)
newTexture:SetTexture("Interface\\AddOns\\SM_CollectionSystem\\Textures\\New_Icon")
button.newTexture = newTexture
-- 在鼠标悬停时隐藏"NEW"标记
button:HookScript("OnEnter", function(self)
if self.newTexture then
@ -416,7 +416,7 @@ function SM_Collections:CreateListItems(parent, data, itemType, model, nameText,
if icon then
ButtonIcon:SetNormalTexture(icon)
ButtonIcon:SetHighlightTexture(icon)
-- 为未获得的项目设置灰色图标
if not item.obtained then
local normalTexture = ButtonIcon:GetNormalTexture()
@ -424,7 +424,7 @@ function SM_Collections:CreateListItems(parent, data, itemType, model, nameText,
normalTexture:SetDesaturated(true)
normalTexture:SetVertexColor(0.5, 0.5, 0.5)
end
local highlightTexture = ButtonIcon:GetHighlightTexture()
if highlightTexture then
highlightTexture:SetDesaturated(true)
@ -434,7 +434,7 @@ function SM_Collections:CreateListItems(parent, data, itemType, model, nameText,
else
ButtonIcon:SetNormalTexture("Interface\\Icons\\INV_Misc_QuestionMark")
ButtonIcon:SetHighlightTexture("Interface\\Icons\\INV_Misc_QuestionMark")
-- 为未获得的项目设置灰色问号图标
if not item.obtained then
local normalTexture = ButtonIcon:GetNormalTexture()
@ -442,7 +442,7 @@ function SM_Collections:CreateListItems(parent, data, itemType, model, nameText,
normalTexture:SetDesaturated(true)
normalTexture:SetVertexColor(0.5, 0.5, 0.5)
end
local highlightTexture = ButtonIcon:GetHighlightTexture()
if highlightTexture then
highlightTexture:SetDesaturated(true)
@ -505,7 +505,7 @@ function SM_Collections:CreateListItems(parent, data, itemType, model, nameText,
--
text:SetText(displayName)
text:SetTextColor(item.obtained and 1 or 0.5, item.obtained and 1 or 0.5, item.obtained and 1 or 0.5)
-- 保存文本对象的引用,以便后续更新
button.text = text
@ -589,12 +589,11 @@ end
function SM_Collections:UpdateRightPanel(selectedItem, itemType)
if not self.MainFrame or not self.MainFrame.RightSidePanel then
return
end
local rightPanel = self.MainFrame.RightSidePanel
--
--
-- 更新坐骑名称
if rightPanel.MountNama then
@ -605,17 +604,17 @@ function SM_Collections:UpdateRightPanel(selectedItem, itemType)
displayName = spellName or "ID: " .. selectedItem.id
end
--
--
rightPanel.MountNama:SetText(displayName or "")
rightPanel.MountNama:Show()
-- 检查文本框的各种属性
--
--
-- "层级=", rightPanel.MountNama:GetDrawLayer(),
-- "宽高=", rightPanel.MountNama:GetWidth(), rightPanel.MountNama:GetHeight(),
-- "位置=", rightPanel.MountNama:GetPoint())
else
end
-- 更新描述文本并确保正确换行
@ -832,23 +831,19 @@ end
-- 刷新收藏状态
function SM_Collections:RefreshCollectionStatus(itemType, itemID, isObtained)
-- 如果当前没有显示面板,不需要刷新
if not self.CurrentPanel or not self.CurrentPanel.scrollChild then
return
end
local buttons = self.CurrentPanel.scrollChild.buttons
if not buttons then
return
end
-- 检查当前是否显示了对应类型的面板
local isCorrectPanel = false
-- 尝试从当前面板的按钮数据推断面板类型
local inferredPanelType = nil
if #buttons > 0 and buttons[1].itemData then
@ -857,34 +852,33 @@ function SM_Collections:RefreshCollectionStatus(itemType, itemID, isObtained)
-- 可以检查buttons[1].itemType如果存在的话
if buttons[1].itemType then
inferredPanelType = buttons[1].itemType
end
end
-- 如果是小伙伴类型,特殊处理
if itemType == "companion" then
-- 检查是否有任何按钮的ID匹配
for _, button in ipairs(buttons) do
if button.itemData and button.itemData.id == itemID then
isCorrectPanel = true
break
end
end
end
-- 如果是卡牌类型,也进行特殊处理
if itemType == "card" then
-- 检查是否有任何按钮的ID匹配
for _, button in ipairs(buttons) do
if button.itemData and button.itemData.id == itemID then
isCorrectPanel = true
break
end
end
end
-- 如果MainFrame.tabID存在使用它否则尝试使用推断的面板类型
if not isCorrectPanel and self.MainFrame and self.MainFrame.tabID then
if (itemType == "mount" and self.MainFrame.tabID == 1) or
@ -896,24 +890,22 @@ function SM_Collections:RefreshCollectionStatus(itemType, itemID, isObtained)
elseif not isCorrectPanel and inferredPanelType and itemType == inferredPanelType then
-- 如果推断出的面板类型与更新的项目类型匹配
isCorrectPanel = true
elseif not isCorrectPanel then
-- 尝试直接检查按钮数据是否包含要更新的项目ID
for _, button in ipairs(buttons) do
if button.itemData and button.itemData.id == itemID then
isCorrectPanel = true
break
end
end
end
if not isCorrectPanel then
return
end
-- 查找对应的按钮并更新状态
local updatedButton = nil
@ -922,7 +914,7 @@ function SM_Collections:RefreshCollectionStatus(itemType, itemID, isObtained)
for i, button in ipairs(buttons) do
if button.itemData and button.itemData.id == itemID then
buttonFound = true
-- 更新获取状态
button.itemData.obtained = isObtained
@ -931,24 +923,22 @@ function SM_Collections:RefreshCollectionStatus(itemType, itemID, isObtained)
if button.text then
-- 使用保存的文本对象引用
button.text:SetTextColor(isObtained and 1 or 0.5, isObtained and 1 or 0.5, isObtained and 1 or 0.5)
else
-- 尝试获取文本对象
local text = button:GetRegions()
if text and text:GetObjectType() == "FontString" then
text:SetTextColor(isObtained and 1 or 0.5, isObtained and 1 or 0.5, isObtained and 1 or 0.5)
else
end
end
-- 更新图标颜色(针对坐骑和小伙伴)
for _, child in ipairs({button:GetChildren()}) do
for _, child in ipairs({ button:GetChildren() }) do
if child:GetName() and string.find(child:GetName(), "CollectionsButtonIcon") then
local normalTexture = child:GetNormalTexture()
local highlightTexture = child:GetHighlightTexture()
if normalTexture then
if isObtained then
normalTexture:SetDesaturated(false)
@ -958,7 +948,7 @@ function SM_Collections:RefreshCollectionStatus(itemType, itemID, isObtained)
normalTexture:SetVertexColor(0.5, 0.5, 0.5)
end
end
if highlightTexture then
if isObtained then
highlightTexture:SetDesaturated(false)
@ -968,7 +958,7 @@ function SM_Collections:RefreshCollectionStatus(itemType, itemID, isObtained)
highlightTexture:SetVertexColor(0.7, 0.7, 0.7)
end
end
break
end
end
@ -982,7 +972,7 @@ function SM_Collections:RefreshCollectionStatus(itemType, itemID, isObtained)
newTexture:SetPoint("TOPRIGHT", button, "TOPRIGHT", -5, -5)
newTexture:SetTexture("Interface\\AddOns\\SM_CollectionSystem\\Textures\\New_Icon")
button.newTexture = newTexture
-- 在鼠标悬停时隐藏"NEW"标记
button:HookScript("OnEnter", function(self)
if self.newTexture then
@ -1002,7 +992,6 @@ function SM_Collections:RefreshCollectionStatus(itemType, itemID, isObtained)
-- 如果是当前选中的按钮,更新右侧面板
if button.isSelected then
updatedButton = button
end
-- 更新已获得按钮列表
@ -1018,14 +1007,13 @@ function SM_Collections:RefreshCollectionStatus(itemType, itemID, isObtained)
end
if not found then
table.insert(obtainedButtons, button)
end
else
-- 从已获得列表中移除
for i, btn in ipairs(obtainedButtons) do
if btn == button then
table.remove(obtainedButtons, i)
break
end
end
@ -1040,20 +1028,20 @@ function SM_Collections:RefreshCollectionStatus(itemType, itemID, isObtained)
end
if not buttonFound then
end
-- 如果更新的是当前选中的项目,刷新右侧面板
if updatedButton then
local panel = self.CurrentPanel
OnItemClick(updatedButton, updatedButton.itemData, itemType, panel)
end
-- 通知玩家
if isObtained then
local typeName = itemType == "mount" and "坐骑" or itemType == "companion" and "小伙伴" or itemType == "card" and "卡牌" or
"物品"
"物品"
local itemName = ""
-- 尝试获取物品名称
@ -1063,9 +1051,9 @@ function SM_Collections:RefreshCollectionStatus(itemType, itemID, isObtained)
-- 显示通知
if itemName and itemName ~= "" then
else
end
-- 播放获得音效
@ -1111,13 +1099,10 @@ function SM_Collections:ResortCollectionButtons(scrollChild, itemType)
button:SetPoint("TOPLEFT", 30, -(i - 1) * (buttonHeight + spacing))
end
end
end
-- 注册事件处理
function SM_Collections:RegisterCollectionEvents()
-- 监听收藏状态更新事件
self:RegisterEvent("ADDON_MESSAGE_PREFIX_SM_S_COLLECTION_UPDATE", function(prefix, message)
local data = self:MessageSplit(message, "|")