Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Core/Config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ local settings = {
LEGACY_DESIGN = {key = "design_all", default = {}},

DESIGNS = {key = "designs", default = {}, refresh = {addonTable.Constants.RefreshReason.Design}},
DESIGNS_ASSIGNED = {key = "designs_assigned", default = {["friend"] = "_name-only", ["enemy"] = "_deer", ["enemySimplified"] = "_hare_simplified"}, refresh = {addonTable.Constants.RefreshReason.Design}},
DESIGNS_ASSIGNED = {key = "designs_assigned", default = {["friend"] = "_name-only", ["enemy"] = "_deer", ["enemyNotInCombat"] = "none", ["enemySimplified"] = "_hare_simplified"}, refresh = {addonTable.Constants.RefreshReason.Design}},

TARGET_SCALE = {key = "target_scale", default = 1.2, refresh = {addonTable.Constants.RefreshReason.TargetBehaviour}},
CAST_SCALE = {key = "cast_scale", default = 1.1, refresh = {addonTable.Constants.RefreshReason.TargetBehaviour}},
Expand Down
9 changes: 9 additions & 0 deletions Core/Initialize.lua
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,11 @@ function addonTable.Core.MigrateSettings()
mapping["enemySimplified"] = "_hare_simplified"
end

-- Initialize enemyNotInCombat to "none" if not set
if mapping["enemyNotInCombat"] == nil then
mapping["enemyNotInCombat"] = "none"
end

local simplified = addonTable.Config.Get(addonTable.Config.Options.SIMPLIFIED_NAMEPLATES)
if simplified["instancesNormal"] == nil then
simplified["instancesNormal"] = true
Expand Down Expand Up @@ -541,6 +546,10 @@ end

function addonTable.Core.GetDesign(kind)
local name = addonTable.Config.Get(addonTable.Config.Options.DESIGNS_ASSIGNED)[kind]
-- If enemyNotInCombat is set to "none", fall back to "enemy" design
if kind == "enemyNotInCombat" and name == "none" then
name = addonTable.Config.Get(addonTable.Config.Options.DESIGNS_ASSIGNED)["enemy"]
end
return addonTable.Core.GetDesignByName(name)
end

Expand Down
19 changes: 19 additions & 0 deletions CustomiseDialog/Main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,15 @@ local function SetupStyleSelect(parent)
enemyStyleDropdown:SetPoint("TOP", allFrames[#allFrames], "BOTTOM")
table.insert(allFrames, enemyStyleDropdown)

local enemyNotInCombatStyleDropdown = addonTable.CustomiseDialog.Components.GetBasicDropdown(container, addonTable.Locales.ENEMY_NOT_IN_COMBAT, function(value)
return addonTable.Config.Get(addonTable.Config.Options.DESIGNS_ASSIGNED)["enemyNotInCombat"] == value
end, function(value)
addonTable.Config.Get(addonTable.Config.Options.DESIGNS_ASSIGNED)["enemyNotInCombat"] = value
addonTable.CallbackRegistry:TriggerEvent("RefreshStateChange", {[addonTable.Constants.RefreshReason.Design] = true})
end)
enemyNotInCombatStyleDropdown:SetPoint("TOP", allFrames[#allFrames], "BOTTOM")
table.insert(allFrames, enemyNotInCombatStyleDropdown)

local simplifiedStyleDropdown
if C_NamePlateManager and C_NamePlateManager.SetNamePlateSimplified then
simplifiedStyleDropdown = addonTable.CustomiseDialog.Components.GetBasicDropdown(container, addonTable.Locales.SIMPLIFIED, function(value)
Expand Down Expand Up @@ -582,9 +591,16 @@ local function SetupStyleSelect(parent)
table.insert(labels, entry.label)
table.insert(values, entry.value)
end

-- Add "None" option for enemyNotInCombat dropdown
local labelsWithNone = CopyTable(labels)
local valuesWithNone = CopyTable(values)
table.insert(labelsWithNone, 1, addonTable.Locales.NONE)
table.insert(valuesWithNone, 1, "none")

friendlyStyleDropdown:Init(labels, values)
enemyStyleDropdown:Init(labels, values)
enemyNotInCombatStyleDropdown:Init(labelsWithNone, valuesWithNone)
if simplifiedStyleDropdown then
simplifiedStyleDropdown:Init(labels, values)
end
Expand Down Expand Up @@ -724,6 +740,9 @@ function addonTable.CustomiseDialog.GetStyleDropdown(parent)
if assigned["enemy"] == entry.value then
assigned["enemy"] = addonTable.Constants.CustomName
end
if assigned["enemyNotInCombat"] == entry.value then
assigned["enemyNotInCombat"] = "none"
end
if assigned["enemySimplified"] == entry.value then
assigned["enemySimplified"] = "_hare_simplified"
end
Expand Down
59 changes: 58 additions & 1 deletion Display/Initialize.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,34 @@ function addonTable.Display.Initialize()
end

addonTable.Display.ManagerMixin = {}

local function IsEnemyInCombatWithGroup(unit)
if not UnitCanAttack("player", unit) then
return false
end

if UnitAffectingCombat(unit) then
return true
end

if UnitThreatSituation("player", unit) ~= nil then
return true
end

local groupSize = GetNumGroupMembers()
if groupSize and groupSize > 0 then
local isRaid = IsInRaid()
for i = 1, groupSize do
local member = isRaid and ("raid" .. i) or ("party" .. i)
if UnitExists(member) and UnitThreatSituation(member, unit) ~= nil then
return true
end
end
end

return false
end

function addonTable.Display.ManagerMixin:OnLoad()
self.styleIndex = 0
self.friendDisplayPool = CreateFramePool("Frame", UIParent, nil, nil, false, function(frame)
Expand All @@ -21,6 +49,11 @@ function addonTable.Display.ManagerMixin:OnLoad()
frame.kind = "enemy"
frame:OnLoad()
end)
self.enemyNotInCombatDisplayPool = CreateFramePool("Frame", UIParent, nil, nil, false, function(frame)
Mixin(frame, addonTable.Display.NameplateMixin)
frame.kind = "enemyNotInCombat"
frame:OnLoad()
end)
self.enemySimplifiedDisplayPool = CreateFramePool("Frame", UIParent, nil, nil, false, function(frame)
Mixin(frame, addonTable.Display.NameplateMixin)
frame.kind = "enemySimplified"
Expand All @@ -44,6 +77,8 @@ function addonTable.Display.ManagerMixin:OnLoad()
self:RegisterEvent("PLAYER_FOCUS_CHANGED")
self:RegisterEvent("PLAYER_LOGIN")
self:RegisterEvent("PLAYER_ENTERING_WORLD")
self:RegisterEvent("UNIT_THREAT_LIST_UPDATE")
self:RegisterEvent("UNIT_HEALTH")
if C_EventUtils.IsEventValid("GARRISON_UPDATE") then
self:RegisterEvent("GARRISON_UPDATE")
end
Expand Down Expand Up @@ -525,7 +560,13 @@ function addonTable.Display.ManagerMixin:Install(unit, nameplate)
if shouldSimplify then
newDisplay = self.enemySimplifiedDisplayPool:Acquire()
else
newDisplay = self.enemyDisplayPool:Acquire()
-- Check if enemy is NOT in combat with the player or group and enemyNotInCombat style is set
local enemyNotInCombatStyle = addonTable.Config.Get(addonTable.Config.Options.DESIGNS_ASSIGNED)["enemyNotInCombat"]
if enemyNotInCombatStyle and enemyNotInCombatStyle ~= "none" and not IsEnemyInCombatWithGroup(unit) then
newDisplay = self.enemyNotInCombatDisplayPool:Acquire()
else
newDisplay = self.enemyDisplayPool:Acquire()
end
end
end
if C_NamePlateManager and C_NamePlateManager.SetNamePlateSimplified then
Expand Down Expand Up @@ -579,6 +620,8 @@ function addonTable.Display.ManagerMixin:Uninstall(unit)
self.friendDisplayPool:Release(display)
elseif display.kind == "enemySimplified" then
self.enemySimplifiedDisplayPool:Release(display)
elseif display.kind == "enemyNotInCombat" then
self.enemyNotInCombatDisplayPool:Release(display)
else
self.enemyDisplayPool:Release(display)
end
Expand Down Expand Up @@ -851,6 +894,20 @@ function addonTable.Display.ManagerMixin:OnEvent(eventName, ...)
self:Uninstall(unit)
self:Install(unit, nameplate)
end
elseif eventName == "UNIT_HEALTH" or eventName == "UNIT_THREAT_LIST_UPDATE" then
local unit = ...
local display = self.nameplateDisplays[unit]
-- Check if we need to switch between enemy and enemyNotInCombat based on combat state
if display and UnitCanAttack("player", unit) then
local enemyNotInCombatStyle = addonTable.Config.Get(addonTable.Config.Options.DESIGNS_ASSIGNED)["enemyNotInCombat"]
local isInCombat = IsEnemyInCombatWithGroup(unit)
local shouldBeNotInCombat = enemyNotInCombatStyle and enemyNotInCombatStyle ~= "none" and not isInCombat

if (display.kind == "enemyNotInCombat" and isInCombat) or (display.kind == "enemy" and shouldBeNotInCombat) then
self:Uninstall(unit)
self:Install(unit)
end
end
elseif eventName == "GLOBAL_MOUSE_UP" then
self:UpdateForMouseover()
self:UnregisterEvent("GLOBAL_MOUSE_UP")
Expand Down
1 change: 1 addition & 0 deletions Locales.lua
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ L["SAVE_AS"] = "Save as"
L["SAVE_CUSTOM_AS"] = "Save Custom as"

L["ENEMY"] = "Enemy"
L["ENEMY_NOT_IN_COMBAT"] = "Enemy not in combat"
L["SIMPLIFIED"] = "Simplified"
L["DEFAULT_BRACKETS"] = "(Default)"

Expand Down