-
Notifications
You must be signed in to change notification settings - Fork 0
/
warlockSpecBars.lua
executable file
·206 lines (173 loc) · 6.01 KB
/
warlockSpecBars.lua
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
local _, ns = ...
local oUF = ns.oUF or oUF
assert(oUF, "oUF_WarlockSpecBars was unable to locate oUF install")
if select(2, UnitClass("player")) ~= "WARLOCK" then return end
local MAX_POWER_PER_EMBER = 10
local SPELL_POWER_DEMONIC_FURY = SPELL_POWER_DEMONIC_FURY
local SPELL_POWER_BURNING_EMBERS = SPELL_POWER_BURNING_EMBERS
local SPELL_POWER_SOUL_SHARDS = SPELL_POWER_SOUL_SHARDS
local SPEC_WARLOCK_DESTRUCTION = SPEC_WARLOCK_DESTRUCTION
local SPEC_WARLOCK_DESTRUCTION_GLYPH_EMBERS = 63304
local SPEC_WARLOCK_AFFLICTION = SPEC_WARLOCK_AFFLICTION
local SPEC_WARLOCK_AFFLICTION_GLYPH_SHARDS = 63302
local SPEC_WARLOCK_DEMONOLOGY = SPEC_WARLOCK_DEMONOLOGY
local LATEST_SPEC = 0
local Colors = {
[1] = {148/255, 130/255, 201/255, 1},
[2] = {95/255, 222/255, 95/255, 1},
[3] = {222/255, 95/255, 95/255, 1},
}
local Update = function(self, event, unit, powerType)
if(self.unit ~= unit or (powerType and powerType ~= "BURNING_EMBERS" and powerType ~= "SOUL_SHARDS" and powerType ~= "DEMONIC_FURY")) then return end
local wsb = self.WarlockSpecBars
if(wsb.PreUpdate) then wsb:PreUpdate(unit) end
local spec = GetSpecialization()
if spec then
if (spec == SPEC_WARLOCK_DESTRUCTION) then
local maxPower = UnitPowerMax("player", SPELL_POWER_BURNING_EMBERS, true)
local power = UnitPower("player", SPELL_POWER_BURNING_EMBERS, true)
local numEmbers = power / MAX_POWER_PER_EMBER
local numBars = floor(maxPower / MAX_POWER_PER_EMBER)
for i = 1, numBars do
wsb[i]:SetMinMaxValues((MAX_POWER_PER_EMBER * i) - MAX_POWER_PER_EMBER, MAX_POWER_PER_EMBER * i)
wsb[i]:SetValue(power)
end
elseif ( spec == SPEC_WARLOCK_AFFLICTION ) then
local numShards = UnitPower("player", SPELL_POWER_SOUL_SHARDS)
local maxShards = UnitPowerMax("player", SPELL_POWER_SOUL_SHARDS)
for i = 1, maxShards do
if i <= numShards then
wsb[i]:SetAlpha(1)
else
wsb[i]:SetAlpha(.2)
end
end
elseif spec == SPEC_WARLOCK_DEMONOLOGY then
local power = UnitPower("player", SPELL_POWER_DEMONIC_FURY)
local maxPower = UnitPowerMax("player", SPELL_POWER_DEMONIC_FURY)
wsb[1]:SetMinMaxValues(0, maxPower)
wsb[1]:SetValue(power)
end
end
if(wsb.PostUpdate) then
return wsb:PostUpdate(spec)
end
end
local function Visibility(self, event, unit)
local wsb = self.WarlockSpecBars
local spacing = select(4, wsb[4]:GetPoint())
local w = wsb:GetWidth()
local s = 0
print("visibility")
local spec = GetSpecialization()
if spec then
if not wsb:IsShown() then
wsb:Show()
end
if LATEST_SPEC ~= spec then
for i = 1, 4 do
local max = select(2, wsb[i]:GetMinMaxValues())
if spec == SPEC_WARLOCK_AFFLICTION then
wsb[i]:SetValue(max)
else
wsb[i]:SetValue(0)
end
wsb[i]:Show()
if wsb[i].bg then wsb[i].bg:SetAlpha(0.15) end
end
end
if spec == SPEC_WARLOCK_DESTRUCTION then
local maxembers = 3
for i = 1, GetNumGlyphSockets() do
local glyphID = select(4, GetGlyphSocketInfo(i))
if glyphID == SPEC_WARLOCK_DESTRUCTION_GLYPH_EMBERS then maxembers = 4 end
end
for i = 1, maxembers do
if i ~= maxembers then
wsb[i]:SetWidth(w / maxembers - spacing)
s = s + (w / maxembers)
else
wsb[i]:SetWidth(w - s)
end
wsb[i]:SetStatusBarColor(unpack(Colors[SPEC_WARLOCK_DESTRUCTION]))
if wsb[i].bg then wsb[i].bg:SetAlpha(0.15) wsb[i].bg:SetTexture(unpack(Colors[SPEC_WARLOCK_DESTRUCTION])) end
end
if maxembers == 3 then wsb[4]:Hide() else wsb[4]:Show() end
elseif spec == SPEC_WARLOCK_AFFLICTION then
local maxshards = 3
print("showing for affliction")
for i = 1, GetNumGlyphSockets() do
local glyphID = select(4, GetGlyphSocketInfo(i))
if glyphID == SPEC_WARLOCK_AFFLICTION_GLYPH_SHARDS then maxshards = 4 end
end
for i = 1, maxshards do
if i ~= maxshards then
wsb[i]:SetWidth(w / maxshards - spacing)
s = s + (w / maxshards)
else
wsb[i]:SetWidth(w - s)
end
wsb[i]:SetStatusBarColor(unpack(Colors[SPEC_WARLOCK_AFFLICTION]))
if wsb[i].bg then wsb[i].bg:SetAlpha(0) end
end
if maxshards == 3 then wsb[4]:Hide() else wsb[4]:Show() end
elseif spec == SPEC_WARLOCK_DEMONOLOGY then
wsb[2]:Hide()
wsb[3]:Hide()
wsb[4]:Hide()
wsb[1]:SetWidth(wsb:GetWidth())
wsb[1]:SetStatusBarColor(unpack(Colors[SPEC_WARLOCK_DEMONOLOGY]))
if wsb[1].bg then wsb[1].bg:SetAlpha(0.15) wsb[1].bg:SetTexture(unpack(Colors[SPEC_WARLOCK_DEMONOLOGY])) end
end
-- force an update each time we respec
Update(self, nil, "player")
else
if wsb:IsShown() then
wsb:Hide()
end
end
LATEST_SPEC = spec
end
local Path = function(self, ...)
return (self.WarlockSpecBars.Override or Update) (self, ...)
end
local ForceUpdate = function(element)
return Path(element.__owner, "ForceUpdate", element.__owner.unit, "SOUL_SHARDS")
end
local function Enable(self)
local wsb = self.WarlockSpecBars
if(wsb) then
wsb.__owner = self
wsb.ForceUpdate = ForceUpdate
self:RegisterEvent("UNIT_POWER", Path)
self:RegisterEvent("UNIT_DISPLAYPOWER", Path)
-- why the fuck does PLAYER_TALENT_UPDATE doesnt trigger on initial login if we register to: self or self.PluginName
wsb.Visibility = CreateFrame("Frame", nil, wsb)
wsb.Visibility:RegisterEvent("PLAYER_TALENT_UPDATE")
wsb.Visibility:SetScript("OnEvent", function(frame, event, unit) Visibility(self, event, unit) end)
for i = 1, 4 do
local Point = wsb[i]
print(i, Point:GetStatusBarTexture())
if not Point:GetStatusBarTexture() then
Point:SetStatusBarTexture([=[Interface\TargetingFrame\UI-StatusBar]=])
end
Point:SetFrameLevel(wsb:GetFrameLevel() + 1)
Point:GetStatusBarTexture():SetHorizTile(false)
if Point.bg then
Point.bg:SetAllPoints()
end
end
wsb:Hide()
Visibility(self)
return true
end
end
local function Disable(self)
local wsb = self.WarlockSpecBars
if(wsb) then
self:UnregisterEvent("UNIT_POWER", Path)
self:UnregisterEvent("UNIT_DISPLAYPOWER", Path)
wsb.Visibility:UnregisterEvent("PLAYER_TALENT_UPDATE")
end
end
oUF:AddElement("WarlockSpecBars", Path, Enable, Disable)