diff --git a/.pkgmeta b/.pkgmeta deleted file mode 100644 index bd74148..0000000 --- a/.pkgmeta +++ /dev/null @@ -1,16 +0,0 @@ -package-as: Bartender4 -externals: - libs/LibStub: svn://svn.wowace.com/wow/libstub/mainline/tags/1.0 - libs/CallbackHandler-1.0: svn://svn.wowace.com/wow/callbackhandler/mainline/trunk/CallbackHandler-1.0 - libs/AceAddon-3.0: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceAddon-3.0 - libs/AceConsole-3.0: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceConsole-3.0 - libs/AceEvent-3.0: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceEvent-3.0 - libs/AceHook-3.0: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceHook-3.0 - libs/AceDB-3.0: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceDB-3.0 - libs/AceDBOptions-3.0: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceDBOptions-3.0 - libs/AceLocale-3.0: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceLocale-3.0 - libs/AceGUI-3.0: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceGUI-3.0 - libs/AceConfig-3.0: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceConfig-3.0 - libs/LibKeyBound-1.0: svn://svn.wowace.com/wow/libkeybound-1-0/mainline/trunk/LibKeyBound-1.0 - libs/LibDBIcon-1.0: svn://svn.wowace.com/wow/libdbicon-1-0/mainline/trunk/LibDBIcon-1.0 - libs/LibWindow-1.1: svn://svn.wowace.com/wow/libwindow-1-1/mainline/trunk/LibWindow-1.1 diff --git a/ActionBar.lua b/ActionBar.lua index 7cee2f9..6f05723 100644 --- a/ActionBar.lua +++ b/ActionBar.lua @@ -1,119 +1,119 @@ ---[[ - Copyright (c) 2009, Hendrik "Nevcairiel" Leppkes < h.leppkes at gmail dot com > - All rights reserved. -]] -local StateBar = Bartender4.StateBar.prototype -local ActionBar = setmetatable({}, {__index = StateBar}) -Bartender4.ActionBar = ActionBar - ---[[=================================================================================== - ActionBar Prototype -===================================================================================]]-- - -local initialPosition -do - -- Sets the Bar to its initial Position in the Center of the Screen - function initialPosition(bar) - bar:ClearSetPoint("CENTER", 0, -250 + (bar.id-1) * 38) - bar:SavePosition() - end -end - --- Apply the specified config to the bar and refresh all settings -function ActionBar:ApplyConfig(config) - StateBar.ApplyConfig(self, config) - - if not self.config.position.x then initialPosition(self) end - - self:UpdateButtons() -end - --- Update the number of buttons in our bar, creating new ones if necessary -function ActionBar:UpdateButtons(numbuttons) - if numbuttons then - self.config.buttons = min(numbuttons, 12) - else - numbuttons = min(self.config.buttons, 12) - end - - local buttons = self.buttons or {} - - local updateBindings = (numbuttons > #buttons) - -- create more buttons if needed - for i = (#buttons+1), numbuttons do - buttons[i] = Bartender4.Button:Create(i, self) - end - - -- show active buttons - for i = 1, numbuttons do - buttons[i]:SetParent(self) - buttons[i]:Show() - buttons[i]:SetAttribute("statehidden", nil) - buttons[i]:Update() - end - - -- hide inactive buttons - for i = (numbuttons + 1), #buttons do - buttons[i]:Hide() - buttons[i]:SetParent(UIParent) - buttons[i]:SetAttribute("statehidden", true) - end - - self.numbuttons = numbuttons - self.buttons = buttons - - self:UpdateButtonLayout() - self:SetGrid() - if updateBindings and self.id == "1" then - self.module:ReassignBindings() - end - - -- need to re-set clickthrough after creating new buttons - self:SetClickThrough() - self:UpdateSelfCast() -- update selfcast and states -end - -function ActionBar:SkinChanged(...) - StateBar.SkinChanged(self, ...) - self:ForAll("Update") -end - - ---[[=================================================================================== - ActionBar Config Interface -===================================================================================]]-- - - --- get the current number of buttons -function ActionBar:GetButtons() - return self.config.buttons -end - --- set the number of buttons and refresh layout -ActionBar.SetButtons = ActionBar.UpdateButtons - -function ActionBar:GetEnabled() - return true -end - -function ActionBar:SetEnabled(state) - if not state then - self.module:DisableBar(self.id) - end -end - -function ActionBar:GetGrid() - return self.config.showgrid -end - -function ActionBar:SetGrid(state) - if state ~= nil then - self.config.showgrid = state - end - if self.config.showgrid then - self:ForAll("ShowGrid") - else - self:ForAll("HideGrid") - end - self:ForAll("UpdateGrid") -end +--[[ + Copyright (c) 2009, Hendrik "Nevcairiel" Leppkes < h.leppkes at gmail dot com > + All rights reserved. +]] +local StateBar = Bartender4.StateBar.prototype +local ActionBar = setmetatable({}, {__index = StateBar}) +Bartender4.ActionBar = ActionBar + +--[[=================================================================================== + ActionBar Prototype +===================================================================================]]-- + +local initialPosition +do + -- Sets the Bar to its initial Position in the Center of the Screen + function initialPosition(bar) + bar:ClearSetPoint("CENTER", 0, -250 + (bar.id-1) * 38) + bar:SavePosition() + end +end + +-- Apply the specified config to the bar and refresh all settings +function ActionBar:ApplyConfig(config) + StateBar.ApplyConfig(self, config) + + if not self.config.position.x then initialPosition(self) end + + self:UpdateButtons() +end + +-- Update the number of buttons in our bar, creating new ones if necessary +function ActionBar:UpdateButtons(numbuttons) + if numbuttons then + self.config.buttons = min(numbuttons, 12) + else + numbuttons = min(self.config.buttons, 12) + end + + local buttons = self.buttons or {} + + local updateBindings = (numbuttons > #buttons) + -- create more buttons if needed + for i = (#buttons+1), numbuttons do + buttons[i] = Bartender4.Button:Create(i, self) + end + + -- show active buttons + for i = 1, numbuttons do + buttons[i]:SetParent(self) + buttons[i]:Show() + buttons[i]:SetAttribute("statehidden", nil) + buttons[i]:Update() + end + + -- hide inactive buttons + for i = (numbuttons + 1), #buttons do + buttons[i]:Hide() + buttons[i]:SetParent(UIParent) + buttons[i]:SetAttribute("statehidden", true) + end + + self.numbuttons = numbuttons + self.buttons = buttons + + self:UpdateButtonLayout() + self:SetGrid() + if updateBindings and self.id == "1" then + self.module:ReassignBindings() + end + + -- need to re-set clickthrough after creating new buttons + self:SetClickThrough() + self:UpdateSelfCast() -- update selfcast and states +end + +function ActionBar:SkinChanged(...) + StateBar.SkinChanged(self, ...) + self:ForAll("Update") +end + + +--[[=================================================================================== + ActionBar Config Interface +===================================================================================]]-- + + +-- get the current number of buttons +function ActionBar:GetButtons() + return self.config.buttons +end + +-- set the number of buttons and refresh layout +ActionBar.SetButtons = ActionBar.UpdateButtons + +function ActionBar:GetEnabled() + return true +end + +function ActionBar:SetEnabled(state) + if not state then + self.module:DisableBar(self.id) + end +end + +function ActionBar:GetGrid() + return self.config.showgrid +end + +function ActionBar:SetGrid(state) + if state ~= nil then + self.config.showgrid = state + end + if self.config.showgrid then + self:ForAll("ShowGrid") + else + self:ForAll("HideGrid") + end + self:ForAll("UpdateGrid") +end diff --git a/ActionBars.lua b/ActionBars.lua index d49274b..90ac4c6 100644 --- a/ActionBars.lua +++ b/ActionBars.lua @@ -1,234 +1,235 @@ ---[[ - Copyright (c) 2009, Hendrik "Nevcairiel" Leppkes < h.leppkes at gmail dot com > - All rights reserved. -]] -local L = LibStub("AceLocale-3.0"):GetLocale("Bartender4") -local BT4ActionBars = Bartender4:NewModule("ActionBars", "AceEvent-3.0") - -local ActionBar, ActionBar_MT - -local abdefaults = { - ['**'] = Bartender4:Merge({ - enabled = true, - buttons = 12, - hidemacrotext = false, - showgrid = false, - }, Bartender4.StateBar.defaults), - [1] = { - states = { - enabled = true, - possess = true, - actionbar = true, - stance = { - DRUID = { bear = 9, cat = 7, prowl = 8 }, - WARRIOR = { battle = 7, def = 8, berserker = 9 }, - ROGUE = { stealth = 7, shadowdance = 7 } - }, - }, - visibility = { - vehicleui = false, - }, - }, - [7] = { - enabled = false, - }, - [8] = { - enabled = false, - }, - [9] = { - enabled = false, - }, - [10] = { - enabled = false, - }, -} - -local defaults = { - profile = { - actionbars = abdefaults, - } -} - -function BT4ActionBars:OnInitialize() - self.db = Bartender4.db:RegisterNamespace("ActionBars", defaults) - - -- fetch the prototype information - ActionBar = Bartender4.ActionBar - ActionBar_MT = {__index = ActionBar} -end - - -local LBF = LibStub("LibButtonFacade", true) - --- setup the 10 actionbars -local first = true -function BT4ActionBars:OnEnable() - if first then - self.playerclass = select(2, UnitClass("player")) - self.actionbars = {} - - for i=1,10 do - local config = self.db.profile.actionbars[i] - if config.enabled then - self.actionbars[i] = self:Create(i, config) - else - self:CreateBarOption(i, self.disabledoptions) - end - end - - first = nil - end - - self:RegisterEvent("UPDATE_BINDINGS", "ReassignBindings") - self:ReassignBindings() -end - -function BT4ActionBars:SetupOptions() - if not self.options then - -- empty table to hold the bar options - self.options = {} - - -- template for disabled bars - self.disabledoptions = { - general = { - type = "group", - name = L["General Settings"], - cmdInline = true, - order = 1, - args = { - enabled = { - type = "toggle", - name = L["Enabled"], - desc = L["Enable/Disable the bar."], - set = function(info, v) if v then BT4ActionBars:EnableBar(info[2]) end end, - get = function() return false end, - } - } - } - } - - -- iterate over bars and create their option tables - for i=1,10 do - local config = self.db.profile.actionbars[i] - if config.enabled then - self:CreateBarOption(i) - else - self:CreateBarOption(i, self.disabledoptions) - end - end - end -end - --- Applys the config in the current profile to all active Bars -function BT4ActionBars:ApplyConfig() - for i=1,10 do - local config = self.db.profile.actionbars[i] - -- make sure the bar has its current config object if it exists already - if self.actionbars[i] then - self.actionbars[i].config = config - end - if config.enabled then - self:EnableBar(i) - else - self:DisableBar(i) - end - end -end - --- we do not allow to disable the actionbars module -function BT4ActionBars:ToggleModule() - return -end - -function BT4ActionBars:UpdateButtons(force) - for i,v in ipairs(self.actionbars) do - for j,button in ipairs(v.buttons) do - button:UpdateAction(force) - end - end -end - -function BT4ActionBars:ReassignBindings() - if InCombatLockdown() then return end - if not self.actionbars or not self.actionbars[1] then return end - local frame = self.actionbars[1] - ClearOverrideBindings(frame) - for i = 1,min(#frame.buttons, 12) do - local button, real_button = ("ACTIONBUTTON%d"):format(i), ("BT4Button%d"):format(i) - for k=1, select('#', GetBindingKey(button)) do - local key = select(k, GetBindingKey(button)) - SetOverrideBindingClick(frame, false, key, real_button) - end - end - - for i = 1, 120 do - -- rename old bindings from Secure to only - local button, real_button = ("CLICK BT4Button%dSecure:LeftButton"):format(i), ("BT4Button%d"):format(i) - - for k=1, select('#', GetBindingKey(button)) do - local key = select(k, GetBindingKey(button)) - if key and key ~= "" then - SetBindingClick(key, real_button, "LeftButton") - end - end - end - SaveBindings(GetCurrentBindingSet() or 1) -end - --- Creates a new bar object based on the id and the specified config -function BT4ActionBars:Create(id, config) - local id = tostring(id) - local bar = setmetatable(Bartender4.StateBar:Create(id, config, (L["Bar %s"]):format(id)), ActionBar_MT) - bar.module = self - - self:CreateBarOption(id) - - bar:ApplyConfig() - - return bar -end - -function BT4ActionBars:DisableBar(id) - id = tonumber(id) - local bar = self.actionbars[id] - if not bar then return end - - bar.config.enabled = false - bar:Disable() - self:CreateBarOption(id, self.disabledoptions) -end - -function BT4ActionBars:EnableBar(id) - id = tonumber(id) - local bar = self.actionbars[id] - local config = self.db.profile.actionbars[id] - config.enabled = true - if not bar then - bar = self:Create(id, config) - self.actionbars[id] = bar - else - bar.disabled = nil - self:CreateBarOption(id) - bar:ApplyConfig(config) - end - if not Bartender4.Locked then - bar:Unlock() - end -end - -function BT4ActionBars:GetAll() - return pairs(self.actionbars) -end - -function BT4ActionBars:ForAll(method, ...) - for _, bar in self:GetAll() do - local func = bar[method] - if func then - func(bar, ...) - end - end -end - -function BT4ActionBars:ForAllButtons(...) - self:ForAll("ForAll", ...) -end +--[[ + Copyright (c) 2009, Hendrik "Nevcairiel" Leppkes < h.leppkes at gmail dot com > + All rights reserved. +]] +local L = LibStub("AceLocale-3.0"):GetLocale("Bartender4") +local BT4ActionBars = Bartender4:NewModule("ActionBars", "AceEvent-3.0") + +local ActionBar, ActionBar_MT + +local abdefaults = { + ['**'] = Bartender4:Merge({ + enabled = true, + buttons = 12, + hidemacrotext = false, + showgrid = false, + }, Bartender4.StateBar.defaults), + [1] = { + states = { + enabled = true, + possess = true, + actionbar = true, + stance = { + DRUID = { bear = 9, cat = 7, prowl = 8 }, + WARRIOR = { battle = 7, def = 8, berserker = 9 }, + ROGUE = { stealth = 7, shadowdance = 7 }, + HERO = { bear = 9, cat = 7, prowl = 8, stealth = 7, shadowdance = 7, battle = 7, def = 8, berserker = 9 }, + }, + }, + visibility = { + vehicleui = false, + }, + }, + [7] = { + enabled = false, + }, + [8] = { + enabled = false, + }, + [9] = { + enabled = false, + }, + [10] = { + enabled = false, + }, +} + +local defaults = { + profile = { + actionbars = abdefaults, + } +} + +function BT4ActionBars:OnInitialize() + self.db = Bartender4.db:RegisterNamespace("ActionBars", defaults) + + -- fetch the prototype information + ActionBar = Bartender4.ActionBar + ActionBar_MT = {__index = ActionBar} +end + + +local LBF = LibStub("LibButtonFacade", true) + +-- setup the 10 actionbars +local first = true +function BT4ActionBars:OnEnable() + if first then + self.playerclass = select(2, UnitClass("player")) + self.actionbars = {} + + for i=1,10 do + local config = self.db.profile.actionbars[i] + if config.enabled then + self.actionbars[i] = self:Create(i, config) + else + self:CreateBarOption(i, self.disabledoptions) + end + end + + first = nil + end + + self:RegisterEvent("UPDATE_BINDINGS", "ReassignBindings") + self:ReassignBindings() +end + +function BT4ActionBars:SetupOptions() + if not self.options then + -- empty table to hold the bar options + self.options = {} + + -- template for disabled bars + self.disabledoptions = { + general = { + type = "group", + name = L["General Settings"], + cmdInline = true, + order = 1, + args = { + enabled = { + type = "toggle", + name = L["Enabled"], + desc = L["Enable/Disable the bar."], + set = function(info, v) if v then BT4ActionBars:EnableBar(info[2]) end end, + get = function() return false end, + } + } + } + } + + -- iterate over bars and create their option tables + for i=1,10 do + local config = self.db.profile.actionbars[i] + if config.enabled then + self:CreateBarOption(i) + else + self:CreateBarOption(i, self.disabledoptions) + end + end + end +end + +-- Applys the config in the current profile to all active Bars +function BT4ActionBars:ApplyConfig() + for i=1,10 do + local config = self.db.profile.actionbars[i] + -- make sure the bar has its current config object if it exists already + if self.actionbars[i] then + self.actionbars[i].config = config + end + if config.enabled then + self:EnableBar(i) + else + self:DisableBar(i) + end + end +end + +-- we do not allow to disable the actionbars module +function BT4ActionBars:ToggleModule() + return +end + +function BT4ActionBars:UpdateButtons(force) + for i,v in ipairs(self.actionbars) do + for j,button in ipairs(v.buttons) do + button:UpdateAction(force) + end + end +end + +function BT4ActionBars:ReassignBindings() + if InCombatLockdown() then return end + if not self.actionbars or not self.actionbars[1] then return end + local frame = self.actionbars[1] + ClearOverrideBindings(frame) + for i = 1,min(#frame.buttons, 12) do + local button, real_button = ("ACTIONBUTTON%d"):format(i), ("BT4Button%d"):format(i) + for k=1, select('#', GetBindingKey(button)) do + local key = select(k, GetBindingKey(button)) + SetOverrideBindingClick(frame, false, key, real_button) + end + end + + for i = 1, 120 do + -- rename old bindings from Secure to only + local button, real_button = ("CLICK BT4Button%dSecure:LeftButton"):format(i), ("BT4Button%d"):format(i) + + for k=1, select('#', GetBindingKey(button)) do + local key = select(k, GetBindingKey(button)) + if key and key ~= "" then + SetBindingClick(key, real_button, "LeftButton") + end + end + end + SaveBindings(GetCurrentBindingSet() or 1) +end + +-- Creates a new bar object based on the id and the specified config +function BT4ActionBars:Create(id, config) + local id = tostring(id) + local bar = setmetatable(Bartender4.StateBar:Create(id, config, (L["Bar %s"]):format(id)), ActionBar_MT) + bar.module = self + + self:CreateBarOption(id) + + bar:ApplyConfig() + + return bar +end + +function BT4ActionBars:DisableBar(id) + id = tonumber(id) + local bar = self.actionbars[id] + if not bar then return end + + bar.config.enabled = false + bar:Disable() + self:CreateBarOption(id, self.disabledoptions) +end + +function BT4ActionBars:EnableBar(id) + id = tonumber(id) + local bar = self.actionbars[id] + local config = self.db.profile.actionbars[id] + config.enabled = true + if not bar then + bar = self:Create(id, config) + self.actionbars[id] = bar + else + bar.disabled = nil + self:CreateBarOption(id) + bar:ApplyConfig(config) + end + if not Bartender4.Locked then + bar:Unlock() + end +end + +function BT4ActionBars:GetAll() + return pairs(self.actionbars) +end + +function BT4ActionBars:ForAll(method, ...) + for _, bar in self:GetAll() do + local func = bar[method] + if func then + func(bar, ...) + end + end +end + +function BT4ActionBars:ForAllButtons(...) + self:ForAll("ForAll", ...) +end diff --git a/ActionButton.lua b/ActionButton.lua index b5582e0..2a0b697 100644 --- a/ActionButton.lua +++ b/ActionButton.lua @@ -1,514 +1,515 @@ ---[[ - Copyright (c) 2009, Hendrik "Nevcairiel" Leppkes < h.leppkes at gmail dot com > - All rights reserved. -]] ---[[ - Action Button Template - - Note: - Some IDs produce a special behaviour! - - Button ID 132 (Last Button in Possess Bar) Creates a Leave Vehicle Button -]] - -local specialButtons = { - [132] = { icon = "Interface\\Icons\\Spell_Shadow_SacrificialShield", tooltip = LEAVE_VEHICLE}, -- Vehicle Leave Button -} - -local Button = CreateFrame("CheckButton") -local Button_MT = {__index = Button} - -local onEnter, onLeave, onUpdate, onDragUpdate - --- upvalues -local _G = _G -local format = string.format -local IsUsableAction, IsActionInRange, GetActionTexture, ActionHasRange = IsUsableAction, IsActionInRange, GetActionTexture, ActionHasRange -local ATTACK_BUTTON_FLASH_TIME, RANGE_INDICATOR, TOOLTIP_UPDATE_TIME = ATTACK_BUTTON_FLASH_TIME, RANGE_INDICATOR, TOOLTIP_UPDATE_TIME - -local Bartender4 = Bartender4 -local LBF = LibStub("LibButtonFacade", true) -local KeyBound = LibStub("LibKeyBound-1.0") - -Bartender4.Button = {} -Bartender4.Button.prototype = Button -Button.BT4init = true -function Bartender4.Button:Create(id, parent) - local absid = (parent.id - 1) * 12 + id - local name = ("BT4Button%d"):format(absid) - local button = setmetatable(CreateFrame("CheckButton", name, parent, "ActionBarButtonTemplate"), Button_MT) - -- work around for "blocked" message when using /click macros - GetClickFrame(name) - - -- Backwards Compat to pre-4.2.0 button names/layout - _G[name .. "Secure"] = button - button.Secure = button - - button.rid = id - button.id = absid - button.parent = parent - button.stateactions = {} - - button:SetRealNormalTexture("") - local oldNT = _G[("%sNormalTexture"):format(name)] - oldNT:Hide() - - button.normalTexture = button:CreateTexture(("%sBTNT"):format(name)) - button.normalTexture:SetWidth(66) - button.normalTexture:SetHeight(66) - button.normalTexture:ClearAllPoints() - button.normalTexture:SetPoint("CENTER", 0, -1) - button.normalTexture:Show() - - - --button:SetFrameStrata("MEDIUM") - - -- overwrite some scripts with out customized versions - button:SetScript("OnEnter", onEnter) - button:SetScript("OnUpdate", onUpdate) - button:SetScript("OnDragStart", onDragUpdate) - --button:SetScript("OnReceiveDrag", nil) - - button.icon = _G[("%sIcon"):format(name)] - button.border = _G[("%sBorder"):format(name)] - button.cooldown = _G[("%sCooldown"):format(name)] - button.macroName = _G[("%sName"):format(name)] - button.hotkey = _G[("%sHotKey"):format(name)] - button.count = _G[("%sCount"):format(name)] - button.flash = _G[("%sFlash"):format(name)] - button.flash:Hide() - - button:SetAttribute("type", "action") - button:SetAttribute("action", absid) - button:SetAttribute("useparent-unit", nil); - button:SetAttribute("useparent-actionpage", nil); - button:SetAttribute("buttonlock", Bartender4.db.profile.buttonlock) - - button:UpdateSelfCast() - - parent:WrapScript(button, "OnDragStart", [[ - local action = self:GetAttribute("action") - if action and (not self:GetAttribute("buttonlock") or IsModifiedClick("PICKUPACTION")) then - return "action", action - end - ]], [[ - control:RunFor(self, self:GetAttribute("UpdateAutoAssist")) - ]]) - - parent:WrapScript(button, "OnReceiveDrag", [[]], [[ - control:RunFor(self, self:GetAttribute("UpdateAutoAssist")) - ]]) - - button:SetAttribute("UpdateAutoAssist", [[ - self:SetAttribute("assisttype", nil) - self:SetAttribute("unit", nil) - if self:GetAttribute("autoassist") then - local action = self:GetAttribute("action") - local type, id, subtype = GetActionInfo(action) - if type == "spell" and id > 0 then - if IsHelpfulSpell(id, subtype) then - self:SetAttribute("assisttype", 1) - self:SetAttribute("unit", G_assist_help) - elseif IsHarmfulSpell(id, subtype) then - self:SetAttribute("assisttype", 2) - self:SetAttribute("unit", G_assist_harm) - end - end - end - ]]) - - button:SetAttribute('_childupdate-init', [[ - control:RunFor(self, self:GetAttribute("UpdateAutoAssist")) - ]]) - - button:SetAttribute('_childupdate-state', [[ - self:SetAttribute("state", message) - local action = self:GetAttribute("action-" .. message) - if not action then return end - if action == 132 then - self:SetAttribute("type", "click") - if not self:GetAttribute("isSpecial") then - self:SetAttribute("showgrid", self:GetAttribute("showgrid") + 1) - self:SetAttribute("isSpecial", true) - end - else - if action > 120 and action <= 126 then - self:SetAttribute("type", "click") - else - self:SetAttribute("type", "action") - end - if self:GetAttribute("isSpecial") then - self:SetAttribute("isSpecial", nil) - self:SetAttribute("showgrid", max(0, self:GetAttribute("showgrid") - 1)) - end - end - self:SetAttribute("action", action) - - -- fix unit on state change - if action <= 120 and self:GetAttribute("autoassist") then - control:RunFor(self, self:GetAttribute("UpdateAutoAssist")) - else - self:SetAttribute("unit", nil) - end - G_state = message - ]]) - - button:SetAttribute('_childupdate-assist-help', [[ - G_assist_help = message - if self:GetAttribute("assisttype") == 1 then - self:SetAttribute("unit", message) - end - ]]) - - button:SetAttribute('_childupdate-assist-harm', [[ - G_assist_harm = message - if self:GetAttribute("assisttype") == 2 then - self:SetAttribute("unit", message) - end - ]]) - - button.SecureInit = true - - if LBF and parent.LBFGroup then - local group = parent.LBFGroup - group:AddButton(button) - end - - if button.parent.config.showgrid then - button:ShowGrid() - end - - --self:UpdateAction(true) - button:UpdateHotkeys() - button:UpdateUsable() - button:UpdateGrid() - button:ToggleButtonElements() - - for page = 0,11,1 do - local action = (page == 0) and button.id or (button.rid + (page - 1) * 12) - button:SetStateAction(page, action) - end - - return button -end - -function onDragUpdate(self) - ActionButton_UpdateState(self) - ActionButton_UpdateFlash(self) -end - -function onEnter(self) - if not (Bartender4.db.profile.tooltip == "nocombat" and InCombatLockdown()) and Bartender4.db.profile.tooltip ~= "disabled" then - self:SetTooltip(self) - end - KeyBound:Set(self) -end - -function onUpdate(self, elapsed) - if self.flashing == 1 then - self.flashtime = self.flashtime - elapsed - if self.flashtime <= 0 then - local overtime = -self.flashtime - if overtime >= ATTACK_BUTTON_FLASH_TIME then - overtime = 0 - end - self.flashtime = ATTACK_BUTTON_FLASH_TIME - overtime - - local flashTexture = self.flash - if flashTexture:IsShown() then - flashTexture:Hide() - else - flashTexture:Show() - end - end - end - - if self.rangeTimer then - self.rangeTimer = self.rangeTimer - elapsed - if self.rangeTimer <= 0 then - local valid = IsActionInRange(self.action) - self.outOfRange = (valid == 0) - - local oor = Bartender4.db.profile.outofrange - if oor == "hotkey" then - local hotkey = self.hotkey - local hkshown = hotkey:GetText() == RANGE_INDICATOR - if valid and hkshown then - hotkey:Show() - elseif hkshown then - hotkey:Hide() - end - - if self.outOfRange then - local oorc = Bartender4.db.profile.colors.range - hotkey:SetVertexColor(oorc.r, oorc.g, oorc.b) - else - hotkey:SetVertexColor(1.0, 1.0, 1.0) - end - elseif oor == "button" then - self:UpdateUsable() - end - self.rangeTimer = TOOLTIP_UPDATE_TIME - end - end -end -Bartender4.Button.onUpdate = onUpdate - -local function updateIcon(self) - if self.action then - if specialButtons[self.action] then - if not LBF then - self.normalTexture:SetTexCoord(0, 0, 0, 0) - end - self.icon:SetTexture(specialButtons[self.action].icon) - self.icon:Show() - self:UpdateUsable() - elseif not LBF then - if GetActionTexture(self.action) then - self.normalTexture:SetTexCoord(0, 0, 0, 0) - else - self.normalTexture:SetTexCoord(-0.15, 1.15, -0.15, 1.17) - end - end - end -end - -local function updateFunc(self) - local parent = self:GetParent() - if not self.BT4init or not parent.BT4BarType then return end - self:UpdateRange() - updateIcon(self) - - if self.SecureInit and not InCombatLockdown() then - local parent = self:GetParent() - parent:SetFrameRef("upd", self) - parent:Execute([[ - local frame = self:GetFrameRef("upd") - control:RunFor(frame, frame:GetAttribute("UpdateAutoAssist")) - ]]) - end -end - -hooksecurefunc("ActionButton_Update", updateFunc) - -Button.SetRealNormalTexture = Button.SetNormalTexture -function Button:SetNormalTexture(...) - self.normalTexture:SetTexture(...) -end - -Button.GetRealNormalTexture = Button.GetNormalTexture -function Button:GetNormalTexture() - return self.normalTexture -end - -function Button:UpdateStates() - self:SetAttribute("autoassist", self.parent.config.autoassist) -end - -function Button:SetStateAction(state, action) - self.stateactions[state] = action - self:RefreshStateAction(state) -end - -function Button:RefreshStateAction(state) - local state = tonumber(state or self:GetAttribute("state")) or 0 - local action = self.stateactions[state] - assert(action, ("No valid action for state %d on button %d of Bar %d"):format(state, self.rid, self.parent.id)) - self:SetAttribute("action-"..state, action) - - if action > 120 and action <= 126 then - self:SetAttribute("clickbutton", _G["VehicleMenuBarActionButton"..tostring(action-120)]) - elseif action == 132 then - self:SetAttribute("clickbutton", PossessButton2) - end -end - -function Button:UpdateSelfCast() - self:SetAttribute("checkselfcast", Bartender4.db.profile.selfcastmodifier and true or nil) - self:SetAttribute("checkfocuscast", Bartender4.db.profile.focuscastmodifier and true or nil) - self:SetAttribute("unit2", Bartender4.db.profile.selfcastrightclick and "player" or nil) -end - -function Button:GetActionID() - return self.action -end - -function Button:Update() - self:UpdateAction(true) - self:UpdateHotkeys() - self:ToggleButtonElements() - self:UpdateRange() -end - -function Button:UpdateAction(force) - ActionButton_UpdateAction(self) -end - -function Button:ToggleButtonElements() - if self.parent.config.hidemacrotext then - self.macroName:Hide() - else - self.macroName:Show() - end -end - -hooksecurefunc("ActionButton_UpdateHotkeys", function(self, ...) - local parent = self:GetParent() - if not self.BT4init or not parent.BT4BarType then return end - - self:UpdateHotkeys() -end) - -function Button:UpdateHotkeys() - local key = self:GetHotkey() or "" - local hotkey = self.hotkey - - if key == "" or self.parent.config.hidehotkey then - hotkey:SetText(RANGE_INDICATOR) - hotkey:SetPoint("TOPLEFT", self, "TOPLEFT", 1, -2) - hotkey:Hide() - else - hotkey:SetText(key) - hotkey:SetPoint("TOPLEFT", self, "TOPLEFT", -2, -2) - hotkey:Show() - end -end - -function Button:GetHotkey() - local key = ((self.id <= 12) and GetBindingKey(format("ACTIONBUTTON%d", self.id))) or GetBindingKey("CLICK "..self:GetName()..":LeftButton") - return key and KeyBound:ToShortKey(key) -end - -function Button:GetBindings() - local keys, binding = "" - - if self.id <= 12 then - binding = format("ACTIONBUTTON%d", self.id) - for i = 1, select('#', GetBindingKey(binding)) do - local hotKey = select(i, GetBindingKey(binding)) - if keys ~= "" then - keys = keys .. ', ' - end - keys = keys .. GetBindingText(hotKey,'KEY_') - end - end - - binding = "CLICK "..self:GetName()..":LeftButton" - for i = 1, select('#', GetBindingKey(binding)) do - local hotKey = select(i, GetBindingKey(binding)) - if keys ~= "" then - keys = keys .. ', ' - end - keys = keys .. GetBindingText(hotKey,'KEY_') - end - - return keys -end - -function Button:SetKey(key) - if self.id <= 12 then - SetBinding(key, format("ACTIONBUTTON%d", self.id)) - else - SetBindingClick(key, self:GetName(), 'LeftButton') - end -end - -function Button:ClearBindings() - if self.id <= 12 then - local binding = format("ACTIONBUTTON%d", self.id) - while GetBindingKey(binding) do - SetBinding(GetBindingKey(binding), nil) - end - end - local binding = "CLICK "..self:GetName()..":LeftButton" - while GetBindingKey(binding) do - SetBinding(GetBindingKey(binding), nil) - end -end - -local actionTmpl = "BT4 Bar %d Button %d" -function Button:GetActionName() - return format(actionTmpl, self.parent.id, self.rid) -end - -hooksecurefunc("ActionButton_UpdateUsable", function(self) - if self.BT4init then - self:UpdateUsable() - end -end) - -function Button:UpdateUsable() - local isUsable, notEnoughMana = IsUsableAction(self.action) - local icon = self.icon - - if Bartender4.db.profile.outofrange == "button" and self.outOfRange then - local oorc = Bartender4.db.profile.colors.range - icon:SetVertexColor(oorc.r, oorc.g, oorc.b) - else - if isUsable or specialButtons[self.action] then - icon:SetVertexColor(1.0, 1.0, 1.0) - elseif notEnoughMana then - local oomc = Bartender4.db.profile.colors.mana - icon:SetVertexColor(oomc.r, oomc.g, oomc.b) - else - icon:SetVertexColor(0.4, 0.4, 0.4) - end - end -end - -function Button:UpdateRange() - if Bartender4.db.profile.outofrange == "none" or not ActionHasRange(self.action) then - self.rangeTimer = nil - self.outOfRange = nil - end - self.hotkey:SetVertexColor(1.0, 1.0, 1.0) - self:UpdateUsable() - onUpdate(self, 10) -end - -function Button:SetTooltip() - if ( GetCVar("UberTooltips") == "1" ) then - GameTooltip_SetDefaultAnchor(GameTooltip, self) - else - GameTooltip:SetOwner(self, "ANCHOR_RIGHT") - end - - if specialButtons[self.action] then - GameTooltip:SetText(specialButtons[self.action].tooltip) - self.UpdateTooltip = self.SetTooltip - else - if ( GameTooltip:SetAction(self.action) ) then - self.UpdateTooltip = self.SetTooltip - else - self.UpdateTooltip = nil - end - end -end - -function Button:UpdateGrid() - if self:GetAttribute("showgrid") > 0 then - ActionButton_ShowGrid(self) - else - ActionButton_HideGrid(self) - end -end - -function Button:ShowGrid() - if not self.gridShown then - self.gridShown = true - self:SetAttribute("showgrid", self:GetAttribute("showgrid") + 1) - self:UpdateGrid() - end -end - -function Button:HideGrid() - if self.gridShown then - self.gridShown = nil - self:SetAttribute("showgrid", max(0, self:GetAttribute("showgrid") - 1)) - self:UpdateGrid() - end -end - -function Button:ClearSetPoint(...) - self:ClearAllPoints() - self:SetPoint(...) -end +--[[ + Copyright (c) 2009, Hendrik "Nevcairiel" Leppkes < h.leppkes at gmail dot com > + All rights reserved. +]] +--[[ + Action Button Template + + Note: + Some IDs produce a special behaviour! + - Button ID 132 (Last Button in Possess Bar) Creates a Leave Vehicle Button +]] + +local specialButtons = { + [132] = { icon = "Interface\\Icons\\Spell_Shadow_SacrificialShield", tooltip = LEAVE_VEHICLE}, -- Vehicle Leave Button +} + +local Button = CreateFrame("CheckButton") +local Button_MT = {__index = Button} + +local onEnter, onLeave, onUpdate, onDragUpdate + +-- upvalues +local _G = _G +local format = string.format +local IsUsableAction, IsActionInRange, GetActionTexture, ActionHasRange = IsUsableAction, IsActionInRange, GetActionTexture, ActionHasRange +local ATTACK_BUTTON_FLASH_TIME, RANGE_INDICATOR, TOOLTIP_UPDATE_TIME = ATTACK_BUTTON_FLASH_TIME, RANGE_INDICATOR, TOOLTIP_UPDATE_TIME + +local Bartender4 = Bartender4 +local LBF = LibStub("LibButtonFacade", true) +local KeyBound = LibStub("LibKeyBound-1.0") + +Bartender4.Button = {} +Bartender4.Button.prototype = Button +Button.BT4init = true +function Bartender4.Button:Create(id, parent) + local absid = (parent.id - 1) * 12 + id + local name = ("BT4Button%d"):format(absid) + local button = setmetatable(CreateFrame("CheckButton", name, parent, "ActionBarButtonTemplate"), Button_MT) + -- work around for "blocked" message when using /click macros + GetClickFrame(name) + + -- Backwards Compat to pre-4.2.0 button names/layout + _G[name .. "Secure"] = button + button.Secure = button + + button.rid = id + button.id = absid + button.parent = parent + button.stateactions = {} + + button:SetRealNormalTexture("") + local oldNT = _G[("%sNormalTexture"):format(name)] + oldNT:Hide() + + button.normalTexture = button:CreateTexture(("%sBTNT"):format(name)) + button.normalTexture:SetWidth(66) + button.normalTexture:SetHeight(66) + button.normalTexture:ClearAllPoints() + button.normalTexture:SetPoint("CENTER", 0, -1) + button.normalTexture:Show() + + + --button:SetFrameStrata("MEDIUM") + + -- overwrite some scripts with out customized versions + button:SetScript("OnEnter", onEnter) + button:SetScript("OnUpdate", onUpdate) + button:SetScript("OnDragStart", onDragUpdate) + --button:SetScript("OnReceiveDrag", nil) + + button.icon = _G[("%sIcon"):format(name)] + button.border = _G[("%sBorder"):format(name)] + button.cooldown = _G[("%sCooldown"):format(name)] + button.macroName = _G[("%sName"):format(name)] + button.hotkey = _G[("%sHotKey"):format(name)] + button.count = _G[("%sCount"):format(name)] + button.flash = _G[("%sFlash"):format(name)] + button.flash:Hide() + + button:SetAttribute("type", "action") + button:SetAttribute("action", absid) + button:SetAttribute("useparent-unit", nil); + button:SetAttribute("useparent-actionpage", nil); + button:SetAttribute("buttonlock", Bartender4.db.profile.buttonlock) + + button:UpdateSelfCast() + + parent:WrapScript(button, "OnDragStart", [[ + local action = self:GetAttribute("action") + if action and (not self:GetAttribute("buttonlock") or IsModifiedClick("PICKUPACTION")) then + return "action", action + end + ]], [[ + control:RunFor(self, self:GetAttribute("UpdateAutoAssist")) + ]]) + + parent:WrapScript(button, "OnReceiveDrag", [[]], [[ + control:RunFor(self, self:GetAttribute("UpdateAutoAssist")) + ]]) + + button:SetAttribute("UpdateAutoAssist", [[ + self:SetAttribute("assisttype", nil) + self:SetAttribute("unit", nil) + if self:GetAttribute("autoassist") then + local action = self:GetAttribute("action") + local type, id, subtype = GetActionInfo(action) + if type == "spell" and id > 0 then + if IsHelpfulSpell(id, subtype) then + self:SetAttribute("assisttype", 1) + self:SetAttribute("unit", G_assist_help) + elseif IsHarmfulSpell(id, subtype) then + self:SetAttribute("assisttype", 2) + self:SetAttribute("unit", G_assist_harm) + end + end + end + ]]) + + button:SetAttribute('_childupdate-init', [[ + control:RunFor(self, self:GetAttribute("UpdateAutoAssist")) + ]]) + + button:SetAttribute('_childupdate-state', [[ + self:SetAttribute("state", message) + local action = self:GetAttribute("action-" .. message) + if not action then return end + if action == 132 then + self:SetAttribute("type", "click") + if not self:GetAttribute("isSpecial") then + self:SetAttribute("showgrid", self:GetAttribute("showgrid") + 1) + self:SetAttribute("isSpecial", true) + end + else + if action > 120 and action <= 126 then + self:SetAttribute("type", "click") + else + self:SetAttribute("type", "action") + end + if self:GetAttribute("isSpecial") then + self:SetAttribute("isSpecial", nil) + self:SetAttribute("showgrid", max(0, self:GetAttribute("showgrid") - 1)) + end + end + self:SetAttribute("action", action) + + -- fix unit on state change + if action <= 120 and self:GetAttribute("autoassist") then + control:RunFor(self, self:GetAttribute("UpdateAutoAssist")) + else + self:SetAttribute("unit", nil) + end + G_state = message + ]]) + + button:SetAttribute('_childupdate-assist-help', [[ + G_assist_help = message + if self:GetAttribute("assisttype") == 1 then + self:SetAttribute("unit", message) + end + ]]) + + button:SetAttribute('_childupdate-assist-harm', [[ + G_assist_harm = message + if self:GetAttribute("assisttype") == 2 then + self:SetAttribute("unit", message) + end + ]]) + + button.SecureInit = true + + if LBF and parent.LBFGroup then + local group = parent.LBFGroup + group:AddButton(button) + end + + if button.parent.config.showgrid then + button:ShowGrid() + end + + --self:UpdateAction(true) + button:UpdateHotkeys() + button:UpdateUsable() + button:UpdateGrid() + button:ToggleButtonElements() + + for page = 0,11,1 do + local action = (page == 0) and button.id or (button.rid + (page - 1) * 12) + button:SetStateAction(page, action) + end + + return button +end + +function onDragUpdate(self) + ActionButton_UpdateState(self) + ActionButton_UpdateFlash(self) +end + +function onEnter(self) + if not (Bartender4.db.profile.tooltip == "nocombat" and InCombatLockdown()) and Bartender4.db.profile.tooltip ~= "disabled" then + self:SetTooltip(self) + end + KeyBound:Set(self) +end + +function onUpdate(self, elapsed) + if self.flashing == 1 then + self.flashtime = self.flashtime - elapsed + if self.flashtime <= 0 then + local overtime = -self.flashtime + if overtime >= ATTACK_BUTTON_FLASH_TIME then + overtime = 0 + end + self.flashtime = ATTACK_BUTTON_FLASH_TIME - overtime + + local flashTexture = self.flash + if flashTexture:IsShown() then + flashTexture:Hide() + else + flashTexture:Show() + end + end + end + + if self.rangeTimer then + self.rangeTimer = self.rangeTimer - elapsed + if self.rangeTimer <= 0 then + local valid = IsActionInRange(self.action) + self.outOfRange = (valid == 0) + + local oor = Bartender4.db.profile.outofrange + if oor == "hotkey" then + local hotkey = self.hotkey + local hkshown = hotkey:GetText() == RANGE_INDICATOR + if valid and hkshown then + hotkey:Show() + elseif hkshown then + hotkey:Hide() + end + + if self.outOfRange then + local oorc = Bartender4.db.profile.colors.range + hotkey:SetVertexColor(oorc.r, oorc.g, oorc.b) + else + hotkey:SetVertexColor(1.0, 1.0, 1.0) + end + elseif oor == "button" then + self:UpdateUsable() + end + self.rangeTimer = TOOLTIP_UPDATE_TIME + end + end +end +Bartender4.Button.onUpdate = onUpdate + +local function updateIcon(self) + if self.action then + if specialButtons[self.action] then + if not LBF then + self.normalTexture:SetTexCoord(0, 0, 0, 0) + end + self.icon:SetTexture(specialButtons[self.action].icon) + self.icon:Show() + self:UpdateUsable() + elseif not LBF then + if GetActionTexture(self.action) then + self.normalTexture:SetTexCoord(0, 0, 0, 0) + else + self.normalTexture:SetTexCoord(-0.15, 1.15, -0.15, 1.17) + end + end + end +end + +local function updateFunc(self) + local parent = self:GetParent() + if not self.BT4init or not parent.BT4BarType then return end + self:UpdateRange() + updateIcon(self) + + if self.SecureInit and not InCombatLockdown() then + local parent = self:GetParent() + parent:SetFrameRef("upd", self) + parent:Execute([[ + local frame = self:GetFrameRef("upd") + control:RunFor(frame, frame:GetAttribute("UpdateAutoAssist")) + ]]) + end +end + +hooksecurefunc("ActionButton_Update", updateFunc) + +Button.SetRealNormalTexture = Button.SetNormalTexture +function Button:SetNormalTexture(...) + self.normalTexture:SetTexture(...) +end + +Button.GetRealNormalTexture = Button.GetNormalTexture +function Button:GetNormalTexture() + return self.normalTexture +end + +function Button:UpdateStates() + self:SetAttribute("autoassist", self.parent.config.autoassist) +end + +function Button:SetStateAction(state, action) + self.stateactions[state] = action + self:RefreshStateAction(state) +end + +function Button:RefreshStateAction(state) + local state = tonumber(state or self:GetAttribute("state")) or 0 + local action = self.stateactions[state] + assert(action, ("No valid action for state %d on button %d of Bar %d"):format(state, self.rid, self.parent.id)) + self:SetAttribute("action-"..state, action) + + if action > 120 and action <= 126 then + self:SetAttribute("clickbutton", _G["VehicleMenuBarActionButton"..tostring(action-120)]) + elseif action == 132 then + self:SetAttribute("clickbutton", PossessButton2) + end +end + +function Button:UpdateSelfCast() + self:SetAttribute("checkmouseovercast", true) + self:SetAttribute("checkselfcast", Bartender4.db.profile.selfcastmodifier and true or nil) + self:SetAttribute("checkfocuscast", Bartender4.db.profile.focuscastmodifier and true or nil) + self:SetAttribute("unit2", Bartender4.db.profile.selfcastrightclick and "player" or nil) +end + +function Button:GetActionID() + return self.action +end + +function Button:Update() + self:UpdateAction(true) + self:UpdateHotkeys() + self:ToggleButtonElements() + self:UpdateRange() +end + +function Button:UpdateAction(force) + ActionButton_UpdateAction(self) +end + +function Button:ToggleButtonElements() + if self.parent.config.hidemacrotext then + self.macroName:Hide() + else + self.macroName:Show() + end +end + +hooksecurefunc("ActionButton_UpdateHotkeys", function(self, ...) + local parent = self:GetParent() + if not self.BT4init or not parent.BT4BarType then return end + + self:UpdateHotkeys() +end) + +function Button:UpdateHotkeys() + local key = self:GetHotkey() or "" + local hotkey = self.hotkey + + if key == "" or self.parent.config.hidehotkey then + hotkey:SetText(RANGE_INDICATOR) + hotkey:SetPoint("TOPLEFT", self, "TOPLEFT", 1, -2) + hotkey:Hide() + else + hotkey:SetText(key) + hotkey:SetPoint("TOPLEFT", self, "TOPLEFT", -2, -2) + hotkey:Show() + end +end + +function Button:GetHotkey() + local key = ((self.id <= 12) and GetBindingKey(format("ACTIONBUTTON%d", self.id))) or GetBindingKey("CLICK "..self:GetName()..":LeftButton") + return key and KeyBound:ToShortKey(key) +end + +function Button:GetBindings() + local keys, binding = "" + + if self.id <= 12 then + binding = format("ACTIONBUTTON%d", self.id) + for i = 1, select('#', GetBindingKey(binding)) do + local hotKey = select(i, GetBindingKey(binding)) + if keys ~= "" then + keys = keys .. ', ' + end + keys = keys .. GetBindingText(hotKey,'KEY_') + end + end + + binding = "CLICK "..self:GetName()..":LeftButton" + for i = 1, select('#', GetBindingKey(binding)) do + local hotKey = select(i, GetBindingKey(binding)) + if keys ~= "" then + keys = keys .. ', ' + end + keys = keys .. GetBindingText(hotKey,'KEY_') + end + + return keys +end + +function Button:SetKey(key) + if self.id <= 12 then + SetBinding(key, format("ACTIONBUTTON%d", self.id)) + else + SetBindingClick(key, self:GetName(), 'LeftButton') + end +end + +function Button:ClearBindings() + if self.id <= 12 then + local binding = format("ACTIONBUTTON%d", self.id) + while GetBindingKey(binding) do + SetBinding(GetBindingKey(binding), nil) + end + end + local binding = "CLICK "..self:GetName()..":LeftButton" + while GetBindingKey(binding) do + SetBinding(GetBindingKey(binding), nil) + end +end + +local actionTmpl = "BT4 Bar %d Button %d" +function Button:GetActionName() + return format(actionTmpl, self.parent.id, self.rid) +end + +hooksecurefunc("ActionButton_UpdateUsable", function(self) + if self.BT4init then + self:UpdateUsable() + end +end) + +function Button:UpdateUsable() + local isUsable, notEnoughMana = IsUsableAction(self.action) + local icon = self.icon + + if Bartender4.db.profile.outofrange == "button" and self.outOfRange then + local oorc = Bartender4.db.profile.colors.range + icon:SetVertexColor(oorc.r, oorc.g, oorc.b) + else + if isUsable or specialButtons[self.action] then + icon:SetVertexColor(1.0, 1.0, 1.0) + elseif notEnoughMana then + local oomc = Bartender4.db.profile.colors.mana + icon:SetVertexColor(oomc.r, oomc.g, oomc.b) + else + icon:SetVertexColor(0.4, 0.4, 0.4) + end + end +end + +function Button:UpdateRange() + if Bartender4.db.profile.outofrange == "none" or not ActionHasRange(self.action) then + self.rangeTimer = nil + self.outOfRange = nil + end + self.hotkey:SetVertexColor(1.0, 1.0, 1.0) + self:UpdateUsable() + onUpdate(self, 10) +end + +function Button:SetTooltip() + if ( GetCVar("UberTooltips") == "1" ) then + GameTooltip_SetDefaultAnchor(GameTooltip, self) + else + GameTooltip:SetOwner(self, "ANCHOR_RIGHT") + end + + if specialButtons[self.action] then + GameTooltip:SetText(specialButtons[self.action].tooltip) + self.UpdateTooltip = self.SetTooltip + else + if ( GameTooltip:SetAction(self.action) ) then + self.UpdateTooltip = self.SetTooltip + else + self.UpdateTooltip = nil + end + end +end + +function Button:UpdateGrid() + if self:GetAttribute("showgrid") > 0 then + ActionButton_ShowGrid(self) + else + ActionButton_HideGrid(self) + end +end + +function Button:ShowGrid() + if not self.gridShown then + self.gridShown = true + self:SetAttribute("showgrid", self:GetAttribute("showgrid") + 1) + self:UpdateGrid() + end +end + +function Button:HideGrid() + if self.gridShown then + self.gridShown = nil + self:SetAttribute("showgrid", max(0, self:GetAttribute("showgrid") - 1)) + self:UpdateGrid() + end +end + +function Button:ClearSetPoint(...) + self:ClearAllPoints() + self:SetPoint(...) +end diff --git a/BagBar.lua b/BagBar.lua index a1db751..dfd4163 100644 --- a/BagBar.lua +++ b/BagBar.lua @@ -1,124 +1,124 @@ ---[[ - Copyright (c) 2009, Hendrik "Nevcairiel" Leppkes < h.leppkes at gmail dot com > - All rights reserved. -]] -local L = LibStub("AceLocale-3.0"):GetLocale("Bartender4") --- register module -local BagBarMod = Bartender4:NewModule("BagBar", "AceHook-3.0") - --- fetch upvalues -local ButtonBar = Bartender4.ButtonBar.prototype -local LBF = LibStub("LibButtonFacade", true) - --- create prototype information -local BagBar = setmetatable({}, {__index = ButtonBar}) - -local table_insert = table.insert - -local defaults = { profile = Bartender4:Merge({ - enabled = true, - keyring = false, - onebag = false, - visibility = { - possess = false, - }, -}, Bartender4.ButtonBar.defaults) } - -function BagBarMod:OnInitialize() - self.db = Bartender4.db:RegisterNamespace("BagBar", defaults) - self:SetEnabledState(self.db.profile.enabled) -end - -local noopFunc = function() end - -function BagBarMod:OnEnable() - if not self.bar then - self.bar = setmetatable(Bartender4.ButtonBar:Create("BagBar", self.db.profile, L["Bag Bar"]), {__index = BagBar}) - end - self.bar:Enable() - self:ToggleOptions() - self:ApplyConfig() -end - -function BagBarMod:ApplyConfig() - self.bar:ApplyConfig(self.db.profile) -end - -function BagBar:ApplyConfig(config) - ButtonBar.ApplyConfig(self, config) - - if not self.config.position.x then - self:ClearSetPoint("CENTER", 142, -18) - self:SavePosition() - end - - self:FeedButtons() - self:UpdateButtonLayout() -end - -function clearSetPoint(btn, ...) - btn:ClearAllPoints() - btn:SetPoint(...) -end - -BagBar.button_width = 30 -BagBar.button_height = 30 -BagBarMod.button_count = 5 -function BagBar:FeedButtons() - local count = 1 - if self.buttons then - while next(self.buttons) do - local btn = table.remove(self.buttons) - btn:Hide() - btn:SetParent(UIParent) - btn:ClearSetPoint("CENTER") - if btn ~= KeyRingButton and btn.LBFButtonData then - local group = self.LBFGroup - group:RemoveButton(btn) - end - end - else - self.buttons = {} - end - - if self.config.keyring then - table_insert(self.buttons, KeyRingButton) - count = count + 1 - end - - if not self.config.onebag then - table_insert(self.buttons, CharacterBag3Slot) - table_insert(self.buttons, CharacterBag2Slot) - table_insert(self.buttons, CharacterBag1Slot) - table_insert(self.buttons, CharacterBag0Slot) - count = count + 4 - end - - table_insert(self.buttons, MainMenuBarBackpackButton) - - for i,v in pairs(self.buttons) do - v:SetParent(self) - v:Show() - if v ~= KeyRingButton then - v:SetNormalTexture("") - - if LBF then - local group = self.LBFGroup - if not v.LBFButtonData then - v.LBFButtonData = { - Button = v, - Icon = _G[v:GetName() .. "IconTexture"], - } - end - group:AddButton(v, v.LBFButtonData) - end - end - - v.ClearSetPoint = clearSetPoint - end - - BagBarMod.button_count = count - if BagBarMod.optionobject then - BagBarMod.optionobject.table.general.args.rows.max = count - end -end +--[[ + Copyright (c) 2009, Hendrik "Nevcairiel" Leppkes < h.leppkes at gmail dot com > + All rights reserved. +]] +local L = LibStub("AceLocale-3.0"):GetLocale("Bartender4") +-- register module +local BagBarMod = Bartender4:NewModule("BagBar", "AceHook-3.0") + +-- fetch upvalues +local ButtonBar = Bartender4.ButtonBar.prototype +local LBF = LibStub("LibButtonFacade", true) + +-- create prototype information +local BagBar = setmetatable({}, {__index = ButtonBar}) + +local table_insert = table.insert + +local defaults = { profile = Bartender4:Merge({ + enabled = true, + keyring = false, + onebag = false, + visibility = { + possess = false, + }, +}, Bartender4.ButtonBar.defaults) } + +function BagBarMod:OnInitialize() + self.db = Bartender4.db:RegisterNamespace("BagBar", defaults) + self:SetEnabledState(self.db.profile.enabled) +end + +local noopFunc = function() end + +function BagBarMod:OnEnable() + if not self.bar then + self.bar = setmetatable(Bartender4.ButtonBar:Create("BagBar", self.db.profile, L["Bag Bar"]), {__index = BagBar}) + end + self.bar:Enable() + self:ToggleOptions() + self:ApplyConfig() +end + +function BagBarMod:ApplyConfig() + self.bar:ApplyConfig(self.db.profile) +end + +function BagBar:ApplyConfig(config) + ButtonBar.ApplyConfig(self, config) + + if not self.config.position.x then + self:ClearSetPoint("CENTER", 142, -18) + self:SavePosition() + end + + self:FeedButtons() + self:UpdateButtonLayout() +end + +function clearSetPoint(btn, ...) + btn:ClearAllPoints() + btn:SetPoint(...) +end + +BagBar.button_width = 30 +BagBar.button_height = 30 +BagBarMod.button_count = 5 +function BagBar:FeedButtons() + local count = 1 + if self.buttons then + while next(self.buttons) do + local btn = table.remove(self.buttons) + btn:Hide() + btn:SetParent(UIParent) + btn:ClearSetPoint("CENTER") + if btn ~= KeyRingButton and btn.LBFButtonData then + local group = self.LBFGroup + group:RemoveButton(btn) + end + end + else + self.buttons = {} + end + + if self.config.keyring then + table_insert(self.buttons, KeyRingButton) + count = count + 1 + end + + if not self.config.onebag then + table_insert(self.buttons, CharacterBag3Slot) + table_insert(self.buttons, CharacterBag2Slot) + table_insert(self.buttons, CharacterBag1Slot) + table_insert(self.buttons, CharacterBag0Slot) + count = count + 4 + end + + table_insert(self.buttons, MainMenuBarBackpackButton) + + for i,v in pairs(self.buttons) do + v:SetParent(self) + v:Show() + if v ~= KeyRingButton then + v:SetNormalTexture("") + + if LBF then + local group = self.LBFGroup + if not v.LBFButtonData then + v.LBFButtonData = { + Button = v, + Icon = _G[v:GetName() .. "IconTexture"], + } + end + group:AddButton(v, v.LBFButtonData) + end + end + + v.ClearSetPoint = clearSetPoint + end + + BagBarMod.button_count = count + if BagBarMod.optionobject then + BagBarMod.optionobject.table.general.args.rows.max = count + end +end diff --git a/Bar.lua b/Bar.lua index 9c24162..44ed11b 100644 --- a/Bar.lua +++ b/Bar.lua @@ -1,519 +1,519 @@ ---[[ - Copyright (c) 2009, Hendrik "Nevcairiel" Leppkes < h.leppkes at gmail dot com > - All rights reserved. -]] ---[[ - Generic Bar Frame Template -]] -local Bar = CreateFrame("Button") -local Bar_MT = {__index = Bar} - -local table_concat, table_insert = table.concat, table.insert - ---[[=================================================================================== - Universal Bar Contructor -===================================================================================]]-- - -local defaults = { - alpha = 1, - fadeout = false, - fadeoutalpha = 0.1, - fadeoutdelay = 0.2, - visibility = { - vehicleui = true, - stance = {}, - }, - position = { - scale = 1, - growVertical = "DOWN", - growHorizontal = "RIGHT", - }, - clickthrough = false, -} - -local Sticky = LibStub("LibSimpleSticky-1.0") -local LibWin = LibStub("LibWindow-1.1") -local snapBars = { WorldFrame, UIParent } - -local barOnEnter, barOnLeave, barOnDragStart, barOnDragStop, barOnClick, barOnUpdateFunc, barOnAttributeChanged -do - function barOnEnter(self) - if not self:GetParent().isMoving then - self:SetBackdropBorderColor(0.5, 0.5, 0, 1) - end - end - - function barOnLeave(self) - self:SetBackdropBorderColor(0, 0, 0, 0) - end - - local function barReAnchorForSnap(self) - local x,y,anchor = nil, nil, self:GetAnchor() - x = (self.config.position.growHorizontal == "RIGHT") and self:GetLeft() or self:GetRight() - y = (self.config.position.growVertical == "DOWN") and self:GetTop() or self:GetBottom() - self:ClearSetPoint(anchor, UIParent, "BOTTOMLEFT", x, y) - self:SetWidth(self.overlay:GetWidth()) - self:SetHeight(self.overlay:GetHeight()) - end - - local function barReAnchorNormal(self) - local x,y,anchor = nil, nil, self:GetAnchor() - x = (self.config.position.growHorizontal == "RIGHT") and self:GetLeft() or self:GetRight() - y = (self.config.position.growVertical == "DOWN") and self:GetTop() or self:GetBottom() - self:ClearSetPoint(anchor, UIParent, "BOTTOMLEFT", x, y) - self:SetWidth(1) - self:SetHeight(1) - end - - function barOnDragStart(self) - local parent = self:GetParent() - if Bartender4.db.profile.snapping then - local offset = 8 - (parent.config.padding or 0) - -- we need to re-anchor the bar and set its proper width for snaping to work properly - barReAnchorForSnap(parent) - Sticky:StartMoving(parent, snapBars, offset, offset, offset, offset) - else - parent:StartMoving() - end - self:SetBackdropBorderColor(0, 0, 0, 0) - parent.isMoving = true - end - - function barOnDragStop(self) - local parent = self:GetParent() - if parent.isMoving then - if Bartender4.db.profile.snapping then - local sticky, stickTo = Sticky:StopMoving(parent) - barReAnchorNormal(parent) - --Bartender4:Print(sticky, stickTo and stickTo:GetName() or nil) - else - parent:StopMovingOrSizing() - end - parent:SavePosition() - parent.isMoving = nil - end - end - - function barOnClick(self) - -- TODO: Hide/Show bar on Click - -- TODO: Once dropdown config is stable, show dropdown on rightclick - end - - function barOnUpdateFunc(self, elapsed) - self.elapsed = self.elapsed + elapsed - if self.elapsed > self.config.fadeoutdelay then - self:ControlFadeOut(self.elapsed) - self.elapsed = 0 - end - end - - function barOnAttributeChanged(self, attribute, value) - if attribute == "fade" then - if value then - self:SetScript("OnUpdate", barOnUpdateFunc) - self:ControlFadeOut() - else - self:SetScript("OnUpdate", nil) - self.faded = nil - self:SetConfigAlpha() - end - end - end -end - -local barregistry = {} -Bartender4.Bar = {} -Bartender4.Bar.defaults = defaults -Bartender4.Bar.prototype = Bar -Bartender4.Bar.barregistry = barregistry -function Bartender4.Bar:Create(id, config, name) - id = tostring(id) - assert(not barregistry[id], "duplicated entry in barregistry.") - - local bar = setmetatable(CreateFrame("Frame", ("BT4Bar%s"):format(id), UIParent, "SecureHandlerStateTemplate"), Bar_MT) - barregistry[id] = bar - - bar.id = id - bar.name = name or id - bar.config = config - bar:SetMovable(true) - bar:HookScript("OnAttributeChanged", barOnAttributeChanged) - - bar:SetWidth(1) - bar:SetHeight(1) - - local overlay = CreateFrame("Button", bar:GetName() .. "Overlay", bar) - bar.overlay = overlay - overlay.bar = bar - table_insert(snapBars, overlay) - overlay:EnableMouse(true) - overlay:RegisterForDrag("LeftButton") - overlay:RegisterForClicks("LeftButtonUp") - overlay:SetBackdrop({ - bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", - tile = true, - tileSize = 16, - edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", - edgeSize = 16, - insets = {left = 5, right = 3, top = 3, bottom = 5} - }) - overlay:SetBackdropColor(0, 1, 0, 0.5) - overlay:SetBackdropBorderColor(0.5, 0.5, 0, 0) - overlay.Text = overlay:CreateFontString(nil, "ARTWORK") - overlay.Text:SetFontObject(GameFontNormal) - overlay.Text:SetText(name) - overlay.Text:Show() - overlay.Text:ClearAllPoints() - overlay.Text:SetPoint("CENTER", overlay, "CENTER") - - overlay:SetScript("OnEnter", barOnEnter) - overlay:SetScript("OnLeave", barOnLeave) - overlay:SetScript("OnDragStart", barOnDragStart) - overlay:SetScript("OnDragStop", barOnDragStop) - overlay:SetScript("OnClick", barOnClick) - - overlay:SetFrameLevel(bar:GetFrameLevel() + 10) - bar:AnchorOverlay() - overlay:Hide() - - bar.elapsed = 0 - bar.hidedriver = {} - - return bar -end - -function Bartender4.Bar:GetAll() - return pairs(barregistry) -end - -function Bartender4.Bar:ForAll(method, ...) - for _,bar in self:GetAll() do - local func = bar[method] - if func then - func(bar, ...) - end - end -end - ---[[=================================================================================== - Universal Bar Prototype -===================================================================================]]-- - -Bar.BT4BarType = "Bar" - -function Bar:ApplyConfig(config) - if config then - self.config = config - end - LibWin.RegisterConfig(self, self.config.position) - - self:UpgradeConfig() - if self.disabled then return end - - if Bartender4.Locked then - self:Lock() - else - self:Unlock() - end - self:LoadPosition() - self:SetConfigScale() - self:SetConfigAlpha() - self:SetClickThrough() - self:InitVisibilityDriver() -end - -function Bar:GetAnchor() - return ((self.config.position.growVertical == "DOWN") and "TOP" or "BOTTOM") .. ((self.config.position.growHorizontal == "RIGHT") and "LEFT" or "RIGHT") -end - -function Bar:AnchorOverlay() - self.overlay:ClearAllPoints() - local anchor = self:GetAnchor() - self.overlay:SetPoint(anchor, self, anchor) -end - -function Bar:UpgradeConfig() - local version = self.config.version or 1 - if version < 2 then - -- LibWindow migration, move scale into position - if self.config.scale then - self.config.position.scale = self.config.scale - self.config.scale = nil - end - -- LibWindow migration, update position data - do - local pos = self.config.position - self:SetScale(pos.scale) - local x, y, s = pos.x, pos.y, self:GetEffectiveScale() - local point, relPoint = pos.point, pos.relPoint - if x and y and point and relPoint then - x, y = x/s, y/s - self:ClearSetPoint(point, UIParent, relPoint, x, y) - self:SavePosition() - pos.relPoint = nil - end - end - end - if version < 3 then - -- Size adjustment is done in first SetSize - self.needSizeFix = true - end - self.config.version = Bartender4.CONFIG_VERSION -end - -function Bar:Unlock() - if self.disabled or self.unlocked then return end - self.unlocked = true - self:DisableVisibilityDriver() - self:Show() - self.overlay:Show() -end - -function Bar:Lock() - if self.disabled or not self.unlocked then return end - self.unlocked = nil - self:StopDragging() - - self:ApplyVisibilityDriver() - - self.overlay:Hide() -end - -function Bar:StopDragging() - barOnDragStop(self.overlay) -end - -function Bar:LoadPosition() - LibWin.RestorePosition(self) -end - -function Bar:SavePosition() - LibWin.SavePosition(self) -end - -function Bar:SetSize(width, height) - self.overlay:SetWidth(width) - self.overlay:SetHeight(height or width) - if self.needSizeFix then - self:SetWidth(width) - self:SetHeight(height or width) - local x, y = self:GetLeft(), self:GetTop() - self:ClearSetPoint("TOPLEFT", UIParent, "BOTTOMLEFT", x, y) - self:SetWidth(1) - self:SetHeight(1) - self:SavePosition() - self.needSizeFix = nil - end -end - -function Bar:GetConfigAlpha() - return self.config.alpha -end - -function Bar:SetConfigAlpha(alpha) - if alpha then - self.config.alpha = alpha - end - if not self.faded then - self:SetAlpha(self.config.alpha) - end -end - -function Bar:GetConfigScale() - return self.config.position.scale -end - -function Bar:SetConfigScale(scale) - if scale then - LibWin.SetScale(self, scale) - end -end - -function Bar:GetClickThrough() - return self.config.clickthrough -end - -function Bar:SetClickThrough(click) - if click ~= nil then - self.config.clickthrough = click - end - if self.ControlClickThrough then - self:ControlClickThrough() - end -end - -function Bar:GetFadeOut() - return self.config.fadeout -end - -function Bar:SetFadeOut(fadeout) - if fadeout ~= nil then - self.config.fadeout = fadeout - self:InitVisibilityDriver() - end -end - -function Bar:GetFadeOutAlpha() - return self.config.fadeoutalpha -end - -function Bar:SetFadeOutAlpha(fadealpha) - if fadealpha ~= nil then - self.config.fadeoutalpha = fadealpha - end - if self.faded then - self:SetAlpha(self.config.fadeoutalpha) - end -end - -function Bar:GetFadeOutDelay() - return self.config.fadeoutdelay -end - -function Bar:SetFadeOutDelay(delay) - if delay ~= nil then - self.config.fadeoutdelay = delay - end -end - -function Bar:ControlFadeOut() - if self.faded and MouseIsOver(self.overlay) then - self:SetAlpha(self.config.alpha) - self.faded = nil - elseif not self.faded and not MouseIsOver(self.overlay) then - local fade = self:GetAttribute("fade") - if tonumber(fade) then - fade = min(max(fade, 0), 100) / 100 - self:SetAlpha(fade) - else - self:SetAlpha(self.config.fadeoutalpha or 0) - end - self.faded = true - end -end - -local directVisCond = { - pet = true, - nopet = true, - combat = true, - nocombat = true, - mounted = true, -} -function Bar:InitVisibilityDriver(returnOnly) - local tmpDriver - if returnOnly then - tmpDriver = self.hidedriver - else - UnregisterStateDriver(self, 'vis') - end - self.hidedriver = {} - - self:SetAttribute("_onstate-vis", [[ - if not newstate then return end - if newstate == "show" then - self:Show() - self:SetAttribute("fade", false) - elseif strsub(newstate, 1, 4) == "fade" then - self:Show() - self:SetAttribute("fade", (newstate == "fade") and true or strsub(newstate, 6)) - elseif newstate == "hide" then - self:Hide() - end - ]]) - - if self.config.visibility.custom and not returnOnly then - table_insert(self.hidedriver, self.config.visibility.customdata or "") - else - for key, value in pairs(self.config.visibility) do - if value then - if key == "always" then - table_insert(self.hidedriver, "hide") - elseif key == "possess" then - table_insert(self.hidedriver, "[bonusbar:5]hide") - elseif key == "vehicleui" then - table_insert(self.hidedriver, "[vehicleui]hide") - elseif key == "vehicle" then - table_insert(self.hidedriver, "[target=vehicle,exists]hide") - elseif directVisCond[key] then - table_insert(self.hidedriver, ("[%s]hide"):format(key)) - elseif key == "stance" then - for k,v in pairs(value) do - if v then - table_insert(self.hidedriver, ("[stance:%d]hide"):format(k)) - end - end - elseif key == "custom" or key == "customdata" then - -- do nothing - else - Bartender4:Print("Invalid visibility state: "..key) - end - end - end - end - table_insert(self.hidedriver, self.config.fadeout and "fade" or "show") - - if not returnOnly then - self:ApplyVisibilityDriver() - else - self.hidedriver, tmpDriver = tmpDriver, self.hidedriver - return table_concat(tmpDriver, ";") - end -end - -function Bar:ApplyVisibilityDriver() - if self.unlocked then return end - -- default state is shown - local driver = table_concat(self.hidedriver, ";") - RegisterStateDriver(self, "vis", driver) -end - -function Bar:DisableVisibilityDriver() - UnregisterStateDriver(self, "vis") - self:SetAttribute("state-vis", "show") - self:Show() -end - -function Bar:GetVisibilityOption(option, index) - if option == "stance" then - return self.config.visibility.stance[index] - else - return self.config.visibility[option] - end -end - -function Bar:SetVisibilityOption(option, value, arg) - if option == "stance" then - self.config.visibility.stance[value] = arg - else - self.config.visibility[option] = value - end - self:InitVisibilityDriver() -end - -function Bar:CopyCustomConditionals() - self.config.visibility.customdata = self:InitVisibilityDriver(true) - self:InitVisibilityDriver() -end - -function Bar:Enable() - if not self.disabled then return end - self.disabled = nil -end - -function Bar:Disable() - if self.disabled then return end - self:Lock() - self.disabled = true - self:UnregisterAllEvents() - self:DisableVisibilityDriver() - self:SetAttribute("state-vis", nil) - self:Hide() -end - ---[[ - Lazyness functions -]] -function Bar:ClearSetPoint(...) - self:ClearAllPoints() - self:SetPoint(...) -end +--[[ + Copyright (c) 2009, Hendrik "Nevcairiel" Leppkes < h.leppkes at gmail dot com > + All rights reserved. +]] +--[[ + Generic Bar Frame Template +]] +local Bar = CreateFrame("Button") +local Bar_MT = {__index = Bar} + +local table_concat, table_insert = table.concat, table.insert + +--[[=================================================================================== + Universal Bar Contructor +===================================================================================]]-- + +local defaults = { + alpha = 1, + fadeout = false, + fadeoutalpha = 0.1, + fadeoutdelay = 0.2, + visibility = { + vehicleui = true, + stance = {}, + }, + position = { + scale = 1, + growVertical = "DOWN", + growHorizontal = "RIGHT", + }, + clickthrough = false, +} + +local Sticky = LibStub("LibSimpleSticky-1.0") +local LibWin = LibStub("LibWindow-1.1") +local snapBars = { WorldFrame, UIParent } + +local barOnEnter, barOnLeave, barOnDragStart, barOnDragStop, barOnClick, barOnUpdateFunc, barOnAttributeChanged +do + function barOnEnter(self) + if not self:GetParent().isMoving then + self:SetBackdropBorderColor(0.5, 0.5, 0, 1) + end + end + + function barOnLeave(self) + self:SetBackdropBorderColor(0, 0, 0, 0) + end + + local function barReAnchorForSnap(self) + local x,y,anchor = nil, nil, self:GetAnchor() + x = (self.config.position.growHorizontal == "RIGHT") and self:GetLeft() or self:GetRight() + y = (self.config.position.growVertical == "DOWN") and self:GetTop() or self:GetBottom() + self:ClearSetPoint(anchor, UIParent, "BOTTOMLEFT", x, y) + self:SetWidth(self.overlay:GetWidth()) + self:SetHeight(self.overlay:GetHeight()) + end + + local function barReAnchorNormal(self) + local x,y,anchor = nil, nil, self:GetAnchor() + x = (self.config.position.growHorizontal == "RIGHT") and self:GetLeft() or self:GetRight() + y = (self.config.position.growVertical == "DOWN") and self:GetTop() or self:GetBottom() + self:ClearSetPoint(anchor, UIParent, "BOTTOMLEFT", x, y) + self:SetWidth(1) + self:SetHeight(1) + end + + function barOnDragStart(self) + local parent = self:GetParent() + if Bartender4.db.profile.snapping then + local offset = 8 - (parent.config.padding or 0) + -- we need to re-anchor the bar and set its proper width for snaping to work properly + barReAnchorForSnap(parent) + Sticky:StartMoving(parent, snapBars, offset, offset, offset, offset) + else + parent:StartMoving() + end + self:SetBackdropBorderColor(0, 0, 0, 0) + parent.isMoving = true + end + + function barOnDragStop(self) + local parent = self:GetParent() + if parent.isMoving then + if Bartender4.db.profile.snapping then + local sticky, stickTo = Sticky:StopMoving(parent) + barReAnchorNormal(parent) + --Bartender4:Print(sticky, stickTo and stickTo:GetName() or nil) + else + parent:StopMovingOrSizing() + end + parent:SavePosition() + parent.isMoving = nil + end + end + + function barOnClick(self) + -- TODO: Hide/Show bar on Click + -- TODO: Once dropdown config is stable, show dropdown on rightclick + end + + function barOnUpdateFunc(self, elapsed) + self.elapsed = self.elapsed + elapsed + if self.elapsed > self.config.fadeoutdelay then + self:ControlFadeOut(self.elapsed) + self.elapsed = 0 + end + end + + function barOnAttributeChanged(self, attribute, value) + if attribute == "fade" then + if value then + self:SetScript("OnUpdate", barOnUpdateFunc) + self:ControlFadeOut() + else + self:SetScript("OnUpdate", nil) + self.faded = nil + self:SetConfigAlpha() + end + end + end +end + +local barregistry = {} +Bartender4.Bar = {} +Bartender4.Bar.defaults = defaults +Bartender4.Bar.prototype = Bar +Bartender4.Bar.barregistry = barregistry +function Bartender4.Bar:Create(id, config, name) + id = tostring(id) + assert(not barregistry[id], "duplicated entry in barregistry.") + + local bar = setmetatable(CreateFrame("Frame", ("BT4Bar%s"):format(id), UIParent, "SecureHandlerStateTemplate"), Bar_MT) + barregistry[id] = bar + + bar.id = id + bar.name = name or id + bar.config = config + bar:SetMovable(true) + bar:HookScript("OnAttributeChanged", barOnAttributeChanged) + + bar:SetWidth(1) + bar:SetHeight(1) + + local overlay = CreateFrame("Button", bar:GetName() .. "Overlay", bar) + bar.overlay = overlay + overlay.bar = bar + table_insert(snapBars, overlay) + overlay:EnableMouse(true) + overlay:RegisterForDrag("LeftButton") + overlay:RegisterForClicks("LeftButtonUp") + overlay:SetBackdrop({ + bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", + tile = true, + tileSize = 16, + edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", + edgeSize = 16, + insets = {left = 5, right = 3, top = 3, bottom = 5} + }) + overlay:SetBackdropColor(0, 1, 0, 0.5) + overlay:SetBackdropBorderColor(0.5, 0.5, 0, 0) + overlay.Text = overlay:CreateFontString(nil, "ARTWORK") + overlay.Text:SetFontObject(GameFontNormal) + overlay.Text:SetText(name) + overlay.Text:Show() + overlay.Text:ClearAllPoints() + overlay.Text:SetPoint("CENTER", overlay, "CENTER") + + overlay:SetScript("OnEnter", barOnEnter) + overlay:SetScript("OnLeave", barOnLeave) + overlay:SetScript("OnDragStart", barOnDragStart) + overlay:SetScript("OnDragStop", barOnDragStop) + overlay:SetScript("OnClick", barOnClick) + + overlay:SetFrameLevel(bar:GetFrameLevel() + 10) + bar:AnchorOverlay() + overlay:Hide() + + bar.elapsed = 0 + bar.hidedriver = {} + + return bar +end + +function Bartender4.Bar:GetAll() + return pairs(barregistry) +end + +function Bartender4.Bar:ForAll(method, ...) + for _,bar in self:GetAll() do + local func = bar[method] + if func then + func(bar, ...) + end + end +end + +--[[=================================================================================== + Universal Bar Prototype +===================================================================================]]-- + +Bar.BT4BarType = "Bar" + +function Bar:ApplyConfig(config) + if config then + self.config = config + end + LibWin.RegisterConfig(self, self.config.position) + + self:UpgradeConfig() + if self.disabled then return end + + if Bartender4.Locked then + self:Lock() + else + self:Unlock() + end + self:LoadPosition() + self:SetConfigScale() + self:SetConfigAlpha() + self:SetClickThrough() + self:InitVisibilityDriver() +end + +function Bar:GetAnchor() + return ((self.config.position.growVertical == "DOWN") and "TOP" or "BOTTOM") .. ((self.config.position.growHorizontal == "RIGHT") and "LEFT" or "RIGHT") +end + +function Bar:AnchorOverlay() + self.overlay:ClearAllPoints() + local anchor = self:GetAnchor() + self.overlay:SetPoint(anchor, self, anchor) +end + +function Bar:UpgradeConfig() + local version = self.config.version or 1 + if version < 2 then + -- LibWindow migration, move scale into position + if self.config.scale then + self.config.position.scale = self.config.scale + self.config.scale = nil + end + -- LibWindow migration, update position data + do + local pos = self.config.position + self:SetScale(pos.scale) + local x, y, s = pos.x, pos.y, self:GetEffectiveScale() + local point, relPoint = pos.point, pos.relPoint + if x and y and point and relPoint then + x, y = x/s, y/s + self:ClearSetPoint(point, UIParent, relPoint, x, y) + self:SavePosition() + pos.relPoint = nil + end + end + end + if version < 3 then + -- Size adjustment is done in first SetSize + self.needSizeFix = true + end + self.config.version = Bartender4.CONFIG_VERSION +end + +function Bar:Unlock() + if self.disabled or self.unlocked then return end + self.unlocked = true + self:DisableVisibilityDriver() + self:Show() + self.overlay:Show() +end + +function Bar:Lock() + if self.disabled or not self.unlocked then return end + self.unlocked = nil + self:StopDragging() + + self:ApplyVisibilityDriver() + + self.overlay:Hide() +end + +function Bar:StopDragging() + barOnDragStop(self.overlay) +end + +function Bar:LoadPosition() + LibWin.RestorePosition(self) +end + +function Bar:SavePosition() + LibWin.SavePosition(self) +end + +function Bar:SetSize(width, height) + self.overlay:SetWidth(width) + self.overlay:SetHeight(height or width) + if self.needSizeFix then + self:SetWidth(width) + self:SetHeight(height or width) + local x, y = self:GetLeft(), self:GetTop() + self:ClearSetPoint("TOPLEFT", UIParent, "BOTTOMLEFT", x, y) + self:SetWidth(1) + self:SetHeight(1) + self:SavePosition() + self.needSizeFix = nil + end +end + +function Bar:GetConfigAlpha() + return self.config.alpha +end + +function Bar:SetConfigAlpha(alpha) + if alpha then + self.config.alpha = alpha + end + if not self.faded then + self:SetAlpha(self.config.alpha) + end +end + +function Bar:GetConfigScale() + return self.config.position.scale +end + +function Bar:SetConfigScale(scale) + if scale then + LibWin.SetScale(self, scale) + end +end + +function Bar:GetClickThrough() + return self.config.clickthrough +end + +function Bar:SetClickThrough(click) + if click ~= nil then + self.config.clickthrough = click + end + if self.ControlClickThrough then + self:ControlClickThrough() + end +end + +function Bar:GetFadeOut() + return self.config.fadeout +end + +function Bar:SetFadeOut(fadeout) + if fadeout ~= nil then + self.config.fadeout = fadeout + self:InitVisibilityDriver() + end +end + +function Bar:GetFadeOutAlpha() + return self.config.fadeoutalpha +end + +function Bar:SetFadeOutAlpha(fadealpha) + if fadealpha ~= nil then + self.config.fadeoutalpha = fadealpha + end + if self.faded then + self:SetAlpha(self.config.fadeoutalpha) + end +end + +function Bar:GetFadeOutDelay() + return self.config.fadeoutdelay +end + +function Bar:SetFadeOutDelay(delay) + if delay ~= nil then + self.config.fadeoutdelay = delay + end +end + +function Bar:ControlFadeOut() + if self.faded and MouseIsOver(self.overlay) then + self:SetAlpha(self.config.alpha) + self.faded = nil + elseif not self.faded and not MouseIsOver(self.overlay) then + local fade = self:GetAttribute("fade") + if tonumber(fade) then + fade = min(max(fade, 0), 100) / 100 + self:SetAlpha(fade) + else + self:SetAlpha(self.config.fadeoutalpha or 0) + end + self.faded = true + end +end + +local directVisCond = { + pet = true, + nopet = true, + combat = true, + nocombat = true, + mounted = true, +} +function Bar:InitVisibilityDriver(returnOnly) + local tmpDriver + if returnOnly then + tmpDriver = self.hidedriver + else + UnregisterStateDriver(self, 'vis') + end + self.hidedriver = {} + + self:SetAttribute("_onstate-vis", [[ + if not newstate then return end + if newstate == "show" then + self:Show() + self:SetAttribute("fade", false) + elseif strsub(newstate, 1, 4) == "fade" then + self:Show() + self:SetAttribute("fade", (newstate == "fade") and true or strsub(newstate, 6)) + elseif newstate == "hide" then + self:Hide() + end + ]]) + + if self.config.visibility.custom and not returnOnly then + table_insert(self.hidedriver, self.config.visibility.customdata or "") + else + for key, value in pairs(self.config.visibility) do + if value then + if key == "always" then + table_insert(self.hidedriver, "hide") + elseif key == "possess" then + table_insert(self.hidedriver, "[bonusbar:5]hide") + elseif key == "vehicleui" then + table_insert(self.hidedriver, "[vehicleui]hide") + elseif key == "vehicle" then + table_insert(self.hidedriver, "[target=vehicle,exists]hide") + elseif directVisCond[key] then + table_insert(self.hidedriver, ("[%s]hide"):format(key)) + elseif key == "stance" then + for k,v in pairs(value) do + if v then + table_insert(self.hidedriver, ("[stance:%d]hide"):format(k)) + end + end + elseif key == "custom" or key == "customdata" then + -- do nothing + else + Bartender4:Print("Invalid visibility state: "..key) + end + end + end + end + table_insert(self.hidedriver, self.config.fadeout and "fade" or "show") + + if not returnOnly then + self:ApplyVisibilityDriver() + else + self.hidedriver, tmpDriver = tmpDriver, self.hidedriver + return table_concat(tmpDriver, ";") + end +end + +function Bar:ApplyVisibilityDriver() + if self.unlocked then return end + -- default state is shown + local driver = table_concat(self.hidedriver, ";") + RegisterStateDriver(self, "vis", driver) +end + +function Bar:DisableVisibilityDriver() + UnregisterStateDriver(self, "vis") + self:SetAttribute("state-vis", "show") + self:Show() +end + +function Bar:GetVisibilityOption(option, index) + if option == "stance" then + return self.config.visibility.stance[index] + else + return self.config.visibility[option] + end +end + +function Bar:SetVisibilityOption(option, value, arg) + if option == "stance" then + self.config.visibility.stance[value] = arg + else + self.config.visibility[option] = value + end + self:InitVisibilityDriver() +end + +function Bar:CopyCustomConditionals() + self.config.visibility.customdata = self:InitVisibilityDriver(true) + self:InitVisibilityDriver() +end + +function Bar:Enable() + if not self.disabled then return end + self.disabled = nil +end + +function Bar:Disable() + if self.disabled then return end + self:Lock() + self.disabled = true + self:UnregisterAllEvents() + self:DisableVisibilityDriver() + self:SetAttribute("state-vis", nil) + self:Hide() +end + +--[[ + Lazyness functions +]] +function Bar:ClearSetPoint(...) + self:ClearAllPoints() + self:SetPoint(...) +end diff --git a/Bartender4.lua b/Bartender4.lua index dc5ba56..1e62561 100644 --- a/Bartender4.lua +++ b/Bartender4.lua @@ -1,439 +1,439 @@ ---[[ - Copyright (c) 2009, Hendrik "Nevcairiel" Leppkes < h.leppkes at gmail dot com > - All rights reserved. -]] -local AceAddon = LibStub("AceAddon-3.0") -Bartender4 = AceAddon:NewAddon("Bartender4", "AceConsole-3.0", "AceEvent-3.0", "AceHook-3.0") - -local L = LibStub("AceLocale-3.0"):GetLocale("Bartender4") - -local LDB = LibStub("LibDataBroker-1.1", true) -local LDBIcon = LibStub("LibDBIcon-1.0", true) - -local defaults = { - profile = { - tooltip = "enabled", - buttonlock = false, - outofrange = "button", - colors = { range = { r = 0.8, g = 0.1, b = 0.1 }, mana = { r = 0.5, g = 0.5, b = 1.0 } }, - selfcastmodifier = true, - focuscastmodifier = true, - selfcastrightclick = false, - snapping = true, - blizzardVehicle = false, - minimapIcon = {}, - } -} - -Bartender4.CONFIG_VERSION = 3 - -function Bartender4:OnInitialize() - self.db = LibStub("AceDB-3.0"):New("Bartender4DB", defaults) - self.db.RegisterCallback(self, "OnProfileChanged", "UpdateModuleConfigs") - self.db.RegisterCallback(self, "OnProfileCopied", "UpdateModuleConfigs") - self.db.RegisterCallback(self, "OnProfileReset", "UpdateModuleConfigs") - - self:SetupOptions() - - self.Locked = true - self:RegisterEvent("PLAYER_REGEN_DISABLED", "CombatLockdown") - - self:HideBlizzard() - self:UpdateBlizzardVehicle() - - if LDB then - createLDBLauncher() - end - - BINDING_HEADER_Bartender4 = "Bartender4" - BINDING_CATEGORY_Bartender4 = "Action Bars" - for i=1,10 do - if i > 1 then - _G[('BINDING_CATEGORY_BT4BLANK%d'):format(i)] = "Action Bars" -- myBindings2 compat - _G[('BINDING_HEADER_BT4BLANK%d'):format(i)] = "Bartender4 " .. L["Bar %s"]:format(i) - end - for k=1,12 do - _G[("BINDING_NAME_CLICK BT4Button%d:LeftButton"):format(((i-1)*12)+k)] = ("Bartender4 %s %s"):format(L["Bar %s"]:format(i), L["Button %s"]:format(k)) - end - end - BINDING_HEADER_BT4PET = "Bartender4 " .. L["Pet Bar"] - BINDING_CATEGORY_BT4PET = "Action Bars" - BINDING_HEADER_BT4STANCE = "Bartender4 " .. L["Stance Bar"] - BINDING_CATEGORY_BT4STANCE = "Action Bars" - for k=1,10 do - _G[("BINDING_NAME_CLICK BT4PetButton%d:LeftButton"):format(k)] = ("Bartender4 %s %s"):format(L["Pet Bar"], L["Button %s"]:format(k)) - _G[("BINDING_NAME_CLICK BT4StanceButton%d:LeftButton"):format(k)] = ("Bartender4 %s %s"):format(L["Stance Bar"], L["Button %s"]:format(k)) - end -end - -function Bartender4:HideBlizzard() - --MultiActionBar_Update = function() end - MultiActionBar_UpdateGrid = function() end - - -- Hide MultiBar Buttons, but keep the bars alive - for i=1,12 do - _G["ActionButton" .. i]:Hide() - _G["ActionButton" .. i]:UnregisterAllEvents() - - _G["MultiBarBottomLeftButton" .. i]:Hide() - _G["MultiBarBottomLeftButton" .. i]:UnregisterAllEvents() - - _G["MultiBarBottomRightButton" .. i]:Hide() - _G["MultiBarBottomRightButton" .. i]:UnregisterAllEvents() - - _G["MultiBarRightButton" .. i]:Hide() - _G["MultiBarRightButton" .. i]:UnregisterAllEvents() - - _G["MultiBarLeftButton" .. i]:Hide() - _G["MultiBarLeftButton" .. i]:UnregisterAllEvents() - end - --UIPARENT_MANAGED_FRAME_POSITIONS['MultiBarRight'] = nil - --UIPARENT_MANAGED_FRAME_POSITIONS['MultiBarLeft'] = nil - --UIPARENT_MANAGED_FRAME_POSITIONS['MultiBarBottomLeft'] = nil - --UIPARENT_MANAGED_FRAME_POSITIONS['MultiBarBottomRight'] = nil - UIPARENT_MANAGED_FRAME_POSITIONS['MainMenuBar'] = nil - UIPARENT_MANAGED_FRAME_POSITIONS['ShapeshiftBarFrame'] = nil - UIPARENT_MANAGED_FRAME_POSITIONS['PossessBarFrame'] = nil - UIPARENT_MANAGED_FRAME_POSITIONS['PETACTIONBAR_YPOS'] = nil - - MainMenuBar:UnregisterAllEvents() - MainMenuBar:Hide() - - --MainMenuBarArtFrame:UnregisterEvent("PLAYER_ENTERING_WORLD") - --MainMenuBarArtFrame:UnregisterEvent("BAG_UPDATE") - MainMenuBarArtFrame:UnregisterEvent("ACTIONBAR_PAGE_CHANGED") - --MainMenuBarArtFrame:UnregisterEvent("KNOWN_CURRENCY_TYPES_UPDATE") - --MainMenuBarArtFrame:UnregisterEvent("CURRENCY_DISPLAY_UPDATE") - MainMenuBarArtFrame:UnregisterEvent("ADDON_LOADED") - --MainMenuBarArtFrame:UnregisterEvent("UNIT_ENTERING_VEHICLE") - --MainMenuBarArtFrame:UnregisterEvent("UNIT_ENTERED_VEHICLE") - --MainMenuBarArtFrame:UnregisterEvent("UNIT_EXITING_VEHICLE") - --MainMenuBarArtFrame:UnregisterEvent("UNIT_EXITED_VEHICLE") - MainMenuBarArtFrame:Hide() - - --MainMenuExpBar:UnregisterAllEvents() - --MainMenuExpBar:Hide() - - ShapeshiftBarFrame:UnregisterAllEvents() - ShapeshiftBarFrame:Hide() - - BonusActionBarFrame:UnregisterAllEvents() - BonusActionBarFrame:Hide() - - PossessBarFrame:UnregisterAllEvents() - PossessBarFrame:Hide() - - if PlayerTalentFrame then - PlayerTalentFrame:UnregisterEvent('ACTIVE_TALENT_GROUP_CHANGED') - else - hooksecurefunc('TalentFrame_LoadUI', function() PlayerTalentFrame:UnregisterEvent('ACTIVE_TALENT_GROUP_CHANGED') end) - end -end - ---[[ function Bartender4:OnEnable() - -- -end ---]] - -function Bartender4:RegisterDefaultsKey(key, subdefaults) - defaults.profile[key] = subdefaults - - self.db:RegisterDefaults(defaults) -end - -function Bartender4:UpdateModuleConfigs() - local unlock = false - if not self.Locked then - self:Lock() - unlock = true - end - - for k,v in AceAddon:IterateModulesOfAddon(self) do - v:ToggleModule() - if v:IsEnabled() and type(v.ApplyConfig) == "function" then - v:ApplyConfig() - end - end - if LDB and LDBIcon then - LDBIcon:Refresh("Bartender4", Bartender4.db.profile.minimapIcon) - end - - self:UpdateBlizzardVehicle() - - if unlock then - self:Unlock() - end -end - -function Bartender4:UpdateBlizzardVehicle() - if self.db.profile.blizzardVehicle then - MainMenuBarArtFrame:RegisterEvent("UNIT_ENTERING_VEHICLE") - MainMenuBarArtFrame:RegisterEvent("UNIT_ENTERED_VEHICLE") - MainMenuBarArtFrame:RegisterEvent("UNIT_EXITING_VEHICLE") - MainMenuBarArtFrame:RegisterEvent("UNIT_EXITED_VEHICLE") - MainMenuBarArtFrame:RegisterEvent("PLAYER_ENTERING_WORLD") - local vehicleModule = Bartender4:GetModule("Vehicle", true) - vehicleModule:Disable() - vehicleModule.blizzardVehicle = true - - RegisterStateDriver(MainMenuBar, "visibility", "hide") - RegisterStateDriver(ShapeshiftBarFrame, "visibility", "hide") - RegisterStateDriver(PossessBarFrame, "visibility", "hide") - - if not self.vehicleController then - self.vehicleController = CreateFrame("Frame", nil, UIParent, "SecureHandlerStateTemplate") - self.vehicleController:SetAttribute("_onstate-vehicle", [[ - if newstate == "vehicle" then - for i=1,6 do - local button, vbutton = ("ACTIONBUTTON%d"):format(i), ("VehicleMenuBarActionButton%d"):format(i) - for k=1,select('#', GetBindingKey(button)) do - local key = select(k, GetBindingKey(button)) - self:SetBindingClick(true, key, vbutton) - end - end - else - self:ClearBindings() - end - ]]) - end - RegisterStateDriver(self.vehicleController, "vehicle", "[vehicleui]vehicle;novehicle") - local btn = "VehicleMenuBarActionButton%d" - for i=1,6 do - local name = btn:format(i) - local button = _G[name] - button.UpdateUsable = Bartender4.Button.prototype.UpdateUsable - button:SetScript("OnUpdate", Bartender4.Button.onUpdate) - button.icon = _G[("%sIcon"):format(name)] - button.border = _G[("%sBorder"):format(name)] - button.cooldown = _G[("%sCooldown"):format(name)] - button.macroName = _G[("%sName"):format(name)] - button.hotkey = _G[("%sHotKey"):format(name)] - button.count = _G[("%sCount"):format(name)] - button.flash = _G[("%sFlash"):format(name)] - button.BT4init = true - button:SetParent(VehicleMenuBarActionButtonFrame) - end - else - MainMenuBarArtFrame:UnregisterEvent("UNIT_ENTERING_VEHICLE") - MainMenuBarArtFrame:UnregisterEvent("UNIT_ENTERED_VEHICLE") - MainMenuBarArtFrame:UnregisterEvent("UNIT_EXITING_VEHICLE") - MainMenuBarArtFrame:UnregisterEvent("UNIT_EXITED_VEHICLE") - MainMenuBarArtFrame:UnregisterEvent("PLAYER_ENTERING_WORLD") - - local vehicleModule = Bartender4:GetModule("Vehicle") - vehicleModule.blizzardVehicle = nil - if vehicleModule.db and vehicleModule.db.profile.enabled then - vehicleModule:Enable() - end - UnregisterStateDriver(MainMenuBar, "visibility") - UnregisterStateDriver(ShapeshiftBarFrame, "visibility") - UnregisterStateDriver(PossessBarFrame, "visibility") - if self.vehicleController then - UnregisterStateDriver(self.vehicleController, "vehicle") - end - local btn = "VehicleMenuBarActionButton%d" - for i=1,6 do - local name = btn:format(i) - local button = _G[name] - button.BT4init = nil - button:SetScript("OnUpdate", ActionButton_OnUpdate) - end - end -end - -function Bartender4:CombatLockdown() - self:Lock() - LibStub("AceConfigDialog-3.0"):Close("Bartender4") -end - -function Bartender4:ToggleLock() - if self.Locked then - self:Unlock() - else - self:Lock() - end -end - -local getSnap, setSnap -do - function getSnap() - return Bartender4.db.profile.snapping - end - - function setSnap(value) - Bartender4.Bar:ForAll("StopDragging") - Bartender4.db.profile.snapping = value - LibStub("AceConfigRegistry-3.0"):NotifyChange("Bartender4") - end -end - -function Bartender4:ShowUnlockDialog() - if not self.unlock_dialog then - local f = CreateFrame('Frame', 'Bartender4Dialog', UIParent) - f:SetFrameStrata('DIALOG') - f:SetToplevel(true) - f:EnableMouse(true) - f:SetClampedToScreen(true) - f:SetWidth(360) - f:SetHeight(110) - f:SetBackdrop{ - bgFile='Interface\\DialogFrame\\UI-DialogBox-Background' , - edgeFile='Interface\\DialogFrame\\UI-DialogBox-Border', - tile = true, - insets = {left = 11, right = 12, top = 12, bottom = 11}, - tileSize = 32, - edgeSize = 32, - } - f:SetPoint('TOP', 0, -50) - f:Hide() - f:SetScript('OnShow', function() PlaySound('igMainMenuOption') end) - f:SetScript('OnHide', function() PlaySound('gsTitleOptionExit') end) - - local tr = f:CreateTitleRegion() - tr:SetAllPoints(f) - - local header = f:CreateTexture(nil, 'ARTWORK') - header:SetTexture('Interface\\DialogFrame\\UI-DialogBox-Header') - header:SetWidth(256); header:SetHeight(64) - header:SetPoint('TOP', 0, 12) - - local title = f:CreateFontString('ARTWORK') - title:SetFontObject('GameFontNormal') - title:SetPoint('TOP', header, 'TOP', 0, -14) - title:SetText(L["Bartender4"]) - - local desc = f:CreateFontString('ARTWORK') - desc:SetFontObject('GameFontHighlight') - desc:SetJustifyV('TOP') - desc:SetJustifyH('LEFT') - desc:SetPoint('TOPLEFT', 18, -32) - desc:SetPoint('BOTTOMRIGHT', -18, 48) - desc:SetText(L["Bars unlocked. Move them now and click Lock when you are done."]) - - local snapping = CreateFrame('CheckButton', 'Bartender4Snapping', f, 'OptionsCheckButtonTemplate') - _G[snapping:GetName() .. 'Text']:SetText(L["Bar Snapping"]) - - snapping:SetScript('OnShow', function(self) - self:SetChecked(getSnap()) - end) - - snapping:SetScript('OnClick', function(self) - setSnap(snapping:GetChecked()) - end) - - local lockBars = CreateFrame('CheckButton', 'Bartender4DialogLock', f, 'OptionsButtonTemplate') - getglobal(lockBars:GetName() .. 'Text'):SetText(L["Lock"]) - - lockBars:SetScript('OnClick', function(self) - Bartender4:Lock() - LibStub("AceConfigRegistry-3.0"):NotifyChange("Bartender4") - end) - - --position buttons - snapping:SetPoint('BOTTOMLEFT', 14, 10) - lockBars:SetPoint('BOTTOMRIGHT', -14, 14) - - self.unlock_dialog = f - end - self.unlock_dialog:Show() -end - -function Bartender4:HideUnlockDialog() - if self.unlock_dialog then - self.unlock_dialog:Hide() - end -end - -function Bartender4:Unlock() - if self.Locked then - self.Locked = false - Bartender4.Bar:ForAll("Unlock") - self:ShowUnlockDialog() - end -end - -function Bartender4:Lock() - if not self.Locked then - self.Locked = true - Bartender4.Bar:ForAll("Lock") - self:HideUnlockDialog() - end -end - -function Bartender4:Merge(target, source) - if type(target) ~= "table" then target = {} end - for k,v in pairs(source) do - if type(v) == "table" then - target[k] = self:Merge(target[k], v) - elseif not target[k] then - target[k] = v - end - end - return target -end - -Bartender4.modulePrototype = {} -function Bartender4.modulePrototype:ToggleModule(info, value) - if value ~= nil then - self.db.profile.enabled = value - else - value = self.db.profile.enabled - end - if value and not self:IsEnabled() then - self:Enable() - elseif not value and self:IsEnabled() then - self:Disable() - end -end - -function Bartender4.modulePrototype:ToggleOptions() - if self.options then - self.options.args = self:IsEnabled() and self.optionobject.table or self.disabledoptions - end -end - -function Bartender4.modulePrototype:OnDisable() - if not self.bar then return end - -- assign new config table - self.bar.config = self.db.profile - self.bar:Disable() - self:ToggleOptions() -end - -Bartender4:SetDefaultModulePrototype(Bartender4.modulePrototype) - -function createLDBLauncher() - local L_BT_LEFT = L["|cffffff00Click|r to toggle bar lock"] - local L_BT_RIGHT = L["|cffffff00Right-click|r to open the options menu"] - - local LDBObj = LibStub("LibDataBroker-1.1"):NewDataObject("Bartender4", { - type = "launcher", - label = "Bartender4", - OnClick = function(_, msg) - if msg == "LeftButton" then - if Bartender4.Locked then - Bartender4["Unlock"](Bartender4) - else - Bartender4["Lock"](Bartender4) - end - elseif msg == "RightButton" then - if LibStub("AceConfigDialog-3.0").OpenFrames["Bartender4"] then - LibStub("AceConfigDialog-3.0"):Close("Bartender4") - else - LibStub("AceConfigDialog-3.0"):Open("Bartender4") - end - end - end, - icon = "Interface\\Icons\\INV_Drink_05", - OnTooltipShow = function(tooltip) - if not tooltip or not tooltip.AddLine then return end - tooltip:AddLine("Bartender4") - tooltip:AddLine(L_BT_LEFT) - tooltip:AddLine(L_BT_RIGHT) - end, - }) - - if LDBIcon then - LDBIcon:Register("Bartender4", LDBObj, Bartender4.db.profile.minimapIcon) - end -end +--[[ + Copyright (c) 2009, Hendrik "Nevcairiel" Leppkes < h.leppkes at gmail dot com > + All rights reserved. +]] +local AceAddon = LibStub("AceAddon-3.0") +Bartender4 = AceAddon:NewAddon("Bartender4", "AceConsole-3.0", "AceEvent-3.0", "AceHook-3.0") + +local L = LibStub("AceLocale-3.0"):GetLocale("Bartender4") + +local LDB = LibStub("LibDataBroker-1.1", true) +local LDBIcon = LibStub("LibDBIcon-1.0", true) + +local defaults = { + profile = { + tooltip = "enabled", + buttonlock = false, + outofrange = "button", + colors = { range = { r = 0.8, g = 0.1, b = 0.1 }, mana = { r = 0.5, g = 0.5, b = 1.0 } }, + selfcastmodifier = true, + focuscastmodifier = true, + selfcastrightclick = false, + snapping = true, + blizzardVehicle = false, + minimapIcon = {}, + } +} + +Bartender4.CONFIG_VERSION = 3 + +function Bartender4:OnInitialize() + self.db = LibStub("AceDB-3.0"):New("Bartender4DB", defaults) + self.db.RegisterCallback(self, "OnProfileChanged", "UpdateModuleConfigs") + self.db.RegisterCallback(self, "OnProfileCopied", "UpdateModuleConfigs") + self.db.RegisterCallback(self, "OnProfileReset", "UpdateModuleConfigs") + + self:SetupOptions() + + self.Locked = true + self:RegisterEvent("PLAYER_REGEN_DISABLED", "CombatLockdown") + + self:HideBlizzard() + self:UpdateBlizzardVehicle() + + if LDB then + createLDBLauncher() + end + + BINDING_HEADER_Bartender4 = "Bartender4" + BINDING_CATEGORY_Bartender4 = "Action Bars" + for i=1,10 do + if i > 1 then + _G[('BINDING_CATEGORY_BT4BLANK%d'):format(i)] = "Action Bars" -- myBindings2 compat + _G[('BINDING_HEADER_BT4BLANK%d'):format(i)] = "Bartender4 " .. L["Bar %s"]:format(i) + end + for k=1,12 do + _G[("BINDING_NAME_CLICK BT4Button%d:LeftButton"):format(((i-1)*12)+k)] = ("Bartender4 %s %s"):format(L["Bar %s"]:format(i), L["Button %s"]:format(k)) + end + end + BINDING_HEADER_BT4PET = "Bartender4 " .. L["Pet Bar"] + BINDING_CATEGORY_BT4PET = "Action Bars" + BINDING_HEADER_BT4STANCE = "Bartender4 " .. L["Stance Bar"] + BINDING_CATEGORY_BT4STANCE = "Action Bars" + for k=1,10 do + _G[("BINDING_NAME_CLICK BT4PetButton%d:LeftButton"):format(k)] = ("Bartender4 %s %s"):format(L["Pet Bar"], L["Button %s"]:format(k)) + _G[("BINDING_NAME_CLICK BT4StanceButton%d:LeftButton"):format(k)] = ("Bartender4 %s %s"):format(L["Stance Bar"], L["Button %s"]:format(k)) + end +end + +function Bartender4:HideBlizzard() + --MultiActionBar_Update = function() end + MultiActionBar_UpdateGrid = function() end + + -- Hide MultiBar Buttons, but keep the bars alive + for i=1,12 do + _G["ActionButton" .. i]:Hide() + _G["ActionButton" .. i]:UnregisterAllEvents() + + _G["MultiBarBottomLeftButton" .. i]:Hide() + _G["MultiBarBottomLeftButton" .. i]:UnregisterAllEvents() + + _G["MultiBarBottomRightButton" .. i]:Hide() + _G["MultiBarBottomRightButton" .. i]:UnregisterAllEvents() + + _G["MultiBarRightButton" .. i]:Hide() + _G["MultiBarRightButton" .. i]:UnregisterAllEvents() + + _G["MultiBarLeftButton" .. i]:Hide() + _G["MultiBarLeftButton" .. i]:UnregisterAllEvents() + end + --UIPARENT_MANAGED_FRAME_POSITIONS['MultiBarRight'] = nil + --UIPARENT_MANAGED_FRAME_POSITIONS['MultiBarLeft'] = nil + --UIPARENT_MANAGED_FRAME_POSITIONS['MultiBarBottomLeft'] = nil + --UIPARENT_MANAGED_FRAME_POSITIONS['MultiBarBottomRight'] = nil + UIPARENT_MANAGED_FRAME_POSITIONS['MainMenuBar'] = nil + UIPARENT_MANAGED_FRAME_POSITIONS['ShapeshiftBarFrame'] = nil + UIPARENT_MANAGED_FRAME_POSITIONS['PossessBarFrame'] = nil + UIPARENT_MANAGED_FRAME_POSITIONS['PETACTIONBAR_YPOS'] = nil + + MainMenuBar:UnregisterAllEvents() + MainMenuBar:Hide() + + --MainMenuBarArtFrame:UnregisterEvent("PLAYER_ENTERING_WORLD") + --MainMenuBarArtFrame:UnregisterEvent("BAG_UPDATE") + MainMenuBarArtFrame:UnregisterEvent("ACTIONBAR_PAGE_CHANGED") + --MainMenuBarArtFrame:UnregisterEvent("KNOWN_CURRENCY_TYPES_UPDATE") + --MainMenuBarArtFrame:UnregisterEvent("CURRENCY_DISPLAY_UPDATE") + MainMenuBarArtFrame:UnregisterEvent("ADDON_LOADED") + --MainMenuBarArtFrame:UnregisterEvent("UNIT_ENTERING_VEHICLE") + --MainMenuBarArtFrame:UnregisterEvent("UNIT_ENTERED_VEHICLE") + --MainMenuBarArtFrame:UnregisterEvent("UNIT_EXITING_VEHICLE") + --MainMenuBarArtFrame:UnregisterEvent("UNIT_EXITED_VEHICLE") + MainMenuBarArtFrame:Hide() + + --MainMenuExpBar:UnregisterAllEvents() + --MainMenuExpBar:Hide() + + ShapeshiftBarFrame:UnregisterAllEvents() + ShapeshiftBarFrame:Hide() + + BonusActionBarFrame:UnregisterAllEvents() + BonusActionBarFrame:Hide() + + PossessBarFrame:UnregisterAllEvents() + PossessBarFrame:Hide() + + if PlayerTalentFrame then + PlayerTalentFrame:UnregisterEvent('ACTIVE_TALENT_GROUP_CHANGED') + else + hooksecurefunc('TalentFrame_LoadUI', function() PlayerTalentFrame:UnregisterEvent('ACTIVE_TALENT_GROUP_CHANGED') end) + end +end + +--[[ function Bartender4:OnEnable() + -- +end +--]] + +function Bartender4:RegisterDefaultsKey(key, subdefaults) + defaults.profile[key] = subdefaults + + self.db:RegisterDefaults(defaults) +end + +function Bartender4:UpdateModuleConfigs() + local unlock = false + if not self.Locked then + self:Lock() + unlock = true + end + + for k,v in AceAddon:IterateModulesOfAddon(self) do + v:ToggleModule() + if v:IsEnabled() and type(v.ApplyConfig) == "function" then + v:ApplyConfig() + end + end + if LDB and LDBIcon then + LDBIcon:Refresh("Bartender4", Bartender4.db.profile.minimapIcon) + end + + self:UpdateBlizzardVehicle() + + if unlock then + self:Unlock() + end +end + +function Bartender4:UpdateBlizzardVehicle() + if self.db.profile.blizzardVehicle then + MainMenuBarArtFrame:RegisterEvent("UNIT_ENTERING_VEHICLE") + MainMenuBarArtFrame:RegisterEvent("UNIT_ENTERED_VEHICLE") + MainMenuBarArtFrame:RegisterEvent("UNIT_EXITING_VEHICLE") + MainMenuBarArtFrame:RegisterEvent("UNIT_EXITED_VEHICLE") + MainMenuBarArtFrame:RegisterEvent("PLAYER_ENTERING_WORLD") + local vehicleModule = Bartender4:GetModule("Vehicle", true) + vehicleModule:Disable() + vehicleModule.blizzardVehicle = true + + RegisterStateDriver(MainMenuBar, "visibility", "hide") + RegisterStateDriver(ShapeshiftBarFrame, "visibility", "hide") + RegisterStateDriver(PossessBarFrame, "visibility", "hide") + + if not self.vehicleController then + self.vehicleController = CreateFrame("Frame", nil, UIParent, "SecureHandlerStateTemplate") + self.vehicleController:SetAttribute("_onstate-vehicle", [[ + if newstate == "vehicle" then + for i=1,6 do + local button, vbutton = ("ACTIONBUTTON%d"):format(i), ("VehicleMenuBarActionButton%d"):format(i) + for k=1,select('#', GetBindingKey(button)) do + local key = select(k, GetBindingKey(button)) + self:SetBindingClick(true, key, vbutton) + end + end + else + self:ClearBindings() + end + ]]) + end + RegisterStateDriver(self.vehicleController, "vehicle", "[vehicleui]vehicle;novehicle") + local btn = "VehicleMenuBarActionButton%d" + for i=1,6 do + local name = btn:format(i) + local button = _G[name] + button.UpdateUsable = Bartender4.Button.prototype.UpdateUsable + button:SetScript("OnUpdate", Bartender4.Button.onUpdate) + button.icon = _G[("%sIcon"):format(name)] + button.border = _G[("%sBorder"):format(name)] + button.cooldown = _G[("%sCooldown"):format(name)] + button.macroName = _G[("%sName"):format(name)] + button.hotkey = _G[("%sHotKey"):format(name)] + button.count = _G[("%sCount"):format(name)] + button.flash = _G[("%sFlash"):format(name)] + button.BT4init = true + button:SetParent(VehicleMenuBarActionButtonFrame) + end + else + MainMenuBarArtFrame:UnregisterEvent("UNIT_ENTERING_VEHICLE") + MainMenuBarArtFrame:UnregisterEvent("UNIT_ENTERED_VEHICLE") + MainMenuBarArtFrame:UnregisterEvent("UNIT_EXITING_VEHICLE") + MainMenuBarArtFrame:UnregisterEvent("UNIT_EXITED_VEHICLE") + MainMenuBarArtFrame:UnregisterEvent("PLAYER_ENTERING_WORLD") + + local vehicleModule = Bartender4:GetModule("Vehicle") + vehicleModule.blizzardVehicle = nil + if vehicleModule.db and vehicleModule.db.profile.enabled then + vehicleModule:Enable() + end + UnregisterStateDriver(MainMenuBar, "visibility") + UnregisterStateDriver(ShapeshiftBarFrame, "visibility") + UnregisterStateDriver(PossessBarFrame, "visibility") + if self.vehicleController then + UnregisterStateDriver(self.vehicleController, "vehicle") + end + local btn = "VehicleMenuBarActionButton%d" + for i=1,6 do + local name = btn:format(i) + local button = _G[name] + button.BT4init = nil + button:SetScript("OnUpdate", ActionButton_OnUpdate) + end + end +end + +function Bartender4:CombatLockdown() + self:Lock() + LibStub("AceConfigDialog-3.0"):Close("Bartender4") +end + +function Bartender4:ToggleLock() + if self.Locked then + self:Unlock() + else + self:Lock() + end +end + +local getSnap, setSnap +do + function getSnap() + return Bartender4.db.profile.snapping + end + + function setSnap(value) + Bartender4.Bar:ForAll("StopDragging") + Bartender4.db.profile.snapping = value + LibStub("AceConfigRegistry-3.0"):NotifyChange("Bartender4") + end +end + +function Bartender4:ShowUnlockDialog() + if not self.unlock_dialog then + local f = CreateFrame('Frame', 'Bartender4Dialog', UIParent) + f:SetFrameStrata('DIALOG') + f:SetToplevel(true) + f:EnableMouse(true) + f:SetClampedToScreen(true) + f:SetWidth(360) + f:SetHeight(110) + f:SetBackdrop{ + bgFile='Interface\\DialogFrame\\UI-DialogBox-Background' , + edgeFile='Interface\\DialogFrame\\UI-DialogBox-Border', + tile = true, + insets = {left = 11, right = 12, top = 12, bottom = 11}, + tileSize = 32, + edgeSize = 32, + } + f:SetPoint('TOP', 0, -50) + f:Hide() + f:SetScript('OnShow', function() PlaySound('igMainMenuOption') end) + f:SetScript('OnHide', function() PlaySound('gsTitleOptionExit') end) + + local tr = f:CreateTitleRegion() + tr:SetAllPoints(f) + + local header = f:CreateTexture(nil, 'ARTWORK') + header:SetTexture('Interface\\DialogFrame\\UI-DialogBox-Header') + header:SetWidth(256); header:SetHeight(64) + header:SetPoint('TOP', 0, 12) + + local title = f:CreateFontString('ARTWORK') + title:SetFontObject('GameFontNormal') + title:SetPoint('TOP', header, 'TOP', 0, -14) + title:SetText(L["Bartender4"]) + + local desc = f:CreateFontString('ARTWORK') + desc:SetFontObject('GameFontHighlight') + desc:SetJustifyV('TOP') + desc:SetJustifyH('LEFT') + desc:SetPoint('TOPLEFT', 18, -32) + desc:SetPoint('BOTTOMRIGHT', -18, 48) + desc:SetText(L["Bars unlocked. Move them now and click Lock when you are done."]) + + local snapping = CreateFrame('CheckButton', 'Bartender4Snapping', f, 'OptionsCheckButtonTemplate') + _G[snapping:GetName() .. 'Text']:SetText(L["Bar Snapping"]) + + snapping:SetScript('OnShow', function(self) + self:SetChecked(getSnap()) + end) + + snapping:SetScript('OnClick', function(self) + setSnap(snapping:GetChecked()) + end) + + local lockBars = CreateFrame('CheckButton', 'Bartender4DialogLock', f, 'OptionsButtonTemplate') + getglobal(lockBars:GetName() .. 'Text'):SetText(L["Lock"]) + + lockBars:SetScript('OnClick', function(self) + Bartender4:Lock() + LibStub("AceConfigRegistry-3.0"):NotifyChange("Bartender4") + end) + + --position buttons + snapping:SetPoint('BOTTOMLEFT', 14, 10) + lockBars:SetPoint('BOTTOMRIGHT', -14, 14) + + self.unlock_dialog = f + end + self.unlock_dialog:Show() +end + +function Bartender4:HideUnlockDialog() + if self.unlock_dialog then + self.unlock_dialog:Hide() + end +end + +function Bartender4:Unlock() + if self.Locked then + self.Locked = false + Bartender4.Bar:ForAll("Unlock") + self:ShowUnlockDialog() + end +end + +function Bartender4:Lock() + if not self.Locked then + self.Locked = true + Bartender4.Bar:ForAll("Lock") + self:HideUnlockDialog() + end +end + +function Bartender4:Merge(target, source) + if type(target) ~= "table" then target = {} end + for k,v in pairs(source) do + if type(v) == "table" then + target[k] = self:Merge(target[k], v) + elseif not target[k] then + target[k] = v + end + end + return target +end + +Bartender4.modulePrototype = {} +function Bartender4.modulePrototype:ToggleModule(info, value) + if value ~= nil then + self.db.profile.enabled = value + else + value = self.db.profile.enabled + end + if value and not self:IsEnabled() then + self:Enable() + elseif not value and self:IsEnabled() then + self:Disable() + end +end + +function Bartender4.modulePrototype:ToggleOptions() + if self.options then + self.options.args = self:IsEnabled() and self.optionobject.table or self.disabledoptions + end +end + +function Bartender4.modulePrototype:OnDisable() + if not self.bar then return end + -- assign new config table + self.bar.config = self.db.profile + self.bar:Disable() + self:ToggleOptions() +end + +Bartender4:SetDefaultModulePrototype(Bartender4.modulePrototype) + +function createLDBLauncher() + local L_BT_LEFT = L["|cffffff00Click|r to toggle bar lock"] + local L_BT_RIGHT = L["|cffffff00Right-click|r to open the options menu"] + + local LDBObj = LibStub("LibDataBroker-1.1"):NewDataObject("Bartender4", { + type = "launcher", + label = "Bartender4", + OnClick = function(_, msg) + if msg == "LeftButton" then + if Bartender4.Locked then + Bartender4["Unlock"](Bartender4) + else + Bartender4["Lock"](Bartender4) + end + elseif msg == "RightButton" then + if LibStub("AceConfigDialog-3.0").OpenFrames["Bartender4"] then + LibStub("AceConfigDialog-3.0"):Close("Bartender4") + else + LibStub("AceConfigDialog-3.0"):Open("Bartender4") + end + end + end, + icon = "Interface\\Icons\\INV_Drink_05", + OnTooltipShow = function(tooltip) + if not tooltip or not tooltip.AddLine then return end + tooltip:AddLine("Bartender4") + tooltip:AddLine(L_BT_LEFT) + tooltip:AddLine(L_BT_RIGHT) + end, + }) + + if LDBIcon then + LDBIcon:Register("Bartender4", LDBObj, Bartender4.db.profile.minimapIcon) + end +end diff --git a/Bartender4.toc b/Bartender4.toc index d3f3412..90c257f 100644 --- a/Bartender4.toc +++ b/Bartender4.toc @@ -1,69 +1,73 @@ -## Interface: 30300 - -## Title: Bartender4 -## Notes: Simple and Advanced combined - Bartender4 ActionBar AddOn - -## Version: @project-version@ - -## Author: Nevcairiel -## X-Email: h.leppkes at gmail dot com - -## X-Category: Action Bars -## X-Website: http://www.wowace.com/projects/bartender4/ -## X-License: All rights reserved. - -## SavedVariables: Bartender4DB -## OptionalDeps: Ace3, ButtonFacade, LibKeyBound-1.0, LibDBIcon-1.0, LibWindow-1.1 - -#@no-lib-strip@ -libs\LibStub\LibStub.lua -libs\CallbackHandler-1.0\CallbackHandler-1.0.xml -#@end-no-lib-strip@ - -libs\LibDataBroker-1.1.lua - -#@no-lib-strip@ -libs\AceAddon-3.0\AceAddon-3.0.xml -libs\AceDB-3.0\AceDB-3.0.xml -libs\AceDBOptions-3.0\AceDBOptions-3.0.xml -libs\AceEvent-3.0\AceEvent-3.0.xml -libs\AceConsole-3.0\AceConsole-3.0.xml -libs\AceHook-3.0\AceHook-3.0.xml -libs\AceLocale-3.0\AceLocale-3.0.xml -libs\AceGUI-3.0\AceGUI-3.0.xml -libs\AceConfig-3.0\AceConfig-3.0.xml - -libs\LibKeyBound-1.0\lib.xml -libs\LibDBIcon-1.0\LibDBIcon-1.0.lua -libs\LibWindow-1.1\LibWindow-1.1.lua -#@end-no-lib-strip@ - -libs\SimpleSticky.lua - -locale\locale.xml - -## Core ## -Bartender4.lua - -## Prototypes ## -Bar.lua -ButtonBar.lua -StateBar.lua -ActionBar.lua - -## Buttons ## -ActionButton.lua -PetButton.lua - -## Modules ## -ActionBars.lua -BagBar.lua -PetBar.lua -StanceBar.lua -MicroMenu.lua -RepXPBar.lua -VehicleBar.lua -MultiCastBar.lua - -## Options ## -Options\Options.xml +## Interface: 30300 +## X-Curse-Packaged-Version: 4.4.2-2-g3b02ee4 +## X-Curse-Project-Name: Bartender4 +## X-Curse-Project-ID: bartender4 +## X-Curse-Repository-ID: wow/bartender4/mainline + +## Title: Bartender4 +## Notes: Simple and Advanced combined - Bartender4 ActionBar AddOn + +## Version: 4.4.2-2-g3b02ee4 + +## Author: Nevcairiel +## X-Email: h.leppkes at gmail dot com + +## X-Category: Action Bars +## X-Website: http://www.wowace.com/projects/bartender4/ +## X-License: All rights reserved. + +## SavedVariables: Bartender4DB +## OptionalDeps: Ace3, ButtonFacade, LibKeyBound-1.0, LibDBIcon-1.0, LibWindow-1.1 + +#@no-lib-strip@ +libs\LibStub\LibStub.lua +libs\CallbackHandler-1.0\CallbackHandler-1.0.xml +#@end-no-lib-strip@ + +libs\LibDataBroker-1.1.lua + +#@no-lib-strip@ +libs\AceAddon-3.0\AceAddon-3.0.xml +libs\AceDB-3.0\AceDB-3.0.xml +libs\AceDBOptions-3.0\AceDBOptions-3.0.xml +libs\AceEvent-3.0\AceEvent-3.0.xml +libs\AceConsole-3.0\AceConsole-3.0.xml +libs\AceHook-3.0\AceHook-3.0.xml +libs\AceLocale-3.0\AceLocale-3.0.xml +libs\AceGUI-3.0\AceGUI-3.0.xml +libs\AceConfig-3.0\AceConfig-3.0.xml + +libs\LibKeyBound-1.0\lib.xml +libs\LibDBIcon-1.0\LibDBIcon-1.0.lua +libs\LibWindow-1.1\LibWindow-1.1.lua +#@end-no-lib-strip@ + +libs\SimpleSticky.lua + +locale\locale.xml + +## Core ## +Bartender4.lua + +## Prototypes ## +Bar.lua +ButtonBar.lua +StateBar.lua +ActionBar.lua + +## Buttons ## +ActionButton.lua +PetButton.lua + +## Modules ## +ActionBars.lua +BagBar.lua +PetBar.lua +StanceBar.lua +MicroMenu.lua +RepXPBar.lua +VehicleBar.lua +MultiCastBar.lua + +## Options ## +Options\Options.xml diff --git a/Bindings.xml b/Bindings.xml index e1a050e..6ce86d9 100644 --- a/Bindings.xml +++ b/Bindings.xml @@ -1,142 +1,150 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + if InCombatLockdown() then + print("Cannot change the button lock during combat.") + return + end + Bartender4.db.profile.buttonlock = not Bartender4.db.profile.buttonlock + Bartender4.Bar:ForAll("ForAll", "SetAttribute", "buttonlock", Bartender4.db.profile.buttonlock) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ButtonBar.lua b/ButtonBar.lua index b51eb0f..14c2434 100644 --- a/ButtonBar.lua +++ b/ButtonBar.lua @@ -1,259 +1,259 @@ ---[[ - Copyright (c) 2009, Hendrik "Nevcairiel" Leppkes < h.leppkes at gmail dot com > - All rights reserved. -]] ---[[ Generic Template for a Bar which contains Buttons ]] - -local Bar = Bartender4.Bar.prototype -local ButtonBar = setmetatable({}, {__index = Bar}) -local ButtonBar_MT = {__index = ButtonBar} - -local defaults = Bartender4:Merge({ - padding = 2, - rows = 1, - hidemacrotext = false, - hidehotkey = false, - skin = { - ID = "DreamLayout", - Backdrop = true, - Gloss = 0, - Zoom = false, - Colors = {}, - }, -}, Bartender4.Bar.defaults) - -Bartender4.ButtonBar = {} -Bartender4.ButtonBar.prototype = ButtonBar -Bartender4.ButtonBar.defaults = defaults - -local LBF = LibStub("LibButtonFacade", true) - -function Bartender4.ButtonBar:Create(id, config, name) - local bar = setmetatable(Bartender4.Bar:Create(id, config, name), ButtonBar_MT) - - if LBF then - bar.LBFGroup = LBF:Group("Bartender4", tostring(id)) - bar.LBFGroup.SkinID = config.skin.ID or "Blizzard" - bar.LBFGroup.Backdrop = config.skin.Backdrop - bar.LBFGroup.Gloss = config.skin.Gloss - bar.LBFGroup.Colors = config.skin.Colors - - LBF:RegisterSkinCallback("Bartender4", self.SkinChanged, self) - end - - return bar -end - -local barregistry = Bartender4.Bar.barregistry -function Bartender4.ButtonBar:SkinChanged(SkinID, Gloss, Backdrop, Group, Button, Colors) - local bar = barregistry[tostring(Group)] - if not bar then return end - - bar:SkinChanged(SkinID, Gloss, Backdrop, Colors, Button) -end - -ButtonBar.BT4BarType = "ButtonBar" - -function ButtonBar:UpdateSkin() - if not self.LBFGroup then return end - local config = self.config - self.LBFGroup:Skin(config.skin.ID, config.skin.Gloss, config.skin.Backdrop, config.skin.Colors) -end - -function ButtonBar:ApplyConfig(config) - Bar.ApplyConfig(self, config) - ButtonBar.UpdateSkin(self) - -- any module inherting this template should call UpdateButtonLayout after setting up its buttons, we cannot call it here - --self:UpdateButtonLayout() -end - --- get the current padding -function ButtonBar:GetPadding() - return self.config.padding -end - --- set the padding and refresh layout -function ButtonBar:SetPadding(pad) - if pad ~= nil then - self.config.padding = pad - end - self:UpdateButtonLayout() -end - - --- get the current number of rows -function ButtonBar:GetRows() - return self.config.rows -end - --- set the number of rows and refresh layout -function ButtonBar:SetRows(rows) - if rows ~= nil then - self.config.rows = rows - end - self:UpdateButtonLayout() -end - -function ButtonBar:GetZoom() - return self.config.skin.Zoom -end - -function ButtonBar:SetZoom(zoom) - self.config.skin.Zoom = zoom - self:UpdateButtonLayout() -end - -function ButtonBar:SetHideMacroText(state) - if state ~= nil then - self.config.hidemacrotext = state - end - self:ForAll("Update") -end - -function ButtonBar:GetHideMacroText() - return self.config.hidemacrotext -end - -function ButtonBar:SetHideHotkey(state) - if state ~= nil then - self.config.hidehotkey = state - end - self:ForAll("Update") -end - -function ButtonBar:GetHideHotkey() - return self.config.hidehotkey -end - -function ButtonBar:SetHGrowth(value) - self.config.position.growHorizontal = value - self:AnchorOverlay() - self:UpdateButtonLayout() -end - -function ButtonBar:GetHGrowth() - return self.config.position.growHorizontal -end - -function ButtonBar:SetVGrowth(value) - self.config.position.growVertical = value - self:AnchorOverlay() - self:UpdateButtonLayout() -end - -function ButtonBar:GetVGrowth() - return self.config.position.growVertical -end - - -ButtonBar.ClickThroughSupport = true -function ButtonBar:SetClickThrough(click) - if click ~= nil then - self.config.clickthrough = click - end - self:ForAll("EnableMouse", not self.config.clickthrough) -end - -local math_floor = math.floor -local math_ceil = math.ceil --- align the buttons and correct the size of the bar overlay frame -ButtonBar.button_width = 36 -ButtonBar.button_height = 36 -function ButtonBar:UpdateButtonLayout() - local buttons = self.buttons - local pad = self:GetPadding() - - local numbuttons = self.numbuttons or #buttons - - -- bail out if the bar has no buttons, for whatever reason - -- (eg. stanceless class, or no stances learned yet, etc.) - if numbuttons == 0 then return end - - local Rows = self:GetRows() - local ButtonPerRow = math_ceil(numbuttons / Rows) -- just a precaution - Rows = math_ceil(numbuttons / ButtonPerRow) - if Rows > numbuttons then - Rows = numbuttons - ButtonPerRow = 1 - end - - local hpad = pad + (self.hpad_offset or 0) - local vpad = pad + (self.vpad_offset or 0) - - self:SetSize((self.button_width + hpad) * ButtonPerRow - pad + 10, (self.button_height + vpad) * Rows - pad + 10) - - local h1, h2, v1, v2 - local xOff, yOff - if self.config.position.growHorizontal == "RIGHT" then - h1, h2 = "LEFT", "RIGHT" - xOff = 5 - else - h1, h2 = "RIGHT", "LEFT" - xOff = -3 - - hpad = -hpad - end - - if self.config.position.growVertical == "DOWN" then - v1, v2 = "TOP", "BOTTOM" - yOff = -3 - else - v1, v2 = "BOTTOM", "TOP" - yOff = 5 - - vpad = -vpad - end - - -- anchor button 1 - local anchor = self:GetAnchor() - buttons[1]:ClearSetPoint(anchor, self, anchor, xOff - (self.hpad_offset or 0), yOff - (self.vpad_offset or 0)) - - -- and anchor all other buttons relative to our button 1 - for i = 2, numbuttons do - -- jump into a new row - if ((i-1) % ButtonPerRow) == 0 then - buttons[i]:ClearSetPoint(v1 .. h1, buttons[i-ButtonPerRow], v2 .. h1, 0, -vpad) - -- align to the previous button - else - buttons[i]:ClearSetPoint("TOP" .. h1, buttons[i-1], "TOP" .. h2, hpad, 0) - end - end - - if not LBF then - for i = 1, #buttons do - local button = buttons[i] - if button.icon and self.config.skin.Zoom then - button.icon:SetTexCoord(0.07,0.93,0.07,0.93) - elseif button.icon then - button.icon:SetTexCoord(0,1,0,1) - end - end - end -end - -function ButtonBar:SkinChanged(SkinID, Gloss, Backdrop, Colors) - self.config.skin.ID = SkinID - self.config.skin.Gloss = Gloss - self.config.skin.Backdrop = Backdrop - self.config.skin.Colors = Colors -end - ---[[=================================================================================== - Utility function -===================================================================================]]-- - --- get a iterator over all buttons -function ButtonBar:GetAll() - return pairs(self.buttons) -end - --- execute a member function on all buttons -function ButtonBar:ForAll(method, ...) - if not self.buttons then return end - for _, button in self:GetAll() do - local func = button[method] - if func then - func(button, ...) - end - end -end +--[[ + Copyright (c) 2009, Hendrik "Nevcairiel" Leppkes < h.leppkes at gmail dot com > + All rights reserved. +]] +--[[ Generic Template for a Bar which contains Buttons ]] + +local Bar = Bartender4.Bar.prototype +local ButtonBar = setmetatable({}, {__index = Bar}) +local ButtonBar_MT = {__index = ButtonBar} + +local defaults = Bartender4:Merge({ + padding = 2, + rows = 1, + hidemacrotext = false, + hidehotkey = false, + skin = { + ID = "DreamLayout", + Backdrop = true, + Gloss = 0, + Zoom = false, + Colors = {}, + }, +}, Bartender4.Bar.defaults) + +Bartender4.ButtonBar = {} +Bartender4.ButtonBar.prototype = ButtonBar +Bartender4.ButtonBar.defaults = defaults + +local LBF = LibStub("LibButtonFacade", true) + +function Bartender4.ButtonBar:Create(id, config, name) + local bar = setmetatable(Bartender4.Bar:Create(id, config, name), ButtonBar_MT) + + if LBF then + bar.LBFGroup = LBF:Group("Bartender4", tostring(id)) + bar.LBFGroup.SkinID = config.skin.ID or "Blizzard" + bar.LBFGroup.Backdrop = config.skin.Backdrop + bar.LBFGroup.Gloss = config.skin.Gloss + bar.LBFGroup.Colors = config.skin.Colors + + LBF:RegisterSkinCallback("Bartender4", self.SkinChanged, self) + end + + return bar +end + +local barregistry = Bartender4.Bar.barregistry +function Bartender4.ButtonBar:SkinChanged(SkinID, Gloss, Backdrop, Group, Button, Colors) + local bar = barregistry[tostring(Group)] + if not bar then return end + + bar:SkinChanged(SkinID, Gloss, Backdrop, Colors, Button) +end + +ButtonBar.BT4BarType = "ButtonBar" + +function ButtonBar:UpdateSkin() + if not self.LBFGroup then return end + local config = self.config + self.LBFGroup:Skin(config.skin.ID, config.skin.Gloss, config.skin.Backdrop, config.skin.Colors) +end + +function ButtonBar:ApplyConfig(config) + Bar.ApplyConfig(self, config) + ButtonBar.UpdateSkin(self) + -- any module inherting this template should call UpdateButtonLayout after setting up its buttons, we cannot call it here + --self:UpdateButtonLayout() +end + +-- get the current padding +function ButtonBar:GetPadding() + return self.config.padding +end + +-- set the padding and refresh layout +function ButtonBar:SetPadding(pad) + if pad ~= nil then + self.config.padding = pad + end + self:UpdateButtonLayout() +end + + +-- get the current number of rows +function ButtonBar:GetRows() + return self.config.rows +end + +-- set the number of rows and refresh layout +function ButtonBar:SetRows(rows) + if rows ~= nil then + self.config.rows = rows + end + self:UpdateButtonLayout() +end + +function ButtonBar:GetZoom() + return self.config.skin.Zoom +end + +function ButtonBar:SetZoom(zoom) + self.config.skin.Zoom = zoom + self:UpdateButtonLayout() +end + +function ButtonBar:SetHideMacroText(state) + if state ~= nil then + self.config.hidemacrotext = state + end + self:ForAll("Update") +end + +function ButtonBar:GetHideMacroText() + return self.config.hidemacrotext +end + +function ButtonBar:SetHideHotkey(state) + if state ~= nil then + self.config.hidehotkey = state + end + self:ForAll("Update") +end + +function ButtonBar:GetHideHotkey() + return self.config.hidehotkey +end + +function ButtonBar:SetHGrowth(value) + self.config.position.growHorizontal = value + self:AnchorOverlay() + self:UpdateButtonLayout() +end + +function ButtonBar:GetHGrowth() + return self.config.position.growHorizontal +end + +function ButtonBar:SetVGrowth(value) + self.config.position.growVertical = value + self:AnchorOverlay() + self:UpdateButtonLayout() +end + +function ButtonBar:GetVGrowth() + return self.config.position.growVertical +end + + +ButtonBar.ClickThroughSupport = true +function ButtonBar:SetClickThrough(click) + if click ~= nil then + self.config.clickthrough = click + end + self:ForAll("EnableMouse", not self.config.clickthrough) +end + +local math_floor = math.floor +local math_ceil = math.ceil +-- align the buttons and correct the size of the bar overlay frame +ButtonBar.button_width = 36 +ButtonBar.button_height = 36 +function ButtonBar:UpdateButtonLayout() + local buttons = self.buttons + local pad = self:GetPadding() + + local numbuttons = self.numbuttons or #buttons + + -- bail out if the bar has no buttons, for whatever reason + -- (eg. stanceless class, or no stances learned yet, etc.) + if numbuttons == 0 then return end + + local Rows = self:GetRows() + local ButtonPerRow = math_ceil(numbuttons / Rows) -- just a precaution + Rows = math_ceil(numbuttons / ButtonPerRow) + if Rows > numbuttons then + Rows = numbuttons + ButtonPerRow = 1 + end + + local hpad = pad + (self.hpad_offset or 0) + local vpad = pad + (self.vpad_offset or 0) + + self:SetSize((self.button_width + hpad) * ButtonPerRow - pad + 10, (self.button_height + vpad) * Rows - pad + 10) + + local h1, h2, v1, v2 + local xOff, yOff + if self.config.position.growHorizontal == "RIGHT" then + h1, h2 = "LEFT", "RIGHT" + xOff = 5 + else + h1, h2 = "RIGHT", "LEFT" + xOff = -3 + + hpad = -hpad + end + + if self.config.position.growVertical == "DOWN" then + v1, v2 = "TOP", "BOTTOM" + yOff = -3 + else + v1, v2 = "BOTTOM", "TOP" + yOff = 5 + + vpad = -vpad + end + + -- anchor button 1 + local anchor = self:GetAnchor() + buttons[1]:ClearSetPoint(anchor, self, anchor, xOff - (self.hpad_offset or 0), yOff - (self.vpad_offset or 0)) + + -- and anchor all other buttons relative to our button 1 + for i = 2, numbuttons do + -- jump into a new row + if ((i-1) % ButtonPerRow) == 0 then + buttons[i]:ClearSetPoint(v1 .. h1, buttons[i-ButtonPerRow], v2 .. h1, 0, -vpad) + -- align to the previous button + else + buttons[i]:ClearSetPoint("TOP" .. h1, buttons[i-1], "TOP" .. h2, hpad, 0) + end + end + + if not LBF then + for i = 1, #buttons do + local button = buttons[i] + if button.icon and self.config.skin.Zoom then + button.icon:SetTexCoord(0.07,0.93,0.07,0.93) + elseif button.icon then + button.icon:SetTexCoord(0,1,0,1) + end + end + end +end + +function ButtonBar:SkinChanged(SkinID, Gloss, Backdrop, Colors) + self.config.skin.ID = SkinID + self.config.skin.Gloss = Gloss + self.config.skin.Backdrop = Backdrop + self.config.skin.Colors = Colors +end + +--[[=================================================================================== + Utility function +===================================================================================]]-- + +-- get a iterator over all buttons +function ButtonBar:GetAll() + return pairs(self.buttons) +end + +-- execute a member function on all buttons +function ButtonBar:ForAll(method, ...) + if not self.buttons then return end + for _, button in self:GetAll() do + local func = button[method] + if func then + func(button, ...) + end + end +end diff --git a/Changelog-Bartender4-4.4.2-2-g3b02ee4.txt b/Changelog-Bartender4-4.4.2-2-g3b02ee4.txt new file mode 100644 index 0000000..deb289f --- /dev/null +++ b/Changelog-Bartender4-4.4.2-2-g3b02ee4.txt @@ -0,0 +1,3 @@ +Hendrik Leppkes: + - Improved sliders in the options with softMin/softMax and bigStep to offer more freedom in configuration. + - Remove old unused option code snippet diff --git a/MicroMenu.lua b/MicroMenu.lua index 9d62456..d13987e 100644 --- a/MicroMenu.lua +++ b/MicroMenu.lua @@ -1,97 +1,98 @@ ---[[ - Copyright (c) 2009, Hendrik "Nevcairiel" Leppkes < h.leppkes at gmail dot com > - All rights reserved. -]] -local L = LibStub("AceLocale-3.0"):GetLocale("Bartender4") --- register module -local MicroMenuMod = Bartender4:NewModule("MicroMenu", "AceHook-3.0") - --- fetch upvalues -local ButtonBar = Bartender4.ButtonBar.prototype - --- create prototype information -local MicroMenuBar = setmetatable({}, {__index = ButtonBar}) - -local table_insert = table.insert - -local defaults = { profile = Bartender4:Merge({ - enabled = true, - vertical = false, - visibility = { - possess = false, - }, - padding = -3, - position = { - scale = 0.8, - }, -}, Bartender4.ButtonBar.defaults) } - -function MicroMenuMod:OnInitialize() - self.db = Bartender4.db:RegisterNamespace("MicroMenu", defaults) - self:SetEnabledState(self.db.profile.enabled) -end - -function MicroMenuMod:OnEnable() - if not self.bar then - self.bar = setmetatable(Bartender4.ButtonBar:Create("MicroMenu", self.db.profile, L["Micro Menu"]), {__index = MicroMenuBar}) - local buttons = {} - table_insert(buttons, CharacterMicroButton) - table_insert(buttons, SpellbookMicroButton) - table_insert(buttons, TalentMicroButton) - table_insert(buttons, AchievementMicroButton) - table_insert(buttons, QuestLogMicroButton) - table_insert(buttons, SocialsMicroButton) - table_insert(buttons, PVPMicroButton) - table_insert(buttons, LFDMicroButton) - table_insert(buttons, MainMenuMicroButton) - table_insert(buttons, HelpMicroButton) - self.bar.buttons = buttons - - MicroMenuMod.button_count = #buttons - - self:SecureHook("UpdateMicroButtons") - - for i,v in pairs(buttons) do - v:SetParent(self.bar) - v:Show() - v:SetFrameLevel(self.bar:GetFrameLevel() + 1) - v.ClearSetPoint = self.bar.ClearSetPoint - end - end - self.bar:Enable() - self:ToggleOptions() - self:ApplyConfig() -end - -function MicroMenuMod:ApplyConfig() - self.bar:ApplyConfig(self.db.profile) -end - -function MicroMenuMod:RestoreButtons() - if not self:IsEnabled() then return end - for k,v in pairs(self.bar.buttons) do - v:SetParent(self.bar) - v:Show() - end - self.bar:UpdateButtonLayout() -end - -function MicroMenuMod:UpdateMicroButtons() - if MainMenuBar.state == "player" then - self:RestoreButtons() - end -end - -MicroMenuBar.button_width = 28 -MicroMenuBar.button_height = 58 -MicroMenuBar.vpad_offset = -21 -function MicroMenuBar:ApplyConfig(config) - ButtonBar.ApplyConfig(self, config) - - if not self.config.position.x then - self:ClearSetPoint("CENTER", -105, 30) - self:SavePosition() - end - - self:UpdateButtonLayout() -end +--[[ + Copyright (c) 2009, Hendrik "Nevcairiel" Leppkes < h.leppkes at gmail dot com > + All rights reserved. +]] +local L = LibStub("AceLocale-3.0"):GetLocale("Bartender4") +-- register module +local MicroMenuMod = Bartender4:NewModule("MicroMenu", "AceHook-3.0") + +-- fetch upvalues +local ButtonBar = Bartender4.ButtonBar.prototype + +-- create prototype information +local MicroMenuBar = setmetatable({}, {__index = ButtonBar}) + +local table_insert = table.insert + +local defaults = { profile = Bartender4:Merge({ + enabled = true, + vertical = false, + visibility = { + possess = false, + }, + padding = -3, + position = { + scale = 0.8, + }, +}, Bartender4.ButtonBar.defaults) } + +function MicroMenuMod:OnInitialize() + self.db = Bartender4.db:RegisterNamespace("MicroMenu", defaults) + self:SetEnabledState(self.db.profile.enabled) +end + +function MicroMenuMod:OnEnable() + if not self.bar then + self.bar = setmetatable(Bartender4.ButtonBar:Create("MicroMenu", self.db.profile, L["Micro Menu"]), {__index = MicroMenuBar}) + local buttons = {} + table_insert(buttons, CharacterMicroButton) + table_insert(buttons, SpellbookMicroButton) + table_insert(buttons, TalentMicroButton) + table_insert(buttons, AchievementMicroButton) + table_insert(buttons, QuestLogMicroButton) + table_insert(buttons, SocialsMicroButton) + table_insert(buttons, LFDMicroButton) + table_insert(buttons, PathToAscensionMicroButton) + table_insert(buttons, MainMenuMicroButton) + table_insert(buttons, HelpMicroButton) + table_insert(buttons, ChallengesMicroButton) + self.bar.buttons = buttons + + MicroMenuMod.button_count = #buttons + + self:SecureHook("UpdateMicroButtons") + + for i,v in pairs(buttons) do + v:SetParent(self.bar) + v:Show() + v:SetFrameLevel(self.bar:GetFrameLevel() + 1) + v.ClearSetPoint = self.bar.ClearSetPoint + end + end + self.bar:Enable() + self:ToggleOptions() + self:ApplyConfig() +end + +function MicroMenuMod:ApplyConfig() + self.bar:ApplyConfig(self.db.profile) +end + +function MicroMenuMod:RestoreButtons() + if not self:IsEnabled() then return end + for k,v in pairs(self.bar.buttons) do + v:SetParent(self.bar) + v:Show() + end + self.bar:UpdateButtonLayout() +end + +function MicroMenuMod:UpdateMicroButtons() + if MainMenuBar.state == "player" then + self:RestoreButtons() + end +end + +MicroMenuBar.button_width = 27 +MicroMenuBar.button_height = 40 +MicroMenuBar.vpad_offset = 0 +function MicroMenuBar:ApplyConfig(config) + ButtonBar.ApplyConfig(self, config) + + if not self.config.position.x then + self:ClearSetPoint("CENTER", -105, 30) + self:SavePosition() + end + + self:UpdateButtonLayout() +end diff --git a/MultiCastBar.lua b/MultiCastBar.lua index a11eac3..1521061 100644 --- a/MultiCastBar.lua +++ b/MultiCastBar.lua @@ -1,61 +1,74 @@ ---[[ - Copyright (c) 2009, Hendrik "Nevcairiel" Leppkes < h.leppkes at gmail dot com > - All rights reserved. -]] - -if not HasMultiCastActionBar or select(2, UnitClass("player")) ~= "SHAMAN" then return end - --- fetch upvalues -local L = LibStub("AceLocale-3.0"):GetLocale("Bartender4") -local Bar = Bartender4.Bar.prototype - -local defaults = { profile = Bartender4:Merge({ - enabled = true, -}, Bartender4.Bar.defaults) } - --- register module -local MultiCastMod = Bartender4:NewModule("MultiCast") - --- create prototype information -local MultiCastBar = setmetatable({}, {__index = Bar}) - -function MultiCastMod:OnInitialize() - self.db = Bartender4.db:RegisterNamespace("MultiCast", defaults) - self:SetEnabledState(self.db.profile.enabled) -end - -function MultiCastMod:OnEnable() - if not self.bar then - self.bar = setmetatable(Bartender4.Bar:Create("MultiCast", self.db.profile, L["Totem Bar"]), {__index = MultiCastBar}) - self.bar.content = MultiCastActionBarFrame - self.bar.content:SetScript("OnShow", nil) - self.bar.content:SetScript("OnHide", nil) - self.bar.content:SetScript("OnUpdate", nil) - self.bar.content.ignoreFramePositionManager = true - - self.bar.content:SetParent(self.bar) - self.bar.content:Show() - self.bar.content:SetFrameLevel(self.bar:GetFrameLevel() + 1) - end - self.bar:Enable() - self:ToggleOptions() - self:ApplyConfig() -end - -function MultiCastMod:ApplyConfig() - if not self:IsEnabled() then return end - self.bar:ApplyConfig(self.db.profile) -end - -function MultiCastBar:ApplyConfig(config) - Bar.ApplyConfig(self, config) - - self:PerformLayout() -end - -function MultiCastBar:PerformLayout() - self:SetSize(230, 40) - local bar = self.content - bar:ClearAllPoints() - bar:SetPoint("TOPLEFT", self, "TOPLEFT", 3, 1) -end +--[[ + Copyright (c) 2009, Hendrik "Nevcairiel" Leppkes < h.leppkes at gmail dot com > + All rights reserved. +]] + +if not HasMultiCastActionBar then return end + +local classMask = UnitClassMask("player") + +if not bit.contains(EnumUtil.CombineMasks(Enum.ClassMask.SHAMAN, Enum.ClassMask.HERO), classMask) then + return +end + +-- fetch upvalues +local L = LibStub("AceLocale-3.0"):GetLocale("Bartender4") +local Bar = Bartender4.Bar.prototype + +local defaults = { profile = Bartender4:Merge({ + enabled = true, +}, Bartender4.Bar.defaults) } + +-- register module +local MultiCastMod = Bartender4:NewModule("MultiCast") + +-- create prototype information +local MultiCastBar = setmetatable({}, {__index = Bar}) + +local function OnShowMultiCastActionBar() + if MultiCastMod:IsEnabled() then + MultiCastMod:ApplyConfig() + end +end + +function MultiCastMod:OnInitialize() + hooksecurefunc("ShowMultiCastActionBar", OnShowMultiCastActionBar) + self.db = Bartender4.db:RegisterNamespace("MultiCast", defaults) + self:SetEnabledState(self.db.profile.enabled) +end + +function MultiCastMod:OnEnable() + if not self.bar then + self.bar = setmetatable(Bartender4.Bar:Create("MultiCast", self.db.profile, L["Totem Bar"]), {__index = MultiCastBar}) + self.bar.content = MultiCastActionBarFrame + self.bar.content:SetScript("OnShow", nil) + self.bar.content:SetScript("OnHide", nil) + self.bar.content:SetScript("OnUpdate", nil) + self.bar.content.ignoreFramePositionManager = true + + self.bar.content:SetParent(self.bar) + self.bar.content:Show() + self.bar.content:SetFrameLevel(self.bar:GetFrameLevel() + 1) + end + self.bar:Enable() + self:ToggleOptions() + self:ApplyConfig() +end + +function MultiCastMod:ApplyConfig() + if not self:IsEnabled() then return end + self.bar:ApplyConfig(self.db.profile) +end + +function MultiCastBar:ApplyConfig(config) + Bar.ApplyConfig(self, config) + + self:PerformLayout() +end + +function MultiCastBar:PerformLayout() + self:SetSize(230, 40) + local bar = self.content + bar:ClearAllPoints() + bar:SetPoint("TOPLEFT", self, "TOPLEFT", 3, 1) +end diff --git a/Options/AceGUIWidget-NumberEditBox.lua b/Options/AceGUIWidget-NumberEditBox.lua index f7dd5fc..cee5384 100644 --- a/Options/AceGUIWidget-NumberEditBox.lua +++ b/Options/AceGUIWidget-NumberEditBox.lua @@ -1,216 +1,216 @@ -local AceGUI = LibStub("AceGUI-3.0") - --------------------------- --- Edit box -- --------------------------- ---[[ - Events : - OnTextChanged - OnEnterPressed - -]] -do - local Type = "NumberEditBox" - local Version = 1 - - local function OnAcquire(self) - self:SetDisabled(false) - self.showbutton = true - end - - local function OnRelease(self) - self.frame:ClearAllPoints() - self.frame:Hide() - self:SetDisabled(false) - end - - local function Control_OnEnter(this) - this.obj:Fire("OnEnter") - end - - local function Control_OnLeave(this) - this.obj:Fire("OnLeave") - end - - local function EditBox_OnEscapePressed(this) - this:ClearFocus() - end - - local function ShowButton(self) - if self.showbutton then - self.button:Show() - self.editbox:SetTextInsets(0,20,3,3) - end - end - - local function HideButton(self) - self.button:Hide() - self.editbox:SetTextInsets(0,0,3,3) - end - - local function EditBox_OnEnterPressed(this) - local self = this.obj - local value = tonumber(this:GetText()) or 0 - local cancel = self:Fire("OnEnterPressed",value) - if not cancel then - HideButton(self) - end - end - - local function Button_OnClick(this) - local editbox = this.obj.editbox - editbox:ClearFocus() - EditBox_OnEnterPressed(editbox) - end - - local function EditBox_OnTextChanged(this) - local self = this.obj - local value = tonumber(this:GetText()) or 0 - if value ~= self.lastvalue then - self:Fire("OnTextChanged",value) - self.lastvalue = value - ShowButton(self) - end - end - - local function SetDisabled(self, disabled) - self.disabled = disabled - if disabled then - self.editbox:EnableMouse(false) - self.editbox:ClearFocus() - self.editbox:SetTextColor(0.5,0.5,0.5) - self.label:SetTextColor(0.5,0.5,0.5) - else - self.editbox:EnableMouse(true) - self.editbox:SetTextColor(1,1,1) - self.label:SetTextColor(1,.82,0) - end - end - - local function SetText(self, text) - self.lastvalue = tonumber(text) or 0 - self.editbox:SetText(tostring(self.lastvalue)) - self.editbox:SetCursorPosition(0) - HideButton(self) - end - - local function SetWidth(self, width) - self.frame:SetWidth(width) - end - - local function SetLabel(self, text) - if text and text ~= "" then - self.label:SetText(text) - self.label:Show() - self.editbox:SetPoint("TOPLEFT",self.frame,"TOPLEFT",7,-18) - self.frame:SetHeight(60) - self.alignoffset = 30 - else - self.label:SetText("") - self.label:Hide() - self.editbox:SetPoint("TOPLEFT",self.frame,"TOPLEFT",7,0) - self.frame:SetHeight(42) - self.alignoffset = 12 - end - end - - local function ModButton_OnClick(self) - local value = self.obj.lastvalue - value = math.floor(value + 0.5) + self.adjust - self.obj.editbox:SetText(tostring(value)) - EditBox_OnEnterPressed(self.obj.editbox) - end - - local function Constructor() - local num = AceGUI:GetNextWidgetNum(Type) - local frame = CreateFrame("Frame",nil,UIParent) - local editbox = CreateFrame("EditBox","AceGUI-3.0NumberEditBox"..num,frame,"InputBoxTemplate") - - local self = {} - self.type = Type - self.num = num - - self.OnRelease = OnRelease - self.OnAcquire = OnAcquire - - self.SetDisabled = SetDisabled - self.SetText = SetText - self.SetWidth = SetWidth - self.SetLabel = SetLabel - - self.frame = frame - frame.obj = self - self.editbox = editbox - editbox.obj = self - - self.alignoffset = 30 - - frame:SetHeight(60) - frame:SetWidth(200) - - editbox:SetScript("OnEnter",Control_OnEnter) - editbox:SetScript("OnLeave",Control_OnLeave) - - editbox:SetAutoFocus(false) - editbox:SetFontObject(ChatFontNormal) - editbox:SetScript("OnEscapePressed",EditBox_OnEscapePressed) - editbox:SetScript("OnEnterPressed",EditBox_OnEnterPressed) - editbox:SetScript("OnTextChanged",EditBox_OnTextChanged) - - editbox:SetTextInsets(0,0,3,3) - editbox:SetMaxLetters(256) - - editbox:SetPoint("BOTTOMLEFT",frame,"BOTTOMLEFT",6,15) - editbox:SetPoint("BOTTOMRIGHT",frame,"BOTTOMRIGHT",0,15) - editbox:SetHeight(19) - - local label = frame:CreateFontString(nil,"OVERLAY","GameFontNormalSmall") - label:SetPoint("TOPLEFT",frame,"TOPLEFT",0,-2) - label:SetPoint("TOPRIGHT",frame,"TOPRIGHT",0,-2) - label:SetJustifyH("LEFT") - label:SetHeight(18) - self.label = label - - local button = CreateFrame("Button",nil,editbox,"UIPanelButtonTemplate") - button:SetWidth(40) - button:SetHeight(20) - button:SetPoint("RIGHT",editbox,"RIGHT",-2,0) - button:SetText(OKAY) - button:SetScript("OnClick", Button_OnClick) - button:Hide() - - self.button = button - button.obj = self - - local minus = CreateFrame("Button", nil, frame, "UIPanelButtonTemplate") - minus:SetWidth(20) - minus:SetHeight(15) - minus:SetPoint("TOPLEFT", editbox, "BOTTOMLEFT", -4, 0) - minus:SetText("-") - minus:Show() - minus.adjust = -1 - minus:SetScript("OnClick", ModButton_OnClick) - minus:SetFrameLevel(editbox:GetFrameLevel() + 2) - - self.minus = minus - minus.obj = self - - local plus = CreateFrame("Button", nil, frame, "UIPanelButtonTemplate") - plus:SetWidth(20) - plus:SetHeight(15) - plus:SetPoint("TOPRIGHT", editbox, "BOTTOMRIGHT", -2, 0) - plus:SetText("+") - plus:Show() - plus.adjust = 1 - plus:SetScript("OnClick", ModButton_OnClick) - plus:SetFrameLevel(editbox:GetFrameLevel() + 2) - - self.plus = plus - plus.obj = self - - AceGUI:RegisterAsWidget(self) - return self - end - - AceGUI:RegisterWidgetType(Type,Constructor,Version) -end +local AceGUI = LibStub("AceGUI-3.0") + +-------------------------- +-- Edit box -- +-------------------------- +--[[ + Events : + OnTextChanged + OnEnterPressed + +]] +do + local Type = "NumberEditBox" + local Version = 1 + + local function OnAcquire(self) + self:SetDisabled(false) + self.showbutton = true + end + + local function OnRelease(self) + self.frame:ClearAllPoints() + self.frame:Hide() + self:SetDisabled(false) + end + + local function Control_OnEnter(this) + this.obj:Fire("OnEnter") + end + + local function Control_OnLeave(this) + this.obj:Fire("OnLeave") + end + + local function EditBox_OnEscapePressed(this) + this:ClearFocus() + end + + local function ShowButton(self) + if self.showbutton then + self.button:Show() + self.editbox:SetTextInsets(0,20,3,3) + end + end + + local function HideButton(self) + self.button:Hide() + self.editbox:SetTextInsets(0,0,3,3) + end + + local function EditBox_OnEnterPressed(this) + local self = this.obj + local value = tonumber(this:GetText()) or 0 + local cancel = self:Fire("OnEnterPressed",value) + if not cancel then + HideButton(self) + end + end + + local function Button_OnClick(this) + local editbox = this.obj.editbox + editbox:ClearFocus() + EditBox_OnEnterPressed(editbox) + end + + local function EditBox_OnTextChanged(this) + local self = this.obj + local value = tonumber(this:GetText()) or 0 + if value ~= self.lastvalue then + self:Fire("OnTextChanged",value) + self.lastvalue = value + ShowButton(self) + end + end + + local function SetDisabled(self, disabled) + self.disabled = disabled + if disabled then + self.editbox:EnableMouse(false) + self.editbox:ClearFocus() + self.editbox:SetTextColor(0.5,0.5,0.5) + self.label:SetTextColor(0.5,0.5,0.5) + else + self.editbox:EnableMouse(true) + self.editbox:SetTextColor(1,1,1) + self.label:SetTextColor(1,.82,0) + end + end + + local function SetText(self, text) + self.lastvalue = tonumber(text) or 0 + self.editbox:SetText(tostring(self.lastvalue)) + self.editbox:SetCursorPosition(0) + HideButton(self) + end + + local function SetWidth(self, width) + self.frame:SetWidth(width) + end + + local function SetLabel(self, text) + if text and text ~= "" then + self.label:SetText(text) + self.label:Show() + self.editbox:SetPoint("TOPLEFT",self.frame,"TOPLEFT",7,-18) + self.frame:SetHeight(60) + self.alignoffset = 30 + else + self.label:SetText("") + self.label:Hide() + self.editbox:SetPoint("TOPLEFT",self.frame,"TOPLEFT",7,0) + self.frame:SetHeight(42) + self.alignoffset = 12 + end + end + + local function ModButton_OnClick(self) + local value = self.obj.lastvalue + value = math.floor(value + 0.5) + self.adjust + self.obj.editbox:SetText(tostring(value)) + EditBox_OnEnterPressed(self.obj.editbox) + end + + local function Constructor() + local num = AceGUI:GetNextWidgetNum(Type) + local frame = CreateFrame("Frame",nil,UIParent) + local editbox = CreateFrame("EditBox","AceGUI-3.0NumberEditBox"..num,frame,"InputBoxTemplate") + + local self = {} + self.type = Type + self.num = num + + self.OnRelease = OnRelease + self.OnAcquire = OnAcquire + + self.SetDisabled = SetDisabled + self.SetText = SetText + self.SetWidth = SetWidth + self.SetLabel = SetLabel + + self.frame = frame + frame.obj = self + self.editbox = editbox + editbox.obj = self + + self.alignoffset = 30 + + frame:SetHeight(60) + frame:SetWidth(200) + + editbox:SetScript("OnEnter",Control_OnEnter) + editbox:SetScript("OnLeave",Control_OnLeave) + + editbox:SetAutoFocus(false) + editbox:SetFontObject(ChatFontNormal) + editbox:SetScript("OnEscapePressed",EditBox_OnEscapePressed) + editbox:SetScript("OnEnterPressed",EditBox_OnEnterPressed) + editbox:SetScript("OnTextChanged",EditBox_OnTextChanged) + + editbox:SetTextInsets(0,0,3,3) + editbox:SetMaxLetters(256) + + editbox:SetPoint("BOTTOMLEFT",frame,"BOTTOMLEFT",6,15) + editbox:SetPoint("BOTTOMRIGHT",frame,"BOTTOMRIGHT",0,15) + editbox:SetHeight(19) + + local label = frame:CreateFontString(nil,"OVERLAY","GameFontNormalSmall") + label:SetPoint("TOPLEFT",frame,"TOPLEFT",0,-2) + label:SetPoint("TOPRIGHT",frame,"TOPRIGHT",0,-2) + label:SetJustifyH("LEFT") + label:SetHeight(18) + self.label = label + + local button = CreateFrame("Button",nil,editbox,"UIPanelButtonTemplate") + button:SetWidth(40) + button:SetHeight(20) + button:SetPoint("RIGHT",editbox,"RIGHT",-2,0) + button:SetText(OKAY) + button:SetScript("OnClick", Button_OnClick) + button:Hide() + + self.button = button + button.obj = self + + local minus = CreateFrame("Button", nil, frame, "UIPanelButtonTemplate") + minus:SetWidth(20) + minus:SetHeight(15) + minus:SetPoint("TOPLEFT", editbox, "BOTTOMLEFT", -4, 0) + minus:SetText("-") + minus:Show() + minus.adjust = -1 + minus:SetScript("OnClick", ModButton_OnClick) + minus:SetFrameLevel(editbox:GetFrameLevel() + 2) + + self.minus = minus + minus.obj = self + + local plus = CreateFrame("Button", nil, frame, "UIPanelButtonTemplate") + plus:SetWidth(20) + plus:SetHeight(15) + plus:SetPoint("TOPRIGHT", editbox, "BOTTOMRIGHT", -2, 0) + plus:SetText("+") + plus:Show() + plus.adjust = 1 + plus:SetScript("OnClick", ModButton_OnClick) + plus:SetFrameLevel(editbox:GetFrameLevel() + 2) + + self.plus = plus + plus.obj = self + + AceGUI:RegisterAsWidget(self) + return self + end + + AceGUI:RegisterWidgetType(Type,Constructor,Version) +end diff --git a/Options/ActionBar.lua b/Options/ActionBar.lua index b1d8f47..f121843 100644 --- a/Options/ActionBar.lua +++ b/Options/ActionBar.lua @@ -1,121 +1,121 @@ ---[[ - Copyright (c) 2009, Hendrik "Nevcairiel" Leppkes < h.leppkes at gmail dot com > - All rights reserved. -]] -local L = LibStub("AceLocale-3.0"):GetLocale("Bartender4") -local StateBar = Bartender4.StateBar.prototype -local ActionBar = Bartender4.ActionBar - ---[[=================================================================================== - ActionBar Options -===================================================================================]]-- - -local module = Bartender4:GetModule("ActionBars") - --- option utilty functions -local optGetter, optSetter -do - local optionMap, getBar, callFunc - -- maps option keys to function names - optionMap = { - buttons = "Buttons", - enabled = "Enabled", - grid = "Grid", - } - - -- 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. (%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 %s in bar %s."):format(func, bar.id)) - return bar[func](bar, ...) - end - - -- universal function to get a option - function optGetter(info) - local bar = getBar(info[2]) - local option = info[#info] - return callFunc(bar, "Get", option) - end - - -- universal function to set a option - function optSetter(info, ...) - local bar = getBar(info[2]) - local option = info[#info] - return callFunc(bar, "Set", option, ...) - end -end - --- returns the option table used for all action bars --- creates it, if the first time called --- the Universal Bar option table is merged into this, alot of stuff gets inherited. -function module:GetOptionsTable() - return self:GetOptionsObject().table -end - -function module:GetOptionsObject() - if not self.baroptions then - local obj = StateBar.GetOptionObject(self) - - local cat_general = { - enabled ={ - order = 4, - name = L["Enabled"], - desc = L["Enable/Disable the bar."], - type = "toggle", - set = optSetter, - get = optGetter, - }, - grid = { - order = 60, - type = "toggle", - name = L["Button Grid"], - desc = L["Toggle the button grid."], - set = optSetter, - get = optGetter, - }, - buttons = { - order = 50, - name = L["Buttons"], - desc = L["Number of buttons."], - type = "range", - min = 1, max = 12, step = 1, - set = optSetter, - get = optGetter, - }, - } - obj:AddElementGroup("general", cat_general) - self.baroptions = obj - end - - return self.baroptions -end - -function module:CreateBarOption(id, options) - if not self.options then return end - - if not options then - options = self:GetOptionsTable() - end - - id = tostring(id) - if not self.options[id] then - self.options[id] = { - order = 10 + tonumber(id), - type = "group", - name = (L["Bar %s"]):format(id), - desc = (L["Configure Bar %s"]):format(id), - childGroups = "tab", - } - end - self.options[id].args = options - - -- register options in the BT GUI - Bartender4:RegisterBarOptions(id, self.options[id]) -end +--[[ + Copyright (c) 2009, Hendrik "Nevcairiel" Leppkes < h.leppkes at gmail dot com > + All rights reserved. +]] +local L = LibStub("AceLocale-3.0"):GetLocale("Bartender4") +local StateBar = Bartender4.StateBar.prototype +local ActionBar = Bartender4.ActionBar + +--[[=================================================================================== + ActionBar Options +===================================================================================]]-- + +local module = Bartender4:GetModule("ActionBars") + +-- option utilty functions +local optGetter, optSetter +do + local optionMap, getBar, callFunc + -- maps option keys to function names + optionMap = { + buttons = "Buttons", + enabled = "Enabled", + grid = "Grid", + } + + -- 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. (%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 %s in bar %s."):format(func, bar.id)) + return bar[func](bar, ...) + end + + -- universal function to get a option + function optGetter(info) + local bar = getBar(info[2]) + local option = info[#info] + return callFunc(bar, "Get", option) + end + + -- universal function to set a option + function optSetter(info, ...) + local bar = getBar(info[2]) + local option = info[#info] + return callFunc(bar, "Set", option, ...) + end +end + +-- returns the option table used for all action bars +-- creates it, if the first time called +-- the Universal Bar option table is merged into this, alot of stuff gets inherited. +function module:GetOptionsTable() + return self:GetOptionsObject().table +end + +function module:GetOptionsObject() + if not self.baroptions then + local obj = StateBar.GetOptionObject(self) + + local cat_general = { + enabled ={ + order = 4, + name = L["Enabled"], + desc = L["Enable/Disable the bar."], + type = "toggle", + set = optSetter, + get = optGetter, + }, + grid = { + order = 60, + type = "toggle", + name = L["Button Grid"], + desc = L["Toggle the button grid."], + set = optSetter, + get = optGetter, + }, + buttons = { + order = 50, + name = L["Buttons"], + desc = L["Number of buttons."], + type = "range", + min = 1, max = 12, step = 1, + set = optSetter, + get = optGetter, + }, + } + obj:AddElementGroup("general", cat_general) + self.baroptions = obj + end + + return self.baroptions +end + +function module:CreateBarOption(id, options) + if not self.options then return end + + if not options then + options = self:GetOptionsTable() + end + + id = tostring(id) + if not self.options[id] then + self.options[id] = { + order = 10 + tonumber(id), + type = "group", + name = (L["Bar %s"]):format(id), + desc = (L["Configure Bar %s"]):format(id), + childGroups = "tab", + } + end + self.options[id].args = options + + -- register options in the BT GUI + Bartender4:RegisterBarOptions(id, self.options[id]) +end diff --git a/Options/BagBar.lua b/Options/BagBar.lua index c894e09..25c5f96 100644 --- a/Options/BagBar.lua +++ b/Options/BagBar.lua @@ -1,68 +1,68 @@ ---[[ - Copyright (c) 2009, Hendrik "Nevcairiel" Leppkes < h.leppkes at gmail dot com > - All rights reserved. -]] -local L = LibStub("AceLocale-3.0"):GetLocale("Bartender4") - -local BagBarMod = Bartender4:GetModule("BagBar") - --- fetch upvalues -local ButtonBar = Bartender4.ButtonBar.prototype - -function BagBarMod:SetupOptions() - if not self.options then - self.optionobject = ButtonBar:GetOptionObject() - self.optionobject.table.general.args.rows.max = self.button_count - local enabled = { - type = "toggle", - order = 1, - name = L["Enabled"], - desc = L["Enable the Bag Bar"], - get = function() return self.db.profile.enabled end, - set = "ToggleModule", - handler = self, - } - self.optionobject:AddElement("general", "enabled", enabled) - - local onebag = { - type = "toggle", - order = 80, - name = L["One Bag"], - desc = L["Only show one Bag Button in the BagBar."], - get = function() return self.db.profile.onebag end, - set = function(info, state) self.db.profile.onebag = state; self.bar:FeedButtons(); self.bar:UpdateButtonLayout() end, - } - self.optionobject:AddElement("general", "onebag", onebag) - - local keyring = { - type = "toggle", - order = 80, - name = L["Keyring"], - desc = L["Show the keyring button."], - get = function() return self.db.profile.keyring end, - set = function(info, state) self.db.profile.keyring = state; self.bar:FeedButtons(); self.bar:UpdateButtonLayout() end, - } - self.optionobject:AddElement("general", "keyring", keyring) - - self.disabledoptions = { - general = { - type = "group", - name = L["General Settings"], - cmdInline = true, - order = 1, - args = { - enabled = enabled, - } - } - } - self.options = { - order = 30, - type = "group", - name = L["Bag Bar"], - desc = L["Configure the Bag Bar"], - childGroups = "tab", - } - Bartender4:RegisterBarOptions("BagBar", self.options) - end - self.options.args = self:IsEnabled() and self.optionobject.table or self.disabledoptions -end +--[[ + Copyright (c) 2009, Hendrik "Nevcairiel" Leppkes < h.leppkes at gmail dot com > + All rights reserved. +]] +local L = LibStub("AceLocale-3.0"):GetLocale("Bartender4") + +local BagBarMod = Bartender4:GetModule("BagBar") + +-- fetch upvalues +local ButtonBar = Bartender4.ButtonBar.prototype + +function BagBarMod:SetupOptions() + if not self.options then + self.optionobject = ButtonBar:GetOptionObject() + self.optionobject.table.general.args.rows.max = self.button_count + local enabled = { + type = "toggle", + order = 1, + name = L["Enabled"], + desc = L["Enable the Bag Bar"], + get = function() return self.db.profile.enabled end, + set = "ToggleModule", + handler = self, + } + self.optionobject:AddElement("general", "enabled", enabled) + + local onebag = { + type = "toggle", + order = 80, + name = L["One Bag"], + desc = L["Only show one Bag Button in the BagBar."], + get = function() return self.db.profile.onebag end, + set = function(info, state) self.db.profile.onebag = state; self.bar:FeedButtons(); self.bar:UpdateButtonLayout() end, + } + self.optionobject:AddElement("general", "onebag", onebag) + + local keyring = { + type = "toggle", + order = 80, + name = L["Keyring"], + desc = L["Show the keyring button."], + get = function() return self.db.profile.keyring end, + set = function(info, state) self.db.profile.keyring = state; self.bar:FeedButtons(); self.bar:UpdateButtonLayout() end, + } + self.optionobject:AddElement("general", "keyring", keyring) + + self.disabledoptions = { + general = { + type = "group", + name = L["General Settings"], + cmdInline = true, + order = 1, + args = { + enabled = enabled, + } + } + } + self.options = { + order = 30, + type = "group", + name = L["Bag Bar"], + desc = L["Configure the Bag Bar"], + childGroups = "tab", + } + Bartender4:RegisterBarOptions("BagBar", self.options) + end + self.options.args = self:IsEnabled() and self.optionobject.table or self.disabledoptions +end diff --git a/Options/Bar.lua b/Options/Bar.lua index b082599..537abd4 100644 --- a/Options/Bar.lua +++ b/Options/Bar.lua @@ -1,474 +1,475 @@ ---[[ - Copyright (c) 2009, Hendrik "Nevcairiel" Leppkes < h.leppkes at gmail dot com > - All rights reserved. -]] -local L = LibStub("AceLocale-3.0"):GetLocale("Bartender4") -local Bar = Bartender4.Bar.prototype - ---[[=================================================================================== - Bar Options -===================================================================================]]-- - -local barregistry = Bartender4.Bar.barregistry - -local function round(num, idp) - local mult = 10^(idp or 0) - return math.floor(num * mult + 0.5) / mult -end - --- option utilty functions -local optGetter, optSetter, visibilityGetter, visibilitySetter, customEnabled, customDisabled, customCopy, clickThroughVis, posGet, posSet, centerHorz, centerVert, resetPos -do - local getBar, optionMap, callFunc - -- maps option keys to function names - optionMap = { - alpha = "ConfigAlpha", - scale = "ConfigScale", - fadeout = "FadeOut", - fadeoutalpha = "FadeOutAlpha", - fadeoutdelay = "FadeOutDelay", - clickthrough = "ClickThrough", - } - - -- 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. (%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 %s in bar %s."):format(func, bar.id)) - return bar[func](bar, ...) - end - - -- universal function to get a option - function optGetter(info) - local bar = getBar(info[2]) - local option = info[#info] - return callFunc(bar, "Get", option) - end - - -- universal function to set a option - function optSetter(info, ...) - local bar = getBar(info[2]) - local option = info[#info] - return callFunc(bar, "Set", option, ...) - end - - function visibilityGetter(info, ...) - local bar = getBar(info[2]) - local option = info[#info] - return bar:GetVisibilityOption(option, ...) - end - - function visibilitySetter(info, ...) - local bar = getBar(info[2]) - local option = info[#info] - bar:SetVisibilityOption(option, ...) - end - - function customEnabled(info) - local bar = getBar(info[2]) - return bar:GetVisibilityOption("custom") - end - - function customDisabled(info) - local bar = getBar(info[2]) - return not bar:GetVisibilityOption("custom") - end - - function customCopy(info) - local bar = getBar(info[2]) - bar:CopyCustomConditionals() - end - - function clickThroughVis(info) - local bar = getBar(info[2]) - return (not bar.ClickThroughSupport) - end - - function posGet(info) - local bar = getBar(info[2]) - local opt = info.arg or info[#info] - if opt == "x" or opt == "y" then - local v = bar.config.position[opt] - return tostring(round(v, 5)) - end - return bar.config.position[opt] - end - - function posSet(info, value) - local bar = getBar(info[2]) - local opt = info.arg or info[#info] - if opt == "x" or opt == "y" then - value = tonumber(value) - end - bar.config.position[opt] = value - bar:LoadPosition() - end - - function centerHorz(info) - local bar = getBar(info[2]) - local pos = bar.config.position - local x_mod = (pos.growHorizontal == "RIGHT") and -1 or 1 - pos.x = (bar.overlay:GetWidth() / 2) * pos.scale * x_mod - if pos.point == "CENTER" or pos.point == "LEFT" or pos.point == "RIGHT" then -- no special handling - pos.point = "CENTER" - else - pos.point = pos.point:gsub("LEFT", ""):gsub("RIGHT", "") - end - bar:LoadPosition() - end - - function centerVert(info) - local bar = getBar(info[2]) - local pos = bar.config.position - local y_mod = (pos.growVertical == "DOWN") and 1 or -1 - pos.y = (bar.overlay:GetHeight() / 2) * pos.scale * y_mod - if pos.point == "CENTER" or pos.point == "TOP" or pos.point == "BOTTOM" then -- no special handling - pos.point = "CENTER" - else - pos.point = pos.point:gsub("TOP", ""):gsub("BOTTOM", "") - end - bar:LoadPosition() - end - - function resetPos(info) - local bar = getBar(info[2]) - local pos = bar.config.position - local x_mod = (pos.growHorizontal == "RIGHT") and -1 or 1 - local y_mod = (pos.growVertical == "DOWN") and 1 or -1 - pos.x = (bar.overlay:GetWidth() / 2) * pos.scale * x_mod - pos.y = (bar.overlay:GetHeight() / 2) * pos.scale * y_mod - pos.point = "CENTER" - bar:LoadPosition() - end -end - -local _, class = UnitClass("player") -local stanceClasses = { - DRUID = true, - WARRIOR = true, - WARLOCK = true, - PRIEST = true, - ROGUE = true, -} - -local function getStanceTable() - local tbl = {} - - if class ~= "WARRIOR" then - tbl[0] = L["No Stance/Form"] - end - - local num = GetNumShapeshiftForms() - for i = 1, num do - tbl[i] = select(2, GetShapeshiftFormInfo(i)) - end - -- HACK: Metamorphosis work around, it is on slot 1 in GetShapeshiftFormInfo() but stance:2 is active.. - if class == "WARLOCK" and tbl[1] == GetSpellInfo(59672) then - tbl[2], tbl[1] = tbl[1], nil - end - - if class == "ROGUE" and tbl[1] == GetSpellInfo(51713) then -- shadow dance hack - tbl[3], tbl[1] = tbl[1], nil - end - return tbl -end - -local validAnchors = { - CENTER = "CENTER", - LEFT = "LEFT", - RIGHT = "RIGHT", - TOP = "TOP", - TOPLEFT = "TOPLEFT", - TOPRIGHT = "TOPRIGHT", - BOTTOM = "BOTTOM", - BOTTOMLEFT = "BOTTOMLEFT", - BOTTOMRIGHT = "BOTTOMRIGHT", -} - -local options -function Bar:GetOptionObject() - local otbl = { - general = { - type = "group", - cmdInline = true, - name = L["General Settings"], - order = 1, - args = { - styleheader = { - order = 10, - type = "header", - name = L["Bar Style & Layout"], - }, - alpha = { - order = 20, - name = L["Alpha"], - desc = L["Configure the alpha of the bar."], - type = "range", - min = .1, max = 1, step = 0.05, - isPercent = true, - get = optGetter, - set = optSetter, - }, - scale = { - order = 30, - name = L["Scale"], - desc = L["Configure the scale of the bar."], - type = "range", - min = .1, max = 2, step = 0.05, - get = optGetter, - set = optSetter, - }, - clickthrough = { - order = 200, - name = L["Click-Through"], - desc = L["Disable any reaction to mouse events on this bar, making the bar click-through."], - type = "toggle", - get = optGetter, - set = optSetter, - hidden = clickThroughVis, - width = "full", - }, - }, - }, - visibility = { - type = "group", - name = L["Visibility"], - order = 2, - get = visibilityGetter, - set = visibilitySetter, - args = { - info = { - order = 1, - type = "description", - name = L["The bar default is to be visible all the time, you can configure conditions here to control when the bar should be hidden."] .. "\n", - }, - fadeout = { - order = 5, - name = L["Fade Out"], - desc = L["Enable the FadeOut mode"], - type = "toggle", - get = optGetter, - set = optSetter, - width = "full", - }, - fadeoutalpha = { - order = 6, - name = L["Fade Out Alpha"], - desc = L["Configure the Fade Out Alpha"], - type = "range", - min = 0, max = 1, step = 0.05, - isPercent = true, - get = optGetter, - set = optSetter, - }, - fadeoutdelay = { - order = 7, - name = L["Fade Out Delay"], - desc = L["Configure the Fade Out Delay"], - type = "range", - min = 0, max = 1, step = 0.01, - get = optGetter, - set = optSetter, - }, - fadeNl = { - order = 8, - type = "description", - name = "", - }, - always = { - order = 10, - type = "toggle", - name = L["Always Hide"], - desc = L["You can set the bar to be always hidden, if you only wish to access it using key-bindings."], - disabled = customEnabled, - }, - possess = { - order = 15, - type = "toggle", - name = L["Hide when Possessing"], - desc = L["Hide this bar when you are possessing a NPC."], - disabled = customEnabled, - }, - vehicle = { - order = 16, - type = "toggle", - name = L["Hide on Vehicle"], - desc = L["Hide this bar when you are riding on a vehicle."], - disabled = customEnabled, - }, - vehicleui = { - order = 17, - type = "toggle", - name = L["Hide with Vehicle UI"], - desc = L["Hide this bar when the game wants to show a vehicle UI."], - disabled = customEnabled, - }, - combat = { - order = 20, - type = "toggle", - name = L["Hide in Combat"], - desc = L["This bar will be hidden once you enter combat."], - disabled = customEnabled, - }, - nocombat = { - order = 21, - type = "toggle", - name = L["Hide out of Combat"], - desc = L["This bar will be hidden whenever you are not in combat."], - disabled = customEnabled, - }, - pet = { - order = 30, - type = "toggle", - name = L["Hide with pet"], - desc = L["Hide this bar when you have a pet."], - disabled = customEnabled, - }, - nopet = { - order = 31, - type = "toggle", - name = L["Hide without pet"], - desc = L["Hide this bar when you have no pet."], - disabled = customEnabled, - }, - stance = { - order = 50, - type = "multiselect", - name = L["Hide in Stance/Form"], - desc = L["Hide this bar in a specific Stance or Form."], - values = getStanceTable, - hidden = function() return (not stanceClasses[class]) end, - disabled = customEnabled, - }, - customNl = { - order = 98, - type = "description", - name = "\n", - }, - customHeader = { - order = 99, - type = "header", - name = L["Custom Conditionals"], - }, - custom = { - order = 100, - type = "toggle", - name = L["Use Custom Condition"], - desc = L["Enable the use of a custom condition, disabling all of the above."], - }, - customCopy = { - order = 101, - type = "execute", - name = L["Copy Conditionals"], - desc = L["Create a copy of the auto-generated conditionals in the custom configuration as a base template."], - func = customCopy, - }, - customDesc = { - order = 102, - type = "description", - name = L["Note: Enabling Custom Conditionals will disable all of the above settings!"], - }, - customdata = { - order = 103, - type = "input", - name = L["Custom Conditionals"], - desc = L["You can use any macro conditionals in the custom string, using \"show\" and \"hide\" as values.\n\nExample: [combat]hide;show"], - width = "full", - multiline = true, - disabled = customDisabled, - }, - }, - }, - position = { - type = "group", - name = L["Positioning"], - order = 20, - args = { - info = { - order = 1, - type = "description", - name = L["The Positioning options here will allow you to position the bar to your liking and with an absolute precision."], - }, - point = { - order = 10, - type = "select", - name = L["Anchor"], - desc = L["Change the current anchor point of the bar."], - values = validAnchors, - get = posGet, - set = posSet, - }, - scale = { - order = 11, - name = L["Scale"], - desc = L["Configure the scale of the bar."], - type = "range", - min = .1, max = 2, step = 0.05, - get = optGetter, - set = optSetter, - }, - nl1 = { - order = 12, - type = "description", - name = "", - }, - x = { - order = 20, - type = "input", - name = L["X Offset"], - desc = L["Offset in X direction (horizontal) from the given anchor point."], - get = posGet, - set = posSet, - dialogControl = "NumberEditBox", - }, - y = { - order = 21, - type = "input", - name = L["Y Offset"], - desc = L["Offset in Y direction (vertical) from the given anchor point."], - get = posGet, - set = posSet, - dialogControl = "NumberEditBox", - }, - nl2 = { - order = 25, - type = "description", - name = "", - }, - centerhorz = { - order = 31, - type = "execute", - name = L["Center Horizontally"], - desc = L["Centers the bar horizontally on screen."], - func = centerHorz, - }, - centervert = { - order = 31, - type = "execute", - name = L["Center Vertically"], - desc = L["Centers the bar vertically on screen."], - func = centerVert, - }, - nl2 = { - order = 35, - type = "description", - name = " ", - }, - reset = { - order = 40, - type = "execute", - name = L["Reset Position"], - desc = L["Reset the position of this bar completly if it ended up off-screen and you cannot reach it anymore."], - func = resetPos, - }, - }, - } - } - return Bartender4:NewOptionObject(otbl) -end +--[[ + Copyright (c) 2009, Hendrik "Nevcairiel" Leppkes < h.leppkes at gmail dot com > + All rights reserved. +]] +local L = LibStub("AceLocale-3.0"):GetLocale("Bartender4") +local Bar = Bartender4.Bar.prototype + +--[[=================================================================================== + Bar Options +===================================================================================]]-- + +local barregistry = Bartender4.Bar.barregistry + +local function round(num, idp) + local mult = 10^(idp or 0) + return math.floor(num * mult + 0.5) / mult +end + +-- option utilty functions +local optGetter, optSetter, visibilityGetter, visibilitySetter, customEnabled, customDisabled, customCopy, clickThroughVis, posGet, posSet, centerHorz, centerVert, resetPos +do + local getBar, optionMap, callFunc + -- maps option keys to function names + optionMap = { + alpha = "ConfigAlpha", + scale = "ConfigScale", + fadeout = "FadeOut", + fadeoutalpha = "FadeOutAlpha", + fadeoutdelay = "FadeOutDelay", + clickthrough = "ClickThrough", + } + + -- 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. (%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 %s in bar %s."):format(func, bar.id)) + return bar[func](bar, ...) + end + + -- universal function to get a option + function optGetter(info) + local bar = getBar(info[2]) + local option = info[#info] + return callFunc(bar, "Get", option) + end + + -- universal function to set a option + function optSetter(info, ...) + local bar = getBar(info[2]) + local option = info[#info] + return callFunc(bar, "Set", option, ...) + end + + function visibilityGetter(info, ...) + local bar = getBar(info[2]) + local option = info[#info] + return bar:GetVisibilityOption(option, ...) + end + + function visibilitySetter(info, ...) + local bar = getBar(info[2]) + local option = info[#info] + bar:SetVisibilityOption(option, ...) + end + + function customEnabled(info) + local bar = getBar(info[2]) + return bar:GetVisibilityOption("custom") + end + + function customDisabled(info) + local bar = getBar(info[2]) + return not bar:GetVisibilityOption("custom") + end + + function customCopy(info) + local bar = getBar(info[2]) + bar:CopyCustomConditionals() + end + + function clickThroughVis(info) + local bar = getBar(info[2]) + return (not bar.ClickThroughSupport) + end + + function posGet(info) + local bar = getBar(info[2]) + local opt = info.arg or info[#info] + if opt == "x" or opt == "y" then + local v = bar.config.position[opt] + return tostring(round(v, 5)) + end + return bar.config.position[opt] + end + + function posSet(info, value) + local bar = getBar(info[2]) + local opt = info.arg or info[#info] + if opt == "x" or opt == "y" then + value = tonumber(value) + end + bar.config.position[opt] = value + bar:LoadPosition() + end + + function centerHorz(info) + local bar = getBar(info[2]) + local pos = bar.config.position + local x_mod = (pos.growHorizontal == "RIGHT") and -1 or 1 + pos.x = (bar.overlay:GetWidth() / 2) * pos.scale * x_mod + if pos.point == "CENTER" or pos.point == "LEFT" or pos.point == "RIGHT" then -- no special handling + pos.point = "CENTER" + else + pos.point = pos.point:gsub("LEFT", ""):gsub("RIGHT", "") + end + bar:LoadPosition() + end + + function centerVert(info) + local bar = getBar(info[2]) + local pos = bar.config.position + local y_mod = (pos.growVertical == "DOWN") and 1 or -1 + pos.y = (bar.overlay:GetHeight() / 2) * pos.scale * y_mod + if pos.point == "CENTER" or pos.point == "TOP" or pos.point == "BOTTOM" then -- no special handling + pos.point = "CENTER" + else + pos.point = pos.point:gsub("TOP", ""):gsub("BOTTOM", "") + end + bar:LoadPosition() + end + + function resetPos(info) + local bar = getBar(info[2]) + local pos = bar.config.position + local x_mod = (pos.growHorizontal == "RIGHT") and -1 or 1 + local y_mod = (pos.growVertical == "DOWN") and 1 or -1 + pos.x = (bar.overlay:GetWidth() / 2) * pos.scale * x_mod + pos.y = (bar.overlay:GetHeight() / 2) * pos.scale * y_mod + pos.point = "CENTER" + bar:LoadPosition() + end +end + +local _, class = UnitClass("player") +local stanceClasses = { + DRUID = true, + HERO = true, + WARRIOR = true, + WARLOCK = true, + PRIEST = true, + ROGUE = true, +} + +local function getStanceTable() + local tbl = {} + + if class ~= "WARRIOR" then + tbl[0] = L["No Stance/Form"] + end + + local num = GetNumShapeshiftForms() + for i = 1, num do + tbl[i] = select(2, GetShapeshiftFormInfo(i)) + end + -- HACK: Metamorphosis work around, it is on slot 1 in GetShapeshiftFormInfo() but stance:2 is active.. + if class == "WARLOCK" and tbl[1] == GetSpellInfo(59672) then + tbl[2], tbl[1] = tbl[1], nil + end + + if class == "ROGUE" and tbl[1] == GetSpellInfo(51713) then -- shadow dance hack + tbl[3], tbl[1] = tbl[1], nil + end + return tbl +end + +local validAnchors = { + CENTER = "CENTER", + LEFT = "LEFT", + RIGHT = "RIGHT", + TOP = "TOP", + TOPLEFT = "TOPLEFT", + TOPRIGHT = "TOPRIGHT", + BOTTOM = "BOTTOM", + BOTTOMLEFT = "BOTTOMLEFT", + BOTTOMRIGHT = "BOTTOMRIGHT", +} + +local options +function Bar:GetOptionObject() + local otbl = { + general = { + type = "group", + cmdInline = true, + name = L["General Settings"], + order = 1, + args = { + styleheader = { + order = 10, + type = "header", + name = L["Bar Style & Layout"], + }, + alpha = { + order = 20, + name = L["Alpha"], + desc = L["Configure the alpha of the bar."], + type = "range", + min = 0, max = 1, bigStep = 0.05, + isPercent = true, + get = optGetter, + set = optSetter, + }, + scale = { + order = 30, + name = L["Scale"], + desc = L["Configure the scale of the bar."], + type = "range", + min = 0, softMin = .1, softMax = 2, bigStep = 0.05, + get = optGetter, + set = optSetter, + }, + clickthrough = { + order = 200, + name = L["Click-Through"], + desc = L["Disable any reaction to mouse events on this bar, making the bar click-through."], + type = "toggle", + get = optGetter, + set = optSetter, + hidden = clickThroughVis, + width = "full", + }, + }, + }, + visibility = { + type = "group", + name = L["Visibility"], + order = 2, + get = visibilityGetter, + set = visibilitySetter, + args = { + info = { + order = 1, + type = "description", + name = L["The bar default is to be visible all the time, you can configure conditions here to control when the bar should be hidden."] .. "\n", + }, + fadeout = { + order = 5, + name = L["Fade Out"], + desc = L["Enable the FadeOut mode"], + type = "toggle", + get = optGetter, + set = optSetter, + width = "full", + }, + fadeoutalpha = { + order = 6, + name = L["Fade Out Alpha"], + desc = L["Configure the Fade Out Alpha"], + type = "range", + min = 0, max = 1, bigStep = 0.05, + isPercent = true, + get = optGetter, + set = optSetter, + }, + fadeoutdelay = { + order = 7, + name = L["Fade Out Delay"], + desc = L["Configure the Fade Out Delay"], + type = "range", + min = 0, softMax = 1, bigStep = 0.01, + get = optGetter, + set = optSetter, + }, + fadeNl = { + order = 8, + type = "description", + name = "", + }, + always = { + order = 10, + type = "toggle", + name = L["Always Hide"], + desc = L["You can set the bar to be always hidden, if you only wish to access it using key-bindings."], + disabled = customEnabled, + }, + possess = { + order = 15, + type = "toggle", + name = L["Hide when Possessing"], + desc = L["Hide this bar when you are possessing a NPC."], + disabled = customEnabled, + }, + vehicle = { + order = 16, + type = "toggle", + name = L["Hide on Vehicle"], + desc = L["Hide this bar when you are riding on a vehicle."], + disabled = customEnabled, + }, + vehicleui = { + order = 17, + type = "toggle", + name = L["Hide with Vehicle UI"], + desc = L["Hide this bar when the game wants to show a vehicle UI."], + disabled = customEnabled, + }, + combat = { + order = 20, + type = "toggle", + name = L["Hide in Combat"], + desc = L["This bar will be hidden once you enter combat."], + disabled = customEnabled, + }, + nocombat = { + order = 21, + type = "toggle", + name = L["Hide out of Combat"], + desc = L["This bar will be hidden whenever you are not in combat."], + disabled = customEnabled, + }, + pet = { + order = 30, + type = "toggle", + name = L["Hide with pet"], + desc = L["Hide this bar when you have a pet."], + disabled = customEnabled, + }, + nopet = { + order = 31, + type = "toggle", + name = L["Hide without pet"], + desc = L["Hide this bar when you have no pet."], + disabled = customEnabled, + }, + stance = { + order = 50, + type = "multiselect", + name = L["Hide in Stance/Form"], + desc = L["Hide this bar in a specific Stance or Form."], + values = getStanceTable, + hidden = function() return (not stanceClasses[class]) end, + disabled = customEnabled, + }, + customNl = { + order = 98, + type = "description", + name = "\n", + }, + customHeader = { + order = 99, + type = "header", + name = L["Custom Conditionals"], + }, + custom = { + order = 100, + type = "toggle", + name = L["Use Custom Condition"], + desc = L["Enable the use of a custom condition, disabling all of the above."], + }, + customCopy = { + order = 101, + type = "execute", + name = L["Copy Conditionals"], + desc = L["Create a copy of the auto-generated conditionals in the custom configuration as a base template."], + func = customCopy, + }, + customDesc = { + order = 102, + type = "description", + name = L["Note: Enabling Custom Conditionals will disable all of the above settings!"], + }, + customdata = { + order = 103, + type = "input", + name = L["Custom Conditionals"], + desc = L["You can use any macro conditionals in the custom string, using \"show\" and \"hide\" as values.\n\nExample: [combat]hide;show"], + width = "full", + multiline = true, + disabled = customDisabled, + }, + }, + }, + position = { + type = "group", + name = L["Positioning"], + order = 20, + args = { + info = { + order = 1, + type = "description", + name = L["The Positioning options here will allow you to position the bar to your liking and with an absolute precision."], + }, + point = { + order = 10, + type = "select", + name = L["Anchor"], + desc = L["Change the current anchor point of the bar."], + values = validAnchors, + get = posGet, + set = posSet, + }, + scale = { + order = 11, + name = L["Scale"], + desc = L["Configure the scale of the bar."], + type = "range", + min = 0, softMin = .1, softMax = 2, bigStep = 0.05, + get = optGetter, + set = optSetter, + }, + nl1 = { + order = 12, + type = "description", + name = "", + }, + x = { + order = 20, + type = "input", + name = L["X Offset"], + desc = L["Offset in X direction (horizontal) from the given anchor point."], + get = posGet, + set = posSet, + dialogControl = "NumberEditBox", + }, + y = { + order = 21, + type = "input", + name = L["Y Offset"], + desc = L["Offset in Y direction (vertical) from the given anchor point."], + get = posGet, + set = posSet, + dialogControl = "NumberEditBox", + }, + nl2 = { + order = 25, + type = "description", + name = "", + }, + centerhorz = { + order = 31, + type = "execute", + name = L["Center Horizontally"], + desc = L["Centers the bar horizontally on screen."], + func = centerHorz, + }, + centervert = { + order = 31, + type = "execute", + name = L["Center Vertically"], + desc = L["Centers the bar vertically on screen."], + func = centerVert, + }, + nl2 = { + order = 35, + type = "description", + name = " ", + }, + reset = { + order = 40, + type = "execute", + name = L["Reset Position"], + desc = L["Reset the position of this bar completly if it ended up off-screen and you cannot reach it anymore."], + func = resetPos, + }, + }, + } + } + return Bartender4:NewOptionObject(otbl) +end diff --git a/Options/ButtonBar.lua b/Options/ButtonBar.lua index 19e0264..09484cc 100644 --- a/Options/ButtonBar.lua +++ b/Options/ButtonBar.lua @@ -1,131 +1,131 @@ ---[[ - Copyright (c) 2009, Hendrik "Nevcairiel" Leppkes < h.leppkes at gmail dot com > - All rights reserved. -]] -local L = LibStub("AceLocale-3.0"):GetLocale("Bartender4") - -local Bar = Bartender4.Bar.prototype -local ButtonBar = Bartender4.ButtonBar.prototype - ---[[=================================================================================== - Bar Options -===================================================================================]]-- - --- option utilty functions -local optGetter, optSetter -do - local getBar, optionMap, callFunc - local barregistry = Bartender4.Bar.barregistry - -- maps option keys to function names - optionMap = { - rows = "Rows", - padding = "Padding", - zoom = "Zoom", - macrotext = "HideMacroText", - hotkey = "HideHotkey", - vgrowth = "VGrowth", - hgrowth = "HGrowth", - } - - -- 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. (%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 %s in bar %s."):format(func, bar.id)) - return bar[func](bar, ...) - end - - -- universal function to get a option - function optGetter(info) - local bar = getBar(info[2]) - local option = info[#info] - return callFunc(bar, "Get", option) - end - - -- universal function to set a option - function optSetter(info, ...) - local bar = getBar(info[2]) - local option = info[#info] - return callFunc(bar, "Set", option, ...) - end -end - -function ButtonBar:GetOptionObject() - local obj = Bar.GetOptionObject() - local otbl_general = { - padding = { - order = 40, - type = "range", - name = L["Padding"], - desc = L["Configure the padding of the buttons."], - min = -10, max = 20, step = 1, - set = optSetter, - get = optGetter, - }, - zoom = { - order = 59, - name = L["Zoom"], - type = "toggle", - desc = L["Toggle Button Zoom\nFor more style options you need to install ButtonFacade"], - get = optGetter, - set = optSetter, - hidden = function() return LibStub("LibButtonFacade", true) and true or false end, - }, - rows = { - order = 70, - name = L["Rows"], - desc = L["Number of rows."], - type = "range", - min = 1, max = 12, step = 1, - set = optSetter, - get = optGetter, - }, - vgrowth = { - order = 75, - name = L["Vertical Growth"], - desc = L["Vertical growth direction for this bar."], - type = "select", - values = {UP = L["Up"], DOWN = L["Down"]}, - set = optSetter, - get = optGetter, - }, - hgrowth = { - order = 76, - name = L["Horizontal Growth"], - desc = L["Horizontal growth direction for this bar."], - type = "select", - values = {LEFT = L["Left"], RIGHT = L["Right"]}, - set = optSetter, - get = optGetter, - }, - hidedesc = { - order = 80, - name = L["Button Look"], - type = "header", - }, - macrotext = { - order = 81, - type = "toggle", - name = L["Hide Macro Text"], - desc = L["Hide the Macro Text on the buttons of this bar."], - set = optSetter, - get = optGetter, - }, - hotkey = { - order = 82, - type = "toggle", - name = L["Hide Hotkey"], - desc = L["Hide the Hotkey on the buttons of this bar."], - set = optSetter, - get = optGetter, - }, - } - obj:AddElementGroup("general", otbl_general) - return obj -end +--[[ + Copyright (c) 2009, Hendrik "Nevcairiel" Leppkes < h.leppkes at gmail dot com > + All rights reserved. +]] +local L = LibStub("AceLocale-3.0"):GetLocale("Bartender4") + +local Bar = Bartender4.Bar.prototype +local ButtonBar = Bartender4.ButtonBar.prototype + +--[[=================================================================================== + Bar Options +===================================================================================]]-- + +-- option utilty functions +local optGetter, optSetter +do + local getBar, optionMap, callFunc + local barregistry = Bartender4.Bar.barregistry + -- maps option keys to function names + optionMap = { + rows = "Rows", + padding = "Padding", + zoom = "Zoom", + macrotext = "HideMacroText", + hotkey = "HideHotkey", + vgrowth = "VGrowth", + hgrowth = "HGrowth", + } + + -- 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. (%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 %s in bar %s."):format(func, bar.id)) + return bar[func](bar, ...) + end + + -- universal function to get a option + function optGetter(info) + local bar = getBar(info[2]) + local option = info[#info] + return callFunc(bar, "Get", option) + end + + -- universal function to set a option + function optSetter(info, ...) + local bar = getBar(info[2]) + local option = info[#info] + return callFunc(bar, "Set", option, ...) + end +end + +function ButtonBar:GetOptionObject() + local obj = Bar.GetOptionObject() + local otbl_general = { + padding = { + order = 40, + type = "range", + name = L["Padding"], + desc = L["Configure the padding of the buttons."], + softMin = -10, softMax = 20, bigStep = 1, + set = optSetter, + get = optGetter, + }, + zoom = { + order = 59, + name = L["Zoom"], + type = "toggle", + desc = L["Toggle Button Zoom\nFor more style options you need to install ButtonFacade"], + get = optGetter, + set = optSetter, + hidden = function() return LibStub("LibButtonFacade", true) and true or false end, + }, + rows = { + order = 70, + name = L["Rows"], + desc = L["Number of rows."], + type = "range", + min = 1, max = 12, step = 1, + set = optSetter, + get = optGetter, + }, + vgrowth = { + order = 75, + name = L["Vertical Growth"], + desc = L["Vertical growth direction for this bar."], + type = "select", + values = {UP = L["Up"], DOWN = L["Down"]}, + set = optSetter, + get = optGetter, + }, + hgrowth = { + order = 76, + name = L["Horizontal Growth"], + desc = L["Horizontal growth direction for this bar."], + type = "select", + values = {LEFT = L["Left"], RIGHT = L["Right"]}, + set = optSetter, + get = optGetter, + }, + hidedesc = { + order = 80, + name = L["Button Look"], + type = "header", + }, + macrotext = { + order = 81, + type = "toggle", + name = L["Hide Macro Text"], + desc = L["Hide the Macro Text on the buttons of this bar."], + set = optSetter, + get = optGetter, + }, + hotkey = { + order = 82, + type = "toggle", + name = L["Hide Hotkey"], + desc = L["Hide the Hotkey on the buttons of this bar."], + set = optSetter, + get = optGetter, + }, + } + obj:AddElementGroup("general", otbl_general) + return obj +end diff --git a/Options/MicroMenu.lua b/Options/MicroMenu.lua index 87f1046..b913ae1 100644 --- a/Options/MicroMenu.lua +++ b/Options/MicroMenu.lua @@ -1,49 +1,49 @@ ---[[ - Copyright (c) 2009, Hendrik "Nevcairiel" Leppkes < h.leppkes at gmail dot com > - All rights reserved. -]] -local L = LibStub("AceLocale-3.0"):GetLocale("Bartender4") - -local MicroMenuMod = Bartender4:GetModule("MicroMenu") - --- fetch upvalues -local ButtonBar = Bartender4.ButtonBar.prototype - -function MicroMenuMod:SetupOptions() - if not self.options then - self.optionobject = ButtonBar:GetOptionObject() - self.optionobject.table.general.args.rows.max = self.button_count - local enabled = { - type = "toggle", - order = 1, - name = L["Enabled"], - desc = L["Enable the Micro Menu"], - get = function() return self.db.profile.enabled end, - set = "ToggleModule", - handler = self, - } - self.optionobject:AddElement("general", "enabled", enabled) - - self.disabledoptions = { - general = { - type = "group", - name = L["General Settings"], - cmdInline = true, - order = 1, - args = { - enabled = enabled, - } - } - } - self.options = { - order = 30, - type = "group", - name = L["Micro Menu"], - desc = L["Configure the Micro Menu"], - childGroups = "tab", - } - self.optionobject.table.general.args.padding.min = -30 - Bartender4:RegisterBarOptions("MicroMenu", self.options) - end - self.options.args = self:IsEnabled() and self.optionobject.table or self.disabledoptions -end +--[[ + Copyright (c) 2009, Hendrik "Nevcairiel" Leppkes < h.leppkes at gmail dot com > + All rights reserved. +]] +local L = LibStub("AceLocale-3.0"):GetLocale("Bartender4") + +local MicroMenuMod = Bartender4:GetModule("MicroMenu") + +-- fetch upvalues +local ButtonBar = Bartender4.ButtonBar.prototype + +function MicroMenuMod:SetupOptions() + if not self.options then + self.optionobject = ButtonBar:GetOptionObject() + self.optionobject.table.general.args.rows.max = self.button_count + local enabled = { + type = "toggle", + order = 1, + name = L["Enabled"], + desc = L["Enable the Micro Menu"], + get = function() return self.db.profile.enabled end, + set = "ToggleModule", + handler = self, + } + self.optionobject:AddElement("general", "enabled", enabled) + + self.disabledoptions = { + general = { + type = "group", + name = L["General Settings"], + cmdInline = true, + order = 1, + args = { + enabled = enabled, + } + } + } + self.options = { + order = 30, + type = "group", + name = L["Micro Menu"], + desc = L["Configure the Micro Menu"], + childGroups = "tab", + } + self.optionobject.table.general.args.padding.min = -30 + Bartender4:RegisterBarOptions("MicroMenu", self.options) + end + self.options.args = self:IsEnabled() and self.optionobject.table or self.disabledoptions +end diff --git a/Options/MultiCastBar.lua b/Options/MultiCastBar.lua index 05ef789..ad6ee01 100644 --- a/Options/MultiCastBar.lua +++ b/Options/MultiCastBar.lua @@ -1,49 +1,55 @@ ---[[ - Copyright (c) 2009, Hendrik "Nevcairiel" Leppkes < h.leppkes at gmail dot com > - All rights reserved. -]] - -if not HasMultiCastActionBar or select(2, UnitClass("player")) ~= "SHAMAN" then return end - --- fetch upvalues -local L = LibStub("AceLocale-3.0"):GetLocale("Bartender4") -local Bar = Bartender4.Bar.prototype - -local MultiCastMod = Bartender4:GetModule("MultiCast") - -function MultiCastMod:SetupOptions() - if not self.options then - self.optionobject = Bar:GetOptionObject() - local enabled = { - type = "toggle", - order = 1, - name = L["Enabled"], - desc = L["Enable the Totem Bar"], - get = function() return self.db.profile.enabled end, - set = "ToggleModule", - handler = self, - } - self.optionobject:AddElement("general", "enabled", enabled) - - self.disabledoptions = { - general = { - type = "group", - name = L["General Settings"], - cmdInline = true, - order = 1, - args = { - enabled = enabled, - } - } - } - self.options = { - order = 100, - type = "group", - name = L["Totem Bar"], - desc = L["Configure the Totem Bar"], - childGroups = "tab", - } - Bartender4:RegisterBarOptions("MultiCast", self.options) - end - self.options.args = self:IsEnabled() and self.optionobject.table or self.disabledoptions -end +--[[ + Copyright (c) 2009, Hendrik "Nevcairiel" Leppkes < h.leppkes at gmail dot com > + All rights reserved. +]] + +if not HasMultiCastActionBar then return end + +local classMask = UnitClassMask("player") + +if not bit.contains(EnumUtil.CombineMasks(Enum.ClassMask.SHAMAN, Enum.ClassMask.HERO), classMask) then + return +end + +-- fetch upvalues +local L = LibStub("AceLocale-3.0"):GetLocale("Bartender4") +local Bar = Bartender4.Bar.prototype + +local MultiCastMod = Bartender4:GetModule("MultiCast") + +function MultiCastMod:SetupOptions() + if not self.options then + self.optionobject = Bar:GetOptionObject() + local enabled = { + type = "toggle", + order = 1, + name = L["Enabled"], + desc = L["Enable the Totem Bar"], + get = function() return self.db.profile.enabled end, + set = "ToggleModule", + handler = self, + } + self.optionobject:AddElement("general", "enabled", enabled) + + self.disabledoptions = { + general = { + type = "group", + name = L["General Settings"], + cmdInline = true, + order = 1, + args = { + enabled = enabled, + } + } + } + self.options = { + order = 100, + type = "group", + name = L["Totem Bar"], + desc = L["Configure the Totem Bar"], + childGroups = "tab", + } + Bartender4:RegisterBarOptions("MultiCast", self.options) + end + self.options.args = self:IsEnabled() and self.optionobject.table or self.disabledoptions +end diff --git a/Options/Options.lua b/Options/Options.lua index 657a2a4..719ea96 100644 --- a/Options/Options.lua +++ b/Options/Options.lua @@ -1,326 +1,316 @@ ---[[ - Copyright (c) 2009, Hendrik "Nevcairiel" Leppkes < h.leppkes at gmail dot com > - All rights reserved. -]] -local L = LibStub("AceLocale-3.0"):GetLocale("Bartender4") - -local AceConfigDialog = LibStub("AceConfigDialog-3.0") - -local getFunc, setFunc -do - function getFunc(info) - return (info.arg and Bartender4.db.profile[info.arg] or Bartender4.db.profile[info[#info]]) - end - - function setFunc(info, value) - local key = info.arg or info[#info] - Bartender4.db.profile[key] = value - end -end - -local KB = LibStub("LibKeyBound-1.0") -local LDBIcon = LibStub("LibDBIcon-1.0", true) -local function getOptions() - if not Bartender4.options then - Bartender4.options = { - type = "group", - name = "Bartender4", - icon = "Interface\\Icons\\INV_Drink_05", - childGroups = "tree", - plugins = {}, - args = { - lock = { - order = 1, - type = "toggle", - name = L["Lock"], - desc = L["Lock all bars."], - get = function() return Bartender4.Locked end, - set = function(info, value) Bartender4[value and "Lock" or "Unlock"](Bartender4) end, - width = "half", - }, - buttonlock = { - order = 2, - type = "toggle", - name = L["Button Lock"], - desc = L["Lock the buttons."], - get = function() return Bartender4.db.profile.buttonlock end, - set = function(info, value) - Bartender4.db.profile.buttonlock = value - Bartender4.Bar:ForAll("ForAll", "SetAttribute", "buttonlock", value) - end, - }, - minimapIcon = { - order = 3, - type = "toggle", - name = L["Minimap Icon"], - desc = L["Show a Icon to open the config at the Minimap"], - get = function() return not Bartender4.db.profile.minimapIcon.hide end, - set = function(info, value) Bartender4.db.profile.minimapIcon.hide = not value; LDBIcon[value and "Show" or "Hide"](LDBIcon, "Bartender4") end, - disabled = function() return not LDBIcon end, - }, - kb = { - order = 4, - type = "execute", - name = L["Key Bindings"], - desc = L["Switch to key-binding mode"], - func = function() - KB:Toggle() - AceConfigDialog:Close("Bartender4") - end, - }, - bars = { - order = 20, - type = "group", - name = L["Bars"], - args = { - options = { - type = "group", - order = 0, - name = function(info) if info.uiType == "dialog" then return "" else return L["Bar Options"] end end, - guiInline = true, - args = { - blizzardVehicle = { - order = 1, - type = "toggle", - name = L["Use Blizzard Vehicle UI"], - desc = L["Enable the use of the Blizzard Vehicle UI, hiding any Bartender4 bars in the meantime."], - width = "full", - get = getFunc, - set = function(info, value) - if UnitHasVehicleUI("player") then - Bartender4:Print(L["You have to exit the vehicle in order to be able to change the Vehicle UI settings."]) - return - end - Bartender4.db.profile.blizzardVehicle = value - Bartender4:UpdateBlizzardVehicle() - end, - }, - selfcastmodifier = { - order = 10, - type = "toggle", - name = L["Self-Cast by modifier"], - desc = L["Toggle the use of the modifier-based self-cast functionality."], - get = getFunc, - set = function(info, value) - Bartender4.db.profile.selfcastmodifier = value - Bartender4.Bar:ForAll("UpdateSelfCast") - end, - }, - setselfcastmod = { - order = 20, - type = "select", - name = L["Self-Cast Modifier"], - desc = L["Select the Self-Cast Modifier"], - get = function(info) return GetModifiedClick("SELFCAST") end, - set = function(info, value) SetModifiedClick("SELFCAST", value); SaveBindings(GetCurrentBindingSet() or 1) end, - values = { NONE = L["None"], ALT = L["ALT"], SHIFT = L["SHIFT"], CTRL = L["CTRL"] }, - }, - selfcast_nl = { - order = 30, - type = "description", - name = "", - }, - focuscastmodifier = { - order = 50, - type = "toggle", - name = L["Focus-Cast by modifier"], - desc = L["Toggle the use of the modifier-based focus-cast functionality."], - get = getFunc, - set = function(info, value) - Bartender4.db.profile.focuscastmodifier = value - Bartender4.Bar:ForAll("UpdateSelfCast") - end, - }, - setfocuscastmod = { - order = 60, - type = "select", - name = L["Focus-Cast Modifier"], - desc = L["Select the Focus-Cast Modifier"], - get = function(info) return GetModifiedClick("FOCUSCAST") end, - set = function(info, value) SetModifiedClick("FOCUSCAST", value); SaveBindings(GetCurrentBindingSet() or 1) end, - values = { NONE = L["None"], ALT = L["ALT"], SHIFT = L["SHIFT"], CTRL = L["CTRL"] }, - }, - focuscast_nl = { - order = 70, - type = "description", - name = "", - }, - selfcastrightclick = { - order = 80, - type = "toggle", - name = L["Right-click Self-Cast"], - desc = L["Toggle the use of the right-click self-cast functionality."], - get = getFunc, - set = function(info, value) - Bartender4.db.profile.selfcastrightclick = value - Bartender4.Bar:ForAll("UpdateSelfCast") - end, - }, - rightclickselfcast_nl = { - order = 90, - type = "description", - name = "", - }, - range = { - order = 100, - name = L["Out of Range Indicator"], - desc = L["Configure how the Out of Range Indicator should display on the buttons."], - type = "select", - style = "dropdown", - get = function() - return Bartender4.db.profile.outofrange - end, - set = function(info, value) - Bartender4.db.profile.outofrange = value - Bartender4.Bar:ForAll("ApplyConfig") - end, - values = { none = L["No Display"], button = L["Full Button Mode"], hotkey = L["Hotkey Mode"] }, - }, - colors = { - order = 130, - type = "group", - guiInline = true, - name = L["Colors"], - get = function(info) - local color = Bartender4.db.profile.colors[info[#info]] - return color.r, color.g, color.b - end, - set = function(info, r, g, b) - local color = Bartender4.db.profile.colors[info[#info]] - color.r, color.g, color.b = r, g, b - Bartender4.Bar:ForAll("ApplyConfig") - end, - args = { - range = { - order = 1, - type = "color", - name = L["Out of Range Indicator"], - desc = L["Specify the Color of the Out of Range Indicator"], - }, - mana = { - order = 2, - type = "color", - name = L["Out of Mana Indicator"], - desc = L["Specify the Color of the Out of Mana Indicator"], - }, - }, - }, - tooltip = { - order = 200, - name = L["Button Tooltip"], - type = "select", - desc = L["Configure the Button Tooltip."], - values = { ["disabled"] = L["Disabled"], ["nocombat"] = L["Disabled in Combat"], ["enabled"] = L["Enabled"] }, - get = function() return Bartender4.db.profile.tooltip end, - set = function(info, value) Bartender4.db.profile.tooltip = value end, - }, - }, - }, - }, - }, - faq = { - name = L["FAQ"], - desc = L["Frequently Asked Questions"], - type = "group", - order = 200, - args = { - faq = { - type = "description", - name = L["FAQ_TEXT"], - }, - }, - }, - }, - } - Bartender4.options.plugins.profiles = { profiles = LibStub("AceDBOptions-3.0"):GetOptionsTable(Bartender4.db) } - for k,v in Bartender4:IterateModules() do - if v.SetupOptions then - v:SetupOptions() - end - end - end - return Bartender4.options -end - -function Bartender4:ChatCommand(input) - if InCombatLockdown() then - self:Print(L["Cannot access options during combat."]) - return - end - if not input or input:trim() == "" then - LibStub("AceConfigDialog-3.0"):Open("Bartender4") - else - LibStub("AceConfigCmd-3.0").HandleCommand(Bartender4, "bt", "Bartender4", input) - end -end - -function Bartender4:SetupOptions() - LibStub("AceConfig-3.0"):RegisterOptionsTable("Bartender4", getOptions) - AceConfigDialog:SetDefaultSize("Bartender4", 680,525) - local optFunc = function() - if InCombatLockdown() then return end - AceConfigDialog:Open("Bartender4") - --[[ - local status = AceConfigDialog:GetStatusTable("Bartender4") - if not status.groups then status.groups = {} end - if not status.groups.groups then status.groups.groups = {} end - status.groups.groups["actionbars"] = true - ]] - end - self:RegisterChatCommand( "bar", "ChatCommand") - self:RegisterChatCommand( "bt", "ChatCommand") - self:RegisterChatCommand( "bt4", "ChatCommand") - self:RegisterChatCommand( "bartender", "ChatCommand") - self:RegisterChatCommand( "bartender4", "ChatCommand") -end - -function Bartender4:RegisterModuleOptions(key, table) - if not self.options then - error("Options table has not been created yet, respond to the callback!", 2) - end - self.options.plugins[key] = { [key] = table } -end - -function Bartender4:RegisterBarOptions(id, table) - if not self.options then - error("Options table has not been created yet, respond to the callback!", 2) - end - self.options.args.bars.args[id] = table -end - -local optionParent = {} -function optionParent:NewCategory(category, data) - self.table[category] = data -end - -local ov = nil -function optionParent:AddElement(category, element, data, ...) - local lvl = self.table[category] - for i = 1, select('#', ...) do - local key = select(i, ...) - if not (lvl.args[key] and lvl.args[key].args) then - error(("Sub-Level Key %s does not exist in options group or is no sub-group."):format(key), ov and 3 or 2) - end - lvl = lvl.args[key] - end - - lvl.args[element] = data -end - -function optionParent:AddElementGroup(category, data, ...) - ov = true - for k,v in pairs(data) do - self:AddElement(category, k, v, ...) - end - ov = nil -end - -function Bartender4:NewOptionObject(otbl) - if not otbl then otbl = {} end - local tbl = { table = otbl } - for k, v in pairs(optionParent) do - tbl[k] = v - end - - return tbl -end +--[[ + Copyright (c) 2009, Hendrik "Nevcairiel" Leppkes < h.leppkes at gmail dot com > + All rights reserved. +]] +local L = LibStub("AceLocale-3.0"):GetLocale("Bartender4") + +local AceConfigDialog = LibStub("AceConfigDialog-3.0") + +local getFunc, setFunc +do + function getFunc(info) + return (info.arg and Bartender4.db.profile[info.arg] or Bartender4.db.profile[info[#info]]) + end + + function setFunc(info, value) + local key = info.arg or info[#info] + Bartender4.db.profile[key] = value + end +end + +local KB = LibStub("LibKeyBound-1.0") +local LDBIcon = LibStub("LibDBIcon-1.0", true) +local function getOptions() + if not Bartender4.options then + Bartender4.options = { + type = "group", + name = "Bartender4", + icon = "Interface\\Icons\\INV_Drink_05", + childGroups = "tree", + plugins = {}, + args = { + lock = { + order = 1, + type = "toggle", + name = L["Lock"], + desc = L["Lock all bars."], + get = function() return Bartender4.Locked end, + set = function(info, value) Bartender4[value and "Lock" or "Unlock"](Bartender4) end, + width = "half", + }, + buttonlock = { + order = 2, + type = "toggle", + name = L["Button Lock"], + desc = L["Lock the buttons."], + get = function() return Bartender4.db.profile.buttonlock end, + set = function(info, value) + Bartender4.db.profile.buttonlock = value + Bartender4.Bar:ForAll("ForAll", "SetAttribute", "buttonlock", value) + end, + }, + minimapIcon = { + order = 3, + type = "toggle", + name = L["Minimap Icon"], + desc = L["Show a Icon to open the config at the Minimap"], + get = function() return not Bartender4.db.profile.minimapIcon.hide end, + set = function(info, value) Bartender4.db.profile.minimapIcon.hide = not value; LDBIcon[value and "Show" or "Hide"](LDBIcon, "Bartender4") end, + disabled = function() return not LDBIcon end, + }, + kb = { + order = 4, + type = "execute", + name = L["Key Bindings"], + desc = L["Switch to key-binding mode"], + func = function() + KB:Toggle() + AceConfigDialog:Close("Bartender4") + end, + }, + bars = { + order = 20, + type = "group", + name = L["Bars"], + args = { + options = { + type = "group", + order = 0, + name = function(info) if info.uiType == "dialog" then return "" else return L["Bar Options"] end end, + guiInline = true, + args = { + blizzardVehicle = { + order = 1, + type = "toggle", + name = L["Use Blizzard Vehicle UI"], + desc = L["Enable the use of the Blizzard Vehicle UI, hiding any Bartender4 bars in the meantime."], + width = "full", + get = getFunc, + set = function(info, value) + if UnitHasVehicleUI("player") then + Bartender4:Print(L["You have to exit the vehicle in order to be able to change the Vehicle UI settings."]) + return + end + Bartender4.db.profile.blizzardVehicle = value + Bartender4:UpdateBlizzardVehicle() + end, + }, + selfcastmodifier = { + order = 10, + type = "toggle", + name = L["Self-Cast by modifier"], + desc = L["Toggle the use of the modifier-based self-cast functionality."], + get = getFunc, + set = function(info, value) + Bartender4.db.profile.selfcastmodifier = value + Bartender4.Bar:ForAll("UpdateSelfCast") + end, + }, + setselfcastmod = { + order = 20, + type = "select", + name = L["Self-Cast Modifier"], + desc = L["Select the Self-Cast Modifier"], + get = function(info) return GetModifiedClick("SELFCAST") end, + set = function(info, value) SetModifiedClick("SELFCAST", value); SaveBindings(GetCurrentBindingSet() or 1) end, + values = { NONE = L["None"], ALT = L["ALT"], SHIFT = L["SHIFT"], CTRL = L["CTRL"] }, + }, + selfcast_nl = { + order = 30, + type = "description", + name = "", + }, + focuscastmodifier = { + order = 50, + type = "toggle", + name = L["Focus-Cast by modifier"], + desc = L["Toggle the use of the modifier-based focus-cast functionality."], + get = getFunc, + set = function(info, value) + Bartender4.db.profile.focuscastmodifier = value + Bartender4.Bar:ForAll("UpdateSelfCast") + end, + }, + setfocuscastmod = { + order = 60, + type = "select", + name = L["Focus-Cast Modifier"], + desc = L["Select the Focus-Cast Modifier"], + get = function(info) return GetModifiedClick("FOCUSCAST") end, + set = function(info, value) SetModifiedClick("FOCUSCAST", value); SaveBindings(GetCurrentBindingSet() or 1) end, + values = { NONE = L["None"], ALT = L["ALT"], SHIFT = L["SHIFT"], CTRL = L["CTRL"] }, + }, + focuscast_nl = { + order = 70, + type = "description", + name = "", + }, + selfcastrightclick = { + order = 80, + type = "toggle", + name = L["Right-click Self-Cast"], + desc = L["Toggle the use of the right-click self-cast functionality."], + get = getFunc, + set = function(info, value) + Bartender4.db.profile.selfcastrightclick = value + Bartender4.Bar:ForAll("UpdateSelfCast") + end, + }, + rightclickselfcast_nl = { + order = 90, + type = "description", + name = "", + }, + range = { + order = 100, + name = L["Out of Range Indicator"], + desc = L["Configure how the Out of Range Indicator should display on the buttons."], + type = "select", + style = "dropdown", + get = function() + return Bartender4.db.profile.outofrange + end, + set = function(info, value) + Bartender4.db.profile.outofrange = value + Bartender4.Bar:ForAll("ApplyConfig") + end, + values = { none = L["No Display"], button = L["Full Button Mode"], hotkey = L["Hotkey Mode"] }, + }, + colors = { + order = 130, + type = "group", + guiInline = true, + name = L["Colors"], + get = function(info) + local color = Bartender4.db.profile.colors[info[#info]] + return color.r, color.g, color.b + end, + set = function(info, r, g, b) + local color = Bartender4.db.profile.colors[info[#info]] + color.r, color.g, color.b = r, g, b + Bartender4.Bar:ForAll("ApplyConfig") + end, + args = { + range = { + order = 1, + type = "color", + name = L["Out of Range Indicator"], + desc = L["Specify the Color of the Out of Range Indicator"], + }, + mana = { + order = 2, + type = "color", + name = L["Out of Mana Indicator"], + desc = L["Specify the Color of the Out of Mana Indicator"], + }, + }, + }, + tooltip = { + order = 200, + name = L["Button Tooltip"], + type = "select", + desc = L["Configure the Button Tooltip."], + values = { ["disabled"] = L["Disabled"], ["nocombat"] = L["Disabled in Combat"], ["enabled"] = L["Enabled"] }, + get = function() return Bartender4.db.profile.tooltip end, + set = function(info, value) Bartender4.db.profile.tooltip = value end, + }, + }, + }, + }, + }, + faq = { + name = L["FAQ"], + desc = L["Frequently Asked Questions"], + type = "group", + order = 200, + args = { + faq = { + type = "description", + name = L["FAQ_TEXT"], + }, + }, + }, + }, + } + Bartender4.options.plugins.profiles = { profiles = LibStub("AceDBOptions-3.0"):GetOptionsTable(Bartender4.db) } + for k,v in Bartender4:IterateModules() do + if v.SetupOptions then + v:SetupOptions() + end + end + end + return Bartender4.options +end + +function Bartender4:ChatCommand(input) + if InCombatLockdown() then + self:Print(L["Cannot access options during combat."]) + return + end + if not input or input:trim() == "" then + LibStub("AceConfigDialog-3.0"):Open("Bartender4") + else + LibStub("AceConfigCmd-3.0").HandleCommand(Bartender4, "bt", "Bartender4", input) + end +end + +function Bartender4:SetupOptions() + LibStub("AceConfig-3.0"):RegisterOptionsTable("Bartender4", getOptions) + AceConfigDialog:SetDefaultSize("Bartender4", 680,525) + self:RegisterChatCommand( "bar", "ChatCommand") + self:RegisterChatCommand( "bt", "ChatCommand") + self:RegisterChatCommand( "bt4", "ChatCommand") + self:RegisterChatCommand( "bartender", "ChatCommand") + self:RegisterChatCommand( "bartender4", "ChatCommand") +end + +function Bartender4:RegisterModuleOptions(key, table) + if not self.options then + error("Options table has not been created yet, respond to the callback!", 2) + end + self.options.plugins[key] = { [key] = table } +end + +function Bartender4:RegisterBarOptions(id, table) + if not self.options then + error("Options table has not been created yet, respond to the callback!", 2) + end + self.options.args.bars.args[id] = table +end + +local optionParent = {} +function optionParent:NewCategory(category, data) + self.table[category] = data +end + +local ov = nil +function optionParent:AddElement(category, element, data, ...) + local lvl = self.table[category] + for i = 1, select('#', ...) do + local key = select(i, ...) + if not (lvl.args[key] and lvl.args[key].args) then + error(("Sub-Level Key %s does not exist in options group or is no sub-group."):format(key), ov and 3 or 2) + end + lvl = lvl.args[key] + end + + lvl.args[element] = data +end + +function optionParent:AddElementGroup(category, data, ...) + ov = true + for k,v in pairs(data) do + self:AddElement(category, k, v, ...) + end + ov = nil +end + +function Bartender4:NewOptionObject(otbl) + if not otbl then otbl = {} end + local tbl = { table = otbl } + for k, v in pairs(optionParent) do + tbl[k] = v + end + + return tbl +end diff --git a/Options/Options.xml b/Options/Options.xml index cea6e7c..83c655c 100644 --- a/Options/Options.xml +++ b/Options/Options.xml @@ -1,19 +1,19 @@ - -