Harden real health text updates
This commit is contained in:
+50
-43
@@ -1,8 +1,6 @@
|
||||
local _G = ShaguTweaks.GetGlobalEnv()
|
||||
local T = ShaguTweaks.T
|
||||
local Abbreviate = ShaguTweaks.Abbreviate
|
||||
local GetColorGradient = ShaguTweaks.GetColorGradient
|
||||
local vanilla = ShaguTweaks.GetExpansion() == "vanilla" or nil
|
||||
local hooksecurefunc = hooksecurefunc or ShaguTweaks.hooksecurefunc
|
||||
|
||||
local module = ShaguTweaks:register({
|
||||
title = T["Real Health Numbers"],
|
||||
@@ -12,6 +10,20 @@ local module = ShaguTweaks:register({
|
||||
enabled = false,
|
||||
})
|
||||
|
||||
local function SetStatusText(fontString, text)
|
||||
if fontString:GetText() ~= text then
|
||||
fontString:SetText(text)
|
||||
end
|
||||
fontString:Show()
|
||||
end
|
||||
|
||||
local function HideStatusText(fontString)
|
||||
fontString:Hide()
|
||||
if fontString:GetText() ~= "" then
|
||||
fontString:SetText("")
|
||||
end
|
||||
end
|
||||
|
||||
module.enable = function(self)
|
||||
TargetFrame.StatusTexts = CreateFrame("Frame", nil, TargetFrame)
|
||||
TargetFrame.StatusTexts:SetAllPoints(TargetFrame)
|
||||
@@ -25,63 +37,58 @@ module.enable = function(self)
|
||||
PetFrameHealthBar.TextString:SetPoint("CENTER", PetFrameHealthBar, "CENTER", -2, 0)
|
||||
PetFrameManaBar.TextString:SetPoint("CENTER", PetFrameManaBar, "CENTER", -2, -2)
|
||||
|
||||
for _, frame in pairs( { TargetFrameHealthBar, TargetFrameManaBar, PlayerFrameHealthBar, PlayerFrameManaBar }) do
|
||||
local largeBars = { TargetFrameHealthBar, TargetFrameManaBar, PlayerFrameHealthBar, PlayerFrameManaBar }
|
||||
for i = 1, table.getn(largeBars) do
|
||||
local frame = largeBars[i]
|
||||
frame.TextString:SetFontObject("GameFontWhite")
|
||||
frame.TextString:SetFont(STANDARD_TEXT_FONT, 10, "OUTLINE")
|
||||
frame.TextString:SetHeight(32)
|
||||
end
|
||||
|
||||
for _, frame in pairs( { PetFrameHealthBar, PetFrameManaBar }) do
|
||||
local petBars = { PetFrameHealthBar, PetFrameManaBar }
|
||||
for i = 1, table.getn(petBars) do
|
||||
local frame = petBars[i]
|
||||
frame.TextString:SetFontObject("GameFontWhite")
|
||||
frame.TextString:SetFont(STANDARD_TEXT_FONT, 9, "OUTLINE")
|
||||
frame.TextString:SetHeight(32)
|
||||
frame.TextString:SetJustifyH("LEFT")
|
||||
end
|
||||
|
||||
local HookTextStatusBar_UpdateTextString = TextStatusBar_UpdateTextString
|
||||
function TextStatusBar_UpdateTextString(sb)
|
||||
local function UpdateHealthText(sb)
|
||||
if not sb then sb = this end
|
||||
if not sb or not sb.TextString or not sb.unit then return end
|
||||
|
||||
HookTextStatusBar_UpdateTextString(sb)
|
||||
local string = sb.TextString
|
||||
sb.lockShow = 42
|
||||
sb:Show()
|
||||
|
||||
if string and sb.unit then
|
||||
-- hide tbc text string element
|
||||
if not vanilla then
|
||||
TargetFrameHealthBarText:Hide()
|
||||
end
|
||||
local min, max = sb:GetMinMaxValues()
|
||||
local cur = sb:GetValue()
|
||||
local percent = max > 0 and floor(cur / max * 100) or 0
|
||||
local name = sb:GetName() or ""
|
||||
|
||||
sb.lockShow = 42
|
||||
sb:Show()
|
||||
if name == "TargetFrameHealthBar" then
|
||||
cur, max = ShaguTweaks.libhealth:GetUnitHealth(sb.unit)
|
||||
end
|
||||
|
||||
local min, max = sb:GetMinMaxValues()
|
||||
local cur = sb:GetValue()
|
||||
local percent = max > 0 and floor(cur/max*100) or 0
|
||||
local text
|
||||
if cur == percent and strfind(name, "Health") then
|
||||
text = percent .. "/" .. percent
|
||||
elseif name == "TargetFrameHealthBar" and cur < max then
|
||||
text = Abbreviate(cur) .. "/" .. Abbreviate(max) .. " - " .. percent .. "%"
|
||||
else
|
||||
text = Abbreviate(cur) .. "/" .. Abbreviate(max)
|
||||
end
|
||||
|
||||
if sb:GetName() == "TargetFrameHealthBar" then
|
||||
cur, max = ShaguTweaks.libhealth:GetUnitHealth(sb.unit)
|
||||
end
|
||||
|
||||
if cur == percent and strfind(sb:GetName(), "Health") then
|
||||
string:SetText(percent .. "/" .. percent)
|
||||
elseif sb:GetName() == "TargetFrameHealthBar" and cur < max then
|
||||
string:SetText(Abbreviate(cur) .. "/" .. Abbreviate(max) .. " - " .. percent .. "%")
|
||||
else
|
||||
string:SetText(Abbreviate(cur) .. "/" .. Abbreviate(max))
|
||||
end
|
||||
|
||||
if max == 0 then
|
||||
string:Hide()
|
||||
string:SetText("")
|
||||
elseif sb.unit == "target" and UnitIsDead("target") then
|
||||
string:Hide()
|
||||
string:SetText("")
|
||||
elseif sb.unit == "target" and UnitIsGhost("target") then
|
||||
string:Hide()
|
||||
string:SetText("")
|
||||
else
|
||||
string:Show()
|
||||
end
|
||||
if max == 0 or
|
||||
(sb.unit == "target" and (UnitIsDead("target") or UnitIsGhost("target"))) then
|
||||
HideStatusText(sb.TextString)
|
||||
else
|
||||
SetStatusText(sb.TextString, text)
|
||||
end
|
||||
end
|
||||
|
||||
-- Append our custom text update instead of replacing the global Blizzard
|
||||
-- function. This keeps the module cooperative with other UI addons that also
|
||||
-- hook TextStatusBar_UpdateTextString.
|
||||
hooksecurefunc("TextStatusBar_UpdateTextString", UpdateHealthText)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user