diff 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
line wrap: on
line diff
--- a/ReAction.lua	Wed Oct 20 23:42:40 2010 +0000
+++ b/ReAction.lua	Thu Oct 21 22:07:11 2010 +0000
@@ -1,10 +1,10 @@
 --[[
   ReAction.lua
 
-  The ReAction core manages 4 collections:
+  The ReAction core manages several collections:
     - modules (via AceAddon)
     - bars
-    - options
+    - bar options
     - bar-type constructors
     
   and publishes events when those collections change. It also implements a couple properties
@@ -25,108 +25,30 @@
 
   ReAction is also an AceAddon-3.0 and contains an AceDB-3.0, which in turn publish more events.
 ]]--
-local version = GetAddOnMetadata("ReAction","Version")
 
------- CORE ------
-local ReAction = LibStub("AceAddon-3.0"):NewAddon( "ReAction",
-  "AceConsole-3.0",
+local addonName, addonTable = ...
+local version = GetAddOnMetadata(addonName,"Version")
+local ReAction = LibStub("AceAddon-3.0"):NewAddon( addonName,
   "AceEvent-3.0"
 )
-
-  -- export to other files in this addon (even if it's a compilation)
-local addonName, addonTable = ...
-local version = GetAddOnMetadata("ReAction","Version")
 addonTable.ReAction = ReAction
 
------- DEBUGGING ------
-ReAction.debug = true
-local dbprint
-if ReAction.debug then
-  dbprint = function(msg)
-    DEFAULT_CHAT_FRAME:AddMessage(msg)
-  end
-else
-  dbprint = function() end
-end
-ReAction.dbprint = dbprint
-
 ------ LIBRARIES ------
 local callbacks = LibStub("CallbackHandler-1.0"):New(ReAction)
 local KB = LibStub("LibKeyBound-1.0")
 local L = LibStub("AceLocale-3.0"):GetLocale("ReAction")
 ReAction.L = L
+ReAction.KB = KB
+ReAction.callbacks = callbacks
 
 ------ PRIVATE ------
-local weak = {__mode="k"}
 local private = { }
 local bars = {}
 local defaultBarConfig = {}
 local barOptionGenerators = { }
-local options = {
-  type = "group",
-  name = "ReAction",
-  childGroups = "tab",
-  args = {
-    _desc = {
-      type = "description",
-      name = L["Customizable replacement for Blizzard's Action Bars"],
-      order = 1,
-    },
-    global = {
-      type = "group",
-      name = L["Global Settings"],
-      desc = L["Global configuration settings"],
-      args = { 
-        unlock = {
-          type     = "toggle",
-          name     = L["Unlock Bars"],
-          desc     = L["Unlock bars for dragging and resizing with the mouse"],
-          handler  = ReAction,
-          get      = "GetConfigMode",
-          set      = function(info, value) ReAction:SetConfigMode(value) end,
-          width    = "double",
-          disabled = InCombatLockdown,
-          order    = 1
-        },
-        skipProfileWarning = {
-          type     = "toggle",
-          name     = L["Skip profile keybind warning"],
-          desc     = L["Don't show a warning about updating keybinds when switching profiles"],
-          get      = function() return ReAction.db.global.skipKeybindWarning end,
-          set      = function(info, value) ReAction.db.global.skipKeybindWarning = value end,
-          width    = "double",
-          order    = 2,
-        },
-      },
-      plugins = { },
-      order = 2,
-    },
-    module = {
-      type = "group",
-      childGroups = "select",
-      name = L["Module Settings"],
-      desc = L["Configuration settings for each module"],
-      args = { },
-      plugins = { },
-      order = 3,
-    },
-  },
-  plugins = { }
-}
-ReAction.options = options
 
-  -- insert an entry into the WoW static popup dialogs list
-StaticPopupDialogs["REACTION_KB_WARN"] = {
-	text = L["ReAction profile changed: check your keybinds, they may need to be updated."],
-	button1 = L["OK"],
-	hideOnEscape = true,
-  enterClicksFirstButton = true,
-	timeout = 0,
-  showAlert = true,
-  whileDead = true,
-}
 
-local SelectBar, DestroyBar, InitializeBars, TearDownBars, DeepCopy, CallModuleMethod, SlashHandler
+local SelectBar, DestroyBar, InitializeBars, TearDownBars, DeepCopy, CallModuleMethod
 do
   local pcall = pcall
   local geterrorhandler = geterrorhandler
@@ -199,32 +121,7 @@
     if m then
       if type(m) == "table" and type(m[method]) == "function" then
         m[method](m,...)
-      else
-        dbprint(("Bad call '%s' to %s module"):format(tostring(method),modulename));
       end
-    else
-      self:Print(("Module '%s' not found"):format(tostring(modulename)))
-    end
-  end
-
-  function SlashHandler(option)
-    if option == "config" then
-      self:ShowConfig()
-    elseif option == "edit" then
-      self:ShowEditor()
-    elseif option == "unlock" then
-      self:SetConfigMode(true)
-    elseif option == "lock" then
-      self:SetConfigMode(false)
-    elseif option == "kb" then
-      self:SetKeybindMode(true)
-    else
-      self:Print(("%3.1f"):format(version))
-      self:Print("/rxn config")
-      self:Print("/rxn edit")
-      self:Print("/rxn lock")
-      self:Print("/rxn unlock")
-      self:Print("/rxn kb")
     end
   end
 
@@ -240,20 +137,14 @@
         defaultBar = { }
       }
     },
-    L["Default"]
+    true -- use global 'Default' (locale-specific)
   )
-  self.db.RegisterCallback(self,"OnProfileChanged")
-  self.db.RegisterCallback(self,"OnProfileReset", "OnProfileChanged")
-  self.db.RegisterCallback(self,"OnProfileCopied","OnProfileChanged")
-
   KB.RegisterCallback(self,"LIBKEYBOUND_ENABLED")
   KB.RegisterCallback(self,"LIBKEYBOUND_DISABLED")
 
-  options.args.profile = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db)
+  self:RegisterEvent("PLAYER_REGEN_DISABLED")
 
-  self:RegisterChatCommand("reaction", SlashHandler)
-  self:RegisterChatCommand("rxn", SlashHandler)
-  self:RegisterEvent("PLAYER_REGEN_DISABLED")
+  self:InitializeOptions()
 end
 
 function ReAction:OnEnable()
@@ -264,12 +155,6 @@
   TearDownBars()
 end
 
-function ReAction:OnProfileChanged()
-  TearDownBars()
-  InitializeBars()
-  self:PopKeybindWarning()
-end
-
 function ReAction:PLAYER_REGEN_DISABLED()
   if private.configMode == true then
     self:UserError(L["ReAction config mode disabled during combat."])
@@ -431,17 +316,12 @@
   return private.defaultBarConfigChoice
 end
 
-function ReAction:RegisterOptions(module, opts, global)
-  options.args[global and "global" or "module"].plugins[module:GetName()] = opts
-  self:RefreshOptions()
-end
-
 function ReAction:RefreshOptions()
   callbacks:Fire("OnOptionsRefreshed")
 end
 
 -- 
--- In addition to global and general module options, options tables 
+-- In addition to global options, options tables 
 -- must be generated dynamically for each bar.
 --
 -- 'func' should be a function or a method string.
@@ -497,10 +377,6 @@
   return private.configMode
 end
 
-function ReAction:ShowConfig()
-  CallModuleMethod("ConfigUI","OpenConfig")
-end
-
 function ReAction:ShowEditor(bar, ...)
   CallModuleMethod("ConfigUI","LaunchBarEditor",bar, ...)
 end
@@ -519,42 +395,3 @@
 function ReAction:GetKeybindMode( mode )
   return private.kbMode
 end
-
-function ReAction:PopKeybindWarning()
-  if not self.db.global.skipKeybindWarning then
-    StaticPopup_Show("REACTION_KB_WARN")
-  end
-end
-
--- Export ReAction launcher to LibDataBroker-aware displays
-LibStub:GetLibrary("LibDataBroker-1.1"):NewDataObject( "ReAction", 
-  {
-    type = "launcher", 
-    icon = "Interface\\Icons\\INV_Qiraj_JewelEncased",
-
-    OnClick = function( frame, button )
-      if not InCombatLockdown() then
-        if IsAltKeyDown() then
-          ReAction:SetKeybindMode( not ReAction:GetKeybindMode() )
-        elseif IsShiftKeyDown() then
-          ReAction:SetConfigMode( not ReAction:GetConfigMode() )
-        elseif button == "RightButton" then
-          ReAction:ShowEditor()
-        else
-          ReAction:ShowConfig()
-        end
-      else
-        ReAction:UserError(L["ReAction: can't configure in combat"])
-      end
-    end,
-
-      -- this isn't included in the 'launcher' type LDB spec but it seems all launcher displays use it
-    OnTooltipShow = function( tooltip )
-      tooltip:AddLine(format("|cffffffff%s|r %s",L["Click"],L["for global configuration"]))
-      tooltip:AddLine(format("|cffffd200%s|r %s",L["Right-click"],L["for bar editor dialog"]))
-      tooltip:AddLine(format("|cff00ff00%s|r %s",L["Shift-click"],L["to unlock bars"]))
-      tooltip:AddLine(format("|cff00cccc%s|r %s",L["Alt-click"],L["for keybind mode"]))
-    end,
-
-  }
-)