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 T = ShaguTweaks.T
|
||||||
local Abbreviate = ShaguTweaks.Abbreviate
|
local Abbreviate = ShaguTweaks.Abbreviate
|
||||||
local GetColorGradient = ShaguTweaks.GetColorGradient
|
local hooksecurefunc = hooksecurefunc or ShaguTweaks.hooksecurefunc
|
||||||
local vanilla = ShaguTweaks.GetExpansion() == "vanilla" or nil
|
|
||||||
|
|
||||||
local module = ShaguTweaks:register({
|
local module = ShaguTweaks:register({
|
||||||
title = T["Real Health Numbers"],
|
title = T["Real Health Numbers"],
|
||||||
@@ -12,6 +10,20 @@ local module = ShaguTweaks:register({
|
|||||||
enabled = false,
|
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)
|
module.enable = function(self)
|
||||||
TargetFrame.StatusTexts = CreateFrame("Frame", nil, TargetFrame)
|
TargetFrame.StatusTexts = CreateFrame("Frame", nil, TargetFrame)
|
||||||
TargetFrame.StatusTexts:SetAllPoints(TargetFrame)
|
TargetFrame.StatusTexts:SetAllPoints(TargetFrame)
|
||||||
@@ -25,63 +37,58 @@ module.enable = function(self)
|
|||||||
PetFrameHealthBar.TextString:SetPoint("CENTER", PetFrameHealthBar, "CENTER", -2, 0)
|
PetFrameHealthBar.TextString:SetPoint("CENTER", PetFrameHealthBar, "CENTER", -2, 0)
|
||||||
PetFrameManaBar.TextString:SetPoint("CENTER", PetFrameManaBar, "CENTER", -2, -2)
|
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:SetFontObject("GameFontWhite")
|
||||||
frame.TextString:SetFont(STANDARD_TEXT_FONT, 10, "OUTLINE")
|
frame.TextString:SetFont(STANDARD_TEXT_FONT, 10, "OUTLINE")
|
||||||
frame.TextString:SetHeight(32)
|
frame.TextString:SetHeight(32)
|
||||||
end
|
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:SetFontObject("GameFontWhite")
|
||||||
frame.TextString:SetFont(STANDARD_TEXT_FONT, 9, "OUTLINE")
|
frame.TextString:SetFont(STANDARD_TEXT_FONT, 9, "OUTLINE")
|
||||||
frame.TextString:SetHeight(32)
|
frame.TextString:SetHeight(32)
|
||||||
frame.TextString:SetJustifyH("LEFT")
|
frame.TextString:SetJustifyH("LEFT")
|
||||||
end
|
end
|
||||||
|
|
||||||
local HookTextStatusBar_UpdateTextString = TextStatusBar_UpdateTextString
|
local function UpdateHealthText(sb)
|
||||||
function TextStatusBar_UpdateTextString(sb)
|
|
||||||
if not sb then sb = this end
|
if not sb then sb = this end
|
||||||
|
if not sb or not sb.TextString or not sb.unit then return end
|
||||||
|
|
||||||
HookTextStatusBar_UpdateTextString(sb)
|
sb.lockShow = 42
|
||||||
local string = sb.TextString
|
sb:Show()
|
||||||
|
|
||||||
if string and sb.unit then
|
local min, max = sb:GetMinMaxValues()
|
||||||
-- hide tbc text string element
|
local cur = sb:GetValue()
|
||||||
if not vanilla then
|
local percent = max > 0 and floor(cur / max * 100) or 0
|
||||||
TargetFrameHealthBarText:Hide()
|
local name = sb:GetName() or ""
|
||||||
end
|
|
||||||
|
|
||||||
sb.lockShow = 42
|
if name == "TargetFrameHealthBar" then
|
||||||
sb:Show()
|
cur, max = ShaguTweaks.libhealth:GetUnitHealth(sb.unit)
|
||||||
|
end
|
||||||
|
|
||||||
local min, max = sb:GetMinMaxValues()
|
local text
|
||||||
local cur = sb:GetValue()
|
if cur == percent and strfind(name, "Health") then
|
||||||
local percent = max > 0 and floor(cur/max*100) or 0
|
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
|
if max == 0 or
|
||||||
cur, max = ShaguTweaks.libhealth:GetUnitHealth(sb.unit)
|
(sb.unit == "target" and (UnitIsDead("target") or UnitIsGhost("target"))) then
|
||||||
end
|
HideStatusText(sb.TextString)
|
||||||
|
else
|
||||||
if cur == percent and strfind(sb:GetName(), "Health") then
|
SetStatusText(sb.TextString, text)
|
||||||
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
|
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user