X-Git-Url: https://www.aleksib.fi/git/wowui.git/blobdiff_plain/7cd9b15270a53b3c833f41e00ed755a30e22b2ef..084e0f6c357adbd2cdefd88dd5b6c45ba81d783a:/OmaRF/Events.lua?ds=sidebyside diff --git a/OmaRF/Events.lua b/OmaRF/Events.lua index aeafc6a..7c31381 100644 --- a/OmaRF/Events.lua +++ b/OmaRF/Events.lua @@ -90,34 +90,28 @@ function M.RegisterUnitEvents(frame) 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(); @@ -147,39 +141,24 @@ local function updateText(frame, unit) 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 @@ -197,10 +176,10 @@ 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(); @@ -212,7 +191,7 @@ local function updateShield(frame, unit) 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(); @@ -230,9 +209,8 @@ end 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 @@ -245,27 +223,27 @@ local function updateAuras(frame, unit) 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 @@ -280,7 +258,8 @@ local function updateAggro(frame, unit) 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;