Mercurial > wow > reaction
changeset 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 | c8777ae7d460 |
children | 1696ff2c80cc |
files | Options.lua ReAction.lua ReAction.toc lib/embeds.xml locale/enUS.lua modules/ConfigUI.lua modules/HideBlizzard.lua |
diffstat | 7 files changed, 255 insertions(+), 269 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Options.lua Thu Oct 21 22:07:11 2010 +0000 @@ -0,0 +1,211 @@ +local addonName, addonTable = ... +local ReAction = addonTable.ReAction +local L = ReAction.L +local InCombatLockdown = InCombatLockdown + + +local configID = "ReAction" +local configProfileID = "ReAction_Profile" + +local function SlashHandler(option) + if option == "config" or option == "options" then + ReAction:ShowOptions() + elseif option == "edit" then + ReAction:ShowEditor() + elseif option == "unlock" then + ReAction:SetConfigMode(true) + elseif option == "lock" then + ReAction:SetConfigMode(false) + elseif option == "kb" then + ReAction:SetKeybindMode(true) + else + print(("%3.1f"):format(version)) + print("/rxn config") + print("/rxn edit") + print("/rxn lock") + print("/rxn unlock") + print("/rxn kb") + end +end + + +function ReAction:GetOptions() + if not self.options then + self.options = { + type = "group", + name = "ReAction", + args = { + _desc = { + type = "description", + name = L["Customizable replacement for Blizzard's Action Bars"], + order = 1, + }, + unlock = { + type = "toggle", + name = L["Unlock Bars"], + desc = L["Unlock bars for dragging and resizing with the mouse"], + handler = self, + get = "GetConfigMode", + set = function(info, value) self:SetConfigMode(value) end, + width = "full", + disabled = InCombatLockdown, + order = 2, + }, + hide = { + type = "toggle", + name = L["Hide Blizzard Action Bars"], + desc = L["Hide the default main bar and extra action bars"], + handler = self:GetModule("HideBlizzard"), + get = "IsHidden", + set = "SetHidden", + disabled = "OptionDisabled", + width = "full", + order = 3, + }, + hideVehicle = { + type = "toggle", + name = L["Hide Blizzard Vehicle Bar"], + desc = L["Hide the default vechicle action bar"], + handler = self:GetModule("HideBlizzard"), + get = "IsHidden", + set = "SetHidden", + disabled = "OptionDisabled", + width = "full", + order = 4, + }, + edit = { + type = "execute", + name = L["Edit Bars..."], + desc = L["Show the ReAction Bar Editor dialogue"], + handler = self:GetModule("ConfigUI"), + func = "OptionShowEditor", + order = 5, + }, + _closeThis = { + type = "toggle", + name = L["Close on Launch"], + desc = L["Close the Interface Options window when launching the ReAction Bar Editor"], + handler = self:GetModule("ConfigUI"), + get = "OptionGetCloseThis", + set = "OptionSetCloseThis", + order = 6, + cmdHidden = true, + dropdownHidden = true, + }, + keybind = { + type = "execute", + name = L["Key Bindings"], + desc = L["Show the keybinding dialogue"], + func = function() self:SetKeybindMode(true) end, + order = 7, + }, + 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 = 8, + }, + } + } + end + return self.options +end + + +function ReAction:GetProfileOptions() + if not self.profileOptions then + self.profileOptions = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db) + end + return self.profileOptions +end + + +function ReAction:InitializeOptions() + local AceConfigReg = LibStub("AceConfigRegistry-3.0") + local AceConfigDialog = LibStub("AceConfigDialog-3.0") + + AceConfigReg:RegisterOptionsTable(configID,ReAction:GetOptions()) + AceConfigReg:RegisterOptionsTable(configProfileID,ReAction:GetProfileOptions()) + + self.configFrame = AceConfigDialog:AddToBlizOptions(configID, L["ReAction"]) + self.configProfileFrame = AceConfigDialog:AddToBlizOptions(configProfileID, L["Profiles"], configID) + + self.configFrame.obj:SetCallback("default", + function() + self.db:ResetProfile() + AceConfigReg:NotifyChange(configID) + end ) + + self.db.RegisterCallback(self,"OnProfileChanged") + self.db.RegisterCallback(self,"OnProfileReset", "OnProfileChanged") + self.db.RegisterCallback(self,"OnProfileCopied","OnProfileChanged") + + SlashCmdList["REACTION"] = SlashHandler + _G["SLASH_REACTION1"] = "/reaction" + _G["SLASH_REACTION2"] = "/rxn" + + 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, + } +end + + +function ReAction:ShowOptions() + InterfaceOptionsFrame_OpenToCategory(configID) +end + + +function ReAction:PopKeybindWarning() + if not self.db.global.skipKeybindWarning then + StaticPopup_Show("REACTION_KB_WARN") + end +end + +function ReAction:OnProfileChanged() + self:Disable() + self:Enable() + self:PopKeybindWarning() +end + + +-- export to LDB +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:ShowOptions() + 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 options"])) + 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, + + } +)
--- 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, - - } -)
--- a/ReAction.toc Wed Oct 20 23:42:40 2010 +0000 +++ b/ReAction.toc Thu Oct 21 22:07:11 2010 +0000 @@ -14,6 +14,7 @@ locale\locale.xml ReAction.lua +Options.lua classes\classes.xml modules\modules.xml
--- a/lib/embeds.xml Wed Oct 20 23:42:40 2010 +0000 +++ b/lib/embeds.xml Thu Oct 21 22:07:11 2010 +0000 @@ -8,7 +8,6 @@ <Include file="AceAddon-3.0\AceAddon-3.0.xml"/> <Include file="AceConfigRegistry-3.0\AceConfigRegistry-3.0.xml"/> - <Include file="AceConsole-3.0\AceConsole-3.0.xml"/> <Include file="AceDB-3.0\AceDB-3.0.xml"/> <Include file="AceDBOptions-3.0\AceDBOptions-3.0.xml"/> <Include file="AceEvent-3.0\AceEvent-3.0.xml"/>
--- a/locale/enUS.lua Wed Oct 20 23:42:40 2010 +0000 +++ b/locale/enUS.lua Thu Oct 21 22:07:11 2010 +0000 @@ -2,25 +2,30 @@ if not L then return end for _, string in pairs({ --- bindings.lua -"ReAction", -"Toggle ReAction Bar Lock", -"ReAction Keybinding Mode", -- ReAction.lua "Bar ", "ReAction: name '%s' already in use", "ReAction config mode disabled during combat.", + +-- Options.lua "Customizable replacement for Blizzard's Action Bars", -"Global Settings", -"Global configuration settings", "Unlock Bars", "Unlock bars for dragging and resizing with the mouse", +"Hide Blizzard Action Bars", +"Hide the default main bar and extra action bars", +"Hide Blizzard Vehicle Bar", +"Hide the default vechicle action bar", +"Edit Bars...", +"Show the ReAction Bar Editor dialogue", +"Close on Launch", +"Close the Interface Options window when launching the ReAction Bar Editor", +"Key Bindings", +"Show the keybinding dialogue", "Skip profile keybind warning", "Don't show a warning about updating keybinds when switching profiles", -"Module Settings", -"Configuration settings for each module", -"Default", +"ReAction", +"Profiles", "ReAction profile changed: check your keybinds, they may need to be updated.", "OK", "ReAction: can't configure in combat", @@ -28,7 +33,7 @@ "Right-click", "Shift-click", "Alt-click", -"for global configuration", +"for options", "for bar editor dialog", "to unlock bars", "for keybind mode", @@ -140,12 +145,6 @@ "Create State", "State named '%s' already exists", --- HideBlizzard -"Hide Blizzard Action Bars", -"Hide the default main bar and extra action bars", -"Hide Blizzard Vehicle Bar", -"Hide the default vechicle action bar", - -- Action "Action Bar", "Action Bars", @@ -217,12 +216,6 @@ "Top Right", "Bottom Left", "Bottom Right", -"Edit Bars...", -"Show the ReAction Bar Editor dialogue", -"Close on Launch", -"Close the Interface Options window when launching the ReAction Bar Editor", -"Key Bindings", -"Show the keybinding dialogue", "Bar Editor", "Global Config", "Opens ReAction global configuration settings panel",
--- a/modules/ConfigUI.lua Wed Oct 20 23:42:40 2010 +0000 +++ b/modules/ConfigUI.lua Thu Oct 21 22:07:11 2010 +0000 @@ -35,11 +35,9 @@ self:RegisterEvent("PLAYER_REGEN_DISABLED") ReAction.RegisterCallback(self,"OnOptionsRegistered","OnOptionsRefreshed") ReAction.RegisterCallback(self,"OnOptionsRefreshed") - self:InitializeOptions() end function module:OnOptionsRefreshed(evt) - AceConfigReg:NotifyChange(configName) if self.editor then self.editor:Refresh() end end @@ -49,60 +47,28 @@ end end -function module:OpenConfig() - InterfaceOptionsFrame_OpenToCategory(configName) +function module:OptionShowEditor() + self:LaunchBarEditor() + -- you can't close a dialog in response to an options click, because the end of the + -- handler for all the button events calls lib:Open() + -- So, schedule a close on the next OnUpdate + if self.db.profile.closeOnLaunch then + self.editor.closePending = true + end end -function module:InitializeOptions() - ReAction:RegisterOptions(self, { - _launchEditor = { - type = "execute", - handler = self, - name = L["Edit Bars..."], - desc = L["Show the ReAction Bar Editor dialogue"], - func = function() - self:LaunchBarEditor() - -- you can't close a dialog in response to an options click, because the end of the - -- handler for all the button events calls lib:Open() - -- So, schedule a close on the next OnUpdate - if self.db.profile.closeOnLaunch then - self.editor.closePending = true - end - end, - order = 2, - }, - _closeThis = { - type = "toggle", - name = L["Close on Launch"], - desc = L["Close the Interface Options window when launching the ReAction Bar Editor"], - get = function() return self.db.profile.closeOnLaunch end, - set = function(info, val) self.db.profile.closeOnLaunch = val end, - order = 3, - }, - _keybind = { - type = "execute", - handler = self, - name = L["Key Bindings"], - desc = L["Show the keybinding dialogue"], - func = function() - ReAction:SetKeybindMode(true) - end, - order = 4, - }, - }, true) -- global +function module:OptionGetCloseThis() + return self.db.profile.closeOnLaunch +end - AceConfigReg:RegisterOptionsTable(configName,ReAction.options) - self.frame = AceConfigDialog:AddToBlizOptions(configName, configName) - self.frame.obj:SetCallback("default", - function() - ReAction.db:ResetProfile() - ReAction:RefreshOptions() - end ) +function module:OptionSetCloseThis(info,val) + self.db.profile.closeOnLaunch = val end + -- Bar Editor -- local function NewEditor() -- private variables @@ -168,7 +134,7 @@ name = L["Global Config"], desc = L["Opens ReAction global configuration settings panel"], func = function() - module:OpenConfig() + ReAction:ShowOptions() -- you can't close a dialog in response to an options click, because the end of the -- handler for all the button events calls lib:Open() -- So, schedule a close on the next OnUpdate
--- a/modules/HideBlizzard.lua Wed Oct 20 23:42:40 2010 +0000 +++ b/modules/HideBlizzard.lua Thu Oct 21 22:07:11 2010 +0000 @@ -37,31 +37,6 @@ -- bother to hide your buttons, they'll obscure some parts of the vehicle bar. VehicleMenuBar:SetFrameLevel(VehicleMenuBar:GetFrameLevel()+3) - ReAction:RegisterOptions(self, { - hide = { - name = L["Hide Blizzard Action Bars"], - desc = L["Hide the default main bar and extra action bars"], - type = "toggle", - order = 10, - width = "double", - handler = self, - get = "IsHidden", - set = "SetHidden", - disabled = "OptionDisabled", - }, - hideVehicle = { - name = L["Hide Blizzard Vehicle Bar"], - desc = L["Hide the default vechicle action bar"], - type = "toggle", - order = 11, - width = "double", - handler = self, - get = "IsHidden", - set = "SetHidden", - disabled = "OptionDisabled", - }, - }, true) -- global - end function module:OnEnable() @@ -135,6 +110,6 @@ InterfaceOptionsActionBarsPanel:HookScript("OnShow", function() if module:IsEnabled() and module:IsHidden() then - ReAction:ShowConfig() + ReAction:ShowOptions() end end )