-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathplugin.class.lua
More file actions
122 lines (100 loc) · 3.21 KB
/
plugin.class.lua
File metadata and controls
122 lines (100 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
local addonName, ns, _ = ...
local Plugin = ns.class()
ns.Plugin = Plugin
-- creates a new, empty plugin object
-- not advised, this class is meant to be inherited from by different plugins
function Plugin:construct(name)
self.hasConfigPanel = false
self.hasConfigButton = true -- default, will only make a difference if hasConfigPanel is true
self.configButton = nil
self.configPanel = nil
self.tooltipText = nil
self.buttonTexture = nil
self.roleIdentifier = nil
self.panelHeaderText = nil
self.panelIconTexture = nil
self.panelDescription = nil
self:SetName(name or 'Unnamed Plugin')
if not ns.currentPlugins then
ns.currentPlugins = {}
end
tinsert(ns.currentPlugins, self)
if ns.IsInitialized() then
self:Initialize()
end
end
-- initialize plugin data - called on plugin creation
function Plugin:Initialize()
-- empty by default, should be overridden if the plugin needs initialization
-- this function exists mostly so plugin authors don't have to worry about calling the default plugin constructor
-- and to make sure TopFit is fully initialized by the time any plugins get initialized
end
-- register a tab in TopFit's config frame for use by this plugin
function Plugin:RegisterConfigPanel()
self.hasConfigPanel = true
if ns.ui.IsConfigFrameInitialized() then
self:CreateConfigPanel()
end
end
function Plugin:CreateConfigPanel()
if self.hasConfigPanel then
self.configButton, self.configPanel = ns.ui.CreateConfigPanel(self.fullPanel, not self.hasConfigButton)
self.configPanel.OnUpdate = function(frame)
if self.OnShow then
self:OnShow()
end
end
if self.configButton then
self:UpdateConfigButton()
end
self:UpdateConfigPanel()
self:InitializeUI()
end
end
-- refreshes data on this plugin's config button
function Plugin:UpdateConfigButton()
if self.configButton then
ns.ui.SetSidebarButtonData(self.configButton, self.name, self.tooltipText, self.buttonTexture, self.roleIdentifier)
end
end
-- refreshes data on this plugin's config panel
function Plugin:UpdateConfigPanel()
if self.configPanel then
ns.ui.SetHeaderTitle(self.configPanel, self.panelHeaderText or self.name)
ns.ui.SetHeaderIcon(self.configPanel, self.panelIconTexture or self.buttonTexture)
ns.ui.SetHeaderDescription(self.configPanel, self.panelDescription or self.tooltipText)
end
end
-- set the name of this plugin
function Plugin:SetName(name)
self.AssertArgumentType(name, 'string')
self.name = name
if self.hasConfigPanel then
self:UpdateConfigButton()
end
end
-- get the name of this plugin
function Plugin:GetName()
return self.name
end
-- set this plugin's tooltip text
function Plugin:SetTooltipText(text)
self.AssertArgumentType(text, 'string')
self.tooltipText = text
if self.hasConfigPanel then
self:UpdateConfigButton()
end
end
-- initialize this plugin's UI elements
function Plugin:InitializeUI()
-- empty by default, should be overridden if the plugin registers a config panel
end
-- returns this plugin's config panel frame, if a config panel has been registered
function Plugin:GetConfigPanel()
return self.configPanel
end
-- set this plugin's config button texture
function Plugin:SetButtonTexture(texture)
self.AssertArgumentType(texture, 'string')
self.buttonTexture = texture
end