comparison ReAction.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
1 -- ReAction.lua 1 -- ReAction.lua
2 -- See modules/ReAction_ModuleTemplate for Module API listing 2 -- See modules/ReAction_ModuleTemplate for Module API listing
3 -- See Bar.lua for Bar object listing 3 -- See Bar.lua for Bar object listing
4 local MAJOR_VERSION = GetAddOnMetadata("ReAction","Version")
4 5
5 ------ LIBRARIES ------ 6 ------ LIBRARIES ------
6 local L = LibStub("AceLocale-3.0"):GetLocale("ReAction") 7 local L = LibStub("AceLocale-3.0"):GetLocale("ReAction")
7 8
8 ------ CORE ------ 9 ------ CORE ------
9 local ReAction = LibStub("AceAddon-3.0"):NewAddon( "ReAction" ) 10 local ReAction = LibStub("AceAddon-3.0"):NewAddon( "ReAction",
11 "AceConsole-3.0"
12 )
10 ReAction.revision = tonumber(("$Revision: 1 $"):match("%d+")) 13 ReAction.revision = tonumber(("$Revision: 1 $"):match("%d+"))
14 ReAction.version = MAJOR_VERSION
11 ReAction.L = L 15 ReAction.L = L
12 16
13 ------ GLOBALS ------ 17 ------ GLOBALS ------
14 _G["ReAction"] = ReAction 18 _G["ReAction"] = ReAction
15 19
23 else 27 else
24 ReAction.print = function() end 28 ReAction.print = function() end
25 end 29 end
26 30
27 ------ PRIVATE ------ 31 ------ PRIVATE ------
28 local SelectBar, DestroyBar, InitializeBars, TearDownBars, DeepCopy, SafeCall, CheckMethod 32 local SelectBar, DestroyBar, InitializeBars, TearDownBars, DeepCopy, SafeCall, CheckMethod, SlashHandler
29 do 33 do
30 local pcall = pcall 34 local pcall = pcall
31 local geterrorhandler = geterrorhandler 35 local geterrorhandler = geterrorhandler
32 36
33 SelectBar = function(x) 37 SelectBar = function(x)
102 if type(m) == "function" then 106 if type(m) == "function" then
103 return m 107 return m
104 end 108 end
105 if type(m) ~= "string" then 109 if type(m) ~= "string" then
106 error("Invalid method") 110 error("Invalid method")
111 end
112 end
113
114 local function CallOptsModule(method,...)
115 local m = ReAction:GetModule("ConfigUI",true)
116 if not m then
117 LoadAddOn("ReAction_ConfigUI")
118 m = ReAction:GetModule("ConfigUI")
119 end
120 if m and type(m) == "table" and type(m[method]) == "function" then
121 m[method](m,...)
122 else
123 ReAction:Print("Options module not found")
124 end
125 end
126
127 SlashHandler = function(option)
128 if option == "config" then
129 CallOptsModule("OpenConfig",true)
130 elseif option == "unlock" then
131 CallOptsModule("SetConfigMode",true)
132 elseif option == "lock" then
133 CallOptsModule("SetConfigMode",false)
134 else
135 ReAction:Print(ReAction.version)
136 ReAction:Print("/reaction config")
137 ReAction:Print("/reaction unlock")
138 ReAction:Print("/reaction lock")
107 end 139 end
108 end 140 end
109 end 141 end
110 142
111 143
119 } 151 }
120 } 152 }
121 -- default profile is character-specific 153 -- default profile is character-specific
122 ) 154 )
123 self.db.RegisterCallback(self,"OnProfileChanged") 155 self.db.RegisterCallback(self,"OnProfileChanged")
156 self.callbacks = LibStub("CallbackHandler-1.0"):New(self)
157 self:RegisterChatCommand("reaction", SlashHandler)
158 self:RegisterChatCommand("rxn", SlashHandler)
124 159
125 self.bars = {} 160 self.bars = {}
126 end 161 end
127 162
128 function ReAction:OnEnable() 163 function ReAction:OnEnable()
191 end 226 end
192 profile.bars[name] = profile.bars[name] or DeepCopy(defaultConfig) 227 profile.bars[name] = profile.bars[name] or DeepCopy(defaultConfig)
193 local bar = self.Bar:new( name, profile.bars[name] ) -- ReAction.Bar defined in Bar.lua 228 local bar = self.Bar:new( name, profile.bars[name] ) -- ReAction.Bar defined in Bar.lua
194 self:CallMethodOnAllModules("ApplyToBar", bar) 229 self:CallMethodOnAllModules("ApplyToBar", bar)
195 self.bars[name] = bar 230 self.bars[name] = bar
231 self.callbacks:Fire("OnCreateBar", bar)
196 return bar 232 return bar
197 end 233 end
198 234
199 function ReAction:EraseBar(x) 235 function ReAction:EraseBar(x)
200 local bar, name = SelectBar(x) 236 local bar, name = SelectBar(x)
201 if name and bar then 237 if name and bar then
202 DestroyBar(bar) 238 DestroyBar(bar)
203 self.db.profile.bars[name] = nil 239 self.db.profile.bars[name] = nil
204 self:CallMethodOnAllModules("EraseBarConfig", name) 240 self:CallMethodOnAllModules("EraseBarConfig", name)
241 self.callbacks:Fire("OnEraseBar",name)
205 end 242 end
206 end 243 end
207 244
208 function ReAction:GetBar(name) 245 function ReAction:GetBar(name)
209 return self.bars[name] 246 return self.bars[name]
219 self.bars[name] = nil 256 self.bars[name] = nil
220 bar.name = newname or "" 257 bar.name = newname or ""
221 local cfg = self.db.profile.bars 258 local cfg = self.db.profile.bars
222 cfg[newname], cfg[name] = cfg[name], nil 259 cfg[newname], cfg[name] = cfg[name], nil
223 self:CallMethodOnAllModules("RenameBarConfig", name, newname) 260 self:CallMethodOnAllModules("RenameBarConfig", name, newname)
224 end 261 self.callbacks:Fire("OnRenameBar", name, newname)
225 end 262 end
226 263 end
227 264
265 ReAction.options = {}
266 -- See modules/ReAction_ConfigUI for valid options contexts.
267 function ReAction:RegisterOptions(context, module, opts)
268 if module == nil or context == nil then
269 error("ReAction:RegisterOptions requires a module object and context ID")
270 end
271 if not self.options[context] then
272 self.options[context] = {}
273 end
274 self.options[context][module] = opts
275 self.callbacks:Fire("OnOptionsRegistered", context, module, opts)
276 end
277
278 function ReAction:GetOptions(context)
279 if context then
280 if not self.options[context] then
281 self.options[context] = { }
282 end
283 return self.options[context]
284 end
285 end
286
287 function ReAction:GetOptionContextList()
288 local c = {}
289 for k in self.options do
290 tinsert(c,k)
291 end
292 return c
293 end
294
295 function ReAction:RefreshOptions()
296 self.callbacks:Fire("OnOptionsRefreshed")
297 end