annotate classes/ReAction_PetActionType.lua @ 9:650f75d08952

Version 0.32
author Flick <flickerstreak@gmail.com>
date Tue, 20 Mar 2007 21:35:57 +0000
parents f920db5fc6b1
children 0ea4c8ab1991
rev   line source
flickerstreak@7 1 -- The ReAction.PetActionType mixin defines Pet action button functionality
flickerstreak@7 2 -- and is an implementation of the ReAction.IActionType interface.
flickerstreak@7 3 --
flickerstreak@7 4 -- The Mixin assumes that it is being mixed in with a ReAction-derived class
flickerstreak@7 5 -- which implements the ReAction.IDisplay and ReAction.PetActionType.IDisplay interfaces.
flickerstreak@7 6
flickerstreak@7 7 local AceOO = AceLibrary("AceOO-2.0")
flickerstreak@7 8
flickerstreak@7 9 ReAction.PetActionType = AceOO.Mixin {
flickerstreak@7 10 -- ReAction.IDisplay interface
flickerstreak@7 11 "SetID",
flickerstreak@7 12 "GetID",
flickerstreak@7 13 "SetupAction",
flickerstreak@7 14 "UpdateAction",
flickerstreak@7 15 "PickupAction",
flickerstreak@7 16 "PlaceAction",
flickerstreak@7 17 "IsActionEmpty",
flickerstreak@7 18 "UpdateTooltip",
flickerstreak@7 19
flickerstreak@7 20 -- Event handlers
flickerstreak@7 21 "PLAYER_ENTERING_WORLD",
flickerstreak@7 22 "PLAYER_CONTROL_LOST",
flickerstreak@7 23 "PLAYER_CONTROL_GAINED",
flickerstreak@7 24 "PLAYER_FARSIGHT_FOCUS_CHANGED",
flickerstreak@7 25 "UNIT_PET",
flickerstreak@7 26 "UNIT_FLAGS",
flickerstreak@7 27 "UNIT_AURA",
flickerstreak@7 28 "PET_BAR_UPDATE",
flickerstreak@7 29 "PET_BAR_UPDATE_COOLDOWN",
flickerstreak@7 30 "PET_BAR_SHOWGRID",
flickerstreak@7 31 "PET_BAR_HIDEGRID",
flickerstreak@7 32
flickerstreak@7 33 -- Internal functions
flickerstreak@7 34 "UpdateCooldown",
flickerstreak@7 35 }
flickerstreak@7 36
flickerstreak@7 37 local RAPAT = ReAction.PetActionType
flickerstreak@7 38
flickerstreak@7 39 -- Required display elements
flickerstreak@7 40 RAPAT.IDisplay = AceOO.Interface {
flickerstreak@7 41 DisplayAutoCast = "function", -- DisplayAutoCast(bool)
flickerstreak@7 42 DisplayAutoCastable = "function", -- DisplayAutoCastable(bool)
flickerstreak@7 43 DisplayIcon = "function", -- DisplayIcon(texture), Display the icon texture (nil for empty slot)
flickerstreak@7 44 DisplayCooldown = "function", -- DisplayCooldown(start, duration, enable), display cooldown timer
flickerstreak@7 45 DisplayInUse = "function", -- DisplayInUse(bool), display whether the action is in use
flickerstreak@7 46 DisplayUsable = "function", -- DisplayUsable(bool), display whether the action can be used now
flickerstreak@7 47 }
flickerstreak@7 48
flickerstreak@7 49
flickerstreak@7 50 -- private constants
flickerstreak@7 51 local actionIDColor = { r=1.00, g=0.82, b=0.00, a=1.00 } -- gold
flickerstreak@7 52
flickerstreak@7 53 -- private functions
flickerstreak@7 54 -- extract and return color fields from a table, to be fed into SetVertexColor()/SetTextColor()
flickerstreak@7 55 local function tcolor(c)
flickerstreak@7 56 return c.r, c.g, c.b, c.a
flickerstreak@7 57 end
flickerstreak@7 58
flickerstreak@7 59 ---------------------------------------
flickerstreak@7 60 -- ReAction.IActionType interface implementation
flickerstreak@7 61 ---------------------------------------
flickerstreak@7 62 function RAPAT:SetID( id ) -- paging not supported
flickerstreak@7 63 id = tonumber(id) -- force data integrity
flickerstreak@7 64 if id then
flickerstreak@7 65 self.config.ids[self.barIdx] = { id }
flickerstreak@7 66 local f = self:GetActionFrame()
flickerstreak@7 67 f:SetAttribute("action",id)
flickerstreak@7 68 -- the following is the goofy hack to work around Blizzard not exporting the pet functions securely
flickerstreak@7 69 f:SetAttribute("clickbutton2",getglobal("PetActionButton"..id))
flickerstreak@7 70 end
flickerstreak@7 71 end
flickerstreak@7 72
flickerstreak@7 73 function RAPAT:GetID()
flickerstreak@7 74 return SecureButton_GetModifiedAttribute(self:GetActionFrame(), "action", button)
flickerstreak@7 75 end
flickerstreak@7 76
flickerstreak@7 77 function RAPAT:SetupAction()
flickerstreak@7 78 local b = self:GetActionFrame()
flickerstreak@7 79 -- Blizzard didn't support TogglePetAutocast functionality in
flickerstreak@7 80 -- SecureButton_OnClick(), so we have to spoof it
flickerstreak@7 81 -- by delegating right-clicks to the hidden default action buttons
flickerstreak@7 82 b:SetAttribute("type", "pet")
flickerstreak@7 83 b:SetAttribute("type2", "click")
flickerstreak@7 84
flickerstreak@7 85 -- shift-clicking to drag locked buttons off
flickerstreak@7 86 b:SetAttribute("checkselfcast", true)
flickerstreak@7 87 b:SetAttribute("useparent-unit", true)
flickerstreak@7 88
flickerstreak@7 89 self:RegisterEvent("PLAYER_ENTERING_WORLD")
flickerstreak@7 90 self:RegisterEvent("PLAYER_CONTROL_LOST");
flickerstreak@7 91 self:RegisterEvent("PLAYER_CONTROL_GAINED");
flickerstreak@7 92 self:RegisterEvent("PLAYER_FARSIGHT_FOCUS_CHANGED");
flickerstreak@7 93 self:RegisterEvent("UNIT_PET");
flickerstreak@7 94 self:RegisterEvent("UNIT_FLAGS");
flickerstreak@7 95 self:RegisterEvent("UNIT_AURA");
flickerstreak@7 96 self:RegisterEvent("PET_BAR_UPDATE");
flickerstreak@7 97 self:RegisterEvent("PET_BAR_UPDATE_COOLDOWN");
flickerstreak@7 98 self:RegisterEvent("PET_BAR_SHOWGRID");
flickerstreak@7 99 self:RegisterEvent("PET_BAR_HIDEGRID");
flickerstreak@7 100
flickerstreak@7 101 self:UpdateAction()
flickerstreak@7 102 end
flickerstreak@7 103
flickerstreak@7 104 function RAPAT:UpdateAction()
flickerstreak@7 105 local id = self:GetID()
flickerstreak@7 106 if id then
flickerstreak@7 107 local name, subtext, texture, isToken, isActive, autoCastAllowed, autoCastEnabled = GetPetActionInfo(id);
flickerstreak@7 108 self:DisplayIcon( isToken and getglobal(texture) or texture )
flickerstreak@7 109 self:DisplayInUse( isActive )
flickerstreak@7 110 self:DisplayAutoCastable( autoCastAllowed )
flickerstreak@7 111 self:DisplayAutoCast( autoCastEnabled )
flickerstreak@7 112 self:DisplayCooldown( GetPetActionCooldown(id) )
flickerstreak@7 113 self:DisplayUsable(GetPetActionsUsable())
flickerstreak@7 114 -- If it's a 'token' save away the tooltip name for updateTooltip
flickerstreak@7 115 self.isToken = isToken
flickerstreak@7 116 if isToken then
flickerstreak@7 117 self.tooltipName = getglobal(name)
flickerstreak@7 118 self.tooltipSubtext = subtext
flickerstreak@7 119 end
flickerstreak@7 120 end
flickerstreak@7 121 end
flickerstreak@7 122
flickerstreak@7 123 function RAPAT:PickupAction()
flickerstreak@7 124 PickupPetAction(self:GetID())
flickerstreak@7 125 self:UpdateAction()
flickerstreak@7 126 end
flickerstreak@7 127
flickerstreak@7 128 function RAPAT:PlaceAction()
flickerstreak@7 129 if not InCombatLockdown() then
flickerstreak@7 130 PlacePetAction(self:GetID())
flickerstreak@7 131 end
flickerstreak@7 132 self:UpdateAction()
flickerstreak@7 133 end
flickerstreak@7 134
flickerstreak@7 135 function RAPAT:IsActionEmpty()
flickerstreak@7 136 local id = self:GetID()
flickerstreak@7 137 return not(id and GetPetActionInfo(id))
flickerstreak@7 138 end
flickerstreak@7 139
flickerstreak@7 140 function RAPAT:UpdateTooltip()
flickerstreak@7 141 local id = self:GetID()
flickerstreak@7 142 if GameTooltip:IsOwned(self:GetActionFrame()) and id then
flickerstreak@7 143 if self.isToken then
flickerstreak@7 144 GameTooltip:SetText(self.tooltipName, 1.0, 1.0, 1.0)
flickerstreak@7 145 if ( self.tooltipSubtext ) then
flickerstreak@7 146 GameTooltip:AddLine(self.tooltipSubtext, "", 0.5, 0.5, 0.5);
flickerstreak@7 147 end
flickerstreak@7 148 GameTooltip:Show();
flickerstreak@7 149 else
flickerstreak@7 150 if GameTooltip:SetPetAction(id) then
flickerstreak@7 151 self.tooltipTime = TOOLTIP_UPDATE_TIME
flickerstreak@7 152 end
flickerstreak@7 153 end
flickerstreak@7 154 else
flickerstreak@7 155 self.tooltipTime = nil
flickerstreak@7 156 end
flickerstreak@7 157 end
flickerstreak@7 158
flickerstreak@7 159
flickerstreak@7 160 -----------------------------
flickerstreak@7 161 -- Event Handling
flickerstreak@7 162 -----------------------------
flickerstreak@7 163 function RAPAT:PLAYER_ENTERING_WORLD()
flickerstreak@7 164 self:UpdateAction()
flickerstreak@7 165 end
flickerstreak@7 166
flickerstreak@7 167 function RAPAT:PLAYER_CONTROL_LOST()
flickerstreak@7 168 self:UpdateAction()
flickerstreak@7 169 end
flickerstreak@7 170
flickerstreak@7 171 function RAPAT:PLAYER_CONTROL_GAINED()
flickerstreak@7 172 self:UpdateAction()
flickerstreak@7 173 end
flickerstreak@7 174
flickerstreak@7 175 function RAPAT:PLAYER_FARSIGHT_FOCUS_CHANGED()
flickerstreak@7 176 self:UpdateAction()
flickerstreak@7 177 end
flickerstreak@7 178
flickerstreak@7 179 function RAPAT:UNIT_PET(unit)
flickerstreak@7 180 if unit == "player" then
flickerstreak@7 181 self:UpdateAction()
flickerstreak@7 182 end
flickerstreak@7 183 end
flickerstreak@7 184
flickerstreak@7 185 function RAPAT:UNIT_FLAGS(unit)
flickerstreak@7 186 if unit == "pet" then
flickerstreak@7 187 self:UpdateAction()
flickerstreak@7 188 end
flickerstreak@7 189 end
flickerstreak@7 190
flickerstreak@7 191 function RAPAT:UNIT_AURA(unit)
flickerstreak@7 192 if unit == "pet" then
flickerstreak@7 193 self:UpdateAction()
flickerstreak@7 194 end
flickerstreak@7 195 end
flickerstreak@7 196
flickerstreak@7 197 function RAPAT:PET_BAR_UPDATE()
flickerstreak@7 198 self:UpdateAction()
flickerstreak@7 199 end
flickerstreak@7 200
flickerstreak@7 201 function RAPAT:PET_BAR_UPDATE_COOLDOWN()
flickerstreak@7 202 self:UpdateCooldown()
flickerstreak@7 203 end
flickerstreak@7 204
flickerstreak@7 205 function RAPAT:PET_BAR_SHOWGRID()
flickerstreak@7 206 self:TempShow(true)
flickerstreak@7 207 end
flickerstreak@7 208
flickerstreak@7 209 function RAPAT:PET_BAR_HIDEGRID()
flickerstreak@7 210 self:TempShow(false)
flickerstreak@7 211 end
flickerstreak@7 212
flickerstreak@7 213
flickerstreak@7 214 -------------------------------------
flickerstreak@7 215 -- Internal functions
flickerstreak@7 216 -------------------------------------
flickerstreak@7 217 function RAPAT:UpdateCooldown()
flickerstreak@7 218 local id = self:GetID()
flickerstreak@7 219 if id then
flickerstreak@7 220 self:DisplayCooldown( GetPetActionCooldown(id) )
flickerstreak@7 221 end
flickerstreak@7 222 end