From 60fa80d4013283cce9ca5a9e8e54bd5b6ba79f7a Mon Sep 17 00:00:00 2001 From: Hendrik Leppkes Date: Mon, 10 Mar 2008 16:20:58 +0000 Subject: [PATCH] set override bindings on Bar1, ShapeshiftBar, PetBar --- ActionBarPrototype.lua | 4 ++++ ActionBars.lua | 17 ++++++++++++++++- Button.lua | 8 ++++---- PetBar.lua | 18 +++++++++++++++++- StanceBar.lua | 21 ++++++++++++++++++++- 5 files changed, 61 insertions(+), 7 deletions(-) diff --git a/ActionBarPrototype.lua b/ActionBarPrototype.lua index 6fc5f90..0a6b59c 100644 --- a/ActionBarPrototype.lua +++ b/ActionBarPrototype.lua @@ -145,6 +145,7 @@ function ActionBar:UpdateButtons(numbuttons) 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) @@ -166,6 +167,9 @@ function ActionBar:UpdateButtons(numbuttons) self:UpdateButtonLayout() self:SetGrid() + if updateBindings and self.id == "1" then + module:ReassignBindings() + end end diff --git a/ActionBars.lua b/ActionBars.lua index 4940564..2ffd4b2 100644 --- a/ActionBars.lua +++ b/ActionBars.lua @@ -1,6 +1,6 @@ --[[ $Id$ ]] -local BT4ActionBars = Bartender4:NewModule("ActionBars") +local BT4ActionBars = Bartender4:NewModule("ActionBars", "AceEvent-3.0") local ActionBar, ActionBar_MT @@ -79,6 +79,8 @@ function BT4ActionBars:OnEnable() end first = nil end + self:RegisterEvent("UPDATE_BINDINGS", "ReassignBindings") + self:ReassignBindings() end -- Applys the config in the current profile to all active Bars @@ -222,6 +224,19 @@ function BT4ActionBars:CreateBarOption(id, options) self.options.args[id].args = options end +function BT4ActionBars:ReassignBindings() + 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 +end + -- Creates a new bar object based on the id and the specified config function BT4ActionBars:Create(id, config) local id = tostring(id) diff --git a/Button.lua b/Button.lua index 6e6f672..7e369dc 100644 --- a/Button.lua +++ b/Button.lua @@ -288,10 +288,10 @@ function Button:GetBindings() 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_') + if keys ~= "" then + keys = keys .. ', ' + end + keys = keys .. GetBindingText(hotKey,'KEY_') end return keys diff --git a/PetBar.lua b/PetBar.lua index 6822233..84fd191 100644 --- a/PetBar.lua +++ b/PetBar.lua @@ -1,7 +1,7 @@ --[[ $Id: StanceBar.lua 61678 2008-02-17 01:37:33Z nevcairiel $ ]] -- register module -local PetBarMod = Bartender4:NewModule("PetBar") +local PetBarMod = Bartender4:NewModule("PetBar", "AceEvent-3.0") -- fetch upvalues local ActionBars = Bartender4:GetModule("ActionBars") @@ -57,6 +57,9 @@ function PetBarMod:OnEnable() self:ApplyConfig() self:SetupOptions() + + self:RegisterEvent("UPDATE_BINDINGS", "ReassignBindings") + self:ReassignBindings() end function PetBarMod:OnDisable() @@ -144,9 +147,22 @@ function PetBarMod:SetupOptions() ActionBars.options.args["Pet"].args = self:IsEnabled() and self.options.table or self.disabledoptions end +function PetBarMod:ReassignBindings() + if not self.bar or not self.bar.buttons then return end + ClearOverrideBindings(self.bar) + for i = 1, 10 do + local button, real_button = ("BONUSACTIONBUTTON%d"):format(i), ("BT4PetButton%d"):format(i) + for k=1, select('#', GetBindingKey(button)) do + local key = select(k, GetBindingKey(button)) + SetOverrideBindingClick(self.bar, false, key, real_button) + end + end +end + function PetBarMod:ApplyConfig() if not self:IsEnabled() then return end self.bar:ApplyConfig(self.db.profile) + self:ReassignBindings() end function PetButtonPrototype:Update() diff --git a/StanceBar.lua b/StanceBar.lua index 596ebfe..39355f9 100644 --- a/StanceBar.lua +++ b/StanceBar.lua @@ -1,7 +1,7 @@ --[[ $Id$ ]] -- register module -local StanceBarMod = Bartender4:NewModule("StanceBar") +local StanceBarMod = Bartender4:NewModule("StanceBar", "AceEvent-3.0") -- fetch upvalues local ActionBars = Bartender4:GetModule("ActionBars") @@ -41,6 +41,8 @@ function StanceBarMod:OnEnable() self.bar:RegisterEvent("PLAYER_AURAS_CHANGED") self.bar:RegisterEvent("PLAYER_REGEN_ENABLED") self.bar:Show() + self:RegisterEvent("UPDATE_BINDINGS", "ReassignBindings") + self:ReassignBindings() end function StanceBarMod:OnDisable() @@ -95,6 +97,18 @@ function StanceBarMod:ApplyConfig() self.bar:ApplyConfig(self.db.profile) end +function StanceBarMod:ReassignBindings() + if not self.bar or not self.bar.buttons then return end + ClearOverrideBindings(self.bar) + for i = 1, min(#self.bar.buttons, 10) do + local button, real_button = ("SHAPESHIFTBUTTON%d"):format(i), ("BT4StanceButton%d"):format(i) + for k=1, select('#', GetBindingKey(button)) do + local key = select(k, GetBindingKey(button)) + SetOverrideBindingClick(self.bar, false, key, real_button) + end + end +end + function StanceButtonPrototype:Update() if not self:IsShown() then return end local id = self:GetID() @@ -205,6 +219,8 @@ function StanceBar:UpdateStanceButtons() local num_stances = GetNumShapeshiftForms() + local updateBindings = (num_stances > #buttons) + for i = (#buttons+1), num_stances do buttons[i] = StanceBarMod:CreateStanceButton(i) end @@ -221,6 +237,9 @@ function StanceBar:UpdateStanceButtons() self.buttons = buttons self:UpdateButtonLayout() + if updateBindings then + StanceBarMod:ReassignBindings() + end end function StanceBar:OnEvent(event, ...)