comparison modules/ReAction_ConfigUI/ReAction_ConfigUI.lua @ 30:0d95ce7a9ec2

- added Ace3 externs - converted ReAction_ConfigUI to use blizzard interface addons panel via AceConfigDialog-3.0 - partially converted FuBar module to LibRock, deprecated it (going to remove it entirely later) - cleaned up a couple other tidbits
author Flick <flickerstreak@gmail.com>
date Wed, 02 Apr 2008 23:31:13 +0000
parents 21bcaf8215ff
children c54c481ad0ed
comparison
equal deleted inserted replaced
29:9c89042bc328 30:0d95ce7a9ec2
2 ReAction Configuration UI module 2 ReAction Configuration UI module
3 3
4 This modules creates and manages ReAction configuration 4 This modules creates and manages ReAction configuration
5 elements, including: 5 elements, including:
6 6
7 - waterfall config menu system 7 - Interface Options panel
8 - bar dragging and resizing control overlays 8 - bar dragging and resizing control overlays
9 - contextual menus 9 - contextual menus
10 10
11 Individual modules are responsible for populating these 11 Individual modules are responsible for populating these
12 configuration elements via the following functions: 12 configuration elements via ReAction:RegisterOptions(). The
13 13 valid values of 'context' are:
14 module:GetGlobalOptions( configModule ) 14
15 module:GetGlobalBarOptions( configModule ) 15 - 'global' : added to the Global Settings tab
16 module:GetModuleOptions( configModule ) 16 - 'module' : added to the Module Settings tab
17 module:GetBarConfigOptions( bar, configModule ) 17 - 'bar' : added to the Bar Settings tab
18 module:GetBarMenuOptions( bar, configModule ) 18 - 'barMenu' : shown on the bar contextual menu
19
20 the ReAction_ConfigUI module is passed in as a parameter so that
21 option handlers can refresh the config UI.
22 19
23 --]] 20 --]]
24 21
25 -- local imports 22 -- local imports
26 local ReAction = ReAction 23 local ReAction = ReAction
27 local L = ReAction.L 24 local L = ReAction.L
28 local _G = _G 25 local _G = _G
29 local Waterfall = AceLibrary("Waterfall-1.0") 26 local InCombatLockdown = InCombatLockdown
27
30 local Dewdrop = AceLibrary("Dewdrop-2.0") 28 local Dewdrop = AceLibrary("Dewdrop-2.0")
31 local print = ReAction.print
32 local InCombatLockdown = InCombatLockdown
33 29
34 -- module declaration 30 -- module declaration
35 local moduleID = "ConfigUI" 31 local moduleID = "ConfigUI"
36 local module = ReAction:NewModule( moduleID, 32 local module = ReAction:NewModule( moduleID,
37 "AceEvent-3.0" 33 "AceEvent-3.0"
38 -- mixins go here
39 ) 34 )
40
41 module.globalOptions = {
42 type = "group",
43 args = {
44 unlock = {
45 type = "toggle",
46 handler = module,
47 name = L["unlock"],
48 guiName = L["Unlock Bars"],
49 desc = L["Unlock bars for dragging and resizing with the mouse"],
50 get = function() return module.configMode end,
51 set = "SetConfigMode",
52 disabled = InCombatLockdown,
53 order = 1
54 },
55 config = {
56 type = "execute",
57 handler = module,
58 name = L["config"],
59 guiName = L["Configure..."],
60 desc = L["Open the configuration dialogue"],
61 func = "OpenConfig",
62 disabled = InCombatLockdown,
63 wfHidden = true, -- don't show this in the waterfall config
64 order = 2
65 },
66 }
67 }
68 35
69 module.configOptions = { 36 module.configOptions = {
70 type = "group", 37 type = "group",
38 childGroups = "tab",
71 args = { 39 args = {
40 desc = {
41 type = "description",
42 name = L["Customizable replacement for Blizzard's Action Bars"],
43 },
72 global = { 44 global = {
73 type = "group", 45 type = "group",
74 name = L["Global Settings"], 46 name = L["Global Settings"],
75 desc = L["Global configuration settings"], 47 desc = L["Global configuration settings"],
76 args = { }, 48 args = {
49 unlock = {
50 type = "toggle",
51 handler = module,
52 name = L["Unlock Bars"],
53 desc = L["Unlock bars for dragging and resizing with the mouse"],
54 get = function() return module.configMode end,
55 set = function(info, value) module:SetConfigMode(value) end,
56 disabled = InCombatLockdown,
57 order = 1
58 },
59 },
77 order = 1, 60 order = 1,
78 }, 61 },
79 module = { 62 module = {
80 type = "group", 63 type = "group",
64 childGroups = "select",
81 name = L["Module Settings"], 65 name = L["Module Settings"],
82 desc = L["Configuration settings for each module"], 66 desc = L["Configuration settings for each module"],
83 args = { }, 67 args = {
84 order = 2, 68 configUI = {
69 type = "group",
70 name = "Config UI",
71 desc = "description",
72 args = {
73 foo = {
74 type = "toggle",
75 handler = module,
76 name = "foo",
77 desc = "description",
78 get = function() return true end,
79 set = function() end,
80 }
81 }
82 },
83 },
84 order = -1,
85 }, 85 },
86 bar = { 86 },
87 type = "group", 87 plugins = { }
88 name = L["Bars"],
89 desc = L["Configuration settings for bars"],
90 args = { },
91 order = 3,
92 },
93 }
94 } 88 }
95 89
96 -- module methods 90 -- module methods
97 function module:OnInitialize() 91 function module:OnInitialize()
98 self.db = ReAction.db:RegisterNamespace( moduleID, 92 self.db = ReAction.db:RegisterNamespace( moduleID,
99 { 93 {
100 profile = { } 94 profile = { }
101 } 95 }
102 ) 96 )
103 end 97 self:InitializeOptions()
104 98 LibStub("AceConfig-3.0"):RegisterOptionsTable("ReAction",self.configOptions)
105 function module:OnEnable() 99 LibStub("AceConfigDialog-3.0"):AddToBlizOptions("ReAction", "ReAction")
106 self:RegisterEvent("PLAYER_REGEN_DISABLED") 100 self:RegisterEvent("PLAYER_REGEN_DISABLED")
107 Waterfall:Register("ReAction", 101 end
108 "aceOptions", self.configOptions, 102
109 "treeLevels", nil, -- infinite 103 function module:InitializeOptions()
110 "colorR", 0.8, 104 for _, m in pairs(ReAction:GetOptions("global")) do
111 "colorG", 0.65, 105 for k, v in pairs(m) do
112 "colorB", 0, 106 self.configOptions.args.global.args[k] = v
113 "defaultPane", "global" ) 107 end
114 end 108 end
115 109 ReAction.RegisterCallback(self,"OnOptionsRegistered")
116 function module:OnDisable() 110 end
117 self:UnregisterEvent("PLAYER_REGEN_DISABLED") 111
118 self:SetConfigMode(false) 112 function module:OnOptionsRegistered(evt, context, module, opts)
119 Waterfall:UnRegister("ReAction") 113 if context == "global" then
114 for k, v in pairs(opts) do
115 self.configOptions.args.global.args[k] = v
116 end
117 elseif context == "module" then
118 for k, v in pairs(opts) do
119 self.configOptions.args.module.args[k] = v
120 end
121 elseif context == "bar" then
122
123 elseif context == "barMenu" then
124
125 end
120 end 126 end
121 127
122 function module:PLAYER_REGEN_DISABLED() 128 function module:PLAYER_REGEN_DISABLED()
123 if self.configMode == true then 129 if self.configMode == true then
124 UIErrorsFrame:AddMessage(L["ReAction config mode disabled during combat."]) 130 UIErrorsFrame:AddMessage(L["ReAction config mode disabled during combat."])
125 self:SetConfigMode(false) 131 self:SetConfigMode(false)
126 Waterfall:Close("ReAction")
127 end 132 end
128 end 133 end
129 134
130 function module:SetConfigMode( mode ) 135 function module:SetConfigMode( mode )
131 ReAction:CallMethodOnAllBars("ShowControls",mode) 136 ReAction:CallMethodOnAllBars("ShowControls",mode)
147 end 152 end
148 end 153 end
149 end 154 end
150 end 155 end
151 156
152 local function refreshWaterfall() 157 local function safecall(module, method, ...)
153 module:RefreshConfig()
154 end
155
156 local function SafeCall(module, method, ...)
157 if module and type(module[method]) == "function" then 158 if module and type(module[method]) == "function" then
158 return module[method](...) 159 return module[method](method, ...)
159 end
160 end
161
162 function module:RefreshOptions()
163 local opts = self.configOptions.args
164
165 for _, m in ReAction:IterateModules() do
166 local o = SafeCall(m,"GetGlobalOptions",self)
167 if o then
168 for k, v in pairs(o) do
169 opts.global.args[k] = v
170 end
171 end
172 end
173
174 for _, m in ReAction:IterateModules() do
175 local o = SafeCall(m,"GetGlobalBarOptions",self)
176 if o then
177 for k, v in pairs(o) do
178 opts.bar.args[k] = v
179 end
180 end
181 end
182
183 for _, m in ReAction:IterateModules() do
184 local o = SafeCall(m,"GetModuleOptions",self)
185 if o then
186 for k, v in pairs(o) do
187 opts.module.args[k] = v
188 end
189 end
190 end
191
192 local barOpts = opts.bar.args
193 for name, bar in pairs(ReAction.bars) do
194 if bar then
195 if barOpts[name] == nil then
196 barOpts[name] = {
197 type = "group",
198 name = name,
199 desc = name,
200 handler = bar,
201 args = {
202 delete = {
203 type = "execute",
204 name = L["Delete Bar"],
205 desc = L["Remove the bar from the current profile"],
206 func = function() ReAction:EraseBar(bar); self:RefreshConfig() end
207 },
208 rename = {
209 type = "text",
210 name = L["Rename Bar"],
211 desc = L["Set a name for the bar"],
212 get = "GetName",
213 set = function(name) ReAction:RenameBar(bar,name); self:RefreshConfig() end
214 }
215 }
216 }
217 end
218 if bar.modConfigOpts == nil then
219 bar.modConfigOpts = { }
220 end
221 for _, m in ReAction:IterateModules() do
222 local o = SafeCall(m,"GetBarConfigOptions",bar,self)
223 if o then
224 for k, v in pairs(o) do
225 barOpts[name].args[k] = v
226 end
227 end
228 end
229 end
230 end
231 -- remove obsolete bar tables
232 for name, opt in pairs(barOpts) do
233 if opt.type == "group" and ReAction.bars[name] == nil then
234 barOpts[name] = nil
235 end
236 end 160 end
237 end 161 end
238 162
239 function module:OpenConfig(bar) 163 function module:OpenConfig(bar)
240 self:RefreshOptions()
241 Dewdrop:Close() 164 Dewdrop:Close()
242 Waterfall:Open("ReAction",bar and "bar."..bar:GetName()) 165 InterfaceOptionsFrame_OpenToFrame("ReAction")
243 end
244
245 function module:RefreshConfig()
246 self:RefreshOptions()
247 Waterfall:Refresh("ReAction")
248 end 166 end
249 167
250 function module:ApplyToBar(bar) 168 function module:ApplyToBar(bar)
251 if self.configMode then 169 if self.configMode then
252 bar:ShowControls(true) 170 bar:ShowControls(self.configMode)
253 end 171 end
254 end 172 end
255 173
256 function module:RemoveFromBar(bar) 174 function module:RemoveFromBar(bar)
257 if bar.controlFrame then 175 if bar.controlFrame then
258 bar.controlFrame:SetParent(UIParent) 176 bar.controlFrame:SetParent(UIParent)
259 bar.controlFrame:ClearAllPoints() 177 bar.controlFrame:ClearAllPoints()
260 bar.controlFrame:Hide() 178 bar.controlFrame:Hide()
261 bar.controlFrame = nil 179 bar.controlFrame = nil
262 end 180 end
263 end
264
265 function module:GetGlobalOptions()
266 return self.globalOptions.args
267 end 181 end
268 182
269 183
270 184
271 185
545 control:SetScript("OnEnter", 459 control:SetScript("OnEnter",
546 function() 460 function()
547 -- add bar type and status information to name 461 -- add bar type and status information to name
548 local name = bar.name 462 local name = bar.name
549 for _, m in ReAction:IterateModules() do 463 for _, m in ReAction:IterateModules() do
550 local suffix = SafeCall(m,"GetBarNameModifier",bar) 464 local suffix = safecall(m,"GetBarNameModifier",bar)
551 if suffix then 465 if suffix then
552 name = format("%s %s",name,suffix) 466 name = ("%s %s"):format(name,suffix)
553 end 467 end
554 end 468 end
555 469
556 GameTooltip:SetOwner(f, "ANCHOR_TOPRIGHT") 470 GameTooltip:SetOwner(f, "ANCHOR_TOPRIGHT")
557 GameTooltip:AddLine(name) 471 GameTooltip:AddLine(name)
609 end 523 end
610 if self.modMenuOpts == nil then 524 if self.modMenuOpts == nil then
611 self.modMenuOpts = { } 525 self.modMenuOpts = { }
612 end 526 end
613 for _, m in ReAction:IterateModules() do 527 for _, m in ReAction:IterateModules() do
614 local opts = SafeCall(m,"GetBarMenuOptions",self,module) 528 local opts = safecall(m,"GetBarMenuOptions",self,module)
615 if opts then 529 if opts then
616 for k, v in pairs(opts) do 530 for k, v in pairs(opts) do
617 self.menuOpts.args[k] = v 531 self.menuOpts.args[k] = v
618 end 532 end
619 end 533 end