857 lines
34 KiB
Lua
857 lines
34 KiB
Lua
-- SM_CollectionSystem.lua
|
||
print("收藏系统开始")
|
||
SM_Collections = {}
|
||
SM_Collections.MainFrame = nil
|
||
SM_Collections.CurrentPanel = nil
|
||
SM_Collections.CurrentTab = 1
|
||
|
||
-- 创建自定义字体对象
|
||
local titleFont = CreateFont("SM_TitleFont")
|
||
titleFont:SetFont("Fonts\\ZYKai_T.ttf", 20, "MONOCHROME")
|
||
|
||
local descFont = CreateFont("SM_DescFont")
|
||
descFont:SetFont("Fonts\\ZYKai_T.ttf", 10, "MONOCHROME")
|
||
|
||
-- 添加坐骑数据
|
||
SM_Collections.Mounts = {
|
||
[458] = { 284, 2, 0, "Brown Horse", "A favorite among Stormwind's guards thanks to its patience and stamina.", 2, "|cFFFFD200Vendor: |rWorld Vendors|n|cFFFFD200Cost: |r1|TINTERFACE\\MONEYFRAME\\UI-GOLDICON.BLP:0|t" },
|
||
[459] = { 4268, 2, 64, "Gray Wolf", "This breed of wolf prefers hunting in the fog, relying on its smoky hide to camouflage it from unsuspecting prey.", 2, "|cFFFFD200Vendor: |rOgunaro Wolfrunner|n|cFFFFD200Zone: |rOrgrimmar|n|cFFFFD200Cost: |r1|TINTERFACE\\MONEYFRAME\\UI-GOLDICON.BLP:0|t" },
|
||
[468] = { 305, 2, 64, "White Stallion", "The powerful and unyielding white stallion features heavily in the myths of ancient human tribes.", 2, "|cFFFFD200Legacy|r" },
|
||
[470] = { 308, 2, 0, "Black Stallion", "Rumored to be favored by SI:7 for night missions due to its dark coat.", 2, "|cFFFFD200Vendor: |rUnger Statforth|n|cFFFFD200Zone: |rWetlands|n|cFFFFD200Cost: |r1|TINTERFACE\\MONEYFRAME\\UI-GOLDICON.BLP:0|t" },
|
||
[578] = { 356, 2, 64, "Black Wolf", "Can howl loudly enough to be heard for miles.", 2, "|cFFFFD200Vendor: |rOgunaro Wolfrunner|n|cFFFFD200Zone: |rOrgrimmar|n|cFFFFD200Cost: |r1|TINTERFACE\\MONEYFRAME\\UI-GOLDICON.BLP:0|t" },
|
||
}
|
||
|
||
-- 获取坐骑信息
|
||
function SM_Collections:GetMountInfo(spellID)
|
||
local info = self.Mounts[spellID]
|
||
if info then
|
||
return unpack(info, 1, 9)
|
||
end
|
||
end
|
||
|
||
-- 获取生物显示ID
|
||
function SM_Collections:GetCreatureDisplayID(itemID, itemType)
|
||
if itemType == "mount" then
|
||
local mountInfo = self:GetMountInfo(itemID)
|
||
if mountInfo then
|
||
return mountInfo -- 第一个返回值就是 creatureDisplayID
|
||
end
|
||
elseif itemType == "companion" then
|
||
local companionMap = {
|
||
[5918] = 5918, -- 猫头鹰
|
||
[2727] = 2727, -- 峭壁山狗
|
||
[721] = 721, -- 兔子
|
||
[105] = 105, -- 鸟
|
||
}
|
||
return companionMap[itemID] or itemID
|
||
elseif itemType == "card" then
|
||
local cardMap = {
|
||
[11502] = 11502, -- 拉格纳罗斯
|
||
[24248] = 24248, -- 巫妖王
|
||
[19299] = 19299, -- 死亡耳语者
|
||
[32588] = 32588, -- 伊利丹
|
||
}
|
||
return cardMap[itemID] or itemID
|
||
end
|
||
|
||
return itemID
|
||
end
|
||
|
||
-- 测试数据
|
||
SM_Collections.Data = {
|
||
Mounts = {
|
||
{ id = 458, name = "棕色马", description = "暴风城卫兵的最爱", obtained = true },
|
||
{ id = 459, name = "灰狼", description = "喜欢在雾中狩猎的狼", obtained = true },
|
||
{ id = 468, name = "白色骏马", description = "强大不屈的白色骏马", obtained = false },
|
||
{ id = 470, name = "黑色骏马", description = "据说SI:7夜间任务的首选", obtained = true },
|
||
{ id = 578, name = "黑狼", description = "嚎叫声能传播数英里", obtained = false },
|
||
{ id = 468, name = "白色骏马", description = "强大不屈的白色骏马", obtained = false },
|
||
{ id = 470, name = "黑色骏马", description = "据说SI:7夜间任务的首选", obtained = true },
|
||
{ id = 578, name = "黑狼", description = "嚎叫声能传播数英里", obtained = false },
|
||
{ id = 458, name = "棕色马", description = "暴风城卫兵的最爱", obtained = true },
|
||
{ id = 458, name = "棕色马", description = "暴风城卫兵的最爱", obtained = true },
|
||
{ id = 459, name = "灰狼", description = "喜欢在雾中狩猎的狼", obtained = true },
|
||
{ id = 468, name = "白色骏马", description = "强大不屈的白色骏马", obtained = false },
|
||
{ id = 470, name = "黑色骏马", description = "据说SI:7夜间任务的首选", obtained = true },
|
||
{ id = 578, name = "黑狼", description = "嚎叫声能传播数英里", obtained = false },
|
||
{ id = 468, name = "白色骏马", description = "强大不屈的白色骏马", obtained = false },
|
||
{ id = 470, name = "黑色骏马", description = "据说SI:7夜间任务的首选", obtained = true },
|
||
{ id = 578, name = "黑狼", description = "嚎叫声能传播数英里", obtained = false },
|
||
{ id = 458, name = "棕色马", description = "暴风城卫兵的最爱", obtained = true },
|
||
},
|
||
|
||
Companions = {
|
||
{ id = 5918, name = "猫头鹰", description = "一只可爱的小猫", obtained = true },
|
||
{ id = 2727, name = "峭壁山狗", description = "一只忠诚的小狗", obtained = false },
|
||
{ id = 721, name = "兔子", description = "一只活泼的兔子", obtained = true },
|
||
{ id = 105, name = "陆行鸟", description = "一只会唱歌的鸟", obtained = false },
|
||
},
|
||
|
||
Cards = {
|
||
{ id = 11502, name = "拉格纳罗斯", description = "火焰之王", obtained = true },
|
||
{ id = 24248, name = "巫妖王阿尔萨斯", description = "亡灵天灾的领袖", obtained = false },
|
||
{ id = 19299, name = "死亡耳语者", description = "毁灭者", obtained = true },
|
||
{ id = 32588, name = "伊利丹·怒风", description = "背叛者", obtained = false },
|
||
},
|
||
|
||
Items = {
|
||
{ id = 33138, name = "秘法刀石", icon = "Interface\\Icons\\INV_Sword_04", obtained = true },
|
||
{ id = 33129, name = "菲纳特的爆竹", icon = "Interface\\Icons\\INV_Shield_05", obtained = false },
|
||
{ id = 33132, name = "精致焰红石", icon = "Interface\\Icons\\INV_Helmet_01", obtained = true },
|
||
{ id = 33133, name = "胡里奥之心", icon = "Interface\\Icons\\INV_Chest_Plate01", obtained = false },
|
||
{ id = 33138, name = "秘法刀石", icon = "Interface\\Icons\\INV_Sword_04", obtained = true },
|
||
{ id = 33129, name = "菲纳特的爆竹", icon = "Interface\\Icons\\INV_Shield_05", obtained = false },
|
||
{ id = 33132, name = "精致焰红石", icon = "Interface\\Icons\\INV_Helmet_01", obtained = true },
|
||
{ id = 33133, name = "胡里奥之心", icon = "Interface\\Icons\\INV_Chest_Plate01", obtained = false },
|
||
{ id = 33138, name = "秘法刀石", icon = "Interface\\Icons\\INV_Sword_04", obtained = true },
|
||
{ id = 33129, name = "菲纳特的爆竹", icon = "Interface\\Icons\\INV_Shield_05", obtained = false },
|
||
{ id = 33132, name = "精致焰红石", icon = "Interface\\Icons\\INV_Helmet_01", obtained = true },
|
||
{ id = 33133, name = "胡里奥之心", icon = "Interface\\Icons\\INV_Chest_Plate01", obtained = false },
|
||
{ id = 33138, name = "秘法刀石", icon = "Interface\\Icons\\INV_Sword_04", obtained = true },
|
||
{ id = 33129, name = "菲纳特的爆竹", icon = "Interface\\Icons\\INV_Shield_05", obtained = false },
|
||
{ id = 33132, name = "精致焰红石", icon = "Interface\\Icons\\INV_Helmet_01", obtained = true },
|
||
{ id = 33133, name = "胡里奥之心", icon = "Interface\\Icons\\INV_Chest_Plate01", obtained = false },
|
||
{ id = 33138, name = "秘法刀石", icon = "Interface\\Icons\\INV_Sword_04", obtained = true },
|
||
{ id = 33129, name = "菲纳特的爆竹", icon = "Interface\\Icons\\INV_Shield_05", obtained = false },
|
||
{ id = 33132, name = "精致焰红石", icon = "Interface\\Icons\\INV_Helmet_01", obtained = true },
|
||
{ id = 33133, name = "胡里奥之心", icon = "Interface\\Icons\\INV_Chest_Plate01", obtained = false },
|
||
|
||
},
|
||
Attribute = {
|
||
{ Name = "生命值", value = 999 },
|
||
{ Name = "近战攻强", value = 999 },
|
||
{ Name = "法术强度", value = 999 },
|
||
{ Name = "暴击等级", value = 999 },
|
||
{ Name = "造成奥术伤害", value = 999 },
|
||
{ Name = "造成火焰伤害", value = 999 },
|
||
{ Name = "受到所有伤害", value = 999 },
|
||
{ Name = "造成暴击伤害", value = 999 },
|
||
{ Name = "造成所有伤害", value = 999 },
|
||
{ Name = "治疗效果", value = 999 },
|
||
}
|
||
}
|
||
|
||
-- 创建主界面
|
||
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\\INV_Misc_QuestionMark") -- 圆形肖像-默认问号图标 可以自行替换
|
||
|
||
-- 标题
|
||
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 MountNama = SM_Collections_Frame:CreateFontString(nil, "OVERLAY")
|
||
MountNama:SetPoint("TOPRIGHT", -80, -100)
|
||
MountNama:SetFontObject(titleFont) -- 使用 SetFontObject 而不是 SetFont
|
||
MountNama:SetText("墨洛墨洛根怪兽")
|
||
MountNama:SetJustifyH("LEFT")
|
||
MountNama:SetJustifyV("TOP")
|
||
MountNama:SetTextColor(230 / 255, 150 / 255, 0 / 255)
|
||
|
||
-- 右上角介绍文本的框体
|
||
local introFrame = CreateFrame("Frame", nil, SM_Collections_Frame)
|
||
local width = MountNama:GetStringWidth()
|
||
introFrame:SetSize(width + 80, 80) -- 增加高度
|
||
introFrame:SetPoint("TOPLEFT", MountNama, "BOTTOMLEFT", 0, -10)
|
||
|
||
-- 介绍文本 - 使用自定义字体
|
||
local introText = introFrame:CreateFontString(nil, "OVERLAY")
|
||
introText:SetPoint("TOPLEFT", 0, -5)
|
||
introText:SetJustifyH("LEFT")
|
||
introText:SetJustifyV("TOP")
|
||
introText:SetWidth(introFrame:GetWidth() - 20)
|
||
introText:SetWordWrap(true)
|
||
introText:SetFontObject(descFont) -- 使用 SetFontObject
|
||
local text =
|
||
"|cFFe59700成就:|r领导骑兵|r\r|cFFe59700类别:|r将军即使是龙族原住民协会的测试也证明,在确定白化公鸭是否与已知的蜻蜓有关方面没有定论。\r\r |cFFe59700--布雷安尼|r"
|
||
introText:SetText(text)
|
||
introFrame:SetHeight(introText:GetStringHeight() + 20)
|
||
introText:SetJustifyH("LEFT")
|
||
introText:SetJustifyV("TOP")
|
||
introText:SetWidth(introFrame:GetWidth() - 20)
|
||
introText:SetWordWrap(true)
|
||
|
||
-- 属性加成标题
|
||
local AttributeBonusFrame = CreateFrame("Frame", "AttributeBonusFrame", introFrame)
|
||
AttributeBonusFrame:SetSize(120, 20) -- 增加高度
|
||
AttributeBonusFrame:SetPoint("CENTER", introFrame, "CENTER", -12, -60)
|
||
AttributeBonusFrame:SetBackdrop({ bgFile = "Interface\\AddOns\\SM_CollectionSystem\\Textures\\AttributeBonusFrame" })
|
||
AttributeBonusFrameText = AttributeBonusFrame:CreateFontString(nil, "OVERLAY")
|
||
AttributeBonusFrameText:SetPoint("CENTER", 0, 0)
|
||
AttributeBonusFrameText:SetFontObject(titleFont) -- 使用 SetFontObject 而不是 SetFont
|
||
AttributeBonusFrameText:SetText("属性加成")
|
||
AttributeBonusFrameText:SetFont("Fonts\\ZYKai_T.ttf", 16, "MONOCHROME")
|
||
|
||
self:CreateAttribute(AttributeBonusFrame)
|
||
|
||
-- 自动换行
|
||
introText:SetWordWrap(true)
|
||
introText:SetWidth(introFrame:GetWidth() - 20) -- 保证和边距一致
|
||
|
||
-- 拖拽功能
|
||
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
|
||
return SM_Collections_Frame
|
||
end
|
||
|
||
function SM_Collections:CreateAttribute(parent)
|
||
local buttonH = 150
|
||
local buttonW = 20
|
||
local spacing = 2
|
||
local AttributeName = nil
|
||
local AttributeValue = 0
|
||
|
||
for i, companion in ipairs(self.Data.Attribute) do
|
||
AttributeName = companion.Name
|
||
AttributeValue = companion.value
|
||
local button = CreateFrame("Button", "SM_CollectionsAttributeutton" .. i, parent)
|
||
button:SetSize(buttonH, buttonW)
|
||
button:SetNormalTexture("Interface\\AddOns\\SM_CollectionSystem\\Textures\\AttributeuttonTexture")
|
||
|
||
-- 垂直排列:只需要按索引计算Y坐标
|
||
button:SetPoint("TOPLEFT", -15, -30 - (i - 1) * (buttonW + spacing))
|
||
|
||
-- 创建左侧文本框 - 属性名称
|
||
local nameText = button:CreateFontString(nil, "OVERLAY")
|
||
nameText:SetPoint("LEFT", 5, 0) -- 左侧对齐,5像素边距
|
||
nameText:SetFontObject(titleFont)
|
||
nameText:SetFont("Fonts\\ZYKai_T.ttf", 10, "MONOCHROME")
|
||
nameText:SetText(AttributeName)
|
||
nameText:SetJustifyH("LEFT")
|
||
nameText:SetJustifyV("CENTER")
|
||
nameText:SetTextColor(1, 1, 1) -- 白色
|
||
|
||
-- 创建右侧文本框 - 属性值
|
||
local valueText = button:CreateFontString(nil, "OVERLAY")
|
||
valueText:SetPoint("RIGHT", -5, 0) -- 右侧对齐,-5像素边距
|
||
valueText:SetFontObject(titleFont)
|
||
valueText:SetFont("Fonts\\ZYKai_T.ttf", 10, "MONOCHROME")
|
||
valueText:SetText(tostring(AttributeValue))
|
||
valueText:SetJustifyH("RIGHT")
|
||
valueText:SetJustifyV("CENTER")
|
||
valueText:SetTextColor(0, 1, 0) -- 绿色,用于区分数值
|
||
|
||
button:Show()
|
||
end
|
||
end
|
||
|
||
-- 创建标签页
|
||
function SM_Collections:CreateTabs(parent)
|
||
local tabs = {}
|
||
local tabNames = { "坐骑收藏", "小伙伴收藏", "卡牌收藏", "物品收藏" }
|
||
|
||
for i = 1, 4 do
|
||
local tab = CreateFrame("Button", "SM_CollectionTab" .. i, parent, "CharacterFrameTabButtonTemplate")
|
||
tab:SetSize(120, 30)
|
||
tab:SetID(i)
|
||
|
||
if i == 1 then
|
||
tab:SetPoint("TOPLEFT", parent, "BOTTOMLEFT", 20, 5)
|
||
else
|
||
tab:SetPoint("LEFT", tabs[i - 1], "RIGHT", 5, 0)
|
||
end
|
||
|
||
tab:SetText(tabNames[i])
|
||
|
||
tab:SetScript("OnClick", function(self)
|
||
SM_Collections:UpdateTabAppearance(self:GetID())
|
||
SM_Collections:ShowTab(self:GetID())
|
||
PlaySound("igCharacterInfoTab")
|
||
end)
|
||
|
||
tabs[i] = tab
|
||
end
|
||
|
||
parent.tabs = tabs
|
||
parent.numTabs = 4
|
||
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
|
||
-- 简单的透明度区分,避免纹理问题
|
||
if i == selectedTab then
|
||
tab:SetAlpha(1.0)
|
||
-- 可选:设置文本颜色
|
||
if tab.GetFontString and tab:GetFontString() then
|
||
tab:GetFontString():SetTextColor(1, 1, 1)
|
||
end
|
||
else
|
||
tab:SetAlpha(0.7)
|
||
if tab.GetFontString and tab:GetFontString() then
|
||
tab:GetFontString():SetTextColor(0.7, 0.7, 0.7)
|
||
end
|
||
end
|
||
end
|
||
end
|
||
|
||
self.MainFrame.selectedTab = selectedTab
|
||
self.CurrentTab = selectedTab
|
||
end
|
||
|
||
-- 显示小伙伴页面
|
||
function SM_Collections:ShowCompanions()
|
||
local panel = self:CreateSplitPanel(self.MainFrame.ContentFrame, self.Data.Companions, "companion")
|
||
|
||
local firstObtained = nil
|
||
for _, companion in ipairs(self.Data.Companions) do
|
||
if companion.obtained then
|
||
firstObtained = companion
|
||
break
|
||
end
|
||
end
|
||
|
||
if firstObtained then
|
||
panel.nameText:SetText(firstObtained.name)
|
||
panel.descText:SetText(firstObtained.description)
|
||
|
||
-- 使用独立的显示ID获取
|
||
local creatureDisplayID = self:GetCreatureDisplayID(firstObtained.id, "companion")
|
||
if creatureDisplayID and creatureDisplayID > 0 then
|
||
panel.model:Hide()
|
||
panel.model:SetPosition(0, 0, 0)
|
||
panel.model.zoomLevel = 0
|
||
panel.model:Show()
|
||
panel.model:SetCreature(creatureDisplayID)
|
||
end
|
||
end
|
||
|
||
panel:Show()
|
||
self.CurrentPanel = panel
|
||
end
|
||
|
||
-- 显示卡牌页面
|
||
function SM_Collections:ShowCards()
|
||
local panel = self:CreateSplitPanel(self.MainFrame.ContentFrame, self.Data.Cards, "card")
|
||
|
||
local firstObtained = nil
|
||
for _, card in ipairs(self.Data.Cards) do
|
||
if card.obtained then
|
||
firstObtained = card
|
||
break
|
||
end
|
||
end
|
||
|
||
if firstObtained then
|
||
panel.nameText:SetText(firstObtained.name)
|
||
panel.descText:SetText(firstObtained.description)
|
||
|
||
-- 使用 GetCreatureDisplayID 函数而不是直接访问 creatureDisplayID
|
||
local creatureDisplayID = self:GetCreatureDisplayID(firstObtained.id, "card")
|
||
if creatureDisplayID and creatureDisplayID > 0 then
|
||
panel.model:Hide()
|
||
panel.model:SetPosition(0, 0, 0)
|
||
panel.model.zoomLevel = 0
|
||
panel.model:Show()
|
||
panel.model:SetCreature(creatureDisplayID)
|
||
print("firstObtained.id = ", firstObtained.id)
|
||
print("creatureDisplayID = ", creatureDisplayID)
|
||
end
|
||
end
|
||
|
||
panel:Show()
|
||
self.CurrentPanel = panel
|
||
end
|
||
|
||
-- 显示指定标签页
|
||
function SM_Collections:ShowTab(tabId)
|
||
self:UpdateTabAppearance(tabId)
|
||
|
||
-- 更彻底地清空当前内容
|
||
if self.CurrentPanel then
|
||
self.CurrentPanel:Hide()
|
||
-- 清理所有子框架
|
||
local children = { self.CurrentPanel:GetChildren() }
|
||
for _, child in ipairs(children) do
|
||
child:Hide()
|
||
end
|
||
self.CurrentPanel = nil
|
||
end
|
||
|
||
-- 清理内容框架中的所有子元素
|
||
if self.MainFrame and self.MainFrame.ContentFrame then
|
||
local children = { self.MainFrame.ContentFrame:GetChildren() }
|
||
for _, child in ipairs(children) do
|
||
child:Hide()
|
||
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
|
||
end
|
||
|
||
-- 创建左右分栏面板
|
||
function SM_Collections:CreateSplitPanel(parent, data, itemType)
|
||
local panel = CreateFrame("Frame", "SM_CollectionsPanel", parent)
|
||
panel:SetAllPoints()
|
||
|
||
-- 左侧列表
|
||
local listFrame = CreateFrame("Frame", "SM_CollectionslistFrame", panel)
|
||
listFrame:SetSize(220, 410)
|
||
listFrame:SetPoint("TOPLEFT", 5, -13)
|
||
listFrame:SetBackdrop({
|
||
bgFile = "Interface\\AddOns\\SM_CollectionSystem\\Textures\\liebiaoditu"
|
||
})
|
||
|
||
local scrollFrameName = "SM_ScrollFrame_" .. itemType .. "_" .. math.random(1000, 9999)
|
||
local scrollFrame = CreateFrame("ScrollFrame", scrollFrameName, listFrame, "UIPanelScrollFrameTemplate")
|
||
scrollFrame:SetSize(200, 415)
|
||
scrollFrame:SetPoint("TOPLEFT", 5, 2)
|
||
|
||
-- 黑色底纹
|
||
local BackgroundFrame = CreateFrame("Frame", "SM_CollectionsOverlayFrame", scrollFrame)
|
||
BackgroundFrame:SetSize(25, 410)
|
||
BackgroundFrame:SetPoint("RIGHT", scrollFrame, "RIGHT", 25.5, 1)
|
||
BackgroundFrame:SetFrameLevel(scrollFrame:GetFrameLevel() + 1)
|
||
local ScrollBarBackground = BackgroundFrame:CreateTexture(nil, "BACKGROUND")
|
||
ScrollBarBackground:SetSize(25, 410)
|
||
ScrollBarBackground:SetPoint("CENTER", BackgroundFrame, "CENTER", 0, 0)
|
||
ScrollBarBackground:SetTexture("Interface\\AddOns\\SM_CollectionSystem\\Textures\\cooldown")
|
||
|
||
-- 覆盖纹理
|
||
local overlayFrame = CreateFrame("Frame", "SM_CollectionsOverlayFrame", BackgroundFrame)
|
||
overlayFrame:SetSize(30, 420)
|
||
overlayFrame:SetPoint("CENTER", BackgroundFrame, "CENTER", 0, 1)
|
||
overlayFrame:SetFrameLevel(BackgroundFrame:GetFrameLevel() + 10)
|
||
local scrollBarOverlay = overlayFrame:CreateTexture(nil, "OVERLAY")
|
||
scrollBarOverlay:SetAllPoints(overlayFrame)
|
||
scrollBarOverlay:SetTexture("Interface\\AddOns\\SM_CollectionSystem\\Textures\\ScrollFrame")
|
||
scrollBarOverlay:SetTexCoord(0, 1, 0, 1)
|
||
scrollBarOverlay:SetVertexColor(1, 1, 1, 1)
|
||
scrollBarOverlay:SetBlendMode("BLEND")
|
||
|
||
local scrollChild = CreateFrame("Frame", "SM_CollectionsScrollChild", scrollFrame)
|
||
scrollChild:SetSize(300, 1)
|
||
scrollFrame:SetScrollChild(scrollChild)
|
||
|
||
-- 右侧模型显示
|
||
local modelFrame = CreateFrame("Frame", "SM_CollectionsModelFrame", self.MainFrame)
|
||
modelFrame:SetSize(380, 410)
|
||
modelFrame:SetPoint("CENTER", 30, 0)
|
||
|
||
-- 3D模型 - 添加完整的初始化
|
||
local model = CreateFrame("PlayerModel", "SM_CollectionsModel", modelFrame)
|
||
model:SetSize(350, 350)
|
||
model:SetPoint("TOP", 0, -30)
|
||
|
||
-- 关键的模型初始化设置
|
||
model:SetCamera(0)
|
||
model:SetFacing(0)
|
||
model.zoomLevel = 0
|
||
model:SetPosition(0, 0, 0)
|
||
|
||
-- 鼠标拖拽旋转
|
||
model:EnableMouse(true)
|
||
model:SetScript("OnMouseDown", function(self, button)
|
||
if button == "LeftButton" then
|
||
self.isRotating = true
|
||
self.lastX = GetCursorPosition()
|
||
end
|
||
end)
|
||
model:SetScript("OnMouseUp", function(self, button)
|
||
if button == "LeftButton" then
|
||
self.isRotating = false
|
||
end
|
||
end)
|
||
|
||
-- 旋转速度(每秒弧度)
|
||
local ROTATE_SPEED = math.rad(90) -- 每秒90度
|
||
|
||
-- 按钮旋转状态
|
||
model.isRotatingLeft = false
|
||
model.isRotatingRight = false
|
||
|
||
-- 左旋转按钮
|
||
local rotateLeftBtn = CreateFrame("Button", nil, modelFrame)
|
||
rotateLeftBtn:SetSize(32, 32)
|
||
rotateLeftBtn:SetPoint("BOTTOM", modelFrame, "BOTTOM", -100, 10)
|
||
|
||
rotateLeftBtn:SetNormalTexture("Interface\\Buttons\\UI-RotationLeft-Button-Up")
|
||
rotateLeftBtn:SetPushedTexture("Interface\\Buttons\\UI-RotationLeft-Button-Down")
|
||
rotateLeftBtn:SetHighlightTexture("Interface\\Buttons\\UI-RotationLeft-Button-Highlight")
|
||
|
||
rotateLeftBtn:SetScript("OnMouseDown", function()
|
||
model.isRotatingLeft = true
|
||
end)
|
||
rotateLeftBtn:SetScript("OnMouseUp", function()
|
||
model.isRotatingLeft = false
|
||
end)
|
||
rotateLeftBtn:HookScript("OnLeave", function()
|
||
model.isRotatingLeft = false
|
||
end)
|
||
|
||
-- 右旋转按钮
|
||
local rotateRightBtn = CreateFrame("Button", nil, modelFrame)
|
||
rotateRightBtn:SetSize(32, 32)
|
||
rotateRightBtn:SetPoint("BOTTOM", modelFrame, "BOTTOM", 100, 10)
|
||
|
||
rotateRightBtn:SetNormalTexture("Interface\\Buttons\\UI-RotationRight-Button-Up")
|
||
rotateRightBtn:SetPushedTexture("Interface\\Buttons\\UI-RotationRight-Button-Down")
|
||
rotateRightBtn:SetHighlightTexture("Interface\\Buttons\\UI-RotationRight-Button-Highlight")
|
||
|
||
rotateRightBtn:SetScript("OnMouseDown", function()
|
||
model.isRotatingRight = true
|
||
end)
|
||
rotateRightBtn:SetScript("OnMouseUp", function()
|
||
model.isRotatingRight = false
|
||
end)
|
||
rotateRightBtn:HookScript("OnLeave", function()
|
||
model.isRotatingRight = false
|
||
end)
|
||
|
||
-- OnUpdate 统一处理拖拽和按钮旋转
|
||
model:SetScript("OnUpdate", function(self, elapsed)
|
||
-- 鼠标拖拽旋转
|
||
if self.isRotating then
|
||
local x = GetCursorPosition()
|
||
local delta = (x - (self.lastX or x)) * 0.01 -- 旋转灵敏度
|
||
self.lastX = x
|
||
self:SetFacing(self:GetFacing() + delta)
|
||
end
|
||
-- 按钮持续旋转
|
||
if self.isRotatingLeft then
|
||
self:SetFacing(self:GetFacing() + ROTATE_SPEED * elapsed)
|
||
elseif self.isRotatingRight then
|
||
self:SetFacing(self:GetFacing() - ROTATE_SPEED * elapsed)
|
||
end
|
||
end)
|
||
|
||
-- 其余UI元素
|
||
local nameText = modelFrame:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
|
||
nameText:SetPoint("BOTTOM", 0, 20)
|
||
nameText:SetTextColor(1, 1, 1)
|
||
|
||
local descText = modelFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
|
||
descText:SetSize(320, 60)
|
||
descText:SetPoint("BOTTOM", 0, 20)
|
||
descText:SetJustifyH("CENTER")
|
||
|
||
panel.listFrame = listFrame
|
||
panel.scrollChild = scrollChild
|
||
panel.modelFrame = modelFrame
|
||
panel.model = model
|
||
panel.nameText = nameText
|
||
panel.descText = descText
|
||
|
||
self:CreateListItems(scrollChild, data, itemType, model, nameText, descText)
|
||
|
||
return panel
|
||
end
|
||
|
||
-- 创建列表项
|
||
function SM_Collections:CreateListItems(parent, data, itemType, model, nameText, descText)
|
||
local buttonHeight = 40
|
||
local spacing = 2
|
||
local iconSize = 30
|
||
local iconSpacing = 5
|
||
|
||
for i, item in ipairs(data) do
|
||
-- 先创建主按钮
|
||
local button = CreateFrame("Button", "Collectionsbutton" .. i, parent)
|
||
button:SetSize(170, buttonHeight)
|
||
button:SetPoint("TOPLEFT", 30, -(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 ButtonIcon = CreateFrame("Button", "CollectionsButtonIcon" .. i, button)
|
||
ButtonIcon:SetSize(iconSize, iconSize)
|
||
ButtonIcon:SetPoint("RIGHT", button, "LEFT", 0, 0)
|
||
-- 创建图标按钮 (左边)
|
||
local name, rank, icon, castTime, minRange, maxRange, spellID, originalIcon = GetSpellInfo(item.id)
|
||
ButtonIcon:SetNormalTexture(icon)
|
||
ButtonIcon:SetHighlightTexture(icon)
|
||
|
||
-- 为 ButtonIcon 添加技能信息提示
|
||
ButtonIcon:SetScript("OnEnter", function()
|
||
GameTooltip:SetOwner(ButtonIcon, "ANCHOR_RIGHT")
|
||
--GameTooltip:SetSpell(item.id)
|
||
GameTooltip:SetHyperlink("spell:" .. item.id)
|
||
GameTooltip:Show()
|
||
end)
|
||
|
||
ButtonIcon:SetScript("OnLeave", function()
|
||
GameTooltip:Hide()
|
||
end)
|
||
|
||
ButtonIcon:SetFrameLevel(button:GetFrameLevel() + 1)
|
||
|
||
local text = button:CreateFontString(nil, "OVERLAY", "GameFontNormal")
|
||
text:SetPoint("LEFT", 10, 0)
|
||
text:SetText(item.name)
|
||
|
||
if item.obtained then
|
||
text:SetTextColor(1, 1, 1)
|
||
else
|
||
text:SetTextColor(0.5, 0.5, 0.5)
|
||
end
|
||
|
||
-- button 只有高亮效果,点击事件移到这里
|
||
button:SetScript("OnClick", function()
|
||
print("点击项目:", item.name, "ID:", item.id)
|
||
nameText:SetText(item.name)
|
||
descText:SetText(item.description)
|
||
|
||
local creatureDisplayID = self:GetCreatureDisplayID(item.id, itemType)
|
||
if creatureDisplayID and creatureDisplayID > 0 then
|
||
model:Hide()
|
||
model:SetPosition(0, 0, 0)
|
||
model.zoomLevel = 0
|
||
model:Show()
|
||
model:SetCreature(creatureDisplayID)
|
||
end
|
||
end)
|
||
|
||
-- button 的简单提示
|
||
button:SetScript("OnEnter", function()
|
||
if item.obtained then
|
||
nameText:SetText(item.name)
|
||
nameText:SetTextColor(1, 1, 1)
|
||
else
|
||
nameText:SetText(item.name .. " (未获得)")
|
||
nameText:SetTextColor(0.8, 0.8, 0.8)
|
||
end
|
||
end)
|
||
|
||
button:Show()
|
||
ButtonIcon:Show()
|
||
end
|
||
|
||
local totalHeight = #data * (buttonHeight + spacing)
|
||
parent:SetHeight(math.max(totalHeight, 1))
|
||
end
|
||
|
||
-- 显示坐骑页面
|
||
function SM_Collections:ShowMounts()
|
||
local panel = self:CreateSplitPanel(self.MainFrame.ContentFrame, self.Data.Mounts, "mount")
|
||
|
||
local firstObtained = nil
|
||
for _, mount in ipairs(self.Data.Mounts) do
|
||
if mount.obtained then
|
||
firstObtained = mount
|
||
break
|
||
end
|
||
end
|
||
|
||
if firstObtained then
|
||
panel.nameText:SetText(firstObtained.name)
|
||
panel.descText:SetText(firstObtained.description)
|
||
|
||
-- 使用独立的显示ID获取
|
||
local creatureDisplayID = self:GetCreatureDisplayID(firstObtained.id, "mount")
|
||
if creatureDisplayID and creatureDisplayID > 0 then
|
||
panel.model:Hide()
|
||
panel.model:SetPosition(0, 0, 0)
|
||
panel.model.zoomLevel = 0
|
||
panel.model:Show()
|
||
panel.model:SetCreature(creatureDisplayID)
|
||
end
|
||
end
|
||
|
||
panel:Show()
|
||
self.CurrentPanel = panel
|
||
end
|
||
|
||
-- 显示物品页面
|
||
function SM_Collections:ShowItems()
|
||
local panel = CreateFrame("Frame", "SM_CollectionsItemsPanel", self.MainFrame.ContentFrame)
|
||
panel:SetAllPoints()
|
||
|
||
-- 创建物品网格背景
|
||
panel:SetBackdrop({
|
||
bgFile = "Interface\\AddOns\\SM_CollectionSystem\\Interface\\DialogFrame\\UI-DialogBox-Background",
|
||
edgeFile = "Interface\\AddOns\\SM_CollectionSystem\\Interface\\DialogFrame\\UI-DialogBox-Border",
|
||
tile = true,
|
||
tileSize = 32,
|
||
edgeSize = 32,
|
||
insets = { left = 11, right = 12, top = 12, bottom = 11 }
|
||
})
|
||
|
||
-- 创建滚动框架
|
||
-- 修复:为 ScrollFrame 提供唯一名称
|
||
local scrollFrameName = "SM_ItemScrollFrame_" .. math.random(1000, 9999)
|
||
local scrollFrame = CreateFrame("ScrollFrame", scrollFrameName, panel, "UIPanelScrollFrameTemplate")
|
||
scrollFrame:SetSize(740, 480)
|
||
scrollFrame:SetPoint("TOPLEFT", 10, -10)
|
||
|
||
local scrollChild = CreateFrame("Frame", "SM_CollectionsItemsScrollChild", scrollFrame)
|
||
scrollChild:SetSize(720, 1)
|
||
scrollFrame:SetScrollChild(scrollChild)
|
||
|
||
-- 创建物品网格
|
||
self:CreateItemGrid(scrollChild)
|
||
|
||
panel:Show()
|
||
self.CurrentPanel = panel
|
||
end
|
||
|
||
-- 创建物品网格
|
||
function SM_Collections:CreateItemGrid(parent)
|
||
local buttonSize = 40
|
||
local spacing = 5
|
||
local buttonsPerRow = 16
|
||
|
||
for i, item in ipairs(self.Data.Items) do
|
||
local button = CreateFrame("Button", "SM_CollectionsItemGridButton", parent)
|
||
button:SetSize(buttonSize, buttonSize)
|
||
|
||
local row = math.floor((i - 1) / buttonsPerRow)
|
||
local col = (i - 1) % buttonsPerRow
|
||
|
||
print("col= ", col) -- 物品名称(无颜色)
|
||
|
||
button:SetPoint("TOPLEFT", 10 + col * (buttonSize + spacing), -10 + -row * (buttonSize + spacing))
|
||
|
||
-- 设置物品图标
|
||
local texture = button:CreateTexture(nil, "ARTWORK")
|
||
texture:SetAllPoints()
|
||
|
||
local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount, itemEquipLoc, itemTexture, itemSellPrice =
|
||
GetItemInfo(item.id);
|
||
|
||
texture:SetTexture(itemTexture)
|
||
|
||
print("itemName= ", itemName) -- 物品名称(无颜色)
|
||
print("itemLink= ", itemLink) -- 完整物品链接(带颜色)
|
||
print("itemRarity= ", itemRarity) -- 物品品质(0灰,1白,2绿,3蓝,4紫,5橙)
|
||
print("itemLevel= ", itemLevel) -- 物品等级(装备强度)
|
||
print("itemMinLevel= ", itemMinLevel) -- 使用所需最低等级
|
||
print("itemType= ", itemType) -- 物品大类(如"武器"、"护甲")
|
||
print("itemSubType= ", itemSubType) -- 物品子类(如"匕首"、"板甲")
|
||
print("itemStackCount= ", itemStackCount) -- 最大堆叠数量
|
||
print("itemEquipLoc= ", itemEquipLoc) -- 装备位置(如"INVTYPE_HEAD"头部)
|
||
print("itemTexture= ", itemTexture) -- 物品图标路径
|
||
print("itemSellPrice= ", itemSellPrice) -- 卖给NPC的价格(铜币)
|
||
|
||
-- 根据获得状态设置颜色
|
||
if not item.obtained then
|
||
texture:SetDesaturated(true) -- 灰色效果
|
||
else
|
||
texture:SetDesaturated(false) -- 正常颜色
|
||
end
|
||
|
||
-- 鼠标悬停效果
|
||
button:SetHighlightTexture("Interface\\Buttons\\ButtonHilight-Square")
|
||
|
||
-- 点击事件
|
||
button:HookScript("OnClick", function()
|
||
if item.obtained then
|
||
print("选择了物品: " .. item.name)
|
||
else
|
||
print("您还没有获得: " .. item.name)
|
||
end
|
||
end)
|
||
|
||
-- 工具提示
|
||
button:HookScript("OnEnter", function(self)
|
||
GameTooltip:SetOwner(button, "ANCHOR_RIGHT")
|
||
GameTooltip:SetText(item.name)
|
||
|
||
GameTooltip:SetHyperlink('Hitem:' .. item.id)
|
||
print("id= ", item.id)
|
||
|
||
GameTooltip:Show()
|
||
end)
|
||
|
||
button:HookScript("OnLeave", function()
|
||
GameTooltip:Hide()
|
||
end)
|
||
|
||
button:Show()
|
||
end
|
||
|
||
-- 更新滚动区域高度
|
||
local rows = math.ceil(#self.Data.Items / buttonsPerRow)
|
||
local totalHeight = rows * (buttonSize + spacing)
|
||
parent:SetHeight(math.max(totalHeight, 1))
|
||
end
|
||
|
||
-- 斜杠命令
|
||
SLASH_SM_COLLECTIONS1 = "/smcollections"
|
||
SLASH_SM_COLLECTIONS2 = "/sm收藏"
|
||
SlashCmdList["SM_COLLECTIONS"] = function()
|
||
-- 确保只创建一次主界面
|
||
if not SM_Collections.MainFrame then
|
||
SM_Collections:CreateMainFrame()
|
||
end
|
||
|
||
-- 简化显示/隐藏逻辑
|
||
if SM_Collections.MainFrame:IsVisible() then
|
||
SM_Collections.MainFrame:Hide()
|
||
else
|
||
SM_Collections.MainFrame:Show()
|
||
-- 只在首次显示时设置默认标签页
|
||
if not SM_Collections.CurrentTab then
|
||
SM_Collections:ShowTab(1)
|
||
end
|
||
end
|
||
end
|
||
|
||
-- 初始化事件
|
||
local SM_Collections_Frame = CreateFrame("Frame")
|
||
SM_Collections_Frame:RegisterEvent("ADDON_LOADED")
|
||
SM_Collections_Frame:SetScript("OnEvent", function(self, event, addonName)
|
||
if addonName == "SM_CollectionSystem" then
|
||
print("SM收藏系统已加载!使用 /smcollections 打开界面")
|
||
end
|
||
end)
|
||
|
||
print("收藏系统结束")
|