Flick@276: local _, ns = ... Flick@276: local ReAction = ns.ReAction flickerstreak@134: local L = ReAction.L flickerstreak@134: local _G = _G flickerstreak@134: local CreateFrame = CreateFrame flickerstreak@134: local format = string.format flickerstreak@134: local GetCVar = GetCVar flickerstreak@134: local GameTooltip_SetDefaultAnchor = GameTooltip_SetDefaultAnchor flickerstreak@134: local CooldownFrame_SetTimer = CooldownFrame_SetTimer flickerstreak@134: local InCombatLockdown = InCombatLockdown flickerstreak@134: local GetNumShapeshiftForms = GetNumShapeshiftForms flickerstreak@134: local GetShapeshiftFormInfo = GetShapeshiftFormInfo flickerstreak@134: local IsUsableSpell = IsUsableSpell flickerstreak@134: local GetSpellInfo = GetSpellInfo flickerstreak@134: flickerstreak@134: -- flickerstreak@134: -- private flickerstreak@134: -- flickerstreak@134: local playerClass = select(2,UnitClass("player")) flickerstreak@134: flickerstreak@134: local eventList = { flickerstreak@134: "PLAYER_REGEN_ENABLED", flickerstreak@134: "PLAYER_ENTERING_WORLD", flickerstreak@134: "UPDATE_SHAPESHIFT_FORM", flickerstreak@134: "UPDATE_SHAPESHIFT_FORMS", flickerstreak@134: "UPDATE_SHAPESHIFT_USABLE", flickerstreak@134: "UPDATE_SHAPESHIFT_COOLDOWN", flickerstreak@137: "UPDATE_BINDINGS", flickerstreak@134: } flickerstreak@134: flickerstreak@134: -- flickerstreak@134: -- Stance Button class flickerstreak@134: -- flickerstreak@218: local buttonTypeID = "Stance" flickerstreak@134: local Super = ReAction.Button flickerstreak@218: local Stance = setmetatable( flickerstreak@218: { Flick@248: defaultBarConfig = { flickerstreak@218: type = buttonTypeID, flickerstreak@218: btnHeight = 36, flickerstreak@218: btnWidth = 36, flickerstreak@218: btnRows = 1, flickerstreak@218: btnColumns = 6, flickerstreak@218: spacing = 3 flickerstreak@218: }, flickerstreak@218: flickerstreak@218: barType = L["Stance Bar"], Flick@231: buttonTypeID = buttonTypeID flickerstreak@218: }, flickerstreak@218: { __index = Super } ) flickerstreak@223: flickerstreak@134: ReAction.Button.Stance = Stance flickerstreak@223: ReAction:RegisterBarType(Stance) flickerstreak@134: Flick@234: function Stance:New( config, bar, idx, idHint ) Flick@277: self = Super.New(self, config, bar, idx, "SecureActionButtonTemplate, ActionButtonTemplate" ) flickerstreak@134: flickerstreak@134: local f = self:GetFrame() flickerstreak@134: local barFrame = bar:GetFrame() flickerstreak@134: local config = self:GetConfig() flickerstreak@134: Flick@249: -- set up the stance ID Flick@249: config.stanceID = config.stanceID or idx flickerstreak@134: flickerstreak@134: -- attribute setup flickerstreak@134: f:SetAttribute("type","spell") flickerstreak@134: flickerstreak@134: -- non secure scripts flickerstreak@134: f:SetScript("OnEvent", function(frame, ...) self:OnEvent(...) end) flickerstreak@134: f:SetScript("OnEnter", function(frame) self:OnEnter() end) flickerstreak@134: f:SetScript("OnLeave", function(frame) self:OnLeave() end) flickerstreak@134: f:SetScript("PreClick", function(frame, ...) self:PreClick(...) end) flickerstreak@134: flickerstreak@134: -- secure handlers flickerstreak@134: -- (none) flickerstreak@134: flickerstreak@134: -- event registration flickerstreak@134: for _, evt in pairs(eventList) do flickerstreak@134: f:RegisterEvent(evt) flickerstreak@134: end flickerstreak@134: flickerstreak@134: -- attach to skinner flickerstreak@134: bar:SkinButton(self) flickerstreak@134: flickerstreak@134: -- initial display flickerstreak@134: if ReAction:GetConfigMode() then flickerstreak@134: self:GetFrame():Show() flickerstreak@134: end flickerstreak@134: flickerstreak@134: self:Refresh() flickerstreak@134: flickerstreak@134: return self flickerstreak@134: end flickerstreak@134: flickerstreak@134: function Stance:GetActionID() flickerstreak@134: return self.config.stanceID flickerstreak@134: end flickerstreak@134: Flick@249: function Stance:AcquireActionID() Flick@249: -- don't use pool Flick@249: end Flick@249: Flick@249: function Stance:ReleaseActionID() Flick@249: -- don't use pool Flick@249: end Flick@249: flickerstreak@134: function Stance:UpdateAction() flickerstreak@134: if InCombatLockdown() then flickerstreak@134: self.updatePending = true flickerstreak@134: else flickerstreak@134: self.updatePending = false flickerstreak@134: local idx = self:GetActionID() flickerstreak@134: local f = self:GetFrame() flickerstreak@179: if idx > GetNumShapeshiftForms() then flickerstreak@134: f:Hide() flickerstreak@134: else flickerstreak@134: f:SetAttribute("spell", select(2,GetShapeshiftFormInfo(idx))) flickerstreak@134: f:Show() flickerstreak@134: self:Update() flickerstreak@134: end flickerstreak@134: end flickerstreak@134: end flickerstreak@134: flickerstreak@134: function Stance:Refresh() flickerstreak@134: Super.Refresh(self) flickerstreak@137: self:UpdateHotkey() flickerstreak@136: self:UpdateAction() flickerstreak@134: end flickerstreak@134: flickerstreak@134: function Stance:Update() flickerstreak@179: local texture, _, isActive, isCastable = GetShapeshiftFormInfo(self:GetActionID()) flickerstreak@134: flickerstreak@134: local icon = self.frames.icon flickerstreak@134: icon:SetTexture(texture) flickerstreak@134: self:GetFrame():SetChecked( isActive and 1 or 0 ) flickerstreak@134: if isCastable then flickerstreak@137: self.frames.hotkey:Show() flickerstreak@134: icon:SetVertexColor(1.0, 1.0, 1.0) flickerstreak@134: else flickerstreak@134: icon:SetVertexColor(0.4, 0.4, 0.4) flickerstreak@134: end flickerstreak@134: flickerstreak@134: self:UpdateCooldown() flickerstreak@134: end flickerstreak@134: flickerstreak@134: function Stance:UpdateCooldown() flickerstreak@179: local start, duration, enabled = GetShapeshiftFormCooldown(self:GetActionID()) flickerstreak@134: if start then flickerstreak@134: CooldownFrame_SetTimer(self.frames.cooldown, start, duration, enabled) flickerstreak@134: end flickerstreak@134: end flickerstreak@134: flickerstreak@134: function Stance:SetTooltip() flickerstreak@134: if GetCVar("UberTooltips") == "1" then flickerstreak@134: GameTooltip_SetDefaultAnchor(GameTooltip, self:GetFrame()) flickerstreak@134: else flickerstreak@134: GameTooltip:SetOwner(self:GetFrame(), "ANCHOR_RIGHT") flickerstreak@134: end flickerstreak@179: GameTooltip:SetShapeshift(self:GetActionID()) flickerstreak@134: end flickerstreak@134: flickerstreak@134: function Stance:OnEnter() flickerstreak@134: self:SetTooltip() flickerstreak@134: end flickerstreak@134: flickerstreak@134: function Stance:OnLeave() flickerstreak@134: GameTooltip:Hide() flickerstreak@134: end flickerstreak@134: flickerstreak@134: function Stance:PreClick() flickerstreak@134: local f = self:GetFrame() flickerstreak@134: f:SetChecked( not f:GetChecked() ) flickerstreak@134: end flickerstreak@134: flickerstreak@134: function Stance:OnEvent(event, arg) flickerstreak@134: if event == "PLAYER_REGEN_ENABLED" then flickerstreak@134: if self.updatePending then flickerstreak@134: self:UpdateAction() flickerstreak@134: end flickerstreak@134: elseif event == "UPDATE_SHAPESHIFT_COOLDOWN" then flickerstreak@134: self:UpdateCooldown() flickerstreak@179: elseif event == "UPDATE_SHAPESHIFT_FORMS" then flickerstreak@134: self:UpdateAction() flickerstreak@134: elseif event == "UNIT_AURA" then flickerstreak@134: if arg == "player" then flickerstreak@134: self:Update() flickerstreak@134: end flickerstreak@137: elseif event == "UPDATE_BINDINGS" then flickerstreak@137: self:UpdateHotkey() flickerstreak@134: else flickerstreak@134: self:Update() flickerstreak@134: end flickerstreak@134: end flickerstreak@134: flickerstreak@134: function Stance:ShowGridTemp(show) flickerstreak@134: if show then flickerstreak@134: self:GetFrame():Show() flickerstreak@134: else flickerstreak@134: self:UpdateAction() flickerstreak@134: end flickerstreak@134: end