清理大多数打印日志信息

This commit is contained in:
尚美 2025-06-17 00:30:16 +08:00
parent e69e2e76f2
commit 5b57b5ec1f
6 changed files with 61 additions and 186 deletions

View File

@ -37,12 +37,10 @@ function SM_ItemCollectionUI:RegisterItemEvents()
end
end)
end
-- 注册相关事件
self.eventFrame:RegisterEvent("CHAT_MSG_LOOT")
self.eventFrame:RegisterEvent("BAG_UPDATE")
print("[事件] 物品获取事件已注册")
end
-- 处理物品获取事件
@ -52,7 +50,6 @@ function SM_ItemCollectionUI:OnLootReceived(msg)
if itemLink then
local itemID = string.match(itemLink, "item:(%d+)")
if itemID then
print("[事件] 检测到物品获取:", itemID)
-- 延迟一点执行更新,确保服务器数据已同步
local itemToUpdate = itemID
local updateFrame = CreateFrame("Frame")
@ -83,7 +80,6 @@ function SM_ItemCollectionUI:OnBagUpdate()
-- 避免重复处理同一物品
if itemID and not self.processedItems[itemID] then
self.processedItems[itemID] = true
print("[事件] 检测到背包物品:", itemID)
-- 延迟一点执行更新,确保服务器数据已同步
local itemToUpdate = itemID
local updateFrame = CreateFrame("Frame")
@ -121,8 +117,6 @@ function SM_ItemCollectionUI:HandleNewItemIcon(model, itemID)
if model and itemID and SM_Collections and SM_Collections.NewItems and SM_Collections.NewItems.item and SM_Collections.NewItems.item[tonumber(itemID)] then
-- 添加"NEW"标记,如果这是新获得的物品
if model.itemData and model.itemData.obtained and SM_Collections.NewItems and SM_Collections.NewItems.item and SM_Collections.NewItems.item[tonumber(itemID)] then
print("[收藏系统] 检测到新物品准备添加NEW图标:", itemID)
-- 创建NEW图标使用OVERLAY层的最高级别(7)确保显示在最顶层
if not model.newTexture then
local newTexture = model:CreateTexture(nil, "OVERLAY", nil, 7)
@ -132,12 +126,10 @@ function SM_ItemCollectionUI:HandleNewItemIcon(model, itemID)
-- 确保纹理在最顶层
newTexture:SetDrawLayer("OVERLAY", 7)
model.newTexture = newTexture
print("[收藏系统] 成功创建NEW图标:", itemID)
else
model.newTexture:Show()
-- 确保纹理在最顶层
model.newTexture:SetDrawLayer("OVERLAY", 7)
print("[收藏系统] 显示已有NEW图标:", itemID)
end
else
-- 如果不是新物品但存在NEW图标隐藏它
@ -265,8 +257,6 @@ end
function SM_ItemCollectionUI:ApplyCamera(model, cameraID)
-- 确保cameraID是有效的数值ID
if type(cameraID) == "string" then
-- 如果传入的是字符串ID需要转换为数值ID
--print("警告传入了字符串相机ID: " .. cameraID .. "应该使用GetCharacterCameraID或GetWeaponCameraID获取数值ID")
return
end
@ -286,8 +276,6 @@ function SM_ItemCollectionUI:ApplyCamera(model, cameraID)
model:SetPosition(x, y, z) -- 武器使用绝对坐标
model:SetFacing(facing or 0)
end
else
--print("摄像机参数未找到ID:", cameraID)
end
end
@ -486,8 +474,6 @@ end
-- 强制清理所有物品模型
function SM_ItemCollectionUI:ForceCleanupModels(panel)
print("[清理] 强制清理所有物品模型")
-- 清理预览框架
if panel and panel.previewFrame then
local children = { panel.previewFrame:GetChildren() }
@ -518,7 +504,7 @@ end
function SM_ItemCollectionUI:ShowItemPreview(slot, panel)
-- 确保物品已排序
self:SortSlotItems(slot)
-- 清除当前选中的模型
self:ClearModelSelection()
@ -641,12 +627,10 @@ function SM_ItemCollectionUI:ShowItemPreview(slot, panel)
end
end
model.itemData = itemData or {id = itemID, obtained = false} -- 保存物品数据以便后续使用
model.itemData = itemData or { id = itemID, obtained = false } -- 保存物品数据以便后续使用
-- 添加"NEW"标记,如果这是新获得的物品
if itemData and itemData.obtained and SM_Collections.NewItems and SM_Collections.NewItems.item and SM_Collections.NewItems.item[tonumber(itemID)] then
print("[收藏系统] 检测到新物品准备添加NEW图标:", itemID)
-- 创建NEW图标使用OVERLAY层的最高级别(7)确保显示在最顶层
if not model.newTexture then
local newTexture = model:CreateTexture(nil, "OVERLAY", nil, 7)
@ -656,15 +640,13 @@ function SM_ItemCollectionUI:ShowItemPreview(slot, panel)
-- 确保纹理在最顶层
newTexture:SetDrawLayer("OVERLAY", 7)
model.newTexture = newTexture
print("[收藏系统] 成功创建NEW图标:", itemID)
else
model.newTexture:Show()
-- 确保纹理在最顶层
model.newTexture:SetDrawLayer("OVERLAY", 7)
print("[收藏系统] 显示已有NEW图标:", itemID)
end
end
if model.TransmogStateTexture then model.TransmogStateTexture:Hide() end
table.insert(modelFrames, model)
model:Show()
@ -672,15 +654,13 @@ function SM_ItemCollectionUI:ShowItemPreview(slot, panel)
model:SetScript("OnEnter", function(self)
-- 处理NEW图标
if self.newTexture and self.newTexture:IsShown() then
print("[收藏系统] 清除NEW图标:", itemID)
self.newTexture:Hide()
-- 从NewItems表中移除
if SM_Collections and SM_Collections.NewItems and SM_Collections.NewItems.item then
SM_Collections.NewItems.item[tonumber(itemID)] = nil
print("[收藏系统] 已清除NEW标记:", itemID)
end
end
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:SetHyperlink("item:" .. itemID)
GameTooltip:Show()
@ -697,7 +677,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
@ -767,12 +747,10 @@ function SM_ItemCollectionUI:ShowItemPreview(slot, panel)
end
end
model.itemData = itemData or {id = itemID, obtained = false} -- 保存物品数据以便后续使用
model.itemData = itemData or { id = itemID, obtained = false } -- 保存物品数据以便后续使用
-- 添加"NEW"标记,如果这是新获得的物品
if itemData and itemData.obtained and SM_Collections.NewItems and SM_Collections.NewItems.item and SM_Collections.NewItems.item[tonumber(itemID)] then
print("[收藏系统] 检测到新物品准备添加NEW图标(3D):", itemID)
-- 创建NEW图标使用OVERLAY层的最高级别(7)确保显示在最顶层
if not model.newTexture then
local newTexture = model:CreateTexture(nil, "OVERLAY", nil, 7)
@ -782,12 +760,10 @@ function SM_ItemCollectionUI:ShowItemPreview(slot, panel)
-- 确保纹理在最顶层
newTexture:SetDrawLayer("OVERLAY", 7)
model.newTexture = newTexture
print("[收藏系统] 成功创建NEW图标(3D):", itemID)
else
model.newTexture:Show()
-- 确保纹理在最顶层
model.newTexture:SetDrawLayer("OVERLAY", 7)
print("[收藏系统] 显示已有NEW图标(3D):", itemID)
end
end
@ -797,15 +773,13 @@ function SM_ItemCollectionUI:ShowItemPreview(slot, panel)
model:SetScript("OnEnter", function(self)
-- 处理NEW图标
if self.newTexture and self.newTexture:IsShown() then
print("[收藏系统] 清除NEW图标:", itemID)
self.newTexture:Hide()
-- 从NewItems表中移除
if SM_Collections and SM_Collections.NewItems and SM_Collections.NewItems.item then
SM_Collections.NewItems.item[tonumber(itemID)] = nil
print("[收藏系统] 已清除NEW标记:", itemID)
end
end
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:SetHyperlink("item:" .. itemID)
GameTooltip:Show()
@ -822,7 +796,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)
-- 获取物品的 obtained 状态
local itemData = nil
for _, item in ipairs(SM_CollectionsDB.itemCache and SM_CollectionsDB.itemCache.items or {}) do
@ -835,7 +809,7 @@ function SM_ItemCollectionUI:ShowItemPreview(slot, panel)
-- 添加状态文本
if not SM_Collections.MainFrame.RightSidePanel.statusText then
SM_Collections.MainFrame.RightSidePanel.statusText = SM_Collections.MainFrame.RightSidePanel
:CreateFontString(nil, "OVERLAY")
:CreateFontString(nil, "OVERLAY")
SM_Collections.MainFrame.RightSidePanel.statusText:SetFont("Fonts\\ZYKai_T.ttf", 14,
"OUTLINE")
SM_Collections.MainFrame.RightSidePanel.statusText:SetPoint("TOP",
@ -972,7 +946,7 @@ function SM_ItemCollectionUI:ShowItemPreview(slot, panel)
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")
: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)
@ -1004,7 +978,6 @@ function SM_ItemCollectionUI:CreatePageButtons(panel, slot)
prevBtn:SetText("上一页")
prevBtn:SetScript("OnClick", function()
if self.currentPage > 1 then
print("[分页] 切换到上一页:", self.currentPage - 1)
self.currentPage = self.currentPage - 1
-- 确保物品始终保持排序
self:SortSlotItems(slot)
@ -1032,7 +1005,6 @@ function SM_ItemCollectionUI:CreatePageButtons(panel, slot)
nextBtn:SetText("下一页")
nextBtn:SetScript("OnClick", function()
if self.currentPage < self.totalPages then
print("[分页] 切换到下一页:", self.currentPage + 1)
self.currentPage = self.currentPage + 1
-- 确保物品始终保持排序
self:SortSlotItems(slot)
@ -1065,15 +1037,12 @@ end
-- 新增函数:对槽位中的物品按获得状态排序
function SM_ItemCollectionUI:SortSlotItems(slot)
if not slot or not slot.items or #slot.items == 0 then
print("[排序] 槽位", slot and slot.invType or "未知", "为空或没有物品,无需排序")
return
end
print("[排序] 开始对槽位", slot.invType, "中的", #slot.items, "个物品排序")
-- 对物品按照已获得状态进行排序,已获得的排在前面
local sortedItems = {}
-- 首先创建一个带状态的物品列表
for _, itemID in ipairs(slot.items) do
local isObtained = false
@ -1085,13 +1054,13 @@ function SM_ItemCollectionUI:SortSlotItems(slot)
end
end
end
table.insert(sortedItems, {id = itemID, obtained = isObtained})
table.insert(sortedItems, { id = itemID, obtained = isObtained })
end
-- 按照获得状态进行排序
table.sort(sortedItems, function(a, b)
if a.obtained and not b.obtained then
return true -- a排在b前面
return true -- a排在b前面
elseif not a.obtained and b.obtained then
return false -- b排在a前面
else
@ -1099,38 +1068,31 @@ function SM_ItemCollectionUI:SortSlotItems(slot)
return a.id < b.id
end
end)
-- 打印排序前后的状态
local beforeIDs = {}
for i, id in ipairs(slot.items) do
beforeIDs[i] = id
end
local afterIDs = {}
for i, item in ipairs(sortedItems) do
afterIDs[i] = item.id
end
print("[排序] 排序前:", table.concat(beforeIDs, ", "))
print("[排序] 排序后:", table.concat(afterIDs, ", "))
-- 更新排序后的物品ID列表
local newItems = {}
for _, item in ipairs(sortedItems) do
table.insert(newItems, item.id)
end
slot.items = newItems
print("[排序] 槽位", slot.invType, "物品排序完成")
return true -- 返回true表示排序成功
end
-- 新增函数:更新物品获得状态并重新排序显示
function SM_ItemCollectionUI:UpdateItemObtainedStatus(itemID, isObtained)
if not itemID then return end
print("[更新] 更新物品", itemID, "获得状态为", isObtained and "已获得" or "未获得")
-- 更新物品缓存中的状态
local itemUpdated = false
if SM_CollectionsDB and SM_CollectionsDB.itemCache and SM_CollectionsDB.itemCache.items then
@ -1142,12 +1104,11 @@ function SM_ItemCollectionUI:UpdateItemObtainedStatus(itemID, isObtained)
end
end
end
if not itemUpdated then
print("[更新] 警告:物品", itemID, "未在缓存中找到")
return false
end
-- 如果物品是新获得的添加到NewItems表中
if isObtained then
if not SM_Collections.NewItems then
@ -1157,9 +1118,8 @@ function SM_ItemCollectionUI:UpdateItemObtainedStatus(itemID, isObtained)
SM_Collections.NewItems.item = {}
end
SM_Collections.NewItems.item[tonumber(itemID)] = true
print("[更新] 物品", itemID, "标记为新获得")
end
-- 找到当前物品所在的槽位
local currentSlot = nil
for _, slot in ipairs(self.ALL_SLOTS) do
@ -1171,21 +1131,20 @@ function SM_ItemCollectionUI:UpdateItemObtainedStatus(itemID, isObtained)
end
if currentSlot then break end
end
if not currentSlot then
print("[更新] 警告:物品", itemID, "未在任何槽位中找到")
return false
end
-- 重新排序当前槽位的物品
self:SortSlotItems(currentSlot)
-- 如果当前正在显示该槽位,则刷新显示
if self.currentPanel and self.currentSelectedButton and self.currentSelectedButton.slotData == currentSlot then
print("[更新] 刷新当前显示的槽位", currentSlot.name)
self:ShowItemPreview(currentSlot, self.currentPanel)
end
return true
end
@ -1437,7 +1396,6 @@ function SM_ItemCollectionUI:ShowItemCollectionUI(parent)
end
if cacheValid then
print("[SM_ItemCollectionUI] 读取缓存,物品数量:"..#SM_CollectionsDB.itemCache.items)
if panel.waitingText then panel.waitingText:Hide() end
self:ProcessAndShowItems(SM_CollectionsDB.itemCache.items, panel)
else
@ -1474,7 +1432,6 @@ function SM_ItemCollectionUI:ShowItemCollectionUI(parent)
end
function SM_ItemCollectionUI:ProcessAndShowItems(items, panel)
print("[SM_ItemCollectionUI] ProcessAndShowItems, items数量"..#items)
-- 清空所有槽位的物品数组
for _, slot in ipairs(self.ALL_SLOTS) do
slot.items = {}
@ -1533,16 +1490,12 @@ end
-- 添加一个调试函数,用于打印物品数组状态
function SM_ItemCollectionUI:DebugPrintItemArrays()
--print("=========== 物品收藏系统调试信息 ===========")
--print("物品槽位数量: " .. #self.ALL_SLOTS)
local totalItems = 0
for i, slot in ipairs(self.ALL_SLOTS) do
local itemCount = slot.items and #slot.items or 0
totalItems = totalItems + itemCount
--print(string.format("%s 槽位包含 %d 个物品", slot.name, itemCount))
-- 如果有物品打印前三个物品的ID
if itemCount > 0 then
local previewItems = {}
@ -1550,11 +1503,6 @@ function SM_ItemCollectionUI:DebugPrintItemArrays()
local itemName = GetItemInfo(slot.items[j]) or "未知"
table.insert(previewItems, string.format("%d(%s)", slot.items[j], itemName))
end
--print(" 示例物品: " .. table.concat(previewItems, ", ") ..
-- (itemCount > 3 and " ..." or ""))
end
end
--print("物品总数: " .. totalItems)
--print("===========================================")
end

View File

@ -25,18 +25,18 @@ SM_Collections.CurrentTab = 1
-- 配置系统
SM_Collections.Config = {
UseServerData = true, -- 数据源切换开关,默认使用服务端数据
ServerTimeout = 5000, -- 服务端超时时间
FallbackToLocal = true, -- 服务端失败时回退到本地数据
Debug = true -- 调试模式
UseServerData = true, -- 数据源切换开关,默认使用服务端数据
ServerTimeout = 5000, -- 服务端超时时间
FallbackToLocal = true, -- 服务端失败时回退到本地数据
Debug = true -- 调试模式
}
-- 新获得的收藏项目记录
SM_Collections.NewItems = {
mount = {}, -- 新获得的坐骑ID
companion = {}, -- 新获得的小伙伴ID
card = {}, -- 新获得的卡牌ID
item = {} -- 新获得的物品ID
mount = {}, -- 新获得的坐骑ID
companion = {}, -- 新获得的小伙伴ID
card = {}, -- 新获得的卡牌ID
item = {} -- 新获得的物品ID
}
-- 添加ADDON_LOADED事件处理以初始化数据库
@ -44,8 +44,6 @@ local InitFrame = CreateFrame("Frame")
InitFrame:RegisterEvent("ADDON_LOADED")
InitFrame:SetScript("OnEvent", function(self, event, addonName)
if addonName == "SM_CollectionSystem" then
print("收藏系统插件加载:", addonName)
-- 确保SM_CollectionsDB存在
if not SM_CollectionsDB then
SM_CollectionsDB = {
@ -55,7 +53,7 @@ InitFrame:SetScript("OnEvent", function(self, event, addonName)
itemCache = { items = {} }
}
end
-- 确保缓存子表存在
if not SM_CollectionsDB.mountCache then
SM_CollectionsDB.mountCache = { mounts = {} }
@ -69,21 +67,18 @@ InitFrame:SetScript("OnEvent", function(self, event, addonName)
if not SM_CollectionsDB.itemCache then
SM_CollectionsDB.itemCache = { items = {} }
end
-- 确保items子表存在
if not SM_CollectionsDB.itemCache.items then
SM_CollectionsDB.itemCache.items = {}
end
-- 注册插件消息在3.3.5中不需要显式注册前缀)
print("收藏系统消息通道已准备就绪")
-- 设置清理数据库的函数,在每次登录时调用
self:RegisterEvent("PLAYER_LOGIN")
elseif event == "PLAYER_LOGIN" then
-- 在登录时清理过期的缓存条目
SM_Collections.CleanupExpiredCacheEntries()
print("收藏系统玩家登录初始化完成")
end
end)

View File

@ -584,7 +584,6 @@ 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

@ -248,20 +248,14 @@ function SM_Collections:HandleItemsData(msg)
-- 将新收到的数据追加到缓存
self.itemDataCache = self.itemDataCache .. msg
-- 显示获取的原始数据
--print("[物品收藏] 收到服务器物品数据: " .. msg:sub(1, 100) .. "...")
--print("[物品收藏] 当前数据缓存总长度: " .. #self.itemDataCache)
-- 我们暂时不处理数据,而是等待更多批次数据到达
-- 只有当收到回调请求或者达到一定大小时才处理
if not self.pendingCallbacks or not self.pendingCallbacks.items then
--print("[物品收藏] 等待更多数据或回调请求...")
return
end
-- 确保所有服务器数据都已接收等待2秒再处理
if not self.itemDataProcessTimer then
--print("[物品收藏] 开始等待2秒处理服务器数据...")
self.itemDataProcessTimer = true
local processFrame = CreateFrame("Frame")
@ -278,9 +272,6 @@ function SM_Collections:HandleItemsData(msg)
processFrame:Show()
return
end
-- 如果已经设置了定时器,不重复处理
--print("[物品收藏] 已设置处理定时器,等待处理...")
end
-- 新增:处理缓存中的所有物品数据
@ -288,16 +279,9 @@ function SM_Collections:ProcessItemsData()
local data = self:MessageSplit(self.itemDataCache, "|")
local items = {}
-- 显示获取的原始数据总量
--print("[物品收藏] 处理全部缓存数据,共 " .. #data .. " 个字段")
-- 确认每组数据的字段数 - 每个物品固定为5个字段
local fieldsPerItem = 5 -- ID、名称、描述、是否获得、类型
-- 记录处理过程详情
--print("[物品收藏] 服务器数据格式: 每个物品 " .. fieldsPerItem .. " 个字段")
--print("[物品收藏] 理论上应该有 " .. math.floor(#data / fieldsPerItem) .. " 个物品")
-- 循环处理数据严格按照5个字段一组来解析
local validItemCount = 0
local slotItems = {} -- 按物品类型统计数量
@ -312,10 +296,6 @@ function SM_Collections:ProcessItemsData()
local itemType = data[i + 4]
if itemID and itemID > 0 then
-- 记录每个解析的物品
--print(string.format("[物品收藏] 获取到物品ID%s名称%s类型%s是否获得%s",
-- itemID, itemName or "未知", itemType or "未知", obtained and "是" or "否"))
-- 统计不同类型物品的数量
if itemType and itemType ~= "" then
slotItems[itemType] = (slotItems[itemType] or 0) + 1
@ -333,42 +313,29 @@ function SM_Collections:ProcessItemsData()
end
end
end
-- 显示各类型物品数量统计
--print("[物品收藏] 物品类型统计:")
for itemType, count in pairs(slotItems) do
--print(string.format(" - %s: %d个", itemType, count))
end
if self.pendingCallbacks and self.pendingCallbacks.items then
local response = {
success = true,
data = items
}
--print(string.format("[物品收藏] 处理完成,共解析了%d个物品", #items))
self.pendingCallbacks.items(response)
self.pendingCallbacks.items = nil
-- 重置缓存和定时器
self.itemDataCache = ""
self.itemDataProcessTimer = nil
else
--print("[物品收藏] 错误: 没有找到回调函数")
end
end
-- 处理收藏状态更新
function SM_Collections:HandleCollectionUpdate(msg)
print("[收藏更新] 收到消息:", msg)
local data = self:MessageSplit(msg, "|")
if #data >= 3 then
local itemType = data[1]
local itemID = tonumber(data[2])
local isObtained = (data[3] == "1")
print("[收藏更新] 解析消息:", itemType, itemID, isObtained and "已获得" or "未获得")
-- 确保数据结构存在
if not SM_CollectionsDB then
@ -428,11 +395,7 @@ function SM_Collections:HandleCollectionUpdate(msg)
end
if not found and isObtained then
table.insert(SM_CollectionsDB.itemCache.items, {id = itemID, obtained = true})
end
-- 物品收藏更新后,立即重新排序当前显示的物品
print("[收藏更新] 物品获取:", itemID, isObtained and "已获得" or "未获得")
end
-- 立即执行物品排序,不等待延迟
self:ForceItemReordering(itemID)
end
@ -469,7 +432,6 @@ function SM_Collections:HandleCollectionUpdate(msg)
-- 如果是新获得的物品记录到NewItems表中
if isObtained then
self.NewItems.item[itemID] = true
print("[收藏系统] 新获得物品:", itemID)
end
end
@ -604,28 +566,23 @@ end
-- 强制物品重排序,立即执行而不等待延迟
function SM_Collections:ForceItemReordering(updatedItemID)
print("[排序] 强制重排序:", updatedItemID)
-- 确保物品收藏UI存在
if not SM_ItemCollectionUI then
print("[排序] 物品收藏UI不存在无法排序")
return
end
-- 确保物品槽位数据存在
if not SM_ItemCollectionUI.ALL_SLOTS then
print("[排序] 物品槽位数据不存在,无法排序")
if not SM_ItemCollectionUI then
return
end
-- 确保物品槽位数据存在
if not SM_ItemCollectionUI.ALL_SLOTS then
return
end
-- 是否当前显示的是物品面板
local isItemPanelVisible = (SM_Collections.MainFrame and SM_Collections.MainFrame.tabID == 4)
print("[排序] 物品面板是否可见:", isItemPanelVisible)
-- 对所有槽位进行排序
local allSlots = SM_ItemCollectionUI.ALL_SLOTS
local targetSlot = nil
-- 找到包含更新物品的槽位
for _, slot in ipairs(allSlots) do
local containsItem = false
@ -633,37 +590,29 @@ function SM_Collections:ForceItemReordering(updatedItemID)
if tonumber(itemID) == tonumber(updatedItemID) then
targetSlot = slot
containsItem = true
print("[排序] 在槽位", slot.invType, "中找到物品", updatedItemID)
break
end
end
-- 无论是否包含物品,都对该槽位进行排序
if #(slot.items or {}) > 0 then
print("[排序] 对槽位", slot.invType, "进行排序")
SM_ItemCollectionUI:SortSlotItems(slot)
end
end
-- 如果物品面板可见,且找到了包含更新物品的槽位
if isItemPanelVisible and targetSlot then
print("[排序] 物品面板可见,立即刷新")
-- 如果当前显示的正是包含更新物品的槽位
if SM_ItemCollectionUI.currentSelectedButton and
SM_ItemCollectionUI.currentSelectedButton.slotData and
SM_ItemCollectionUI.currentSelectedButton.slotData.invType == targetSlot.invType then
print("[排序] 刷新当前槽位:", targetSlot.invType)
if SM_ItemCollectionUI.currentSelectedButton and
SM_ItemCollectionUI.currentSelectedButton.slotData and
SM_ItemCollectionUI.currentSelectedButton.slotData.invType == targetSlot.invType then
-- 直接重新显示物品预览
SM_ItemCollectionUI:ShowItemPreview(targetSlot, SM_ItemCollectionUI.currentPanel)
-- 强制立即重新加载整个物品面板
SM_Collections:ShowItems()
else
-- 当前显示的不是包含更新物品的槽位,但我们仍然刷新当前显示
print("[排序] 当前显示的不是目标槽位,刷新当前槽位")
local currentSlot = SM_ItemCollectionUI.currentSelectedButton.slotData
SM_ItemCollectionUI:ShowItemPreview(currentSlot, SM_ItemCollectionUI.currentPanel)
end
@ -672,7 +621,6 @@ end
-- 消息处理函数
function SM_Collections_MessageEvent(self, event, prefix, msg, type, sender)
print("收到消息: 事件=", event, "前缀=", prefix, "类型=", type, "发送者=", sender)
if event == 'CHAT_MSG_WHISPER' or event == 'CHAT_MSG_ADDON' then
if prefix == 'SM_S_COLLECTIONS_MOUNTS' then
SM_Collections:HandleMountsData(msg) -- 坐骑
@ -688,7 +636,6 @@ function SM_Collections_MessageEvent(self, event, prefix, msg, type, sender)
SM_Collections:HandleItemAttributesData(msg) -- 物品属性
elseif prefix == "SM_S_COLLECTION_UPDATE" then
print("收到收藏更新消息:", msg)
SM_Collections:HandleCollectionUpdate(msg)
end
@ -704,16 +651,14 @@ SlashCmdList["SM_COLLECTIONS_TEST"] = function(msg)
for word in msg:gmatch("%S+") do
table.insert(args, word)
end
local itemType = args[1] or "item"
local itemID = tonumber(args[2] or "12345")
local status = args[3] or "1"
print("执行测试更新命令: 类型=", itemType, "ID=", itemID, "状态=", status)
-- 构造测试消息
local testMsg = itemType .. "|" .. itemID .. "|" .. status
-- 直接调用处理函数
SM_Collections:HandleCollectionUpdate(testMsg)
end
@ -728,7 +673,6 @@ SM_Collections_EventFrame:SetScript('OnEvent', function(self, event, ...)
local addonName = ...
if addonName == "SM_CollectionSystem" then
print("收藏系统插件加载完成")
-- 在3.3.5中不需要显式注册前缀
end
elseif event == 'CHAT_MSG_ADDON' then
SM_Collections_MessageEvent(self, event, ...)
@ -752,7 +696,6 @@ SM_Collections_EventFrame:SetScript('OnEvent', function(self, event, ...)
prefix == "SM_S_COLLECTIONS_ATTRIBUTES" or
prefix == "SM_S_COLLECTIONS_ITEM_ATTRIBUTES" or
prefix == "SM_S_COLLECTION_UPDATE") then
print("收到系统私聊消息:", prefix, content:sub(1, 50))
SM_Collections_MessageEvent(self, "CHAT_MSG_WHISPER", prefix, content)
end
end

View File

@ -5,7 +5,6 @@
-- 点击处理逻辑
function OnItemClick(button, itemData, itemType, panel)
print("点击处理逻辑")
-- 设置按钮选中状态
if button then
-- 取消其他按钮的选中状态
@ -71,12 +70,10 @@ function OnItemClick(button, itemData, itemType, panel)
local creatureDisplayID = nil
-- 如果服务端已经提供了displayID优先使用它
if itemData.displayID and itemData.displayID > 0 then
print("服务端已经提供了displayID= ", itemData.displayID)
creatureDisplayID = itemData.displayID
else
-- 否则从映射表中获取
creatureDisplayID = SM_Collections:GetCreatureDisplayID(itemData.id, itemType)
print("从映射表中获取")
end
if panel and panel.model and creatureDisplayID and creatureDisplayID > 0 then
@ -85,7 +82,6 @@ function OnItemClick(button, itemData, itemType, panel)
panel.model.zoomLevel = 0
panel.model:Show()
panel.model:SetCreature(creatureDisplayID)
--print("点击显示模型ID = " .. creatureDisplayID)
else
print("无法显示模型: ",
panel and "面板存在" or "面板不存在",
@ -387,13 +383,11 @@ function SM_Collections:CreateListItems(parent, data, itemType, model, nameText,
-- 使用SetScript而不是HookScript确保只有一个处理函数
button:SetScript("OnEnter", function(self)
print("[收藏系统] 按钮鼠标悬停:", itemType, item.id)
if self.newTexture and self.newTexture:IsShown() then
self.newTexture:Hide()
-- 从NewItems表中移除
if SM_Collections.NewItems and SM_Collections.NewItems[itemType] then
SM_Collections.NewItems[itemType][item.id] = nil
print("[收藏系统] 清除NEW标记:", itemType, item.id)
end
end
@ -1007,13 +1001,11 @@ function SM_Collections:RefreshCollectionStatus(itemType, itemID, isObtained)
-- 使用SetScript而不是HookScript确保只有一个处理函数
button:SetScript("OnEnter", function(self)
print("[收藏系统] 按钮鼠标悬停:", itemType, itemID)
if self.newTexture and self.newTexture:IsShown() then
self.newTexture:Hide()
-- 从NewItems表中移除
if SM_Collections.NewItems and SM_Collections.NewItems[itemType] then
SM_Collections.NewItems[itemType][itemID] = nil
print("[收藏系统] 清除NEW标记:", itemType, itemID)
end
end

View File

@ -1,7 +1,6 @@
-- SM_Utils.lua
-- function SM_Collections:MessageSplit(inputstr, sep)
-- print("分割1")
-- if not inputstr or inputstr == "" then
-- return {}
-- end
@ -18,7 +17,6 @@
-- 消息分割函数
function SM_Collections:MessageSplit(msg, delimiter)
print("分割2")
local result = {}
local from = 1
local delim_from, delim_to = string.find(msg, delimiter, from)