From 3a379989dc22d9669f626877de32b8d95ec7457e Mon Sep 17 00:00:00 2001 From: michaelsp Date: Sat, 10 Feb 2024 00:31:09 +0100 Subject: [PATCH] Added an option to health-current status to include shields values into health amount (github issue #202) --- Options/locales/deDE.lua | 1 + Options/locales/enUS.lua | 1 + Options/locales/esES.lua | 1 + Options/locales/frFR.lua | 1 + Options/locales/itIT.lua | 1 + Options/locales/koKR.lua | 1 + Options/locales/ptBR.lua | 1 + Options/locales/ruRU.lua | 1 + Options/locales/zhCN.lua | 1 + Options/locales/zhTW.lua | 1 + Options/modules/statuses/StatusHealth.lua | 15 ++++- modules/StatusHealth.lua | 73 +++++++++++++---------- 12 files changed, 65 insertions(+), 33 deletions(-) diff --git a/Options/locales/deDE.lua b/Options/locales/deDE.lua index 7bdb948d..0af59a78 100644 --- a/Options/locales/deDE.lua +++ b/Options/locales/deDE.lua @@ -816,6 +816,7 @@ L["Frequent Updates"] = "Häufigere Aktualisierungen" -- L["Update frequency"] = "" -- L["Select the health update frequency."] = "" -- L["Add shields to health percent"] = "" +-- L["Add shields to health amount"] = "" -- health-low status -- L["Use Health Percent"] = "" diff --git a/Options/locales/enUS.lua b/Options/locales/enUS.lua index 953858fd..9b49066b 100644 --- a/Options/locales/enUS.lua +++ b/Options/locales/enUS.lua @@ -824,6 +824,7 @@ L["Instant"] = true L["Update frequency"] = true L["Select the health update frequency."] = true L["Add shields to health percent"] = true +L["Add shields to health amount"] = true -- health-low status L["Use Health Percent"] = true diff --git a/Options/locales/esES.lua b/Options/locales/esES.lua index bb5d2c1f..dc5c8d62 100644 --- a/Options/locales/esES.lua +++ b/Options/locales/esES.lua @@ -821,6 +821,7 @@ L["Instant"] = "Instantaneo" L["Update frequency"] = "Frecuencia de actualizaciones" L["Select the health update frequency."] = "Elige la frequencia de actualización de las vidas." L["Add shields to health percent"] = "Añade escudos al porcentaje de vida" +L["Add shields to health amount"] = "Añade escudos al valor de vida" -- health-low status L["Use Health Percent"] = "Usar Porcentajes" diff --git a/Options/locales/frFR.lua b/Options/locales/frFR.lua index d7c4c7be..bc590608 100644 --- a/Options/locales/frFR.lua +++ b/Options/locales/frFR.lua @@ -819,6 +819,7 @@ L["Frequent Updates"] = "Mises à jour fréquentes" -- L["Update frequency"] = "" -- L["Select the health update frequency."] = "" -- L["Add shields to health percent"] = "" +-- L["Add shields to health amount"] = "" -- health-low status -- L["Use Health Percent"] = "" diff --git a/Options/locales/itIT.lua b/Options/locales/itIT.lua index fe7c0db5..86554614 100644 --- a/Options/locales/itIT.lua +++ b/Options/locales/itIT.lua @@ -819,6 +819,7 @@ L["Normal"] = "Normale" -- L["Update frequency"] = "" -- L["Select the health update frequency."] = "" -- L["Add shields to health percent"] = "" +-- L["Add shields to health amount"] = "" -- health-low status -- L["Use Health Percent"] = "" diff --git a/Options/locales/koKR.lua b/Options/locales/koKR.lua index 16cb641a..6104db4a 100644 --- a/Options/locales/koKR.lua +++ b/Options/locales/koKR.lua @@ -819,6 +819,7 @@ L["Instant"] = "즉시" L["Update frequency"] = "업데이트 빈도" L["Select the health update frequency."] = "생명력 업데이트 빈도 선택" -- L["Add shields to health percent"] = "" +-- L["Add shields to health amount"] = "" -- health-low status L["Use Health Percent"] = "생명력 비율(%) 사용" diff --git a/Options/locales/ptBR.lua b/Options/locales/ptBR.lua index 4a3432df..42b1e8ec 100644 --- a/Options/locales/ptBR.lua +++ b/Options/locales/ptBR.lua @@ -819,6 +819,7 @@ L["%s Color"] = "%s" -- L["Update frequency"] = "" -- L["Select the health update frequency."] = "" -- L["Add shields to health percent"] = "" +-- L["Add shields to health amount"] = "" -- health-low status -- L["Use Health Percent"] = "" diff --git a/Options/locales/ruRU.lua b/Options/locales/ruRU.lua index 3de681ad..1ed1dd25 100644 --- a/Options/locales/ruRU.lua +++ b/Options/locales/ruRU.lua @@ -819,6 +819,7 @@ L["Instant"] = "мгновенно" L["Update frequency"] = "Частота обновления" L["Select the health update frequency."] = "Выберите частоту обновления здоровья." -- L["Add shields to health percent"] = "" +-- L["Add shields to health amount"] = "" -- health-low status L["Use Health Percent"] = "Использовать процент здоровья" diff --git a/Options/locales/zhCN.lua b/Options/locales/zhCN.lua index 24ba3d62..c5e5698b 100644 --- a/Options/locales/zhCN.lua +++ b/Options/locales/zhCN.lua @@ -820,6 +820,7 @@ L["Instant"] = "立刻" L["Update frequency"] = "更新的频率" L["Select the health update frequency."] = "选择生命值更新频率" -- L["Add shields to health percent"] = "" +-- L["Add shields to health amount"] = "" -- health-low status L["Use Health Percent"] = "使用生命值的百分比" diff --git a/Options/locales/zhTW.lua b/Options/locales/zhTW.lua index 48bd2fd2..c492d1b0 100644 --- a/Options/locales/zhTW.lua +++ b/Options/locales/zhTW.lua @@ -820,6 +820,7 @@ L["Normal"] = "一般" -- L["Update frequency"] = "" -- L["Select the health update frequency."] = "" -- L["Add shields to health percent"] = "" +-- L["Add shields to health amount"] = "" -- health-low status -- L["Use Health Percent"] = "" diff --git a/Options/modules/statuses/StatusHealth.lua b/Options/modules/statuses/StatusHealth.lua index cdd7b99f..8c1fd55b 100644 --- a/Options/modules/statuses/StatusHealth.lua +++ b/Options/modules/statuses/StatusHealth.lua @@ -113,7 +113,7 @@ Grid2Options:RegisterStatusOptions("health-current", "health", function(self, st end, } else - options.healthShield = { + options.healthPercentShield = { type = "toggle", tristate = false, width = "full", @@ -126,6 +126,19 @@ Grid2Options:RegisterStatusOptions("health-current", "health", function(self, st status:Refresh() end, } + options.healthAmountShield = { + type = "toggle", + tristate = false, + width = "full", + order = 51, + name = L["Add shields to health amount"], + desc = L["Add shields to health amount"], + get = function () return status.dbx.addAmountShield end, + set = function (_, v) + status.dbx.addAmountShield = v or nil + status:Refresh() + end, + } end options.deadAsFullHealth = { type = "toggle", diff --git a/modules/StatusHealth.lua b/modules/StatusHealth.lua index 41c9e07b..7171c46c 100644 --- a/modules/StatusHealth.lua +++ b/modules/StatusHealth.lua @@ -230,6 +230,7 @@ end -- health-current status HealthCurrent.IsActive = Grid2.statusLibrary.IsActive +-- percent health local function HealthCurrent_ShieldUpdate(unit) if unit_is_valid[unit] then HealthCurrent:UpdateIndicators(unit) @@ -241,20 +242,6 @@ local function HealthCurrent_GetPercentTextShield(self, unit) return fmt( fmtPercent, m == 0 and 0 or (UnitHealth(unit)+UnitGetTotalAbsorbs(unit))*100/m ) end -function HealthCurrent:OnEnable() - Health_Enable(self) - if self.addShield then - RegisterEvent( "UNIT_ABSORB_AMOUNT_CHANGED", HealthCurrent_ShieldUpdate ) - end -end - -function HealthCurrent:OnDisable() - Health_Disable(self) - if self.addShield then - UnregisterEvent( "UNIT_ABSORB_AMOUNT_CHANGED" ) - end -end - local function HealthCurrent_GetPercentSTD(self,unit) local m = UnitHealthMax(unit) return m == 0 and 0 or UnitHealth(unit) / m @@ -266,20 +253,37 @@ local function HealthCurrent_GetPercentDFH(self, unit) return m == 0 and 1 or UnitHealth(unit) / m end -if Grid2.isClassic then - function HealthCurrent:GetText1(unit) - local h = UnitHealth(unit) - return h<1000 and fmt("%d",h) or fmt("%.1fk",h/1000) - end - function HealthCurrent:GetText2(unit) - return tostring(UnitHealth(unit)) +-- text health +local function HealthCurrent_GetTextClassic(self, unit) + local h = UnitHealth(unit) + return h<1000 and fmt("%d",h) or fmt("%.1fk",h/1000) +end + +local function HealthCurrent_GetTextClassicRaw(self, unit) + return tostring(UnitHealth(unit)) +end + +local function HealthCurrent_GetTextRetail(self, unit) + return fmt("%.1fk", UnitHealth(unit) / 1000) +end + +local function HealthCurrent_GetTextRetailShield(self, unit) + return fmt("%.1fk", (UnitHealth(unit)+UnitGetTotalAbsorbs(unit)) / 1000) +end + +function HealthCurrent:OnEnable() + Health_Enable(self) + if self.addShield then + RegisterEvent( "UNIT_ABSORB_AMOUNT_CHANGED", HealthCurrent_ShieldUpdate ) end -else - function HealthCurrent:GetText1(unit) - return fmt("%.1fk", UnitHealth(unit) / 1000) +end + +function HealthCurrent:OnDisable() + Health_Disable(self) + if self.addShield then + UnregisterEvent( "UNIT_ABSORB_AMOUNT_CHANGED" ) end end -HealthCurrent.GetText = HealthCurrent.GetText1 function HealthCurrent:GetColor(unit) local f,t @@ -293,14 +297,19 @@ function HealthCurrent:GetColor(unit) end function HealthCurrent:UpdateDB() + local dbx = self.dbx fmtPercent = Grid2.db.profile.formatting.percentFormat - self.addShield = Grid2.isWoW90 and self.dbx.addPercentShield or nil - self.GetText = self.dbx.displayRawNumbers and self.GetText2 or self.GetText1 - self.GetPercent = self.dbx.deadAsFullHealth and HealthCurrent_GetPercentDFH or HealthCurrent_GetPercentSTD - self.GetPercentText = self.addShield and HealthCurrent_GetPercentTextShield or nil - self.color1 = Grid2:MakeColor(self.dbx.color1) - self.color2 = Grid2:MakeColor(self.dbx.color2) - self.color3 = Grid2:MakeColor(self.dbx.color3) + if Grid2.isClassic then + self.GetText = dbx.displayRawNumbers and HealthCurrent_GetTextClassicRaw or HealthCurrent_GetTextClassic + else + self.addShield = (dbx.addPercentShield or dbx.addAmountShield) or nil + self.GetText = dbx.addAmountShield and HealthCurrent_GetTextRetailShield or HealthCurrent_GetTextRetail + self.GetPercentText = dbx.addPercentShield and HealthCurrent_GetPercentTextShield or nil + end + self.GetPercent = dbx.deadAsFullHealth and HealthCurrent_GetPercentDFH or HealthCurrent_GetPercentSTD + self.color1 = Grid2:MakeColor(dbx.color1) + self.color2 = Grid2:MakeColor(dbx.color2) + self.color3 = Grid2:MakeColor(dbx.color3) Health_UpdateStatuses() end