WOW_Collection_System/SM_UI_MainFrame.lua

536 lines
22 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- SM_UI_MainFrame.lua
-- 创建主界面
function SM_Collections:CreateMainFrame()
if self.MainFrame then
return self.MainFrame
end
SM_Collections_Frame = CreateFrame("Frame", "SM_Collections_MainFrame", UIParent);
SM_Collections_Frame:SetSize(800, 540);
SM_Collections_Frame:SetPoint("CENTER", 0, 0);
SM_Collections_Frame_Texture = SM_Collections_Frame:CreateTexture(nil, 'OVERLAY')
SM_Collections_Frame_Texture:SetPoint('TOP')
SM_Collections_Frame_Texture:SetAllPoints(SM_Collections_Frame)
SM_Collections_Frame_Texture:SetTexture("Interface\\AddOns\\SM_CollectionSystem\\Textures\\back")
-- 左上角圆形头像/LOGO - 修改为存储引用
local icon = SM_Collections_Frame:CreateTexture(nil, "ARTWORK")
icon:SetSize(80, 80)
icon:SetPoint("TOPLEFT", 5, -5)
SetPortraitToTexture(icon, "Interface\\ICONS\\Ability_Mount_RidingHorse") -- 默认显示坐骑图标
SM_Collections_Frame.cornerIcon = icon -- 存储引用
-- 标题
local title = SM_Collections_Frame:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
title:SetPoint("TOP", 0, -20)
title:SetText("我的收藏系统")
-- 关闭按钮
local closeBtn = CreateFrame("Button", "SM_CollectionsCloseBtn", SM_Collections_Frame, "UIPanelCloseButton")
closeBtn:SetSize(40, 40)
closeBtn:SetPoint("TOPRIGHT", 4, -8)
closeBtn:SetScript("OnClick", function() SM_Collections_Frame:Hide() end)
-- -- 测试按钮
-- local WardrobeSlotButton = CreateFrame("Button", "SM_CollectionsWardrobeSlotButton", closeBtn, "SM_CollectionSystemWardrobeItemsModelTemplate")
-- WardrobeSlotButton:SetPoint("TOPRIGHT", 10, 10)
-- WardrobeSlotButton:SetScript("OnClick", function()
-- SM_Collections_Frame:Hide()
-- end)
-- 创建右侧面板容器
local rightSidePanel = CreateFrame("Frame", "SM_CollectionsRightSidePanel", SM_Collections_Frame)
rightSidePanel:SetSize(170, 420)
rightSidePanel:SetPoint("TOPRIGHT", -15, -80)
SM_Collections_Frame.RightSidePanel = rightSidePanel
self.RightSidePanel = rightSidePanel
-- 添加底部衬托纹理:作为背景。
rightSidePanel.ItemFrameTexture1 = rightSidePanel:CreateTexture(nil, "BORDER")
rightSidePanel.ItemFrameTexture1:SetAllPoints(rightSidePanel)
-- rightSidePanel.ItemFrameTexture1:SetTexture( "Interface\\AddOns\\SM_CollectionSystem\\Interface\\Buttons\\Boxes_Pushed")
-- 坐骑名称文本 - 使用自定义字体
local titleFont = CreateFont("SM_TitleFont")
titleFont:SetFont("Fonts\\ZYKai_T.ttf", 20, "MONOCHROME")
-- 坐骑召唤、小伙伴召唤、卡牌召唤按钮
rightSidePanel.CallButon = CreateFrame("Button", "SM_CollectionsRightSidePanelCallButon", rightSidePanel)
rightSidePanel.CallButon:SetSize(30, 30)
rightSidePanel.CallButon:SetPoint("TOPRIGHT", -40, 30)
rightSidePanel.CallButon:SetNormalTexture("Interface\\ICONS\\Ability_Mount_RidingHorse.blp")
rightSidePanel.CallButon:SetHighlightTexture("Interface\\ICONS\\Ability_Mount_RidingHorse.blp")
rightSidePanel.CallButon:SetPushedTexture("Interface\\ICONS\\Ability_Mount_RidingHorse.blp")
rightSidePanel.CallButon:SetScript("OnClick", function() print("召唤") end)
rightSidePanel.CallButon = rightSidePanel.CallButon
rightSidePanel.CallButon.String = rightSidePanel.CallButon:CreateFontString(nil, "OVERLAY", "GameFontNormal")
rightSidePanel.CallButon.String:SetPoint("RIGHT",rightSidePanel.CallButon,"LEFT", -10, 0)
rightSidePanel.CallButon.String:SetText("随机召唤坐骑")
rightSidePanel.CallButon.String:SetFontObject(titleFont)
rightSidePanel.CallButon.String:SetTextColor(230 / 255, 150 / 255, 0 / 255)
rightSidePanel.CallButon.String:SetFont("Fonts\\ZYKai_T.ttf", 16, "MONOCHROME")
-- 创建标题容器
local titleContainer = CreateFrame("Frame", nil, rightSidePanel)
titleContainer:SetSize(180, 50) -- 增加高度给文本更多空间
titleContainer:SetPoint("TOP", rightSidePanel, "TOP", 0, -15) -- 居中放置,与顶部保持一定距离
-- 添加背景以便于调试 (可选)
titleContainer.bg = titleContainer:CreateTexture(nil, "BACKGROUND")
titleContainer.bg:SetAllPoints()
-- 坐骑名称文本框 - 增加大小和可见性
local MountNama = titleContainer:CreateFontString(nil, "OVERLAY")
MountNama:SetPoint("TOP", titleContainer, "TOP", 0, -5) -- 放在顶部中间位置
MountNama:SetFontObject(titleFont)
MountNama:SetSize(170, 40) -- 增加大小
MountNama:SetText("坐骑名称测试") -- 设置默认文本用于测试
MountNama:SetJustifyH("CENTER") -- 居中对齐
MountNama:SetJustifyV("TOP")
MountNama:SetTextColor(1, 1, 0) -- 更改为鲜黄色,更易于看见
-- 设置高层级
MountNama:SetDrawLayer("OVERLAY", 7)
rightSidePanel.MountNama = MountNama
-- 创建介绍文本容器
local introContainer = CreateFrame("Frame", nil, titleContainer)
introContainer:SetSize(180, 120) -- 增加高度以容纳更多文本
introContainer:SetPoint("TOP", titleContainer, "BOTTOM", 0, -5) -- 放在标题容器下方,居中对齐
-- 介绍文本 - 使用自定义字体
local descFont = CreateFont("SM_DescFont")
descFont:SetFont("Fonts\\ZYKai_T.ttf", 10, "MONOCHROME")
local introText = introContainer:CreateFontString(nil, "OVERLAY")
introText:SetPoint("TOP", introContainer, "TOP", 0, 0) -- 放在介绍容器顶部中间
introText:SetSize(170, 0) -- 宽度固定,高度自适应
introText:SetJustifyH("CENTER") -- 居中对齐
introText:SetJustifyV("TOP")
introText:SetSpacing(2)
introText:SetWordWrap(true)
introText:SetFontObject(descFont)
introText:SetText("")
rightSidePanel.introText = introText
-- 属性加成标题 - 调整位置防止与介绍文本重叠
local AttributeBonusFrame = CreateFrame("Frame", "AttributeBonusFrame", rightSidePanel)
AttributeBonusFrame:SetSize(150, 20)
AttributeBonusFrame:SetPoint("CENTER", rightSidePanel, "CENTER", 0,30) -- 增加间距
AttributeBonusFrame:SetBackdrop({ bgFile = "Interface\\AddOns\\SM_CollectionSystem\\Textures\\AttributeBonusFrame" })
local AttributeBonusFrameText = AttributeBonusFrame:CreateFontString(nil, "OVERLAY")
AttributeBonusFrameText:SetPoint("CENTER", 0, 0)
AttributeBonusFrameText:SetFontObject(titleFont)
AttributeBonusFrameText:SetText("属性加成")
AttributeBonusFrameText:SetFont("Fonts\\ZYKai_T.ttf", 16, "MONOCHROME")
AttributeBonusFrame:Hide()
rightSidePanel.AttributeBonusFrame = AttributeBonusFrame
-- 拖拽功能
SM_Collections_Frame:SetScript("OnMouseDown", function(self, button)
if button == "LeftButton" then
self:StartMoving()
end
end)
SM_Collections_Frame:SetScript("OnMouseUp", function(self, button)
if button == "LeftButton" then
self:StopMovingOrSizing()
end
end)
-- 创建标签页
self:CreateTabs(SM_Collections_Frame)
-- 创建内容区域
local contentFrame = CreateFrame("Frame", "SM_CollectionsContentFrame", SM_Collections_Frame)
contentFrame:SetPoint("TOPLEFT", 20, -80)
contentFrame:SetPoint("BOTTOMRIGHT", -20, 20)
SM_Collections_Frame.ContentFrame = contentFrame
self.MainFrame = SM_Collections_Frame
-- 默认显示坐骑标签页
self:UpdateTabAppearance(1)
self:ShowTab(1)
return SM_Collections_Frame
end
-- 创建标签页
function SM_Collections:CreateTabs(parent)
local tabs = {}
local tabNames = { "坐骑收藏", "小伙伴收藏", "卡牌收藏", "物品收藏" }
for i = 1, #tabNames do
local tab = CreateFrame("Button", "SM_CollectionTab" .. i, parent, "CharacterFrameTabButtonTemplate")
tab:SetSize(120, 32)
tab:SetID(i)
if i == 1 then
tab:SetPoint("TOPLEFT", parent, "BOTTOMLEFT", 20, 12)
else
tab:SetPoint("LEFT", tabs[i - 1], "RIGHT", -15, 0) -- 修改标签之间的间隔
end
tab:SetText(tabNames[i])
tab:SetScript("OnClick", function(self)
SM_Collections:UpdateTabAppearance(self:GetID())
SM_Collections:ShowTab(self:GetID())
PlaySound("igCharacterInfoTab")
end)
-- 处理模板中的纹理层
-- 1. 获取禁用状态的纹理并隐藏它们
local leftDisabled = _G[tab:GetName().."LeftDisabled"]
local middleDisabled = _G[tab:GetName().."MiddleDisabled"]
local rightDisabled = _G[tab:GetName().."RightDisabled"]
if leftDisabled then leftDisabled:Hide() end
if middleDisabled then middleDisabled:Hide() end
if rightDisabled then rightDisabled:Hide() end
-- 2. 调整标准纹理的位置和大小
local left = _G[tab:GetName().."Left"]
local middle = _G[tab:GetName().."Middle"]
local right = _G[tab:GetName().."Right"]
if left and middle and right then
-- 确保纹理对齐正确
left:ClearAllPoints()
left:SetPoint("TOPLEFT", tab, "TOPLEFT", 0, 0)
middle:ClearAllPoints()
middle:SetPoint("LEFT", left, "RIGHT", 0, 0)
middle:SetWidth(tab:GetWidth() - 40) -- 减去左右两侧的宽度
right:ClearAllPoints()
right:SetPoint("LEFT", middle, "RIGHT", 0, 0)
end
-- 添加鼠标悬停时的高亮效果
tab:HookScript("OnEnter", function(self)
if self:GetID() ~= SM_Collections.MainFrame.selectedTab then
local highlight = _G[self:GetName().."HighlightTexture"]
if highlight then
highlight:Show()
highlight:SetAlpha(0.7)
highlight:SetBlendMode("ADD")
end
end
end)
-- 鼠标离开时恢复正常状态
tab:HookScript("OnLeave", function(self)
if self:GetID() ~= SM_Collections.MainFrame.selectedTab then
local highlight = _G[self:GetName().."HighlightTexture"]
if highlight then
highlight:Hide()
end
end
end)
tabs[i] = tab
end
parent.tabs = tabs
parent.numTabs = #tabNames
parent.selectedTab = 1
self:UpdateTabAppearance(1)
end
-- 更新标签页外观
function SM_Collections:UpdateTabAppearance(selectedTab)
if not self.MainFrame or not self.MainFrame.tabs then return end
for i = 1, self.MainFrame.numTabs do
local tab = self.MainFrame.tabs[i]
if tab then
local left = _G[tab:GetName().."Left"]
local middle = _G[tab:GetName().."Middle"]
local right = _G[tab:GetName().."Right"]
local highlight = _G[tab:GetName().."HighlightTexture"]
if i == selectedTab then
tab:SetAlpha(1.0)
-- 显示选中状态的纹理
if left and middle and right then
-- 设置选中状态纹理使用UI-Character-ActiveTab纹理
left:SetTexture("Interface\\PaperDollInfoFrame\\UI-Character-ActiveTab")
middle:SetTexture("Interface\\PaperDollInfoFrame\\UI-Character-ActiveTab")
right:SetTexture("Interface\\PaperDollInfoFrame\\UI-Character-ActiveTab")
end
-- 强化选中标签的文本颜色
if tab.GetFontString and tab:GetFontString() then
tab:GetFontString():SetTextColor(1, 1, 0) -- 选中的标签使用金黄色文字
tab:GetFontString():SetFont(tab:GetFontString():GetFont(), 13, "OUTLINE") -- 添加字体轮廓
end
-- 显示一个额外的高亮效果
if highlight then
highlight:Show()
highlight:SetAlpha(0.5) -- 让高亮效果在选中状态下也显示
highlight:SetBlendMode("ADD")
end
-- 提高选中标签的层级
tab:SetFrameLevel(self.MainFrame:GetFrameLevel() + 6)
else
tab:SetAlpha(0.9)
-- 显示未选中状态的纹理
if left and middle and right then
-- 设置未选中状态纹理使用UI-Character-InActiveTab纹理
left:SetTexture("Interface\\PaperDollInfoFrame\\UI-Character-InActiveTab")
middle:SetTexture("Interface\\PaperDollInfoFrame\\UI-Character-InActiveTab")
right:SetTexture("Interface\\PaperDollInfoFrame\\UI-Character-InActiveTab")
end
-- 恢复未选中标签的正常文本样式
if tab.GetFontString and tab:GetFontString() then
tab:GetFontString():SetTextColor(0.8, 0.8, 0.8) -- 未选中的标签使用浅灰色文字
tab:GetFontString():SetFont(tab:GetFontString():GetFont(), 12, "") -- 恢复正常字体大小
end
-- 鼠标未悬停状态下隐藏高亮效果
if highlight then
highlight:Hide() -- 完全隐藏高亮效果
end
-- 降低未选中标签的层级
tab:SetFrameLevel(self.MainFrame:GetFrameLevel() + 4)
end
end
end
self.MainFrame.selectedTab = selectedTab
self.CurrentTab = selectedTab
end
-- 更新左上角图标
function SM_Collections:UpdateCornerIcon(tabID)
if not self.MainFrame or not self.MainFrame.cornerIcon then return end
local iconTexture = "Interface\\ICONS\\Ability_Mount_RidingHorse" -- 默认坐骑图标
if tabID == 1 then -- 坐骑收藏
iconTexture = "Interface\\ICONS\\Ability_Mount_RidingHorse"
elseif tabID == 2 then -- 小伙伴收藏
iconTexture = "Interface\\ICONS\\Ability_Hunter_BeastCall"
elseif tabID == 3 then -- 卡牌收藏
iconTexture = "Interface\\ICONS\\INV_Misc_Book_07"
elseif tabID == 4 then -- 物品收藏
iconTexture = "Interface\\ICONS\\INV_Box_01"
end
SetPortraitToTexture(self.MainFrame.cornerIcon, iconTexture)
end
-- 显示指定标签页
function SM_Collections:ShowTab(tabID)
if not self.MainFrame or not self.MainFrame.ContentFrame then return end
-- 更新左上角图标
self:UpdateCornerIcon(tabID)
-- 先清空内容框架
for i, v in ipairs({ self.MainFrame.ContentFrame:GetChildren() }) do
v:Hide()
end
-- 清理右侧面板的属性加成显示
if self.MainFrame and self.MainFrame.RightSidePanel then
-- 隐藏属性加成框架
if self.MainFrame.RightSidePanel.AttributeBonusFrame then
-- 隐藏框架
self.MainFrame.RightSidePanel.AttributeBonusFrame:Hide()
-- 隐藏属性按钮(用于坐骑、小伙伴和卡牌)
local children = { self.MainFrame.RightSidePanel.AttributeBonusFrame:GetChildren() }
for _, child in ipairs(children) do
if child:GetName() and (string.find(child:GetName(), "SM_CollectionsAttributeutton") or
string.find(child:GetName(), "SM_ItemCollectionAttributeButton")) then
child:Hide()
end
end
end
-- 隐藏物品收藏属性按钮
if self.MainFrame.RightSidePanel.attributeButtons then
for _, button in ipairs(self.MainFrame.RightSidePanel.attributeButtons) do
button:Hide()
end
end
-- 隐藏物品收藏属性文本
if self.MainFrame.RightSidePanel.attributeTexts then
for _, text in ipairs(self.MainFrame.RightSidePanel.attributeTexts) do
text:Hide()
end
end
-- 更新或隐藏召唤按钮
if self.MainFrame.RightSidePanel.CallButon then
if tabID == 1 then
-- 坐骑收藏,显示召唤按钮并设置文本为"随机召唤坐骑"
self.MainFrame.RightSidePanel.CallButon:Show()
self.MainFrame.RightSidePanel.CallButon.String:SetText("随机召唤坐骑")
self.MainFrame.RightSidePanel.CallButon:SetNormalTexture(
"Interface\\ICONS\\Ability_Mount_RidingHorse.blp")
self.MainFrame.RightSidePanel.CallButon:SetHighlightTexture(
"Interface\\ICONS\\Ability_Mount_RidingHorse.blp")
self.MainFrame.RightSidePanel.CallButon:SetPushedTexture(
"Interface\\ICONS\\Ability_Mount_RidingHorse.blp")
elseif tabID == 2 then
-- 小伙伴收藏,显示召唤按钮并设置文本为"随机召唤小伙伴"
self.MainFrame.RightSidePanel.CallButon:Show()
self.MainFrame.RightSidePanel.CallButon.String:SetText("随机召唤小伙伴")
self.MainFrame.RightSidePanel.CallButon:SetNormalTexture(
"Interface\\ICONS\\Ability_Hunter_BeastCall.blp")
self.MainFrame.RightSidePanel.CallButon:SetHighlightTexture(
"Interface\\ICONS\\Ability_Hunter_BeastCall.blp")
self.MainFrame.RightSidePanel.CallButon:SetPushedTexture(
"Interface\\ICONS\\Ability_Hunter_BeastCall.blp")
elseif tabID == 3 then
-- 卡牌收藏,隐藏召唤按钮
self.MainFrame.RightSidePanel.CallButon:Hide()
elseif tabID == 4 then
-- 物品收藏,隐藏召唤按钮
self.MainFrame.RightSidePanel.CallButon:Hide()
end
end
end
-- 显示对应标签页的内容
if tabID == 1 then
self:ShowMounts()
elseif tabID == 2 then
self:ShowCompanions()
elseif tabID == 3 then
self:ShowCards()
elseif tabID == 4 then
self:ShowItems()
end
self.MainFrame.selectedTab = tabID
self.CurrentTab = tabID
end
-- 显示物品收藏界面
function SM_Collections:ShowItems()
-- 清理右侧面板中可能存在的旧属性加成文本
if self.MainFrame and self.MainFrame.RightSidePanel then
-- 清除旧的属性文本
if self.MainFrame.RightSidePanel.attributeTexts then
for _, text in ipairs(self.MainFrame.RightSidePanel.attributeTexts) do
text:Hide()
end
end
end
-- 加载ItemCollection模块
if not SM_ItemCollectionUI then
-- 确认模块已加载
if not SM_ItemCollectionUI then
return
end
end
-- 初始化模块 - 每次切换标签都确保初始化
if not SM_ItemCollectionUI.initialized then
SM_ItemCollectionUI:Init()
end
-- 调用物品收藏界面模块中的实现
local panel = SM_ItemCollectionUI:ShowItemCollectionUI(self.MainFrame.ContentFrame)
-- 确保主窗口的右侧面板可见
if self.MainFrame and self.MainFrame.RightSidePanel then
self.MainFrame.RightSidePanel:Show()
end
return panel
end
-- 下面补充内容切换的函数(示例)
function SM_Collections:ShowMounts()
--
-- 确保属性加成框架隐藏
if self.MainFrame and self.MainFrame.RightSidePanel then
if self.MainFrame.RightSidePanel.AttributeBonusFrame then
self.MainFrame.RightSidePanel.AttributeBonusFrame:Hide()
end
-- 清除属性文本
if self.MainFrame.RightSidePanel.attributeTexts then
for _, text in ipairs(self.MainFrame.RightSidePanel.attributeTexts) do
text:Hide()
end
end
end
SM_Collections.DataManager:GetMounts(function(mounts)
--
local panel = self:CreateSplitPanel(self.MainFrame.ContentFrame, mounts, "mount")
-- 不需要手动选择第一个项目CreateSplitPanel函数已经处理了自动选择
-- 只需确保面板显示即可
panel:Show()
self.CurrentPanel = panel
end)
end
function SM_Collections:ShowCompanions()
-- 确保属性加成框架隐藏
if self.MainFrame and self.MainFrame.RightSidePanel then
if self.MainFrame.RightSidePanel.AttributeBonusFrame then
self.MainFrame.RightSidePanel.AttributeBonusFrame:Hide()
end
-- 清除属性文本
if self.MainFrame.RightSidePanel.attributeTexts then
for _, text in ipairs(self.MainFrame.RightSidePanel.attributeTexts) do
text:Hide()
end
end
end
SM_Collections.DataManager:GetCompanions(function(companions)
local panel = self:CreateSplitPanel(self.MainFrame.ContentFrame, companions, "companion")
-- 不需要手动选择第一个项目CreateSplitPanel函数已经处理了自动选择
-- 只需确保面板显示即可
panel:Show()
self.CurrentPanel = panel
end)
end
function SM_Collections:ShowCards()
-- 确保属性加成框架隐藏
if self.MainFrame and self.MainFrame.RightSidePanel then
if self.MainFrame.RightSidePanel.AttributeBonusFrame then
self.MainFrame.RightSidePanel.AttributeBonusFrame:Hide()
end
-- 清除属性文本
if self.MainFrame.RightSidePanel.attributeTexts then
for _, text in ipairs(self.MainFrame.RightSidePanel.attributeTexts) do
text:Hide()
end
end
end
SM_Collections.DataManager:GetCards(function(cards)
local panel = self:CreateSplitPanel(self.MainFrame.ContentFrame, cards, "card")
-- 不需要手动选择第一个项目CreateSplitPanel函数已经处理了自动选择
-- 只需确保面板显示即可
panel:Show()
self.CurrentPanel = panel
end)
end