flickerstreak@7: -- The ReAction.PetActionType mixin defines Pet action button functionality flickerstreak@7: -- and is an implementation of the ReAction.IActionType interface. flickerstreak@7: -- flickerstreak@7: -- The Mixin assumes that it is being mixed in with a ReAction-derived class flickerstreak@7: -- which implements the ReAction.IDisplay and ReAction.PetActionType.IDisplay interfaces. flickerstreak@7: flickerstreak@7: local AceOO = AceLibrary("AceOO-2.0") flickerstreak@7: flickerstreak@7: ReAction.PetActionType = AceOO.Mixin { flickerstreak@7: -- ReAction.IDisplay interface flickerstreak@7: "SetID", flickerstreak@7: "GetID", flickerstreak@7: "SetupAction", flickerstreak@7: "UpdateAction", flickerstreak@7: "PickupAction", flickerstreak@7: "PlaceAction", flickerstreak@7: "IsActionEmpty", flickerstreak@7: "UpdateTooltip", flickerstreak@7: flickerstreak@7: -- Event handlers flickerstreak@7: "PLAYER_ENTERING_WORLD", flickerstreak@7: "PLAYER_CONTROL_LOST", flickerstreak@7: "PLAYER_CONTROL_GAINED", flickerstreak@7: "PLAYER_FARSIGHT_FOCUS_CHANGED", flickerstreak@7: "UNIT_PET", flickerstreak@7: "UNIT_FLAGS", flickerstreak@7: "UNIT_AURA", flickerstreak@7: "PET_BAR_UPDATE", flickerstreak@7: "PET_BAR_UPDATE_COOLDOWN", flickerstreak@7: "PET_BAR_SHOWGRID", flickerstreak@7: "PET_BAR_HIDEGRID", flickerstreak@7: flickerstreak@7: -- Internal functions flickerstreak@7: "UpdateCooldown", flickerstreak@7: } flickerstreak@7: flickerstreak@7: local RAPAT = ReAction.PetActionType flickerstreak@7: flickerstreak@7: -- Required display elements flickerstreak@7: RAPAT.IDisplay = AceOO.Interface { flickerstreak@7: DisplayAutoCast = "function", -- DisplayAutoCast(bool) flickerstreak@7: DisplayAutoCastable = "function", -- DisplayAutoCastable(bool) flickerstreak@7: DisplayIcon = "function", -- DisplayIcon(texture), Display the icon texture (nil for empty slot) flickerstreak@7: DisplayCooldown = "function", -- DisplayCooldown(start, duration, enable), display cooldown timer flickerstreak@7: DisplayInUse = "function", -- DisplayInUse(bool), display whether the action is in use flickerstreak@7: DisplayUsable = "function", -- DisplayUsable(bool), display whether the action can be used now flickerstreak@7: } flickerstreak@7: flickerstreak@7: flickerstreak@7: -- private constants flickerstreak@7: local actionIDColor = { r=1.00, g=0.82, b=0.00, a=1.00 } -- gold 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: -- ReAction.IActionType interface implementation flickerstreak@7: --------------------------------------- flickerstreak@7: function RAPAT:SetID( id ) -- paging not supported flickerstreak@7: id = tonumber(id) -- force data integrity flickerstreak@7: if id then flickerstreak@7: local f = self:GetActionFrame() flickerstreak@7: f:SetAttribute("action",id) flickerstreak@7: -- the following is the goofy hack to work around Blizzard not exporting the pet functions securely flickerstreak@7: f:SetAttribute("clickbutton2",getglobal("PetActionButton"..id)) flickerstreak@7: end flickerstreak@7: end flickerstreak@7: flickerstreak@7: function RAPAT:GetID() flickerstreak@7: return SecureButton_GetModifiedAttribute(self:GetActionFrame(), "action", button) flickerstreak@7: end flickerstreak@7: flickerstreak@7: function RAPAT:SetupAction() flickerstreak@7: local b = self:GetActionFrame() flickerstreak@7: -- Blizzard didn't support TogglePetAutocast functionality in flickerstreak@7: -- SecureButton_OnClick(), so we have to spoof it flickerstreak@7: -- by delegating right-clicks to the hidden default action buttons flickerstreak@7: b:SetAttribute("type", "pet") flickerstreak@7: b:SetAttribute("type2", "click") flickerstreak@7: flickerstreak@7: -- shift-clicking to drag locked buttons off flickerstreak@7: b:SetAttribute("checkselfcast", true) flickerstreak@7: b:SetAttribute("useparent-unit", true) flickerstreak@7: flickerstreak@7: self:RegisterEvent("PLAYER_ENTERING_WORLD") flickerstreak@7: self:RegisterEvent("PLAYER_CONTROL_LOST"); flickerstreak@7: self:RegisterEvent("PLAYER_CONTROL_GAINED"); flickerstreak@7: self:RegisterEvent("PLAYER_FARSIGHT_FOCUS_CHANGED"); flickerstreak@7: self:RegisterEvent("UNIT_PET"); flickerstreak@7: self:RegisterEvent("UNIT_FLAGS"); flickerstreak@7: self:RegisterEvent("UNIT_AURA"); flickerstreak@7: self:RegisterEvent("PET_BAR_UPDATE"); flickerstreak@7: self:RegisterEvent("PET_BAR_UPDATE_COOLDOWN"); flickerstreak@7: self:RegisterEvent("PET_BAR_SHOWGRID"); flickerstreak@7: self:RegisterEvent("PET_BAR_HIDEGRID"); flickerstreak@7: flickerstreak@7: self:UpdateAction() flickerstreak@7: end flickerstreak@7: flickerstreak@7: function RAPAT:UpdateAction() flickerstreak@7: local id = self:GetID() flickerstreak@7: if id then flickerstreak@7: local name, subtext, texture, isToken, isActive, autoCastAllowed, autoCastEnabled = GetPetActionInfo(id); flickerstreak@7: self:DisplayIcon( isToken and getglobal(texture) or texture ) flickerstreak@7: self:DisplayInUse( isActive ) flickerstreak@7: self:DisplayAutoCastable( autoCastAllowed ) flickerstreak@7: self:DisplayAutoCast( autoCastEnabled ) flickerstreak@7: self:DisplayCooldown( GetPetActionCooldown(id) ) flickerstreak@7: self:DisplayUsable(GetPetActionsUsable()) flickerstreak@7: -- If it's a 'token' save away the tooltip name for updateTooltip flickerstreak@7: self.isToken = isToken flickerstreak@7: if isToken then flickerstreak@7: self.tooltipName = getglobal(name) flickerstreak@7: self.tooltipSubtext = subtext flickerstreak@7: end flickerstreak@7: end flickerstreak@7: end flickerstreak@7: flickerstreak@7: function RAPAT:PickupAction() flickerstreak@7: PickupPetAction(self:GetID()) flickerstreak@7: self:UpdateAction() flickerstreak@7: end flickerstreak@7: flickerstreak@7: function RAPAT:PlaceAction() flickerstreak@7: if not InCombatLockdown() then flickerstreak@7: PlacePetAction(self:GetID()) flickerstreak@7: end flickerstreak@7: self:UpdateAction() flickerstreak@7: end flickerstreak@7: flickerstreak@7: function RAPAT:IsActionEmpty() flickerstreak@7: local id = self:GetID() flickerstreak@7: return not(id and GetPetActionInfo(id)) flickerstreak@7: end flickerstreak@7: flickerstreak@7: function RAPAT:UpdateTooltip() flickerstreak@7: local id = self:GetID() flickerstreak@7: if GameTooltip:IsOwned(self:GetActionFrame()) and id then flickerstreak@7: if self.isToken then flickerstreak@7: GameTooltip:SetText(self.tooltipName, 1.0, 1.0, 1.0) flickerstreak@7: if ( self.tooltipSubtext ) then flickerstreak@7: GameTooltip:AddLine(self.tooltipSubtext, "", 0.5, 0.5, 0.5); flickerstreak@7: end flickerstreak@7: GameTooltip:Show(); flickerstreak@7: else flickerstreak@7: if GameTooltip:SetPetAction(id) then flickerstreak@7: self.tooltipTime = TOOLTIP_UPDATE_TIME flickerstreak@7: end flickerstreak@7: end flickerstreak@7: else flickerstreak@7: self.tooltipTime = nil flickerstreak@7: end flickerstreak@7: end flickerstreak@7: flickerstreak@7: flickerstreak@7: ----------------------------- flickerstreak@7: -- Event Handling flickerstreak@7: ----------------------------- flickerstreak@7: function RAPAT:PLAYER_ENTERING_WORLD() flickerstreak@7: self:UpdateAction() flickerstreak@7: end flickerstreak@7: flickerstreak@7: function RAPAT:PLAYER_CONTROL_LOST() flickerstreak@7: self:UpdateAction() flickerstreak@7: end flickerstreak@7: flickerstreak@7: function RAPAT:PLAYER_CONTROL_GAINED() flickerstreak@7: self:UpdateAction() flickerstreak@7: end flickerstreak@7: flickerstreak@7: function RAPAT:PLAYER_FARSIGHT_FOCUS_CHANGED() flickerstreak@7: self:UpdateAction() flickerstreak@7: end flickerstreak@7: flickerstreak@7: function RAPAT:UNIT_PET(unit) flickerstreak@7: if unit == "player" then flickerstreak@7: self:UpdateAction() flickerstreak@7: end flickerstreak@7: end flickerstreak@7: flickerstreak@7: function RAPAT:UNIT_FLAGS(unit) flickerstreak@7: if unit == "pet" then flickerstreak@7: self:UpdateAction() flickerstreak@7: end flickerstreak@7: end flickerstreak@7: flickerstreak@7: function RAPAT:UNIT_AURA(unit) flickerstreak@7: if unit == "pet" then flickerstreak@7: self:UpdateAction() flickerstreak@7: end flickerstreak@7: end flickerstreak@7: flickerstreak@7: function RAPAT:PET_BAR_UPDATE() flickerstreak@7: self:UpdateAction() flickerstreak@7: end flickerstreak@7: flickerstreak@7: function RAPAT:PET_BAR_UPDATE_COOLDOWN() flickerstreak@7: self:UpdateCooldown() flickerstreak@7: end flickerstreak@7: flickerstreak@7: function RAPAT:PET_BAR_SHOWGRID() flickerstreak@7: self:TempShow(true) flickerstreak@7: end flickerstreak@7: flickerstreak@7: function RAPAT:PET_BAR_HIDEGRID() flickerstreak@7: self:TempShow(false) flickerstreak@7: end flickerstreak@7: flickerstreak@7: flickerstreak@7: ------------------------------------- flickerstreak@7: -- Internal functions flickerstreak@7: ------------------------------------- flickerstreak@7: function RAPAT:UpdateCooldown() flickerstreak@7: local id = self:GetID() flickerstreak@7: if id then flickerstreak@7: self:DisplayCooldown( GetPetActionCooldown(id) ) flickerstreak@7: end flickerstreak@7: end