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