end
local registerUnitEvents = M.RegisterUnitEvents;
+local function updateMaxHealth(frame, unit)
+ frame.health.max = UnitHealthMax(unit);
+end
+
local function updateHealth(frame, unit)
local current, max = UnitHealth(unit), frame.health.max;
- frame.health:Show();
- -- sanity check, occasionally UnitHealthMax gives zero
- if current > max then
- -- somehow current health has gone over the maximum (missed maxhealth event)
- frame.health.max = UnitHealthMax(unit);
- max = frame.health.max;
- if current > max then
- -- error state, still over maximum
- frame.health:SetWidth(width);
- return;
- end
- elseif max > 0 then
- frame.health:SetWidth(current/frame.health.max*width);
- else
+ if current > max or max <= 0 then
+ -- somehow current health has gone over the maximum (missed maxhealth event possibly)
+ -- just put health bar full and update max health for next event
frame.health:SetWidth(width);
- return;
- end
-
- if UnitIsDeadOrGhost(unit) then
+ updateMaxHealth(frame, unit);
+ frame.health:Show();
+ elseif UnitIsDeadOrGhost(unit) then
frame.health:Hide();
+ else
+ frame.health:SetWidth(current/max*width);
+ frame.health:Show();
end
end
local function updateText(frame, unit)
- local current, max = UnitHealth(unit), frame.health.max;
- local healthLost = max - current;
+ local healthLost = frame.health.max - UnitHealth(unit);
if UnitIsDeadOrGhost(unit) then
frame.text:SetText("Dead");
frame.text:Show();
end
local function updateIncomingRes(frame, unit)
- if UnitHasIncomingResurrection(unit) then
- frame.rez:Show();
- else
- frame.rez:Hide();
- end
+ if UnitHasIncomingResurrection(unit) then frame.rez:Show();
+ else frame.rez:Hide(); end
end
-local function updateMaxHealth(frame, unit)
- frame.health.max = UnitHealthMax(unit);
+local function updateMaxPower(frame, unit)
+ frame.mana.max = UnitPowerMax(unit);
end
local function updatePower(frame, unit)
local current, max = UnitPower(unit), frame.mana.max;
- -- sanity check, occasionally UnitPowerMax gives zero
- if current > max then
- frame.mana.max = UnitPowerMax(unit);
- max = frame.mana.max;
- if current > max then
- -- error
- frame.mana:SetWidth(width);
- return;
- end
- elseif max > 0 then
- frame.mana:SetWidth(UnitPower(unit)/max*width);
- else
+ if current > max or max <= 0 then
frame.mana:SetWidth(width);
+ updateMaxPower(frame, unit);
+ else
+ frame.mana:SetWidth(current/max*width);
end
end
-local function updateMaxPower(frame, unit)
- frame.mana.max = UnitPowerMax(unit);
-end
-
local function updatePowerColor(frame, unit)
frame.mana:SetVertexColor(unpack(powerColors[UnitPowerType(unit)]));
end
local function updateHealPred(frame, unit)
local incoming = UnitGetIncomingHeals(unit) or 0;
if incoming > 0 then
- local max = frame.health.max;
+ -- always at least 1 pixel space for heal prediction
local space = width - frame.health:GetWidth() + 1;
- local pred = (incoming / max) * width;
- frame.healpred:SetWidth(min(space, pred));
+ incoming = (incoming / frame.health.max) * width;
+ frame.healpred:SetWidth(min(space, incoming));
frame.healpred:Show();
else
frame.healpred:Hide();
if shield > 0 then
local max = frame.health.max;
local space = width - frame.health:GetWidth();
- shield = (shield / max) * width;
+ shield = (shield / frame.health.max) * width;
if space < shield then
frame.shield:SetWidth(space);
frame.shieldhl:Show();
local function updateHealAbsorb(frame, unit)
local absorb = UnitGetTotalHealAbsorbs(unit) or 0;
if absorb > 0 then
- local max = frame.health.max;
local space = frame.health:GetWidth();
- absorb = (absorb / max) * width;
+ absorb = (absorb / frame.health.max) * width;
frame.healabsorb:SetWidth(min(space, absorb));
frame.healabsorb:Show();
else
if alert then
if frame.overlay.color ~= overlayColorAlert then
frame.overlay:SetVertexColor(unpack(overlayColorAlert));
- frame.overlay:Show();
frame.overlay.color = overlayColorAlert;
+ frame.overlay:Show();
end
elseif 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;
+ frame.overlay:Show();
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;
+ frame.overlay:Show();
end
else
if frame.overlay.color ~= nil then
- frame.overlay:Hide();
frame.overlay.color = nil;
+ frame.overlay:Hide();
end
end
end
end
local function updateVehicle(frame)
- local shouldTargetVehicle = UnitHasVehicleUI(frame.unit) and UnitTargetsVehicleInRaidUI(frame.unit) and UnitExists(frame.vehicle);
+ local shouldTargetVehicle = UnitHasVehicleUI(frame.unit) and
+ UnitTargetsVehicleInRaidUI(frame.unit) and UnitExists(frame.vehicle);
if shouldTargetVehicle then
if not frame.inVehicle then
frame.inVehicle = true;
frame.overlay = frame:CreateTexture(nil, "ARTWORK", nil, 1);
frame.overlay:SetPoint("TOPLEFT", frame.background, "TOPLEFT");
frame.overlay:SetPoint("BOTTOMRIGHT", frame.background, "BOTTOMRIGHT");
- frame.overlay:SetColorTexture(1, 1, 1);
+ frame.overlay:SetTexture("Interface\\RaidFrame\\Raid-Bar-Hp-Fill");
frame.overlay:Hide();
frame.name = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
frame.name:SetPoint("CENTER", frame.background, "CENTER", 0, 11);
-- let other addons hook these to anchor tooltip elsewhere
GameTooltip = _G["GameTooltip"];
GameTooltip_SetDefaultAnchor = _G["GameTooltip_SetDefaultAnchor"];
+ _, class = UnitClass("player");
loadCharSettings();
- class = UnitClass("player");
CFrame:SetPoint("CENTER", nil, "CENTER", anchorX, anchorY);
CFrame:SetHeight((height+2)*8);
CFrame:SetWidth((width+2)*5);