diff 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
line wrap: on
line diff
--- a/ReAction.lua	Wed Apr 02 18:22:02 2008 +0000
+++ b/ReAction.lua	Wed Apr 02 23:31:13 2008 +0000
@@ -1,13 +1,17 @@
 -- ReAction.lua
 -- See modules/ReAction_ModuleTemplate for Module API listing
 -- See Bar.lua for Bar object listing
+local MAJOR_VERSION = GetAddOnMetadata("ReAction","Version")
 
 ------ LIBRARIES ------
 local L = LibStub("AceLocale-3.0"):GetLocale("ReAction")
 
 ------ CORE ------
-local ReAction = LibStub("AceAddon-3.0"):NewAddon( "ReAction" )
+local ReAction = LibStub("AceAddon-3.0"):NewAddon( "ReAction",
+  "AceConsole-3.0"
+)
 ReAction.revision = tonumber(("$Revision: 1 $"):match("%d+"))
+ReAction.version = MAJOR_VERSION
 ReAction.L = L
 
 ------ GLOBALS ------
@@ -25,7 +29,7 @@
 end
 
 ------ PRIVATE ------
-local SelectBar, DestroyBar, InitializeBars, TearDownBars, DeepCopy, SafeCall, CheckMethod
+local SelectBar, DestroyBar, InitializeBars, TearDownBars, DeepCopy, SafeCall, CheckMethod, SlashHandler
 do
   local pcall = pcall
   local geterrorhandler = geterrorhandler
@@ -106,6 +110,34 @@
       error("Invalid method")
     end
   end
+
+  local function CallOptsModule(method,...)
+   local m = ReAction:GetModule("ConfigUI",true)
+   if not m then
+     LoadAddOn("ReAction_ConfigUI")
+     m = ReAction:GetModule("ConfigUI")
+   end
+   if m and type(m) == "table" and type(m[method]) == "function" then
+     m[method](m,...)
+   else
+     ReAction:Print("Options module not found")
+   end
+  end
+
+  SlashHandler = function(option)
+    if option == "config" then
+      CallOptsModule("OpenConfig",true)
+    elseif option == "unlock" then
+      CallOptsModule("SetConfigMode",true)
+    elseif option == "lock" then
+      CallOptsModule("SetConfigMode",false)
+    else
+      ReAction:Print(ReAction.version)
+      ReAction:Print("/reaction config")
+      ReAction:Print("/reaction unlock")
+      ReAction:Print("/reaction lock")
+    end
+  end
 end
 
 
@@ -121,6 +153,9 @@
     -- default profile is character-specific
   )
   self.db.RegisterCallback(self,"OnProfileChanged")
+  self.callbacks = LibStub("CallbackHandler-1.0"):New(self)
+  self:RegisterChatCommand("reaction", SlashHandler)
+  self:RegisterChatCommand("rxn", SlashHandler)
 
   self.bars = {}
 end
@@ -193,6 +228,7 @@
   local bar = self.Bar:new( name, profile.bars[name] )  -- ReAction.Bar defined in Bar.lua
   self:CallMethodOnAllModules("ApplyToBar", bar)
   self.bars[name] = bar
+  self.callbacks:Fire("OnCreateBar", bar)
   return bar
 end
 
@@ -202,6 +238,7 @@
     DestroyBar(bar)
     self.db.profile.bars[name] = nil
     self:CallMethodOnAllModules("EraseBarConfig", name)
+    self.callbacks:Fire("OnEraseBar",name)
   end
 end
 
@@ -221,7 +258,40 @@
     local cfg = self.db.profile.bars
     cfg[newname], cfg[name] = cfg[name], nil
     self:CallMethodOnAllModules("RenameBarConfig", name, newname)
+    self.callbacks:Fire("OnRenameBar", name, newname)
   end
 end
 
+ReAction.options = {}
+-- See modules/ReAction_ConfigUI for valid options contexts.
+function ReAction:RegisterOptions(context, module, opts)
+  if module == nil or context == nil then
+    error("ReAction:RegisterOptions requires a module object and context ID")
+  end
+  if not self.options[context] then
+    self.options[context] = {}
+  end
+  self.options[context][module] = opts
+  self.callbacks:Fire("OnOptionsRegistered", context, module, opts)
+end
 
+function ReAction:GetOptions(context)
+  if context then
+    if not self.options[context] then
+      self.options[context] = { }
+    end
+    return self.options[context]
+  end
+end
+
+function ReAction:GetOptionContextList()
+  local c = {}
+  for k in self.options do
+    tinsert(c,k)
+  end
+  return c
+end
+
+function ReAction:RefreshOptions()
+  self.callbacks:Fire("OnOptionsRefreshed")
+end