Mercurial > wow > reaction
comparison ReAction.lua @ 48:7b7d178dec52
Implemented bar-type selection, extended CreateBar functionality
author | Flick <flickerstreak@gmail.com> |
---|---|
date | Sat, 12 Apr 2008 00:15:09 +0000 |
parents | e12b736c23c3 |
children | c3c64e2def50 |
comparison
equal
deleted
inserted
replaced
47:e12b736c23c3 | 48:7b7d178dec52 |
---|---|
145 self:RegisterChatCommand("rxn", SlashHandler) | 145 self:RegisterChatCommand("rxn", SlashHandler) |
146 self:RegisterEvent("PLAYER_REGEN_DISABLED") | 146 self:RegisterEvent("PLAYER_REGEN_DISABLED") |
147 | 147 |
148 self.bars = {} | 148 self.bars = {} |
149 self.options = {} | 149 self.options = {} |
150 self.defaultBarConfig = {} | |
150 | 151 |
151 self:RegisterOptions("global", self, { | 152 self:RegisterOptions("global", self, { |
152 unlock = { | 153 unlock = { |
153 type = "toggle", | 154 type = "toggle", |
154 handler = module, | 155 handler = module, |
243 self:Print(("Module '%s' not found"):format(tostring(modulename))) | 244 self:Print(("Module '%s' not found"):format(tostring(modulename))) |
244 end | 245 end |
245 end | 246 end |
246 | 247 |
247 | 248 |
248 function ReAction:CreateBar(name, defaultConfig, prefix) | 249 function ReAction:CreateBar(name, ...) |
250 local config = select(1,...) | |
251 if config and type(config) ~= "table" then | |
252 bartype = select(1,...) | |
253 if type(bartype) ~= "string" then | |
254 error("ReAction:CreateBar() - first argument must be a config table or a default config type string") | |
255 end | |
256 config = self.defaultBarConfig[bartype] | |
257 if not config then | |
258 error(("ReAction:CreateBar() - unknown bar type '%s'"):format(bartype)) | |
259 end | |
260 config = DeepCopy(config) | |
261 config.btnRows = select(2,...) or config.btnRows or 1 | |
262 config.btnColumns = select(3,...) or config.btnColumns or 12 | |
263 config.btnWidth = select(4,...) or config.btnWidth or 36 | |
264 config.btnHeight = select(4,...) or config.btnHeight or 36 | |
265 config.spacing = select(5,...) or config.spacing or 3 | |
266 config.width = config.width or config.btnColumns*(config.btnWidth + config.spacing) + 1 | |
267 config.height = config.height or config.btnRows*(config.btnHeight + config.spacing) + 1 | |
268 config.anchor = config.anchor or "BOTTOM" | |
269 config.anchorTo = config.anchorTo or "UIParent" | |
270 config.relativePoint = config.relativePoint or "BOTTOM" | |
271 config.y = config.y or 200 | |
272 config.x = config.x or 0 | |
273 end | |
249 local profile = self.db.profile | 274 local profile = self.db.profile |
250 defaultConfig = defaultConfig or profile.defaultBar | 275 config = config or DeepCopy(profile.defaultBar) |
251 prefix = prefix or L["Bar "] | 276 prefix = prefix or L["Bar "] |
252 if not name then | 277 if not name then |
253 i = 1 | 278 i = 1 |
254 repeat | 279 repeat |
255 name = prefix..i | 280 name = prefix..i |
256 i = i + 1 | 281 i = i + 1 |
257 until self.bars[name] == nil | 282 until self.bars[name] == nil |
258 end | 283 end |
259 profile.bars[name] = profile.bars[name] or DeepCopy(defaultConfig) | 284 profile.bars[name] = profile.bars[name] or config |
260 local bar = self.Bar:new( name, profile.bars[name] ) -- ReAction.Bar defined in Bar.lua | 285 local bar = self.Bar:new( name, profile.bars[name] ) -- ReAction.Bar defined in Bar.lua |
261 self:CallMethodOnAllModules("ApplyToBar", bar) | 286 self:CallMethodOnAllModules("ApplyToBar", bar) |
262 self.bars[name] = bar | 287 self.bars[name] = bar |
263 self.callbacks:Fire("OnCreateBar", bar) | 288 self.callbacks:Fire("OnCreateBar", bar) |
264 if self.configMode then | 289 if self.configMode then |
297 self.callbacks:Fire("OnRenameBar", name, newname) | 322 self.callbacks:Fire("OnRenameBar", name, newname) |
298 end | 323 end |
299 end | 324 end |
300 end | 325 end |
301 | 326 |
327 function ReAction:RegisterDefaultBarConfig( name, config, isDefaultChoice ) | |
328 self.defaultBarConfig[name] = config | |
329 if isDefaultChoice then | |
330 self.defaultBarConfigChoice = name | |
331 end | |
332 self:RefreshOptions() | |
333 end | |
334 | |
335 function ReAction:UnregisterDefaultBarConfig( name ) | |
336 self.defaultBarConfig[name] = nil | |
337 if self.defaultBarConfigChoice == name then | |
338 self.defaultBarConfigChoice = nil | |
339 end | |
340 self:RefreshOptions() | |
341 end | |
342 | |
302 -- See modules/ReAction_ConfigUI for valid options contexts. | 343 -- See modules/ReAction_ConfigUI for valid options contexts. |
303 function ReAction:RegisterOptions(context, module, opts) | 344 function ReAction:RegisterOptions(context, module, opts) |
304 if module == nil or context == nil then | 345 if module == nil or context == nil then |
305 error("ReAction:RegisterOptions requires a module object and context ID") | 346 error("ReAction:RegisterOptions requires a module object and context ID") |
306 end | 347 end |
318 end | 359 end |
319 return self.options[context] | 360 return self.options[context] |
320 end | 361 end |
321 end | 362 end |
322 | 363 |
323 function ReAction:GetOptionContextList() | |
324 local c = {} | |
325 for k in self.options do | |
326 tinsert(c,k) | |
327 end | |
328 return c | |
329 end | |
330 | |
331 function ReAction:RefreshOptions() | 364 function ReAction:RefreshOptions() |
332 self.callbacks:Fire("OnOptionsRefreshed") | 365 self.callbacks:Fire("OnOptionsRefreshed") |
333 end | 366 end |
334 | 367 |
335 function ReAction:SetConfigMode( mode ) | 368 function ReAction:SetConfigMode( mode ) |