优化武器附魔效果,
1、点击武器附魔显示子元素 2、选中子元素,在右侧的角色模型武器上显示附魔效果
This commit is contained in:
parent
f46f79f70a
commit
454ff77760
BIN
Interface/PaperDoll/UI-PaperDoll-Slot-Finger.blp
Normal file
BIN
Interface/PaperDoll/UI-PaperDoll-Slot-Finger.blp
Normal file
Binary file not shown.
BIN
Interface/PaperDoll/UI-PaperDoll-Slot-Neck.blp
Normal file
BIN
Interface/PaperDoll/UI-PaperDoll-Slot-Neck.blp
Normal file
Binary file not shown.
BIN
Interface/PaperDoll/UI-PaperDoll-Slot-Trinket.blp
Normal file
BIN
Interface/PaperDoll/UI-PaperDoll-Slot-Trinket.blp
Normal file
Binary file not shown.
@ -109,6 +109,22 @@ function SM_ItemCollectionUI:Init()
|
||||
-- 注册物品获取事件
|
||||
self:RegisterItemEvents()
|
||||
|
||||
-- 添加界面关闭事件处理
|
||||
if SM_Collections.MainFrame then
|
||||
SM_Collections.MainFrame:HookScript("OnHide", function()
|
||||
-- 隐藏所有附魔相关元素
|
||||
if self.enchantPreviewFrame then
|
||||
self.enchantPreviewFrame:Hide()
|
||||
end
|
||||
|
||||
-- 恢复右侧面板
|
||||
self:RestoreRightSidePanel()
|
||||
|
||||
-- 取消附魔模式标记
|
||||
self.inEnchantMode = false
|
||||
end)
|
||||
end
|
||||
|
||||
self.initialized = true
|
||||
end
|
||||
|
||||
@ -481,7 +497,7 @@ function SM_ItemCollectionUI:UpdateAttributes(itemID, itemType)
|
||||
end)
|
||||
end
|
||||
|
||||
-- 处理按钮点击事件
|
||||
-- 处理按钮点击事件
|
||||
function SM_ItemCollectionUI:HandleButtonClick(slot)
|
||||
if not self.currentPanel then
|
||||
return
|
||||
@ -496,11 +512,59 @@ function SM_ItemCollectionUI:HandleButtonClick(slot)
|
||||
end
|
||||
self.currentPage = 1
|
||||
|
||||
-- 如果当前处于附魔模式,需要先恢复正常显示
|
||||
if self.inEnchantMode then
|
||||
print("从附魔模式切换到普通模式")
|
||||
-- 隐藏附魔相关元素
|
||||
if self.enchantPreviewFrame then
|
||||
self.enchantPreviewFrame:Hide()
|
||||
end
|
||||
|
||||
-- 清理附魔模型和标题引用,确保下次能正确创建
|
||||
if self.enchantPlayerModel then
|
||||
self.enchantPlayerModel:Hide()
|
||||
self.enchantPlayerModel = nil
|
||||
end
|
||||
|
||||
if self.enchantTitleText then
|
||||
self.enchantTitleText:Hide()
|
||||
self.enchantTitleText = nil
|
||||
end
|
||||
|
||||
-- 恢复右侧面板
|
||||
self:RestoreRightSidePanel()
|
||||
|
||||
-- 取消附魔模式标记
|
||||
self.inEnchantMode = false
|
||||
end
|
||||
|
||||
-- 检查是否点击了物品收藏选项卡
|
||||
if slot.name == "物品收藏" then
|
||||
print("点击了物品收藏选项卡") -- 调试信息
|
||||
-- 隐藏武器附魔页面
|
||||
if self.enchantPreviewFrame then
|
||||
print("隐藏武器附魔页面") -- 调试信息
|
||||
self.enchantPreviewFrame:Hide()
|
||||
else
|
||||
print("武器附魔页面不存在") -- 调试信息
|
||||
end
|
||||
-- 隐藏其他页面
|
||||
if self.currentPanel then
|
||||
self.currentPanel:Hide()
|
||||
end
|
||||
-- 显示头部页面
|
||||
local headSlot = self.ALL_SLOTS[1] -- 假设头部是第一个槽位
|
||||
self:ShowItemPreview(headSlot, self.currentPanel)
|
||||
end
|
||||
|
||||
-- 确保按获得状态对物品排序
|
||||
self:SortSlotItems(slot)
|
||||
|
||||
-- 显示物品预览
|
||||
self:ShowItemPreview(slot, self.currentPanel)
|
||||
|
||||
-- 显示分页按钮(确保在ShowItemPreview之后调用,以便正确更新)
|
||||
self:ShowPageButtons()
|
||||
end
|
||||
|
||||
-- 强制清理所有物品模型
|
||||
@ -522,7 +586,10 @@ function SM_ItemCollectionUI:ForceCleanupModels(panel)
|
||||
if child.Border then child.Border:Hide() end
|
||||
-- 隐藏并移除
|
||||
child:Hide()
|
||||
child:SetParent(nil)
|
||||
-- 避免对FontString和Texture设置nil父元素
|
||||
if child.GetObjectType and child:GetObjectType() ~= "FontString" and child:GetObjectType() ~= "Texture" then
|
||||
child:SetParent(nil)
|
||||
end
|
||||
child:ClearAllPoints()
|
||||
end
|
||||
end
|
||||
@ -533,26 +600,11 @@ end
|
||||
|
||||
-- 显示物品预览
|
||||
function SM_ItemCollectionUI:ShowItemPreview(slot, panel)
|
||||
-- 确保物品已排序
|
||||
self:SortSlotItems(slot)
|
||||
|
||||
-- 清除当前选中的模型
|
||||
self:ClearModelSelection()
|
||||
|
||||
if not panel then
|
||||
panel = self.currentPanel
|
||||
end
|
||||
|
||||
if not panel then
|
||||
return
|
||||
end
|
||||
|
||||
-- 清理旧的预览内容
|
||||
if panel.previewFrame and panel.previewFrame:IsShown() then
|
||||
local children = { panel.previewFrame:GetChildren() }
|
||||
for _, child in ipairs(children) do
|
||||
child:Hide()
|
||||
child:SetParent(nil)
|
||||
end
|
||||
panel.previewFrame:Hide()
|
||||
end
|
||||
@ -1356,8 +1408,8 @@ function SM_ItemCollectionUI:CreateButtons()
|
||||
-- 显示当前按钮的选中状态
|
||||
self.SelectedTexture:Show()
|
||||
|
||||
-- 这里可以添加处理附魔选择的函数
|
||||
-- SM_ItemCollectionUI:HandleEnchantButtonClick(self.slotData)
|
||||
-- 调用附魔处理函数
|
||||
SM_ItemCollectionUI:HandleEnchantButtonClick("INVTYPE_WEAPONMAINHAND")
|
||||
end)
|
||||
|
||||
-- 设置提示
|
||||
@ -1429,8 +1481,8 @@ function SM_ItemCollectionUI:CreateButtons()
|
||||
-- 显示当前按钮的选中状态
|
||||
self.SelectedTexture:Show()
|
||||
|
||||
-- 这里可以添加处理附魔选择的函数
|
||||
-- SM_ItemCollectionUI:HandleEnchantButtonClick(self.slotData)
|
||||
-- 调用附魔处理函数
|
||||
SM_ItemCollectionUI:HandleEnchantButtonClick("INVTYPE_WEAPONOFFHAND")
|
||||
end)
|
||||
|
||||
-- 设置提示
|
||||
@ -1514,6 +1566,11 @@ end
|
||||
|
||||
-- 显示物品收藏界面
|
||||
function SM_ItemCollectionUI:ShowItemCollectionUI(parent)
|
||||
-- 隐藏武器附魔页面
|
||||
if self.enchantPreviewFrame then
|
||||
self.enchantPreviewFrame:Hide()
|
||||
end
|
||||
|
||||
-- 确保已初始化(防止ALL_SLOTS未初始化导致缓存数据无法分类)
|
||||
if not self.initialized then
|
||||
self:Init()
|
||||
@ -1683,3 +1740,784 @@ function SM_ItemCollectionUI:DebugPrintItemArrays()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- 处理附魔按钮点击
|
||||
function SM_ItemCollectionUI:HandleEnchantButtonClick(slotType)
|
||||
print("处理附魔按钮点击:", slotType)
|
||||
|
||||
-- 完全清理预览框架的所有内容
|
||||
if self.previewFrame then
|
||||
-- 隐藏所有子元素
|
||||
local children = {self.previewFrame:GetChildren()}
|
||||
for _, child in ipairs(children) do
|
||||
child:Hide()
|
||||
end
|
||||
|
||||
-- 清除当前预览内容的引用
|
||||
if self.currentPreviewContent then
|
||||
self.currentPreviewContent:Hide()
|
||||
self.currentPreviewContent = nil
|
||||
end
|
||||
end
|
||||
|
||||
-- 标记当前处于附魔模式
|
||||
self.inEnchantMode = true
|
||||
|
||||
-- 创建或显示附魔预览容器
|
||||
if not self.enchantPreviewFrame then
|
||||
self:CreateEnchantPreviewFrame()
|
||||
else
|
||||
-- 如果已存在但可能被隐藏,确保重新显示并更新
|
||||
self.enchantPreviewFrame:ClearAllPoints()
|
||||
self.enchantPreviewFrame:SetParent(self.previewFrame)
|
||||
self.enchantPreviewFrame:SetPoint("TOPLEFT", 0, 0)
|
||||
self.enchantPreviewFrame:SetPoint("BOTTOMRIGHT", 0, 0)
|
||||
|
||||
-- 确保所有子元素可见
|
||||
for _, button in ipairs(self.enchantButtons or {}) do
|
||||
if button then
|
||||
button:Show()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- 显示附魔预览容器并设置合适的层级
|
||||
self.enchantPreviewFrame:Show()
|
||||
if self.enchantPreviewFrame.SetFrameLevel then
|
||||
self.enchantPreviewFrame:SetFrameLevel(SM_Collections.MainFrame:GetFrameLevel() + 50) -- 提高层级
|
||||
end
|
||||
|
||||
-- 创建右侧角色模型面板
|
||||
-- 每次都重新创建右侧模型面板,确保显示正常
|
||||
self.enchantModelPanel = nil
|
||||
self.enchantTitleText = nil
|
||||
self.enchantPlayerModel = nil
|
||||
self:CreateEnchantModelPanel()
|
||||
|
||||
-- 记录当前预览内容
|
||||
self.currentPreviewContent = self.enchantPreviewFrame
|
||||
|
||||
-- 更新右侧标题为默认文本
|
||||
if self.enchantTitleText then
|
||||
self.enchantTitleText:SetText("武器附魔预览")
|
||||
end
|
||||
|
||||
-- 隐藏分页控件
|
||||
self:HidePageButtons()
|
||||
|
||||
-- 隐藏主界面召唤按钮(如果存在)
|
||||
if SM_Collections.MainFrame and SM_Collections.MainFrame.RightSidePanel and SM_Collections.MainFrame.RightSidePanel.CallButon then
|
||||
SM_Collections.MainFrame.RightSidePanel.CallButon:Hide()
|
||||
end
|
||||
|
||||
-- 加载附魔数据并显示
|
||||
self:LoadEnchantEffects(slotType)
|
||||
|
||||
-- 确保附魔框架的父元素正确设置为收藏界面
|
||||
if self.enchantPreviewFrame and SM_Collections.MainFrame then
|
||||
self.enchantPreviewFrame:SetParent(SM_Collections.MainFrame)
|
||||
if self.enchantPreviewFrame.SetFrameLevel then
|
||||
self.enchantPreviewFrame:SetFrameLevel(SM_Collections.MainFrame:GetFrameLevel() + 100) -- 大幅提高层级
|
||||
end
|
||||
|
||||
-- 确保附魔按钮在顶层显示
|
||||
for _, button in ipairs(self.enchantButtons or {}) do
|
||||
if button and button.SetFrameLevel then
|
||||
button:SetFrameLevel(self.enchantPreviewFrame:GetFrameLevel() + 10)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- 打印调试信息
|
||||
if self.enchantPreviewFrame and self.enchantPreviewFrame.GetFrameLevel then
|
||||
print("附魔预览框架已设置,层级:", self.enchantPreviewFrame:GetFrameLevel())
|
||||
end
|
||||
end
|
||||
|
||||
-- 隐藏分页按钮
|
||||
function SM_ItemCollectionUI:HidePageButtons()
|
||||
-- 隐藏常规分页按钮
|
||||
if self.pageButtons then
|
||||
if self.pageButtons.prev then self.pageButtons.prev:Hide() end
|
||||
if self.pageButtons.next then self.pageButtons.next:Hide() end
|
||||
if self.pageButtons.text then self.pageButtons.text:Hide() end
|
||||
end
|
||||
|
||||
-- 查找并隐藏可能存在的其他分页按钮
|
||||
local mainFrame = SM_Collections.MainFrame
|
||||
if mainFrame then
|
||||
for i, region in ipairs({mainFrame:GetRegions()}) do
|
||||
if region:IsObjectType("FontString") and region:GetText() and string.find(region:GetText(), "/") then
|
||||
region:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
for _, child in ipairs({mainFrame:GetChildren()}) do
|
||||
if child:GetName() and (string.find(child:GetName(), "Prev") or string.find(child:GetName(), "Next") or string.find(child:GetName(), "Page")) then
|
||||
child:Hide()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- 显示分页按钮
|
||||
function SM_ItemCollectionUI:ShowPageButtons()
|
||||
-- 显示常规分页按钮
|
||||
if self.pageButtons then
|
||||
if self.pageButtons.prev then self.pageButtons.prev:Show() end
|
||||
if self.pageButtons.next then self.pageButtons.next:Show() end
|
||||
if self.pageButtons.text then self.pageButtons.text:Show() end
|
||||
end
|
||||
|
||||
-- 更新分页文本
|
||||
if self.pageButtons and self.pageButtons.text then
|
||||
local totalPages = 1
|
||||
if self.currentSelectedButton and self.currentSelectedButton.slotData then
|
||||
local slot = self.currentSelectedButton.slotData
|
||||
totalPages = math.ceil(#slot.items / self.itemsPerPage)
|
||||
end
|
||||
self.pageButtons.text:SetText(self.currentPage .. "/" .. totalPages)
|
||||
end
|
||||
end
|
||||
|
||||
-- 创建右侧角色模型面板
|
||||
function SM_ItemCollectionUI:CreateEnchantModelPanel()
|
||||
local panel = SM_Collections.MainFrame.RightSidePanel
|
||||
if not panel then return end
|
||||
|
||||
-- 彻底清理和隐藏面板上的所有元素
|
||||
-- 保存原始内容以便恢复
|
||||
if not panel.originalContent then
|
||||
panel.originalContent = {
|
||||
children = {},
|
||||
regions = {}
|
||||
}
|
||||
|
||||
-- 安全地保存子元素原始状态
|
||||
local children = {panel:GetChildren()}
|
||||
for i, child in ipairs(children) do
|
||||
if child and child.IsVisible then
|
||||
panel.originalContent.children[i] = {
|
||||
element = child,
|
||||
visible = child:IsVisible()
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
-- 安全地保存区域原始状态
|
||||
local regions = {panel:GetRegions()}
|
||||
for i, region in ipairs(regions) do
|
||||
if region and region.IsVisible then
|
||||
panel.originalContent.regions[i] = {
|
||||
element = region,
|
||||
visible = region:IsVisible()
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- 隐藏所有子元素
|
||||
local children = {panel:GetChildren()}
|
||||
for _, child in ipairs(children) do
|
||||
-- 如果这是一个按钮,特别是召唤按钮,确保隐藏
|
||||
if child:IsObjectType("Button") or (child:GetName() and string.find(child:GetName(), "CallButon")) then
|
||||
child:Hide()
|
||||
else
|
||||
child:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
-- 隐藏所有区域(文本、纹理等)
|
||||
local regions = {panel:GetRegions()}
|
||||
for _, region in ipairs(regions) do
|
||||
region:Hide()
|
||||
end
|
||||
|
||||
-- 特别处理已知的UI元素
|
||||
if panel.MountNama then panel.MountNama:Hide() end
|
||||
if panel.introText then panel.introText:Hide() end
|
||||
if panel.AttributeBonusFrame then panel.AttributeBonusFrame:Hide() end
|
||||
if panel.CallButon then panel.CallButon:Hide() end -- 特别隐藏召唤按钮
|
||||
if panel.statusText then panel.statusText:Hide() end -- 隐藏状态文本
|
||||
|
||||
-- 遍历所有可能命名的子元素
|
||||
for _, child in ipairs(children) do
|
||||
if child:GetName() then
|
||||
local name = child:GetName():lower()
|
||||
if string.find(name, "call") or string.find(name, "summon") or string.find(name, "buton") then
|
||||
child:Hide()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- 创建标题文本
|
||||
-- 确保之前的标题文本已经被清理
|
||||
if self.enchantTitleText then
|
||||
self.enchantTitleText:Hide()
|
||||
self.enchantTitleText = nil
|
||||
end
|
||||
|
||||
-- 创建新的标题文本
|
||||
local titleText = panel:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
|
||||
titleText:SetPoint("TOP", panel, "TOP", 0, -10)
|
||||
titleText:SetText("武器附魔预览")
|
||||
titleText:SetTextColor(1, 0.82, 0)
|
||||
self.enchantTitleText = titleText
|
||||
self.enchantTitleText:Show()
|
||||
|
||||
-- 创建角色模型
|
||||
-- 确保之前的模型已经被清理
|
||||
if self.enchantPlayerModel then
|
||||
self.enchantPlayerModel:Hide()
|
||||
self.enchantPlayerModel = nil
|
||||
end
|
||||
|
||||
-- 创建新的角色模型
|
||||
local modelFrame = CreateFrame("DressUpModel", "EnchantPreviewModel", panel)
|
||||
modelFrame:SetPoint("TOP", self.enchantTitleText, "BOTTOM", 0, -10)
|
||||
modelFrame:SetPoint("BOTTOM", panel, "BOTTOM", 0, 10)
|
||||
modelFrame:SetPoint("LEFT", panel, "LEFT", 10, 0)
|
||||
modelFrame:SetPoint("RIGHT", panel, "RIGHT", -10, 0)
|
||||
modelFrame:SetUnit("player")
|
||||
modelFrame:SetModelScale(1.0)
|
||||
|
||||
-- 启用鼠标旋转
|
||||
modelFrame:EnableMouse(true)
|
||||
modelFrame:SetScript("OnMouseDown", function(self, button)
|
||||
if button == "LeftButton" then
|
||||
self.rotating = true
|
||||
self.startX, self.startY = GetCursorPosition()
|
||||
end
|
||||
end)
|
||||
|
||||
modelFrame:SetScript("OnMouseUp", function(self, button)
|
||||
if button == "LeftButton" then
|
||||
self.rotating = false
|
||||
end
|
||||
end)
|
||||
|
||||
modelFrame:SetScript("OnUpdate", function(self)
|
||||
if self.rotating then
|
||||
local x, y = GetCursorPosition()
|
||||
local dx = x - (self.startX or x)
|
||||
self.startX, self.startY = x, y
|
||||
|
||||
-- 根据鼠标移动调整模型朝向
|
||||
self:SetFacing(self:GetFacing() + dx / 100)
|
||||
end
|
||||
end)
|
||||
|
||||
-- 保存模型引用
|
||||
self.enchantPlayerModel = modelFrame
|
||||
|
||||
-- 测试使用默认武器
|
||||
local defaultWeaponID = 30227 -- 一个好看的双手武器
|
||||
if modelFrame.SetItem then
|
||||
modelFrame:SetItem(defaultWeaponID)
|
||||
elseif modelFrame.TryOn then
|
||||
modelFrame:TryOn("item:" .. defaultWeaponID)
|
||||
end
|
||||
|
||||
-- 确保模型可见
|
||||
modelFrame:Show()
|
||||
|
||||
-- 确保所有附魔元素都正确设置父元素
|
||||
if self.enchantTitleText and self.enchantTitleText.SetParent then
|
||||
self.enchantTitleText:SetParent(panel)
|
||||
end
|
||||
|
||||
if self.enchantPlayerModel and self.enchantPlayerModel.SetParent then
|
||||
self.enchantPlayerModel:SetParent(panel)
|
||||
end
|
||||
|
||||
-- 设置更高的框架层级,确保显示在顶层
|
||||
-- 增加安全检查,确保对象存在且有SetFrameLevel方法
|
||||
if self.enchantTitleText and self.enchantTitleText.SetFrameLevel then
|
||||
self.enchantTitleText:SetFrameLevel(panel:GetFrameLevel() + 150)
|
||||
end
|
||||
|
||||
if self.enchantPlayerModel and self.enchantPlayerModel.SetFrameLevel then
|
||||
self.enchantPlayerModel:SetFrameLevel(panel:GetFrameLevel() + 150)
|
||||
end
|
||||
|
||||
-- 打印调试信息
|
||||
if panel and panel.GetFrameLevel then
|
||||
print("右侧面板层级:", panel:GetFrameLevel())
|
||||
end
|
||||
if self.enchantTitleText and self.enchantTitleText.GetFrameLevel then
|
||||
print("标题文本层级:", self.enchantTitleText:GetFrameLevel())
|
||||
end
|
||||
if self.enchantPlayerModel and self.enchantPlayerModel.GetFrameLevel then
|
||||
print("模型层级:", self.enchantPlayerModel:GetFrameLevel())
|
||||
end
|
||||
|
||||
-- 最后一次检查确保召唤按钮不会显示
|
||||
if panel.CallButon then
|
||||
panel.CallButon:Hide()
|
||||
end
|
||||
|
||||
return panel
|
||||
end
|
||||
|
||||
-- 恢复右侧面板的正常显示
|
||||
function SM_ItemCollectionUI:RestoreRightSidePanel()
|
||||
local panel = SM_Collections.MainFrame.RightSidePanel
|
||||
if not panel then return end
|
||||
|
||||
-- 隐藏附魔相关元素
|
||||
if self.enchantTitleText then
|
||||
self.enchantTitleText:Hide()
|
||||
-- 不再尝试设置父元素为nil,只是隐藏并释放引用
|
||||
self.enchantTitleText = nil
|
||||
end
|
||||
|
||||
if self.enchantPlayerModel then
|
||||
self.enchantPlayerModel:Hide()
|
||||
-- 不再尝试设置父元素为nil,只是隐藏并释放引用
|
||||
self.enchantPlayerModel = nil
|
||||
end
|
||||
|
||||
-- 恢复保存的原始内容
|
||||
if panel.originalContent then
|
||||
-- 恢复子元素
|
||||
for _, childInfo in ipairs(panel.originalContent.children or {}) do
|
||||
if childInfo and childInfo.element and childInfo.visible then
|
||||
childInfo.element:Show()
|
||||
end
|
||||
end
|
||||
|
||||
-- 恢复区域
|
||||
for _, regionInfo in ipairs(panel.originalContent.regions or {}) do
|
||||
if regionInfo and regionInfo.element and regionInfo.visible then
|
||||
regionInfo.element:Show()
|
||||
end
|
||||
end
|
||||
|
||||
-- 清除保存的内容
|
||||
panel.originalContent = nil
|
||||
else
|
||||
-- 如果没有保存的内容,确保所有区域和子元素可见
|
||||
local regions = {panel:GetRegions()}
|
||||
for _, region in ipairs(regions) do
|
||||
region:Show()
|
||||
end
|
||||
end
|
||||
|
||||
-- 保存当前物品类型信息,用于恢复标题和描述
|
||||
local currentSlot = self.currentSelectedButton and self.currentSelectedButton.slotData
|
||||
local itemID = currentSlot and currentSlot.items and currentSlot.items[1] or nil
|
||||
local slotName = currentSlot and currentSlot.name or "物品收藏"
|
||||
|
||||
-- 恢复标题文本
|
||||
if panel.MountNama then
|
||||
panel.MountNama:Show()
|
||||
-- 更新标题内容
|
||||
if itemID then
|
||||
local itemName = GetItemInfo(itemID) or ""
|
||||
panel.MountNama:SetText(itemName)
|
||||
else
|
||||
panel.MountNama:SetText(slotName)
|
||||
end
|
||||
end
|
||||
|
||||
-- 恢复介绍文本
|
||||
if panel.introText then
|
||||
panel.introText:Show()
|
||||
-- 更新介绍内容
|
||||
if currentSlot then
|
||||
if itemID then
|
||||
panel.introText:SetText("物品ID: " .. itemID .. "\n类型: " .. slotName)
|
||||
else
|
||||
panel.introText:SetText("类型: " .. slotName .. "\n暂无物品数据")
|
||||
end
|
||||
else
|
||||
panel.introText:SetText("请选择物品类型")
|
||||
end
|
||||
end
|
||||
|
||||
-- 恢复物品状态显示
|
||||
if itemID and panel.statusText 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
|
||||
|
||||
local statusText = itemData and itemData.obtained and "|cFF00FF00已获得|r" or "|cFFFF0000未获得|r"
|
||||
panel.statusText:SetText(statusText)
|
||||
panel.statusText:Show()
|
||||
end
|
||||
|
||||
-- 恢复属性加成框架
|
||||
if panel.AttributeBonusFrame then
|
||||
if currentSlot and currentSlot.items and #currentSlot.items > 0 then
|
||||
panel.AttributeBonusFrame:Show()
|
||||
-- 如果需要,更新属性数据
|
||||
if itemID then
|
||||
self:UpdateAttributes(itemID, currentSlot.invType)
|
||||
end
|
||||
else
|
||||
panel.AttributeBonusFrame:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
-- 显示分页按钮
|
||||
self:ShowPageButtons()
|
||||
|
||||
-- 取消附魔模式标记
|
||||
self.inEnchantMode = false
|
||||
|
||||
-- 显示当前选中的按钮状态
|
||||
if self.currentSelectedButton and self.currentSelectedButton.SelectedTexture then
|
||||
self.currentSelectedButton.SelectedTexture:Show()
|
||||
end
|
||||
end
|
||||
|
||||
-- 创建附魔预览框架
|
||||
function SM_ItemCollectionUI:CreateEnchantPreviewFrame()
|
||||
local previewFrame = self.previewFrame
|
||||
|
||||
-- 创建附魔预览容器
|
||||
local enchantPreview = CreateFrame("Frame", "ItemCollectionEnchantPreviewFrame", previewFrame)
|
||||
enchantPreview:SetSize(580, 410)
|
||||
enchantPreview:SetPoint("TOPLEFT", 0, 0)
|
||||
enchantPreview:SetPoint("BOTTOMRIGHT", 0, 0)
|
||||
self.enchantPreviewFrame = enchantPreview
|
||||
|
||||
-- 创建6x3网格的附魔预览按钮
|
||||
self.enchantButtons = {}
|
||||
|
||||
local COLUMNS = 6
|
||||
local ROWS = 3
|
||||
local BUTTON_WIDTH = 85
|
||||
local BUTTON_HEIGHT = 110
|
||||
local X_SPACING = 8
|
||||
local Y_SPACING = 10
|
||||
local START_X = 10
|
||||
local START_Y = -10
|
||||
|
||||
for i = 1, ROWS do
|
||||
for j = 1, COLUMNS do
|
||||
local index = (i-1) * COLUMNS + j
|
||||
local button = self:CreateEnchantEffectButton(enchantPreview, index)
|
||||
|
||||
-- 设置位置
|
||||
local xPos = START_X + (j-1) * (BUTTON_WIDTH + X_SPACING)
|
||||
local yPos = START_Y - (i-1) * (BUTTON_HEIGHT + Y_SPACING)
|
||||
button:SetPoint("TOPLEFT", xPos, yPos)
|
||||
|
||||
table.insert(self.enchantButtons, button)
|
||||
end
|
||||
end
|
||||
|
||||
-- 创建翻页按钮
|
||||
local prevPageButton = CreateFrame("Button", "EnchantPrevPageButton", enchantPreview, "UIPanelButtonTemplate")
|
||||
prevPageButton:SetSize(80, 22)
|
||||
prevPageButton:SetPoint("BOTTOMLEFT", 10, 10)
|
||||
prevPageButton:SetText("上一页")
|
||||
prevPageButton:SetScript("OnClick", function()
|
||||
local currentPage = self.currentEnchantPage or 1
|
||||
if currentPage > 1 then
|
||||
self:ShowEnchantPage(currentPage - 1)
|
||||
end
|
||||
end)
|
||||
self.enchantPrevPageButton = prevPageButton
|
||||
|
||||
local nextPageButton = CreateFrame("Button", "EnchantNextPageButton", enchantPreview, "UIPanelButtonTemplate")
|
||||
nextPageButton:SetSize(80, 22)
|
||||
nextPageButton:SetPoint("BOTTOMRIGHT", -10, 10)
|
||||
nextPageButton:SetText("下一页")
|
||||
nextPageButton:SetScript("OnClick", function()
|
||||
local currentPage = self.currentEnchantPage or 1
|
||||
local totalPages = math.ceil(#self.currentEnchantList / (ROWS * COLUMNS))
|
||||
if currentPage < totalPages then
|
||||
self:ShowEnchantPage(currentPage + 1)
|
||||
end
|
||||
end)
|
||||
self.enchantNextPageButton = nextPageButton
|
||||
|
||||
-- 页码显示
|
||||
local pageText = enchantPreview:CreateFontString(nil, "ARTWORK", "GameFontNormal")
|
||||
pageText:SetPoint("BOTTOM", 0, 10)
|
||||
pageText:SetText("1/1")
|
||||
self.enchantPageText = pageText
|
||||
|
||||
return enchantPreview
|
||||
end
|
||||
|
||||
-- 创建单个附魔效果预览按钮
|
||||
function SM_ItemCollectionUI:CreateEnchantEffectButton(parent, index)
|
||||
local button = CreateFrame("Button", "EnchantEffectButton"..index, parent)
|
||||
button:SetSize(85, 110)
|
||||
|
||||
-- 创建边框
|
||||
local border = button:CreateTexture(nil, "BACKGROUND")
|
||||
border:SetSize(85, 110)
|
||||
border:SetPoint("CENTER")
|
||||
border:SetTexture("Interface\\AddOns\\SM_CollectionSystem\\Textures\\liebiaoditu_kuang_A")
|
||||
|
||||
-- 创建模型查看器(使用DressUpModel或Model而不是PlayerModel,更适合3.3.5)
|
||||
local modelFrame = CreateFrame("DressUpModel", "EnchantEffectModel"..index, button)
|
||||
modelFrame:SetSize(75, 100)
|
||||
modelFrame:SetPoint("CENTER")
|
||||
modelFrame:SetUnit("none") -- 初始化为空
|
||||
modelFrame:SetModelScale(1.0)
|
||||
button.modelFrame = modelFrame
|
||||
print("创建模型框架 #" .. index .. ", 类型: DressUpModel")
|
||||
|
||||
-- 创建选中高亮
|
||||
local highlight = button:CreateTexture(nil, "HIGHLIGHT")
|
||||
highlight:SetSize(85, 110)
|
||||
highlight:SetPoint("CENTER")
|
||||
highlight:SetTexture("Interface\\AddOns\\SM_CollectionSystem\\Textures\\liebiaoditu_kuang_B")
|
||||
highlight:SetBlendMode("ADD")
|
||||
|
||||
-- 创建选中状态
|
||||
local selected = button:CreateTexture(nil, "OVERLAY")
|
||||
selected:SetSize(85, 110)
|
||||
selected:SetPoint("CENTER")
|
||||
selected:SetTexture("Interface\\AddOns\\SM_CollectionSystem\\Textures\\liebiaoditu_kuang_C")
|
||||
selected:Hide()
|
||||
button.selectedTexture = selected
|
||||
|
||||
-- 名称标签
|
||||
local name = button:CreateFontString(nil, "OVERLAY", "GameFontNormal")
|
||||
name:SetPoint("BOTTOM", 0, 5)
|
||||
name:SetWidth(80)
|
||||
name:SetHeight(20)
|
||||
name:SetJustifyH("CENTER")
|
||||
button.nameText = name
|
||||
|
||||
-- 点击事件
|
||||
button:SetScript("OnClick", function(self)
|
||||
-- 清除所有按钮选中状态
|
||||
for _, btn in ipairs(SM_ItemCollectionUI.enchantButtons) do
|
||||
btn.selectedTexture:Hide()
|
||||
end
|
||||
|
||||
-- 设置当前按钮选中状态
|
||||
self.selectedTexture:Show()
|
||||
|
||||
-- 应用附魔效果
|
||||
if self.enchantData then
|
||||
SM_ItemCollectionUI:ApplyEnchantEffect(self.enchantData)
|
||||
end
|
||||
end)
|
||||
|
||||
button:SetScript("OnEnter", function(self)
|
||||
if self.enchantData then
|
||||
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
|
||||
GameTooltip:SetText(self.enchantData.name)
|
||||
GameTooltip:AddLine(self.enchantData.description or "武器附魔效果", 1, 1, 1, true)
|
||||
GameTooltip:Show()
|
||||
end
|
||||
end)
|
||||
|
||||
button:SetScript("OnLeave", function()
|
||||
GameTooltip:Hide()
|
||||
end)
|
||||
|
||||
return button
|
||||
end
|
||||
|
||||
-- 加载附魔效果数据
|
||||
function SM_ItemCollectionUI:LoadEnchantEffects(slotType)
|
||||
-- 这里可以根据不同的武器类型加载不同的附魔数据
|
||||
-- 示例数据,实际中应该从配置文件或数据库中读取
|
||||
local enchantEffects = {
|
||||
-- 格式: {id = 附魔ID, name = "附魔名称", description = "描述", weaponId = 默认武器ID}
|
||||
{id = 3789, name = "烈焰武器", description = "火焰附魔效果", weaponId = 30227}, -- 红色
|
||||
{id = 1903, name = "冰霜武器", description = "冰霜附魔效果", weaponId = 30227}, -- 蓝色
|
||||
{id = 1896, name = "生命偷取", description = "生命偷取效果", weaponId = 30227}, -- 紫色
|
||||
{id = 2674, name = "法术能量", description = "法术能量效果", weaponId = 30227}, -- 浅蓝色
|
||||
{id = 3844, name = "极效敏捷", description = "增加敏捷效果", weaponId = 30227}, -- 黄色
|
||||
{id = 2675, name = "魔法冷却", description = "魔法冷却效果", weaponId = 30227}, -- 青色
|
||||
{id = 3222, name = "干枯能量", description = "干枯能量效果", weaponId = 30227}, -- 红色
|
||||
{id = 3273, name = "断筋毒药", description = "断筋毒药效果", weaponId = 30227}, -- 绿色
|
||||
{id = 2671, name = "坚韧", description = "坚韧效果", weaponId = 30227}, -- 白色
|
||||
{id = 3225, name = "锐利", description = "锐利效果", weaponId = 30227}, -- 紫蓝色
|
||||
{id = 3239, name = "火焰石", description = "火焰石效果", weaponId = 30227}, -- 橙色
|
||||
{id = 2667, name = "强效魔法", description = "强效魔法效果", weaponId = 30227}, -- 蓝紫色
|
||||
{id = 2670, name = "圣光", description = "圣光效果", weaponId = 30227}, -- 黄白色
|
||||
{id = 2671, name = "次级坚韧", description = "次级坚韧效果", weaponId = 30227}, -- 白色
|
||||
{id = 3241, name = "暗影石", description = "暗影石效果", weaponId = 30227}, -- 深紫色
|
||||
{id = 2672, name = "智慧", description = "智慧效果", weaponId = 30227}, -- 青蓝色
|
||||
{id = 2673, name = "强效智力", description = "强效智力效果", weaponId = 30227}, -- 明亮蓝色
|
||||
{id = 3251, name = "巨石板锤", description = "巨石板锤效果", weaponId = 30227}, -- 蓝绿色
|
||||
}
|
||||
|
||||
self.currentEnchantList = enchantEffects
|
||||
self.currentEnchantPage = 1
|
||||
self.currentEnchantType = slotType
|
||||
|
||||
-- 显示第一页
|
||||
self:ShowEnchantPage(1)
|
||||
end
|
||||
|
||||
-- 显示指定页的附魔效果
|
||||
function SM_ItemCollectionUI:ShowEnchantPage(page)
|
||||
local ITEMS_PER_PAGE = 18 -- 6x3
|
||||
local startIndex = (page - 1) * ITEMS_PER_PAGE + 1
|
||||
local endIndex = math.min(startIndex + ITEMS_PER_PAGE - 1, #self.currentEnchantList)
|
||||
|
||||
-- 更新页码显示
|
||||
local totalPages = math.ceil(#self.currentEnchantList / ITEMS_PER_PAGE)
|
||||
self.enchantPageText:SetText(page.."/"..totalPages)
|
||||
self.currentEnchantPage = page
|
||||
|
||||
-- 更新按钮状态
|
||||
if page > 1 then
|
||||
self.enchantPrevPageButton:Enable()
|
||||
else
|
||||
self.enchantPrevPageButton:Disable()
|
||||
end
|
||||
|
||||
if page < totalPages then
|
||||
self.enchantNextPageButton:Enable()
|
||||
else
|
||||
self.enchantNextPageButton:Disable()
|
||||
end
|
||||
|
||||
-- 隐藏所有按钮
|
||||
for _, button in ipairs(self.enchantButtons) do
|
||||
button:Hide()
|
||||
button.selectedTexture:Hide()
|
||||
button.enchantData = nil
|
||||
end
|
||||
|
||||
-- 显示当前页的附魔效果
|
||||
local buttonIndex = 1
|
||||
for i = startIndex, endIndex do
|
||||
local enchantData = self.currentEnchantList[i]
|
||||
local button = self.enchantButtons[buttonIndex]
|
||||
|
||||
if button and enchantData then
|
||||
button.enchantData = enchantData
|
||||
button.nameText:SetText(enchantData.name)
|
||||
button:Show()
|
||||
|
||||
-- 设置模型显示
|
||||
self:SetupEnchantModel(button.modelFrame, enchantData)
|
||||
|
||||
buttonIndex = buttonIndex + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- 设置附魔模型显示
|
||||
function SM_ItemCollectionUI:SetupEnchantModel(model, enchantData)
|
||||
-- 安全检查:确保模型对象存在
|
||||
if not model or type(model) ~= "table" or not model.SetModelScale then
|
||||
print("错误: 无效的模型对象")
|
||||
return
|
||||
end
|
||||
|
||||
-- 重置模型
|
||||
if model.ClearModel then
|
||||
model:ClearModel()
|
||||
end
|
||||
|
||||
-- 设置为隐形NPC以显示武器
|
||||
if model.SetDisplayID then
|
||||
model:SetDisplayID(21723) -- 通用隐形生物ID
|
||||
elseif model.SetCreature then
|
||||
model:SetCreature(21723)
|
||||
elseif model.SetUnit then
|
||||
model:SetUnit("none")
|
||||
end
|
||||
|
||||
-- 设置缩放
|
||||
model:SetModelScale(1.0)
|
||||
|
||||
-- 手持附魔武器
|
||||
local enchantedItemLink = "item:" .. enchantData.weaponId .. ":" .. enchantData.id
|
||||
if model.TryOn then
|
||||
model:TryOn(enchantedItemLink)
|
||||
elseif model.SetItem then
|
||||
model:SetItem(enchantData.weaponId)
|
||||
end
|
||||
|
||||
-- 调整位置和角度使武器竖直显示
|
||||
if model.SetPosition then
|
||||
-- 调整到略微上方并前倾以便更好地展示武器
|
||||
model:SetPosition(0.2, 0, -0.1)
|
||||
end
|
||||
|
||||
if model.SetFacing then
|
||||
model:SetFacing(0.5) -- 稍微旋转以便更好地看到武器
|
||||
end
|
||||
|
||||
-- 确保模型可见
|
||||
model:Show()
|
||||
end
|
||||
|
||||
-- 应用选中的附魔效果
|
||||
function SM_ItemCollectionUI:ApplyEnchantEffect(enchantData)
|
||||
-- 获取预览模型(使用新的右侧角色模型)
|
||||
local previewModel = self.enchantPlayerModel
|
||||
if not previewModel then
|
||||
print("错误: 右侧预览模型不存在")
|
||||
return
|
||||
end
|
||||
|
||||
-- 获取当前玩家装备的武器或使用默认武器
|
||||
local weaponID = self:GetPlayerWeaponID() or enchantData.weaponId
|
||||
|
||||
-- 创建附魔武器链接
|
||||
local enchantedWeaponLink = "item:" .. weaponID .. ":" .. enchantData.id
|
||||
|
||||
-- 更新右侧标题为附魔名称
|
||||
if self.enchantTitleText then
|
||||
self.enchantTitleText:SetText(enchantData.name)
|
||||
end
|
||||
|
||||
print("准备应用附魔物品:", enchantedWeaponLink)
|
||||
|
||||
-- 保存当前的角色朝向和位置
|
||||
local currentFacing = previewModel:GetFacing()
|
||||
local currentPosition = {previewModel:GetPosition()}
|
||||
|
||||
-- 在预览模型上应用附魔武器
|
||||
if previewModel.TryOn then
|
||||
previewModel:TryOn(enchantedWeaponLink)
|
||||
print("应用附魔效果:", enchantData.name, "到武器ID:", weaponID)
|
||||
else
|
||||
print("错误: 预览模型没有TryOn方法,尝试使用替代方法")
|
||||
|
||||
-- 尝试使用其他方法
|
||||
if previewModel.SetModel then
|
||||
-- 尝试直接设置模型
|
||||
print("尝试使用SetModel方法")
|
||||
previewModel:SetModel("Interface\\Buttons\\TalkToMeQuestionMark.mdx")
|
||||
end
|
||||
|
||||
-- 如果有SetItem方法,直接显示物品
|
||||
if previewModel.SetItem then
|
||||
print("尝试使用SetItem方法")
|
||||
previewModel:SetItem(weaponID)
|
||||
end
|
||||
end
|
||||
|
||||
-- 恢复之前的朝向和位置,保持用户的视角设置
|
||||
previewModel:SetFacing(currentFacing)
|
||||
if #currentPosition == 3 then
|
||||
previewModel:SetPosition(currentPosition[1], currentPosition[2], currentPosition[3])
|
||||
end
|
||||
|
||||
-- 确保模型可见
|
||||
previewModel:Show()
|
||||
end
|
||||
|
||||
-- 获取玩家当前装备的武器ID
|
||||
function SM_ItemCollectionUI:GetPlayerWeaponID()
|
||||
-- 检查主手和副手武器槽
|
||||
local mainHandID = GetInventoryItemID("player", 16) -- 16是主手武器槽
|
||||
local offHandID = GetInventoryItemID("player", 17) -- 17是副手武器槽
|
||||
|
||||
return mainHandID or offHandID
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user