Skip to content

Commit

Permalink
swapping some events around for health and power (this includes tags)
Browse files Browse the repository at this point in the history
  • Loading branch information
kodewdle committed Nov 30, 2024
1 parent ec75319 commit d5fb0e0
Show file tree
Hide file tree
Showing 16 changed files with 34 additions and 111 deletions.
16 changes: 8 additions & 8 deletions ElvUI/Core/General/Tags.lua
Original file line number Diff line number Diff line change
Expand Up @@ -274,23 +274,23 @@ for textFormat in pairs(E.GetFormattedTextStyles) do
return E:GetFormattedText(textFormat, UnitHealth(unit), UnitHealthMax(unit))
end)

E:AddTag(format('power:%s', tagFormat), 'UNIT_DISPLAYPOWER UNIT_POWER_FREQUENT UNIT_MAXPOWER', function(unit)
E:AddTag(format('power:%s', tagFormat), 'UNIT_DISPLAYPOWER UNIT_POWER_UPDATE UNIT_MAXPOWER', function(unit)
local powerType = UnitPowerType(unit)
local min = UnitPower(unit, powerType)
if min ~= 0 then
return E:GetFormattedText(textFormat, min, UnitPowerMax(unit, powerType))
end
end)

E:AddTag(format('additionalmana:%s', tagFormat), 'UNIT_POWER_FREQUENT UNIT_MAXPOWER UNIT_DISPLAYPOWER', function(unit)
E:AddTag(format('additionalmana:%s', tagFormat), 'UNIT_POWER_UPDATE UNIT_MAXPOWER UNIT_DISPLAYPOWER', function(unit)
local altIndex = _G.ALT_POWER_BAR_PAIR_DISPLAY_INFO[E.myclass]
local min = altIndex and altIndex[UnitPowerType(unit)] and UnitPower(unit, POWERTYPE_MANA)
if min and min ~= 0 then
return E:GetFormattedText(textFormat, min, UnitPowerMax(unit, POWERTYPE_MANA))
end
end, not E.Retail)

E:AddTag(format('mana:%s', tagFormat), 'UNIT_POWER_FREQUENT UNIT_MAXPOWER UNIT_DISPLAYPOWER', function(unit)
E:AddTag(format('mana:%s', tagFormat), 'UNIT_POWER_UPDATE UNIT_MAXPOWER UNIT_DISPLAYPOWER', function(unit)
local min = UnitPower(unit, POWERTYPE_MANA)
if min ~= 0 then
return E:GetFormattedText(textFormat, min, UnitPowerMax(unit, POWERTYPE_MANA))
Expand Down Expand Up @@ -328,19 +328,19 @@ for textFormat in pairs(E.GetFormattedTextStyles) do
return E:GetFormattedText(textFormat, min, max, nil, true)
end)

E:AddTag(format('power:%s:shortvalue', tagFormat), 'UNIT_DISPLAYPOWER UNIT_POWER_FREQUENT UNIT_MAXPOWER', function(unit)
E:AddTag(format('power:%s:shortvalue', tagFormat), 'UNIT_DISPLAYPOWER UNIT_POWER_UPDATE UNIT_MAXPOWER', function(unit)
local powerType = UnitPowerType(unit)
local min = UnitPower(unit, powerType)
if min ~= 0 and tagFormat ~= 'deficit' then
return E:GetFormattedText(textFormat, min, UnitPowerMax(unit, powerType), nil, true)
end
end)

E:AddTag(format('mana:%s:shortvalue', tagFormat), 'UNIT_POWER_FREQUENT UNIT_MAXPOWER', function(unit)
E:AddTag(format('mana:%s:shortvalue', tagFormat), 'UNIT_POWER_UPDATE UNIT_MAXPOWER', function(unit)
return E:GetFormattedText(textFormat, UnitPower(unit, POWERTYPE_MANA), UnitPowerMax(unit, POWERTYPE_MANA), nil, true)
end)

E:AddTag(format('additionalmana:%s:shortvalue', tagFormat), 'UNIT_POWER_FREQUENT UNIT_MAXPOWER UNIT_DISPLAYPOWER', function(unit)
E:AddTag(format('additionalmana:%s:shortvalue', tagFormat), 'UNIT_POWER_UPDATE UNIT_MAXPOWER UNIT_DISPLAYPOWER', function(unit)
local altIndex = _G.ALT_POWER_BAR_PAIR_DISPLAY_INFO[E.myclass]
local min = altIndex and altIndex[UnitPowerType(unit)] and UnitPower(unit, POWERTYPE_MANA)
if min and min ~= 0 and tagFormat ~= 'deficit' then
Expand Down Expand Up @@ -725,7 +725,7 @@ E:AddTag('classpowercolor', 'UNIT_POWER_FREQUENT UNIT_DISPLAYPOWER'..(E.Retail a
return Hex(r, g, b)
end, E.Classic)

E:AddTag('permana', 'UNIT_POWER_FREQUENT UNIT_DISPLAYPOWER', function(unit)
E:AddTag('permana', 'UNIT_POWER_UPDATE UNIT_DISPLAYPOWER', function(unit)
local m = UnitPowerMax(unit)
if m == 0 then
return 0
Expand All @@ -734,7 +734,7 @@ E:AddTag('permana', 'UNIT_POWER_FREQUENT UNIT_DISPLAYPOWER', function(unit)
end
end)

E:AddTag('manacolor', 'UNIT_POWER_FREQUENT UNIT_DISPLAYPOWER', function()
E:AddTag('manacolor', 'UNIT_POWER_UPDATE UNIT_DISPLAYPOWER', function()
local color = ElvUF.colors.power.MANA
return Hex(color.r, color.g, color.b)
end)
Expand Down
1 change: 0 additions & 1 deletion ElvUI/Core/Modules/Nameplates/Elements/Health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ function NP:Construct_HealthPrediction(nameplate)
HealthPrediction.healAbsorbBar:SetReverseFill(true)

HealthPrediction.maxOverflow = 1
HealthPrediction.frequentUpdates = true

return HealthPrediction
end
Expand Down
1 change: 0 additions & 1 deletion ElvUI/Core/Modules/Nameplates/Elements/Power.lua
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ function NP:Construct_Power(nameplate)

NP.StatusBars[Power] = true

Power.frequentUpdates = true
Power.colorTapping = false
Power.colorClass = false

Expand Down
6 changes: 2 additions & 4 deletions ElvUI/Core/Modules/Nameplates/Plugins/TargetIndicator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,9 @@ local function Enable(self)

if E.Classic then
self:RegisterEvent('UNIT_HEALTH_FREQUENT', Path)
else
self:RegisterEvent('UNIT_HEALTH', Path)
end

self:RegisterEvent('UNIT_HEALTH', Path)
self:RegisterEvent('UNIT_MAXHEALTH', Path)
self:RegisterEvent('PLAYER_TARGET_CHANGED', Path, true)

Expand All @@ -148,10 +147,9 @@ local function Disable(self)

if E.Classic then
self:UnregisterEvent('UNIT_HEALTH_FREQUENT', Path)
else
self:UnregisterEvent('UNIT_HEALTH', Path)
end

self:UnregisterEvent('UNIT_HEALTH', Path)
self:UnregisterEvent('UNIT_MAXHEALTH', Path)
self:UnregisterEvent('PLAYER_TARGET_CHANGED', Path)
end
Expand Down
6 changes: 2 additions & 4 deletions ElvUI/Core/Modules/Nameplates/StyleFilter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,7 @@ NP.StyleFilterDefaultEvents = { -- list of events style filter uses to populate
UNIT_CONNECTION = false,
UNIT_DISPLAYPOWER = false,
UNIT_MAXHEALTH = false,
UNIT_HEALTH = false,
UNIT_NAME_UPDATE = false,
UNIT_PET = false,
UNIT_POWER_UPDATE = false,
Expand Down Expand Up @@ -1406,8 +1407,6 @@ NP.StyleFilterDefaultEvents = { -- list of events style filter uses to populate

if E.Classic then
NP.StyleFilterDefaultEvents.UNIT_HEALTH_FREQUENT = false
else
NP.StyleFilterDefaultEvents.UNIT_HEALTH = false
end

NP.StyleFilterCastEvents = {
Expand Down Expand Up @@ -1494,11 +1493,10 @@ function NP:StyleFilterConfigure()

if t.healthThreshold then
events.UNIT_MAXHEALTH = 1
events.UNIT_HEALTH = 1

if E.Classic then
events.UNIT_HEALTH_FREQUENT = 1
else
events.UNIT_HEALTH = 1
end
end

Expand Down
1 change: 0 additions & 1 deletion ElvUI/Core/Modules/UnitFrames/Elements/ClassBars.lua
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,6 @@ end
function UF:Construct_AdditionalPowerBar(frame)
local additionalPower = CreateFrame('StatusBar', '$parent_AdditionalPowerBar', frame)
additionalPower.colorPower = true
additionalPower.frequentUpdates = true
additionalPower.PostUpdate = UF.PostUpdateAdditionalPower
additionalPower.PostUpdateColor = UF.PostColorAdditionalPower
additionalPower.PostVisibility = UF.PostVisibilityAdditionalPower
Expand Down
1 change: 0 additions & 1 deletion ElvUI/Core/Modules/UnitFrames/Units/Focus.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ function UF:Construct_FocusFrame(frame)

frame.Health = UF:Construct_HealthBar(frame, true, true, 'RIGHT')
frame.Power = UF:Construct_PowerBar(frame, true, true, 'LEFT')
frame.Power.frequentUpdates = true
frame.PowerPrediction = UF:Construct_PowerPrediction(frame)
frame.Name = UF:Construct_NameText(frame)
frame.Portrait3D = UF:Construct_Portrait(frame, 'model')
Expand Down
1 change: 0 additions & 1 deletion ElvUI/Core/Modules/UnitFrames/Units/Player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ function UF:Construct_PlayerFrame(frame)
frame.ThreatIndicator = UF:Construct_Threat(frame)
frame.Health = UF:Construct_HealthBar(frame, true, true, 'RIGHT')
frame.Power = UF:Construct_PowerBar(frame, true, true, 'LEFT')
frame.Power.frequentUpdates = true
frame.Name = UF:Construct_NameText(frame)
frame.Portrait3D = UF:Construct_Portrait(frame, 'model')
frame.Portrait2D = UF:Construct_Portrait(frame, 'texture')
Expand Down
1 change: 0 additions & 1 deletion ElvUI/Core/Modules/UnitFrames/Units/Target.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ function UF:Construct_TargetFrame(frame)

frame.Health = UF:Construct_HealthBar(frame, true, true, 'RIGHT')
frame.Power = UF:Construct_PowerBar(frame, true, true, 'LEFT')
frame.Power.frequentUpdates = true
frame.PowerPrediction = UF:Construct_PowerPrediction(frame)
frame.Name = UF:Construct_NameText(frame)
frame.Portrait3D = UF:Construct_Portrait(frame, 'model')
Expand Down
32 changes: 2 additions & 30 deletions ElvUI_Libraries/Core/oUF/elements/additionalpower.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ A default texture will be applied if the widget is a StatusBar and doesn't have
## Options
.frequentUpdates - Indicates whether to use UNIT_POWER_FREQUENT instead UNIT_POWER_UPDATE to update the bar (boolean)
.displayPairs - Use to override display pairs. (table)
.smoothGradient - 9 color values to be used with the .colorSmooth option (table)
Expand Down Expand Up @@ -174,12 +173,7 @@ end
local function ElementEnable(self)
local element = self.AdditionalPower

if(element.frequentUpdates) then
self:RegisterEvent('UNIT_POWER_FREQUENT', Path)
else
self:RegisterEvent('UNIT_POWER_UPDATE', Path)
end

self:RegisterEvent('UNIT_POWER_UPDATE', Path)
self:RegisterEvent('UNIT_MAXPOWER', Path)

element:Show()
Expand All @@ -192,9 +186,8 @@ end
local function ElementDisable(self)
local element = self.AdditionalPower

self:UnregisterEvent('UNIT_MAXPOWER', Path)
self:UnregisterEvent('UNIT_POWER_FREQUENT', Path)
self:UnregisterEvent('UNIT_POWER_UPDATE', Path)
self:UnregisterEvent('UNIT_MAXPOWER', Path)

element:Hide()

Expand Down Expand Up @@ -253,32 +246,11 @@ local function ForceUpdate(element)
return VisibilityPath(element.__owner, 'ForceUpdate', element.__owner.unit)
end

--[[ Power:SetFrequentUpdates(state, isForced)
Used to toggle frequent updates.
* self - the Power element
* state - the desired state (boolean)
* isForced - forces the event update even if the state wasn't changed (boolean)
--]]
local function SetFrequentUpdates(element, state, isForced)
if(element.frequentUpdates ~= state or isForced) then
element.frequentUpdates = state
if(state) then
oUF:UnregisterEvent(element.__owner, 'UNIT_POWER_UPDATE', Path)
oUF:RegisterEvent(element.__owner, 'UNIT_POWER_FREQUENT', Path)
else
oUF:UnregisterEvent(element.__owner, 'UNIT_POWER_FREQUENT', Path)
oUF:RegisterEvent(element.__owner, 'UNIT_POWER_UPDATE', Path)
end
end
end

local function Enable(self, unit)
local element = self.AdditionalPower
if(element and UnitIsUnit(unit, 'player')) then
element.__owner = self
element.ForceUpdate = ForceUpdate
element.SetFrequentUpdates = SetFrequentUpdates

oUF:RegisterEvent(self, 'UNIT_DISPLAYPOWER', VisibilityPath)

Expand Down
4 changes: 2 additions & 2 deletions ElvUI_Libraries/Core/oUF/elements/classpower.lua
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ end

do
function ClassPowerEnable(self)
self:RegisterEvent('UNIT_POWER_FREQUENT', Path)
self:RegisterEvent('UNIT_MAXPOWER', Path)
self:RegisterEvent('UNIT_POWER_UPDATE', Path)

if oUF.isRetail then -- according to Blizz any class may receive this event due to specific spell auras
self:RegisterEvent('UNIT_POWER_POINT_CHARGE', Path)
Expand All @@ -277,7 +277,7 @@ do
end

function ClassPowerDisable(self)
self:UnregisterEvent('UNIT_POWER_UPDATE', Path)
self:UnregisterEvent('UNIT_POWER_FREQUENT', Path)
self:UnregisterEvent('UNIT_MAXPOWER', Path)

if oUF.isRetail then
Expand Down
14 changes: 4 additions & 10 deletions ElvUI_Libraries/Core/oUF/elements/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -355,15 +355,12 @@ local function Enable(self)
element.SetColorThreat = SetColorThreat

oUF:RegisterEvent(self, 'UNIT_MAXHEALTH', Path)
oUF:RegisterEvent(self, 'UNIT_HEALTH', Path)

if oUF.isRetail then
oUF:RegisterEvent(self, 'UNIT_MAX_HEALTH_MODIFIERS_CHANGED', Path)
end

if oUF.isClassic then
elseif oUF.isClassic then
oUF:RegisterEvent(self, 'UNIT_HEALTH_FREQUENT', Path)
else
oUF:RegisterEvent(self, 'UNIT_HEALTH', Path)
end

if(element.colorDisconnected) then
Expand Down Expand Up @@ -414,14 +411,11 @@ local function Disable(self)

if oUF.isRetail then
oUF:UnregisterEvent(self, 'UNIT_MAX_HEALTH_MODIFIERS_CHANGED', Path)
end

if oUF.isClassic then
elseif oUF.isClassic then
oUF:UnregisterEvent(self, 'UNIT_HEALTH_FREQUENT', Path)
else
oUF:UnregisterEvent(self, 'UNIT_HEALTH', Path)
end

oUF:UnregisterEvent(self, 'UNIT_HEALTH', Path)
oUF:UnregisterEvent(self, 'UNIT_MAXHEALTH', Path)
oUF:UnregisterEvent(self, 'UNIT_CONNECTION', ColorPath)
oUF:UnregisterEvent(self, 'UNIT_FACTION', ColorPath)
Expand Down
6 changes: 2 additions & 4 deletions ElvUI_Libraries/Core/oUF/elements/healthprediction.lua
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,12 @@ local function Enable(self)
element.ForceUpdate = ForceUpdate
element.SetUseHealComm = SetUseHealComm

oUF:RegisterEvent(self, 'UNIT_HEALTH', Path)
oUF:RegisterEvent(self, 'UNIT_MAXHEALTH', Path)
oUF:RegisterEvent(self, 'UNIT_HEAL_PREDICTION', Path)

if oUF.isClassic then
oUF:RegisterEvent(self, 'UNIT_HEALTH_FREQUENT', Path)
else
oUF:RegisterEvent(self, 'UNIT_HEALTH', Path)
end

if oUF.isRetail then
Expand Down Expand Up @@ -415,13 +414,12 @@ local function Disable(self)
element.overHealAbsorb:Hide()
end

oUF:UnregisterEvent(self, 'UNIT_HEALTH', Path)
oUF:UnregisterEvent(self, 'UNIT_MAXHEALTH', Path)
oUF:UnregisterEvent(self, 'UNIT_HEAL_PREDICTION', Path)

if oUF.isClassic then
oUF:UnregisterEvent(self, 'UNIT_HEALTH_FREQUENT', Path)
else
oUF:UnregisterEvent(self, 'UNIT_HEALTH', Path)
end

if oUF.isRetail then
Expand Down
31 changes: 1 addition & 30 deletions ElvUI_Libraries/Core/oUF/elements/power.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ A default texture will be applied if the widget is a StatusBar and doesn't have
## Options
.frequentUpdates - Indicates whether to use UNIT_POWER_FREQUENT instead UNIT_POWER_UPDATE to update the
bar (boolean)
.displayAltPower - Use this to let the widget display alternative power, if the unit has one.
By default, it does so only for raid and party units. If none, the display will fall
back to the primary power (boolean)
Expand Down Expand Up @@ -74,7 +72,6 @@ The following options are listed by priority. The first check that returns true
Background:SetTexture(1, 1, 1, .5)
-- Options
Power.frequentUpdates = true
Power.colorTapping = true
Power.colorDisconnected = true
Power.colorPower = true
Expand Down Expand Up @@ -353,26 +350,6 @@ local function SetColorThreat(element, state, isForced)
end
end

--[[ Power:SetFrequentUpdates(state, isForced)
Used to toggle frequent updates.
* self - the Power element
* state - the desired state (boolean)
* isForced - forces the event update even if the state wasn't changed (boolean)
--]]
local function SetFrequentUpdates(element, state, isForced)
if(element.frequentUpdates ~= state or isForced) then
element.frequentUpdates = state
if(state) then
oUF:UnregisterEvent(element.__owner, 'UNIT_POWER_UPDATE', Path)
oUF:RegisterEvent(element.__owner, 'UNIT_POWER_FREQUENT', Path)
else
oUF:UnregisterEvent(element.__owner, 'UNIT_POWER_FREQUENT', Path)
oUF:RegisterEvent(element.__owner, 'UNIT_POWER_UPDATE', Path)
end
end
end

local function Enable(self)
local element = self.Power
if(element) then
Expand All @@ -382,13 +359,8 @@ local function Enable(self)
element.SetColorSelection = SetColorSelection
element.SetColorTapping = SetColorTapping
element.SetColorThreat = SetColorThreat
element.SetFrequentUpdates = SetFrequentUpdates

if(element.frequentUpdates) then
oUF:RegisterEvent(self, 'UNIT_POWER_FREQUENT', Path)
else
oUF:RegisterEvent(self, 'UNIT_POWER_UPDATE', Path)
end
oUF:RegisterEvent(self, 'UNIT_POWER_UPDATE', Path)

if(element.colorDisconnected) then
oUF:RegisterEvent(self, 'UNIT_CONNECTION', ColorPath)
Expand Down Expand Up @@ -434,7 +406,6 @@ local function Disable(self)
oUF:UnregisterEvent(self, 'UNIT_MAXPOWER', Path)
oUF:UnregisterEvent(self, 'UNIT_POWER_BAR_HIDE', Path)
oUF:UnregisterEvent(self, 'UNIT_POWER_BAR_SHOW', Path)
oUF:UnregisterEvent(self, 'UNIT_POWER_FREQUENT', Path)
oUF:UnregisterEvent(self, 'UNIT_POWER_UPDATE', Path)
oUF:UnregisterEvent(self, 'UNIT_CONNECTION', ColorPath)
oUF:UnregisterEvent(self, 'UNIT_FACTION', ColorPath)
Expand Down
Loading

0 comments on commit d5fb0e0

Please sign in to comment.