2525function UUF :CreateUnitSecondaryPowerBar (unitFrame , unit )
2626 local FrameDB = UUF .db .profile .Units [UUF :GetNormalizedUnit (unit )].Frame
2727 local DB = UUF .db .profile .Units [UUF :GetNormalizedUnit (unit )].SecondaryPowerBar
28- local container = unitFrame .Container
28+ local unitFrameContainer = unitFrame .Container
2929
3030 if not DB .Enabled then return end
3131
3232 local powerType = UUF :GetSecondaryPowerType ()
3333 if not powerType and not UUF :IsRunePower () then return end
3434
35- local element = {}
36- element .Ticks = {}
35+ local secondaryPowerElement = {}
36+ secondaryPowerElement .Ticks = {}
3737
3838 local maxPower = UUF :IsRunePower () and 6 or (UnitPowerMax (" player" , powerType ) or 6 )
3939 local totalWidth = FrameDB .Width - 2
4040 local unitFrameWidth = totalWidth / maxPower
4141
42- element .ContainerBackground = container :CreateTexture (nil , " BACKGROUND" )
43- element .ContainerBackground :SetTexture (UUF .Media .Background )
42+ secondaryPowerElement .ContainerBackground = unitFrameContainer :CreateTexture (nil , " BACKGROUND" )
43+ secondaryPowerElement .ContainerBackground :SetTexture (UUF .Media .Background )
4444
4545 for i = 1 , maxPower do
46- local bar = CreateFrame (" StatusBar" , nil , container )
47- bar :SetStatusBarTexture (UUF .Media .Foreground )
48- bar :SetMinMaxValues (0 , 1 )
49- bar .frequentUpdates = DB .Smooth
50- bar :Hide ()
46+ local secondaryPowerBar = CreateFrame (" StatusBar" , nil , unitFrameContainer )
47+ secondaryPowerBar :SetStatusBarTexture (UUF .Media .Foreground )
48+ secondaryPowerBar :SetMinMaxValues (0 , 1 )
49+ secondaryPowerBar .frequentUpdates = DB .Smooth
50+ secondaryPowerBar :Hide ()
5151
52- bar .Background = bar :CreateTexture (nil , " BACKGROUND" )
53- bar .Background :SetAllPoints (bar )
54- bar .Background :SetTexture (UUF .Media .Background )
52+ secondaryPowerBar .Background = secondaryPowerBar :CreateTexture (nil , " BACKGROUND" )
53+ secondaryPowerBar .Background :SetAllPoints (secondaryPowerBar )
54+ secondaryPowerBar .Background :SetTexture (UUF .Media .Background )
5555
56- element [i ] = bar
56+ secondaryPowerElement [i ] = secondaryPowerBar
5757 end
5858
59- element .OverlayFrame = CreateFrame (" Frame" , nil , container )
60- element .OverlayFrame :SetFrameLevel (container :GetFrameLevel () + 10 )
59+ secondaryPowerElement .OverlayFrame = CreateFrame (" Frame" , nil , unitFrameContainer )
60+ secondaryPowerElement .OverlayFrame :SetFrameLevel (unitFrameContainer :GetFrameLevel () + 10 )
6161
6262 for i = 1 , maxPower - 1 do
63- local tick = element .OverlayFrame :CreateTexture (nil , " OVERLAY" )
64- tick :SetTexture (" Interface\\ Buttons\\ WHITE8x8" )
65- tick :SetDrawLayer (" OVERLAY" , 7 )
66- element .Ticks [i ] = tick
63+ local secondaryPowerBarTick = secondaryPowerElement .OverlayFrame :CreateTexture (nil , " OVERLAY" )
64+ secondaryPowerBarTick :SetTexture (" Interface\\ Buttons\\ WHITE8x8" )
65+ secondaryPowerBarTick :SetDrawLayer (" OVERLAY" , 7 )
66+ secondaryPowerElement .Ticks [i ] = secondaryPowerBarTick
6767 end
6868
69- element .PowerBarBorder = element .OverlayFrame :CreateTexture (nil , " OVERLAY" )
70- element .PowerBarBorder :SetTexture (" Interface\\ Buttons\\ WHITE8x8" )
71- element .PowerBarBorder :SetDrawLayer (" OVERLAY" , 6 )
69+ secondaryPowerElement .PowerBarBorder = secondaryPowerElement .OverlayFrame :CreateTexture (nil , " OVERLAY" )
70+ secondaryPowerElement .PowerBarBorder :SetTexture (" Interface\\ Buttons\\ WHITE8x8" )
71+ secondaryPowerElement .PowerBarBorder :SetDrawLayer (" OVERLAY" , 6 )
7272
73- element .PostUpdateColor = function (self )
73+ secondaryPowerElement .PostUpdateColor = function (self )
7474 if DB .ColourByType then return end
7575 for i = 1 , # self do
7676 self [i ]:SetStatusBarColor (DB .Foreground [1 ], DB .Foreground [2 ], DB .Foreground [3 ], DB .Foreground [4 ] or 1 )
7777 end
7878 end
7979
8080 if UUF :IsRunePower () then
81- element .sortOrder = " asc"
82- element .colorSpec = DB .ColourByType
83- unitFrame .Runes = element
81+ secondaryPowerElement .sortOrder = " asc"
82+ secondaryPowerElement .colorSpec = DB .ColourByType
83+ unitFrame .Runes = secondaryPowerElement
8484 else
85- unitFrame .ClassPower = element
85+ unitFrame .ClassPower = secondaryPowerElement
8686 end
8787
88- return element
88+ return secondaryPowerElement
8989end
9090
9191function UUF :UpdateUnitSecondaryPowerBar (unitFrame , unit )
@@ -94,61 +94,62 @@ function UUF:UpdateUnitSecondaryPowerBar(unitFrame, unit)
9494 local FrameDB = UUF .db .profile .Units [UUF :GetNormalizedUnit (unit )].Frame
9595 local DB = UUF .db .profile .Units [UUF :GetNormalizedUnit (unit )].SecondaryPowerBar
9696 local isRunes = UUF :IsRunePower ()
97- local elementName = isRunes and " Runes" or " ClassPower"
97+ local secondaryPowerBarElementName = isRunes and " Runes" or " ClassPower"
9898
9999 local powerType = UUF :GetSecondaryPowerType ()
100100 if not DB .Enabled or (not powerType and not isRunes ) then
101- if unitFrame [elementName ] then
102- if unitFrame :IsElementEnabled (elementName ) then
103- unitFrame :DisableElement (elementName )
101+ if unitFrame [secondaryPowerBarElementName ] then
102+ if unitFrame :IsElementEnabled (secondaryPowerBarElementName ) then
103+ unitFrame :DisableElement (secondaryPowerBarElementName )
104104 end
105- local element = unitFrame [elementName ]
106- for i = 1 , # element do element [i ]:Hide () end
107- for i = 1 , # element .Ticks do element .Ticks [i ]:Hide () end
108- if element .ContainerBackground then element .ContainerBackground :Hide () end
109- if element .PowerBarBorder then element .PowerBarBorder :Hide () end
110- if element .OverlayFrame then element .OverlayFrame :Hide () end
111- unitFrame [elementName ] = nil
105+ local secondaryPowerBarElement = unitFrame [secondaryPowerBarElementName ]
106+ for i = 1 , # secondaryPowerBarElement do secondaryPowerBarElement [i ]:Hide () end
107+ for i = 1 , # secondaryPowerBarElement .Ticks do secondaryPowerBarElement .Ticks [i ]:Hide () end
108+ if secondaryPowerBarElement .ContainerBackground then secondaryPowerBarElement .ContainerBackground :Hide () end
109+ if secondaryPowerBarElement .PowerBarBorder then secondaryPowerBarElement .PowerBarBorder :Hide () end
110+ if secondaryPowerBarElement .OverlayFrame then secondaryPowerBarElement .OverlayFrame :Hide () end
111+ unitFrame [secondaryPowerBarElementName ] = nil
112112 end
113113 UUF :UpdateHealthBarLayout (unitFrame , unit )
114114 return
115115 end
116116
117117 local currentMaxPower = isRunes and 6 or (UnitPowerMax (" player" , powerType ) or 6 )
118- local element = unitFrame [elementName ]
118+ local secondaryPowerBarElement = unitFrame [secondaryPowerBarElementName ]
119119
120- if not element or # element ~= currentMaxPower then
121- if element and unitFrame :IsElementEnabled (elementName ) then
122- unitFrame :DisableElement (elementName )
120+ if not secondaryPowerBarElement or # secondaryPowerBarElement ~= currentMaxPower then
121+ if secondaryPowerBarElement and unitFrame :IsElementEnabled (secondaryPowerBarElementName ) then
122+ unitFrame :DisableElement (secondaryPowerBarElementName )
123123 end
124- unitFrame [elementName ] = UUF :CreateUnitSecondaryPowerBar (unitFrame , unit )
125- element = unitFrame [elementName ]
126- if not element then return end
127- unitFrame :EnableElement (elementName )
124+ unitFrame [secondaryPowerBarElementName ] = UUF :CreateUnitSecondaryPowerBar (unitFrame , unit )
125+ secondaryPowerBarElement = unitFrame [secondaryPowerBarElementName ]
126+ if not secondaryPowerBarElement then return end
127+ unitFrame :EnableElement (secondaryPowerBarElementName )
128128 end
129129
130130 local totalWidth = FrameDB .Width - 2
131131 local unitFrameWidth = totalWidth / currentMaxPower
132132
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 ()
133+ secondaryPowerBarElement .ContainerBackground :SetSize (totalWidth , DB .Height )
134+ secondaryPowerBarElement .ContainerBackground :SetVertexColor (DB .Background [1 ], DB .Background [2 ], DB .Background [3 ], DB .Background [4 ] or 1 )
135+ secondaryPowerBarElement .ContainerBackground :ClearAllPoints ()
136+ secondaryPowerBarElement .ContainerBackground :SetPoint (" TOPLEFT" , unitFrame .Container , " TOPLEFT" , 1 , - 1 )
137+ secondaryPowerBarElement .ContainerBackground :Show ()
138138
139- element .OverlayFrame :SetAllPoints (unitFrame .Container )
140- element .OverlayFrame :SetFrameLevel (unitFrame .Container :GetFrameLevel () + 10 )
141- element .OverlayFrame :Show ()
142139
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 ()
140+ secondaryPowerBarElement .OverlayFrame :SetAllPoints (unitFrame .Container )
141+ secondaryPowerBarElement .OverlayFrame :SetFrameLevel (unitFrame .Container :GetFrameLevel () + 10 )
142+ secondaryPowerBarElement .OverlayFrame :Show ()
143+
144+ secondaryPowerBarElement .PowerBarBorder :ClearAllPoints ()
145+ secondaryPowerBarElement .PowerBarBorder :SetVertexColor (0 , 0 , 0 , 1 )
146+ secondaryPowerBarElement .PowerBarBorder :SetPoint (" TOPLEFT" , unitFrame .Container , " TOPLEFT" , 1 , - 1 - DB .Height )
147+ secondaryPowerBarElement .PowerBarBorder :SetPoint (" TOPRIGHT" , unitFrame .Container , " TOPLEFT" , 1 + totalWidth , - 1 - DB .Height )
148+ secondaryPowerBarElement .PowerBarBorder :SetHeight (1 )
149+ secondaryPowerBarElement .PowerBarBorder :Show ()
149150
150151 for i = 1 , currentMaxPower do
151- local bar = element [i ]
152+ local bar = secondaryPowerBarElement [i ]
152153 bar :ClearAllPoints ()
153154 bar :SetPoint (" TOPLEFT" , unitFrame .Container , " TOPLEFT" , 1 + ((i - 1 ) * unitFrameWidth ), - 1 )
154155 bar :SetSize (unitFrameWidth , DB .Height )
@@ -157,26 +158,26 @@ function UUF:UpdateUnitSecondaryPowerBar(unitFrame, unit)
157158 end
158159
159160 for i = 1 , currentMaxPower - 1 do
160- local tick = element .Ticks [i ]
161+ local tick = secondaryPowerBarElement .Ticks [i ]
161162 tick :ClearAllPoints ()
162163 tick :SetSize (1 , DB .Height )
163164 tick :SetVertexColor (0 , 0 , 0 , 1 )
164165 tick :SetPoint (" TOPLEFT" , unitFrame .Container , " TOPLEFT" , 1 + (i * unitFrameWidth ) - 0.5 , - 1 )
165166 tick :Show ()
166167 end
167168
168- for i = currentMaxPower , # element .Ticks do
169- element .Ticks [i ]:Hide ()
169+ for i = currentMaxPower , # secondaryPowerBarElement .Ticks do
170+ secondaryPowerBarElement .Ticks [i ]:Hide ()
170171 end
171172
172173 if isRunes then
173- element .colorSpec = DB .ColourByType
174+ secondaryPowerBarElement .colorSpec = DB .ColourByType
174175 end
175176
176- if element .PostUpdateColor then
177- element :PostUpdateColor ()
177+ if secondaryPowerBarElement .PostUpdateColor then
178+ secondaryPowerBarElement :PostUpdateColor ()
178179 end
179180
180181 UUF :UpdateHealthBarLayout (unitFrame , unit )
181- element :ForceUpdate ()
182+ secondaryPowerBarElement :ForceUpdate ()
182183end
0 commit comments