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