Skip to content

Commit

Permalink
feat: 添加一些设置
Browse files Browse the repository at this point in the history
  • Loading branch information
DengSir committed Sep 5, 2024
1 parent 9a8dcd8 commit 5450f8f
Show file tree
Hide file tree
Showing 12 changed files with 189 additions and 33 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "Libs/LibShowUIPanel-1.0"]
path = Libs/LibShowUIPanel-1.0
url = https://github.com/DengSir/LibShowUIPanel-1.0.git
[submodule "Libs/tdOptions"]
path = Libs/tdOptions
url = [email protected]:DengSir/tdOptions.git
85 changes: 81 additions & 4 deletions Addon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ function Addon:OnInitialize()
global = { --
userCache = {},
},
profile = {},
profile = { --
characterGear = true,
inspectGear = true,
inspectCompare = true,
showTalentBackground = true,
},
}

---@type tdInspectProfile | AceDB.Schema
Expand All @@ -66,15 +71,22 @@ function Addon:OnInitialize()
end

self.db.global.version = ns.VERSION

self.CharacterGearParent = CreateFrame('Frame', nil, PaperDollFrame)
self.CharacterGearParent:SetPoint('TOPLEFT', CharacterFrame, 'TOPRIGHT', -33, -12)
self.CharacterGearParent:SetSize(1, 1)
self.CharacterGearParent:SetScript('OnShow', function()
self:OpenCharacterGearFrame()
end)

self:SetupOptionFrame()
end

function Addon:OnEnable()
self:RegisterEvent('ADDON_LOADED')
self:RegisterMessage('INSPECT_READY')
self:RegisterMessage('INSPECT_TALENT_READY', 'INSPECT_READY')

self.GearFrame = ns.UI.CharacterGearFrame:Create(PaperDollFrame)
self.GearFrame:SetPoint('TOPLEFT', CharacterFrame, 'TOPRIGHT', -33, -12)
self:RegisterMessage('TDINSPECT_OPTION_CHANGED')
end

function Addon:OnModuleCreated(module)
Expand Down Expand Up @@ -112,3 +124,68 @@ function Addon:INSPECT_READY(_, unit, name)
ShowUIPanel(self.InspectFrame)
end
end

function Addon:TDINSPECT_OPTION_CHANGED(_, key, value)
if key == 'characterGear' then
if value then
if self.CharacterGearParent:IsShown() then
self:OpenCharacterGearFrame()
end
elseif self.CharacterGearFrame then
if not self.db.profile.inspectCompare or not self.InspectGearFrame or not self.InspectGearFrame:IsShown() then
self.CharacterGearFrame:Hide()
end
end
elseif key == 'inspectGear' then
if value then
if InspectPaperDollFrame:IsShown() then
self:OpenInspectGearFrame()
elseif self.InspectGearFrame then
self.InspectGearFrame:Hide()
end
end
end
end

---@return UI.CharacterGearFrame
function Addon:GetCharacterGearFrame()
if not self.CharacterGearFrame then
self.CharacterGearFrame = ns.UI.CharacterGearFrame:Create(self.CharacterGearParent)
end
return self.CharacterGearFrame
end

function Addon:GetInspectGearFrame()
if not self.InspectGearFrame then
self.InspectGearFrame = ns.UI.InspectGearFrame:Create(InspectPaperDollFrame)
self.InspectGearFrame:SetPoint('TOPLEFT', InspectPaperDollFrame, 'TOPRIGHT', -33, -12)
end
return self.InspectGearFrame
end

function Addon:OpenCharacterGearFrame()
if self.db.profile.characterGear then
local characterGearFrame = self:GetCharacterGearFrame()

if characterGearFrame:IsShown() then
return
end

characterGearFrame:TapTo(self.CharacterGearParent, 'TOPLEFT')
characterGearFrame:Show()
end
end

function Addon:OpenInspectGearFrame()
if self.db.profile.inspectGear then
local inspectGearFrame = self:GetInspectGearFrame()
inspectGearFrame:Show()

if self.db.profile.inspectCompare then
local characterGearFrame = self:GetCharacterGearFrame()

characterGearFrame:TapTo(inspectGearFrame, 'TOPLEFT', inspectGearFrame, 'TOPRIGHT', 0, 0)
characterGearFrame:Show()
end
end
end
1 change: 0 additions & 1 deletion Core/Pool.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ function Pool:Alloc(parent)
end

function Pool:Free()
print(self, debugstack())
self.pool[self] = true

if self.Hide then
Expand Down
1 change: 1 addition & 0 deletions Libs/tdOptions
Submodule tdOptions added at 19552f
1 change: 1 addition & 0 deletions Load.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@
<Script file="UI\GearFrame.lua" />
<Script file="UI\InspectGearFrame.lua" />
<Script file="UI\CharacterGearFrame.lua" />
<Script file="UI\Option.lua" />
<Script file="UI\ElvUI.lua" />
</Ui>
21 changes: 19 additions & 2 deletions UI/CharacterGearFrame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ local CharacterGearFrame = ns.Addon:NewClass('UI.CharacterGearFrame', ns.UI.Gear

function CharacterGearFrame:Constructor()
self:SetScript('OnShow', self.OnShow)
self:SetScript('OnHide', self.UnregisterAllEvents)
self:SetScript('OnHide', self.OnHide)

self.Talent2:SetScript('OnClick', function(button)
if not InCombatLockdown() then
Expand All @@ -23,13 +23,30 @@ end
function CharacterGearFrame:OnShow()
self:RegisterEvent('UNIT_INVENTORY_CHANGED')
self:RegisterEvent('UNIT_LEVEL', 'UNIT_INVENTORY_CHANGED')
self:RegisterMessage('TDINSPECT_OPTION_CHANGED', 'UpdateOption')
self:Update()

if GearManagerDialog then
GearManagerDialog:SetFrameLevel(self:GetFrameLevel() + 10)
end
end

function CharacterGearFrame:OnHide()
self:UnregisterAllEvents()
self:UnregisterAllMessages()
self:Hide()
end

function CharacterGearFrame:UpdateOption(_, key, value)
if key == 'showTalentBackground' then
if value then
self:UpdateTalents()
else
self:SetBackground()
end
end
end

function CharacterGearFrame:UNIT_INVENTORY_CHANGED(_, unit)
if unit == 'player' then
self:Update()
Expand Down Expand Up @@ -85,5 +102,5 @@ function CharacterGearFrame:TapTo(frame, ...)
self:SetParent(frame)
self:ClearAllPoints()
self:SetPoint(...)
self:Show()
self:UpdateOption()
end
27 changes: 18 additions & 9 deletions UI/GearFrame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function GearFrame:Create(parent)
end

function GearFrame:Constructor()
self:Hide()
self:SetScript('OnSizeChanged', self.OnSizeChanged)

local SlotColumn = CreateFrame('Frame', nil, self)
Expand Down Expand Up @@ -143,16 +144,24 @@ function GearFrame:SetLevel(level)
end

function GearFrame:SetBackground(background)
local base
if background then
base = [[Interface\TalentFrame\]] .. background .. '-'
if not background then
self.TopLeft:Hide()
self.TopRight:Hide()
self.BottomLeft:Hide()
self.BottomRight:Hide()
self:SetBackdropColor(0, 0, 0, 0.95)
else
base = [[Interface\TalentFrame\MageFire-]]
local base = [[Interface\TalentFrame\]] .. background .. '-'
self.TopLeft:SetTexture(base .. 'TopLeft')
self.TopRight:SetTexture(base .. 'TopRight')
self.BottomLeft:SetTexture(base .. 'BottomLeft')
self.BottomRight:SetTexture(base .. 'BottomRight')
self.TopLeft:Show()
self.TopRight:Show()
self.BottomLeft:Show()
self.BottomRight:Show()
self:SetBackdropColor(0, 0, 0, 0)
end
self.TopLeft:SetTexture(base .. 'TopLeft')
self.TopRight:SetTexture(base .. 'TopRight')
self.BottomLeft:SetTexture(base .. 'BottomLeft')
self.BottomRight:SetTexture(base .. 'BottomRight')
end

function GearFrame:UpdateTalents()
Expand All @@ -177,7 +186,7 @@ function GearFrame:UpdateTalent(button, group, isActive)
button.Text:SetText(name)
button.Point:SetText(points)
button:Show()
self:SetBackground(bg)
self:SetBackground(ns.Addon.db.profile.showTalentBackground and bg or nil)
else
button:Hide()
self:SetBackground()
Expand Down
9 changes: 5 additions & 4 deletions UI/InspectGearFrame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,14 @@ function InspectGearFrame:OnShow()
self:RegisterEvent('UNIT_INVENTORY_CHANGED')
self:RegisterEvent('GET_ITEM_INFO_RECEIVED', 'UpdateItemLevel')
self:Update()

ns.Addon.GearFrame:TapTo(self, 'TOPLEFT', self, 'TOPRIGHT', 0, 0)
end

function InspectGearFrame:OnHide()
self.unit = nil
self.class = nil
self:UnregisterAllEvents()
self:UnregisterAllMessages()

ns.Addon.GearFrame:TapTo(PaperDollFrame, 'TOPLEFT', CharacterFrame, 'TOPRIGHT', -33, -12)
self:Hide()
end

function InspectGearFrame:UNIT_INVENTORY_CHANGED(_, unit)
Expand All @@ -47,6 +44,10 @@ function InspectGearFrame:UNIT_INVENTORY_CHANGED(_, unit)
end
end

function InspectGearFrame:UpdateOption()
self:SetShown(ns.Addon.db.profile.inspectGear)
end

function InspectGearFrame:UpdateItemLevel()
self:SetItemLevel(Inspect:GetItemLevel())
end
Expand Down
50 changes: 50 additions & 0 deletions UI/Option.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
-- Option.lua
-- @Author : Dencer ([email protected])
-- @Link : https://dengsir.github.io
-- @Date : 9/5/2024, 1:39:10 PM
--
---@type ns
local ns = select(2, ...)

local L = ns.L
local tdOptions = LibStub('tdOptions')

---@class Addon
local Addon = ns.Addon

function Addon:SetupOptionFrame()
local order = 0
local function orderGen()
order = order + 1
return order
end

local function fullToggle(name)
return {type = 'toggle', name = name, width = 'full', order = orderGen()}
end

local options = {
type = 'group',
name = format('tdInspect - |cff00ff00%s|r', C_AddOns.GetAddOnMetadata('tdInspect', 'Version')),
get = function(item)
return self.db.profile[item[#item]]
end,
set = function(item, value)
local key = item[#item]
self.db.profile[key] = value
self:SendMessage('TDINSPECT_OPTION_CHANGED', key, value)
end,
args = {
characterGear = fullToggle(L['Show character gear list']),
inspectGear = fullToggle(L['Show inspect gear list']),
inspectCompare = fullToggle(L['Show inspect compare']),
showTalentBackground = fullToggle(L['Show talent background']),
},
}

tdOptions:Register('tdInspect', options)
end

function Addon:OpenOptionFrame()
tdOptions:Open('tdInspect')
end
14 changes: 6 additions & 8 deletions UI/PaperDoll.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ function PaperDoll:Constructor()
self.LevelText = InspectLevelText
self.ModelFrame = ns.UI.ModelFrame:Bind(self:CreateInsetFrame())

self.GearFrame = ns.UI.InspectGearFrame:Create(self)
self.GearFrame:SetPoint('TOPLEFT', self, 'TOPRIGHT', -33, -12)

self:SetScript('OnShow', self.OnShow)
self:SetScript('OnHide', self.OnHide)
end
Expand All @@ -90,18 +87,19 @@ function PaperDoll:OnShow()
self:RegisterEvent('UNIT_LEVEL', 'UpdateInfo')
self:UpdateInfo()
self:Update()
end

function PaperDoll:INSPECT_READY()
self:Update()
self:UpdateInfo()
ns.Addon:OpenInspectGearFrame()
end

function PaperDoll:OnHide()
self:UnregisterAllEvents()
self:UnregisterAllMessages()
end

function PaperDoll:INSPECT_READY()
self:Update()
self:UpdateInfo()
end

function PaperDoll:CreateInsetFrame()
local frame = CreateFrame('Frame', nil, self)
frame:SetPoint('TOPLEFT', 65, -76)
Expand Down
9 changes: 4 additions & 5 deletions UI/Template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,13 @@
edgeSize = 16,
insets = {left = 4, right = 4, top = 4, bottom = 4},
}
self:SetBackdropColor(0, 0, 0, 0.95)
self.ItemLevel:SetFont(self.ItemLevel:GetFont(), 12, "OUTLINE")
self.Talent2.Text:SetTextColor(0.6, 0.6, 0.6)
self.Talent2.Point:SetTextColor(0.6, 0.6, 0.6)
self.TopLeft:SetVertexColor(0.2, 0.2, 0.2, 0.8)
self.TopRight:SetVertexColor(0.2, 0.2, 0.2, 0.8)
self.BottomLeft:SetVertexColor(0.2, 0.2, 0.2, 0.8)
self.BottomRight:SetVertexColor(0.2, 0.2, 0.2, 0.8)
self.TopLeft:SetVertexColor(0.2, 0.2, 0.2, 0.95)
self.TopRight:SetVertexColor(0.2, 0.2, 0.2, 0.95)
self.BottomLeft:SetVertexColor(0.2, 0.2, 0.2, 0.95)
self.BottomRight:SetVertexColor(0.2, 0.2, 0.2, 0.95)
</OnLoad>
</Scripts>
</Frame>
Expand Down
1 change: 1 addition & 0 deletions tdInspect.toc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#@end-debug@
#@project-interface@
## Title: tdInspect
## IconTexture: 132092
## Author: Dencer
## Version: @project-version@
## OptionalDeps: LibCompress
Expand Down

0 comments on commit 5450f8f

Please sign in to comment.