@@ -4,7 +4,6 @@ local Mana = Grid2.statusPrototype:new("mana")
44local ManaAlt = Grid2 .statusPrototype :new (" manaalt" , false )
55local Power = Grid2 .statusPrototype :new (" power" ,false )
66local PowerAlt = Grid2 .statusPrototype :new (" poweralt" ,false )
7- local LowMana = Grid2 .statusPrototype :new (" lowmana" ,false )
87
98local max = math.max
109local fmt = string.format
@@ -16,6 +15,10 @@ local UnitPowerMax = UnitPowerMax
1615local unit_is_valid = Grid2 .roster_guids
1716local canaccessvalue = Grid2 .canaccessvalue
1817
18+ local ScaleTo100 = CurveConstants .ScaleTo100
19+ local format = string.format
20+ local fmtPercent = " %.0f%%"
21+
1922local statuses = {} -- Enabled statuses
2023
2124-- Methods shared by all statuses
@@ -66,26 +69,16 @@ function PowerAlt:IsActive(unit)
6669 return canaccessvalue (power ) and power > 0
6770end
6871
69- if Grid2 .secretsEnabled then
70- function PowerAlt :GetPercent (unit )
71- return UnitPowerPercent (unit ,10 ,false )
72- end
73- function PowerAlt :GetText (unit )
74- return AbbreviateLargeNumbers ( UnitPower (unit ,10 ) )
75- end
76- else
77- function PowerAlt :GetPercent (unit )
78- local m = UnitPowerMax (unit ,10 )
79- return m == 0 and 0 or max (UnitPower (unit ,10 ),0 ) / UnitPowerMax (unit ,10 )
80- end
81- function PowerAlt :GetText (unit )
82- local power = UnitPower (unit ,10 )
83- if power >= 1000 then
84- return fmt (" %.1fk" , power / 1000 )
85- else
86- return tostring ( max (power ,0 ) )
87- end
88- end
72+ function PowerAlt :GetPercentText (unit )
73+ return format ( fmtPercent , UnitPowerPercent (unit , 10 , false , ScaleTo100 ) )
74+ end
75+
76+ function PowerAlt :GetPercent (unit )
77+ return UnitPowerPercent (unit ,10 ,false )
78+ end
79+
80+ function PowerAlt :GetText (unit )
81+ return AbbreviateLargeNumbers ( UnitPower (unit ,10 ) )
8982end
9083
9184Grid2 .setupFunc [" poweralt" ] = function (baseKey , dbx )
@@ -125,27 +118,16 @@ function Power:GetColor(unit)
125118 return c .r , c .g , c .b , c .a
126119end
127120
128- if Grid2 .secretsEnabled then
129- -- local ScaleTo100 = CurveConstants.ScaleTo100
130- function Power :GetPercent (unit )
131- return UnitPowerPercent (unit ,nil ,false )
132- end
133- function Power :GetText (unit )
134- return AbbreviateLargeNumbers ( UnitPower (unit ) )
135- end
136- else
137- function Power :GetPercent (unit )
138- local m = UnitPowerMax (unit )
139- return m == 0 and 0 or UnitPower (unit ) / m
140- end
141- function Power :GetText (unit )
142- local power = UnitPower (unit )
143- if power >= 1000 then
144- return fmt (" %.1fk" , power / 1000 )
145- else
146- return tostring (power )
147- end
148- end
121+ function Power :GetPercentText (unit )
122+ return format ( fmtPercent , UnitPowerPercent (unit , nil , false , ScaleTo100 ) )
123+ end
124+
125+ function Power :GetPercent (unit )
126+ return UnitPowerPercent (unit ,nil ,false )
127+ end
128+
129+ function Power :GetText (unit )
130+ return AbbreviateLargeNumbers ( UnitPower (unit ) )
149131end
150132
151133function Power :UpdateDB ()
@@ -164,6 +146,7 @@ function Power:UpdateDB()
164146 powerColors [" POWER_TYPE_RED_POWER" ] = self .dbx .color2 -- garrison proving grounds for friendly NPCs
165147 self .IsActive = self .filtered and self .IsActiveFilter or self .IsActiveStandard
166148 self .UpdateUnitPower = self .filtered and self .UpdateUnitPowerFilter or self .UpdateUnitPowerStandard
149+ fmtPercent = Grid2 .db .profile .formatting .percentFormat
167150end
168151
169152Grid2 .setupFunc [" power" ] = function (baseKey , dbx )
@@ -221,22 +204,16 @@ local function Mana_IsActiveSecondaryF(self, unit)
221204 return not self .filtered [unit ] and UnitPowerMax (unit ,0 )~= 0 and UnitPowerType (unit )~= 0
222205end
223206
224- local Mana_GetPercent , Mana_GetText
225- if Grid2 .secretsEnabled then
226- function Mana_GetPercent (self , unit )
227- return UnitPowerPercent (unit ,0 ,false )
228- end
229- function Mana_GetText (self , unit )
230- return AbbreviateLargeNumbers ( UnitPower (unit ,0 ) )
231- end
232- else
233- function Mana_GetPercent (self , unit )
234- local m = UnitPowerMax (unit ,0 )
235- return m == 0 and 0 or UnitPower (unit ,0 ) / m
236- end
237- function Mana_GetText (self , unit )
238- return fmt (" %.1fk" , UnitPower (unit ,0 ) / 1000 )
239- end
207+ local function Mana_GetPercentText (self , unit )
208+ return format ( fmtPercent , UnitPowerPercent (unit , 0 , false , ScaleTo100 ) )
209+ end
210+
211+ local function Mana_GetPercent (self , unit )
212+ return UnitPowerPercent (unit ,0 ,false )
213+ end
214+
215+ local function Mana_GetText (self , unit )
216+ return AbbreviateLargeNumbers ( UnitPower (unit ,0 ) )
240217end
241218
242219local function Mana_UpdateDB (self )
254231Mana .GetColor = Grid2 .statusLibrary .GetColor
255232Mana .OnEnable = status_OnEnable
256233Mana .OnDisable = status_OnDisable
234+ Mana .GetPercentText = Mana_GetPercentText
257235Mana .GetPercent = Mana_GetPercent
258236Mana .GetText = Mana_GetText
259237Mana .UpdateDB = Mana_UpdateDB
@@ -269,6 +247,7 @@ Grid2:DbSetStatusDefaultValue( "mana", {type = "mana", color1= {r=0,g=0,b=1,a=1}
269247ManaAlt .GetColor = Grid2 .statusLibrary .GetColor
270248ManaAlt .OnEnable = status_OnEnable
271249ManaAlt .OnDisable = status_OnDisable
250+ ManaAlt .GetPercentText = Mana_GetPercentText
272251ManaAlt .GetPercent = Mana_GetPercent
273252ManaAlt .GetText = Mana_GetText
274253ManaAlt .UpdateDB = Mana_UpdateDB
@@ -279,36 +258,3 @@ Grid2.setupFunc["manaalt"] = function(baseKey, dbx)
279258end
280259
281260Grid2 :DbSetStatusDefaultValue ( " manaalt" , {type = " manaalt" , displayType = 2 , color1 = {r = 0 ,g = 0 ,b = 1 ,a = 1 }} )
282-
283- -- Low Mana status, not available in Midnight
284- if Grid2 .secretsEnabled then return end
285-
286- local lowManaThreshold
287-
288- LowMana .GetColor = Grid2 .statusLibrary .GetColor
289- LowMana .OnEnable = status_OnEnable
290- LowMana .OnDisable = status_OnDisable
291-
292- function LowMana :UpdateUnitPower (unit , powerType )
293- if powerType == " MANA" then
294- self :UpdateIndicators (unit )
295- end
296- end
297-
298- function LowMana :IsActive (unit )
299- if UnitPowerType (unit )== 0 then
300- local m = UnitPowerMax (unit )
301- return ( m == 0 and 0 or UnitPower (unit )/ m ) < lowManaThreshold
302- end
303- end
304-
305- function LowMana :UpdateDB ()
306- lowManaThreshold = self .dbx .threshold
307- end
308-
309- Grid2 .setupFunc [" lowmana" ] = function (baseKey , dbx )
310- Grid2 :RegisterStatus (LowMana , {" color" }, baseKey , dbx )
311- return LowMana
312- end
313-
314- Grid2 :DbSetStatusDefaultValue ( " lowmana" , {type = " lowmana" , threshold = 0.75 , color1 = {r = 0.5 ,g = 0 ,b = 1 ,a = 1 }})
0 commit comments