comparison modules/ReAction_ConfigUI/ReAction_ConfigUI.lua @ 47:e12b736c23c3

Added Layout Editor
author Flick <flickerstreak@gmail.com>
date Fri, 11 Apr 2008 22:21:28 +0000
parents aa0b7fd68462
children 7b7d178dec52
comparison
equal deleted inserted replaced
46:aa0b7fd68462 47:e12b736c23c3
5 --]] 5 --]]
6 6
7 -- local imports 7 -- local imports
8 local ReAction = ReAction 8 local ReAction = ReAction
9 local L = ReAction.L 9 local L = ReAction.L
10 local AceConfigReg = LibStub("AceConfigRegistry-3.0")
11 local AceConfigDialog = LibStub("AceConfigDialog-3.0")
10 12
11 -- module declaration 13 -- module declaration
12 local moduleID = "ConfigUI" 14 local moduleID = "ConfigUI"
13 local module = ReAction:NewModule( moduleID ) 15 local module = ReAction:NewModule( moduleID,
16 "AceEvent-3.0"
17 )
14 18
15 -- module methods 19 -- module methods
16 function module:OnInitialize() 20 function module:OnInitialize()
21 self.db = ReAction.db:RegisterNamespace( moduleID,
22 {
23 profile = {
24 closeOnLaunch = true,
25 editorCloseOnLaunch = true,
26 }
27 }
28 )
29
17 ReAction.RegisterCallback(self,"OnOptionsRegistered") 30 ReAction.RegisterCallback(self,"OnOptionsRegistered")
18 ReAction.RegisterCallback(self,"OnOptionsRefreshed") 31 ReAction.RegisterCallback(self,"OnOptionsRefreshed")
32 ReAction.RegisterCallback(self,"OnCreateBar")
33 ReAction.RegisterCallback(self,"OnEraseBar")
34 ReAction.RegisterCallback(self,"OnRenameBar")
19 self:InitializeOptions() 35 self:InitializeOptions()
36 self:RegisterEvent("PLAYER_REGEN_DISABLED")
20 end 37 end
21 38
22 function module:OnOptionsRegistered(evt, context, module, opts) 39 function module:OnOptionsRegistered(evt, context, module, opts)
23 local c = self.configOptions.args[context] 40 local c = self.configOptions.args[context]
24 if c then 41 if c then
25 for k, v in pairs(opts) do 42 for k, v in pairs(opts) do
26 c.args[k] = v 43 c.args[k] = v
27 end 44 end
45 elseif c == "bar" then
46
28 end 47 end
29 end 48 end
30 49
31 function module:OnOptionsRefreshed(evt) 50 function module:OnOptionsRefreshed(evt)
32 -- TODO: refresh options frame (just OpenConfig again?) 51 -- TODO: refresh options frame (just OpenConfig again?)
33 end 52 end
34 53
35 function module:OpenConfig(bar) 54 function module:OnCreateBar(evt, bar)
36 InterfaceOptionsFrame_OpenToFrame("ReAction") 55 local name = bar:GetName()
37 if bar then 56 -- AceConfig doesn't allow spaces, etc, in arg key names, and they must be
38 -- TODO: select the correct bar pane 57 -- unique strings. So generate a unique key (it can be whatever) for the bar
39 end 58 local key
40 end 59 local i = 1
41 60 repeat
42 function module:InitializeOptions() 61 key = ("bar%s"):format(i)
43 self.configOptions = { 62 i = i+1
63 until self.layoutOpts.args[key] == nil
64 self.barOptMap[name] = key
65 self.layoutOpts.args[key] = {
44 type = "group", 66 type = "group",
67 name = name,
45 childGroups = "tab", 68 childGroups = "tab",
46 args = { 69 args = {
70 general = {
71 type = "group",
72 name = L["General"],
73 args = {
74 name = {
75 type = "input",
76 name = L["Rename Bar"],
77 get = function() return bar:GetName() end,
78 set = function(info, value) return ReAction:RenameBar(bar, value) end,
79 order = 1,
80 },
81 delete = {
82 type = "execute",
83 name = L["Delete Bar"],
84 desc = function() return bar:GetName() end,
85 confirm = true,
86 func = function() ReAction:EraseBar(bar) end,
87 order = -1
88 },
89
90 }
91 },
92 },
93
94 }
95 end
96
97 function module:OnEraseBar(evt, name)
98 local key = self.barOptMap[name]
99 self.barOptMap[name] = nil
100 if key then
101 self.layoutOpts.args[key] = nil
102 self:RefreshLayoutEditor()
103 end
104 end
105
106 function module:OnRenameBar(evt, oldname, newname)
107 local key = self.barOptMap[oldname]
108 self.barOptMap[oldname], self.barOptMap[newname] = nil, key
109 if key then
110 self.layoutOpts.args[key].name = newname
111 self:RefreshLayoutEditor()
112 end
113 end
114
115 function module:PLAYER_REGEN_DISABLED()
116 if self.editor then
117 self.editor:Hide()
118 end
119 end
120
121 function module:UserError(msg)
122 -- any user errors should be flashed to the UIErrorsFrame
123 UIErrorsFrame:AddMessage(msg)
124 end
125
126 function module:OpenConfig()
127 InterfaceOptionsFrame_OpenToFrame("ReAction")
128 end
129
130 function module:LaunchLayoutEditor(bar)
131 if InCombatLockdown() then
132 self:UserError(L["ReAction config mode disabled during combat."])
133 else
134 if not self.editor then
135 -- use a local container to work around AceConfigDialog closing
136 -- both the layout editor and the global options when interface options is closed
137 local ed = LibStub("AceGUI-3.0"):Create("Frame")
138 ed.frame:SetClampedToScreen(true)
139 local old_OnUpdate = ed.frame:GetScript("OnUpdate")
140 ed.frame:SetScript("OnUpdate", function(dt)
141 if old_OnUpdate then
142 old_OnUpdate(dt)
143 end
144 if ed.closePending then
145 InterfaceOptionsFrame:Hide()
146 ed.closePending = false
147 end
148 if ed.selfClosePending then
149 ed:Hide()
150 AceConfigReg:NotifyChange("ReAction")
151 ed.selfClosePending = false
152 end
153 end )
154 ed:SetCallback("OnClose",
155 function()
156 ReAction:SetConfigMode(false)
157 end )
158 self.editor = ed
159 AceConfigDialog:SetDefaultSize("ReAction-Layout", 600, 450)
160 end
161
162 AceConfigDialog:Open("ReAction-Layout", self.editor)
163 ReAction:SetConfigMode(true)
164 end
165 end
166
167 function module:RefreshLayoutEditor()
168 AceConfigReg:NotifyChange("ReAction-Layout")
169 if self.editor and self.editor.frame:IsShown() then
170 AceConfigDialog:Open("ReAction-Layout", self.editor)
171 end
172 end
173
174 function module:GetBarTypes()
175 local opts = self.optBarTypes or { }
176 self.optBarTypes = opts
177
178 -- TODO: get these from module registration somehow
179 opts[1] = "foo"
180
181 return opts
182 end
183
184 function module:CreateBar()
185 local name = self.tmpBarName
186 local type = self.tmpBarType
187
188 self.tmpBarName = nil
189 self.tmpBarType = nil
190
191 -- TODO: get from module registration
192 -- TODO: use rows/cols info
193 ReAction:CreateBar(name)
194 end
195
196 function module:InitializeOptions()
197 -- general config options
198 local opts = {
199 type = "group",
200 name = "ReAction",
201 childGroups = "tab",
202 args = {
203 _desc = {
204 type = "description",
205 name = L["Customizable replacement for Blizzard's Action Bars"],
206 order = 1,
207 },
208 _launchLayout = {
209 type = "execute",
210 handler = self,
211 name = L["Layout Editor..."],
212 desc = L["Show the ReAction Layout Editor to edit your bars"],
213 func = function()
214 self:LaunchLayoutEditor()
215 -- you can't close a dialog in response to an options click, because the end of the
216 -- handler for all the button events calls lib:Open()
217 -- So, schedule a close on the next OnUpdate
218 if self.db.profile.closeOnLaunch then
219 self.editor.closePending = true
220 end
221 end,
222 order = 2,
223 },
224 _closeThis = {
225 type = "toggle",
226 name = L["Close on Launch"],
227 desc = L["Close the Interface Options window when launching the ReAction Layout Editor"],
228 get = function() return self.db.profile.closeOnLaunch end,
229 set = function(info, val) self.db.profile.closeOnLaunch = val end,
230 order = 3,
231 },
47 global = { 232 global = {
48 type = "group", 233 type = "group",
49 name = L["Global Settings"], 234 name = L["Global Settings"],
50 desc = L["Global configuration settings"], 235 desc = L["Global configuration settings"],
51 args = { }, 236 args = { },
52 order = 1, 237 order = 3,
53 }, 238 },
54 bar = { 239 _profile = LibStub("AceDBOptions-3.0"):GetOptionsTable(ReAction.db),
55 type = "group",
56 name = L["Bar Config"],
57 desc = L["Configuration settings for bars"],
58 args = { },
59 order = 2,
60 },
61 module = { 240 module = {
62 type = "group", 241 type = "group",
63 childGroups = "select", 242 childGroups = "select",
64 name = L["Module Settings"], 243 name = L["Module Settings"],
65 desc = L["Configuration settings for each module"], 244 desc = L["Configuration settings for each module"],
67 order = -1, 246 order = -1,
68 }, 247 },
69 }, 248 },
70 plugins = { } 249 plugins = { }
71 } 250 }
72 251 self.configOptions = opts
73 for c, tbl in pairs(self.configOptions.args) do 252 opts.args._profile.order = -2
253 AceConfigReg:RegisterOptionsTable("ReAction",opts)
254 self.frame = AceConfigDialog:AddToBlizOptions("ReAction", "ReAction")
255 self.frame.obj:SetCallback("default",
256 function()
257 ReAction.db:ResetProfile()
258 module:OpenConfig()
259 end )
260
261 -- import options from registered modules
262 for c, tbl in pairs(opts.args) do
74 for _, m in pairs(ReAction:GetOptions(c)) do 263 for _, m in pairs(ReAction:GetOptions(c)) do
75 for k, v in pairs(m) do 264 for k, v in pairs(m) do
76 tbl.args[k] = v 265 tbl.args[k] = v
77 end 266 end
78 end 267 end
79 end 268 end
80
81 self.configOptions.args.desc = {
82 type = "description",
83 name = L["Customizable replacement for Blizzard's Action Bars"],
84 }
85 self.configOptions.args.profile = LibStub("AceDBOptions-3.0"):GetOptionsTable(ReAction.db)
86 self.configOptions.args.profile.order = -2
87 269
88 ReAction:RegisterOptions("module",self, { 270 ReAction:RegisterOptions("module",self, {
89 configUI = { 271 configUI = {
90 type = "group", 272 type = "group",
91 name = "Config UI", 273 name = "Config UI",
101 } 283 }
102 } 284 }
103 }, 285 },
104 }) 286 })
105 287
106 LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable("ReAction",self.configOptions) 288 -- layout editor options
107 self.frame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("ReAction", "ReAction") 289 local layoutOpts = {
108 self.frame.obj:SetCallback("default", function() ReAction.db:ResetProfile() end) 290 type = "group",
109 end 291 name = ("ReAction - %s"):format(L["Layout"]),
110 292 handler = self,
293 childGroups = "tree",
294 args = {
295 desc = {
296 type = "description",
297 name = L["Use the mouse to arrange and resize the bars on screen. Tooltips on bars indicate additional functionality."],
298 order = 1
299 },
300 launchConfig = {
301 type = "execute",
302 name = L["Global Config"],
303 desc = L["Opens ReAction global configuration settings panel"],
304 func = function()
305 self:OpenConfig()
306 -- you can't close a dialog in response to an options click, because the end of the
307 -- handler for all the button events calls lib:Open()
308 -- So, schedule a close on the next appropriate event
309 if self.db.profile.editorCloseOnLaunch then
310 self.editor.selfClosePending = true
311 end
312 end,
313 order = 2
314 },
315 closThis = {
316 type = "toggle",
317 name = L["Close on Launch"],
318 desc = L["Close the Layout Editor when opening the ReAction global Interface Options"],
319 get = function() return self.db.profile.editorCloseOnLaunch end,
320 set = function(info, val) self.db.profile.editorCloseOnLaunch = val end,
321 order = 3,
322 },
323 new = {
324 type = "group",
325 name = L["New Bar..."],
326 order = 4,
327 args = {
328 desc = {
329 type = "description",
330 name = L["Choose a name, type, and initial grid for your new action bar:"],
331 order = 1,
332 },
333 name = {
334 type = "input",
335 name = L["Bar Name"],
336 desc = L["Enter a name for your new action bar"],
337 get = function() return self.tmpBarName or "" end,
338 set = function(info, val) self.tmpBarName = val end,
339 order = 2,
340 },
341 type = {
342 type = "select",
343 name = L["Button Type"],
344 get = function() return self.tmpBarType or "" end,
345 set = function(info, val) self.tmpBarType = val end,
346 values = "GetBarTypes",
347 order = 3,
348 },
349 grid = {
350 type = "group",
351 name = L["Button Grid"],
352 inline = true,
353 args = {
354 hdr = {
355 type = "header",
356 name = L["Button Grid"],
357 order = 1,
358 },
359 rows = {
360 type = "range",
361 name = L["Rows"],
362 get = function() return self.tmpBarRows or 1 end,
363 set = function(info, val) self.tmpBarRows = val end,
364 width = "half",
365 min = 1,
366 max = 32,
367 step = 1,
368 order = 2,
369 },
370 cols = {
371 type = "range",
372 name = L["Columns"],
373 get = function() return self.tmpBarCols or 12 end,
374 set = function(info, val) self.tmpBarCols = val end,
375 width = "half",
376 min = 1,
377 max = 32,
378 step = 1,
379 order = 3,
380 },
381 sz = {
382 type = "range",
383 name = L["Size"],
384 get = function() return self.tmpBarSize or 36 end,
385 set = function(info, val) self.tmpBarSize = val end,
386 width = "half",
387 min = 10,
388 max = 72,
389 step = 1,
390 order = 4,
391 },
392 spacing = {
393 type = "range",
394 name = L["Spacing"],
395 get = function() return self.tmpBarSpacing or 3 end,
396 set = function(info, val) self.tmpBarSpacing = val end,
397 width = "half",
398 min = 0,
399 max = 24,
400 step = 1,
401 order = 5,
402 }
403 },
404 order = 4
405 },
406 spacer = {
407 type = "header",
408 name = "",
409 width = "full",
410 order = -2
411 },
412 go = {
413 type = "execute",
414 name = L["Create Bar"],
415 func = "CreateBar",
416 order = -1,
417 }
418 }
419 }
420 }
421 }
422 self.layoutOpts = layoutOpts
423 self.barOptMap = { }
424 AceConfigReg:RegisterOptionsTable("ReAction-Layout",layoutOpts)
425 end
426