annotate classes/ReAction_PetActionType.lua @ 16:832aab6fed49

(none)
author Flick <flickerstreak@gmail.com>
date Thu, 22 Mar 2007 21:08:43 +0000
parents 0ea4c8ab1991
children
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 local f = self:GetActionFrame()
flickerstreak@7 66 f:SetAttribute("action",id)
flickerstreak@7 67 -- the following is the goofy hack to work around Blizzard not exporting the pet functions securely
flickerstreak@7 68 f:SetAttribute("clickbutton2",getglobal("PetActionButton"..id))
flickerstreak@7 69 end
flickerstreak@7 70 end
flickerstreak@7 71
flickerstreak@7 72 function RAPAT:GetID()
flickerstreak@7 73 return SecureButton_GetModifiedAttribute(self:GetActionFrame(), "action", button)
flickerstreak@7 74 end
flickerstreak@7 75
flickerstreak@7 76 function RAPAT:SetupAction()
flickerstreak@7 77 local b = self:GetActionFrame()
flickerstreak@7 78 -- Blizzard didn't support TogglePetAutocast functionality in
flickerstreak@7 79 -- SecureButton_OnClick(), so we have to spoof it
flickerstreak@7 80 -- by delegating right-clicks to the hidden default action buttons
flickerstreak@7 81 b:SetAttribute("type", "pet")
flickerstreak@7 82 b:SetAttribute("type2", "click")
flickerstreak@7 83
flickerstreak@7 84 -- shift-clicking to drag locked buttons off
flickerstreak@7 85 b:SetAttribute("checkselfcast", true)
flickerstreak@7 86 b:SetAttribute("useparent-unit", true)
flickerstreak@7 87
flickerstreak@7 88 self:RegisterEvent("PLAYER_ENTERING_WORLD")
flickerstreak@7 89 self:RegisterEvent("PLAYER_CONTROL_LOST");
flickerstreak@7 90 self:RegisterEvent("PLAYER_CONTROL_GAINED");
flickerstreak@7 91 self:RegisterEvent("PLAYER_FARSIGHT_FOCUS_CHANGED");
flickerstreak@7 92 self:RegisterEvent("UNIT_PET");
flickerstreak@7 93 self:RegisterEvent("UNIT_FLAGS");
flickerstreak@7 94 self:RegisterEvent("UNIT_AURA");
flickerstreak@7 95 self:RegisterEvent("PET_BAR_UPDATE");
flickerstreak@7 96 self:RegisterEvent("PET_BAR_UPDATE_COOLDOWN");
flickerstreak@7 97 self:RegisterEvent("PET_BAR_SHOWGRID");
flickerstreak@7 98 self:RegisterEvent("PET_BAR_HIDEGRID");
flickerstreak@7 99
flickerstreak@7 100 self:UpdateAction()
flickerstreak@7 101 end
flickerstreak@7 102
flickerstreak@7 103 function RAPAT:UpdateAction()
flickerstreak@7 104 local id = self:GetID()
flickerstreak@7 105 if id then
flickerstreak@7 106 local name, subtext, texture, isToken, isActive, autoCastAllowed, autoCastEnabled = GetPetActionInfo(id);
flickerstreak@7 107 self:DisplayIcon( isToken and getglobal(texture) or texture )
flickerstreak@7 108 self:DisplayInUse( isActive )
flickerstreak@7 109 self:DisplayAutoCastable( autoCastAllowed )
flickerstreak@7 110 self:DisplayAutoCast( autoCastEnabled )
flickerstreak@7 111 self:DisplayCooldown( GetPetActionCooldown(id) )
flickerstreak@7 112 self:DisplayUsable(GetPetActionsUsable())
flickerstreak@7 113 -- If it's a 'token' save away the tooltip name for updateTooltip
flickerstreak@7 114 self.isToken = isToken
flickerstreak@7 115 if isToken then
flickerstreak@7 116 self.tooltipName = getglobal(name)
flickerstreak@7 117 self.tooltipSubtext = subtext
flickerstreak@7 118 end
flickerstreak@7 119 end
flickerstreak@7 120 end
flickerstreak@7 121
flickerstreak@7 122 function RAPAT:PickupAction()
flickerstreak@7 123 PickupPetAction(self:GetID())
flickerstreak@7 124 self:UpdateAction()
flickerstreak@7 125 end
flickerstreak@7 126
flickerstreak@7 127 function RAPAT:PlaceAction()
flickerstreak@7 128 if not InCombatLockdown() then
flickerstreak@7 129 PlacePetAction(self:GetID())
flickerstreak@7 130 end
flickerstreak@7 131 self:UpdateAction()
flickerstreak@7 132 end
flickerstreak@7 133
flickerstreak@7 134 function RAPAT:IsActionEmpty()
flickerstreak@7 135 local id = self:GetID()
flickerstreak@7 136 return not(id and GetPetActionInfo(id))
flickerstreak@7 137 end
flickerstreak@7 138
flickerstreak@7 139 function RAPAT:UpdateTooltip()
flickerstreak@7 140 local id = self:GetID()
flickerstreak@7 141 if GameTooltip:IsOwned(self:GetActionFrame()) and id then
flickerstreak@7 142 if self.isToken then
flickerstreak@7 143 GameTooltip:SetText(self.tooltipName, 1.0, 1.0, 1.0)
flickerstreak@7 144 if ( self.tooltipSubtext ) then
flickerstreak@7 145 GameTooltip:AddLine(self.tooltipSubtext, "", 0.5, 0.5, 0.5);
flickerstreak@7 146 end
flickerstreak@7 147 GameTooltip:Show();
flickerstreak@7 148 else
flickerstreak@7 149 if GameTooltip:SetPetAction(id) then
flickerstreak@7 150 self.tooltipTime = TOOLTIP_UPDATE_TIME
flickerstreak@7 151 end
flickerstreak@7 152 end
flickerstreak@7 153 else
flickerstreak@7 154 self.tooltipTime = nil
flickerstreak@7 155 end
flickerstreak@7 156 end
flickerstreak@7 157
flickerstreak@7 158
flickerstreak@7 159 -----------------------------
flickerstreak@7 160 -- Event Handling
flickerstreak@7 161 -----------------------------
flickerstreak@7 162 function RAPAT:PLAYER_ENTERING_WORLD()
flickerstreak@7 163 self:UpdateAction()
flickerstreak@7 164 end
flickerstreak@7 165
flickerstreak@7 166 function RAPAT:PLAYER_CONTROL_LOST()
flickerstreak@7 167 self:UpdateAction()
flickerstreak@7 168 end
flickerstreak@7 169
flickerstreak@7 170 function RAPAT:PLAYER_CONTROL_GAINED()
flickerstreak@7 171 self:UpdateAction()
flickerstreak@7 172 end
flickerstreak@7 173
flickerstreak@7 174 function RAPAT:PLAYER_FARSIGHT_FOCUS_CHANGED()
flickerstreak@7 175 self:UpdateAction()
flickerstreak@7 176 end
flickerstreak@7 177
flickerstreak@7 178 function RAPAT:UNIT_PET(unit)
flickerstreak@7 179 if unit == "player" then
flickerstreak@7 180 self:UpdateAction()
flickerstreak@7 181 end
flickerstreak@7 182 end
flickerstreak@7 183
flickerstreak@7 184 function RAPAT:UNIT_FLAGS(unit)
flickerstreak@7 185 if unit == "pet" then
flickerstreak@7 186 self:UpdateAction()
flickerstreak@7 187 end
flickerstreak@7 188 end
flickerstreak@7 189
flickerstreak@7 190 function RAPAT:UNIT_AURA(unit)
flickerstreak@7 191 if unit == "pet" then
flickerstreak@7 192 self:UpdateAction()
flickerstreak@7 193 end
flickerstreak@7 194 end
flickerstreak@7 195
flickerstreak@7 196 function RAPAT:PET_BAR_UPDATE()
flickerstreak@7 197 self:UpdateAction()
flickerstreak@7 198 end
flickerstreak@7 199
flickerstreak@7 200 function RAPAT:PET_BAR_UPDATE_COOLDOWN()
flickerstreak@7 201 self:UpdateCooldown()
flickerstreak@7 202 end
flickerstreak@7 203
flickerstreak@7 204 function RAPAT:PET_BAR_SHOWGRID()
flickerstreak@7 205 self:TempShow(true)
flickerstreak@7 206 end
flickerstreak@7 207
flickerstreak@7 208 function RAPAT:PET_BAR_HIDEGRID()
flickerstreak@7 209 self:TempShow(false)
flickerstreak@7 210 end
flickerstreak@7 211
flickerstreak@7 212
flickerstreak@7 213 -------------------------------------
flickerstreak@7 214 -- Internal functions
flickerstreak@7 215 -------------------------------------
flickerstreak@7 216 function RAPAT:UpdateCooldown()
flickerstreak@7 217 local id = self:GetID()
flickerstreak@7 218 if id then
flickerstreak@7 219 self:DisplayCooldown( GetPetActionCooldown(id) )
flickerstreak@7 220 end
flickerstreak@7 221 end