X-Git-Url: https://www.aleksib.fi/git/wowui.git/blobdiff_plain/fdbd89d788a6442f2fe57abb8f2321bd6c452889..3e6730c2c495d9016dde6cbb76c2bd6f86b05cbe:/OmaUF/Events.lua diff --git a/OmaUF/Events.lua b/OmaUF/Events.lua index fa8965a..862e7df 100644 --- a/OmaUF/Events.lua +++ b/OmaUF/Events.lua @@ -20,6 +20,7 @@ local UnitIsGroupLeader, UnitIsGroupAssistant = UnitIsGroupLeader, UnitIsGroupAs local HasLFGRestrictions = HasLFGRestrictions; local UnitPlayerControlled, UnitIsPlayer = UnitPlayerControlled, UnitIsPlayer; local UnitIsTapDenied, UnitSelectionColor = UnitIsTapDenied, UnitSelectionColor; +local GetRaidTargetIndex, SetRaidTargetIconTexture = GetRaidTargetIndex, SetRaidTargetIconTexture; local RAID_CLASS_COLORS = RAID_CLASS_COLORS; local updateAuraFrames = OmaUFAuras.UpdateAuras; @@ -32,23 +33,33 @@ local powerColors = Settings.PowerColors; local M = {}; OmaUFEvents = M; function M.RegisterUnitEvents(frame) - -- events are taken from FrameXML/CompactUnitFrame.lua - -- TODO raid marker support, - -- player flags support (/afk, /dnd) + -- events are taken from FrameXML/CompactUnitFrame.lua and FrameXML/TargetFrame.lua + -- TODO player flags support (/afk, /dnd) + frame:RegisterEvent("RAID_TARGET_UPDATE"); -- have to register all and just check local displayed = frame.unit ~= frame.displayed and frame.displayed or nil; frame:RegisterUnitEvent("UNIT_HEALTH", frame.unit, displayed); frame:RegisterUnitEvent("UNIT_HEALTH_FREQUENT", frame.unit, displayed); frame:RegisterUnitEvent("UNIT_MAXHEALTH", frame.unit, displayed); - 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); + if frame.mana then + 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); + end + if frame.healpred then + frame:RegisterUnitEvent("UNIT_HEAL_PREDICTION", frame.unit, displayed); + end + if frame.shield then + frame:RegisterUnitEvent("UNIT_ABSORB_AMOUNT_CHANGED", frame.unit, displayed); + end + if frame.healabsorb then + frame:RegisterUnitEvent("UNIT_HEAL_ABSORB_AMOUNT_CHANGED", frame.unit, displayed); + end + if frame.auras then + frame:RegisterUnitEvent("UNIT_AURA", frame.unit, displayed); + end frame:RegisterUnitEvent("UNIT_NAME_UPDATE", frame.unit, displayed); - frame:RegisterUnitEvent("UNIT_AURA", frame.unit, displayed); - frame:RegisterUnitEvent("UNIT_HEAL_PREDICTION", frame.unit, displayed); - frame:RegisterUnitEvent("UNIT_ABSORB_AMOUNT_CHANGED", frame.unit, displayed); - frame:RegisterUnitEvent("UNIT_HEAL_ABSORB_AMOUNT_CHANGED", frame.unit, displayed); frame:RegisterUnitEvent("UNIT_THREAT_SITUATION_UPDATE", frame.unit, displayed); frame:RegisterUnitEvent("UNIT_CONNECTION", frame.unit, displayed); frame:RegisterUnitEvent("UNIT_FACTION", frame.unit, displayed); @@ -79,12 +90,14 @@ local function updateHealthText(frame, unit) frame.healthText:SetText("Dead"); elseif not UnitIsConnected(unit) then frame.healthText:SetText("DC"); + elseif frame.healthText.percent then + frame.healthText:SetFormattedText("%.1f", UnitHealth(unit)/frame.health.max*100); else local current = UnitHealth(unit); - if current > 1200000000 then -- 1.2B - frame.healthText:SetFormattedText("%.1fB", current / 1000000000); - elseif current > 1200000 then -- 1.2M - frame.healthText:SetFormattedText("%.1fM", current / 1000000); + if current > 1000000000 then -- 1.0B + frame.healthText:SetFormattedText("%.2fB", current / 1000000000); + elseif current > 1000000 then -- 1.0M + frame.healthText:SetFormattedText("%.2fM", current / 1000000); elseif current > 1000 then -- 1K frame.healthText:SetFormattedText("%.1fK", current / 1000); else @@ -130,7 +143,7 @@ end local function updateName(frame, unit) local name = UnitName(unit); if not name then return end - frame.name:SetText(ssub(name, 1, 10)); + frame.name:SetText(ssub(name, 1, frame.name.count)); end local function updateHealPred(frame, unit) @@ -193,9 +206,10 @@ local function updateAggro(frame, unit) end end +-- only works for player frame local function updateVehicle(frame) - local shouldTargetVehicle = UnitHasVehicleUI(frame.unit) and - UnitTargetsVehicleInRaidUI(frame.unit) and UnitExists(frame.vehicle); + local shouldTargetVehicle = UnitHasVehicleUI("player") and + UnitTargetsVehicleInRaidUI("player") and UnitExists("vehicle"); if shouldTargetVehicle then if not frame.inVehicle then frame.inVehicle = true; @@ -314,12 +328,22 @@ local function updateHealthColor(frame, unit) end end +local function updateRaidMarker(frame, unit) + local index = GetRaidTargetIndex(unit); + if index then + SetRaidTargetIconTexture(frame.targeticon, index); + frame.targeticon:Show(); + else + frame.targeticon:Hide(); + end +end + local eventFuncs = { ["UNIT_HEALTH"] = function(frame) updateHealth(frame, frame.displayed); updateHealthText(frame, frame.displayed); - updateShield(frame, frame.displayed); - updateHealAbsorb(frame, frame.displayed); + if frame.shield then updateShield(frame, frame.displayed) end + if frame.healabsorb then updateHealAbsorb(frame, frame.displayed) end end, ["UNIT_POWER"] = function(frame) updatePower(frame, frame.displayed); @@ -344,8 +368,8 @@ local eventFuncs = { updateMaxHealth(frame, frame.displayed); updateHealth(frame, frame.displayed); updateHealthText(frame, frame.displayed); - updateShield(frame, frame.displayed); - updateHealAbsorb(frame, frame.displayed); + if frame.shield then updateShield(frame, frame.displayed) end + if frame.healabsorb then updateHealAbsorb(frame, frame.displayed) end end, ["UNIT_MAXPOWER"] = function(frame) updateMaxPower(frame, frame.displayed); @@ -392,26 +416,32 @@ local eventFuncs = { ["PARTY_LEADER_CHANGED"] = function(frame) updateLeaderIcon(frame, frame.unit); end, + ["RAID_TARGET_UPDATE"] = function(frame) + updateRaidMarker(frame, frame.displayed); + end, ["UPDATE_ALL_BARS"] = function(frame) if frame.vehicle then updateVehicle(frame) end updateMaxHealth(frame, frame.displayed); - updateMaxPower(frame, frame.displayed); updateHealth(frame, frame.displayed); updateHealthText(frame, frame.displayed); - updatePower(frame, frame.displayed); - updatePowerText(frame, frame.displayed); - updateAuras(frame, frame.displayed); - updateShield(frame, frame.displayed); - updateHealPred(frame, frame.displayed); - updateHealAbsorb(frame, frame.displayed); - updatePowerColor(frame, frame.displayed); + updateHealthColor(frame, frame.displayed); updateAggro(frame, frame.displayed); + updateRaidMarker(frame, frame.displayed); + if frame.mana then + updateMaxPower(frame, frame.displayed); + updatePower(frame, frame.displayed); + updatePowerText(frame, frame.displayed); + updatePowerColor(frame, frame.displayed); + end + if frame.auras then updateAuras(frame, frame.displayed) end + if frame.shield then updateShield(frame, frame.displayed) end + if frame.healpred then updateHealPred(frame, frame.displayed) end + if frame.healabsorb then updateHealAbsorb(frame, frame.displayed) end if frame.name then updateName(frame, frame.displayed) end if frame.level then updateLevelText(frame, frame.unit) end if frame.status then updateStatus(frame, frame.unit) end if frame.pvp then updatePVP(frame, frame.unit) end if frame.leader then updateLeaderIcon(frame, frame.unit) end - updateHealthColor(frame, frame.displayed); end, }; eventFuncs["UNIT_HEALTH_FREQUENT"] = eventFuncs["UNIT_HEALTH"]; @@ -423,6 +453,8 @@ eventFuncs["UNIT_PET"] = eventFuncs["UPDATE_ALL_BARS"]; eventFuncs["GROUP_ROSTER_UPDATE"] = eventFuncs["UPDATE_ALL_BARS"]; eventFuncs["PLAYER_ENTERING_WORLD"] = eventFuncs["UPDATE_ALL_BARS"]; eventFuncs["PLAYER_TARGET_CHANGED"] = eventFuncs["UPDATE_ALL_BARS"]; +eventFuncs["INSTANCE_ENCOUNTER_ENGAGE_UNIT"] = eventFuncs["UPDATE_ALL_BARS"]; +eventFuncs["UNIT_TARGETABLE_CHANGED"] = eventFuncs["UPDATE_ALL_BARS"]; function M.UnitEvent(self, event, arg1) eventFuncs[event](self, arg1);