Skip to content

Commit

Permalink
refactor: 优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
DengSir committed Sep 5, 2024
1 parent afa68d1 commit 625355e
Show file tree
Hide file tree
Showing 24 changed files with 210 additions and 385 deletions.
40 changes: 40 additions & 0 deletions .emmy/UI/Template.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---@meta
---@class tdInspectPortraitTemplate : Frame
---@field PortraitRing Texture
---@field Portrait Texture
---@field PortraitRingQuality Texture
---@field LevelBorder Texture
---@field Level FontString
---@field PortraitRingCover Texture
local tdInspectPortraitTemplate = {}

---@class tdInspectGearTalentFrame : Button
---@field Icon Texture
---@field CircleMask MaskTexture
---@field Text FontString
---@field Point FontString
local tdInspectGearTalentFrame = {}

---@class __tdInspectGearFrameTemplate_Portrait : tdInspectPortraitTemplate , Frame

---@class __tdInspectGearFrameTemplate_Talent1 : tdInspectGearTalentFrame , Button

---@class __tdInspectGearFrameTemplate_Talent2 : tdInspectGearTalentFrame , Button

---@class tdInspectGearFrameTemplate : BackdropTemplate , Frame
---@field Name FontString
---@field ItemLevel FontString
---@field TopLeft Texture
---@field TopRight Texture
---@field BottomLeft Texture
---@field BottomRight Texture
---@field Portrait __tdInspectGearFrameTemplate_Portrait
---@field Talent1 __tdInspectGearFrameTemplate_Talent1
---@field Talent2 __tdInspectGearFrameTemplate_Talent2
local tdInspectGearFrameTemplate = {}

---@class tdInspectSocketItemTemplate : Button
---@field Icon Texture
---@field Border Texture
---@field CircleMask MaskTexture
local tdInspectSocketItemTemplate = {}
17 changes: 11 additions & 6 deletions Addon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
---@field Inspect Inspect
---@field Talent Talent
---@field Glyph Glyph
---@field ItemLevelCalculator ItemLevelCalculator
local ns = select(2, ...)

local ShowUIPanel = LibStub('LibShowUIPanel-1.0').ShowUIPanel
Expand All @@ -19,6 +20,12 @@ local ShowUIPanel = LibStub('LibShowUIPanel-1.0').ShowUIPanel
---@field EnchantItem UI.EnchantItem
---@field InspectFrame UI.InspectFrame
---@field InspectGearFrame UI.InspectGearFrame
---@field GlyphItem UI.GlyphItem
---@field TalentFrame UI.TalentFrame
---@field CharacterGearFrame UI.CharacterGearFrame
---@field GlyphFrame UI.GlyphFrame
---@field PaperDoll UI.PaperDoll
---@field InspectTalent UI.InspectTalent
ns.UI = {}
ns.L = LibStub('AceLocale-3.0'):GetLocale('tdInspect')

Expand All @@ -30,22 +37,20 @@ _G.BINDING_HEADER_TDINSPECT = 'tdInspect'
_G.BINDING_NAME_TDINSPECT_VIEW_TARGET = ns.L['Inspect target']
_G.BINDING_NAME_TDINSPECT_VIEW_MOUSEOVER = ns.L['Inspect mouseover']

---@class Addon: AceAddon-3.0, LibClass-2.0, AceEvent-3.0
---@class Addon: AceAddon, LibClass-2.0, AceEvent-3.0
local Addon = LibStub('AceAddon-3.0'):NewAddon('tdInspect', 'LibClass-2.0', 'AceEvent-3.0')
ns.Addon = Addon

function Addon:OnInitialize()
---@class tdInspectProfile
---@class tdInspectProfile: table
local profile = { --
global = { --
userCache = {},
},
profile = { --
showModel = true,
},
profile = {},
}

---@type tdInspectProfile
---@type tdInspectProfile | AceDB.Schema
self.db = LibStub('AceDB-3.0'):New('TDDB_INSPECT2', profile, true)

if not self.db.global.version or self.db.global.version < 20000 then
Expand Down
2 changes: 1 addition & 1 deletion Core/Inspect.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ local function sleep(n)
coroutine.yield()
end

---@class Inspect: AceAddon-3.0, AceEvent-3.0, AceComm-3.0
---@class Inspect: AceModule, AceEvent-3.0, AceComm-3.0
local Inspect = ns.Addon:NewModule('Inspect', 'AceEvent-3.0', 'AceComm-3.0')

function Inspect:OnInitialize()
Expand Down
2 changes: 1 addition & 1 deletion Core/ItemLevelCalculator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ local ipairs = ipairs
local select = select
local max, min = math.max, math.min

---@class ItemLevelCalculator
local ItemLevelCalculator = ns.Addon:NewClass('ItemLevelCalculator')
ns.ItemLevelCalculator = ItemLevelCalculator

local SLOTS = {
INVSLOT_HEAD, INVSLOT_NECK, INVSLOT_SHOULDER, INVSLOT_CHEST, INVSLOT_WAIST, INVSLOT_LEGS, INVSLOT_FEET,
Expand Down
59 changes: 59 additions & 0 deletions Core/Pool.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
-- Pool.lua
-- @Author : Dencer ([email protected])
-- @Link : https://dengsir.github.io
-- @Date : 9/2/2024, 1:13:38 PM
--
---@class ns
local ns = select(2, ...)

---@class Pool
---@field pool table<any, boolean>
---@field OnFree? function
---@field Create? function
---@field New? function
---@field SetParent? function
---@field Hide? function
local Pool = {}
ns.Pool = Pool

function Pool:Alloc(parent)
local obj = next(self.pool)
if not obj then
if self.Create then
obj = self:Create(parent)
else
obj = self:New(parent)
end
else
self.pool[obj] = nil

if obj.SetParent then
obj:SetParent(parent)
end
if obj.Show then
obj:Show()
end
end
return obj
end

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

if self.Hide then
self:Hide()
end
if self.SetParent then
self:SetParent(nil)
end
if self.OnFree then
self:OnFree()
end
end

function Pool:Mixin(class)
class.pool = {}
class.Alloc = Pool.Alloc
class.Free = Pool.Free
end
5 changes: 2 additions & 3 deletions Core/TipScaner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
-- @Author : Dencer ([email protected])
-- @Link : https://dengsir.github.io
-- @Date : 5/22/2020, 9:31:04 AM

---@type ns
---@class ns
local ns = select(2, ...)

---@type GameTooltip
---@class TipScaner : GameTooltip
local TipScaner = CreateFrame('GameTooltip')
ns.TipScaner = TipScaner

Expand Down
2 changes: 1 addition & 1 deletion Libs/LibTooltipExtra-1.0
4 changes: 2 additions & 2 deletions Load.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
<Script file="Core\Talent.lua" />
<Script file="Core\Glyph.lua" />
<Script file="Core\Ala.lua" />
<Script file="Core\Pool.lua" />

<Script file="Tooltip\FixItemSet.lua" />
<Script file="Tooltip\FixMetaGem.lua" />
<Script file="Tooltip\FixRune.lua" />
<Script file="Tooltip\FixRune.lua" build="Vanilla" />

<Include file="UI\Template.xml" />
<Script file="UI\SocketItem.lua" />
<Script file="UI\BaseItem.lua" />
<Script file="UI\SlotItem.lua" />
<Script file="UI\ModelFrame.lua" />
Expand Down
10 changes: 2 additions & 8 deletions UI/BaseItem.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,11 @@
---@type ns
local ns = select(2, ...)

local tonumber = tonumber

---@class UI.BaseItem: Object, Button, AceEvent-3.0
---@class UI.BaseItem: AceEvent-3.0, Object, Button
local BaseItem = ns.Addon:NewClass('UI.BaseItem', 'Button')

function BaseItem:Constructor()
self:SetScript('OnHide', self.OnHide)
end

function BaseItem:OnHide()
self:UnregisterAllEvents()
self:SetScript('OnHide', self.UnregisterAllEvents)
end

function BaseItem:GET_ITEM_INFO_RECEIVED(_, itemId, ok)
Expand Down
21 changes: 8 additions & 13 deletions UI/EnchantItem.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@
---@type ns
local ns = select(2, ...)

---@class UI.EnchantItem : UI.SocketItem
local EnchantItem = ns.Addon:NewClass('UI.EnchantItem', ns.UI.SocketItem)
---@class UI.EnchantItem : AceEvent-3.0, Object, Button, tdInspectSocketItemTemplate, Pool
local EnchantItem = ns.Addon:NewClass('UI.EnchantItem', 'Button')

ns.Pool:Mixin(EnchantItem)

function EnchantItem:Create(parent)
return self:Bind(CreateFrame('Button', nil, parent, 'tdInspectSocketItemTemplate'))
end

function EnchantItem:Constructor()
self:SetScript('OnEnter', self.OnEnter)
Expand All @@ -20,17 +26,6 @@ function EnchantItem:OnFree()
self.spell = nil
end

function EnchantItem:Alloc(parent)
local obj = tremove(self.pool)
if not obj then
obj = self:New(parent)
else
obj:SetParent(parent)
end
obj:Show()
return obj
end

function EnchantItem:OnEnter()
if self.item then
GameTooltip:SetOwner(self, 'ANCHOR_RIGHT')
Expand Down
58 changes: 0 additions & 58 deletions UI/EquipFrame.lua

This file was deleted.

Loading

0 comments on commit 625355e

Please sign in to comment.