dbed189a040f9c58956f6a65fb1eff9186f8e8ef
[wowui.git] / RaidFrameHealth.lua
1 hooksecurefunc("CompactUnitFrame_UpdateStatusText",
2     function(frame)
3         if frame and not frame:IsForbidden() then
4             local frameName = frame:GetName();
5             if frameName and frameName:match("^CompactRaidFrame%d") and frame.unit then
6                 -- conditions taken from CompactUnitFrame.lua
7                 if not UnitIsConnected(frame.unit) or UnitIsDeadOrGhost(frame.displayedUnit) then
8                     return;
9                 elseif ( frame.optionTable.healthText == "losthealth" ) then
10                     -- only losthealth option is condensed
11                     local healthLost = UnitHealthMax(frame.displayedUnit) - UnitHealth(frame.displayedUnit);
12                     local prettyHealth;
13                     if healthLost > 1200000000 then -- 1.2B
14                         local h1b = healthLost / 1000000000;
15                         local h100m = (healthLost % 1000000000) / 100000000;
16                         prettyHealth = string.format("-%d.%dB", h1b, h100m);
17                     elseif healthLost > 1200000 then -- 1.2M
18                         prettyHealth = string.format("-%dM", healthLost / 1000000);
19                     elseif healthLost > 1000 then -- 1K
20                         prettyHealth = string.format("-%dK", healthLost / 1000);
21                     else
22                         prettyHealth = string.format("-%d", healthLost)
23                     end
24
25                     if healthLost > 0 then
26                         frame.statusText:SetText(prettyHealth);
27                         frame.statusText:Show();
28                     else
29                         frame.statusText:Hide();
30                     end
31                 end
32             end
33         end
34     end
35 );