56591cf - Delete unnecessary libraries
[wowui.git] / OmaRF / UpdateStatusTextHook.lua
1 local UnitIsConnected = UnitIsConnected;
2 local UnitIsDeadOrGhost = UnitIsDeadOrGhost;
3 local UnitHealthMax = UnitHealthMax;
4 local UnitHealth = UnitHealth;
5 local format = string.format
6
7 hooksecurefunc("CompactUnitFrame_UpdateStatusText", function(frame)
8     -- allowClassColorsForNPCs only in regular raid frames,
9     -- match only to them
10     if frame.optionTable.allowClassColorsForNPCs ~= nil then
11         -- conditions taken from CompactUnitFrame.lua
12         if not UnitIsConnected(frame.unit) or UnitIsDeadOrGhost(frame.displayedUnit) then
13             return;
14         elseif (frame.optionTable.healthText == "losthealth") then
15             -- only losthealth option is condensed
16             local healthLost = UnitHealthMax(frame.displayedUnit) - UnitHealth(frame.displayedUnit);
17             if healthLost <= 0 then return end
18
19             local prettyHealth;
20             if healthLost > 1200000000 then -- 1.2B
21                 local h1b = healthLost / 1000000000;
22                 local h100m = (healthLost % 1000000000) / 100000000;
23                 prettyHealth = format("-%d.%dB", h1b, h100m);
24             elseif healthLost > 1200000 then -- 1.2M
25                 prettyHealth = format("-%dM", healthLost / 1000000);
26             elseif healthLost > 1000 then -- 1K
27                 prettyHealth = format("-%dK", healthLost / 1000);
28             else
29                 prettyHealth = format("-%d", healthLost)
30             end
31
32             frame.statusText:SetText(prettyHealth);
33         end
34     end
35 end);