annotate classes/StanceButton.lua @ 166:8241be11dcc0

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