annotate ReAction.lua @ 175:df68b5a40490

Remove ReAction global in favor of built in addon table (drycoded)
author Flick <flickerstreak@gmail.com>
date Wed, 20 Oct 2010 17:11:50 +0000
parents 8cc187143acd
children 55c2fc0c8d55
rev   line source
flickerstreak@63 1 --[[
flickerstreak@63 2 ReAction.lua
flickerstreak@63 3
flickerstreak@63 4 The ReAction core manages 4 collections:
flickerstreak@63 5 - modules (via AceAddon)
flickerstreak@63 6 - bars
flickerstreak@63 7 - options
flickerstreak@63 8 - bar-type constructors
flickerstreak@63 9
flickerstreak@90 10 and publishes events when those collections change. It also implements a couple properties
flickerstreak@63 11 and has a couple convenience methods which drill down to particular modules.
flickerstreak@63 12
flickerstreak@90 13 Most of the "real work" of the addon happens in Bar.lua, Overlay.lua, State.lua, and the various modules.
flickerstreak@63 14
flickerstreak@63 15 Events (with handler arguments):
flickerstreak@63 16 --------------------------------
flickerstreak@63 17 "OnCreateBar" (bar, name) : after a bar object is created
flickerstreak@63 18 "OnDestroyBar" (bar, name) : before a bar object is destroyed
flickerstreak@63 19 "OnEraseBar" (bar, name) : before a bar config is removed from the profile db
flickerstreak@63 20 "OnRenameBar" (bar, oldname, newname) : after a bar is renamed
flickerstreak@63 21 "OnRefreshBar" (bar, name) : after a bar's state has been updated
flickerstreak@63 22 "OnOptionsRefreshed" () : after the global options tree is refreshed
flickerstreak@63 23 "OnConfigModeChanged" (mode) : after the config mode is changed
flickerstreak@63 24 "OnBarOptionGeneratorRegistered" (module, function) : after an options generator function is registered
flickerstreak@63 25
flickerstreak@63 26 ReAction is also an AceAddon-3.0 and contains an AceDB-3.0, which in turn publish more events.
flickerstreak@63 27 ]]--
flickerstreak@63 28 local version = GetAddOnMetadata("ReAction","Version")
flickerstreak@27 29
flickerstreak@27 30 ------ CORE ------
flickerstreak@30 31 local ReAction = LibStub("AceAddon-3.0"):NewAddon( "ReAction",
flickerstreak@33 32 "AceConsole-3.0",
flickerstreak@33 33 "AceEvent-3.0"
flickerstreak@30 34 )
flickerstreak@27 35
flickerstreak@175 36 -- export to other files in this addon (even if it's a compilation)
flickerstreak@175 37 local addonName, addonTable = ...
flickerstreak@175 38 local version = GetAddOnMetadata("ReAction","Version")
flickerstreak@175 39 addonTable.ReAction = ReAction
flickerstreak@27 40
flickerstreak@28 41 ------ DEBUGGING ------
flickerstreak@25 42 ReAction.debug = true
flickerstreak@36 43 local dbprint
flickerstreak@25 44 if ReAction.debug then
flickerstreak@36 45 dbprint = function(msg)
flickerstreak@25 46 DEFAULT_CHAT_FRAME:AddMessage(msg)
flickerstreak@25 47 end
flickerstreak@25 48 else
flickerstreak@36 49 dbprint = function() end
flickerstreak@25 50 end
flickerstreak@36 51 ReAction.dbprint = dbprint
flickerstreak@25 52
flickerstreak@33 53 ------ LIBRARIES ------
flickerstreak@63 54 local callbacks = LibStub("CallbackHandler-1.0"):New(ReAction)
flickerstreak@88 55 local KB = LibStub("LibKeyBound-1.0")
flickerstreak@33 56 local L = LibStub("AceLocale-3.0"):GetLocale("ReAction")
flickerstreak@33 57 ReAction.L = L
flickerstreak@33 58
flickerstreak@28 59 ------ PRIVATE ------
flickerstreak@88 60 local weak = {__mode="k"}
flickerstreak@116 61 local private = { }
flickerstreak@63 62 local bars = {}
flickerstreak@63 63 local defaultBarConfig = {}
flickerstreak@63 64 local barOptionGenerators = { }
flickerstreak@63 65 local options = {
flickerstreak@63 66 type = "group",
flickerstreak@63 67 name = "ReAction",
flickerstreak@63 68 childGroups = "tab",
flickerstreak@63 69 args = {
flickerstreak@63 70 _desc = {
flickerstreak@63 71 type = "description",
flickerstreak@63 72 name = L["Customizable replacement for Blizzard's Action Bars"],
flickerstreak@63 73 order = 1,
flickerstreak@63 74 },
flickerstreak@63 75 global = {
flickerstreak@63 76 type = "group",
flickerstreak@63 77 name = L["Global Settings"],
flickerstreak@63 78 desc = L["Global configuration settings"],
flickerstreak@63 79 args = {
flickerstreak@63 80 unlock = {
flickerstreak@63 81 type = "toggle",
flickerstreak@63 82 name = L["Unlock Bars"],
flickerstreak@63 83 desc = L["Unlock bars for dragging and resizing with the mouse"],
flickerstreak@63 84 handler = ReAction,
flickerstreak@63 85 get = "GetConfigMode",
flickerstreak@63 86 set = function(info, value) ReAction:SetConfigMode(value) end,
flickerstreak@116 87 width = "double",
flickerstreak@63 88 disabled = InCombatLockdown,
flickerstreak@63 89 order = 1
flickerstreak@63 90 },
flickerstreak@116 91 skipProfileWarning = {
flickerstreak@116 92 type = "toggle",
flickerstreak@116 93 name = L["Skip profile keybind warning"],
flickerstreak@116 94 desc = L["Don't show a warning about updating keybinds when switching profiles"],
flickerstreak@116 95 get = function() return ReAction.db.global.skipKeybindWarning end,
flickerstreak@116 96 set = function(info, value) ReAction.db.global.skipKeybindWarning = value end,
flickerstreak@116 97 width = "double",
flickerstreak@116 98 order = 2,
flickerstreak@116 99 },
flickerstreak@63 100 },
flickerstreak@63 101 plugins = { },
flickerstreak@63 102 order = 2,
flickerstreak@63 103 },
flickerstreak@63 104 module = {
flickerstreak@63 105 type = "group",
flickerstreak@63 106 childGroups = "select",
flickerstreak@63 107 name = L["Module Settings"],
flickerstreak@63 108 desc = L["Configuration settings for each module"],
flickerstreak@63 109 args = { },
flickerstreak@63 110 plugins = { },
flickerstreak@63 111 order = 3,
flickerstreak@63 112 },
flickerstreak@63 113 },
flickerstreak@63 114 plugins = { }
flickerstreak@63 115 }
flickerstreak@63 116 ReAction.options = options
flickerstreak@63 117
flickerstreak@116 118 -- insert an entry into the WoW static popup dialogs list
flickerstreak@116 119 StaticPopupDialogs["REACTION_KB_WARN"] = {
flickerstreak@116 120 text = L["ReAction profile changed: check your keybinds, they may need to be updated."],
flickerstreak@116 121 button1 = L["OK"],
flickerstreak@116 122 hideOnEscape = true,
flickerstreak@116 123 enterClicksFirstButton = true,
flickerstreak@116 124 timeout = 0,
flickerstreak@116 125 showAlert = true,
flickerstreak@116 126 whileDead = true,
flickerstreak@116 127 }
flickerstreak@116 128
flickerstreak@116 129 local SelectBar, DestroyBar, InitializeBars, TearDownBars, DeepCopy, CallModuleMethod, SlashHandler
flickerstreak@28 130 do
flickerstreak@28 131 local pcall = pcall
flickerstreak@28 132 local geterrorhandler = geterrorhandler
flickerstreak@63 133 local self = ReAction
flickerstreak@63 134 local inited = false
flickerstreak@28 135
flickerstreak@63 136 function SelectBar(x)
flickerstreak@28 137 local bar, name
flickerstreak@28 138 if type(x) == "string" then
flickerstreak@28 139 name = x
flickerstreak@63 140 bar = self:GetBar(name)
flickerstreak@50 141 else
flickerstreak@63 142 for k,v in pairs(bars) do
flickerstreak@50 143 if v == x then
flickerstreak@28 144 name = k
flickerstreak@50 145 bar = x
flickerstreak@28 146 end
flickerstreak@28 147 end
flickerstreak@28 148 end
flickerstreak@28 149 return bar, name
flickerstreak@28 150 end
flickerstreak@28 151
flickerstreak@63 152 function DestroyBar(x)
flickerstreak@28 153 local bar, name = SelectBar(x)
flickerstreak@63 154 if bar and name then
flickerstreak@63 155 bars[name] = nil
flickerstreak@63 156 callbacks:Fire("OnDestroyBar", bar, name)
flickerstreak@28 157 bar:Destroy()
flickerstreak@28 158 end
flickerstreak@28 159 end
flickerstreak@28 160
flickerstreak@63 161 function InitializeBars()
flickerstreak@63 162 if not inited then
flickerstreak@63 163 for name, config in pairs(self.db.profile.bars) do
flickerstreak@28 164 if config then
flickerstreak@63 165 self:CreateBar(name, config)
flickerstreak@28 166 end
flickerstreak@28 167 end
flickerstreak@101 168 -- re-anchor and refresh in case anchor order does not match init order
flickerstreak@63 169 for name, bar in pairs(bars) do
flickerstreak@63 170 bar:ApplyAnchor()
flickerstreak@101 171 callbacks:Fire("OnRefreshBar", bar, name)
flickerstreak@63 172 end
flickerstreak@63 173 inited = true
flickerstreak@28 174 end
flickerstreak@28 175 end
flickerstreak@28 176
flickerstreak@63 177 function TearDownBars()
flickerstreak@63 178 for name, bar in pairs(bars) do
flickerstreak@28 179 if bar then
flickerstreak@63 180 bars[name] = DestroyBar(bar)
flickerstreak@28 181 end
flickerstreak@28 182 end
flickerstreak@63 183 inited = false
flickerstreak@28 184 end
flickerstreak@28 185
flickerstreak@63 186 function DeepCopy(x)
flickerstreak@28 187 if type(x) ~= "table" then
flickerstreak@28 188 return x
flickerstreak@28 189 end
flickerstreak@28 190 local r = {}
flickerstreak@28 191 for k,v in pairs(x) do
flickerstreak@28 192 r[k] = DeepCopy(v)
flickerstreak@28 193 end
flickerstreak@28 194 return r
flickerstreak@28 195 end
flickerstreak@28 196
flickerstreak@63 197 function CallModuleMethod(modulename, method, ...)
flickerstreak@63 198 local m = self:GetModule(modulename,true)
flickerstreak@63 199 if m then
flickerstreak@63 200 if type(m) == "table" and type(m[method]) == "function" then
flickerstreak@63 201 m[method](m,...)
flickerstreak@63 202 else
flickerstreak@63 203 dbprint(("Bad call '%s' to %s module"):format(tostring(method),modulename));
flickerstreak@63 204 end
flickerstreak@63 205 else
flickerstreak@63 206 self:Print(("Module '%s' not found"):format(tostring(modulename)))
flickerstreak@63 207 end
flickerstreak@28 208 end
flickerstreak@28 209
flickerstreak@63 210 function SlashHandler(option)
flickerstreak@30 211 if option == "config" then
flickerstreak@63 212 self:ShowConfig()
flickerstreak@58 213 elseif option == "edit" then
flickerstreak@63 214 self:ShowEditor()
flickerstreak@50 215 elseif option == "unlock" then
flickerstreak@63 216 self:SetConfigMode(true)
flickerstreak@50 217 elseif option == "lock" then
flickerstreak@63 218 self:SetConfigMode(false)
flickerstreak@88 219 elseif option == "kb" then
flickerstreak@88 220 self:SetKeybindMode(true)
flickerstreak@30 221 else
flickerstreak@169 222 self:Print(("%3.1f"):format(version))
flickerstreak@63 223 self:Print("/rxn config")
flickerstreak@63 224 self:Print("/rxn edit")
flickerstreak@63 225 self:Print("/rxn lock")
flickerstreak@63 226 self:Print("/rxn unlock")
flickerstreak@88 227 self:Print("/rxn kb")
flickerstreak@30 228 end
flickerstreak@30 229 end
flickerstreak@92 230
flickerstreak@28 231 end
flickerstreak@28 232
flickerstreak@28 233
flickerstreak@28 234 ------ HANDLERS ------
flickerstreak@28 235 function ReAction:OnInitialize()
flickerstreak@28 236 self.db = LibStub("AceDB-3.0"):New("ReAction_DB",
flickerstreak@28 237 {
flickerstreak@28 238 profile = {
flickerstreak@28 239 bars = { },
flickerstreak@28 240 defaultBar = { }
flickerstreak@28 241 }
flickerstreak@111 242 },
flickerstreak@114 243 L["Default"]
flickerstreak@28 244 )
flickerstreak@28 245 self.db.RegisterCallback(self,"OnProfileChanged")
flickerstreak@95 246 self.db.RegisterCallback(self,"OnProfileReset", "OnProfileChanged")
flickerstreak@95 247 self.db.RegisterCallback(self,"OnProfileCopied","OnProfileChanged")
flickerstreak@63 248
flickerstreak@88 249 KB.RegisterCallback(self,"LIBKEYBOUND_ENABLED")
flickerstreak@88 250 KB.RegisterCallback(self,"LIBKEYBOUND_DISABLED")
flickerstreak@88 251
flickerstreak@63 252 options.args.profile = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db)
flickerstreak@63 253
flickerstreak@30 254 self:RegisterChatCommand("reaction", SlashHandler)
flickerstreak@30 255 self:RegisterChatCommand("rxn", SlashHandler)
flickerstreak@33 256 self:RegisterEvent("PLAYER_REGEN_DISABLED")
flickerstreak@28 257 end
flickerstreak@28 258
flickerstreak@28 259 function ReAction:OnEnable()
flickerstreak@28 260 InitializeBars()
flickerstreak@28 261 end
flickerstreak@28 262
flickerstreak@28 263 function ReAction:OnDisable()
flickerstreak@28 264 TearDownBars()
flickerstreak@28 265 end
flickerstreak@28 266
flickerstreak@28 267 function ReAction:OnProfileChanged()
flickerstreak@33 268 TearDownBars()
flickerstreak@33 269 InitializeBars()
flickerstreak@116 270 self:PopKeybindWarning()
flickerstreak@28 271 end
flickerstreak@28 272
flickerstreak@33 273 function ReAction:PLAYER_REGEN_DISABLED()
flickerstreak@63 274 if private.configMode == true then
flickerstreak@63 275 self:UserError(L["ReAction config mode disabled during combat."])
flickerstreak@33 276 self:SetConfigMode(false)
flickerstreak@88 277 self:SetKeybindMode(false)
flickerstreak@33 278 end
flickerstreak@33 279 end
flickerstreak@33 280
flickerstreak@88 281 function ReAction:LIBKEYBOUND_ENABLED( evt )
flickerstreak@88 282 self:SetKeybindMode(true)
flickerstreak@88 283 end
flickerstreak@88 284
flickerstreak@88 285 function ReAction:LIBKEYBOUND_DISABLED( evt )
flickerstreak@88 286 return self:SetKeybindMode(false)
flickerstreak@88 287 end
flickerstreak@88 288
flickerstreak@33 289
flickerstreak@28 290
flickerstreak@28 291 ------ API ------
flickerstreak@77 292
flickerstreak@61 293 function ReAction:UserError(msg)
flickerstreak@61 294 -- any user errors should be flashed to the UIErrorsFrame
flickerstreak@61 295 UIErrorsFrame:AddMessage(msg)
flickerstreak@61 296 end
flickerstreak@61 297
flickerstreak@63 298 -- usage:
flickerstreak@91 299 -- (1) ReAction:CreateBar(name, [cfgTable])
flickerstreak@63 300 -- (2) ReAction:CreateBar(name, "barType", [nRows], [nCols], [btnSize], [btnSpacing])
flickerstreak@91 301 function ReAction:CreateBar(name, config, ...)
flickerstreak@91 302 local profile = self.db.profile
flickerstreak@91 303
flickerstreak@127 304 if name then
flickerstreak@127 305 if bars[name] then
flickerstreak@127 306 self:UserError(format(L["ReAction: name '%s' already in use"],name))
flickerstreak@127 307 return nil
flickerstreak@127 308 end
flickerstreak@127 309 else
flickerstreak@91 310 local prefix = L["Bar "]
flickerstreak@91 311 local i = 1
flickerstreak@91 312 repeat
flickerstreak@91 313 name = prefix..i
flickerstreak@91 314 i = i + 1
flickerstreak@91 315 until bars[name] == nil
flickerstreak@91 316 end
flickerstreak@91 317
flickerstreak@91 318 if type(config) == "string" then
flickerstreak@91 319 config = defaultBarConfig[config]
flickerstreak@48 320 if not config then
flickerstreak@91 321 error(("ReAction:CreateBar() - unknown bar type '%s'"):format(tostring(select(1,...))))
flickerstreak@48 322 end
flickerstreak@48 323 config = DeepCopy(config)
flickerstreak@91 324 config.btnRows = select(1,...) or config.btnRows or 1
flickerstreak@91 325 config.btnColumns = select(2,...) or config.btnColumns or 12
flickerstreak@91 326 config.btnWidth = select(3,...) or config.btnWidth or 36
flickerstreak@91 327 config.btnHeight = select(3,...) or config.btnHeight or 36
flickerstreak@91 328 config.spacing = select(4,...) or config.spacing or 3
flickerstreak@48 329 config.width = config.width or config.btnColumns*(config.btnWidth + config.spacing) + 1
flickerstreak@48 330 config.height = config.height or config.btnRows*(config.btnHeight + config.spacing) + 1
flickerstreak@81 331 config.anchor = config.anchor or "UIParent"
flickerstreak@81 332 config.point = config.point or "BOTTOM"
flickerstreak@81 333 config.relpoint = config.relpoint or "BOTTOM"
flickerstreak@48 334 config.y = config.y or 200
flickerstreak@48 335 config.x = config.x or 0
flickerstreak@48 336 end
flickerstreak@91 337 config = config or profile.bars[name] or DeepCopy(profile.defaultBar)
flickerstreak@91 338
flickerstreak@91 339 profile.bars[name] = config
flickerstreak@91 340 local bar = self.Bar:New( name, config ) -- ReAction.Bar defined in Bar.lua
flickerstreak@63 341 bars[name] = bar
flickerstreak@63 342 callbacks:Fire("OnCreateBar", bar, name)
flickerstreak@63 343 if private.configMode then
flickerstreak@33 344 bar:ShowControls(true)
flickerstreak@33 345 end
flickerstreak@33 346
flickerstreak@28 347 return bar
flickerstreak@28 348 end
flickerstreak@28 349
flickerstreak@28 350 function ReAction:EraseBar(x)
flickerstreak@28 351 local bar, name = SelectBar(x)
flickerstreak@63 352 if bar and name then
flickerstreak@63 353 callbacks:Fire("OnEraseBar", bar, name)
flickerstreak@28 354 DestroyBar(bar)
flickerstreak@28 355 self.db.profile.bars[name] = nil
flickerstreak@28 356 end
flickerstreak@28 357 end
flickerstreak@28 358
flickerstreak@28 359 function ReAction:GetBar(name)
flickerstreak@63 360 return bars[name]
flickerstreak@63 361 end
flickerstreak@63 362
flickerstreak@90 363 -- returns pairs of name, bar
flickerstreak@63 364 function ReAction:IterateBars()
flickerstreak@63 365 return pairs(bars)
flickerstreak@28 366 end
flickerstreak@28 367
flickerstreak@28 368 function ReAction:RenameBar(x, newname)
flickerstreak@28 369 local bar, name = SelectBar(x)
flickerstreak@63 370 if type(newname) ~= "string" then
flickerstreak@63 371 error("ReAction:RenameBar() - second argument must be a string")
flickerstreak@63 372 end
flickerstreak@63 373 if bar and name and #newname > 0 then
flickerstreak@127 374 if newname == name then
flickerstreak@127 375 return
flickerstreak@127 376 end
flickerstreak@63 377 if bars[newname] then
flickerstreak@127 378 self:UserError(format(L["ReAction: name '%s' already in use"],newname))
flickerstreak@47 379 else
flickerstreak@63 380 bars[newname], bars[name] = bars[name], nil
flickerstreak@47 381 bar:SetName(newname or "")
flickerstreak@47 382 local cfg = self.db.profile.bars
flickerstreak@47 383 cfg[newname], cfg[name] = cfg[name], nil
flickerstreak@63 384 callbacks:Fire("OnRenameBar", bar, name, newname)
flickerstreak@28 385 end
flickerstreak@28 386 end
flickerstreak@28 387 end
flickerstreak@28 388
flickerstreak@63 389 function ReAction:RefreshBar(x)
flickerstreak@63 390 local bar, name = SelectBar(x)
flickerstreak@63 391 if bar and name then
flickerstreak@63 392 callbacks:Fire("OnRefreshBar", bar, name)
flickerstreak@63 393 end
flickerstreak@63 394 end
flickerstreak@63 395
flickerstreak@53 396 function ReAction:RegisterBarType( name, config, isDefaultChoice )
flickerstreak@63 397 defaultBarConfig[name] = config
flickerstreak@48 398 if isDefaultChoice then
flickerstreak@81 399 private.defaultBarConfigChoice = name
flickerstreak@48 400 end
flickerstreak@48 401 self:RefreshOptions()
flickerstreak@48 402 end
flickerstreak@48 403
flickerstreak@53 404 function ReAction:UnregisterBarType( name )
flickerstreak@63 405 defaultBarConfig[name] = nil
flickerstreak@63 406 if private.defaultBarConfigChoice == name then
flickerstreak@63 407 private.defaultBarConfigChoice = nil
flickerstreak@48 408 end
flickerstreak@48 409 self:RefreshOptions()
flickerstreak@48 410 end
flickerstreak@48 411
flickerstreak@63 412 function ReAction:IterateBarTypes()
flickerstreak@63 413 return pairs(defaultBarConfig)
flickerstreak@63 414 end
flickerstreak@63 415
flickerstreak@63 416 function ReAction:GetBarTypeConfig(name)
flickerstreak@63 417 if name then
flickerstreak@63 418 return defaultBarConfig[name]
flickerstreak@63 419 end
flickerstreak@63 420 end
flickerstreak@63 421
flickerstreak@63 422 function ReAction:GetBarTypeOptions( fill )
flickerstreak@63 423 fill = fill or { }
flickerstreak@63 424 for k in self:IterateBarTypes() do
flickerstreak@63 425 fill[k] = k
flickerstreak@63 426 end
flickerstreak@63 427 return fill
flickerstreak@63 428 end
flickerstreak@63 429
flickerstreak@63 430 function ReAction:GetDefaultBarType()
flickerstreak@63 431 return private.defaultBarConfigChoice
flickerstreak@63 432 end
flickerstreak@63 433
flickerstreak@63 434 function ReAction:RegisterOptions(module, opts, global)
flickerstreak@63 435 options.args[global and "global" or "module"].plugins[module:GetName()] = opts
flickerstreak@63 436 self:RefreshOptions()
flickerstreak@30 437 end
flickerstreak@30 438
flickerstreak@30 439 function ReAction:RefreshOptions()
flickerstreak@63 440 callbacks:Fire("OnOptionsRefreshed")
flickerstreak@63 441 end
flickerstreak@63 442
flickerstreak@63 443 --
flickerstreak@63 444 -- In addition to global and general module options, options tables
flickerstreak@63 445 -- must be generated dynamically for each bar.
flickerstreak@63 446 --
flickerstreak@63 447 -- 'func' should be a function or a method string.
flickerstreak@63 448 -- The function or method will be passed the bar as its parameter.
flickerstreak@63 449 -- (methods will of course get the module as the first 'self' parameter)
flickerstreak@63 450 --
flickerstreak@63 451 -- A generator can be unregistered by passing a nil func.
flickerstreak@63 452 --
flickerstreak@63 453 function ReAction:RegisterBarOptionGenerator( module, func )
flickerstreak@63 454 if not module or type(module) ~= "table" then -- doesn't need to be a proper module, strictly
flickerstreak@63 455 error("ReAction:RegisterBarOptionGenerator() : Invalid module")
flickerstreak@63 456 end
flickerstreak@63 457 if type(func) == "string" then
flickerstreak@63 458 if not module[func] then
flickerstreak@63 459 error(("ReAction:RegisterBarOptionGenerator() : Invalid method '%s'"):format(func))
flickerstreak@63 460 end
flickerstreak@63 461 elseif func and type(func) ~= "function" then
flickerstreak@63 462 error("ReAction:RegisterBarOptionGenerator() : Invalid function")
flickerstreak@63 463 end
flickerstreak@63 464 barOptionGenerators[module] = func
flickerstreak@63 465 callbacks:Fire("OnBarOptionGeneratorRegistered", module, func)
flickerstreak@63 466 end
flickerstreak@63 467
flickerstreak@63 468 -- builds a table suitable for use as an AceConfig3 group 'plugins' sub-table
flickerstreak@63 469 function ReAction:GenerateBarOptionsTable( bar )
flickerstreak@63 470 local opts = { }
flickerstreak@63 471 for module, func in pairs(barOptionGenerators) do
flickerstreak@63 472 local success, r
flickerstreak@63 473 if type(func) == "string" then
flickerstreak@63 474 success, r = pcall(module[func], module, bar)
flickerstreak@63 475 else
flickerstreak@63 476 success, r = pcall(func, bar)
flickerstreak@63 477 end
flickerstreak@63 478 if success then
flickerstreak@90 479 if r then
flickerstreak@90 480 opts[module:GetName()] = { [module:GetName()] = r }
flickerstreak@90 481 end
flickerstreak@63 482 else
flickerstreak@63 483 geterrorhandler()(r)
flickerstreak@63 484 end
flickerstreak@63 485 end
flickerstreak@63 486 return opts
flickerstreak@30 487 end
flickerstreak@33 488
flickerstreak@33 489 function ReAction:SetConfigMode( mode )
flickerstreak@77 490 if mode ~= private.configMode then
flickerstreak@77 491 private.configMode = mode
flickerstreak@77 492 callbacks:Fire("OnConfigModeChanged", mode)
flickerstreak@77 493 end
flickerstreak@63 494 end
flickerstreak@63 495
flickerstreak@63 496 function ReAction:GetConfigMode()
flickerstreak@63 497 return private.configMode
flickerstreak@33 498 end
flickerstreak@38 499
flickerstreak@38 500 function ReAction:ShowConfig()
flickerstreak@63 501 CallModuleMethod("ConfigUI","OpenConfig")
flickerstreak@38 502 end
flickerstreak@38 503
flickerstreak@81 504 function ReAction:ShowEditor(bar, ...)
flickerstreak@81 505 CallModuleMethod("ConfigUI","LaunchBarEditor",bar, ...)
flickerstreak@47 506 end
flickerstreak@88 507
flickerstreak@88 508 function ReAction:SetKeybindMode( mode )
flickerstreak@88 509 if mode ~= private.kbMode then
flickerstreak@88 510 if mode then
flickerstreak@88 511 KB:Activate()
flickerstreak@88 512 else
flickerstreak@88 513 KB:Deactivate()
flickerstreak@88 514 end
flickerstreak@88 515 private.kbMode = KB:IsShown() or false
flickerstreak@88 516 end
flickerstreak@88 517 end
flickerstreak@88 518
flickerstreak@88 519 function ReAction:GetKeybindMode( mode )
flickerstreak@88 520 return private.kbMode
flickerstreak@88 521 end
flickerstreak@88 522
flickerstreak@116 523 function ReAction:PopKeybindWarning()
flickerstreak@116 524 if not self.db.global.skipKeybindWarning then
flickerstreak@116 525 StaticPopup_Show("REACTION_KB_WARN")
flickerstreak@92 526 end
flickerstreak@88 527 end
flickerstreak@122 528
flickerstreak@122 529 -- Export ReAction launcher to LibDataBroker-aware displays
flickerstreak@122 530 LibStub:GetLibrary("LibDataBroker-1.1"):NewDataObject( "ReAction",
flickerstreak@122 531 {
flickerstreak@122 532 type = "launcher",
flickerstreak@122 533 icon = "Interface\\Icons\\INV_Qiraj_JewelEncased",
flickerstreak@122 534
flickerstreak@122 535 OnClick = function( frame, button )
flickerstreak@122 536 if not InCombatLockdown() then
flickerstreak@122 537 if IsAltKeyDown() then
flickerstreak@122 538 ReAction:SetKeybindMode( not ReAction:GetKeybindMode() )
flickerstreak@122 539 elseif IsShiftKeyDown() then
flickerstreak@122 540 ReAction:SetConfigMode( not ReAction:GetConfigMode() )
flickerstreak@122 541 elseif button == "RightButton" then
flickerstreak@122 542 ReAction:ShowEditor()
flickerstreak@122 543 else
flickerstreak@122 544 ReAction:ShowConfig()
flickerstreak@122 545 end
flickerstreak@122 546 else
flickerstreak@122 547 ReAction:UserError(L["ReAction: can't configure in combat"])
flickerstreak@122 548 end
flickerstreak@122 549 end,
flickerstreak@122 550
flickerstreak@122 551 -- this isn't included in the 'launcher' type LDB spec but it seems all launcher displays use it
flickerstreak@122 552 OnTooltipShow = function( tooltip )
flickerstreak@122 553 tooltip:AddLine(format("|cffffffff%s|r %s",L["Click"],L["for global configuration"]))
flickerstreak@122 554 tooltip:AddLine(format("|cffffd200%s|r %s",L["Right-click"],L["for bar editor dialog"]))
flickerstreak@122 555 tooltip:AddLine(format("|cff00ff00%s|r %s",L["Shift-click"],L["to unlock bars"]))
flickerstreak@122 556 tooltip:AddLine(format("|cff00cccc%s|r %s",L["Alt-click"],L["for keybind mode"]))
flickerstreak@122 557 end,
flickerstreak@122 558
flickerstreak@122 559 }
flickerstreak@122 560 )