From 177f03f29fc6992a1244cdcb91b7f5fd9a7fdac2 Mon Sep 17 00:00:00 2001 From: Hendrik Leppkes Date: Fri, 7 Mar 2008 15:38:34 +0000 Subject: [PATCH] - add more descriptive error messages to get/set handlers - add MicroMenu module (may not be 100% complete yet) --- ActionBarPrototype.lua | 4 +- Bar.lua | 4 +- Bartender4.toc | 1 + ButtonBar.lua | 4 +- MicroMenu.lua | 123 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 130 insertions(+), 6 deletions(-) create mode 100644 MicroMenu.lua diff --git a/ActionBarPrototype.lua b/ActionBarPrototype.lua index 1775c39..6fc5f90 100644 --- a/ActionBarPrototype.lua +++ b/ActionBarPrototype.lua @@ -24,14 +24,14 @@ do -- retrieves a valid bar object from the modules actionbars table function getBar(id) local bar = module.actionbars[tonumber(id)] - assert(bar, "Invalid bar id in options table.") + assert(bar, ("Invalid bar id in options table. (%s)"):format(id)) return bar end -- calls a function on the bar function callFunc(bar, type, option, ...) local func = type .. (optionMap[option] or option) - assert(bar[func], "Invalid get/set function."..func) + assert(bar[func], ("Invalid get/set function %s in bar %s."):format(func, bar.id)) return bar[func](bar, ...) end diff --git a/Bar.lua b/Bar.lua index 02eb143..3be938a 100644 --- a/Bar.lua +++ b/Bar.lua @@ -131,14 +131,14 @@ do -- retrieves a valid bar object from the barregistry table function getBar(id) local bar = barregistry[tostring(id)] - assert(bar, "Invalid bar id in options table.") + assert(bar, ("Invalid bar id in options table. (%s)"):format(id)) return bar end -- calls a function on the bar function callFunc(bar, type, option, ...) local func = type .. (optionMap[option] or option) - assert(bar[func], "Invalid get/set function.") + assert(bar[func], ("Invalid get/set function %s in bar %s."):format(func, bar.id)) return bar[func](bar, ...) end diff --git a/Bartender4.toc b/Bartender4.toc index 8a7a1b1..8c475de 100644 --- a/Bartender4.toc +++ b/Bartender4.toc @@ -27,3 +27,4 @@ ActionBarPrototype.lua ActionBarStates.lua StanceBar.lua PetBar.lua +MicroMenu.lua diff --git a/ButtonBar.lua b/ButtonBar.lua index 5c7e263..d3e1e88 100644 --- a/ButtonBar.lua +++ b/ButtonBar.lua @@ -41,14 +41,14 @@ do -- retrieves a valid bar object from the barregistry table function getBar(id) local bar = barregistry[tostring(id)] - assert(bar, "Invalid bar id in options table.") + assert(bar, ("Invalid bar id in options table. (%s)"):format(id)) return bar end -- calls a function on the bar function callFunc(bar, type, option, ...) local func = type .. (optionMap[option] or option) - assert(bar[func], "Invalid get/set function.") + assert(bar[func], ("Invalid get/set function %s in bar %s."):format(func, bar.id)) return bar[func](bar, ...) end diff --git a/MicroMenu.lua b/MicroMenu.lua new file mode 100644 index 0000000..66afaf4 --- /dev/null +++ b/MicroMenu.lua @@ -0,0 +1,123 @@ +--[[ $Id: StanceBar.lua 62418 2008-02-21 16:53:12Z nevcairiel $ ]] + +-- register module +local MicroMenuMod = Bartender4:NewModule("MicroMenu", "AceHook-3.0") + +-- fetch upvalues +local ActionBars = Bartender4:GetModule("ActionBars") +local Bar = Bartender4.Bar.prototype + +-- create prototype information +local MicroMenuBar = setmetatable({}, {__index = Bar}) + +local table_insert = table.insert + +local defaults = { profile = Bartender4:Merge({ + enabled = true, +}, Bartender4.Bar.defaults) } + +function MicroMenuMod:OnInitialize() + self.db = Bartender4.db:RegisterNamespace("MicroMenu", defaults) + self:SetEnabledState(self.db.profile.enabled) + self:SetupOptions() +end + +local noopFunc = function() end + +function MicroMenuMod:OnEnable() + if not self.bar then + self.bar = setmetatable(Bartender4.Bar:Create("MicroMenu", nil, self.db.profile), {__index = MicroMenuBar}) + local buttons = {} + table_insert(buttons, CharacterMicroButton) + table_insert(buttons, SpellbookMicroButton) + table_insert(buttons, TalentMicroButton) + table_insert(buttons, QuestLogMicroButton) + table_insert(buttons, SocialsMicroButton) + table_insert(buttons, LFGMicroButton) + table_insert(buttons, MainMenuMicroButton) + table_insert(buttons, HelpMicroButton) + self.bar.buttons = buttons + + self:RawHook("UpdateTalentButton", noopFunc, true) + + for i,v in pairs(buttons) do + v:SetParent(self.bar) + v:Show() + v:SetFrameLevel(self.bar:GetFrameLevel() + 1) + end + + -- TODO: real start position + self.bar:SetPoint("CENTER") + + self.bar:ApplyConfig(self.db.profile) + end + self.bar.disabled = nil + self:SetupOptions() +end + +function MicroMenuMod:OnDisable() + if not self.bar then return end + self.bar.disabled = true + self.bar:UnregisterAllEvents() + self.bar:Hide() + self:SetupOptions() +end + +function MicroMenuMod:ApplyConfig() + self.bar:ApplyConfig(self.db.profile) +end + +function MicroMenuMod:SetupOptions() + if not self.options then + self.options = Bar:GetOptionObject() + local enabled = { + type = "toggle", + order = 1, + name = "Enabled", + desc = "Enable the Micro Menu", + get = function() return self.db.profile.enabled end, + set = "ToggleModule", + handler = self, + } + self.options:AddElement("general", "enabled", enabled) + + self.disabledoptions = { + general = { + type = "group", + name = "General Settings", + cmdInline = true, + order = 1, + args = { + enabled = enabled, + } + } + } + ActionBars.options.args["MicroMenu"] = { + order = 30, + type = "group", + name = "Micro Menu", + desc = "Configure the Micro Menu", + childGroups = "tab", + } + end + ActionBars.options.args["MicroMenu"].args = self:IsEnabled() and self.options.table or self.disabledoptions +end + +function MicroMenuBar:ApplyConfig(config) + Bar.ApplyConfig(self, config) + self:PerformLayout() +end + +function MicroMenuBar:PerformLayout() + if self.config.vertical then + -- TODO: vertical + else + self:SetSize(212, 45) + self.buttons[1]:ClearAllPoints() + self.buttons[1]:SetPoint("TOPLEFT", self, "TOPLEFT", 5, 18) + for i = 2, #self.buttons do + self.buttons[i]:ClearAllPoints() + self.buttons[i]:SetPoint("TOPLEFT", self.buttons[i-1], "TOPRIGHT", -4, 0) + end + end +end