flickerstreak@7: -- The ReAction.PetActionDisplay mixin defines 'regular' action button display functionality flickerstreak@7: -- and is an implementation of the ReAction.IDisplay and ReAction.ActionType.IDisplay interfaces. flickerstreak@7: -- flickerstreak@7: -- This Mixin assumes that it has been mixed in with a ReAction-derived class which implements flickerstreak@7: -- the ReAction.IActionType and ReAction.IColorScheme interfaces. flickerstreak@7: -- flickerstreak@7: -- This mixin uses properties of self.config to define display elements: flickerstreak@7: -- flickerstreak@7: -- self.config = { flickerstreak@7: -- keyBindLoc = "POSITION", -- keybind anchor location flickerstreak@7: -- showKeyBind = true/false, -- show keybind labels flickerstreak@7: -- showGrid = true/false, -- always show empty buttons flickerstreak@7: -- } flickerstreak@7: -- flickerstreak@7: flickerstreak@7: local AceOO = AceLibrary("AceOO-2.0") flickerstreak@7: flickerstreak@7: ReAction.PetActionDisplay = AceOO.Mixin { flickerstreak@7: -- ReAction.IDisplay interface flickerstreak@7: "SetupDisplay", flickerstreak@7: "UpdateDisplay", flickerstreak@7: "TempShow", flickerstreak@7: "GetActionFrame", flickerstreak@7: "GetBaseButtonSize", flickerstreak@7: "DisplayID", flickerstreak@7: "DisplayHotkey", flickerstreak@7: flickerstreak@7: -- ReAction.PetActionType.IDisplay interface flickerstreak@7: "DisplayAutoCast", flickerstreak@7: "DisplayAutoCastable", flickerstreak@7: "DisplayInUse", flickerstreak@7: "DisplayUsable", flickerstreak@7: "DisplayIcon", flickerstreak@7: "DisplayCooldown", flickerstreak@7: flickerstreak@7: -- Event handlers flickerstreak@7: "PreClick", flickerstreak@7: "PostClick", flickerstreak@7: "OnDragStart", flickerstreak@7: "OnReceiveDrag", flickerstreak@7: "OnEnter", flickerstreak@7: "OnLeave", flickerstreak@7: flickerstreak@7: -- internal functions flickerstreak@7: "ApplyLayout", flickerstreak@7: "ApplyStyle", flickerstreak@7: "DisplayVisibility", flickerstreak@7: } flickerstreak@7: flickerstreak@7: local RAPAD = ReAction.PetActionDisplay flickerstreak@7: flickerstreak@7: flickerstreak@7: -- private constants flickerstreak@7: local _G = getfenv(0) flickerstreak@7: flickerstreak@7: local actionIDColor = { r=1.00, g=0.82, b=0.00, a=1.00 } -- gold flickerstreak@7: flickerstreak@7: flickerstreak@7: -- private functions flickerstreak@7: -- extract and return color fields from a table, to be fed into SetVertexColor()/SetTextColor() flickerstreak@7: local function tcolor(c) flickerstreak@7: return c.r, c.g, c.b, c.a flickerstreak@7: end flickerstreak@7: flickerstreak@7: flickerstreak@7: ----------------------------------- flickerstreak@7: -- Interface Implementation Methods flickerstreak@7: ----------------------------------- flickerstreak@7: function RAPAD:SetupDisplay( name ) flickerstreak@7: -- create the button widget flickerstreak@7: local b = CreateFrame("CheckButton", name, nil, "ActionButtonTemplate, SecureActionButtonTemplate") flickerstreak@7: b:EnableMouse() flickerstreak@7: b:RegisterForDrag("LeftButton", "RightButton") flickerstreak@7: b:RegisterForClicks("AnyUp") flickerstreak@7: b:SetScript("PreClick", function(arg1) self:PreClick(arg1) end) flickerstreak@7: b:SetScript("PostClick", function(arg1) self:PostClick(arg1) end) flickerstreak@7: b:SetScript("OnDragStart", function(arg1) self:OnDragStart(arg1) end) flickerstreak@7: b:SetScript("OnReceiveDrag", function() self:OnReceiveDrag() end) flickerstreak@7: b:SetScript("OnEnter", function() self:OnEnter() end) flickerstreak@7: b:SetScript("OnLeave", function() self:OnLeave() end) flickerstreak@7: flickerstreak@7: flickerstreak@7: b:SetWidth(30) flickerstreak@7: b:SetHeight(30) flickerstreak@7: flickerstreak@7: local tx = b:GetNormalTexture() flickerstreak@7: tx:ClearAllPoints() flickerstreak@7: tx:SetWidth(54) flickerstreak@7: tx:SetHeight(54) flickerstreak@7: tx:SetPoint("CENTER",0,-1) flickerstreak@7: flickerstreak@7: local autoCastable = b:CreateTexture(nil, "OVERLAY") flickerstreak@7: autoCastable:SetTexture("Interface\\Buttons\\UI-AutoCastableOverlay") flickerstreak@7: autoCastable:SetWidth(58) flickerstreak@7: autoCastable:SetHeight(58) flickerstreak@7: autoCastable:SetPoint("CENTER") flickerstreak@7: autoCastable:Hide() flickerstreak@7: flickerstreak@7: local autoCast = CreateFrame("Model",nil,b) flickerstreak@7: autoCast:SetModel("Interface\\Buttons\\UI-AutoCastButton.mdx") flickerstreak@7: autoCast:SetScale(1.2) flickerstreak@7: autoCast:SetAllPoints() flickerstreak@7: autoCast:SetSequence(0) flickerstreak@7: autoCast:SetSequenceTime(0,0) flickerstreak@7: autoCast:SetFrameStrata("HIGH") -- Otherwise it won't appear on top of the icon for some reason flickerstreak@7: autoCast:Hide() flickerstreak@7: flickerstreak@7: flickerstreak@7: local cd = _G[name.."Cooldown"] flickerstreak@7: cd:SetScale(1); flickerstreak@7: cd:ClearAllPoints(); flickerstreak@7: cd:SetWidth(33); flickerstreak@7: cd:SetHeight(33); flickerstreak@7: cd:SetPoint("CENTER", -2, -1); flickerstreak@7: flickerstreak@7: -- store references to the various sub-frames of ActionButtonTemplate so we don't have to look it up all the time flickerstreak@7: self.frames = { flickerstreak@7: button = b, flickerstreak@7: autoCastable = autoCastable, --_G[name.."AutoCastable"], flickerstreak@7: autoCast = autoCast, --_G[name.."AutoCast"], flickerstreak@7: hotkey = _G[name.."HotKey"], flickerstreak@7: cooldown = cd, flickerstreak@7: icon = _G[name.."Icon"], flickerstreak@7: normalTexture = tx, --_G[name.."NormalTexture2"], flickerstreak@7: actionID = nil, -- defer creating actionID font string until it's actually requested flickerstreak@7: } flickerstreak@7: flickerstreak@7: self.tmpShow_ = 0 flickerstreak@7: end flickerstreak@7: flickerstreak@7: function RAPAD:UpdateDisplay() flickerstreak@7: self:ApplyLayout() flickerstreak@7: self:ApplyStyle() flickerstreak@7: self:DisplayVisibility() flickerstreak@7: -- refresh the action ID display flickerstreak@7: if ReAction.showIDs_ then flickerstreak@8: self:DisplayID(true) flickerstreak@7: end flickerstreak@7: end flickerstreak@7: flickerstreak@7: function RAPAD:TempShow( visible ) flickerstreak@7: visible = visible and true or false -- force data integrity flickerstreak@7: self.showTmp_ = max(0, (self.showTmp_ or 0) + (visible and 1 or -1)) flickerstreak@7: self:DisplayVisibility() flickerstreak@7: end flickerstreak@7: flickerstreak@7: function RAPAD:GetActionFrame() flickerstreak@7: return self.frames.button flickerstreak@7: end flickerstreak@7: flickerstreak@7: function RAPAD:GetBaseButtonSize() flickerstreak@7: return 30 flickerstreak@7: end flickerstreak@7: flickerstreak@8: function RAPAD:DisplayID( show ) flickerstreak@7: local f = self.frames.actionID flickerstreak@8: if show then flickerstreak@7: if not f then flickerstreak@7: -- create the actionID label flickerstreak@7: f = self.frames.button:CreateFontString(nil,"ARTWORK","NumberFontNormalSmall") flickerstreak@7: f:SetPoint("BOTTOMLEFT") flickerstreak@7: f:SetTextColor( tcolor(actionIDColor) ) flickerstreak@7: self.frames.actionID = f flickerstreak@7: end flickerstreak@8: f:SetText(tostring(self:GetID())) flickerstreak@7: f:Show() flickerstreak@7: elseif f then flickerstreak@7: f:Hide() flickerstreak@7: end flickerstreak@7: end flickerstreak@7: flickerstreak@7: function RAPAD:DisplayHotkey(txt) flickerstreak@7: self.frames.hotkey:SetText(string.upper(txt or "")) flickerstreak@7: end flickerstreak@7: flickerstreak@7: function RAPAD:DisplayInUse( inUse ) flickerstreak@7: self.frames.button:SetChecked( inUse and 1 or 0 ) flickerstreak@7: end flickerstreak@7: flickerstreak@7: function RAPAD:DisplayUsable( usable ) flickerstreak@7: SetDesaturation(self.frames.icon, (not usable) and 1 or nil) -- argument is backward flickerstreak@7: self.frames.hotkey:SetTextColor(self:GetHotkeyColor(usable, false, false, self.frames.hotkey:GetText()) ) flickerstreak@7: end flickerstreak@7: flickerstreak@7: function RAPAD:DisplayAutoCast( show ) flickerstreak@7: if show then flickerstreak@7: self.frames.autoCast:Show() flickerstreak@7: else flickerstreak@7: self.frames.autoCast:Hide() flickerstreak@7: end flickerstreak@7: end flickerstreak@7: flickerstreak@7: function RAPAD:DisplayAutoCastable( show ) flickerstreak@7: if show then flickerstreak@7: self.frames.autoCastable:Show() flickerstreak@7: else flickerstreak@7: self.frames.autoCastable:Hide() flickerstreak@7: end flickerstreak@7: end flickerstreak@7: flickerstreak@7: function RAPAD:DisplayIcon( texture ) flickerstreak@7: local f = self.frames.button flickerstreak@7: local icon = self.frames.icon flickerstreak@7: if texture then flickerstreak@7: icon:SetTexture(texture) flickerstreak@7: icon:Show() flickerstreak@7: f:SetNormalTexture("Interface\\Buttons\\UI-Quickslot2") flickerstreak@7: else flickerstreak@7: f:SetScript("OnUpdate",nil) flickerstreak@7: icon:Hide() flickerstreak@7: f:SetNormalTexture("Interface\\Buttons\\UI-Quickslot") flickerstreak@7: end flickerstreak@7: self:DisplayVisibility() flickerstreak@7: end flickerstreak@7: flickerstreak@7: function RAPAD:DisplayCooldown( start, duration, enable ) flickerstreak@7: CooldownFrame_SetTimer(self.frames.cooldown, start, duration, enable) flickerstreak@7: end flickerstreak@7: flickerstreak@7: flickerstreak@7: flickerstreak@7: flickerstreak@7: flickerstreak@7: flickerstreak@7: ---------------------- flickerstreak@7: -- Event Handlers flickerstreak@7: ---------------------- flickerstreak@7: function RAPAD:PreClick() flickerstreak@7: -- not sure why we have to do this flickerstreak@7: self.frames.button:SetChecked(0) flickerstreak@7: end flickerstreak@7: flickerstreak@7: function RAPAD:PostClick() flickerstreak@7: self:UpdateAction() flickerstreak@7: end flickerstreak@7: flickerstreak@7: function RAPAD:OnDragStart() flickerstreak@7: if LOCK_ACTIONBAR ~= "1" or IsShiftKeyDown() then flickerstreak@7: self:PickupAction() flickerstreak@7: end flickerstreak@7: end flickerstreak@7: flickerstreak@7: function RAPAD:OnReceiveDrag() flickerstreak@7: self:PlaceAction() flickerstreak@7: end flickerstreak@7: flickerstreak@7: function RAPAD:OnEnter() flickerstreak@7: self:SetTooltip() -- from ReAction base class flickerstreak@7: end flickerstreak@7: flickerstreak@7: function RAPAD:OnLeave() flickerstreak@7: self:ClearTooltip() -- from ReAction base class flickerstreak@7: end flickerstreak@7: flickerstreak@7: flickerstreak@7: flickerstreak@7: ---------------------- flickerstreak@7: -- Internal methods flickerstreak@7: ---------------------- flickerstreak@7: flickerstreak@7: local function placeLabel( label, anchor ) flickerstreak@7: local top = string.match(anchor,"TOP") flickerstreak@7: local bottom = string.match(anchor, "BOTTOM") flickerstreak@7: label:ClearAllPoints() flickerstreak@7: label:SetWidth(40) flickerstreak@7: label:SetPoint(top or bottom,0,top and 2 or -2) flickerstreak@7: local j flickerstreak@7: if string.match(anchor,"LEFT") then flickerstreak@7: j = "LEFT" flickerstreak@7: elseif string.match(anchor,"RIGHT") then flickerstreak@7: j = "RIGHT" flickerstreak@7: else flickerstreak@7: j = "CENTER" flickerstreak@7: end flickerstreak@7: label:SetJustifyH(j) flickerstreak@7: end flickerstreak@7: flickerstreak@7: flickerstreak@7: function RAPAD:ApplyLayout() flickerstreak@7: local f = self.frames flickerstreak@7: flickerstreak@7: if self.config.keyBindLoc then flickerstreak@7: placeLabel(f.hotkey, self.config.keyBindLoc) flickerstreak@7: end flickerstreak@7: flickerstreak@7: if self.config.showKeyBind then flickerstreak@7: f.hotkey:Show() flickerstreak@7: else flickerstreak@7: f.hotkey:Hide() flickerstreak@7: end flickerstreak@7: flickerstreak@7: if self.config.showBorder then flickerstreak@7: f.normalTexture:SetAlpha(1) flickerstreak@7: else flickerstreak@7: f.normalTexture:SetAlpha(0) flickerstreak@7: end flickerstreak@7: end flickerstreak@7: flickerstreak@7: function RAPAD:ApplyStyle() flickerstreak@7: flickerstreak@7: end flickerstreak@7: flickerstreak@7: function RAPAD:DisplayVisibility() flickerstreak@7: local b = self.frames.button flickerstreak@7: flickerstreak@7: -- can't hide/show in combat flickerstreak@7: if not InCombatLockdown() then flickerstreak@7: if b:GetAttribute("statehidden") then flickerstreak@7: b:Hide() flickerstreak@7: elseif not self:IsActionEmpty() then flickerstreak@7: b:GetNormalTexture():SetAlpha(1.0) flickerstreak@7: b:Show() flickerstreak@7: elseif self.showTmp_ and self.showTmp_ > 0 or self.config.showGrid then flickerstreak@7: b:GetNormalTexture():SetAlpha(0.5) flickerstreak@7: self.frames.cooldown:Hide() flickerstreak@7: b:Show() flickerstreak@7: else flickerstreak@7: b:Hide() flickerstreak@7: end flickerstreak@7: end flickerstreak@7: end flickerstreak@7: