Mercurial > wow > reaction
comparison classes/StanceButton.lua @ 134:d186e041ca14
Added stance bar support
| author | Flick <flickerstreak@gmail.com> |
|---|---|
| date | Tue, 17 Mar 2009 23:38:38 +0000 |
| parents | |
| children | b8a14165b807 |
comparison
equal
deleted
inserted
replaced
| 133:729e284b2576 | 134:d186e041ca14 |
|---|---|
| 1 local ReAction = ReAction | |
| 2 local L = ReAction.L | |
| 3 local _G = _G | |
| 4 local CreateFrame = CreateFrame | |
| 5 local format = string.format | |
| 6 local GetCVar = GetCVar | |
| 7 local GameTooltip_SetDefaultAnchor = GameTooltip_SetDefaultAnchor | |
| 8 local CooldownFrame_SetTimer = CooldownFrame_SetTimer | |
| 9 local InCombatLockdown = InCombatLockdown | |
| 10 local GetNumShapeshiftForms = GetNumShapeshiftForms | |
| 11 local GetShapeshiftFormInfo = GetShapeshiftFormInfo | |
| 12 local IsUsableSpell = IsUsableSpell | |
| 13 local GetSpellInfo = GetSpellInfo | |
| 14 | |
| 15 ReAction:UpdateRevision("$Revision: 154 $") | |
| 16 | |
| 17 -- | |
| 18 -- private | |
| 19 -- | |
| 20 local playerClass = select(2,UnitClass("player")) | |
| 21 | |
| 22 local aspects = { | |
| 23 -- All rank one, so that the usable check works | |
| 24 GetSpellInfo(13163), -- monkey | |
| 25 GetSpellInfo(13165), -- hawk | |
| 26 GetSpellInfo(5118), -- cheetah | |
| 27 GetSpellInfo(34074), -- viper | |
| 28 GetSpellInfo(13161), -- beast | |
| 29 GetSpellInfo(13159), -- pack | |
| 30 GetSpellInfo(20043), -- wild | |
| 31 GetSpellInfo(61846), -- dragonhawk | |
| 32 } | |
| 33 | |
| 34 local aspectLinks = { } | |
| 35 | |
| 36 local eventList = { | |
| 37 "PLAYER_REGEN_ENABLED", | |
| 38 "PLAYER_ENTERING_WORLD", | |
| 39 "UPDATE_SHAPESHIFT_FORM", | |
| 40 "UPDATE_SHAPESHIFT_FORMS", | |
| 41 "UPDATE_SHAPESHIFT_USABLE", | |
| 42 "UPDATE_SHAPESHIFT_COOLDOWN", | |
| 43 -- "UPDATE_INVENTORY_ALERTS" -- WTF? | |
| 44 } | |
| 45 | |
| 46 local eventListHunter = { | |
| 47 "PLAYER_REGEN_ENABLED", | |
| 48 "PLAYER_ENTERING_WORLD", | |
| 49 "SPELL_UPDATE_COOLDOWN", | |
| 50 "SPELL_UPDATE_USABLE", | |
| 51 "UNIT_AURA", | |
| 52 "SPELLS_CHANGED" | |
| 53 } | |
| 54 | |
| 55 if playerClass == "HUNTER" then | |
| 56 eventList = eventListHunter | |
| 57 end | |
| 58 | |
| 59 -- | |
| 60 -- Stance Button class | |
| 61 -- | |
| 62 local Super = ReAction.Button | |
| 63 local Stance = setmetatable( { }, { __index = Super } ) | |
| 64 ReAction.Button.Stance = Stance | |
| 65 | |
| 66 function Stance:New( idx, moduleConfig, bar, idHint ) | |
| 67 local name = format("ReAction_%s_Stance_%d",bar:GetName(),idx) | |
| 68 | |
| 69 self = Super.New(self, name, moduleConfig.buttons[bar:GetName()][idx], bar, idx, "SecureActionButtonTemplate, ActionButtonTemplate" ) | |
| 70 self.moduleConfig = moduleConfig | |
| 71 self.hunterIdx = 1 | |
| 72 | |
| 73 local f = self:GetFrame() | |
| 74 local barFrame = bar:GetFrame() | |
| 75 local config = self:GetConfig() | |
| 76 | |
| 77 -- set up the base stance ID | |
| 78 self:SetActionIDPool("stance",8) | |
| 79 config.stanceID = self:AcquireActionID(config.stanceID, idHint, true) | |
| 80 | |
| 81 -- attribute setup | |
| 82 f:SetAttribute("type","spell") | |
| 83 self:UpdateAction() | |
| 84 | |
| 85 -- non secure scripts | |
| 86 f:SetScript("OnEvent", function(frame, ...) self:OnEvent(...) end) | |
| 87 f:SetScript("OnEnter", function(frame) self:OnEnter() end) | |
| 88 f:SetScript("OnLeave", function(frame) self:OnLeave() end) | |
| 89 f:SetScript("PreClick", function(frame, ...) self:PreClick(...) end) | |
| 90 | |
| 91 -- secure handlers | |
| 92 -- (none) | |
| 93 | |
| 94 -- event registration | |
| 95 f:EnableMouse(true) | |
| 96 f:RegisterForClicks("AnyUp") | |
| 97 for _, evt in pairs(eventList) do | |
| 98 f:RegisterEvent(evt) | |
| 99 end | |
| 100 | |
| 101 -- attach to skinner | |
| 102 bar:SkinButton(self) | |
| 103 | |
| 104 -- initial display | |
| 105 if ReAction:GetConfigMode() then | |
| 106 self:GetFrame():Show() | |
| 107 end | |
| 108 | |
| 109 self:Refresh() | |
| 110 | |
| 111 return self | |
| 112 end | |
| 113 | |
| 114 function Stance:GetModuleConfig() | |
| 115 -- this is the Stance module config structure, | |
| 116 -- not the config structure of the bar itself | |
| 117 return self.moduleConfig | |
| 118 end | |
| 119 | |
| 120 function Stance:GetActionID() | |
| 121 return self.config.stanceID | |
| 122 end | |
| 123 | |
| 124 function Stance:UpdateAction() | |
| 125 if InCombatLockdown() then | |
| 126 self.updatePending = true | |
| 127 else | |
| 128 self.updatePending = false | |
| 129 local idx = self:GetActionID() | |
| 130 local f = self:GetFrame() | |
| 131 local c = self:GetModuleConfig() | |
| 132 if playerClass == "HUNTER" then | |
| 133 if c.showHunterAspects then | |
| 134 -- re-map the index in the case of "hide monkey/hawk" | |
| 135 if c.hideMonkeyHawk then | |
| 136 local usable, outOfMana = IsUsableSpell(aspects[8]) | |
| 137 if usable or outOfMana then | |
| 138 idx = idx + 2 | |
| 139 if idx > 8 then | |
| 140 f:Hide() | |
| 141 return | |
| 142 end | |
| 143 end | |
| 144 end | |
| 145 self.hunterIdx = idx | |
| 146 -- cache the highest rank spellID | |
| 147 if not aspectLinks[aspects[idx]] then | |
| 148 aspectLinks[aspects[idx]] = GetSpellLink(aspects[idx],"") | |
| 149 end | |
| 150 local usable, outOfMana = IsUsableSpell(aspects[idx]) | |
| 151 if usable or outOfMana then | |
| 152 f:SetAttribute("spell",aspects[idx]) | |
| 153 f:Show() | |
| 154 self:Update() | |
| 155 else | |
| 156 -- haven't learned this spell yet | |
| 157 f:Hide() | |
| 158 end | |
| 159 else | |
| 160 f:Hide() | |
| 161 end | |
| 162 elseif idx > GetNumShapeshiftForms() or | |
| 163 playerClass == "PALADIN" and c.hidePaladinAuras or | |
| 164 playerClass == "DEATHKNIGHT" and c.hideDKPresences then | |
| 165 f:Hide() | |
| 166 else | |
| 167 f:SetAttribute("spell", select(2,GetShapeshiftFormInfo(idx))) | |
| 168 f:Show() | |
| 169 self:Update() | |
| 170 end | |
| 171 end | |
| 172 end | |
| 173 | |
| 174 function Stance:Refresh() | |
| 175 Super.Refresh(self) | |
| 176 self:Update() | |
| 177 end | |
| 178 | |
| 179 function Stance:Update() | |
| 180 local texture, isActive, isCastable | |
| 181 if playerClass == "HUNTER" then | |
| 182 local name, rank | |
| 183 local spell = aspects[self.hunterIdx] | |
| 184 name, rank, texture = GetSpellInfo(spell) | |
| 185 isCastable = IsUsableSpell(spell) | |
| 186 for i = 1, 40 do | |
| 187 local buff = UnitBuff("player",i,true) | |
| 188 if not buff then break end | |
| 189 if buff == spell then | |
| 190 isActive = true | |
| 191 texture = "Interface\\Icons\\Spell_Nature_WispSplode" | |
| 192 break | |
| 193 end | |
| 194 end | |
| 195 else | |
| 196 local _ | |
| 197 texture, _, isActive, isCastable = GetShapeshiftFormInfo(self:GetActionID()) | |
| 198 end | |
| 199 | |
| 200 local icon = self.frames.icon | |
| 201 icon:SetTexture(texture) | |
| 202 self:GetFrame():SetChecked( isActive and 1 or 0 ) | |
| 203 if isCastable then | |
| 204 icon:SetVertexColor(1.0, 1.0, 1.0) | |
| 205 else | |
| 206 icon:SetVertexColor(0.4, 0.4, 0.4) | |
| 207 end | |
| 208 | |
| 209 self:UpdateCooldown() | |
| 210 end | |
| 211 | |
| 212 function Stance:UpdateCooldown() | |
| 213 local start, duration, enabled | |
| 214 if playerClass == "HUNTER" then | |
| 215 local spell = aspects[self.hunterIdx] | |
| 216 if spell then | |
| 217 start, duration, enabled = GetSpellCooldown(spell) | |
| 218 end | |
| 219 else | |
| 220 start, duration, enabled = GetShapeshiftFormCooldown(self:GetActionID()) | |
| 221 end | |
| 222 if start then | |
| 223 CooldownFrame_SetTimer(self.frames.cooldown, start, duration, enabled) | |
| 224 end | |
| 225 end | |
| 226 | |
| 227 function Stance:SetTooltip() | |
| 228 if GetCVar("UberTooltips") == "1" then | |
| 229 GameTooltip_SetDefaultAnchor(GameTooltip, self:GetFrame()) | |
| 230 else | |
| 231 GameTooltip:SetOwner(self:GetFrame(), "ANCHOR_RIGHT") | |
| 232 end | |
| 233 if playerClass == "HUNTER" then | |
| 234 local aspect = aspects[self.hunterIdx] | |
| 235 if aspect and aspectLinks[aspect] then | |
| 236 GameTooltip:SetHyperlink(aspectLinks[aspect]) | |
| 237 end | |
| 238 else | |
| 239 GameTooltip:SetShapeshift(self:GetActionID()) | |
| 240 end | |
| 241 end | |
| 242 | |
| 243 function Stance:OnEnter() | |
| 244 self:SetTooltip() | |
| 245 end | |
| 246 | |
| 247 function Stance:OnLeave() | |
| 248 GameTooltip:Hide() | |
| 249 end | |
| 250 | |
| 251 function Stance:PreClick() | |
| 252 local f = self:GetFrame() | |
| 253 f:SetChecked( not f:GetChecked() ) | |
| 254 end | |
| 255 | |
| 256 function Stance:OnEvent(event, arg) | |
| 257 if event == "PLAYER_REGEN_ENABLED" then | |
| 258 if self.updatePending then | |
| 259 self:UpdateAction() | |
| 260 end | |
| 261 elseif event == "UPDATE_SHAPESHIFT_COOLDOWN" then | |
| 262 self:UpdateCooldown() | |
| 263 elseif event == "UPDATE_SHAPESHIFT_FORMS" or | |
| 264 event == "SPELLS_CHANGED" then | |
| 265 aspectLinks = { } -- force repopulate of the spellIDs | |
| 266 self:UpdateAction() | |
| 267 elseif event == "UNIT_AURA" then | |
| 268 if arg == "player" then | |
| 269 self:Update() | |
| 270 end | |
| 271 else | |
| 272 self:Update() | |
| 273 end | |
| 274 end | |
| 275 | |
| 276 function Stance:ShowGridTemp(show) | |
| 277 if show then | |
| 278 self:GetFrame():Show() | |
| 279 else | |
| 280 self:UpdateAction() | |
| 281 end | |
| 282 end |
