X-Git-Url: https://www.aleksib.fi/git/wowui.git/blobdiff_plain/8f4bc830f37b66724627f90628b8e3179ad98440..6d5df6677a8d4e1dc16b0707dbe31f18d179b3b3:/RaidFrameHealth.lua diff --git a/RaidFrameHealth.lua b/RaidFrameHealth.lua index dbed189..3ed8555 100644 --- a/RaidFrameHealth.lua +++ b/RaidFrameHealth.lua @@ -1,35 +1,35 @@ -hooksecurefunc("CompactUnitFrame_UpdateStatusText", - function(frame) - if frame and not frame:IsForbidden() then - local frameName = frame:GetName(); - if frameName and frameName:match("^CompactRaidFrame%d") and frame.unit then - -- conditions taken from CompactUnitFrame.lua - if not UnitIsConnected(frame.unit) or UnitIsDeadOrGhost(frame.displayedUnit) then - return; - elseif ( frame.optionTable.healthText == "losthealth" ) then - -- only losthealth option is condensed - local healthLost = UnitHealthMax(frame.displayedUnit) - UnitHealth(frame.displayedUnit); - local prettyHealth; - if healthLost > 1200000000 then -- 1.2B - local h1b = healthLost / 1000000000; - local h100m = (healthLost % 1000000000) / 100000000; - prettyHealth = string.format("-%d.%dB", h1b, h100m); - elseif healthLost > 1200000 then -- 1.2M - prettyHealth = string.format("-%dM", healthLost / 1000000); - elseif healthLost > 1000 then -- 1K - prettyHealth = string.format("-%dK", healthLost / 1000); - else - prettyHealth = string.format("-%d", healthLost) - end +local UnitIsConnected = UnitIsConnected; +local UnitIsDeadOrGhost = UnitIsDeadOrGhost; +local UnitHealthMax = UnitHealthMax; +local UnitHealth = UnitHealth; - if healthLost > 0 then - frame.statusText:SetText(prettyHealth); - frame.statusText:Show(); - else - frame.statusText:Hide(); - end +hooksecurefunc("CompactUnitFrame_UpdateStatusText", function(frame) + if frame and not frame:IsForbidden() then + local frameName = frame:GetName(); + if frameName and frameName:match("^CompactRaidFrame%d") and frame.unit then + -- conditions taken from CompactUnitFrame.lua + if not UnitIsConnected(frame.unit) or UnitIsDeadOrGhost(frame.displayedUnit) then + return; + elseif (frame.optionTable.healthText == "losthealth") then + -- only losthealth option is condensed + local healthLost = UnitHealthMax(frame.displayedUnit) - UnitHealth(frame.displayedUnit); + if healthLost <= 0 then return end + + local prettyHealth; + if healthLost > 1200000000 then -- 1.2B + local h1b = healthLost / 1000000000; + local h100m = (healthLost % 1000000000) / 100000000; + prettyHealth = string.format("-%d.%dB", h1b, h100m); + elseif healthLost > 1200000 then -- 1.2M + prettyHealth = string.format("-%dM", healthLost / 1000000); + elseif healthLost > 1000 then -- 1K + prettyHealth = string.format("-%dK", healthLost / 1000); + else + prettyHealth = string.format("-%d", healthLost) end + + frame.statusText:SetText(prettyHealth); end end end -); +end);