Skip to content

Commit 933d1fb

Browse files
committed
secondary power bar
1 parent b1d0a80 commit 933d1fb

2 files changed

Lines changed: 56 additions & 79 deletions

File tree

Core/Globals.lua

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -390,34 +390,30 @@ function UUF:GetSecondaryPowerType()
390390
end
391391

392392
function UUF:UpdateHealthBarLayout(unitFrame, unit)
393-
local FrameDB = UUF.db.profile.Units[UUF:GetNormalizedUnit(unit)].Frame
394393
local PowerBarDB = UUF.db.profile.Units[UUF:GetNormalizedUnit(unit)].PowerBar
395394
local SecondaryPowerBarDB = UUF.db.profile.Units[UUF:GetNormalizedUnit(unit)].SecondaryPowerBar
396395

397396
local topOffset = -1
398397
local bottomOffset = 1
399-
local heightReduction = 2
400398

401-
local hasSecondaryPower = UUF:GetSecondaryPowerType() ~= nil or UUF:IsRunePower()
399+
local hasSecondaryPower =
400+
SecondaryPowerBarDB
401+
and SecondaryPowerBarDB.Enabled
402+
and (unitFrame.Runes or unitFrame.ClassPower)
402403

403-
if SecondaryPowerBarDB and SecondaryPowerBarDB.Enabled and hasSecondaryPower then
404+
if hasSecondaryPower then
404405
topOffset = topOffset - SecondaryPowerBarDB.Height - 1
405-
heightReduction = heightReduction + SecondaryPowerBarDB.Height + 1
406406
end
407407

408408
if PowerBarDB and PowerBarDB.Enabled then
409409
bottomOffset = bottomOffset + PowerBarDB.Height + 1
410-
heightReduction = heightReduction + PowerBarDB.Height + 1
411410
end
412411

413412
unitFrame.HealthBackground:ClearAllPoints()
414413
unitFrame.HealthBackground:SetPoint("TOPLEFT", unitFrame.Container, "TOPLEFT", 1, topOffset)
415414
unitFrame.HealthBackground:SetPoint("BOTTOMRIGHT", unitFrame.Container, "BOTTOMRIGHT", -1, bottomOffset)
416-
unitFrame.HealthBackground:SetHeight(FrameDB.Height - heightReduction)
417415

418416
unitFrame.Health:ClearAllPoints()
419417
unitFrame.Health:SetPoint("TOPLEFT", unitFrame.Container, "TOPLEFT", 1, topOffset)
420418
unitFrame.Health:SetPoint("BOTTOMRIGHT", unitFrame.Container, "BOTTOMRIGHT", -1, bottomOffset)
421-
unitFrame.Health:SetHeight(FrameDB.Height - heightReduction)
422419
end
423-

Elements/SecondaryPowerBar.lua

Lines changed: 51 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ local UpdateSecondaryPowerBarEventFrame = CreateFrame("Frame")
44
UpdateSecondaryPowerBarEventFrame:RegisterEvent("TRAIT_CONFIG_UPDATED")
55
UpdateSecondaryPowerBarEventFrame:RegisterEvent("PLAYER_SPECIALIZATION_CHANGED")
66
UpdateSecondaryPowerBarEventFrame:RegisterEvent("UPDATE_SHAPESHIFT_FORM")
7+
UpdateSecondaryPowerBarEventFrame:RegisterEvent("PLAYER_ENTERING_WORLD") -- Add this
78
UpdateSecondaryPowerBarEventFrame:SetScript("OnEvent", function(self, event, ...)
8-
if event == "PLAYER_SPECIALIZATION_CHANGED" then local unit = ... if unit ~= "player" then return end end
9+
if event == "PLAYER_SPECIALIZATION_CHANGED" then
10+
local unit = ...
11+
if unit ~= "player" then return end
12+
end
913
C_Timer.After(0.1, function()
1014
if UUF.PLAYER then
1115
UUF:UpdateUnitSecondaryPowerBar(UUF.PLAYER, "player")
@@ -36,15 +40,10 @@ function UUF:CreateUnitSecondaryPowerBar(unitFrame, unit)
3640
local unitFrameWidth = totalWidth / maxPower
3741

3842
element.ContainerBackground = container:CreateTexture(nil, "BACKGROUND")
39-
element.ContainerBackground:SetPoint("TOPLEFT", container, "TOPLEFT", 1, -1)
40-
element.ContainerBackground:SetSize(totalWidth, DB.Height)
4143
element.ContainerBackground:SetTexture(UUF.Media.Background)
42-
element.ContainerBackground:SetVertexColor(DB.Background[1], DB.Background[2], DB.Background[3], DB.Background[4] or 1)
4344

4445
for i = 1, maxPower do
4546
local bar = CreateFrame("StatusBar", nil, container)
46-
bar:SetSize(unitFrameWidth, DB.Height)
47-
bar:SetPoint("TOPLEFT", container, "TOPLEFT", 1 + ((i - 1) * unitFrameWidth), -1)
4847
bar:SetStatusBarTexture(UUF.Media.Foreground)
4948
bar:SetMinMaxValues(0, 1)
5049
bar.frequentUpdates = DB.Smooth
@@ -53,60 +52,39 @@ function UUF:CreateUnitSecondaryPowerBar(unitFrame, unit)
5352
bar.Background = bar:CreateTexture(nil, "BACKGROUND")
5453
bar.Background:SetAllPoints(bar)
5554
bar.Background:SetTexture(UUF.Media.Background)
56-
bar.Background:SetVertexColor(DB.Background[1], DB.Background[2], DB.Background[3], DB.Background[4] or 1)
5755

5856
element[i] = bar
5957
end
6058

6159
element.OverlayFrame = CreateFrame("Frame", nil, container)
62-
element.OverlayFrame:SetAllPoints(container)
6360
element.OverlayFrame:SetFrameLevel(container:GetFrameLevel() + 10)
6461

6562
for i = 1, maxPower - 1 do
6663
local tick = element.OverlayFrame:CreateTexture(nil, "OVERLAY")
6764
tick:SetTexture("Interface\\Buttons\\WHITE8x8")
68-
tick:SetVertexColor(0, 0, 0, 1)
6965
tick:SetDrawLayer("OVERLAY", 7)
70-
tick:SetSize(1, DB.Height)
71-
tick:SetPoint("TOPLEFT", container, "TOPLEFT", 1 + (i * unitFrameWidth) - 0.5, -1)
7266
element.Ticks[i] = tick
7367
end
7468

7569
element.PowerBarBorder = element.OverlayFrame:CreateTexture(nil, "OVERLAY")
7670
element.PowerBarBorder:SetTexture("Interface\\Buttons\\WHITE8x8")
77-
element.PowerBarBorder:SetVertexColor(0, 0, 0, 1)
7871
element.PowerBarBorder:SetDrawLayer("OVERLAY", 6)
79-
element.PowerBarBorder:SetPoint("TOPLEFT", container, "TOPLEFT", 1, -1 - DB.Height)
80-
element.PowerBarBorder:SetPoint("TOPRIGHT", container, "TOPLEFT", 1 + totalWidth, -1 - DB.Height)
81-
element.PowerBarBorder:SetHeight(1)
72+
73+
element.PostUpdateColor = function(self)
74+
if DB.ColourByType then return end
75+
for i = 1, #self do
76+
self[i]:SetStatusBarColor(DB.Foreground[1], DB.Foreground[2], DB.Foreground[3], DB.Foreground[4] or 1)
77+
end
78+
end
8279

8380
if UUF:IsRunePower() then
8481
element.sortOrder = "asc"
8582
element.colorSpec = DB.ColourByType
86-
if not DB.ColourByType then
87-
element.PostUpdateColor = function(self)
88-
for i = 1, #self do
89-
self[i]:SetStatusBarColor(DB.Foreground[1], DB.Foreground[2], DB.Foreground[3], DB.Foreground[4] or 1)
90-
end
91-
end
92-
end
9383
unitFrame.Runes = element
9484
else
95-
element.PostUpdateColor = function(self)
96-
if DB.ColourByType then return end
97-
for i = 1, #self do
98-
self[i]:SetStatusBarColor(DB.Foreground[1], DB.Foreground[2], DB.Foreground[3], DB.Foreground[4] or 1)
99-
end
100-
end
10185
unitFrame.ClassPower = element
10286
end
10387

104-
element.ContainerBackground:Show()
105-
element.PowerBarBorder:Show()
106-
element.OverlayFrame:Show()
107-
108-
UUF:UpdateHealthBarLayout(unitFrame, unit)
109-
11088
return element
11189
end
11290

@@ -124,78 +102,81 @@ function UUF:UpdateUnitSecondaryPowerBar(unitFrame, unit)
124102
if unitFrame:IsElementEnabled(elementName) then
125103
unitFrame:DisableElement(elementName)
126104
end
127-
128105
local element = unitFrame[elementName]
129-
for i = 1, #element do
130-
element[i]:Hide()
131-
element[i]:SetParent(nil)
132-
end
133-
134-
if element.Ticks then
135-
for i = 1, #element.Ticks do
136-
element.Ticks[i]:Hide()
137-
element.Ticks[i]:SetParent(nil)
138-
end
139-
end
140-
106+
for i = 1, #element do element[i]:Hide() end
107+
for i = 1, #element.Ticks do element.Ticks[i]:Hide() end
141108
if element.ContainerBackground then element.ContainerBackground:Hide() end
142109
if element.PowerBarBorder then element.PowerBarBorder:Hide() end
143110
if element.OverlayFrame then element.OverlayFrame:Hide() end
144-
145111
unitFrame[elementName] = nil
146112
end
147-
148113
UUF:UpdateHealthBarLayout(unitFrame, unit)
149114
return
150115
end
151116

152117
local currentMaxPower = isRunes and 6 or (UnitPowerMax("player", powerType) or 6)
153-
local existingMaxPower = unitFrame[elementName] and #unitFrame[elementName] or 0
118+
local element = unitFrame[elementName]
154119

155-
if not unitFrame[elementName] or currentMaxPower ~= existingMaxPower then
156-
if unitFrame[elementName] then
157-
if unitFrame:IsElementEnabled(elementName) then
158-
unitFrame:DisableElement(elementName)
159-
end
120+
if not element or #element ~= currentMaxPower then
121+
if element and unitFrame:IsElementEnabled(elementName) then
122+
unitFrame:DisableElement(elementName)
160123
end
161-
162124
unitFrame[elementName] = UUF:CreateUnitSecondaryPowerBar(unitFrame, unit)
163-
164-
if unitFrame[elementName] then
165-
unitFrame:EnableElement(elementName)
166-
UUF:UpdateHealthBarLayout(unitFrame, unit)
167-
unitFrame[elementName]:ForceUpdate()
168-
end
169-
return
170-
end
171-
172-
if not unitFrame:IsElementEnabled(elementName) then
125+
element = unitFrame[elementName]
126+
if not element then return end
173127
unitFrame:EnableElement(elementName)
174128
end
175129

176130
local totalWidth = FrameDB.Width - 2
177131
local unitFrameWidth = totalWidth / currentMaxPower
178-
local element = unitFrame[elementName]
132+
133+
element.ContainerBackground:SetSize(totalWidth, DB.Height)
134+
element.ContainerBackground:SetVertexColor(DB.Background[1], DB.Background[2], DB.Background[3], DB.Background[4] or 1)
135+
element.ContainerBackground:ClearAllPoints()
136+
element.ContainerBackground:SetPoint("TOPLEFT", unitFrame.Container, "TOPLEFT", 1, -1)
137+
element.ContainerBackground:Show()
138+
139+
element.OverlayFrame:SetAllPoints(unitFrame.Container)
140+
element.OverlayFrame:SetFrameLevel(unitFrame.Container:GetFrameLevel() + 10)
141+
element.OverlayFrame:Show()
142+
143+
element.PowerBarBorder:ClearAllPoints()
144+
element.PowerBarBorder:SetVertexColor(0, 0, 0, 1)
145+
element.PowerBarBorder:SetPoint("TOPLEFT", unitFrame.Container, "TOPLEFT", 1, -1 - DB.Height)
146+
element.PowerBarBorder:SetPoint("TOPRIGHT", unitFrame.Container, "TOPLEFT", 1 + totalWidth, -1 - DB.Height)
147+
element.PowerBarBorder:SetHeight(1)
148+
element.PowerBarBorder:Show()
179149

180150
for i = 1, currentMaxPower do
181151
local bar = element[i]
182152
bar:ClearAllPoints()
183153
bar:SetPoint("TOPLEFT", unitFrame.Container, "TOPLEFT", 1 + ((i - 1) * unitFrameWidth), -1)
184154
bar:SetSize(unitFrameWidth, DB.Height)
185-
bar:SetStatusBarTexture(UUF.Media.Foreground)
186-
bar.Background:SetAllPoints(bar)
187-
bar.Background:SetTexture(UUF.Media.Background)
188155
bar.Background:SetVertexColor(DB.Background[1], DB.Background[2], DB.Background[3], DB.Background[4] or 1)
156+
bar:Show()
189157
end
190158

191159
for i = 1, currentMaxPower - 1 do
192160
local tick = element.Ticks[i]
193161
tick:ClearAllPoints()
194162
tick:SetSize(1, DB.Height)
163+
tick:SetVertexColor(0, 0, 0, 1)
195164
tick:SetPoint("TOPLEFT", unitFrame.Container, "TOPLEFT", 1 + (i * unitFrameWidth) - 0.5, -1)
196165
tick:Show()
197166
end
198167

168+
for i = currentMaxPower, #element.Ticks do
169+
element.Ticks[i]:Hide()
170+
end
171+
172+
if isRunes then
173+
element.colorSpec = DB.ColourByType
174+
end
175+
176+
if element.PostUpdateColor then
177+
element:PostUpdateColor()
178+
end
179+
199180
UUF:UpdateHealthBarLayout(unitFrame, unit)
200181
element:ForceUpdate()
201182
end

0 commit comments

Comments
 (0)