Mercurial > wow > reaction
comparison StanceButton.lua @ 245:65f2805957a0
No real reason to store some of the code in a subdirectory.
| author | Flick |
|---|---|
| date | Sat, 26 Mar 2011 12:35:08 -0700 |
| parents | classes/StanceButton.lua@0e20f65375d5 |
| children | 9e708a155ab9 |
comparison
equal
deleted
inserted
replaced
| 244:f255cd69e890 | 245:65f2805957a0 |
|---|---|
| 1 local addonName, addonTable = ... | |
| 2 local ReAction = addonTable.ReAction | |
| 3 local L = ReAction.L | |
| 4 local _G = _G | |
| 5 local CreateFrame = CreateFrame | |
| 6 local format = string.format | |
| 7 local GetCVar = GetCVar | |
| 8 local GameTooltip_SetDefaultAnchor = GameTooltip_SetDefaultAnchor | |
| 9 local CooldownFrame_SetTimer = CooldownFrame_SetTimer | |
| 10 local InCombatLockdown = InCombatLockdown | |
| 11 local GetNumShapeshiftForms = GetNumShapeshiftForms | |
| 12 local GetShapeshiftFormInfo = GetShapeshiftFormInfo | |
| 13 local IsUsableSpell = IsUsableSpell | |
| 14 local GetSpellInfo = GetSpellInfo | |
| 15 | |
| 16 -- | |
| 17 -- private | |
| 18 -- | |
| 19 local playerClass = select(2,UnitClass("player")) | |
| 20 | |
| 21 local eventList = { | |
| 22 "PLAYER_REGEN_ENABLED", | |
| 23 "PLAYER_ENTERING_WORLD", | |
| 24 "UPDATE_SHAPESHIFT_FORM", | |
| 25 "UPDATE_SHAPESHIFT_FORMS", | |
| 26 "UPDATE_SHAPESHIFT_USABLE", | |
| 27 "UPDATE_SHAPESHIFT_COOLDOWN", | |
| 28 "UPDATE_BINDINGS", | |
| 29 } | |
| 30 | |
| 31 -- | |
| 32 -- Stance Button class | |
| 33 -- | |
| 34 local buttonTypeID = "Stance" | |
| 35 local Super = ReAction.Button | |
| 36 local Stance = setmetatable( | |
| 37 { | |
| 38 defaultConfig = { | |
| 39 type = buttonTypeID, | |
| 40 btnHeight = 36, | |
| 41 btnWidth = 36, | |
| 42 btnRows = 1, | |
| 43 btnColumns = 6, | |
| 44 spacing = 3 | |
| 45 }, | |
| 46 | |
| 47 barType = L["Stance Bar"], | |
| 48 buttonTypeID = buttonTypeID | |
| 49 }, | |
| 50 { __index = Super } ) | |
| 51 | |
| 52 ReAction.Button.Stance = Stance | |
| 53 ReAction:RegisterBarType(Stance) | |
| 54 | |
| 55 function Stance:New( config, bar, idx, idHint ) | |
| 56 local name = format("ReAction_%s_Stance_%d",bar:GetName(),idx) | |
| 57 | |
| 58 self = Super.New(self, name, config, bar, idx, "SecureActionButtonTemplate, ActionButtonTemplate" ) | |
| 59 | |
| 60 local f = self:GetFrame() | |
| 61 local barFrame = bar:GetFrame() | |
| 62 local config = self:GetConfig() | |
| 63 | |
| 64 -- set up the base stance ID | |
| 65 self:SetActionIDPool("stance",8) | |
| 66 config.stanceID = self:AcquireActionID(config.stanceID, idHint, true) | |
| 67 | |
| 68 -- attribute setup | |
| 69 f:SetAttribute("type","spell") | |
| 70 | |
| 71 -- non secure scripts | |
| 72 f:SetScript("OnEvent", function(frame, ...) self:OnEvent(...) end) | |
| 73 f:SetScript("OnEnter", function(frame) self:OnEnter() end) | |
| 74 f:SetScript("OnLeave", function(frame) self:OnLeave() end) | |
| 75 f:SetScript("PreClick", function(frame, ...) self:PreClick(...) end) | |
| 76 | |
| 77 -- secure handlers | |
| 78 -- (none) | |
| 79 | |
| 80 -- event registration | |
| 81 f:EnableMouse(true) | |
| 82 f:RegisterForClicks("AnyUp") | |
| 83 for _, evt in pairs(eventList) do | |
| 84 f:RegisterEvent(evt) | |
| 85 end | |
| 86 | |
| 87 -- attach to skinner | |
| 88 bar:SkinButton(self) | |
| 89 | |
| 90 -- initial display | |
| 91 if ReAction:GetConfigMode() then | |
| 92 self:GetFrame():Show() | |
| 93 end | |
| 94 | |
| 95 self:Refresh() | |
| 96 | |
| 97 return self | |
| 98 end | |
| 99 | |
| 100 function Stance:GetActionID() | |
| 101 return self.config.stanceID | |
| 102 end | |
| 103 | |
| 104 function Stance:UpdateAction() | |
| 105 if InCombatLockdown() then | |
| 106 self.updatePending = true | |
| 107 else | |
| 108 self.updatePending = false | |
| 109 local idx = self:GetActionID() | |
| 110 local f = self:GetFrame() | |
| 111 if idx > GetNumShapeshiftForms() then | |
| 112 f:Hide() | |
| 113 else | |
| 114 f:SetAttribute("spell", select(2,GetShapeshiftFormInfo(idx))) | |
| 115 f:Show() | |
| 116 self:Update() | |
| 117 end | |
| 118 end | |
| 119 end | |
| 120 | |
| 121 function Stance:Refresh() | |
| 122 Super.Refresh(self) | |
| 123 self:UpdateHotkey() | |
| 124 self:UpdateAction() | |
| 125 end | |
| 126 | |
| 127 function Stance:Update() | |
| 128 local texture, _, isActive, isCastable = GetShapeshiftFormInfo(self:GetActionID()) | |
| 129 | |
| 130 local icon = self.frames.icon | |
| 131 icon:SetTexture(texture) | |
| 132 self:GetFrame():SetChecked( isActive and 1 or 0 ) | |
| 133 if isCastable then | |
| 134 self.frames.hotkey:Show() | |
| 135 icon:SetVertexColor(1.0, 1.0, 1.0) | |
| 136 else | |
| 137 icon:SetVertexColor(0.4, 0.4, 0.4) | |
| 138 end | |
| 139 | |
| 140 self:UpdateCooldown() | |
| 141 end | |
| 142 | |
| 143 function Stance:UpdateCooldown() | |
| 144 local start, duration, enabled = GetShapeshiftFormCooldown(self:GetActionID()) | |
| 145 if start then | |
| 146 CooldownFrame_SetTimer(self.frames.cooldown, start, duration, enabled) | |
| 147 end | |
| 148 end | |
| 149 | |
| 150 function Stance:SetTooltip() | |
| 151 if GetCVar("UberTooltips") == "1" then | |
| 152 GameTooltip_SetDefaultAnchor(GameTooltip, self:GetFrame()) | |
| 153 else | |
| 154 GameTooltip:SetOwner(self:GetFrame(), "ANCHOR_RIGHT") | |
| 155 end | |
| 156 GameTooltip:SetShapeshift(self:GetActionID()) | |
| 157 end | |
| 158 | |
| 159 function Stance:OnEnter() | |
| 160 self:SetTooltip() | |
| 161 end | |
| 162 | |
| 163 function Stance:OnLeave() | |
| 164 GameTooltip:Hide() | |
| 165 end | |
| 166 | |
| 167 function Stance:PreClick() | |
| 168 local f = self:GetFrame() | |
| 169 f:SetChecked( not f:GetChecked() ) | |
| 170 end | |
| 171 | |
| 172 function Stance:OnEvent(event, arg) | |
| 173 if event == "PLAYER_REGEN_ENABLED" then | |
| 174 if self.updatePending then | |
| 175 self:UpdateAction() | |
| 176 end | |
| 177 elseif event == "UPDATE_SHAPESHIFT_COOLDOWN" then | |
| 178 self:UpdateCooldown() | |
| 179 elseif event == "UPDATE_SHAPESHIFT_FORMS" then | |
| 180 self:UpdateAction() | |
| 181 elseif event == "UNIT_AURA" then | |
| 182 if arg == "player" then | |
| 183 self:Update() | |
| 184 end | |
| 185 elseif event == "UPDATE_BINDINGS" then | |
| 186 self:UpdateHotkey() | |
| 187 else | |
| 188 self:Update() | |
| 189 end | |
| 190 end | |
| 191 | |
| 192 function Stance:ShowGridTemp(show) | |
| 193 if show then | |
| 194 self:GetFrame():Show() | |
| 195 else | |
| 196 self:UpdateAction() | |
| 197 end | |
| 198 end |
