X-Git-Url: https://www.aleksib.fi/git/wowui.git/blobdiff_plain/60bc5ec4ced3b57fd841af7f693728049a0d09a0..7cd9b15270a53b3c833f41e00ed755a30e22b2ef:/OmaUF/Events.lua diff --git a/OmaUF/Events.lua b/OmaUF/Events.lua index 6e4fa69..cbc8b0a 100644 --- a/OmaUF/Events.lua +++ b/OmaUF/Events.lua @@ -1,11 +1,12 @@ -- Events.lua +-- TODO -- recheck these, pvp functions not added yet local _; local unpack = unpack; local ssub = string.sub; local min = math.min; local ceil = math.ceil; local UnitName, UnitClass, UnitExists = UnitName, UnitClass, UnitExists; -local UnitDebuff, UnitIsCharmed = UnitDebuff, UnitIsCharmed; +local UnitDebuff, UnitIsCharmed, UnitIsFriend = UnitDebuff, UnitIsCharmed, UnitIsFriend; local UnitPower, UnitPowerMax, UnitPowerType = UnitPower, UnitPowerMax, UnitPowerType; local UnitHealth, UnitHealthMax = UnitHealth, UnitHealthMax; local UnitGetIncomingHeals, UnitGetTotalAbsorbs = UnitGetIncomingHeals, UnitGetTotalAbsorbs; @@ -17,13 +18,12 @@ local UnitGroupRolesAssigned = UnitGroupRolesAssigned; 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; @@ -38,6 +38,8 @@ function M.RegisterEvents(frame) 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); @@ -59,13 +61,13 @@ local function updateHealth(frame, unit) 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 @@ -82,8 +84,16 @@ local function updateHealthText(frame, unit) 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(); @@ -106,15 +116,15 @@ local function updatePower(frame, unit) 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 @@ -140,21 +150,18 @@ local function updatePowerColor(frame, unit) 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 @@ -166,8 +173,8 @@ local function updateShield(frame, unit) 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(); @@ -191,7 +198,7 @@ local function updateHealAbsorb(frame, unit) 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 @@ -200,26 +207,7 @@ local function updateHealAbsorb(frame, unit) end local function updateAuras(frame, unit) - if 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) @@ -249,7 +237,7 @@ end local function updateRole(frame, unit) local role = UnitGroupRolesAssigned(unit); if role == "HEALER" or role == "TANK" or role == "DAMAGER" then - frame.role:SetTexCoord(GetTexCoordsForRole(role)); + frame.role:SetTexCoord(GetTexCoordsForRoleSmallCircle(role)); frame.role:Show(); else frame.role:Hide(); @@ -257,6 +245,7 @@ local function updateRole(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); @@ -324,6 +313,43 @@ local function updatePVP(frame, unit) end end +local function updateLeaderIcon(frame, unit) + if UnitIsGroupLeader(frame.unit) then + if HasLFGRestrictions() then + frame.leader:SetTexture("Interface\\LFGFrame\\UI-LFG-ICON-PORTRAITROLES"); + frame.leader:SetTexCoord(0, 0.296875, 0.015625, 0.3125); + else + frame.leader:SetTexture("Interface\\GROUPFRAME\\UI-Group-LeaderIcon"); + frame.leader:SetTexCoord(0, 1, 0, 1); + end + frame.leader:Show(); + elseif UnitIsGroupAssistant(frame.unit) then + frame.leader:SetTexture("Interface\\GROUPFRAME\\UI-Group-AssistantIcon"); + frame.leader:SetTexCoord(0, 1, 0, 1); + frame.leader:Show(); + else + frame.leader:Hide(); + 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); @@ -365,9 +391,13 @@ local eventFuncs = { 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); @@ -395,6 +425,10 @@ local eventFuncs = { end, ["UNIT_FACTION"] = function(frame) updatePVP(frame, frame.unit); + updateHealthColor(frame, frame.displayed); + end, + ["PARTY_LEADER_CHANGED"] = function(frame) + updateLeaderIcon(frame, frame.unit); end, ["UPDATE_ALL_BARS"] = function(frame) updateVehicle(frame); @@ -415,9 +449,13 @@ local eventFuncs = { updateLevelText(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"]; @@ -428,7 +466,3 @@ eventFuncs["PLAYER_TARGET_CHANGED"] = eventFuncs["UPDATE_ALL_BARS"]; function M.UnitEvent(self, event, arg1) eventFuncs[event](self, arg1); end - -function M.LoadChar() - width = Settings.Character.Width; -end