Skip to content

Commit

Permalink
clean up env conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
kodewdle committed Jan 6, 2025
1 parent 974ec75 commit df7af94
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 142 deletions.
53 changes: 12 additions & 41 deletions ElvUI/Core/Defaults/Profile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -934,72 +934,43 @@ P.nameplates = {
minus = true,
pets = false,
totems = false,
enviromentConditionals = {
enabled = true,
dungeons = true,
raids = true,
arena = true,
battleground = true,
resting = true,
world = true,
},
},
friendly = {
guardians = false,
minions = false,
npcs = true,
pets = false,
totems = false,
enviromentConditionals = {
enabled = true,
dungeons = false,
raids = false,
arena = false,
battleground = false,
resting = true,
world = true,
},
},
stackingNameplates = {
enviromentConditionals = {
enabled = true,
dungeons = true,
raids = true,
arena = true,
battleground = true,
resting = false,
world = true,
},
},
},
enviromentConditions = {
enemyEnabled = false,
enemy = {
dungeons = true,
raids = true,
party = true,
raid = true,
arena = true,
battleground = true,
pvp = true,
resting = true,
world = true,
world = true,
},
friendlyEnabled = false,
friendly = {
dungeons = false,
raids = false,
party = false,
raid = false,
arena = false,
battleground = false,
pvp = false,
resting = true,
world = true,
world = true,
},
stackingEnabled = false,
stackingNameplates = {
dungeons = true,
raids = true,
party = true,
raid = true,
arena = true,
battleground = true,
pvp = true,
resting = false,
world = true,
},
},
},
cutaway = {
health = {
Expand Down
155 changes: 61 additions & 94 deletions ElvUI/Core/Modules/Nameplates/Nameplates.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ local GetNumSubgroupMembers = GetNumSubgroupMembers
local GetPartyAssignment = GetPartyAssignment
local InCombatLockdown = InCombatLockdown
local IsInGroup = IsInGroup
local IsInInstance = IsInInstance
local IsInRaid = IsInRaid
local IsResting = IsResting
local UIParent = UIParent
local UnitClass = UnitClass
local UnitClassification = UnitClassification
Expand Down Expand Up @@ -147,8 +149,14 @@ function NP:CVarReset()
end
end

function NP:ToggleCVar(cvar, enabled)
E:SetCVar(cvar, enabled and 1 or 0)
end

function NP:SetCVars()
if NP.db.clampToScreen then
local db = NP.db

if db.clampToScreen then
E:SetCVar('nameplateOtherTopInset', 0.08)
E:SetCVar('nameplateOtherBottomInset', 0.1)

Expand All @@ -164,35 +172,43 @@ function NP:SetCVars()
end
end

E:SetCVar('nameplateMotion', NP.db.motionType == 'STACKED' and 1 or 0)

if E.Cata then
E:SetCVar('nameplateMaxDistance', NP.db.loadDistance)
E:SetCVar('nameplateMaxDistance', db.loadDistance)
end

E:SetCVar('NameplatePersonalShowAlways', NP.db.units.PLAYER.visibility.showAlways and 1 or 0)
E:SetCVar('NameplatePersonalShowInCombat', NP.db.units.PLAYER.visibility.showInCombat and 1 or 0)
E:SetCVar('NameplatePersonalShowWithTarget', NP.db.units.PLAYER.visibility.showWithTarget and 1 or 0)
E:SetCVar('NameplatePersonalHideDelayAlpha', NP.db.units.PLAYER.visibility.alphaDelay)
E:SetCVar('NameplatePersonalHideDelaySeconds', NP.db.units.PLAYER.visibility.hideDelay)

-- the order of these is important !!
E:SetCVar('nameplateShowAll', NP.db.visibility.showAll and 1 or 0)
E:SetCVar('nameplateShowSelf', (NP.db.units.PLAYER.useStaticPosition or not NP.db.units.PLAYER.enable) and 0 or 1)
E:SetCVar('nameplateShowEnemyMinions', NP.db.visibility.enemy.minions and 1 or 0)
E:SetCVar('nameplateShowEnemyGuardians', NP.db.visibility.enemy.guardians and 1 or 0)
E:SetCVar('nameplateShowEnemyMinus', NP.db.visibility.enemy.minus and 1 or 0)
E:SetCVar('nameplateShowEnemyPets', NP.db.visibility.enemy.pets and 1 or 0)
E:SetCVar('nameplateShowEnemyTotems', NP.db.visibility.enemy.totems and 1 or 0)
E:SetCVar('nameplateShowFriendlyMinions', NP.db.visibility.friendly.minions and 1 or 0)
E:SetCVar('nameplateShowFriendlyGuardians', NP.db.visibility.friendly.guardians and 1 or 0)
E:SetCVar('nameplateShowFriendlyNPCs', NP.db.visibility.friendly.npcs and 1 or 0)
E:SetCVar('nameplateShowFriendlyPets', NP.db.visibility.friendly.pets and 1 or 0)
E:SetCVar('nameplateShowFriendlyTotems', NP.db.visibility.friendly.totems and 1 or 0)
local visibility = db.visibility
NP:ToggleCVar('nameplateShowAll', visibility.showAll)
NP:ToggleCVar('nameplateShowOnlyNames', visibility.nameplateShowOnlyNames)

local enemyVisibility = visibility.enemy
NP:ToggleCVar('nameplateShowEnemyMinions', enemyVisibility.minions)
NP:ToggleCVar('nameplateShowEnemyGuardians', enemyVisibility.guardians)
NP:ToggleCVar('nameplateShowEnemyMinus', enemyVisibility.minus)
NP:ToggleCVar('nameplateShowEnemyPets', enemyVisibility.pets)
NP:ToggleCVar('nameplateShowEnemyTotems', enemyVisibility.totems)

local friendlyVisibility = visibility.friendly
NP:ToggleCVar('nameplateShowFriendlyMinions', friendlyVisibility.minions)
NP:ToggleCVar('nameplateShowFriendlyGuardians', friendlyVisibility.guardians)
NP:ToggleCVar('nameplateShowFriendlyNPCs', friendlyVisibility.npcs)
NP:ToggleCVar('nameplateShowFriendlyPets', friendlyVisibility.pets)
NP:ToggleCVar('nameplateShowFriendlyTotems', friendlyVisibility.totems)

local playerDB = db.units.PLAYER
local playerVisibility = playerDB.visibility
E:SetCVar('NameplatePersonalHideDelayAlpha', playerVisibility.alphaDelay)
E:SetCVar('NameplatePersonalHideDelaySeconds', playerVisibility.hideDelay)

NP:ToggleCVar('NameplatePersonalShowAlways', playerVisibility.showAlways)
NP:ToggleCVar('NameplatePersonalShowInCombat', playerVisibility.showInCombat)
NP:ToggleCVar('NameplatePersonalShowWithTarget', playerVisibility.showWithTarget)

NP:ToggleCVar('nameplateShowSelf', not (playerDB.useStaticPosition or not playerDB.enable))

-- Blizzard bug resets them after reload
E:SetCVar('nameplateOverlapH', NP.db.overlapH)
E:SetCVar('nameplateOverlapV', NP.db.overlapV)
E:SetCVar('nameplateOverlapH', db.overlapH)
E:SetCVar('nameplateOverlapV', db.overlapV)

-- 10.1 things
E:SetCVar('nameplatePlayerMaxDistance', 60)
Expand Down Expand Up @@ -568,84 +584,37 @@ end

function NP:GROUP_LEFT()
NP.IsInGroup = IsInRaid() or IsInGroup()

wipe(NP.GroupRoles)
end

function NP:ToggleNameplates(friendly, enabled)
if friendly then
SetCVar("nameplateShowFriends", enabled and 1 or 0)
else
SetCVar("nameplateShowEnemies", enabled and 1 or 0)
end
end
function NP:EnviromentConditionals()
local inInstance, instanceType = IsInInstance()
local value = (inInstance and instanceType) or (IsResting() and 'resting') or 'world'

local db = NP.db
local env = db.enviromentConditions
if env.friendlyEnabled then -- Handle friendly nameplates
NP:ToggleCVar('nameplateShowFriends', env.friendly[value])
end

function NP:ToggleStackingNameplates(enabled)
SetCVar("nameplateMotion", enabled and 1 or 0)
end
if env.enemyEnabled then -- Handle enemy nameplates
NP:ToggleCVar('nameplateShowEnemies', env.enemy[value])
end

function NP:EnviromentConditionals()
local inInstance, instanceType = IsInInstance()
local isResting = IsResting()
local db = self.db.enviromentConditions
-- Handle friendly nameplates
if db.friendlyEnabled then
if inInstance and instanceType == "party" then
self:ToggleNameplates(true, db.friendly.dungeons)
elseif inInstance and instanceType == "raid" then
self:ToggleNameplates(true, db.friendly.raids)
elseif inInstance and instanceType == "arena" then
self:ToggleNameplates(true, db.friendly.arena)
elseif inInstance and instanceType == "pvp" then
self:ToggleNameplates(true, db.friendly.battleground)
elseif isResting then
self:ToggleNameplates(true, db.friendly.resting)
else
self:ToggleNameplates(true, db.friendly.world)
end
end

-- Handle enemy nameplates
if db.enemyEnabled then
if inInstance and instanceType == "party" then
self:ToggleNameplates(false, db.enemy.dungeons)
elseif inInstance and instanceType == "raid" then
self:ToggleNameplates(false, db.enemy.raids)
elseif inInstance and instanceType == "arena" then
self:ToggleNameplates(false, db.enemy.arena)
elseif inInstance and instanceType == "pvp" then
self:ToggleNameplates(false, db.enemy.battleground)
elseif isResting then
self:ToggleNameplates(false, db.enemy.resting)
else
self:ToggleNameplates(false, db.enemy.world)
end
end

-- Handle stacking nameplates
if db.stackingEnabled then
if inInstance and instanceType == "party" then
self:ToggleStackingNameplates(db.stackingNameplates.dungeons)
elseif inInstance and instanceType == "raid" then
self:ToggleStackingNameplates(db.stackingNameplates.raids)
elseif inInstance and instanceType == "arena" then
self:ToggleStackingNameplates(db.stackingNameplates.arena)
elseif inInstance and instanceType == "pvp" then
self:ToggleStackingNameplates(db.stackingNameplates.battleground)
elseif isResting then
self:ToggleStackingNameplates(db.stackingNameplates.resting)
else
self:ToggleStackingNameplates(db.stackingNameplates.world)
end
end
if env.stackingEnabled then -- Handle stacking nameplates
NP:ToggleCVar('nameplateMotion', env.stackingNameplates[value])
else
NP:ToggleCVar('nameplateMotion', db.motionType == 'STACKED')
end
end

function NP:PLAYER_ENTERING_WORLD(_, initLogin, isReload)
function NP:PLAYER_ENTERING_WORLD(event, initLogin, isReload)
if initLogin or isReload then
NP:ConfigureAll(true)
end

self:EnviromentConditionals()
NP:EnviromentConditionals(event)
end

function NP:ToggleStaticPlate()
Expand Down Expand Up @@ -1037,8 +1006,6 @@ function NP:Initialize()
ElvUF:RegisterStyle('ElvNP', NP.Style)
ElvUF:SetActiveStyle('ElvNP')

E:SetCVar('nameplateShowOnlyNames', NP.db.visibility.nameplateShowOnlyNames and 1 or 0)

NP.Plates = {}
NP.PlateGUID = {}
NP.StatusBars = {}
Expand Down Expand Up @@ -1109,8 +1076,8 @@ function NP:Initialize()
NP:RegisterEvent('PLAYER_REGEN_ENABLED')
NP:RegisterEvent('PLAYER_REGEN_DISABLED')
NP:RegisterEvent('PLAYER_ENTERING_WORLD')
NP:RegisterEvent("ZONE_CHANGED_NEW_AREA", "EnviromentConditionals")
NP:RegisterEvent("PLAYER_UPDATE_RESTING", "EnviromentConditionals")
NP:RegisterEvent('PLAYER_UPDATE_RESTING', 'EnviromentConditionals')
NP:RegisterEvent('ZONE_CHANGED_NEW_AREA', 'EnviromentConditionals')
NP:RegisterEvent('COMBAT_LOG_EVENT_UNFILTERED')
NP:RegisterEvent('GROUP_ROSTER_UPDATE')
NP:RegisterEvent('GROUP_LEFT')
Expand Down
15 changes: 8 additions & 7 deletions ElvUI_Options/Core/Nameplates.lua
Original file line number Diff line number Diff line change
Expand Up @@ -444,13 +444,14 @@ NamePlates.generalGroup.args.plateVisibility.args.playerVisibility.args.alphaDel
NamePlates.generalGroup.args.plateVisibility.args.enemyVisibility = ACH:MultiSelect(L["Enemy"], nil, 10, { guardians = L["Guardians"], minions = L["Minions"], minus = L["Minus"], pets = L["Pets"], totems = L["Totems"] }, nil, nil, function(_, key) return E.db.nameplates.visibility.enemy[key] end, function(_, key, value) E.db.nameplates.visibility.enemy[key] = value NP:SetCVars() NP:ConfigureAll() end, function() return not E.db.nameplates.visibility.showAll end)
NamePlates.generalGroup.args.plateVisibility.args.friendlyVisibility = ACH:MultiSelect(L["Friendly"], nil, 15, { guardians = L["Guardians"], minions = L["Minions"], npcs = L["NPC"], pets = L["Pets"], totems = L["Totems"] }, nil, nil, function(_, key) return E.db.nameplates.visibility.friendly[key] end, function(_, key, value) E.db.nameplates.visibility.friendly[key] = value NP:SetCVars() NP:ConfigureAll() end, function() return not E.db.nameplates.visibility.showAll end)

NamePlates.generalGroup.args.enviromentConditions = ACH:Group(L["Enviroment Conditions"], nil, 51)
NamePlates.generalGroup.args.enviromentConditions.args.enemyEnabled = ACH:Toggle(L["Enemy Enabled"], L["This option controls whether nameplates will follow the visibility settings below."], 9, nil, nil, 250, function(info) return E.db.nameplates.enviromentConditions[info[#info]] end, function(info, value) E.db.nameplates.enviromentConditions[info[#info]] = value NP:EnviromentConditionals() end)
NamePlates.generalGroup.args.enviromentConditions.args.enemy = ACH:MultiSelect(L["Enemy"], nil, 10, { dungeons = L["Dungeons"], raids = L["Raids"], arena = L["Arena"], battleground = L["Battleground"], resting = L["Resting"], world = L["World"] }, nil, nil, function(_, key) return E.db.nameplates.enviromentConditions.enemy[key] end, function(_, key, value) E.db.nameplates.enviromentConditions.enemy[key] = value NP:EnviromentConditionals() end, nil)
NamePlates.generalGroup.args.enviromentConditions.args.friendlyEnabled = ACH:Toggle(L["Friendly Enabled"], L["This option controls whether nameplates will follow the visibility settings below."], 19, nil, nil, 250, function(info) return E.db.nameplates.enviromentConditions[info[#info]] end, function(info, value) E.db.nameplates.enviromentConditions[info[#info]] = value NP:EnviromentConditionals() end)
NamePlates.generalGroup.args.enviromentConditions.args.friendly = ACH:MultiSelect(L["Friendly"], nil, 20, { dungeons = L["Dungeons"], raids = L["Raids"], arena = L["Arena"], battleground = L["Battleground"], resting = L["Resting"], world = L["World"] }, nil, nil, function(_, key) return E.db.nameplates.enviromentConditions.friendly[key] end, function(_, key, value) E.db.nameplates.visibility.enviromentConditions.friendly[key] = value NP:EnviromentConditionals() end, nil)
NamePlates.generalGroup.args.enviromentConditions.args.stackingEnabled = ACH:Toggle(L["Stacking Enabled"], L["This option controls whether nameplates will follow the settings below."], 29, nil, nil, 250, function(info) return E.db.nameplates.enviromentConditions[info[#info]] end, function(info, value) E.db.nameplates.enviromentConditions[info[#info]] = value NP:EnviromentConditionals() end)
NamePlates.generalGroup.args.enviromentConditions.args.stacking = ACH:MultiSelect(L["Stacking Plates"], nil, 30, { dungeons = L["Dungeons"], raids = L["Raids"], arena = L["Arena"], battleground = L["Battleground"], resting = L["Resting"], world = L["World"] }, nil, nil, function(_, key) return E.db.nameplates.enviromentConditions.stackingNameplates[key] end, function(_, key, value) E.db.nameplates.enviromentConditions.stackingNameplates[key] = value NP:EnviromentConditionals() end, nil)
local envConditions = { party = L["Dungeons"], raid = L["Raids"], arena = L["Arena"], pvp = L["Battleground"], resting = L["Resting"], world = L["World"] }
NamePlates.generalGroup.args.enviromentConditions = ACH:Group(L["Enviroment Conditions"], nil, 60, nil, function(info) return E.db.nameplates.enviromentConditions[info[#info]] end, function(info, value) E.db.nameplates.enviromentConditions[info[#info]] = value NP:EnviromentConditionals() end)
NamePlates.generalGroup.args.enviromentConditions.args.enemyEnabled = ACH:Toggle(L["Enemy Enabled"], L["This option controls whether nameplates will follow the visibility settings below."], 10, nil, nil, 250)
NamePlates.generalGroup.args.enviromentConditions.args.enemy = ACH:MultiSelect(L["Enemy"], nil, 11, envConditions, nil, nil, function(_, key) return E.db.nameplates.enviromentConditions.enemy[key] end, function(_, key, value) E.db.nameplates.enviromentConditions.enemy[key] = value NP:EnviromentConditionals() end, nil, function() return not E.db.nameplates.enviromentConditions.enemyEnabled end)
NamePlates.generalGroup.args.enviromentConditions.args.friendlyEnabled = ACH:Toggle(L["Friendly Enabled"], L["This option controls whether nameplates will follow the visibility settings below."], 20, nil, nil, 250)
NamePlates.generalGroup.args.enviromentConditions.args.friendly = ACH:MultiSelect(L["Friendly"], nil, 21, envConditions, nil, nil, function(_, key) return E.db.nameplates.enviromentConditions.friendly[key] end, function(_, key, value) E.db.nameplates.visibility.enviromentConditions.friendly[key] = value NP:EnviromentConditionals() end, nil, function() return not E.db.nameplates.enviromentConditions.friendlyEnabled end)
NamePlates.generalGroup.args.enviromentConditions.args.stackingEnabled = ACH:Toggle(L["Stacking Enabled"], L["This option controls whether nameplates will follow the settings below."], 30, nil, nil, 250)
NamePlates.generalGroup.args.enviromentConditions.args.stacking = ACH:MultiSelect(L["Stacking Plates"], nil, 31, envConditions, nil, nil, function(_, key) return E.db.nameplates.enviromentConditions.stackingNameplates[key] end, function(_, key, value) E.db.nameplates.enviromentConditions.stackingNameplates[key] = value NP:EnviromentConditionals() end, nil, function() return not E.db.nameplates.enviromentConditions.stackingEnabled end)

NamePlates.generalGroup.args.bossMods = ACH:Group(L["Boss Mod Auras"], nil, 55, nil, function(info) return E.db.nameplates.bossMods[info[#info]] end, function(info, value) E.db.nameplates.bossMods[info[#info]] = value NP:ConfigureAll() end)
NamePlates.generalGroup.args.bossMods.args.enable = ACH:Toggle(L["Enable"], nil, 0)
Expand Down

0 comments on commit df7af94

Please sign in to comment.