优化收藏系统:物品收藏设定为服务端获取数据
This commit is contained in:
parent
a694357f29
commit
57f2c1ec61
@ -19,7 +19,7 @@ function SM_ItemCollectionUI:Init()
|
||||
LoadAddOn("SM_CollectionSystem")
|
||||
end
|
||||
|
||||
print("物品收藏界面初始化")
|
||||
|
||||
|
||||
-- 初始化物品槽位数据
|
||||
self:InitSlotData()
|
||||
@ -30,26 +30,26 @@ end
|
||||
function SM_ItemCollectionUI:InitSlotData()
|
||||
-- 获取物品分类数据
|
||||
local MODEL_SLOTS = {
|
||||
{ name = "头部", invType = "INVTYPE_HEAD", items = { 16908, 16929, 16939, 16947, 16955, 16963, 16983, 16999 }, icon = "Interface\\PaperDoll\\UI-PaperDoll-Slot-Head" },
|
||||
{ name = "肩部", invType = "INVTYPE_SHOULDER", items = { 41870, 42010, 42713, 16868, 47901, 48016, 48062, 48076 }, icon = "Interface\\PaperDoll\\UI-PaperDoll-Slot-Shoulder" },
|
||||
{ name = "背部", invType = "INVTYPE_CLOAK", items = { 17078, 13340, 17102, 46014, 47095, 47232, 47418, 17107 }, icon = "Interface\\PaperDoll\\UI-PaperDoll-Slot-Chest" },
|
||||
{ name = "胸部", invType = "INVTYPE_CHEST", items = { 40989, 41080, 41088, 42659, 42870, 42877, 43129, 43310 }, icon = "Interface\\PaperDoll\\UI-PaperDoll-Slot-Chest" },
|
||||
{ name = "衬衣", invType = "INVTYPE_BODY", items = { 41249, 41250, 41251, 41252, 41253, 41254, 41255, 42360, 42361, 42363, 42365 }, icon = "Interface\\PaperDoll\\UI-PaperDoll-Slot-Shirt" },
|
||||
{ name = "战袍", invType = "INVTYPE_TABARD", items = { 31778, 31779, 31780, 31781, 31804, 32445, 32828, 35221, 35279, 35280, 36941, 38309, 38310, 38311, 38312 }, icon = "Interface\\PaperDoll\\UI-PaperDoll-Slot-Tabard" },
|
||||
{ name = "手腕", invType = "INVTYPE_WRIST", items = { 1182, 1732, 1740, 1748, 1756, 1846, 1852, 2150, 2384, 2390, 2396, 2402, 2421 }, icon = "Interface\\PaperDoll\\UI-PaperDoll-Slot-Wrists" },
|
||||
{ name = "手", invType = "INVTYPE_HAND", items = { 40496, 40498, 40541, 41268, 41284, 41286, 41287, 41288, 41289, 41290, 41291, 41292, 41293 }, icon = "Interface\\PaperDoll\\UI-PaperDoll-Slot-Hands" },
|
||||
{ name = "腰带", invType = "INVTYPE_WAIST", items = { 15347, 15349, 15361, 15369, 15378, 15388, 15399, 15428 }, icon = "Interface\\PaperDoll\\UI-PaperDoll-Slot-Waist" },
|
||||
{ name = "腿", invType = "INVTYPE_LEGS", items = { 7760, 7359, 7929, 7926, 14677, 14668, 14585, 14444 }, icon = "Interface\\PaperDoll\\UI-PaperDoll-Slot-Legs" },
|
||||
{ name = "脚", invType = "INVTYPE_FEET", items = { 43171, 43585, 43839, 43857, 43970, 44021, 44202, 44358, 44673, 44899, 44900, 45135, 45258, 45441, 45483, 45537, 45566 }, icon = "Interface\\PaperDoll\\UI-PaperDoll-Slot-Feet" },
|
||||
{ name = "远程", invType = "INVTYPE_RANGED", items = { 36622, 36623, 36624, 36625, 36626, 36629, 36630, 36632, 36633, 36634, 36635, 36637, 36882, 37023, 37122 }, icon = "Interface\\PaperDoll\\UI-PaperDoll-Slot-Ranged" },
|
||||
{ name = "主手", invType = "INVTYPE_WEAPONMAINHAND", items = { 18803, 18816, 18827, 18832, 18838, 18842, 18844, 18848 }, icon = "Interface\\PaperDoll\\UI-PaperDoll-Slot-MainHand" },
|
||||
{ name = "副手", invType = "INVTYPE_WEAPONMAINHAND", items = { 38175, 38198, 38181, 39127, 39132, 39802, 40004, 42297 }, icon = "Interface\\PaperDoll\\UI-PaperDoll-Slot-Relic" },
|
||||
{ name = "头部", invType = "INVTYPE_HEAD", items = {}, icon = "Interface\\PaperDoll\\UI-PaperDoll-Slot-Head" },
|
||||
{ name = "肩部", invType = "INVTYPE_SHOULDER", items = {}, icon = "Interface\\PaperDoll\\UI-PaperDoll-Slot-Shoulder" },
|
||||
{ name = "背部", invType = "INVTYPE_CLOAK", items = {}, icon = "Interface\\PaperDoll\\UI-PaperDoll-Slot-Chest" },
|
||||
{ name = "胸部", invType = "INVTYPE_CHEST", items = {}, icon = "Interface\\PaperDoll\\UI-PaperDoll-Slot-Chest" },
|
||||
{ name = "衬衣", invType = "INVTYPE_BODY", items = {}, icon = "Interface\\PaperDoll\\UI-PaperDoll-Slot-Shirt" },
|
||||
{ name = "战袍", invType = "INVTYPE_TABARD", items = {}, icon = "Interface\\PaperDoll\\UI-PaperDoll-Slot-Tabard" },
|
||||
{ name = "手腕", invType = "INVTYPE_WRIST", items = {}, icon = "Interface\\PaperDoll\\UI-PaperDoll-Slot-Wrists" },
|
||||
{ name = "手", invType = "INVTYPE_HAND", items = {}, icon = "Interface\\PaperDoll\\UI-PaperDoll-Slot-Hands" },
|
||||
{ name = "腰带", invType = "INVTYPE_WAIST", items = {}, icon = "Interface\\PaperDoll\\UI-PaperDoll-Slot-Waist" },
|
||||
{ name = "腿", invType = "INVTYPE_LEGS", items = {}, icon = "Interface\\PaperDoll\\UI-PaperDoll-Slot-Legs" },
|
||||
{ name = "脚", invType = "INVTYPE_FEET", items = {}, icon = "Interface\\PaperDoll\\UI-PaperDoll-Slot-Feet" },
|
||||
{ name = "远程", invType = "INVTYPE_RANGED", items = {}, icon = "Interface\\PaperDoll\\UI-PaperDoll-Slot-Ranged" },
|
||||
{ name = "主手", invType = "INVTYPE_WEAPONMAINHAND", items = {}, icon = "Interface\\PaperDoll\\UI-PaperDoll-Slot-MainHand" },
|
||||
{ name = "副手", invType = "INVTYPE_WEAPONMAINHAND", items = {}, icon = "Interface\\PaperDoll\\UI-PaperDoll-Slot-Relic" },
|
||||
}
|
||||
|
||||
local ICON_SLOTS = {
|
||||
{ name = "颈部", invType = "INVTYPE_NECK", items = { 50724, 50728, 50763, 50809, 50852, 51008, 51012, 51016, 51331, 51333, 51335, 51347, 51349, 51353, 51355 }, icon = "Interface\\PaperDoll\\UI-PaperDoll-Slot-Neck" },
|
||||
{ name = "戒指", invType = "INVTYPE_FINGER", items = { 51024, 51336, 51358, 51381, 51387, 51557, 51558, 51559, 51560, 51843, 51849, 51855, 51878, 51884, 51900, 51913, 51991, 51992 }, icon = "Interface\\PaperDoll\\UI-PaperDoll-Slot-RFinger" },
|
||||
{ name = "饰品", invType = "INVTYPE_TRINKET", items = { 47728, 47734, 47735, 47879, 47880, 47881, 47882, 47946, 47947, 47948, 47949, 48018, 48019, 48020, 48021, 48722, 48724 }, icon = "Interface\\PaperDoll\\UI-PaperDoll-Slot-Trinket" },
|
||||
{ name = "颈部", invType = "INVTYPE_NECK", items = {}, icon = "Interface\\PaperDoll\\UI-PaperDoll-Slot-Neck" },
|
||||
{ name = "戒指", invType = "INVTYPE_FINGER", items = {}, icon = "Interface\\PaperDoll\\UI-PaperDoll-Slot-RFinger" },
|
||||
{ name = "饰品", invType = "INVTYPE_TRINKET", items = {}, icon = "Interface\\PaperDoll\\UI-PaperDoll-Slot-Trinket" },
|
||||
}
|
||||
|
||||
-- 合并所有槽位到一个数组
|
||||
@ -139,6 +139,13 @@ end
|
||||
|
||||
-- 辅助函数:应用摄像机参数
|
||||
function SM_ItemCollectionUI:ApplyCamera(model, cameraID)
|
||||
-- 确保cameraID是有效的数值ID
|
||||
if type(cameraID) == "string" then
|
||||
-- 如果传入的是字符串ID,需要转换为数值ID
|
||||
print("警告:传入了字符串相机ID: " .. cameraID .. ",应该使用GetCharacterCameraID或GetWeaponCameraID获取数值ID")
|
||||
return
|
||||
end
|
||||
|
||||
local params = SM_CeShiModel.Cameras[cameraID]
|
||||
|
||||
if params then
|
||||
@ -302,7 +309,7 @@ end
|
||||
-- 处理按钮点击事件
|
||||
function SM_ItemCollectionUI:HandleButtonClick(slot)
|
||||
if not self.currentPanel then
|
||||
print("错误:没有有效的面板对象")
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
@ -348,6 +355,35 @@ function SM_ItemCollectionUI:ShowItemPreview(slot, panel)
|
||||
|
||||
-- 判断是否是图标类物品
|
||||
local isIconOnly = (slot.invType == "INVTYPE_NECK" or slot.invType == "INVTYPE_FINGER" or slot.invType == "INVTYPE_TRINKET")
|
||||
|
||||
-- 检查槽位是否有物品
|
||||
if #slot.items == 0 then
|
||||
-- 如果没有物品,显示一个提示信息
|
||||
local noItemsText = previewFrame:CreateFontString(nil, "OVERLAY")
|
||||
noItemsText:SetFont("Fonts\\ZYKai_T.ttf", 16, "OUTLINE")
|
||||
noItemsText:SetPoint("CENTER", previewFrame, "CENTER", 0, 0)
|
||||
noItemsText:SetText("该分类下暂无物品数据")
|
||||
noItemsText:SetTextColor(1, 0.82, 0)
|
||||
noItemsText:Show()
|
||||
|
||||
-- 更新右侧信息面板
|
||||
if SM_Collections.MainFrame and SM_Collections.MainFrame.RightSidePanel then
|
||||
if SM_Collections.MainFrame.RightSidePanel.MountNama then
|
||||
SM_Collections.MainFrame.RightSidePanel.MountNama:SetText("无物品")
|
||||
end
|
||||
|
||||
if SM_Collections.MainFrame.RightSidePanel.introText then
|
||||
SM_Collections.MainFrame.RightSidePanel.introText:SetText("类型: " .. slot.name .. "\n暂无物品数据")
|
||||
end
|
||||
|
||||
-- 清空属性加成显示
|
||||
if SM_Collections.MainFrame.RightSidePanel.AttributeBonusFrame then
|
||||
SM_Collections.MainFrame.RightSidePanel.AttributeBonusFrame:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
if isIconOnly then
|
||||
-- 为图标类物品创建预览,现在也使用WardrobeItemsModelTemplate
|
||||
@ -454,207 +490,234 @@ function SM_ItemCollectionUI:ShowItemPreview(slot, panel)
|
||||
-- 创建物品模型预览(现有代码保持不变)
|
||||
local modelFrames = {}
|
||||
|
||||
for j = 1, 8 do
|
||||
for j = 1, #slot.items do
|
||||
local itemID = slot.items[j]
|
||||
if not itemID then break end
|
||||
|
||||
-- 使用 SM_CollectionSystemWardrobeItemsModelTemplate 创建模型,替换原有的自定义框架
|
||||
local model = CreateFrame("DressUpModel", nil, previewFrame, "SM_CollectionSystemWardrobeItemsModelTemplate")
|
||||
model:SetSize(78, 104) -- 使用模板定义的尺寸 (78x104)
|
||||
|
||||
-- 计算位置,调整间距以适应新的模板尺寸
|
||||
local row = math.floor((j - 1) / 6)
|
||||
local col = (j - 1) % 6
|
||||
model:SetPoint("TOPLEFT", 24 + col * 92, -38 - row * 120) -- 调整间距从130改为90,从150改为120
|
||||
|
||||
-- 模板已经包含了所有必要的视觉元素,无需手动创建背景和边框
|
||||
-- 包括:SolidBackground, Border, TransmogStateTexture, Highlight, NewString, NewGlow, Favorite.Icon, HideVisual.Icon
|
||||
|
||||
model:Show()
|
||||
|
||||
-- 确保初始状态下选中图标是隐藏的
|
||||
if model.TransmogStateTexture then
|
||||
model.TransmogStateTexture:Hide()
|
||||
end
|
||||
|
||||
table.insert(modelFrames, model)
|
||||
|
||||
-- 添加交互功能 - 直接在模型上设置,而不是在边框层
|
||||
model:EnableMouse(true)
|
||||
model:SetScript("OnEnter", function(self)
|
||||
-- 模板的高亮效果会自动显示,无需手动控制
|
||||
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
|
||||
GameTooltip:SetHyperlink("item:" .. itemID)
|
||||
GameTooltip:Show()
|
||||
end)
|
||||
|
||||
model:SetScript("OnLeave", function(self)
|
||||
-- 模板的高亮效果会自动隐藏
|
||||
GameTooltip:Hide()
|
||||
end)
|
||||
|
||||
-- 使用局部变量来确保闭包捕获正确的引用
|
||||
local currentItemID = itemID
|
||||
local currentModel = model
|
||||
|
||||
model:SetScript("OnMouseDown", function(self)
|
||||
-- 设置选中状态(会自动清除之前的选中状态)
|
||||
SM_ItemCollectionUI:SelectModel(currentModel)
|
||||
|
||||
-- print("点击了物品:", currentItemID)
|
||||
|
||||
-- 更新右侧面板信息
|
||||
if SM_Collections.MainFrame and SM_Collections.MainFrame.RightSidePanel then
|
||||
local itemName = GetItemInfo(currentItemID)
|
||||
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: " ..
|
||||
currentItemID .. "\n类型: " .. slot.name)
|
||||
end
|
||||
|
||||
-- 更新属性加成
|
||||
SM_ItemCollectionUI:UpdateAttributes(currentItemID, slot.invType)
|
||||
|
||||
-- 防止无效物品ID导致客户端崩溃
|
||||
if type(itemID) ~= "number" or itemID <= 0 then
|
||||
print(string.format("[物品收藏] 跳过无效的物品ID: %s", tostring(itemID)))
|
||||
-- 使用do-continue模式替代goto
|
||||
do
|
||||
-- 这里相当于continue,跳过剩余代码直接进入下一次循环
|
||||
-- Lua 5.1不支持goto,所以使用这种方式模拟continue
|
||||
end
|
||||
end)
|
||||
else
|
||||
-- 在else块中放置原来goto前的所有代码
|
||||
-- 使用 SM_CollectionSystemWardrobeItemsModelTemplate 创建模型,替换原有的自定义框架
|
||||
local model = CreateFrame("DressUpModel", nil, previewFrame, "SM_CollectionSystemWardrobeItemsModelTemplate")
|
||||
model:SetSize(78, 104) -- 使用模板定义的尺寸 (78x104)
|
||||
|
||||
-- 不同装备类型的显示逻辑保持不变
|
||||
if slot.invType == "INVTYPE_WEAPONMAINHAND" or slot.invType == "INVTYPE_WEAPONOFFHAND" then
|
||||
model:ClearModel()
|
||||
-- 设置模型类型和预览动画
|
||||
if slot.invType == "INVTYPE_WEAPONMAINHAND" then
|
||||
self:SetModelType(model, "main")
|
||||
else
|
||||
self:SetModelType(model, "off")
|
||||
-- 计算位置,调整间距以适应新的模板尺寸
|
||||
local row = math.floor((j - 1) / 6)
|
||||
local col = (j - 1) % 6
|
||||
model:SetPoint("TOPLEFT", 24 + col * 92, -38 - row * 120) -- 调整间距从130改为90,从150改为120
|
||||
|
||||
-- 模板已经包含了所有必要的视觉元素,无需手动创建背景和边框
|
||||
-- 包括:SolidBackground, Border, TransmogStateTexture, Highlight, NewString, NewGlow, Favorite.Icon, HideVisual.Icon
|
||||
|
||||
model:Show()
|
||||
|
||||
-- 确保初始状态下选中图标是隐藏的
|
||||
if model.TransmogStateTexture then
|
||||
model.TransmogStateTexture:Hide()
|
||||
end
|
||||
|
||||
model:Undress()
|
||||
model:TryOn(itemID)
|
||||
table.insert(modelFrames, model)
|
||||
|
||||
-- 应用摄像机参数
|
||||
local weaponCameraID = SM_CeShiModel:GetWeaponCameraID(slot.invType)
|
||||
self:ApplyCamera(model, weaponCameraID)
|
||||
elseif slot.invType == "INVTYPE_RANGED" then
|
||||
model:ClearModel()
|
||||
model:SetUnit("player")
|
||||
model.animID = ANIMATION_RANGED_PREVIEW
|
||||
|
||||
model:Undress()
|
||||
model:TryOn(itemID)
|
||||
|
||||
-- 应用摄像机参数
|
||||
local cameraID = SM_CeShiModel:GetCharacterCameraID(slot.invType)
|
||||
self:ApplyCamera(model, cameraID)
|
||||
|
||||
-- 添加模型旋转功能
|
||||
-- 添加交互功能 - 直接在模型上设置,而不是在边框层
|
||||
model:EnableMouse(true)
|
||||
|
||||
-- 启用鼠标滚轮
|
||||
model:EnableMouseWheel(true)
|
||||
|
||||
-- 使用旋转状态变量
|
||||
model.isRotating = false
|
||||
model.lastX = 0
|
||||
|
||||
-- 保存当前模型引用,用于在事件处理中使用
|
||||
local currentModel = model
|
||||
local currentItemID = itemID
|
||||
|
||||
-- 为每个模型创建一个独立的更新帧
|
||||
local updateFrame = CreateFrame("Frame", nil, model)
|
||||
updateFrame:SetScript("OnUpdate", function(self, elapsed)
|
||||
if currentModel.isRotating then
|
||||
local x = GetCursorPosition()
|
||||
local delta = (x - (currentModel.lastX or x)) * 0.01
|
||||
currentModel.lastX = x
|
||||
currentModel:SetFacing(currentModel:GetFacing() + delta)
|
||||
end
|
||||
model:SetScript("OnEnter", function(self)
|
||||
-- 模板的高亮效果会自动显示,无需手动控制
|
||||
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
|
||||
GameTooltip:SetHyperlink("item:" .. itemID)
|
||||
GameTooltip:Show()
|
||||
end)
|
||||
|
||||
-- 添加鼠标事件
|
||||
model:SetScript("OnMouseDown", function(self, button)
|
||||
if button == "LeftButton" then
|
||||
-- 选中模型并更新右侧信息
|
||||
SM_ItemCollectionUI:SelectModel(currentModel)
|
||||
|
||||
-- 更新右侧面板信息
|
||||
if SM_Collections.MainFrame and SM_Collections.MainFrame.RightSidePanel then
|
||||
local itemName = GetItemInfo(currentItemID)
|
||||
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: " ..
|
||||
currentItemID .. "\n类型: " .. slot.name)
|
||||
end
|
||||
|
||||
-- 更新属性加成
|
||||
SM_ItemCollectionUI:UpdateAttributes(currentItemID, slot.invType)
|
||||
end
|
||||
|
||||
-- 启用旋转模式
|
||||
self.isRotating = true
|
||||
self.lastX = GetCursorPosition()
|
||||
end
|
||||
end)
|
||||
|
||||
-- 添加鼠标滚轮事件
|
||||
model:SetScript("OnMouseWheel", function(self, delta)
|
||||
-- delta为1表示向上滚动,为-1表示向下滚动
|
||||
local rotationAmount = math.rad(15) -- 每次旋转15度
|
||||
|
||||
-- 向上滚动向右旋转,向下滚动向左旋转
|
||||
self:SetFacing(self:GetFacing() - (delta * rotationAmount))
|
||||
end)
|
||||
|
||||
model:SetScript("OnMouseUp", function(self, button)
|
||||
if button == "LeftButton" then
|
||||
self.isRotating = false
|
||||
end
|
||||
end)
|
||||
|
||||
-- 确保鼠标离开时停止旋转
|
||||
model:SetScript("OnLeave", function(self)
|
||||
if self.isRotating then
|
||||
self.isRotating = false
|
||||
end
|
||||
|
||||
-- 隐藏工具提示
|
||||
-- 模板的高亮效果会自动隐藏
|
||||
GameTooltip:Hide()
|
||||
end)
|
||||
else
|
||||
-- 常规装备显示逻辑
|
||||
self:SetModelType(model, "player")
|
||||
model:TryOn(itemID)
|
||||
|
||||
local cameraID = SM_CeShiModel:GetCharacterCameraID(slot.invType)
|
||||
self:ApplyCamera(model, cameraID)
|
||||
end
|
||||
-- 使用局部变量来确保闭包捕获正确的引用
|
||||
local currentItemID = itemID
|
||||
local currentModel = model
|
||||
|
||||
-- 应用冻结动画
|
||||
self:FreezeAnimation(model)
|
||||
model:SetScript("OnMouseDown", function(self)
|
||||
-- 设置选中状态(会自动清除之前的选中状态)
|
||||
SM_ItemCollectionUI:SelectModel(currentModel)
|
||||
|
||||
-- 可选:设置模板的额外功能
|
||||
-- 如果需要显示新物品标识
|
||||
if model.NewString and model.NewGlow then
|
||||
-- 根据需要显示或隐藏新物品标识
|
||||
-- model.NewString:Show()
|
||||
-- model.NewGlow:Show()
|
||||
end
|
||||
-- print("点击了物品:", currentItemID)
|
||||
|
||||
-- 如果需要显示收藏状态
|
||||
if model.Favorite and model.Favorite.Icon then
|
||||
-- 根据收藏状态显示或隐藏收藏图标
|
||||
-- model.Favorite.Icon:Show()
|
||||
end
|
||||
-- 更新右侧面板信息
|
||||
if SM_Collections.MainFrame and SM_Collections.MainFrame.RightSidePanel then
|
||||
local itemName = GetItemInfo(currentItemID)
|
||||
if SM_Collections.MainFrame.RightSidePanel.MountNama then
|
||||
SM_Collections.MainFrame.RightSidePanel.MountNama:SetText(itemName or "")
|
||||
end
|
||||
|
||||
-- 如果需要显示隐藏状态
|
||||
if model.HideVisual and model.HideVisual.Icon then
|
||||
-- 根据隐藏状态显示或隐藏图标
|
||||
-- model.HideVisual.Icon:Show()
|
||||
if SM_Collections.MainFrame.RightSidePanel.introText then
|
||||
SM_Collections.MainFrame.RightSidePanel.introText:SetText("物品ID: " ..
|
||||
currentItemID .. "\n类型: " .. slot.name)
|
||||
end
|
||||
|
||||
-- 更新属性加成
|
||||
SM_ItemCollectionUI:UpdateAttributes(currentItemID, slot.invType)
|
||||
end
|
||||
end)
|
||||
|
||||
-- 不同装备类型的显示逻辑保持不变
|
||||
if slot.invType == "INVTYPE_WEAPONMAINHAND" or slot.invType == "INVTYPE_WEAPONOFFHAND" then
|
||||
model:ClearModel()
|
||||
-- 设置模型类型和预览动画
|
||||
if slot.invType == "INVTYPE_WEAPONMAINHAND" then
|
||||
self:SetModelType(model, "main")
|
||||
else
|
||||
self:SetModelType(model, "off")
|
||||
end
|
||||
|
||||
model:Undress()
|
||||
|
||||
-- 使用pcall避免TryOn失败导致的错误
|
||||
local success, error = pcall(function() model:TryOn(itemID) end)
|
||||
if not success then
|
||||
print(string.format("[物品收藏] 警告: 模型无法装备物品 %d: %s", itemID, error))
|
||||
end
|
||||
|
||||
-- 应用摄像机参数 - 使用GetWeaponCameraID获取正确的数值ID
|
||||
local weaponCameraID = SM_CeShiModel:GetWeaponCameraID(slot.invType)
|
||||
self:ApplyCamera(model, weaponCameraID)
|
||||
elseif slot.invType == "INVTYPE_RANGED" then
|
||||
model:ClearModel()
|
||||
model:SetUnit("player")
|
||||
model.animID = ANIMATION_RANGED_PREVIEW
|
||||
|
||||
model:Undress()
|
||||
|
||||
-- 使用pcall避免TryOn失败导致的错误
|
||||
local success, error = pcall(function() model:TryOn(itemID) end)
|
||||
if not success then
|
||||
print(string.format("[物品收藏] 警告: 模型无法装备物品 %d: %s", itemID, error))
|
||||
end
|
||||
|
||||
-- 应用摄像机参数 - 使用GetCharacterCameraID获取正确的数值ID
|
||||
local cameraID = SM_CeShiModel:GetCharacterCameraID(slot.invType)
|
||||
self:ApplyCamera(model, cameraID)
|
||||
|
||||
-- 添加模型旋转功能
|
||||
model:EnableMouse(true)
|
||||
|
||||
-- 启用鼠标滚轮
|
||||
model:EnableMouseWheel(true)
|
||||
|
||||
-- 使用旋转状态变量
|
||||
model.isRotating = false
|
||||
model.lastX = 0
|
||||
|
||||
-- 保存当前模型引用,用于在事件处理中使用
|
||||
local currentModel = model
|
||||
local currentItemID = itemID
|
||||
|
||||
-- 为每个模型创建一个独立的更新帧
|
||||
local updateFrame = CreateFrame("Frame", nil, model)
|
||||
updateFrame:SetScript("OnUpdate", function(self, elapsed)
|
||||
if currentModel.isRotating then
|
||||
local x = GetCursorPosition()
|
||||
local delta = (x - (currentModel.lastX or x)) * 0.01
|
||||
currentModel.lastX = x
|
||||
currentModel:SetFacing(currentModel:GetFacing() + delta)
|
||||
end
|
||||
end)
|
||||
|
||||
-- 添加鼠标事件
|
||||
model:SetScript("OnMouseDown", function(self, button)
|
||||
if button == "LeftButton" then
|
||||
-- 选中模型并更新右侧信息
|
||||
SM_ItemCollectionUI:SelectModel(currentModel)
|
||||
|
||||
-- 更新右侧面板信息
|
||||
if SM_Collections.MainFrame and SM_Collections.MainFrame.RightSidePanel then
|
||||
local itemName = GetItemInfo(currentItemID)
|
||||
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: " ..
|
||||
currentItemID .. "\n类型: " .. slot.name)
|
||||
end
|
||||
|
||||
-- 更新属性加成
|
||||
SM_ItemCollectionUI:UpdateAttributes(currentItemID, slot.invType)
|
||||
end
|
||||
|
||||
-- 启用旋转模式
|
||||
self.isRotating = true
|
||||
self.lastX = GetCursorPosition()
|
||||
end
|
||||
end)
|
||||
|
||||
-- 添加鼠标滚轮事件
|
||||
model:SetScript("OnMouseWheel", function(self, delta)
|
||||
-- delta为1表示向上滚动,为-1表示向下滚动
|
||||
local rotationAmount = math.rad(15) -- 每次旋转15度
|
||||
|
||||
-- 向上滚动向右旋转,向下滚动向左旋转
|
||||
self:SetFacing(self:GetFacing() - (delta * rotationAmount))
|
||||
end)
|
||||
|
||||
model:SetScript("OnMouseUp", function(self, button)
|
||||
if button == "LeftButton" then
|
||||
self.isRotating = false
|
||||
end
|
||||
end)
|
||||
|
||||
-- 确保鼠标离开时停止旋转
|
||||
model:SetScript("OnLeave", function(self)
|
||||
if self.isRotating then
|
||||
self.isRotating = false
|
||||
end
|
||||
|
||||
-- 隐藏工具提示
|
||||
GameTooltip:Hide()
|
||||
end)
|
||||
else
|
||||
-- 常规装备显示逻辑
|
||||
self:SetModelType(model, "player")
|
||||
|
||||
-- 使用pcall避免TryOn失败导致的错误
|
||||
local success, error = pcall(function() model:TryOn(itemID) end)
|
||||
if not success then
|
||||
print(string.format("[物品收藏] 警告: 模型无法装备物品 %d: %s", itemID, error))
|
||||
end
|
||||
|
||||
-- 应用摄像机参数 - 使用GetCharacterCameraID获取正确的数值ID
|
||||
local cameraID = SM_CeShiModel:GetCharacterCameraID(slot.invType)
|
||||
self:ApplyCamera(model, cameraID)
|
||||
end
|
||||
|
||||
-- 应用冻结动画
|
||||
self:FreezeAnimation(model)
|
||||
|
||||
-- 可选:设置模板的额外功能
|
||||
-- 如果需要显示新物品标识
|
||||
if model.NewString and model.NewGlow then
|
||||
-- 根据需要显示或隐藏新物品标识
|
||||
-- model.NewString:Show()
|
||||
-- model.NewGlow:Show()
|
||||
end
|
||||
|
||||
-- 如果需要显示收藏状态
|
||||
if model.Favorite and model.Favorite.Icon then
|
||||
-- 根据收藏状态显示或隐藏收藏图标
|
||||
-- model.Favorite.Icon:Show()
|
||||
end
|
||||
|
||||
-- 如果需要显示隐藏状态
|
||||
if model.HideVisual and model.HideVisual.Icon then
|
||||
-- 根据隐藏状态显示或隐藏图标
|
||||
-- model.HideVisual.Icon:Show()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -837,7 +900,7 @@ function SM_ItemCollectionUI:CreateButtons()
|
||||
-- 关键改动:将slot对象存储在按钮上,而不是依赖闭包
|
||||
btn.slotData = slot
|
||||
btn:SetScript("OnClick", function(self)
|
||||
print("当前选中= ", self:GetID())
|
||||
|
||||
-- 播放点击音效
|
||||
PlaySound("igSpellBookSpellIconPickup")
|
||||
|
||||
@ -866,8 +929,6 @@ end
|
||||
|
||||
-- 显示物品收藏界面
|
||||
function SM_ItemCollectionUI:ShowItemCollectionUI(parent)
|
||||
print("显示物品收藏界面")
|
||||
|
||||
-- 确保已初始化
|
||||
if not self.initialized then
|
||||
self:Init()
|
||||
@ -919,6 +980,241 @@ function SM_ItemCollectionUI:ShowItemCollectionUI(parent)
|
||||
end
|
||||
end
|
||||
|
||||
-- 创建一个等待提示
|
||||
local waitingText = panel:CreateFontString(nil, "OVERLAY")
|
||||
waitingText:SetFont("Fonts\\ZYKai_T.ttf", 16, "OUTLINE")
|
||||
waitingText:SetPoint("CENTER", panel, "CENTER", 0, 0)
|
||||
waitingText:SetText("正在从服务器获取物品数据...")
|
||||
waitingText:SetTextColor(1, 0.82, 0)
|
||||
waitingText:Show()
|
||||
panel.waitingText = waitingText
|
||||
|
||||
-- 在处理数据前清空并重置所有槽位的物品数组
|
||||
for _, slot in ipairs(self.ALL_SLOTS) do
|
||||
slot.items = {}
|
||||
end
|
||||
|
||||
-- 创建槽位映射表,便于按类型分配物品
|
||||
local slotTypeMap = {
|
||||
["头部"] = "INVTYPE_HEAD",
|
||||
["肩部"] = "INVTYPE_SHOULDER",
|
||||
["背部"] = "INVTYPE_CLOAK",
|
||||
["胸部"] = "INVTYPE_CHEST",
|
||||
["衬衣"] = "INVTYPE_BODY",
|
||||
["战袍"] = "INVTYPE_TABARD",
|
||||
["手腕"] = "INVTYPE_WRIST",
|
||||
["手"] = "INVTYPE_HAND",
|
||||
["腰带"] = "INVTYPE_WAIST",
|
||||
["腿"] = "INVTYPE_LEGS",
|
||||
["脚"] = "INVTYPE_FEET",
|
||||
["远程"] = "INVTYPE_RANGED",
|
||||
["主手"] = "INVTYPE_WEAPONMAINHAND",
|
||||
["副手"] = "INVTYPE_WEAPONOFFHAND",
|
||||
["颈部"] = "INVTYPE_NECK",
|
||||
["戒指"] = "INVTYPE_FINGER",
|
||||
["饰品"] = "INVTYPE_TRINKET"
|
||||
}
|
||||
|
||||
-- 新增: 辅助函数,根据服务器返回的物品类型获取对应的装备位置类型
|
||||
function self:GetItemEquipLocFromServerData(serverItemType)
|
||||
-- 直接转换中文类型名称到装备位置
|
||||
if slotTypeMap[serverItemType] then
|
||||
return slotTypeMap[serverItemType]
|
||||
end
|
||||
|
||||
-- 尝试匹配部分名称
|
||||
for typeName, invType in pairs(slotTypeMap) do
|
||||
if string.find(serverItemType, typeName) then
|
||||
return invType
|
||||
end
|
||||
end
|
||||
|
||||
-- 根据关键词进行更广泛的匹配
|
||||
local lowerType = string.lower(serverItemType)
|
||||
if string.find(lowerType, "头") then
|
||||
return "INVTYPE_HEAD"
|
||||
elseif string.find(lowerType, "肩") then
|
||||
return "INVTYPE_SHOULDER"
|
||||
elseif string.find(lowerType, "披风") or string.find(lowerType, "斗篷") or string.find(lowerType, "背") then
|
||||
return "INVTYPE_CLOAK"
|
||||
elseif string.find(lowerType, "胸") or string.find(lowerType, "上衣") then
|
||||
return "INVTYPE_CHEST"
|
||||
elseif string.find(lowerType, "衬衫") or string.find(lowerType, "衬衣") then
|
||||
return "INVTYPE_BODY"
|
||||
elseif string.find(lowerType, "战袍") or string.find(lowerType, "徽章") then
|
||||
return "INVTYPE_TABARD"
|
||||
elseif string.find(lowerType, "腕") or string.find(lowerType, "护腕") then
|
||||
return "INVTYPE_WRIST"
|
||||
elseif string.find(lowerType, "手套") or (string.find(lowerType, "手") and not string.find(lowerType, "武器")) then
|
||||
return "INVTYPE_HAND"
|
||||
elseif string.find(lowerType, "腰") or string.find(lowerType, "带") then
|
||||
return "INVTYPE_WAIST"
|
||||
elseif string.find(lowerType, "腿") or string.find(lowerType, "裤") then
|
||||
return "INVTYPE_LEGS"
|
||||
elseif string.find(lowerType, "脚") or string.find(lowerType, "鞋") or string.find(lowerType, "靴") then
|
||||
return "INVTYPE_FEET"
|
||||
elseif string.find(lowerType, "远程") or string.find(lowerType, "弓") or string.find(lowerType, "枪") then
|
||||
return "INVTYPE_RANGED"
|
||||
elseif string.find(lowerType, "主手") or string.find(lowerType, "双手武器") or
|
||||
string.find(lowerType, "单手武器") or string.find(lowerType, "法杖") then
|
||||
return "INVTYPE_WEAPONMAINHAND"
|
||||
elseif string.find(lowerType, "副手") or string.find(lowerType, "盾") then
|
||||
return "INVTYPE_WEAPONOFFHAND"
|
||||
elseif string.find(lowerType, "颈") or string.find(lowerType, "项链") then
|
||||
return "INVTYPE_NECK"
|
||||
elseif string.find(lowerType, "戒指") or string.find(lowerType, "指环") then
|
||||
return "INVTYPE_FINGER"
|
||||
elseif string.find(lowerType, "饰品") or string.find(lowerType, "护符") then
|
||||
return "INVTYPE_TRINKET"
|
||||
end
|
||||
|
||||
-- 如果无法匹配,返回nil
|
||||
return nil
|
||||
end
|
||||
|
||||
-- 从服务器请求物品数据
|
||||
SM_Collections.DataManager:GetItems(function(items)
|
||||
-- 隐藏等待提示
|
||||
if panel.waitingText then
|
||||
panel.waitingText:Hide()
|
||||
end
|
||||
|
||||
-- 显示调试信息
|
||||
print("[物品收藏] 从服务器获取到 " .. #items .. " 个物品")
|
||||
|
||||
-- 按物品类型整理到各个槽位中
|
||||
for i, item in ipairs(items) do
|
||||
-- 确保物品ID是有效的数值
|
||||
local itemID = tonumber(item.id)
|
||||
if itemID and itemID > 0 then
|
||||
-- 从服务器数据中获取物品类型
|
||||
local itemEquipLoc = nil
|
||||
|
||||
-- 首先使用服务器返回的itemType字段
|
||||
if item.itemType and item.itemType ~= "" then
|
||||
-- 使用新增的辅助函数解析服务器返回的类型
|
||||
itemEquipLoc = self:GetItemEquipLocFromServerData(item.itemType)
|
||||
if itemEquipLoc then
|
||||
print(string.format("[物品收藏] 物品 %d (%s) 使用服务器返回的类型: %s -> %s",
|
||||
itemID, item.name, item.itemType, itemEquipLoc))
|
||||
else
|
||||
print(string.format("[物品收藏] 物品 %d (%s) 服务器类型无法识别: %s",
|
||||
itemID, item.name, tostring(item.itemType)))
|
||||
end
|
||||
end
|
||||
|
||||
-- 如果没有通过服务器获取到有效的类型,尝试API
|
||||
if not itemEquipLoc then
|
||||
-- 尝试通过API获取物品信息
|
||||
local _, _, _, _, _, _, _, apiEquipLoc = GetItemInfo(itemID)
|
||||
if apiEquipLoc and apiEquipLoc ~= "" then
|
||||
itemEquipLoc = apiEquipLoc
|
||||
print(string.format("[物品收藏] 物品 %d (%s) 使用API获取的类型: %s",
|
||||
itemID, item.name, itemEquipLoc))
|
||||
else
|
||||
-- 如果没有类型信息,根据物品描述和名称尝试推断
|
||||
-- 尝试根据物品名称或描述猜测
|
||||
local desc = item.description and string.lower(item.description) or ""
|
||||
local name = item.name and string.lower(item.name) or ""
|
||||
|
||||
-- 基于名称和描述的关键词匹配
|
||||
if string.find(name, "头盔") or string.find(name, "头饰") or string.find(name, "头巾") or
|
||||
string.find(desc, "头部") then
|
||||
itemEquipLoc = "INVTYPE_HEAD"
|
||||
elseif string.find(name, "肩膀") or string.find(name, "护肩") or
|
||||
string.find(desc, "肩部") then
|
||||
itemEquipLoc = "INVTYPE_SHOULDER"
|
||||
elseif string.find(name, "披风") or string.find(name, "斗篷") or
|
||||
string.find(desc, "背部") then
|
||||
itemEquipLoc = "INVTYPE_CLOAK"
|
||||
elseif string.find(name, "胸甲") or string.find(name, "上衣") or
|
||||
string.find(desc, "胸部") then
|
||||
itemEquipLoc = "INVTYPE_CHEST"
|
||||
elseif string.find(name, "衬衫") or string.find(desc, "衬衣") then
|
||||
itemEquipLoc = "INVTYPE_BODY"
|
||||
elseif string.find(name, "战袍") or string.find(desc, "徽章") then
|
||||
itemEquipLoc = "INVTYPE_TABARD"
|
||||
elseif string.find(name, "护腕") or string.find(desc, "手腕") then
|
||||
itemEquipLoc = "INVTYPE_WRIST"
|
||||
elseif string.find(name, "手套") or string.find(desc, "手") then
|
||||
itemEquipLoc = "INVTYPE_HAND"
|
||||
elseif string.find(name, "腰带") or string.find(desc, "腰部") then
|
||||
itemEquipLoc = "INVTYPE_WAIST"
|
||||
elseif string.find(name, "腿甲") or string.find(desc, "腿") then
|
||||
itemEquipLoc = "INVTYPE_LEGS"
|
||||
elseif string.find(name, "靴子") or string.find(desc, "脚") then
|
||||
itemEquipLoc = "INVTYPE_FEET"
|
||||
elseif string.find(name, "弓") or string.find(name, "枪") or
|
||||
string.find(desc, "远程") then
|
||||
itemEquipLoc = "INVTYPE_RANGED"
|
||||
elseif string.find(desc, "主手") or string.find(name, "双手") or
|
||||
string.find(name, "剑") or string.find(name, "斧") or
|
||||
string.find(name, "锤") or string.find(name, "匕首") or
|
||||
string.find(name, "法杖") or string.find(name, "魔杖") then
|
||||
itemEquipLoc = "INVTYPE_WEAPONMAINHAND"
|
||||
elseif string.find(desc, "副手") or string.find(name, "盾") then
|
||||
itemEquipLoc = "INVTYPE_WEAPONOFFHAND"
|
||||
elseif string.find(name, "项链") or string.find(desc, "颈部") then
|
||||
itemEquipLoc = "INVTYPE_NECK"
|
||||
elseif string.find(name, "戒指") or string.find(desc, "手指") then
|
||||
itemEquipLoc = "INVTYPE_FINGER"
|
||||
elseif string.find(name, "饰品") or string.find(desc, "饰品") then
|
||||
itemEquipLoc = "INVTYPE_TRINKET"
|
||||
end
|
||||
|
||||
if itemEquipLoc then
|
||||
print(string.format("[物品收藏] 物品 %d (%s) 通过名称/描述推断类型: %s",
|
||||
itemID, item.name, itemEquipLoc))
|
||||
else
|
||||
-- 如果完全无法确定类型,根据ID进行最后的兜底分配
|
||||
-- 使用物品ID的余数来分配槽位 (仅作为最后的处理手段)
|
||||
local slotIndex = (itemID % #self.ALL_SLOTS) + 1
|
||||
itemEquipLoc = self.ALL_SLOTS[slotIndex].invType
|
||||
print(string.format("[物品收藏] 物品 %d (%s) 无法确定类型,通过ID随机分配: %s",
|
||||
itemID, item.name, itemEquipLoc))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- 查找对应的槽位并添加物品
|
||||
local slotFound = false
|
||||
for j, slot in ipairs(self.ALL_SLOTS) do
|
||||
if slot.invType == itemEquipLoc then
|
||||
-- 避免重复添加相同物品ID
|
||||
local exists = false
|
||||
for _, existingID in ipairs(slot.items) do
|
||||
if existingID == itemID then
|
||||
exists = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if not exists then
|
||||
-- 将物品添加到对应的槽位
|
||||
table.insert(slot.items, itemID)
|
||||
slotFound = true
|
||||
end
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if not slotFound then
|
||||
print(string.format("[物品收藏] 警告: 物品 %d (%s) 未找到对应槽位,类型: %s",
|
||||
itemID, item.name, tostring(itemEquipLoc)))
|
||||
end
|
||||
else
|
||||
print("[物品收藏] 跳过无效的物品ID: " .. tostring(item.id))
|
||||
end
|
||||
end
|
||||
|
||||
-- 统计每个槽位的物品数量并打印
|
||||
for j, slot in ipairs(self.ALL_SLOTS) do
|
||||
print(string.format("[物品收藏] 槽位 %s 包含 %d 个物品", slot.name, #slot.items))
|
||||
end
|
||||
|
||||
-- 调用我们新添加的调试函数打印更详细的信息
|
||||
self:DebugPrintItemArrays()
|
||||
|
||||
-- 创建新按钮,无需重用旧按钮
|
||||
self:CreateButtons()
|
||||
self:ShowButtons()
|
||||
@ -944,6 +1240,7 @@ function SM_ItemCollectionUI:ShowItemCollectionUI(parent)
|
||||
-- 显示对应的物品预览
|
||||
self:ShowItemPreview(firstButton.slotData, panel)
|
||||
end
|
||||
end)
|
||||
|
||||
return panel
|
||||
end
|
||||
@ -976,3 +1273,31 @@ if originalShowTab then
|
||||
originalShowTab(self, tabID)
|
||||
end
|
||||
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 = {}
|
||||
for j = 1, math.min(3, itemCount) do
|
||||
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
|
||||
|
||||
@ -56,7 +56,7 @@ function SM_Collections.LocalDataProvider:GetMounts(callback)
|
||||
},
|
||||
}
|
||||
if SM_Collections.Config.Debug then
|
||||
print("LocalDataProvider: 返回", #mounts, "个坐骑")
|
||||
|
||||
end
|
||||
callback(mounts)
|
||||
end
|
||||
@ -114,7 +114,7 @@ function SM_Collections.LocalDataProvider:GetCompanions(callback)
|
||||
},
|
||||
}
|
||||
if SM_Collections.Config.Debug then
|
||||
print("LocalDataProvider: 返回", #companions, "个小伙伴")
|
||||
|
||||
end
|
||||
callback(companions)
|
||||
end
|
||||
@ -156,7 +156,7 @@ function SM_Collections.LocalDataProvider:GetCards(callback)
|
||||
},
|
||||
}
|
||||
if SM_Collections.Config.Debug then
|
||||
print("LocalDataProvider: 返回", #cards, "个卡牌")
|
||||
|
||||
end
|
||||
callback(cards)
|
||||
end
|
||||
@ -180,7 +180,7 @@ function SM_Collections.LocalDataProvider:GetItems(callback)
|
||||
}
|
||||
}
|
||||
if SM_Collections.Config.Debug then
|
||||
print("LocalDataProvider: 返回", #items, "个物品")
|
||||
|
||||
end
|
||||
callback(items)
|
||||
end
|
||||
@ -189,7 +189,7 @@ end
|
||||
function SM_Collections.LocalDataProvider:GetAttributes(callback)
|
||||
local attributes = {}
|
||||
if SM_Collections.Config.Debug then
|
||||
print("LocalDataProvider: 返回", #attributes, "个属性加成")
|
||||
|
||||
end
|
||||
callback(attributes)
|
||||
end
|
||||
@ -266,7 +266,7 @@ function SM_Collections.LocalDataProvider:GetAttributesForSpecificItem(itemId, i
|
||||
}
|
||||
local attributes = attributeMap[itemType] and attributeMap[itemType][itemId] or {}
|
||||
if SM_Collections.Config.Debug then
|
||||
print("LocalDataProvider: 为", itemType, itemId, "返回", #attributes, "个特定属性")
|
||||
|
||||
end
|
||||
callback(attributes)
|
||||
end
|
||||
@ -279,12 +279,12 @@ function SM_Collections.ServerDataProvider:GetMounts(callback)
|
||||
self:SendServerRequest("GET_MOUNTS", {}, function(response)
|
||||
if response and response.success then
|
||||
if SM_Collections.Config.Debug then
|
||||
-- print("ServerDataProvider: 从服务端获取到", #response.data, "个坐骑")
|
||||
--
|
||||
end
|
||||
callback(response.data)
|
||||
else
|
||||
if SM_Collections.Config.FallbackToLocal then
|
||||
print("服务端获取坐骑失败,回退到本地数据")
|
||||
|
||||
SM_Collections.LocalDataProvider:GetMounts(callback)
|
||||
else
|
||||
callback({})
|
||||
@ -300,7 +300,7 @@ function SM_Collections.ServerDataProvider:GetCompanions(callback)
|
||||
callback(response.data)
|
||||
else
|
||||
if SM_Collections.Config.FallbackToLocal then
|
||||
print("服务端获取小伙伴收藏失败,回退到本地数据")
|
||||
|
||||
SM_Collections.LocalDataProvider:GetCompanions(callback)
|
||||
else
|
||||
callback({})
|
||||
@ -316,7 +316,7 @@ function SM_Collections.ServerDataProvider:GetCards(callback)
|
||||
callback(response.data)
|
||||
else
|
||||
if SM_Collections.Config.FallbackToLocal then
|
||||
print("服务端获取卡牌收藏失败,回退到本地数据")
|
||||
|
||||
SM_Collections.LocalDataProvider:GetCards(callback)
|
||||
else
|
||||
callback({})
|
||||
@ -332,7 +332,7 @@ function SM_Collections.ServerDataProvider:GetItems(callback)
|
||||
callback(response.data)
|
||||
else
|
||||
if SM_Collections.Config.FallbackToLocal then
|
||||
print("服务端获取物品收藏失败,回退到本地数据")
|
||||
|
||||
SM_Collections.LocalDataProvider:GetItems(callback)
|
||||
else
|
||||
callback({})
|
||||
@ -346,12 +346,12 @@ function SM_Collections.ServerDataProvider:GetAttributes(callback)
|
||||
self:SendServerRequest("GET_ATTRIBUTES", {}, function(response)
|
||||
if response and response.success then
|
||||
if SM_Collections.Config.Debug then
|
||||
-- print("ServerDataProvider: 从服务端获取到", #response.data, "个属性加成")
|
||||
--
|
||||
end
|
||||
callback(response.data)
|
||||
else
|
||||
if SM_Collections.Config.FallbackToLocal then
|
||||
print("服务端获取坐骑属性加成收藏失败,回退到本地数据")
|
||||
|
||||
SM_Collections.LocalDataProvider:GetAttributes(callback)
|
||||
else
|
||||
callback({})
|
||||
@ -369,12 +369,12 @@ function SM_Collections.ServerDataProvider:GetAttributesForSpecificItem(itemId,
|
||||
self:SendServerRequest("GET_ITEM_ATTRIBUTES", requestData, function(response)
|
||||
if response and response.success then
|
||||
if SM_Collections.Config.Debug then
|
||||
-- print("ServerDataProvider: 从服务端获取到", #response.data, "个特定属性")
|
||||
--
|
||||
end
|
||||
callback(response.data)
|
||||
else
|
||||
if SM_Collections.Config.FallbackToLocal then
|
||||
print("服务端获取特定属性失败,回退到本地数据")
|
||||
|
||||
SM_Collections.LocalDataProvider:GetAttributesForSpecificItem(itemId, itemType, callback)
|
||||
else
|
||||
callback({})
|
||||
@ -386,7 +386,7 @@ end
|
||||
-- 发送服务端请求
|
||||
function SM_Collections.ServerDataProvider:SendServerRequest(command, data, callback)
|
||||
if SM_Collections.Config.Debug then
|
||||
-- print("发送服务端请求:", command)
|
||||
--
|
||||
end
|
||||
|
||||
-- 确保pendingCallbacks表已初始化
|
||||
@ -401,7 +401,7 @@ function SM_Collections.ServerDataProvider:SendServerRequest(command, data, call
|
||||
requestMessage = command .. "|" .. data.itemType .. "|" .. data.itemId
|
||||
end
|
||||
|
||||
-- print("发送requestMessage:", requestMessage)
|
||||
--
|
||||
|
||||
-- 发送消息给服务端
|
||||
-- 尝试通过两种方式发送,增加成功机会
|
||||
@ -448,9 +448,9 @@ function SM_Collections.ServerDataProvider:SendServerRequest(command, data, call
|
||||
end
|
||||
|
||||
if SM_Collections.pendingCallbacks and SM_Collections.pendingCallbacks[callbackKey] then
|
||||
print("服务端请求超时:", self.command, "超时时间:", self.timeoutSeconds)
|
||||
|
||||
if SM_Collections.Config.FallbackToLocal then
|
||||
print("回退到本地数据")
|
||||
|
||||
local localProvider = SM_Collections.LocalDataProvider:new()
|
||||
if self.command == "GET_MOUNTS" then
|
||||
localProvider:GetMounts(callback)
|
||||
|
||||
181
SM_Events.lua
181
SM_Events.lua
@ -120,7 +120,7 @@ function SM_Collections:HandleItemAttributesData(msg)
|
||||
self.pendingCallbacks.item_attributes(response)
|
||||
self.pendingCallbacks.item_attributes = nil
|
||||
else
|
||||
-- print("没有找到物品属性回调函数", self.pendingCallbacks and "回调表存在" or "回调表不存在")
|
||||
--
|
||||
end
|
||||
end
|
||||
|
||||
@ -154,7 +154,7 @@ function SM_Collections:HandleCompanionsData(msg)
|
||||
spellIcon = nil
|
||||
end
|
||||
else
|
||||
-- print("无效的companionID:", companionID)
|
||||
--
|
||||
spellName = nil
|
||||
spellIcon = nil
|
||||
end
|
||||
@ -180,13 +180,13 @@ function SM_Collections:HandleCompanionsData(msg)
|
||||
self.pendingCallbacks.companions(response)
|
||||
self.pendingCallbacks.companions = nil
|
||||
else
|
||||
-- print("没有找到回调函数", self.pendingCallbacks and "回调表存在" or "回调表不存在")
|
||||
--
|
||||
end
|
||||
end
|
||||
|
||||
-- 处理卡牌数据
|
||||
function SM_Collections:HandleCardsData(msg)
|
||||
print("处理卡牌数据= ", msg)
|
||||
|
||||
local data = self:MessageSplit(msg, "|")
|
||||
local cards = {}
|
||||
|
||||
@ -218,7 +218,7 @@ function SM_Collections:HandleCardsData(msg)
|
||||
})
|
||||
|
||||
-- 输出调试信息
|
||||
print("解析卡牌: ID=", id, "名称=", name, "已获得=", obtained and "是" or "否")
|
||||
|
||||
end
|
||||
|
||||
-- 移动到下一组数据
|
||||
@ -234,34 +234,127 @@ function SM_Collections:HandleCardsData(msg)
|
||||
self.pendingCallbacks.cards(response)
|
||||
self.pendingCallbacks.cards = nil
|
||||
else
|
||||
-- print("没有找到卡牌回调函数", self.pendingCallbacks and "回调表存在" or "回调表不存在")
|
||||
--
|
||||
end
|
||||
end
|
||||
|
||||
-- 处理物品数据
|
||||
function SM_Collections:HandleItemsData(msg)
|
||||
local data = self:MessageSplit(msg, "|")
|
||||
-- 缓存机制:如果不存在,初始化缓存
|
||||
if not self.itemDataCache then
|
||||
self.itemDataCache = ""
|
||||
end
|
||||
|
||||
-- 将新收到的数据追加到缓存
|
||||
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")
|
||||
processFrame:SetScript("OnUpdate", function(self, elapsed)
|
||||
self.elapsed = (self.elapsed or 0) + elapsed
|
||||
if self.elapsed >= 2 then
|
||||
self:SetScript("OnUpdate", nil)
|
||||
self:Hide()
|
||||
|
||||
-- 处理缓存中的所有数据
|
||||
SM_Collections:ProcessItemsData()
|
||||
end
|
||||
end)
|
||||
processFrame:Show()
|
||||
return
|
||||
end
|
||||
|
||||
-- 如果已经设置了定时器,不重复处理
|
||||
print("[物品收藏] 已设置处理定时器,等待处理...")
|
||||
end
|
||||
|
||||
-- 新增:处理缓存中的所有物品数据
|
||||
function SM_Collections:ProcessItemsData()
|
||||
local data = self:MessageSplit(self.itemDataCache, "|")
|
||||
local items = {}
|
||||
for i = 1, #data, 4 do
|
||||
if data[i] and data[i + 1] and data[i + 2] and data[i + 3] then
|
||||
table.insert(items, {
|
||||
id = tonumber(data[i]),
|
||||
name = data[i + 1],
|
||||
description = data[i + 2],
|
||||
obtained = data[i + 3] == "1"
|
||||
})
|
||||
|
||||
-- 显示获取的原始数据总量
|
||||
print("[物品收藏] 处理全部缓存数据,共 " .. #data .. " 个字段")
|
||||
|
||||
-- 确认每组数据的字段数 - 每个物品固定为5个字段
|
||||
local fieldsPerItem = 5 -- ID、名称、描述、是否获得、类型
|
||||
|
||||
-- 记录处理过程详情
|
||||
print("[物品收藏] 服务器数据格式: 每个物品 " .. fieldsPerItem .. " 个字段")
|
||||
print("[物品收藏] 理论上应该有 " .. math.floor(#data / fieldsPerItem) .. " 个物品")
|
||||
|
||||
-- 循环处理数据,严格按照5个字段一组来解析
|
||||
local validItemCount = 0
|
||||
local slotItems = {} -- 按物品类型统计数量
|
||||
|
||||
for i = 1, #data, fieldsPerItem do
|
||||
-- 确保有完整的5个字段
|
||||
if i + fieldsPerItem - 1 <= #data then
|
||||
local itemID = tonumber(data[i])
|
||||
local itemName = data[i + 1]
|
||||
local itemDesc = data[i + 2]
|
||||
local obtained = data[i + 3] == "1"
|
||||
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
|
||||
end
|
||||
|
||||
table.insert(items, {
|
||||
id = itemID,
|
||||
name = itemName or "",
|
||||
description = itemDesc or "",
|
||||
obtained = obtained,
|
||||
itemType = itemType or ""
|
||||
})
|
||||
|
||||
validItemCount = validItemCount + 1
|
||||
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("没有找到物品回调函数", self.pendingCallbacks and "回调表存在" or "回调表不存在")
|
||||
print("[物品收藏] 错误: 没有找到回调函数")
|
||||
end
|
||||
end
|
||||
|
||||
@ -283,53 +376,53 @@ end
|
||||
|
||||
-- 处理收藏状态更新
|
||||
function SM_Collections:HandleCollectionUpdate(msg)
|
||||
print("处理收藏状态更新: ", msg)
|
||||
|
||||
local data = self:MessageSplit(msg, "|")
|
||||
print("#data: ", #data)
|
||||
|
||||
if #data >= 3 then
|
||||
local itemType = data[1]
|
||||
local itemID = tonumber(data[2])
|
||||
local isObtained = (data[3] == "1")
|
||||
|
||||
print("解析收藏更新: 类型=", itemType, "ID=", itemID, "已获得=", isObtained and "是" or "否")
|
||||
|
||||
|
||||
if itemID and itemType then
|
||||
-- 更新本地数据
|
||||
if itemType == "mount" then
|
||||
self.DataManager:UpdateMountStatus(itemID, isObtained)
|
||||
print("已更新坐骑状态: ID=", itemID, "已获得=", isObtained and "是" or "否")
|
||||
|
||||
-- 如果是新获得的坐骑,记录到NewItems表中
|
||||
if isObtained then
|
||||
self.NewItems.mount[itemID] = true
|
||||
print("记录新获得的坐骑: ID=", itemID)
|
||||
|
||||
end
|
||||
elseif itemType == "companion" then
|
||||
self.DataManager:UpdateCompanionStatus(itemID, isObtained)
|
||||
print("已更新小伙伴状态: ID=", itemID, "已获得=", isObtained and "是" or "否")
|
||||
|
||||
-- 如果是新获得的小伙伴,记录到NewItems表中
|
||||
if isObtained then
|
||||
self.NewItems.companion[itemID] = true
|
||||
print("记录新获得的小伙伴: ID=", itemID)
|
||||
|
||||
end
|
||||
elseif itemType == "card" then
|
||||
self.DataManager:UpdateCardStatus(itemID, isObtained)
|
||||
print("已更新卡牌状态: ID=", itemID, "已获得=", isObtained and "是" or "否")
|
||||
|
||||
-- 如果是新获得的卡牌,记录到NewItems表中
|
||||
if isObtained then
|
||||
self.NewItems.card[itemID] = true
|
||||
print("记录新获得的卡牌: ID=", itemID)
|
||||
|
||||
end
|
||||
elseif itemType == "item" then
|
||||
self.DataManager:UpdateItemStatus(itemID, isObtained)
|
||||
print("已更新物品状态: ID=", itemID, "已获得=", isObtained and "是" or "否")
|
||||
|
||||
-- 如果是新获得的物品,记录到NewItems表中
|
||||
if isObtained then
|
||||
self.NewItems.item[itemID] = true
|
||||
print("记录新获得的物品: ID=", itemID)
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
print("MainFrame存在:", self.MainFrame and "是" or "否")
|
||||
|
||||
|
||||
-- 检查当前是否显示了对应类型的面板
|
||||
local isCurrentPanel = false
|
||||
@ -340,10 +433,10 @@ function SM_Collections:HandleCollectionUpdate(msg)
|
||||
-- 检查当前面板中的按钮数据类型
|
||||
if self.CurrentPanel.scrollChild and self.CurrentPanel.scrollChild.buttons and #self.CurrentPanel.scrollChild.buttons > 0 then
|
||||
local firstButton = self.CurrentPanel.scrollChild.buttons[1]
|
||||
print("第一个按钮信息: ", firstButton and "存在" or "不存在")
|
||||
|
||||
if firstButton then
|
||||
print("按钮itemType: ", firstButton.itemType or "nil")
|
||||
print("按钮itemData: ", firstButton.itemData and "存在" or "不存在")
|
||||
|
||||
|
||||
end
|
||||
|
||||
if firstButton and firstButton.itemType then
|
||||
@ -356,13 +449,13 @@ function SM_Collections:HandleCollectionUpdate(msg)
|
||||
elseif firstButton.itemType == "item" then
|
||||
inferredTabID = 4
|
||||
end
|
||||
print("从当前面板推断tabID:", inferredTabID)
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local effectiveTabID = self.MainFrame.tabID or inferredTabID
|
||||
print("有效tabID:", effectiveTabID)
|
||||
|
||||
|
||||
if effectiveTabID then
|
||||
if (itemType == "mount" and effectiveTabID == 1) or
|
||||
@ -374,8 +467,8 @@ function SM_Collections:HandleCollectionUpdate(msg)
|
||||
end
|
||||
end
|
||||
|
||||
print("当前面板ID: ", self.MainFrame and self.MainFrame.tabID or "nil")
|
||||
print("当前面板是否匹配: ", isCurrentPanel and "是" or "否")
|
||||
|
||||
|
||||
|
||||
-- 无论当前面板是什么,都尝试刷新UI
|
||||
-- 如果不是当前面板,RefreshCollectionStatus函数内部会自己处理
|
||||
@ -383,7 +476,7 @@ function SM_Collections:HandleCollectionUpdate(msg)
|
||||
|
||||
-- 如果是卡牌且当前显示的是卡牌面板,强制重新加载
|
||||
if itemType == "card" and isCurrentPanel then
|
||||
print("强制重新加载卡牌面板")
|
||||
|
||||
-- 使用 3.3.5 支持的延迟执行方法
|
||||
local cardReloadFrame = CreateFrame("Frame")
|
||||
cardReloadFrame:SetScript("OnUpdate", function(self, elapsed)
|
||||
@ -399,7 +492,7 @@ function SM_Collections:HandleCollectionUpdate(msg)
|
||||
|
||||
-- 如果是卡牌且获得了新卡牌,强制重新加载卡牌面板
|
||||
if itemType == "card" and isObtained and not isCurrentPanel then
|
||||
print("获得新卡牌,强制重新加载卡牌数据")
|
||||
|
||||
-- 更新本地数据,但不切换面板
|
||||
local cardDataReloadFrame = CreateFrame("Frame")
|
||||
cardDataReloadFrame:SetScript("OnUpdate", function(self, elapsed)
|
||||
@ -409,7 +502,7 @@ function SM_Collections:HandleCollectionUpdate(msg)
|
||||
self:Hide()
|
||||
-- 重新获取卡牌数据,但不显示
|
||||
SM_Collections.DataManager:GetCards(function(cards)
|
||||
print("卡牌数据已更新,共", #cards, "张卡牌")
|
||||
|
||||
end)
|
||||
end
|
||||
end)
|
||||
@ -418,7 +511,7 @@ function SM_Collections:HandleCollectionUpdate(msg)
|
||||
|
||||
-- 如果是小伙伴且获得了新的小伙伴,强制重新加载小伙伴面板
|
||||
if itemType == "companion" and isObtained then
|
||||
print("强制重新加载小伙伴面板")
|
||||
|
||||
-- 使用 3.3.5 支持的延迟执行方法
|
||||
local companionReloadFrame = CreateFrame("Frame")
|
||||
companionReloadFrame:SetScript("OnUpdate", function(self, elapsed)
|
||||
@ -435,7 +528,7 @@ function SM_Collections:HandleCollectionUpdate(msg)
|
||||
end
|
||||
end
|
||||
else
|
||||
print("收藏状态更新数据格式错误: ", msg)
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@ -456,7 +549,7 @@ function SM_Collections_MessageEvent(self, event, prefix, msg, type, sender)
|
||||
SM_Collections:HandleItemAttributesData(msg) -- 物品属性
|
||||
|
||||
elseif prefix == "SM_S_COLLECTION_UPDATE" then
|
||||
print("SM_S_COLLECTION_UPDATE= ", msg)
|
||||
|
||||
SM_Collections:HandleCollectionUpdate(msg) --404行
|
||||
|
||||
end
|
||||
@ -472,8 +565,8 @@ SM_Collections_EventFrame:SetScript('OnEvent', function(self, event, ...)
|
||||
if event == 'ADDON_LOADED' then
|
||||
local addonName = ...
|
||||
if addonName == "SM_CollectionSystem" then
|
||||
print("SM收藏系统已加载!使用 /smcollections 打开界面")
|
||||
print("数据源模式:", SM_Collections.Config.UseServerData and "服务端" or "本地")
|
||||
|
||||
|
||||
end
|
||||
elseif event == 'CHAT_MSG_ADDON' then
|
||||
SM_Collections_MessageEvent(self, event, ...)
|
||||
@ -482,7 +575,7 @@ SM_Collections_EventFrame:SetScript('OnEvent', function(self, event, ...)
|
||||
-- 确保设置了默认的tabID
|
||||
if SM_Collections.MainFrame then
|
||||
SM_Collections.MainFrame.tabID = SM_Collections.MainFrame.tabID or 1
|
||||
print("创建MainFrame并设置默认tabID:", SM_Collections.MainFrame.tabID)
|
||||
|
||||
end
|
||||
SM_Collections.MainFrame:Hide()
|
||||
end
|
||||
|
||||
@ -308,7 +308,7 @@ end
|
||||
|
||||
-- 创建类型图标和文本
|
||||
function SM_Collections:CreateTypeIcon(parent)
|
||||
print("parent父级名称 ", parent.model:GetName())
|
||||
|
||||
if parent.typeIcon then
|
||||
return parent.typeIcon
|
||||
end
|
||||
@ -458,7 +458,7 @@ end
|
||||
|
||||
-- 显示物品收藏界面
|
||||
function SM_Collections:ShowItems()
|
||||
print("显示物品收藏界面")
|
||||
|
||||
|
||||
-- 清理右侧面板中可能存在的旧属性加成文本
|
||||
if self.MainFrame and self.MainFrame.RightSidePanel then
|
||||
@ -474,7 +474,7 @@ function SM_Collections:ShowItems()
|
||||
if not SM_ItemCollectionUI then
|
||||
-- 确认模块已加载
|
||||
if not SM_ItemCollectionUI then
|
||||
print("无法加载物品收藏界面模块")
|
||||
|
||||
return
|
||||
end
|
||||
end
|
||||
@ -497,7 +497,7 @@ end
|
||||
|
||||
-- 下面补充内容切换的函数(示例)
|
||||
function SM_Collections:ShowMounts()
|
||||
-- print("显示坐骑")
|
||||
--
|
||||
|
||||
-- 确保属性加成框架隐藏
|
||||
if self.MainFrame and self.MainFrame.RightSidePanel then
|
||||
@ -514,7 +514,7 @@ function SM_Collections:ShowMounts()
|
||||
end
|
||||
|
||||
SM_Collections.DataManager:GetMounts(function(mounts)
|
||||
-- print("GetMounts:")
|
||||
--
|
||||
local panel = self:CreateSplitPanel(self.MainFrame.ContentFrame, mounts, "mount")
|
||||
|
||||
-- 不需要手动选择第一个项目,CreateSplitPanel函数已经处理了自动选择
|
||||
@ -525,7 +525,7 @@ function SM_Collections:ShowMounts()
|
||||
end
|
||||
|
||||
function SM_Collections:ShowCompanions()
|
||||
print("显示小伙伴")
|
||||
|
||||
-- 确保属性加成框架隐藏
|
||||
if self.MainFrame and self.MainFrame.RightSidePanel then
|
||||
if self.MainFrame.RightSidePanel.AttributeBonusFrame then
|
||||
@ -551,7 +551,7 @@ function SM_Collections:ShowCompanions()
|
||||
end
|
||||
|
||||
function SM_Collections:ShowCards()
|
||||
print("显示卡牌收藏")
|
||||
|
||||
|
||||
-- 确保属性加成框架隐藏
|
||||
if self.MainFrame and self.MainFrame.RightSidePanel then
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
-- 在这里添加点击处理逻辑
|
||||
function OnItemClick(button, itemData, itemType, panel)
|
||||
print("点击了物品:", itemData.id, "类型:", itemType)
|
||||
|
||||
|
||||
-- 设置按钮选中状态
|
||||
if button then
|
||||
@ -26,7 +26,7 @@ function OnItemClick(button, itemData, itemType, panel)
|
||||
if button.selectedTexture then
|
||||
button.selectedTexture:Show()
|
||||
end
|
||||
print("设置按钮选中状态:", button.isSelected and "已选中" or "未选中")
|
||||
|
||||
end
|
||||
|
||||
-- 更新名称和描述
|
||||
@ -58,7 +58,7 @@ function OnItemClick(button, itemData, itemType, panel)
|
||||
-- 更新名称
|
||||
if SM_Collections.MainFrame.RightSidePanel.MountNama then
|
||||
SM_Collections.MainFrame.RightSidePanel.MountNama:SetText(displayName or "")
|
||||
print("更新右侧面板名称为:", displayName)
|
||||
|
||||
SM_Collections.MainFrame.RightSidePanel.MountNama:Show()
|
||||
end
|
||||
|
||||
@ -74,7 +74,7 @@ function OnItemClick(button, itemData, itemType, panel)
|
||||
-- 如果服务端已经提供了displayID,优先使用它
|
||||
if itemData.displayID and itemData.displayID > 0 then
|
||||
creatureDisplayID = itemData.displayID
|
||||
print("使用服务端提供的displayID: " .. creatureDisplayID)
|
||||
|
||||
else
|
||||
-- 否则从映射表中获取
|
||||
creatureDisplayID = SM_Collections:GetCreatureDisplayID(itemData.id, itemType)
|
||||
@ -473,7 +473,7 @@ function SM_Collections:CreateListItems(parent, data, itemType, model, nameText,
|
||||
end
|
||||
end
|
||||
|
||||
--print("列表项显示名称:", displayName, "原始名称:", item.name)
|
||||
--
|
||||
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)
|
||||
|
||||
@ -560,12 +560,12 @@ end
|
||||
|
||||
function SM_Collections:UpdateRightPanel(selectedItem, itemType)
|
||||
if not self.MainFrame or not self.MainFrame.RightSidePanel then
|
||||
print("UpdateRightPanel: 右侧面板不存在")
|
||||
|
||||
return
|
||||
end
|
||||
local rightPanel = self.MainFrame.RightSidePanel
|
||||
|
||||
-- print("UpdateRightPanel: 更新右侧面板,物品ID:", selectedItem.id, "类型:", itemType)
|
||||
--
|
||||
|
||||
-- 更新坐骑名称
|
||||
if rightPanel.MountNama then
|
||||
@ -576,17 +576,17 @@ function SM_Collections:UpdateRightPanel(selectedItem, itemType)
|
||||
displayName = spellName or "ID: " .. selectedItem.id
|
||||
end
|
||||
|
||||
-- print("UpdateRightPanel: 设置名称为:", displayName)
|
||||
--
|
||||
rightPanel.MountNama:SetText(displayName or "")
|
||||
rightPanel.MountNama:Show()
|
||||
|
||||
-- 检查文本框的各种属性
|
||||
-- print("名称文本框状态: 可见=", rightPanel.MountNama:IsVisible(),
|
||||
--
|
||||
-- "层级=", rightPanel.MountNama:GetDrawLayer(),
|
||||
-- "宽高=", rightPanel.MountNama:GetWidth(), rightPanel.MountNama:GetHeight(),
|
||||
-- "位置=", rightPanel.MountNama:GetPoint())
|
||||
else
|
||||
print("UpdateRightPanel: MountNama不存在")
|
||||
|
||||
end
|
||||
|
||||
-- 更新描述文本并确保正确换行
|
||||
@ -803,17 +803,17 @@ end
|
||||
|
||||
-- 刷新收藏状态
|
||||
function SM_Collections:RefreshCollectionStatus(itemType, itemID, isObtained)
|
||||
print("刷新收藏状态: 类型=", itemType, "ID=", itemID, "已获得=", isObtained and "是" or "否")
|
||||
|
||||
|
||||
-- 如果当前没有显示面板,不需要刷新
|
||||
if not self.CurrentPanel or not self.CurrentPanel.scrollChild then
|
||||
print("当前没有显示面板,跳过刷新")
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
local buttons = self.CurrentPanel.scrollChild.buttons
|
||||
if not buttons then
|
||||
print("没有找到按钮列表,跳过刷新")
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
@ -828,7 +828,7 @@ function SM_Collections:RefreshCollectionStatus(itemType, itemID, isObtained)
|
||||
-- 可以检查buttons[1].itemType,如果存在的话
|
||||
if buttons[1].itemType then
|
||||
inferredPanelType = buttons[1].itemType
|
||||
print("从按钮推断面板类型: ", inferredPanelType)
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@ -838,7 +838,7 @@ function SM_Collections:RefreshCollectionStatus(itemType, itemID, isObtained)
|
||||
for _, button in ipairs(buttons) do
|
||||
if button.itemData and button.itemData.id == itemID then
|
||||
isCorrectPanel = true
|
||||
print("小伙伴特殊处理: 找到匹配按钮,强制设置面板类型正确")
|
||||
|
||||
break
|
||||
end
|
||||
end
|
||||
@ -850,7 +850,7 @@ function SM_Collections:RefreshCollectionStatus(itemType, itemID, isObtained)
|
||||
for _, button in ipairs(buttons) do
|
||||
if button.itemData and button.itemData.id == itemID then
|
||||
isCorrectPanel = true
|
||||
print("卡牌特殊处理: 找到匹配按钮,强制设置面板类型正确")
|
||||
|
||||
break
|
||||
end
|
||||
end
|
||||
@ -867,24 +867,24 @@ function SM_Collections:RefreshCollectionStatus(itemType, itemID, isObtained)
|
||||
elseif not isCorrectPanel and inferredPanelType and itemType == inferredPanelType then
|
||||
-- 如果推断出的面板类型与更新的项目类型匹配
|
||||
isCorrectPanel = true
|
||||
print("通过推断确定当前面板类型:", inferredPanelType)
|
||||
|
||||
elseif not isCorrectPanel then
|
||||
-- 尝试直接检查按钮数据是否包含要更新的项目ID
|
||||
for _, button in ipairs(buttons) do
|
||||
if button.itemData and button.itemData.id == itemID then
|
||||
isCorrectPanel = true
|
||||
print("通过按钮ID匹配确定面板类型正确")
|
||||
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if not isCorrectPanel then
|
||||
print("当前面板类型不匹配,跳过UI刷新")
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
print("开始查找匹配按钮,共有", #buttons, "个按钮")
|
||||
|
||||
|
||||
-- 查找对应的按钮并更新状态
|
||||
local updatedButton = nil
|
||||
@ -893,7 +893,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
|
||||
print("找到匹配按钮: 索引=", i, "原状态=", button.itemData.obtained and "已获得" or "未获得")
|
||||
|
||||
|
||||
-- 更新获取状态
|
||||
button.itemData.obtained = isObtained
|
||||
@ -902,15 +902,15 @@ 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)
|
||||
print("已更新按钮文本颜色(使用保存的引用)")
|
||||
|
||||
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)
|
||||
print("已更新按钮文本颜色(使用GetRegions)")
|
||||
|
||||
else
|
||||
print("无法找到按钮文本对象")
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@ -943,7 +943,7 @@ function SM_Collections:RefreshCollectionStatus(itemType, itemID, isObtained)
|
||||
-- 如果是当前选中的按钮,更新右侧面板
|
||||
if button.isSelected then
|
||||
updatedButton = button
|
||||
print("这是当前选中的按钮,将更新右侧面板")
|
||||
|
||||
end
|
||||
|
||||
-- 更新已获得按钮列表
|
||||
@ -959,14 +959,14 @@ function SM_Collections:RefreshCollectionStatus(itemType, itemID, isObtained)
|
||||
end
|
||||
if not found then
|
||||
table.insert(obtainedButtons, button)
|
||||
print("添加到已获得列表,现在共有", #obtainedButtons, "个已获得项目")
|
||||
|
||||
end
|
||||
else
|
||||
-- 从已获得列表中移除
|
||||
for i, btn in ipairs(obtainedButtons) do
|
||||
if btn == button then
|
||||
table.remove(obtainedButtons, i)
|
||||
print("从已获得列表中移除,现在共有", #obtainedButtons, "个已获得项目")
|
||||
|
||||
break
|
||||
end
|
||||
end
|
||||
@ -981,13 +981,13 @@ function SM_Collections:RefreshCollectionStatus(itemType, itemID, isObtained)
|
||||
end
|
||||
|
||||
if not buttonFound then
|
||||
print("未找到匹配按钮,ID=", itemID)
|
||||
|
||||
end
|
||||
|
||||
-- 如果更新的是当前选中的项目,刷新右侧面板
|
||||
if updatedButton then
|
||||
local panel = self.CurrentPanel
|
||||
print("手动触发点击事件更新右侧面板")
|
||||
|
||||
OnItemClick(updatedButton, updatedButton.itemData, itemType, panel)
|
||||
end
|
||||
|
||||
@ -1004,9 +1004,9 @@ function SM_Collections:RefreshCollectionStatus(itemType, itemID, isObtained)
|
||||
|
||||
-- 显示通知
|
||||
if itemName and itemName ~= "" then
|
||||
print("|cFF00FF00新收藏解锁:|r " .. typeName .. " - " .. itemName)
|
||||
|
||||
else
|
||||
print("|cFF00FF00新收藏解锁:|r " .. typeName .. " (ID: " .. itemID .. ")")
|
||||
|
||||
end
|
||||
|
||||
-- 播放获得音效
|
||||
@ -1053,12 +1053,12 @@ function SM_Collections:ResortCollectionButtons(scrollChild, itemType)
|
||||
end
|
||||
end
|
||||
|
||||
print("已重新排序按钮,共", #buttons, "个按钮")
|
||||
|
||||
end
|
||||
|
||||
-- 注册事件处理
|
||||
function SM_Collections:RegisterCollectionEvents()
|
||||
print("注册事件处理")
|
||||
|
||||
-- 监听收藏状态更新事件
|
||||
self:RegisterEvent("ADDON_MESSAGE_PREFIX_SM_S_COLLECTION_UPDATE", function(prefix, message)
|
||||
local data = self:MessageSplit(message, "|")
|
||||
|
||||
10
SM_Utils.lua
10
SM_Utils.lua
@ -34,7 +34,7 @@ SM_Collections.SpellToDisplayIDMap = {
|
||||
function SM_Collections:GetCreatureDisplayID(itemID, itemType)
|
||||
-- 检查itemID是否有效
|
||||
if not itemID or type(itemID) ~= "number" or itemID <= 0 then
|
||||
print("GetCreatureDisplayID: 无效的itemID:", itemID)
|
||||
|
||||
if itemType == "mount" then
|
||||
return 16358 -- 返回默认坐骑ID
|
||||
elseif itemType == "companion" then
|
||||
@ -48,7 +48,7 @@ function SM_Collections:GetCreatureDisplayID(itemID, itemType)
|
||||
if SM_Collections.SpellToDisplayIDMap and SM_Collections.SpellToDisplayIDMap[itemID] then
|
||||
local mountData = SM_Collections.SpellToDisplayIDMap[itemID]
|
||||
if mountData.effectMiscValue then
|
||||
print("从Mount.lua找到坐骑显示ID:", itemID, "->", mountData.effectMiscValue)
|
||||
|
||||
return mountData.effectMiscValue
|
||||
end
|
||||
end
|
||||
@ -60,20 +60,20 @@ function SM_Collections:GetCreatureDisplayID(itemID, itemType)
|
||||
end
|
||||
|
||||
-- 如果本地映射表中没有,提示错误
|
||||
print("警告: 未找到坐骑技能ID的显示ID映射:", itemID)
|
||||
|
||||
return 16358 -- 返回一个默认模型ID,避免显示错误
|
||||
elseif itemType == "companion" then
|
||||
-- 使用Companions.lua中的数据
|
||||
if SM_Collections.Companions and SM_Collections.Companions[itemID] then
|
||||
local companionData = SM_Collections.Companions[itemID]
|
||||
if companionData.effectMiscValue then
|
||||
print("从Companions.lua找到小伙伴显示ID:", itemID, "->", companionData.effectMiscValue)
|
||||
|
||||
return companionData.effectMiscValue
|
||||
end
|
||||
end
|
||||
|
||||
-- 如果上面的方法失败,返回默认ID
|
||||
print("未找到companion的displayID, 使用默认ID:", itemID)
|
||||
|
||||
return 7380 -- 默认小伙伴ID
|
||||
elseif itemType == "card" then
|
||||
local cardMap = {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user