Skip to content

Commit def14fa

Browse files
committed
Merge PR #152: Nicknames - Northern Sky Raid Tools compatibility (precedence popup) (by Maelareth)
2 parents 9e9fd66 + 561db04 commit def14fa

8 files changed

Lines changed: 220 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
* Moved **Pixel-Perfect Scaling** to **General → Settings**, since it applies globally to both party and raid. (by Krathe)
4141
* (Aura Designer) New icon and square indicators now default their **border inset to 0**, flush with the icon edge, matching the other indicator types. (by Krathe)
4242
* (Auto Layouts) Saved layouts are tidied of leftover built-in text overrides after the Text Designer migration, so the override list no longer lists dead entries. (by Krathe)
43+
* (Nicknames) **Northern Sky Raid Tools compatibility** — when NSRT is also set to put nicknames on DandersFrames frames, a one-time prompt lets you choose which addon decides the names shown on your frames (changeable later under **General → Nicknames → Name precedence**), so the two no longer silently fight. (by Maelareth)
4344

4445
### Bug Fixes
4546

Features/Nicknames.lua

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,166 @@ end
10351035
-- INIT (called from Core.lua after PLAYER_LOGIN)
10361036
-- ============================================================
10371037

1038+
-- ============================================================
1039+
-- NSRT PRECEDENCE / CONFLICT PROMPT
1040+
-- Northern Sky Raid Tools can also be set to put nicknames on DandersFrames
1041+
-- frames; when its "DandersFrames" toggle is on it OVERWRITES DF:GetUnitName,
1042+
-- so the two would fight. We detect that, prompt the user once which should
1043+
-- win, and store the choice (framePrecedence) which DF:GetFrameName honours.
1044+
-- Entirely DF-side: we never modify NSRT, only READ its toggle.
1045+
-- The same choice can be changed later in the Nicknames options page.
1046+
-- ============================================================
1047+
1048+
-- True if NSRT is loaded AND configured to manage names on DandersFrames frames.
1049+
function NK:NSRTManagingNames()
1050+
return (C_AddOns and C_AddOns.IsAddOnLoaded and C_AddOns.IsAddOnLoaded("NorthernSkyRaidTools"))
1051+
and NSRT and NSRT.Settings
1052+
and NSRT.Settings["GlobalNickNames"]
1053+
and NSRT.Settings["DandersFrames"]
1054+
and true or false
1055+
end
1056+
1057+
-- Should DandersFrames' own nicknames win on our frames? Yes — unless the user
1058+
-- explicitly chose NSRT AND NSRT is actually managing names right now.
1059+
function NK:HasPrecedence()
1060+
local data = NK:GetDB()
1061+
if data and data.framePrecedence == "nsrt" and NK:NSRTManagingNames() then
1062+
return false
1063+
end
1064+
return true
1065+
end
1066+
1067+
-- The name to display on our own frames, honouring precedence. When DF wins we
1068+
-- resolve our own nickname first; when the user has chosen NSRT we ask NSRT's
1069+
-- own resolver DIRECTLY (NSAPI:GetName) so its name shows, bypassing our hook
1070+
-- (which would otherwise keep returning the DF nickname).
1071+
function NK:GetDisplayName(unit)
1072+
if NK:HasPrecedence() then
1073+
local nick = NK:Resolve(unit)
1074+
if nick then return nick end
1075+
return DF:GetUnitName(unit)
1076+
end
1077+
local raw = UnitName(unit)
1078+
if NSAPI and NSAPI.GetName and raw then
1079+
return NSAPI:GetName(raw, "DandersFrames") or raw
1080+
end
1081+
return raw or unit
1082+
end
1083+
1084+
-- Build + show the one-time conflict popup (DandersFrames' own alert style).
1085+
function NK:ShowConflictPopup()
1086+
if NK._conflictPopup then NK._conflictPopup:Show(); return end
1087+
1088+
local L = DF.L
1089+
local theme = (DF.GUI and DF.GUI.GetThemeColor and DF.GUI.GetThemeColor())
1090+
or { r = 0.9, g = 0.55, b = 0.15 }
1091+
1092+
local popup = CreateFrame("Frame", "DFNicknameConflictPopup", UIParent, "BackdropTemplate")
1093+
popup:SetSize(490, 250)
1094+
popup:SetPoint("CENTER")
1095+
popup:SetFrameStrata("FULLSCREEN_DIALOG")
1096+
popup:SetFrameLevel(200)
1097+
popup:SetBackdrop({ bgFile = "Interface\\Buttons\\WHITE8x8", edgeFile = "Interface\\Buttons\\WHITE8x8", edgeSize = 2 })
1098+
popup:SetBackdropColor(0.1, 0.1, 0.1, 0.98)
1099+
popup:SetBackdropBorderColor(theme.r, theme.g, theme.b, 1)
1100+
popup:EnableMouse(true)
1101+
popup:SetMovable(true)
1102+
popup:RegisterForDrag("LeftButton")
1103+
popup:SetScript("OnDragStart", popup.StartMoving)
1104+
popup:SetScript("OnDragStop", popup.StopMovingOrSizing)
1105+
tinsert(UISpecialFrames, "DFNicknameConflictPopup") -- Esc closes (re-prompts next login)
1106+
1107+
local title = popup:CreateFontString(nil, "OVERLAY", "DFFontNormalLarge")
1108+
title:SetPoint("TOP", 0, -16)
1109+
title:SetText(L["Addon nicknames conflict"])
1110+
title:SetTextColor(1, 0.3, 0.3)
1111+
1112+
local warnTex = "Interface\\AddOns\\DandersFrames\\Media\\Icons\\warning"
1113+
local lw = popup:CreateTexture(nil, "OVERLAY"); lw:SetSize(18, 18)
1114+
lw:SetPoint("RIGHT", title, "LEFT", -8, 0); lw:SetTexture(warnTex); lw:SetVertexColor(1, 0.3, 0.3)
1115+
local rw = popup:CreateTexture(nil, "OVERLAY"); rw:SetSize(18, 18)
1116+
rw:SetPoint("LEFT", title, "RIGHT", 8, 0); rw:SetTexture(warnTex); rw:SetVertexColor(1, 0.3, 0.3)
1117+
1118+
local msg = popup:CreateFontString(nil, "OVERLAY", "DFFontHighlight")
1119+
msg:SetPoint("TOP", title, "BOTTOM", 0, -16)
1120+
msg:SetPoint("LEFT", 28, 0); msg:SetPoint("RIGHT", -28, 0); msg:SetJustifyH("CENTER")
1121+
msg:SetText(L["Both %s and %s are set to show nicknames on your frames.\n\nWhich one should decide the names shown here?"]
1122+
:format("|cffe68c26DandersFrames|r", "|cff6fb1e0Northern Sky Raid Tools|r"))
1123+
1124+
local sub = popup:CreateFontString(nil, "OVERLAY", "DFFontHighlightSmall")
1125+
sub:SetPoint("TOP", msg, "BOTTOM", 0, -12)
1126+
sub:SetPoint("LEFT", 28, 0); sub:SetPoint("RIGHT", -28, 0); sub:SetJustifyH("CENTER")
1127+
sub:SetText(L["This only changes who controls names on DandersFrames frames - you can change it later in Nicknames settings."])
1128+
sub:SetTextColor(0.7, 0.7, 0.7)
1129+
1130+
local function choose(pref)
1131+
local d = NK:GetDB(); if d then d.framePrecedence = pref end
1132+
popup:Hide()
1133+
NK:RefreshAllFrames()
1134+
end
1135+
1136+
local function makeButton(text, primary, onClick)
1137+
local b = CreateFrame("Button", nil, popup, "BackdropTemplate")
1138+
b:SetSize(225, 42)
1139+
b:SetBackdrop({ bgFile = "Interface\\Buttons\\WHITE8x8", edgeFile = "Interface\\Buttons\\WHITE8x8", edgeSize = 1 })
1140+
if primary then
1141+
b:SetBackdropColor(theme.r * 0.3, theme.g * 0.3, theme.b * 0.3, 1)
1142+
b:SetBackdropBorderColor(theme.r, theme.g, theme.b, 1)
1143+
else
1144+
b:SetBackdropColor(0.15, 0.15, 0.15, 1)
1145+
b:SetBackdropBorderColor(0.4, 0.4, 0.4, 1)
1146+
end
1147+
local t = b:CreateFontString(nil, "OVERLAY", "DFFontHighlightSmall")
1148+
t:SetPoint("LEFT", 6, 0); t:SetPoint("RIGHT", -6, 0); t:SetJustifyH("CENTER")
1149+
t:SetWordWrap(true); t:SetText(text); t:SetTextColor(1, 1, 1)
1150+
b:SetScript("OnEnter", function(self) self:SetBackdropBorderColor(theme.r, theme.g, theme.b, 1) end)
1151+
b:SetScript("OnLeave", function(self)
1152+
if primary then self:SetBackdropBorderColor(theme.r, theme.g, theme.b, 1)
1153+
else self:SetBackdropBorderColor(0.4, 0.4, 0.4, 1) end
1154+
end)
1155+
b:SetScript("OnClick", onClick)
1156+
return b
1157+
end
1158+
1159+
local dfBtn = makeButton(L["Use %s nicknames"]:format("DandersFrames"), true, function() choose("self") end)
1160+
dfBtn:SetPoint("BOTTOM", -118, 16)
1161+
local nsBtn = makeButton(L["Use %s nicknames"]:format("Northern Sky Raid Tools"), false, function() choose("nsrt") end)
1162+
nsBtn:SetPoint("BOTTOM", 118, 16)
1163+
1164+
NK._conflictPopup = popup
1165+
popup:Show()
1166+
end
1167+
1168+
-- Prompt once if there's an unresolved DF/NSRT name conflict. Defers out of combat.
1169+
function NK:CheckConflictPrompt()
1170+
local data = NK:GetDB()
1171+
if not data or not data.enabled then return end
1172+
if data.framePrecedence ~= nil then return end -- already decided
1173+
-- Only prompt users who actually USE DF nicknames (enabled defaults true,
1174+
-- so without this every NSRT user would get the popup with nothing to
1175+
-- choose between). Once they add a first nickname, the conflict is real
1176+
-- and the popup appears at next login (framePrecedence is still nil).
1177+
local hasAny = (data.entries and #data.entries > 0)
1178+
or (NK.received and next(NK.received) ~= nil)
1179+
or (data.selfNick and data.selfNick ~= "")
1180+
if not hasAny then return end
1181+
if not NK:NSRTManagingNames() then return end -- no conflict
1182+
if InCombatLockdown and InCombatLockdown() then
1183+
if not NK._conflictCombatWatch then
1184+
local f = CreateFrame("Frame")
1185+
f:RegisterEvent("PLAYER_REGEN_ENABLED")
1186+
f:SetScript("OnEvent", function(self)
1187+
self:UnregisterEvent("PLAYER_REGEN_ENABLED")
1188+
NK._conflictCombatWatch = nil
1189+
NK:CheckConflictPrompt()
1190+
end)
1191+
NK._conflictCombatWatch = f
1192+
end
1193+
return
1194+
end
1195+
NK:ShowConflictPopup()
1196+
end
1197+
10381198
function NK:Init()
10391199
if self.initialized then return end
10401200
self.initialized = true
@@ -1059,4 +1219,8 @@ function NK:Init()
10591219

10601220
-- Make sure any names already on screen pick up existing rules.
10611221
NK:RefreshAllFrames()
1222+
1223+
-- If NSRT is also set to manage our frame names, prompt once which wins.
1224+
-- Delayed so NSRT's saved vars / settings are loaded first.
1225+
if C_Timer then C_Timer.After(3, function() NK:CheckConflictPrompt() end) end
10621226
end

Frames/Bars.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2119,7 +2119,7 @@ function DF:UpdateName(frame)
21192119

21202120
-- Use raid DB for raid frames, party DB for party frames
21212121
local db = DF:GetFrameDB(frame)
2122-
local name = DF:GetUnitName(frame.unit)
2122+
local name = DF:GetFrameName(frame.unit)
21232123

21242124
-- Truncate name if needed (UTF-8 aware)
21252125
if name then

Frames/Core.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,20 @@ function DF:GetUnitName(unit)
511511
return UnitName(unit) or unit
512512
end
513513

514+
-- Display name used by our own frame rendering. DandersFrames' native nicknames
515+
-- resolve FIRST here, so they stay authoritative on our frames even when another
516+
-- nickname addon (e.g. NSRT) overwrites DF:GetUnitName. NK:HasPrecedence() gates
517+
-- this: it returns false only when the user has explicitly chosen to let the
518+
-- other addon win, in which case we fall through to DF:GetUnitName (which that
519+
-- addon may own) and finally the raw name.
520+
function DF:GetFrameName(unit)
521+
local NK = DF.Nicknames
522+
if NK and NK.GetDisplayName then
523+
return NK:GetDisplayName(unit)
524+
end
525+
return DF:GetUnitName(unit)
526+
end
527+
514528
-- Iterator for all compact unit frames (player, party, raid)
515529
-- Accepts a callback function OR returns an iterator if no callback provided
516530
-- Usage with callback: DF:IterateCompactFrames(function(frame) ... end)

Frames/Update.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ function DF:UpdateUnitFrame(frame, source)
535535
if hideLegacyText then
536536
frame.nameText:Hide()
537537
else
538-
local name = DF:GetUnitName(unit) or unit
538+
local name = DF:GetFrameName(unit) or unit
539539
-- Truncate name if needed (UTF-8 aware)
540540
local nameLength = db.nameTextLength or 0
541541
if nameLength > 0 and DF:UTF8Len(name) > nameLength then
@@ -598,7 +598,7 @@ function DF:UpdateUnitFrame(frame, source)
598598
if hideLegacyText then
599599
frame.nameText:Hide()
600600
else
601-
local name = DF:GetUnitName(unit) or unit
601+
local name = DF:GetFrameName(unit) or unit
602602
-- Truncate name if needed (UTF-8 aware)
603603
local nameLength = db.nameTextLength or 0
604604
if nameLength > 0 and DF:UTF8Len(name) > nameLength then

Locales/enUS.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,6 +1890,7 @@ L["Add a nickname"] = true
18901890
L["Add from"] = true
18911891
L["Add from:"] = true
18921892
L["Added"] = true
1893+
L["Addon nicknames conflict"] = true
18931894
L["All nicknames"] = true
18941895
L["Angle <name>"] = true
18951896
L["Apply to"] = true
@@ -1902,6 +1903,7 @@ L["Blocked: contained formatting codes"] = true
19021903
L["Blocked: contains a filtered word"] = true
19031904
L["Blocked: empty"] = true
19041905
L["Blocked: too long"] = true
1906+
L["Both %s and %s are set to show nicknames on your frames.\n\nWhich one should decide the names shown here?"] = true
19051907
L["Brackets [name]"] = true
19061908
L["Character / text"] = true
19071909
L["Contains"] = true
@@ -1918,6 +1920,8 @@ L["Mark nicknames"] = true
19181920
L["Marker style"] = true
19191921
L["Match"] = true
19201922
L["My added"] = true
1923+
L["Name precedence"] = true
1924+
L["Names on frames decided by"] = true
19211925
L["Needs re-link"] = true
19221926
L["Nickname"] = true
19231927
L["Nicknames"] = true
@@ -1926,6 +1930,7 @@ L["No characters found."] = true
19261930
L["No group members found."] = true
19271931
L["No nickname rules yet. Add one above."] = true
19281932
L["No nicknames received yet."] = true
1933+
L["Northern Sky Raid Tools can also show nicknames on DandersFrames frames. Choose which one decides the names shown here."] = true
19291934
L["Overlapping rule"] = true
19301935
L["Overlaps with rule(s) %s. For names they share, the rule higher in the list wins."] = true
19311936
L["Overridden"] = true
@@ -1944,6 +1949,8 @@ L["Source"] = true
19441949
L["Starts with"] = true
19451950
L["Starts with: matches any character whose name begins with this text."] = true
19461951
L["This Battle.net friend could not be matched after an update. Remove this rule and add them again."] = true
1952+
L["This only changes who controls names on DandersFrames frames - you can change it later in Nicknames settings."] = true
1953+
L["Use %s nicknames"] = true
19471954
L["You are not in a guild."] = true
19481955
L["Your nickname (broadcast)"] = true
19491956

Options/NicknamesPage.lua

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,36 @@ function DF.BuildNicknamesPage(guiRef, pageRef, dbRef)
777777
recvContent:SetHeight(mmax(1, n * ROW_HEIGHT))
778778
end
779779

780+
-- ===== Name precedence (only shown when NSRT can also manage our names) =====
781+
-- Northern Sky Raid Tools can also be set to put nicknames on DandersFrames
782+
-- frames; when both are active they fight. This mirrors the one-time conflict
783+
-- popup (Features/Nicknames.lua) so the choice can be changed here later.
784+
if C_AddOns and C_AddOns.IsAddOnLoaded and C_AddOns.IsAddOnLoaded("NorthernSkyRaidTools") then
785+
local precHeader = parent:CreateFontString(nil, "OVERLAY", "DFFontNormal")
786+
precHeader:SetPoint("TOPLEFT", recvBg, "BOTTOMLEFT", 0, -18)
787+
precHeader:SetText(L["Name precedence"])
788+
do local pc = themeColor(); precHeader:SetTextColor(pc.r, pc.g, pc.b) end
789+
790+
local precDesc = parent:CreateFontString(nil, "OVERLAY", "DFFontDisableSmall")
791+
precDesc:SetPoint("TOPLEFT", precHeader, "BOTTOMLEFT", 0, -6)
792+
precDesc:SetWidth(LIST_WIDTH)
793+
precDesc:SetJustifyH("LEFT")
794+
precDesc:SetText(L["Northern Sky Raid Tools can also show nicknames on DandersFrames frames. Choose which one decides the names shown here."])
795+
796+
local precOpts = {
797+
self = "DandersFrames", nsrt = "Northern Sky Raid Tools",
798+
_order = { "self", "nsrt" },
799+
}
800+
local precDD = GUI:CreateDropdown(parent, L["Names on frames decided by"], precOpts, nil, nil, nil,
801+
function() local d = NK:GetDB(); return (d and d.framePrecedence == "nsrt") and "nsrt" or "self" end,
802+
function(v)
803+
local d = NK:GetDB(); if d then d.framePrecedence = v end
804+
NK:RefreshAllFrames()
805+
end)
806+
precDD:SetSize(220, 50)
807+
precDD:SetPoint("TOPLEFT", precDesc, "BOTTOMLEFT", -4, -8)
808+
end
809+
780810
-- Keep this panel in sync with changes made anywhere (e.g. incoming shares).
781811
NK.onChange = Refresh
782812
Refresh()

TextDesigner/DataSource.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ LiveSource.__index = LiveSource
146146
function LiveSource:_isMock() return false end
147147

148148
function LiveSource:GetName()
149-
if DF.GetUnitName then return DF:GetUnitName(self.unit) end
149+
if DF.GetFrameName then return DF:GetFrameName(self.unit) end
150150
return UnitName(self.unit) or ""
151151
end
152152

0 commit comments

Comments
 (0)