comparison ReAction.lua @ 182:55c2fc0c8d55

Collect options in one file clean up ReAction.lua a bit remove AceConsole-3.0
author Flick <flickerstreak@gmail.com>
date Thu, 21 Oct 2010 22:07:11 +0000
parents df68b5a40490
children 1ee86bbb05a0
comparison
equal deleted inserted replaced
181:c8777ae7d460 182:55c2fc0c8d55
1 --[[ 1 --[[
2 ReAction.lua 2 ReAction.lua
3 3
4 The ReAction core manages 4 collections: 4 The ReAction core manages several collections:
5 - modules (via AceAddon) 5 - modules (via AceAddon)
6 - bars 6 - bars
7 - options 7 - bar options
8 - bar-type constructors 8 - bar-type constructors
9 9
10 and publishes events when those collections change. It also implements a couple properties 10 and publishes events when those collections change. It also implements a couple properties
11 and has a couple convenience methods which drill down to particular modules. 11 and has a couple convenience methods which drill down to particular modules.
12 12
23 "OnConfigModeChanged" (mode) : after the config mode is changed 23 "OnConfigModeChanged" (mode) : after the config mode is changed
24 "OnBarOptionGeneratorRegistered" (module, function) : after an options generator function is registered 24 "OnBarOptionGeneratorRegistered" (module, function) : after an options generator function is registered
25 25
26 ReAction is also an AceAddon-3.0 and contains an AceDB-3.0, which in turn publish more events. 26 ReAction is also an AceAddon-3.0 and contains an AceDB-3.0, which in turn publish more events.
27 ]]-- 27 ]]--
28 local version = GetAddOnMetadata("ReAction","Version") 28
29 29 local addonName, addonTable = ...
30 ------ CORE ------ 30 local version = GetAddOnMetadata(addonName,"Version")
31 local ReAction = LibStub("AceAddon-3.0"):NewAddon( "ReAction", 31 local ReAction = LibStub("AceAddon-3.0"):NewAddon( addonName,
32 "AceConsole-3.0",
33 "AceEvent-3.0" 32 "AceEvent-3.0"
34 ) 33 )
35
36 -- export to other files in this addon (even if it's a compilation)
37 local addonName, addonTable = ...
38 local version = GetAddOnMetadata("ReAction","Version")
39 addonTable.ReAction = ReAction 34 addonTable.ReAction = ReAction
40
41 ------ DEBUGGING ------
42 ReAction.debug = true
43 local dbprint
44 if ReAction.debug then
45 dbprint = function(msg)
46 DEFAULT_CHAT_FRAME:AddMessage(msg)
47 end
48 else
49 dbprint = function() end
50 end
51 ReAction.dbprint = dbprint
52 35
53 ------ LIBRARIES ------ 36 ------ LIBRARIES ------
54 local callbacks = LibStub("CallbackHandler-1.0"):New(ReAction) 37 local callbacks = LibStub("CallbackHandler-1.0"):New(ReAction)
55 local KB = LibStub("LibKeyBound-1.0") 38 local KB = LibStub("LibKeyBound-1.0")
56 local L = LibStub("AceLocale-3.0"):GetLocale("ReAction") 39 local L = LibStub("AceLocale-3.0"):GetLocale("ReAction")
57 ReAction.L = L 40 ReAction.L = L
41 ReAction.KB = KB
42 ReAction.callbacks = callbacks
58 43
59 ------ PRIVATE ------ 44 ------ PRIVATE ------
60 local weak = {__mode="k"}
61 local private = { } 45 local private = { }
62 local bars = {} 46 local bars = {}
63 local defaultBarConfig = {} 47 local defaultBarConfig = {}
64 local barOptionGenerators = { } 48 local barOptionGenerators = { }
65 local options = { 49
66 type = "group", 50
67 name = "ReAction", 51 local SelectBar, DestroyBar, InitializeBars, TearDownBars, DeepCopy, CallModuleMethod
68 childGroups = "tab",
69 args = {
70 _desc = {
71 type = "description",
72 name = L["Customizable replacement for Blizzard's Action Bars"],
73 order = 1,
74 },
75 global = {
76 type = "group",
77 name = L["Global Settings"],
78 desc = L["Global configuration settings"],
79 args = {
80 unlock = {
81 type = "toggle",
82 name = L["Unlock Bars"],
83 desc = L["Unlock bars for dragging and resizing with the mouse"],
84 handler = ReAction,
85 get = "GetConfigMode",
86 set = function(info, value) ReAction:SetConfigMode(value) end,
87 width = "double",
88 disabled = InCombatLockdown,
89 order = 1
90 },
91 skipProfileWarning = {
92 type = "toggle",
93 name = L["Skip profile keybind warning"],
94 desc = L["Don't show a warning about updating keybinds when switching profiles"],
95 get = function() return ReAction.db.global.skipKeybindWarning end,
96 set = function(info, value) ReAction.db.global.skipKeybindWarning = value end,
97 width = "double",
98 order = 2,
99 },
100 },
101 plugins = { },
102 order = 2,
103 },
104 module = {
105 type = "group",
106 childGroups = "select",
107 name = L["Module Settings"],
108 desc = L["Configuration settings for each module"],
109 args = { },
110 plugins = { },
111 order = 3,
112 },
113 },
114 plugins = { }
115 }
116 ReAction.options = options
117
118 -- insert an entry into the WoW static popup dialogs list
119 StaticPopupDialogs["REACTION_KB_WARN"] = {
120 text = L["ReAction profile changed: check your keybinds, they may need to be updated."],
121 button1 = L["OK"],
122 hideOnEscape = true,
123 enterClicksFirstButton = true,
124 timeout = 0,
125 showAlert = true,
126 whileDead = true,
127 }
128
129 local SelectBar, DestroyBar, InitializeBars, TearDownBars, DeepCopy, CallModuleMethod, SlashHandler
130 do 52 do
131 local pcall = pcall 53 local pcall = pcall
132 local geterrorhandler = geterrorhandler 54 local geterrorhandler = geterrorhandler
133 local self = ReAction 55 local self = ReAction
134 local inited = false 56 local inited = false
197 function CallModuleMethod(modulename, method, ...) 119 function CallModuleMethod(modulename, method, ...)
198 local m = self:GetModule(modulename,true) 120 local m = self:GetModule(modulename,true)
199 if m then 121 if m then
200 if type(m) == "table" and type(m[method]) == "function" then 122 if type(m) == "table" and type(m[method]) == "function" then
201 m[method](m,...) 123 m[method](m,...)
202 else 124 end
203 dbprint(("Bad call '%s' to %s module"):format(tostring(method),modulename));
204 end
205 else
206 self:Print(("Module '%s' not found"):format(tostring(modulename)))
207 end
208 end
209
210 function SlashHandler(option)
211 if option == "config" then
212 self:ShowConfig()
213 elseif option == "edit" then
214 self:ShowEditor()
215 elseif option == "unlock" then
216 self:SetConfigMode(true)
217 elseif option == "lock" then
218 self:SetConfigMode(false)
219 elseif option == "kb" then
220 self:SetKeybindMode(true)
221 else
222 self:Print(("%3.1f"):format(version))
223 self:Print("/rxn config")
224 self:Print("/rxn edit")
225 self:Print("/rxn lock")
226 self:Print("/rxn unlock")
227 self:Print("/rxn kb")
228 end 125 end
229 end 126 end
230 127
231 end 128 end
232 129
238 profile = { 135 profile = {
239 bars = { }, 136 bars = { },
240 defaultBar = { } 137 defaultBar = { }
241 } 138 }
242 }, 139 },
243 L["Default"] 140 true -- use global 'Default' (locale-specific)
244 ) 141 )
245 self.db.RegisterCallback(self,"OnProfileChanged")
246 self.db.RegisterCallback(self,"OnProfileReset", "OnProfileChanged")
247 self.db.RegisterCallback(self,"OnProfileCopied","OnProfileChanged")
248
249 KB.RegisterCallback(self,"LIBKEYBOUND_ENABLED") 142 KB.RegisterCallback(self,"LIBKEYBOUND_ENABLED")
250 KB.RegisterCallback(self,"LIBKEYBOUND_DISABLED") 143 KB.RegisterCallback(self,"LIBKEYBOUND_DISABLED")
251 144
252 options.args.profile = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db)
253
254 self:RegisterChatCommand("reaction", SlashHandler)
255 self:RegisterChatCommand("rxn", SlashHandler)
256 self:RegisterEvent("PLAYER_REGEN_DISABLED") 145 self:RegisterEvent("PLAYER_REGEN_DISABLED")
146
147 self:InitializeOptions()
257 end 148 end
258 149
259 function ReAction:OnEnable() 150 function ReAction:OnEnable()
260 InitializeBars() 151 InitializeBars()
261 end 152 end
262 153
263 function ReAction:OnDisable() 154 function ReAction:OnDisable()
264 TearDownBars() 155 TearDownBars()
265 end
266
267 function ReAction:OnProfileChanged()
268 TearDownBars()
269 InitializeBars()
270 self:PopKeybindWarning()
271 end 156 end
272 157
273 function ReAction:PLAYER_REGEN_DISABLED() 158 function ReAction:PLAYER_REGEN_DISABLED()
274 if private.configMode == true then 159 if private.configMode == true then
275 self:UserError(L["ReAction config mode disabled during combat."]) 160 self:UserError(L["ReAction config mode disabled during combat."])
429 314
430 function ReAction:GetDefaultBarType() 315 function ReAction:GetDefaultBarType()
431 return private.defaultBarConfigChoice 316 return private.defaultBarConfigChoice
432 end 317 end
433 318
434 function ReAction:RegisterOptions(module, opts, global)
435 options.args[global and "global" or "module"].plugins[module:GetName()] = opts
436 self:RefreshOptions()
437 end
438
439 function ReAction:RefreshOptions() 319 function ReAction:RefreshOptions()
440 callbacks:Fire("OnOptionsRefreshed") 320 callbacks:Fire("OnOptionsRefreshed")
441 end 321 end
442 322
443 -- 323 --
444 -- In addition to global and general module options, options tables 324 -- In addition to global options, options tables
445 -- must be generated dynamically for each bar. 325 -- must be generated dynamically for each bar.
446 -- 326 --
447 -- 'func' should be a function or a method string. 327 -- 'func' should be a function or a method string.
448 -- The function or method will be passed the bar as its parameter. 328 -- The function or method will be passed the bar as its parameter.
449 -- (methods will of course get the module as the first 'self' parameter) 329 -- (methods will of course get the module as the first 'self' parameter)
495 375
496 function ReAction:GetConfigMode() 376 function ReAction:GetConfigMode()
497 return private.configMode 377 return private.configMode
498 end 378 end
499 379
500 function ReAction:ShowConfig()
501 CallModuleMethod("ConfigUI","OpenConfig")
502 end
503
504 function ReAction:ShowEditor(bar, ...) 380 function ReAction:ShowEditor(bar, ...)
505 CallModuleMethod("ConfigUI","LaunchBarEditor",bar, ...) 381 CallModuleMethod("ConfigUI","LaunchBarEditor",bar, ...)
506 end 382 end
507 383
508 function ReAction:SetKeybindMode( mode ) 384 function ReAction:SetKeybindMode( mode )
517 end 393 end
518 394
519 function ReAction:GetKeybindMode( mode ) 395 function ReAction:GetKeybindMode( mode )
520 return private.kbMode 396 return private.kbMode
521 end 397 end
522
523 function ReAction:PopKeybindWarning()
524 if not self.db.global.skipKeybindWarning then
525 StaticPopup_Show("REACTION_KB_WARN")
526 end
527 end
528
529 -- Export ReAction launcher to LibDataBroker-aware displays
530 LibStub:GetLibrary("LibDataBroker-1.1"):NewDataObject( "ReAction",
531 {
532 type = "launcher",
533 icon = "Interface\\Icons\\INV_Qiraj_JewelEncased",
534
535 OnClick = function( frame, button )
536 if not InCombatLockdown() then
537 if IsAltKeyDown() then
538 ReAction:SetKeybindMode( not ReAction:GetKeybindMode() )
539 elseif IsShiftKeyDown() then
540 ReAction:SetConfigMode( not ReAction:GetConfigMode() )
541 elseif button == "RightButton" then
542 ReAction:ShowEditor()
543 else
544 ReAction:ShowConfig()
545 end
546 else
547 ReAction:UserError(L["ReAction: can't configure in combat"])
548 end
549 end,
550
551 -- this isn't included in the 'launcher' type LDB spec but it seems all launcher displays use it
552 OnTooltipShow = function( tooltip )
553 tooltip:AddLine(format("|cffffffff%s|r %s",L["Click"],L["for global configuration"]))
554 tooltip:AddLine(format("|cffffd200%s|r %s",L["Right-click"],L["for bar editor dialog"]))
555 tooltip:AddLine(format("|cff00ff00%s|r %s",L["Shift-click"],L["to unlock bars"]))
556 tooltip:AddLine(format("|cff00cccc%s|r %s",L["Alt-click"],L["for keybind mode"]))
557 end,
558
559 }
560 )