切换菜单随机选择以获取菜单 | 如无任何获取则选择第一个菜单项 更新卡牌状态[不完美],仍需切换才能显示已获得的高亮状态 移除多处冗余代码,增加main文件 添加菜单选中纹理,对已获得菜单排序
414 lines
14 KiB
Lua
414 lines
14 KiB
Lua
-- 显示卡牌
|
||
function SM_Collections:ShowCards()
|
||
print("显示卡牌面板")
|
||
|
||
-- 隐藏其他面板
|
||
if self.CurrentPanel then
|
||
self.CurrentPanel:Hide()
|
||
end
|
||
|
||
-- 设置当前标签页
|
||
self.MainFrame.tabID = 3
|
||
|
||
-- 更新菜单选中状态
|
||
self:UpdateMenuSelection(3)
|
||
|
||
-- 获取卡牌数据
|
||
self.DataManager:GetCards(function(data)
|
||
if not data or #data == 0 then
|
||
print("卡牌数据为空")
|
||
return
|
||
end
|
||
|
||
print("获取到卡牌数据,共", #data, "条")
|
||
|
||
-- 创建分栏面板
|
||
local panel = self:CreateSplitPanel(self.MainFrame.RightSidePanel, data, "card")
|
||
|
||
-- 确保右侧面板可见
|
||
if self.MainFrame.RightSidePanel then
|
||
self.MainFrame.RightSidePanel:Show()
|
||
end
|
||
|
||
-- 设置当前面板
|
||
self.CurrentPanel = panel
|
||
|
||
-- 检查是否有选中的按钮
|
||
local hasSelectedButton = false
|
||
if panel and panel.scrollChild and panel.scrollChild.buttons then
|
||
for _, button in ipairs(panel.scrollChild.buttons) do
|
||
if button.isSelected then
|
||
hasSelectedButton = true
|
||
print("找到选中的按钮,ID:", button.itemData.id)
|
||
break
|
||
end
|
||
end
|
||
|
||
-- 如果没有选中按钮,选择第一个
|
||
if not hasSelectedButton and #panel.scrollChild.buttons > 0 then
|
||
local firstButton = panel.scrollChild.buttons[1]
|
||
firstButton.isSelected = true
|
||
if firstButton.selectedTexture then
|
||
firstButton.selectedTexture:Show()
|
||
end
|
||
|
||
-- 手动触发点击事件
|
||
OnItemClick(firstButton, firstButton.itemData, "card", panel)
|
||
print("没有找到选中按钮,已选择第一个按钮")
|
||
end
|
||
end
|
||
end)
|
||
end
|
||
|
||
-- 更新菜单选中状态
|
||
function SM_Collections:UpdateMenuSelection(tabID)
|
||
print("更新菜单选中状态为:", tabID)
|
||
|
||
if not self.MainFrame or not self.MainFrame.MenuButtons then
|
||
print("主框架或菜单按钮不存在")
|
||
return
|
||
end
|
||
|
||
-- 遍历所有菜单按钮,更新选中状态
|
||
for i, button in ipairs(self.MainFrame.MenuButtons) do
|
||
if i == tabID then
|
||
-- 选中当前标签页
|
||
button:SetNormalTexture("Interface\\AddOns\\SM_CollectionSystem\\Textures\\liebiaoditu_kuang_B")
|
||
if button.Text then
|
||
button.Text:SetTextColor(1, 1, 0) -- 金黄色
|
||
end
|
||
print("设置按钮", i, "为选中状态")
|
||
else
|
||
-- 取消其他标签页的选中状态
|
||
button:SetNormalTexture("Interface\\AddOns\\SM_CollectionSystem\\Textures\\liebiaoditu_kuang_A")
|
||
if button.Text then
|
||
button.Text:SetTextColor(1, 1, 1) -- 白色
|
||
end
|
||
end
|
||
end
|
||
|
||
-- 更新当前标签页ID
|
||
self.MainFrame.tabID = tabID
|
||
end
|
||
|
||
-- 创建主窗体
|
||
function SM_Collections:CreateMainFrame()
|
||
local mainFrame = CreateFrame("Frame", "SM_CollectionsMainFrame", UIParent)
|
||
mainFrame:SetSize(600, 450)
|
||
mainFrame:SetPoint("CENTER", 0, 0)
|
||
mainFrame:SetFrameStrata("HIGH")
|
||
mainFrame:EnableMouse(true)
|
||
mainFrame:SetMovable(true)
|
||
mainFrame:RegisterForDrag("LeftButton")
|
||
mainFrame:SetScript("OnDragStart", mainFrame.StartMoving)
|
||
mainFrame:SetScript("OnDragStop", mainFrame.StopMovingOrSizing)
|
||
|
||
-- 设置背景
|
||
mainFrame:SetBackdrop({
|
||
bgFile = "Interface\\AddOns\\SM_CollectionSystem\\Textures\\MainFrameBackground",
|
||
edgeFile = "Interface\\AddOns\\SM_CollectionSystem\\Textures\\MainFrameBorder",
|
||
tile = false,
|
||
tileSize = 64,
|
||
edgeSize = 32,
|
||
insets = { left = 11, right = 12, top = 12, bottom = 11 }
|
||
})
|
||
|
||
-- 标题
|
||
local titleText = mainFrame:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
|
||
titleText:SetPoint("TOP", 0, -15)
|
||
titleText:SetText("收藏系统")
|
||
titleText:SetTextColor(1, 0.8, 0)
|
||
|
||
-- 关闭按钮
|
||
local closeButton = CreateFrame("Button", "SM_CollectionsCloseButton", mainFrame, "UIPanelCloseButton")
|
||
closeButton:SetPoint("TOPRIGHT", -5, -5)
|
||
closeButton:SetScript("OnClick", function()
|
||
mainFrame:Hide()
|
||
end)
|
||
|
||
-- 左侧菜单
|
||
local menuFrame = CreateFrame("Frame", "SM_CollectionsMenuFrame", mainFrame)
|
||
menuFrame:SetSize(150, 400)
|
||
menuFrame:SetPoint("TOPLEFT", 15, -40)
|
||
|
||
-- 菜单按钮
|
||
local menuButtons = {}
|
||
local menuItems = {"坐骑", "小伙伴", "卡牌", "物品"}
|
||
local buttonHeight = 40
|
||
local spacing = 5
|
||
|
||
for i, item in ipairs(menuItems) do
|
||
local button = CreateFrame("Button", "SM_CollectionsMenuButton" .. i, menuFrame)
|
||
button:SetSize(120, buttonHeight)
|
||
button:SetPoint("TOPLEFT", 0, -(i - 1) * (buttonHeight + spacing))
|
||
button:SetNormalTexture("Interface\\AddOns\\SM_CollectionSystem\\Textures\\liebiaoditu_kuang_A")
|
||
button:SetHighlightTexture("Interface\\AddOns\\SM_CollectionSystem\\Textures\\liebiaoditu_kuang_B")
|
||
|
||
-- 添加选中状态纹理
|
||
local selectedTexture = button:CreateTexture(nil, "OVERLAY")
|
||
selectedTexture:SetAllPoints(button)
|
||
selectedTexture:SetTexture("Interface\\AddOns\\SM_CollectionSystem\\Textures\\liebiaoditu_kuang_B")
|
||
selectedTexture:Hide()
|
||
button.selectedTexture = selectedTexture
|
||
|
||
-- 按钮文本
|
||
local text = button:CreateFontString(nil, "OVERLAY", "GameFontNormal")
|
||
text:SetPoint("CENTER", 0, 0)
|
||
text:SetText(item)
|
||
button.Text = text
|
||
|
||
-- 点击处理
|
||
button:SetScript("OnClick", function()
|
||
-- 更新菜单选中状态
|
||
self:UpdateMenuSelection(i)
|
||
|
||
-- 根据按钮显示不同的内容
|
||
if i == 1 then
|
||
self:ShowMounts()
|
||
elseif i == 2 then
|
||
self:ShowCompanions()
|
||
elseif i == 3 then
|
||
self:ShowCards()
|
||
elseif i == 4 then
|
||
self:ShowItems()
|
||
end
|
||
end)
|
||
|
||
table.insert(menuButtons, button)
|
||
end
|
||
|
||
-- 保存菜单按钮引用
|
||
mainFrame.MenuButtons = menuButtons
|
||
|
||
-- 右侧内容区域
|
||
local rightPanel = CreateFrame("Frame", "SM_CollectionsRightPanel", mainFrame)
|
||
rightPanel:SetSize(400, 400)
|
||
rightPanel:SetPoint("TOPRIGHT", -15, -40)
|
||
|
||
-- 坐骑名称
|
||
local mountName = rightPanel:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
|
||
mountName:SetPoint("TOP", rightPanel, "TOP", 0, -10)
|
||
mountName:SetSize(380, 30)
|
||
mountName:SetJustifyH("CENTER")
|
||
mountName:SetTextColor(1, 1, 1)
|
||
rightPanel.MountNama = mountName
|
||
|
||
-- 描述文本
|
||
local introText = rightPanel:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
|
||
introText:SetPoint("TOP", mountName, "BOTTOM", 0, -10)
|
||
introText:SetSize(380, 0)
|
||
introText:SetJustifyH("CENTER")
|
||
rightPanel.introText = introText
|
||
|
||
-- 属性加成框架
|
||
local attributeBonusFrame = CreateFrame("Frame", "SM_CollectionsAttributeBonusFrame", rightPanel)
|
||
attributeBonusFrame:SetSize(150, 200)
|
||
attributeBonusFrame:SetPoint("BOTTOMRIGHT", rightPanel, "BOTTOMRIGHT", 0, 0)
|
||
|
||
-- 属性加成标题
|
||
local bonusTitle = attributeBonusFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
|
||
bonusTitle:SetPoint("TOP", attributeBonusFrame, "TOP", 0, 0)
|
||
bonusTitle:SetText("属性加成")
|
||
bonusTitle:SetTextColor(1, 0.8, 0)
|
||
|
||
rightPanel.AttributeBonusFrame = attributeBonusFrame
|
||
mainFrame.RightSidePanel = rightPanel
|
||
|
||
-- 初始化属性文本数组
|
||
rightPanel.attributeTexts = {}
|
||
|
||
-- 保存主窗体引用
|
||
self.MainFrame = mainFrame
|
||
|
||
-- 默认显示坐骑标签页
|
||
mainFrame.tabID = 1
|
||
self:UpdateMenuSelection(1)
|
||
|
||
return mainFrame
|
||
end
|
||
|
||
-- 显示坐骑
|
||
function SM_Collections:ShowMounts()
|
||
print("显示坐骑面板")
|
||
|
||
-- 隐藏其他面板
|
||
if self.CurrentPanel then
|
||
self.CurrentPanel:Hide()
|
||
end
|
||
|
||
-- 设置当前标签页
|
||
self.MainFrame.tabID = 1
|
||
|
||
-- 更新菜单选中状态
|
||
self:UpdateMenuSelection(1)
|
||
|
||
-- 获取坐骑数据
|
||
self.DataManager:GetMounts(function(data)
|
||
if not data or #data == 0 then
|
||
print("坐骑数据为空")
|
||
return
|
||
end
|
||
|
||
print("获取到坐骑数据,共", #data, "条")
|
||
|
||
-- 创建分栏面板
|
||
local panel = self:CreateSplitPanel(self.MainFrame.RightSidePanel, data, "mount")
|
||
|
||
-- 确保右侧面板可见
|
||
if self.MainFrame.RightSidePanel then
|
||
self.MainFrame.RightSidePanel:Show()
|
||
end
|
||
|
||
-- 设置当前面板
|
||
self.CurrentPanel = panel
|
||
|
||
-- 检查是否有选中的按钮
|
||
local hasSelectedButton = false
|
||
if panel and panel.scrollChild and panel.scrollChild.buttons then
|
||
for _, button in ipairs(panel.scrollChild.buttons) do
|
||
if button.isSelected then
|
||
hasSelectedButton = true
|
||
print("找到选中的按钮,ID:", button.itemData.id)
|
||
break
|
||
end
|
||
end
|
||
|
||
-- 如果没有选中按钮,选择第一个
|
||
if not hasSelectedButton and #panel.scrollChild.buttons > 0 then
|
||
local firstButton = panel.scrollChild.buttons[1]
|
||
firstButton.isSelected = true
|
||
if firstButton.selectedTexture then
|
||
firstButton.selectedTexture:Show()
|
||
end
|
||
|
||
-- 手动触发点击事件
|
||
OnItemClick(firstButton, firstButton.itemData, "mount", panel)
|
||
print("没有找到选中按钮,已选择第一个按钮")
|
||
end
|
||
end
|
||
end)
|
||
end
|
||
|
||
-- 显示小伙伴
|
||
function SM_Collections:ShowCompanions()
|
||
print("显示小伙伴面板")
|
||
|
||
-- 隐藏其他面板
|
||
if self.CurrentPanel then
|
||
self.CurrentPanel:Hide()
|
||
end
|
||
|
||
-- 设置当前标签页
|
||
self.MainFrame.tabID = 2
|
||
|
||
-- 更新菜单选中状态
|
||
self:UpdateMenuSelection(2)
|
||
|
||
-- 获取小伙伴数据
|
||
self.DataManager:GetCompanions(function(data)
|
||
if not data or #data == 0 then
|
||
print("小伙伴数据为空")
|
||
return
|
||
end
|
||
|
||
print("获取到小伙伴数据,共", #data, "条")
|
||
|
||
-- 创建分栏面板
|
||
local panel = self:CreateSplitPanel(self.MainFrame.RightSidePanel, data, "companion")
|
||
|
||
-- 确保右侧面板可见
|
||
if self.MainFrame.RightSidePanel then
|
||
self.MainFrame.RightSidePanel:Show()
|
||
end
|
||
|
||
-- 设置当前面板
|
||
self.CurrentPanel = panel
|
||
|
||
-- 检查是否有选中的按钮
|
||
local hasSelectedButton = false
|
||
if panel and panel.scrollChild and panel.scrollChild.buttons then
|
||
for _, button in ipairs(panel.scrollChild.buttons) do
|
||
if button.isSelected then
|
||
hasSelectedButton = true
|
||
print("找到选中的按钮,ID:", button.itemData.id)
|
||
break
|
||
end
|
||
end
|
||
|
||
-- 如果没有选中按钮,选择第一个
|
||
if not hasSelectedButton and #panel.scrollChild.buttons > 0 then
|
||
local firstButton = panel.scrollChild.buttons[1]
|
||
firstButton.isSelected = true
|
||
if firstButton.selectedTexture then
|
||
firstButton.selectedTexture:Show()
|
||
end
|
||
|
||
-- 手动触发点击事件
|
||
OnItemClick(firstButton, firstButton.itemData, "companion", panel)
|
||
print("没有找到选中按钮,已选择第一个按钮")
|
||
end
|
||
end
|
||
end)
|
||
end
|
||
|
||
-- 显示物品
|
||
function SM_Collections:ShowItems()
|
||
print("显示物品面板")
|
||
|
||
-- 隐藏其他面板
|
||
if self.CurrentPanel then
|
||
self.CurrentPanel:Hide()
|
||
end
|
||
|
||
-- 设置当前标签页
|
||
self.MainFrame.tabID = 4
|
||
|
||
-- 更新菜单选中状态
|
||
self:UpdateMenuSelection(4)
|
||
|
||
-- 获取物品数据
|
||
self.DataManager:GetItems(function(data)
|
||
if not data or #data == 0 then
|
||
print("物品数据为空")
|
||
return
|
||
end
|
||
|
||
print("获取到物品数据,共", #data, "条")
|
||
|
||
-- 创建分栏面板
|
||
local panel = self:CreateSplitPanel(self.MainFrame.RightSidePanel, data, "item")
|
||
|
||
-- 确保右侧面板可见
|
||
if self.MainFrame.RightSidePanel then
|
||
self.MainFrame.RightSidePanel:Show()
|
||
end
|
||
|
||
-- 设置当前面板
|
||
self.CurrentPanel = panel
|
||
|
||
-- 检查是否有选中的按钮
|
||
local hasSelectedButton = false
|
||
if panel and panel.scrollChild and panel.scrollChild.buttons then
|
||
for _, button in ipairs(panel.scrollChild.buttons) do
|
||
if button.isSelected then
|
||
hasSelectedButton = true
|
||
print("找到选中的按钮,ID:", button.itemData.id)
|
||
break
|
||
end
|
||
end
|
||
|
||
-- 如果没有选中按钮,选择第一个
|
||
if not hasSelectedButton and #panel.scrollChild.buttons > 0 then
|
||
local firstButton = panel.scrollChild.buttons[1]
|
||
firstButton.isSelected = true
|
||
if firstButton.selectedTexture then
|
||
firstButton.selectedTexture:Show()
|
||
end
|
||
|
||
-- 手动触发点击事件
|
||
OnItemClick(firstButton, firstButton.itemData, "item", panel)
|
||
print("没有找到选中按钮,已选择第一个按钮")
|
||
end
|
||
end
|
||
end)
|
||
end |