annotate modules/ReAction_ConfigUI/ReAction_ConfigUI.lua @ 50:c3c64e2def50

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