-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstagger.lua
More file actions
234 lines (179 loc) · 6.44 KB
/
stagger.lua
File metadata and controls
234 lines (179 loc) · 6.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
--[[
# Element: Monk Stagger Bar
Handles the visibility and updating of the Monk's stagger bar.
## Widget
Stagger - A `StatusBar` used to represent the current stagger level.
## Notes
A default texture will be applied if the widget is a StatusBar and doesn't have a texture set.
## Options
.smoothing - Which smoothing method to use, defaults to Enum.StatusBarInterpolation.Immediate (number)
## Examples
local Stagger = CreateFrame('StatusBar', nil, self)
Stagger:SetSize(120, 20)
Stagger:SetPoint('TOPLEFT', self, 'BOTTOMLEFT', 0, 0)
-- Register with oUF
self.Stagger = Stagger
--]]
local _, ns = ...
local oUF = ns.oUF
local Private = oUF.Private
-- sourced from Blizzard_FrameXMLBase/Constants.lua
local SPEC_MONK_BREWMASTER = _G.SPEC_MONK_BREWMASTER or 1
local BREWMASTER_POWER_BAR_NAME = 'STAGGER'
-- percentages at which bar should change color
local STAGGER_YELLOW_TRANSITION = _G.STAGGER_YELLOW_TRANSITION or 0.3
local STAGGER_RED_TRANSITION = _G.STAGGER_RED_TRANSITION or 0.6
-- table indices of bar colors
local STAGGER_GREEN_INDEX = _G.STAGGER_GREEN_INDEX or 1
local STAGGER_YELLOW_INDEX = _G.STAGGER_YELLOW_INDEX or 2
local STAGGER_RED_INDEX = _G.STAGGER_RED_INDEX or 3
local function UpdateColor(self, event, unit)
if(unit and unit ~= self.unit) then return end
local element = self.Stagger
local colors = self.colors.power[BREWMASTER_POWER_BAR_NAME]
local perc = (element.cur or 0) / (element.max or 1)
local color
if(perc >= STAGGER_RED_TRANSITION) then
color = colors and colors[STAGGER_RED_INDEX]
elseif(perc > STAGGER_YELLOW_TRANSITION) then
color = colors and colors[STAGGER_YELLOW_INDEX]
else
color = colors and colors[STAGGER_GREEN_INDEX]
end
if(color) then
element:SetStatusBarColor(color:GetRGB())
end
--[[ Callback: Stagger:PostUpdateColor(color)
Called after the element color has been updated.
* self - the Stagger element
* color - the used ColorMixin-based object (table?)
--]]
if(element.PostUpdateColor) then
element:PostUpdateColor(color)
end
end
local function Update(self, event, unit)
if(unit and unit ~= self.unit) then return end
local element = self.Stagger
--[[ Callback: Stagger:PreUpdate()
Called before the element has been updated.
* self - the Stagger element
--]]
if(element.PreUpdate) then
element:PreUpdate()
end
-- Blizzard code has nil checks for UnitStagger return
local cur = UnitStagger('player') or 0
local max = UnitHealthMax('player')
element:SetMinMaxValues(0, max)
element:SetValue(cur, element.smoothing)
element.cur = cur
element.max = max
--[[ Callback: Stagger:PostUpdate(cur, max)
Called after the element has been updated.
* self - the Stagger element
* cur - the amount of staggered damage (number)
* max - the player's maximum possible health value (number)
--]]
if(element.PostUpdate) then
element:PostUpdate(cur, max)
end
end
local function Path(self, ...)
--[[ Override: Stagger.Override(self, event, unit)
Used to completely override the internal update function.
* self - the parent object
* event - the event triggering the update (string)
* unit - the unit accompanying the event (string)
--]]
do
(self.Stagger.Override or Update)(self, ...)
end
--[[ Override: Stagger.UpdateColor(self, event, unit)
Used to completely override the internal function for updating the widgets' colors.
* self - the parent object
* event - the event triggering the update (string)
* unit - the unit accompanying the event (string)
--]]
(self.Stagger.UpdateColor or UpdateColor) (self, ...)
end
local function Visibility(self, event, unit)
local element = self.Stagger
if(SPEC_MONK_BREWMASTER ~= C_SpecializationInfo.GetSpecialization() or UnitHasVehiclePlayerFrameUI('player')) then
if(element:IsShown()) then
element:Hide()
self:UnregisterEvent('UNIT_AURA', Path)
--[[ Callback: Stagger:PostVisibility(isVisible)
Called after the element's visibility has been changed.
* self - the Stagger element
* isVisible - the current visibility state of the element (boolean)
--]]
if(element.PostVisibility) then
element:PostVisibility(false)
end
end
else
if(not element:IsShown()) then
element:Show()
Private.SmartRegisterUnitEvent(self, 'UNIT_AURA', 'player', Path)
if(element.PostVisibility) then
element:PostVisibility(true)
end
end
Path(self, event, unit)
end
end
local function VisibilityPath(self, ...)
--[[ Override: Stagger.OverrideVisibility(self, event, unit)
Used to completely override the internal visibility toggling function.
* self - the parent object
* event - the event triggering the update (string)
* unit - the unit accompanying the event (string)
--]]
(self.Stagger.OverrideVisibility or Visibility)(self, ...)
end
local function ForceUpdate(element)
VisibilityPath(element.__owner, 'ForceUpdate', element.__owner.unit)
end
local function Disable(self)
local element = self.Stagger
if(element) then
element:Hide()
self:UnregisterEvent('UNIT_AURA', Path)
self:UnregisterEvent('UNIT_DISPLAYPOWER', VisibilityPath)
self:UnregisterEvent('PLAYER_TALENT_UPDATE', VisibilityPath)
MonkStaggerBar:RegisterEvent('PLAYER_ENTERING_WORLD')
MonkStaggerBar:RegisterEvent('PLAYER_SPECIALIZATION_CHANGED')
MonkStaggerBar:RegisterEvent('UNIT_DISPLAYPOWER')
MonkStaggerBar:RegisterEvent('UNIT_EXITED_VEHICLE')
MonkStaggerBar:RegisterEvent('UPDATE_VEHICLE_ACTIONBAR')
end
end
local function Enable(self, unit)
if(UnitClassBase('player') ~= 'MONK') then
Disable(self)
return false
end
local element = self.Stagger
if(element and UnitIsUnit(unit, 'player')) then
element.__owner = self
element.ForceUpdate = ForceUpdate
if(not element.smoothing) then
element.smoothing = Enum.StatusBarInterpolation.Immediate
end
Private.SmartRegisterUnitEvent(self, 'UNIT_DISPLAYPOWER', unit, VisibilityPath)
self:RegisterEvent('PLAYER_TALENT_UPDATE', VisibilityPath, true)
if(element:IsObjectType('StatusBar') and not element:GetStatusBarTexture()) then
element:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
end
MonkStaggerBar:UnregisterEvent('PLAYER_ENTERING_WORLD')
MonkStaggerBar:UnregisterEvent('PLAYER_SPECIALIZATION_CHANGED')
MonkStaggerBar:UnregisterEvent('UNIT_DISPLAYPOWER')
MonkStaggerBar:UnregisterEvent('UNIT_EXITED_VEHICLE')
MonkStaggerBar:UnregisterEvent('UPDATE_VEHICLE_ACTIONBAR')
-- do not change this without taking Visibility into account
element:Hide()
return true
end
end
oUF:AddElement('Stagger', VisibilityPath, Enable, Disable)