local UnitLevel, UnitClassification = UnitLevel, UnitClassification;
local RAID_CLASS_COLORS = RAID_CLASS_COLORS;
+local updateAuraFrames = OmaUFAuras.UpdateAuras;
+
local Settings = OmaUFSettings;
local baseColor = Settings.BaseColor;
-local overlayColorDispel = Settings.OverlayColorDispel;
-local overlayColorCharm = Settings.OverlayColorCharm;
-local overlayColorAlert = Settings.OverlayColorAlert;
+local healthColor = Settings.HealthColor;
local powerColors = Settings.PowerColors;
-local width = 10;
local M = {};
OmaUFEvents = M;
frame:RegisterUnitEvent("UNIT_POWER", frame.unit, displayed);
frame:RegisterUnitEvent("UNIT_MAXPOWER", frame.unit, displayed);
frame:RegisterUnitEvent("UNIT_DISPLAYPOWER", frame.unit, displayed);
+ frame:RegisterUnitEvent("UNIT_POWER_BAR_SHOW", frame.unit, displayed);
+ frame:RegisterUnitEvent("UNIT_POWER_BAR_HIDE", frame.unit, displayed);
frame:RegisterUnitEvent("UNIT_NAME_UPDATE", frame.unit, displayed);
frame:RegisterUnitEvent("UNIT_AURA", frame.unit, displayed);
frame:RegisterUnitEvent("UNIT_HEAL_PREDICTION", frame.unit, displayed);
max = frame.health.max;
if current > max then
-- error state, still over maximum
- frame.health:SetWidth(width);
+ frame.health:SetWidth(frame.width);
return;
end
elseif max > 0 then
- frame.health:SetWidth(current/frame.health.max*width);
+ frame.health:SetWidth(current/frame.health.max*frame.width);
else
- frame.health:SetWidth(width);
+ frame.health:SetWidth(frame.width);
return;
end
elseif not UnitIsConnected(unit) then
frame.healthText:SetText("DC");
frame.healthText:Show();
- elseif max > 0 and current < max then
- frame.healthText:SetText(ceil(current/max*100));
+ elseif max > 0 then
+ if current > 1200000000 then -- 1.2B
+ frame.healthText:SetFormattedText("%.1fB", current / 1000000000);
+ elseif current > 1200000 then -- 1.2M
+ frame.healthText:SetFormattedText("%.1fM", current / 1000000);
+ elseif current > 1000 then -- 1K
+ frame.healthText:SetFormattedText("%.1fK", current / 1000);
+ else
+ frame.healthText:SetFormattedText("%d", current)
+ end
frame.healthText:Show();
else
frame.healthText:Hide();
max = frame.mana.max;
if current > max then
-- error
- frame.mana:SetWidth(width);
+ frame.mana:SetWidth(frame.width);
return;
end
end
if max > 0 then
- frame.mana:SetWidth(UnitPower(unit)/max*width);
+ frame.mana:SetWidth(UnitPower(unit)/max*frame.width);
frame.mana:Show();
else
- frame.mana:SetWidth(width);
+ frame.mana:SetWidth(frame.width);
frame.mana:Show();
end
end
end
local function updateName(frame, unit)
+ if not frame.name then return end
local name = UnitName(unit);
if not name then return end
frame.name:SetText(ssub(name, 1, 10));
-
- local _, class = UnitClass(unit);
- local color = RAID_CLASS_COLORS[class];
- if color then frame.name:SetVertexColor(color.r, color.g, color.b) end
end
local function updateHealPred(frame, unit)
local incoming = UnitGetIncomingHeals(unit) or 0;
if incoming > 0 then
local max = frame.health.max;
- local space = width - frame.health:GetWidth() + 1;
- local pred = (incoming / max) * width;
+ local space = frame.width - frame.health:GetWidth() + 1;
+ local pred = (incoming / max) * frame.width;
frame.healpred:SetWidth(min(space, pred));
frame.healpred:Show();
else
local shield = UnitGetTotalAbsorbs(unit) or 0;
if shield > 0 then
local max = frame.health.max;
- local space = width - frame.health:GetWidth();
- shield = (shield / max) * width;
+ local space = frame.width - frame.health:GetWidth();
+ shield = (shield / max) * frame.width;
if space == 0 then
frame.shield:Hide();
frame.shieldhl:Show();
if absorb > 0 then
local max = frame.health.max;
local space = frame.health:GetWidth();
- absorb = (absorb / max) * width;
+ absorb = (absorb / max) * frame.width;
frame.healabsorb:SetWidth(min(space, absorb));
frame.healabsorb:Show();
else
end
local function updateAuras(frame, unit)
- if UnitIsFriend("player", unit) and UnitDebuff(unit, 1, "RAID") ~= nil then
- -- something dispellable
- if frame.overlay.color ~= overlayColorDispel then
- frame.overlay:SetVertexColor(unpack(overlayColorDispel));
- frame.overlay:Show();
- frame.overlay.color = overlayColorDispel;
- end
- -- don't overlay charmed when in vehicle
- elseif UnitIsCharmed(unit) and unit == frame.unit then
- if frame.overlay.color ~= overlayColorCharm then
- frame.overlay:SetVertexColor(unpack(overlayColorCharm));
- frame.overlay:Show();
- frame.overlay.color = overlayColorCharm;
- end
- else
- if frame.overlay.color ~= nil then
- frame.overlay:Hide();
- frame.overlay.color = nil;
- end
- end
+ updateAuraFrames(frame, unit);
end
local function updateAggro(frame, unit)
end
local function updateLevelText(frame, unit, levelup)
+ if not frame.level then return end
if levelup then
-- PLAYER_LEVEL_UP
frame.level:SetText(levelup);
end
end
+local function updateHealthColor(frame, unit)
+ if not UnitPlayerControlled(unit) and UnitIsTapDenied(unit) then
+ frame.health:SetVertexColor(0.5, 0.5, 0.5);
+ elseif UnitIsPlayer(unit) then
+ local _, class = UnitClass(unit);
+ local color = RAID_CLASS_COLORS[class];
+ if color then
+ frame.health:SetVertexColor(color.r, color.g, color.b)
+ else
+ frame.health:SetVertexColor(unpack(healthColor))
+ end
+ elseif UnitPlayerControlled(unit) then
+ frame.health:SetVertexColor(0, 1, 0);
+ else
+ frame.health:SetVertexColor(UnitSelectionColor(unit));
+ end
+end
+
local eventFuncs = {
["UNIT_HEALTH"] = function(frame)
updateHealth(frame, frame.displayed);
end,
["UNIT_DISPLAYPOWER"] = function(frame)
updatePowerColor(frame, frame.displayed);
+ updateMaxPower(frame, frame.displayed);
+ updatePower(frame, frame.displayed);
+ updatePowerText(frame, frame.displayed);
end,
["UNIT_NAME_UPDATE"] = function(frame)
updateName(frame, frame.displayed);
+ updateHealthColor(frame, frame.displayed);
end,
["UNIT_CONNECTION"] = function(frame)
updateHealthText(frame, frame.displayed);
end,
["UNIT_FACTION"] = function(frame)
updatePVP(frame, frame.unit);
+ updateHealthColor(frame, frame.displayed);
end,
["PARTY_LEADER_CHANGED"] = function(frame)
updateLeaderIcon(frame, frame.unit);
updateStatus(frame, frame.unit);
updatePVP(frame, frame.unit);
updateLeaderIcon(frame, frame.unit);
+ updateHealthColor(frame, frame.displayed);
end,
};
eventFuncs["UNIT_HEALTH_FREQUENT"] = eventFuncs["UNIT_HEALTH"];
+eventFuncs["UNIT_POWER_BAR_SHOW"] = eventFuncs["UNIT_DISPLAYPOWER"];
+eventFuncs["UNIT_POWER_BAR_HIDE"] = eventFuncs["UNIT_DISPLAYPOWER"];
eventFuncs["UNIT_ENTERED_VEHICLE"] = eventFuncs["UPDATE_ALL_BARS"];
eventFuncs["UNIT_EXITED_VEHICLE"] = eventFuncs["UPDATE_ALL_BARS"];
eventFuncs["UNIT_PET"] = eventFuncs["UPDATE_ALL_BARS"];
function M.UnitEvent(self, event, arg1)
eventFuncs[event](self, arg1);
end
-
-function M.LoadChar()
- width = Settings.Character.Width;
-end