Repository navigation
Expand file tree
/
Copy pathCustomNames_Guild.lua
More file actions
66 lines (60 loc) · 2.21 KB
/
Copy pathCustomNames_Guild.lua
File metadata and controls
66 lines (60 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
local lib = LibStub("CustomNames")
local function GetBattleTag(bnetIDAccount)
if issecretvalue(bnetIDAccount) or not bnetIDAccount then return end
local info = C_BattleNet.GetAccountInfoByID(bnetIDAccount)
if not info then return end
local tag = info.battleTag
if tag == nil or issecretvalue(tag) then return end
return tag
end
local function updateGuildRoster(self, ...)
local frame = ...
local name = frame.NameFrame.Name:GetText()
if issecretvalue(name) then return end
if name then
local memberInfo = frame:GetMemberInfo()
if memberInfo and memberInfo.clubType == Enum.ClubType.BattleNet then
name = GetBattleTag(memberInfo.bnetAccountId)
if not name then return end
end
local customName = lib.Get(name)
if customName and customName ~= name then
frame.NameFrame.Name:SetText(customName)
frame.NameFrame.RankIcon:ClearAllPoints();
frame.NameFrame.RankIcon:SetPoint("LEFT", frame.NameFrame.Name, "LEFT", frame.NameFrame.Name:GetStringWidth(),
0);
end
end
end
ScrollUtil.AddInitializedFrameCallback(CommunitiesFrame.MemberList.ScrollBox, updateGuildRoster)
local function replaceDisplayName(link, display, name, customName)
local s, e = display:find(name, 1, true)
if s then
return link .. display:sub(1, s - 1) .. customName .. display:sub(e + 1) .. "|h"
end
end
local function convertName(link, name, display)
local customName = lib.Get(name)
if customName and customName ~= name then
return replaceDisplayName(link, display, name, customName)
end
end
local function convertBNName(link, name, bnetIDAccount, display)
local btag = GetBattleTag(tonumber(bnetIDAccount))
if not btag then return end
local customName = lib.Get(btag)
if customName and customName ~= btag then
return replaceDisplayName(link, display, name, customName)
end
end
local function updateCommunityChat(messageFrame)
for _, line in ipairs(messageFrame.visibleLines) do
local text = line:GetText()
if not issecretvalue(text) and text then
text = text:gsub("(|HplayerCommunity:([^:]+).-|h)(.-)|h", convertName)
text = text:gsub("(|HBNplayerCommunity:([^:]+):([^:]+).-|h)(.-)|h", convertBNName)
line:SetText(text)
end
end
end
CommunitiesFrame.Chat.MessageFrame:AddOnDisplayRefreshedCallback(updateCommunityChat)