From e072ee9e08728cdf996b01d2375f85a9f290536a Mon Sep 17 00:00:00 2001 From: Hendrik Leppkes Date: Mon, 16 Jun 2008 15:07:46 +0000 Subject: [PATCH] - now using the blizzard actionbutton template for action buttons - this means: -- draging of spells in combat is possible again -- empty buttons will be really hidden -- the lock actionbuttons option from the BT menu is currently gone, use the interface options setting to lock moving your actions --- ActionBarPrototype.lua | 1 - ActionBars.lua | 13 +- Button.lua | 450 ++++++++--------------------------------- Options.lua | 4 +- 4 files changed, 100 insertions(+), 368 deletions(-) diff --git a/ActionBarPrototype.lua b/ActionBarPrototype.lua index 94bf099..0dcadd8 100644 --- a/ActionBarPrototype.lua +++ b/ActionBarPrototype.lua @@ -172,7 +172,6 @@ function ActionBar:UpdateButtons(numbuttons) -- show active buttons for i = 1, numbuttons do buttons[i]:SetParent(self) - buttons[i]:SetLevels() buttons[i]:Show() buttons[i]:UpdateAction(true) end diff --git a/ActionBars.lua b/ActionBars.lua index dc4260d..8c34108 100644 --- a/ActionBars.lua +++ b/ActionBars.lua @@ -183,12 +183,23 @@ function BT4ActionBars:ReassignBindings() local frame = self.actionbars[1] ClearOverrideBindings(frame) for i = 1,min(#frame.buttons, 12) do - local button, real_button = ("ACTIONBUTTON%d"):format(i), ("BT4Button%dSecure"):format(i) + 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 = ATTACK_BUTTON_FLASH_TIME then + if ( overtime >= ATTACK_BUTTON_FLASH_TIME ) then overtime = 0 end self.flashtime = ATTACK_BUTTON_FLASH_TIME - overtime - + local flashTexture = self.flash - if flashTexture:IsVisible() then + if ( flashTexture:IsShown() ) then flashTexture:Hide() else flashTexture:Show() @@ -170,16 +103,16 @@ function onUpdate(self, elapsed) end end - if self.rangeTimer then + if ( self.rangeTimer ) then self.rangeTimer = self.rangeTimer - elapsed + if self.rangeTimer <= 0 then local valid = IsActionInRange(self.action) - local hotkey = self.hotkey - local hkshown = (hotkey:GetText() == RANGE_INDICATOR and oor == "hotkey") + local hkshown = (self.hotkey:GetText() == RANGE_INDICATOR and oor == "hotkey") if valid and hkshown then - hotkey:Show() + self.hotkey:Show() elseif hkshown then - hotkey:Hide() + self.hotkey:Hide() end self.outOfRange = (valid == 0) self:UpdateUsable() @@ -230,94 +163,68 @@ function Button:SetStateAction(state, action) self:SetAttribute(("*action-S%dRight"):format(state), action) end -function Button:CalculateAction() - return SecureButton_GetModifiedAttribute(self, "action", SecureButton_GetEffectiveButton(self)) or 1 -end - function Button:GetActionID() return self.action end -function Button:UpdateAction(force) - local action = self:CalculateAction() - if action ~= self.action or force then - self.action = action - self:Update() - end +function Button:Update() + local oldthis = this + this = self + ActionButton_Update(self) + this = oldthis + + self:UpdateUsable(true) end -function Button:Update() - local action = self.action - self:UpdateIcon() - self:UpdateCount() - self:UpdateHotkeys() - if ( HasAction(action) ) then - self:RegisterActionEvents() - - self:UpdateState() - self:UpdateUsable(true) - self:UpdateCooldown() - self:UpdateFlash() - - self:ShowButton() - self:SetScript("OnUpdate", onUpdate) +function Button:UpdateAction() + local oldthis = this + this = self + ActionButton_UpdateAction(self) + this = oldthis +end + +orig_ActionButton_UpdateUsable = ActionButton_UpdateUsable +ActionButton_UpdateUsable = function(...) + if this.isBartender4Button then + this:UpdateHotkeys() else - self:UnregisterActionEvents() - - self.cooldown:Hide() - - if ( self.showgrid == 0 and not self.parent.config.showgrid ) then - self:HideButton() + return orig_ActionButton_UpdateUsable(...) + end +end +function Button:UpdateUsable(force) + local isUsable, notEnoughMana = IsUsableAction(self.action) + local icon, hotkey = self.icon, self.hotkey + if force or not oor then + oor = Bartender4.db.profile.outofrange + oorcolor, oomcolor = Bartender4.db.profile.colors.range, Bartender4.db.profile.colors.mana + end + + if oor == "button" and self.outOfRange then + icon:SetVertexColor(oorcolor.r, oorcolor.g, oorcolor.b) + hotkey:SetVertexColor(1.0, 1.0, 1.0) + else + if oor == "hotkey" and self.outOfRange then + hotkey:SetVertexColor(oorcolor.r, oorcolor.g, oorcolor.b) + else + hotkey:SetVertexColor(1.0, 1.0, 1.0) end - self:SetScript("OnUpdate", nil) - end - - if ( IsEquippedAction(action) ) then - self.border:SetVertexColor(0, 1.0, 0, 0.75) - self.border:Show() - else - self.border:Hide() - end - - if ( GameTooltip:GetOwner() == self) then - self:SetTooltip() - end - - if not IsConsumableAction(action) and not IsStackableAction(action) and not self.parent.config.hidemacrotext then - self.macroName:SetText(GetActionText(action)) - else - self.macroName:SetText("") - end - -end - -function Button:UpdateIcon() - local texture = GetActionTexture(self.action) - if ( texture ) then - self.rangeTimer = -1 - self.icon:SetTexture(texture) - self.icon:Show() - self.normalTexture:SetTexture("Interface\\Buttons\\UI-Quickslot2") - self.normalTexture:SetTexCoord(0, 0, 0, 0) - self.iconTex = texture - else - self.rangeTimer = nil - self.icon:Hide() - self.cooldown:Hide() - self.normalTexture:SetTexture("Interface\\Buttons\\UI-Quickslot") - self.normalTexture:SetTexCoord(-0.15, 1.15, -0.15, 1.17) - self.hotkey:SetVertexColor(0.6, 0.6, 0.6) - self.iconTex = nil + if isUsable then + icon:SetVertexColor(1.0, 1.0, 1.0) + elseif notEnoughMana then + icon:SetVertexColor(oomcolor.r, oomcolor.g, oomcolor.b) + else + icon:SetVertexColor(0.4, 0.4, 0.4) + end end end -function Button:UpdateCount() - local action = self.action - if ( IsConsumableAction(action) or IsStackableAction(action) ) then - self.count:SetText(GetActionCount(action)) +orig_ActionButton_UpdateHotkeys = ActionButton_UpdateHotkeys +ActionButton_UpdateHotkeys = function(...) + if this.isBartender4Button then + this:UpdateHotkeys() else - self.count:SetText("") + return orig_ActionButton_UpdateHotkeys(...) end end @@ -393,205 +300,20 @@ function Button:GetActionName() return format(actionTmpl, self.parent.id, self.rid) end -function Button:UpdateState() - local action = self.action - if ( IsCurrentAction(action) or IsAutoRepeatAction(action) ) then - self:SetChecked(1) - else - self:SetChecked(0) - end -end - -function Button:UpdateUsable(force) - local isUsable, notEnoughMana = IsUsableAction(self.action) - local icon, hotkey = self.icon, self.hotkey - if force or not oor then - oor = Bartender4.db.profile.outofrange - oorcolor, oomcolor = Bartender4.db.profile.colors.range, Bartender4.db.profile.colors.mana - end - - if oor == "button" and self.outOfRange then - icon:SetVertexColor(oorcolor.r, oorcolor.g, oorcolor.b) - hotkey:SetVertexColor(1.0, 1.0, 1.0) - else - if oor == "hotkey" and self.outOfRange then - hotkey:SetVertexColor(oorcolor.r, oorcolor.g, oorcolor.b) - else - hotkey:SetVertexColor(1.0, 1.0, 1.0) - end - - if isUsable then - icon:SetVertexColor(1.0, 1.0, 1.0) - elseif notEnoughMana then - icon:SetVertexColor(oomcolor.r, oomcolor.g, oomcolor.b) - else - icon:SetVertexColor(0.4, 0.4, 0.4) - end - end -end - -function Button:UpdateCooldown() - local start, duration, enable = GetActionCooldown(self.action) - CooldownFrame_SetTimer(self.cooldown, start, duration, enable) -end - -function Button:UpdateFlash() - local action = self.action - if ( (IsAttackAction(action) and IsCurrentAction(action)) or IsAutoRepeatAction(action) ) then - self:StartFlash() - else - self:StopFlash() - end -end - -function Button:StartFlash() - self.flashing = 1 - self.flashtime = 0 - self:UpdateState() -end - -function Button:StopFlash() - self.flashing = 0 - self.flash:Hide() - self:UpdateState() -end - -function Button:SetTooltip() - if ( GetCVar("UberTooltips") == "1" ) then - GameTooltip_SetDefaultAnchor(GameTooltip, self) - else - GameTooltip:SetOwner(self, "ANCHOR_RIGHT") - end - - if ( GameTooltip:SetAction(self.action) ) then - self.UpdateTooltip = self.SetTooltip - else - self.UpdateTooltip = nil - end -end - -function Button:ShowButton() - if self.Proxy:IsShown() then return end - self.pushedTexture:SetTexture(self.textureCache.pushed) - self.highlightTexture:SetTexture(self.textureCache.highlight) - - self.Proxy:Show() -end - -function Button:HideButton() - if not self.Proxy:IsShown() then return end - self.textureCache.pushed = self.pushedTexture:GetTexture() - self.textureCache.highlight = self.highlightTexture:GetTexture() - - self.pushedTexture:SetTexture("") - self.highlightTexture:SetTexture("") - - self.Proxy:Hide() -end - function Button:ShowGrid() - self.showgrid = self.showgrid + 1 - - self:ShowButton() + if not self.gridShown then + self.gridShown = true + self:SetAttribute("showgrid", self:GetAttribute("showgrid") + 1) + end + ActionButton_ShowGrid(self) end function Button:HideGrid() - if self.showgrid > 0 then self.showgrid = self.showgrid - 1 end - if ( self.showgrid == 0 and not HasAction(self.action) and not self.parent.config.showgrid ) then - self:HideButton() - end -end - -function Button:RegisterButtonEvents() - self:RegisterEvent("ACTIONBAR_SLOT_CHANGED") - self:RegisterEvent("PLAYER_ENTERING_WORLD") - self:RegisterEvent("ACTIONBAR_PAGE_CHANGED") - self:RegisterEvent("ACTIONBAR_SHOWGRID") - self:RegisterEvent("ACTIONBAR_HIDEGRID") - self:RegisterEvent("UPDATE_BINDINGS") - self:RegisterEvent("UPDATE_SHAPESHIFT_FORM") -end - -local actionevents = { - "PLAYER_TARGET_CHANGED", - "ACTIONBAR_UPDATE_STATE", - "ACTIONBAR_UPDATE_USABLE", - "ACTIONBAR_UPDATE_COOLDOWN", - --"UPDATE_INVENTORY_ALERTS", - --"PLAYER_AURAS_CHANGED", - "CRAFT_SHOW", - "CRAFT_CLOSE", - "TRADE_SKILL_SHOW", - "TRADE_SKILL_CLOSE", - "PLAYER_ENTER_COMBAT", - "PLAYER_LEAVE_COMBAT", - "START_AUTOREPEAT_SPELL", - "STOP_AUTOREPEAT_SPELL", -} - -function Button:RegisterActionEvents() - if self.eventsregistered then return end - self.eventsregistered = true - - for _, event in ipairs(actionevents) do - self:RegisterEvent(event) - end -end - -function Button:UnregisterActionEvents() - if not self.eventsregistered then return end - self.eventsregistered = nil - - for _, event in ipairs(actionevents) do - self:UnregisterEvent(event) - end -end - -function Button:EventHandler(event, arg1) - if ( event == "ACTIONBAR_SLOT_CHANGED" ) then - if ( arg1 == 0 or arg1 == self.action ) then - self:Update() - end - elseif ( event == "PLAYER_ENTERING_WORLD" ) then - self:Update() - elseif ( event == "ACTIONBAR_PAGE_CHANGED" or event == "UPDATE_BONUS_ACTIONBAR" ) then - self:UpdateAction() - elseif ( event == "ACTIONBAR_SHOWGRID" ) then - self:ShowGrid() - elseif ( event == "ACTIONBAR_HIDEGRID" ) then - self:HideGrid() - elseif ( event == "UPDATE_BINDINGS" ) then - self:UpdateHotkeys() - elseif not self.eventsregistered then - return - -- Action Event Handlers, only set when the button actually has an action - elseif ( event == "PLAYER_TARGET_CHANGED" ) then - self.rangeTimer = -1 - elseif ( event == "ACTIONBAR_UPDATE_STATE" ) then - self:UpdateState() - elseif ( event == "ACTIONBAR_UPDATE_USABLE" ) then - self:UpdateUsable() - elseif ( event == "ACTIONBAR_UPDATE_COOLDOWN" ) then - self:UpdateCooldown() - elseif ( event == "CRAFT_SHOW" or event == "CRAFT_CLOSE" or event == "TRADE_SKILL_SHOW" or event == "TRADE_SKILL_CLOSE" ) then - self:UpdateState() - elseif ( event == "PLAYER_ENTER_COMBAT" ) then - if ( IsAttackAction(self.action) ) then - self:StartFlash() - end - elseif ( event == "PLAYER_LEAVE_COMBAT" ) then - if ( IsAttackAction(self.action) ) then - self:StopFlash() - end - elseif ( event == "START_AUTOREPEAT_SPELL" ) then - if ( IsAutoRepeatAction(self.action) ) then - self:StartFlash() - end - elseif ( event == "STOP_AUTOREPEAT_SPELL" ) then - if ( self.flashing == 1 and not IsAttackAction(self.action) ) then - self:StopFlash() - end + if self.gridShown then + self.gridShown = nil + self:SetAttribute("showgrid", self:GetAttribute("showgrid") - 1) end + ActionButton_HideGrid(self) end function Button:ClearSetPoint(...) diff --git a/Options.lua b/Options.lua index 027e954..954d207 100644 --- a/Options.lua +++ b/Options.lua @@ -33,14 +33,14 @@ local function getOptions() get = function() return Bartender4.Locked end, set = function(info, value) Bartender4[value and "Lock" or "Unlock"](Bartender4) end, }, - buttonlock = { + --[[buttonlock = { order = 2, type = "toggle", name = "Button Lock", desc = "Lock the buttons.", get = getFunc, set = setFunc, - }, + },--]] bars = { order = 20, type = "group",