diff --git a/Button.lua b/Button.lua index f6b2128..6e6f672 100644 --- a/Button.lua +++ b/Button.lua @@ -11,6 +11,7 @@ local onEnter, onLeave, onUpdate, onDragStart, onReceiveDrag -- upvalues local _G = _G +local format = string.format local IsUsableAction = IsUsableAction local IsActionInRange = IsActionInRange @@ -271,28 +272,26 @@ function Button:GetHotkey() end function Button:GetBindings() - local keys, binding + 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 .. ', ' .. GetBindingText(hotKey,'KEY_') - else - keys = GetBindingText(hotKey,'KEY_') + 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 .. ', ' .. GetBindingText(hotKey,'KEY_') - else - keys = GetBindingText(hotKey,'KEY_') - end + if keys ~= "" then + keys = keys .. ', ' + end + keys = keys .. GetBindingText(hotKey,'KEY_') end return keys @@ -306,9 +305,9 @@ function Button:SetKey(key) end end -local actionTmpl = "BT4 Bar %d Button %d %s" +local actionTmpl = "BT4 Bar %d Button %d" function Button:GetActionName() - return format(actionTmpl, self.parent.id, self.rid, HasAction(self.action) and (" (".. (GetActionText(self.action) or "") ..")")) + return format(actionTmpl, self.parent.id, self.rid) end function Button:UpdateState() diff --git a/PetBar.lua b/PetBar.lua index 3f5b025..6822233 100644 --- a/PetBar.lua +++ b/PetBar.lua @@ -70,6 +70,11 @@ function PetBarMod:OnDisable() self:SetupOptions() end +local function onEnter(self, ...) + self:OnEnter(...) + KeyBound:Set(self) +end + function PetBarMod:CreatePetButton(id) local name = "BT4PetButton" .. id local button = setmetatable(CreateFrame("CheckButton", name, self.bar, "PetActionButtonTemplate"), PetButton_MT) @@ -82,6 +87,9 @@ function PetBarMod:CreatePetButton(id) button:UnregisterAllEvents() button:SetScript("OnEvent", nil) + button.OnEnter = button:GetScript("OnEnter") + button:SetScript("OnEnter", onEnter) + button.flash = _G[name .. "Flash"] button.cooldown = _G[name .. "Cooldown"] button.icon = _G[name .. "Icon"] @@ -238,6 +246,45 @@ end -- import style function PetButtonPrototype.ApplyStyle = Bartender4.ButtonStyle.ApplyStyle +function PetButtonPrototype:GetHotkey() + local key = GetBindingKey(format("BONUSACTIONBUTTON%d", self:GetID())) or GetBindingKey("CLICK "..self:GetName()..":LeftButton") + return key and KeyBound:ToShortKey(key) +end + +function PetButtonPrototype:GetBindings() + local keys, binding = "" + + binding = format("BONUSACTIONBUTTON%d", self:GetID()) + 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 + + 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 PetButtonPrototype:SetKey(key) + SetBinding(key, format("BONUSACTIONBUTTON%d", self:GetID())) +end + +local actionTmpl = "Pet Button %d (%s)" +function PetButtonPrototype:GetActionName() + local id = self:GetID() + return format(actionTmpl, id, (GetPetActionInfo(id))) +end + function PetButtonPrototype:ClearSetPoint(...) self:ClearAllPoints() self:SetPoint(...) diff --git a/StanceBar.lua b/StanceBar.lua index 97bfd4f..596ebfe 100644 --- a/StanceBar.lua +++ b/StanceBar.lua @@ -12,6 +12,8 @@ local StanceBar = setmetatable({}, {__index = ButtonBar}) local StanceButtonPrototype = CreateFrame("CheckButton") local StanceButton_MT = {__index = StanceButtonPrototype} +local format = string.format + local defaults = { profile = Bartender4:Merge({ enabled = true, scale = 1.5, @@ -124,11 +126,56 @@ end StanceButtonPrototype.ApplyStyle = Bartender4.ButtonStyle.ApplyStyle +function StanceButtonPrototype:GetHotkey() + local key = GetBindingKey(format("SHAPESHIFTBUTTON%d", self:GetID())) or GetBindingKey("CLICK "..self:GetName()..":LeftButton") + return key and KeyBound:ToShortKey(key) +end + +function StanceButtonPrototype:GetBindings() + local keys, binding = "" + + binding = format("SHAPESHIFTBUTTON%d", self:GetID()) + 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 + + 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 StanceButtonPrototype:SetKey(key) + SetBinding(key, format("SHAPESHIFTBUTTON%d", self:GetID())) +end + +local actionTmpl = "Stance Button %d (%s)" +function StanceButtonPrototype:GetActionName() + local id = self:GetID() + return format(actionTmpl, id, select(2, GetShapeshiftFormInfo(id))) +end + + function StanceButtonPrototype:ClearSetPoint(...) self:ClearAllPoints() self:SetPoint(...) end +local function onEnter(self, ...) + self:OnEnter(...) + KeyBound:Set(self) +end + function StanceBarMod:CreateStanceButton(id) local button = setmetatable(CreateFrame("CheckButton", "BT4StanceButton" .. id, self.bar, "ShapeshiftButtonTemplate"), StanceButton_MT) button:SetID(id) @@ -138,6 +185,10 @@ function StanceBarMod:CreateStanceButton(id) button.normalTexture:SetTexture("") button.checkedTexture = button:GetCheckedTexture() button.checkedTexture:SetTexture("") + + button.OnEnter = button:GetScript("OnEnter") + button:SetScript("OnEnter", onEnter) + return button end