-
Notifications
You must be signed in to change notification settings - Fork 0
/
Friends.lua
279 lines (249 loc) · 9.46 KB
/
Friends.lua
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
local _, core = ...
local clientLevelNameString = "%s (%d |c%s%s|r%s) |cff%02x%02x%02x%s|r"
local levelNameClassString = "%d %s%s%s"
local activezone, inactivezone = {r=0.3, g=1.0, b=0.3}, {r=0.65, g=0.65, b=0.65}
local statusTable = { "|cffff0000[AFK]|r", "|cffff0000[DND]|r", "" }
local groupedTable = { "|cffaaaaaa*|r", "" }
local function onClick(self, arg1)
ChatFrame_SendSmartTell(arg1)
end
local dropdown = CreateFrame("Frame")
dropdown.displayMode = "MENU"
dropdown.initialize = function(self, level)
if level ~= 1 then return end
local numBNetTotal, numBNetOnline, numBNetFavorite, numBNetFavoriteOnline = BNGetNumFriends()
local numWoWOnline = C_FriendList.GetNumOnlineFriends()
if (numBNetOnline + numWoWOnline) > 0 then
if numWoWOnline > 0 then
local info = UIDropDownMenu_CreateInfo()
info.text = "World of Warcraft"
info.isTitle = true
info.notCheckable = true
UIDropDownMenu_AddButton(info)
for i = 1, numWoWOnline do
local friendInfo = C_FriendList.GetFriendInfoByIndex(i)
local name = friendInfo.name
local class = friendInfo.class
local zonec
if friendInfo.area == GetRealZoneText() then
zonec = activezone
else
zonec = inactivezone
end
for k, v in pairs(LOCALIZED_CLASS_NAMES_MALE) do if class == v then class = k end end
local classc = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
local grouped
if UnitInParty(name) or UnitInRaid(name) then
grouped = 1
else
grouped = 2
end
local info = UIDropDownMenu_CreateInfo()
info.text = format(levelNameClassString, friendInfo.level, name, groupedTable[grouped], " "..friendInfo.status)
-- info.value = i
info.func = onClick
info.arg1 = name
info.colorCode = "|c"..classc.colorStr
info.notCheckable = true
UIDropDownMenu_AddButton(info)
end
end
if numBNetOnline > 0 then
local info = UIDropDownMenu_CreateInfo()
info.text = "Battle.net"
info.isTitle = true
info.notCheckable = true
UIDropDownMenu_AddButton(info)
local friendIndices = {}
for i = 1, numBNetFavoriteOnline do tinsert(friendIndices, i) end
for i = numBNetFavorite + 1, numBNetOnline + (numBNetFavorite - numBNetFavoriteOnline) do tinsert(friendIndices, i) end
for i, v in ipairs(friendIndices) do
local accountInfo = C_BattleNet.GetFriendAccountInfo(v)
local accountName = accountInfo.accountName
local gameAccountInfo = accountInfo.gameAccountInfo
local characterName = gameAccountInfo and gameAccountInfo.characterName
local client = gameAccountInfo and gameAccountInfo.clientProgram
if client == BNET_CLIENT_WOW then
local class = gameAccountInfo.className
for k, v in pairs(LOCALIZED_CLASS_NAMES_MALE) do if class == v then class = k end end
local classc = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class].colorStr
local grouped
if UnitInParty(characterName) or UnitInRaid(characterName) then
grouped = 1
else
grouped = 2
end
local info = UIDropDownMenu_CreateInfo()
info.text = accountName
-- info.value = i
info.func = onClick
info.arg1 = accountName
-- info.colorCode = "|c"..classc.colorStr
info.notCheckable = true
UIDropDownMenu_AddButton(info)
else
GameTooltip:AddDoubleLine("|cffeeeeee"..accountName.."|r", "|cffeeeeee"..client.." ("..(characterName or "")..")|r")
end
end
end
end
end
local module = core:NewModule("Friends", {
type = "data source",
label = "Friends",
OnClick = function(self, button)
if button == "LeftButton" then
ToggleFriendsFrame(1)
else
GameTooltip:Hide()
ToggleDropDownMenu(nil, nil, dropdown, self, 0, 0)
end
end,
})
function module:OnInitialize()
self:RegisterEvent("PLAYER_LOGIN", "Update")
self:RegisterEvent("FRIENDLIST_UPDATE", "Update")
self:RegisterEvent("BN_FRIEND_ACCOUNT_ONLINE", "Update")
self:RegisterEvent("BN_FRIEND_ACCOUNT_OFFLINE", "Update")
end
function module:Update()
local numBNetTotal, numBNetOnline = BNGetNumFriends()
local numWoWOnline = C_FriendList.GetNumOnlineFriends()
self.text = numBNetOnline + numWoWOnline
end
function module:OnTooltipShow()
local numBNetTotal, numBNetOnline, numBNetFavorite, numBNetFavoriteOnline = BNGetNumFriends()
local numWoWOnline = C_FriendList.GetNumOnlineFriends()
if (numBNetOnline + numWoWOnline) > 0 then
self:AddLine("Friends", HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b)
if numWoWOnline > 0 then
GameTooltip:AddLine(" ")
GameTooltip:AddLine("World of Warcraft")
for i = 1, numWoWOnline do
local friendInfo = C_FriendList.GetFriendInfoByIndex(i)
local name = friendInfo.name
local status = 0
if friendInfo.isAFK then
status = 1
elseif friendInfo.isDND then
status = 2
else
status = 3
end
local zonec
if friendInfo.area == GetRealZoneText() then
zonec = activezone
else
zonec = inactivezone
end
local class = friendInfo.className
for k, v in pairs(LOCALIZED_CLASS_NAMES_MALE) do
if v == class then
class = k
end
end
local classc = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
local grouped
if UnitInParty(name) or UnitInRaid(name) then
grouped = 1
else
grouped = 2
end
GameTooltip:AddDoubleLine(format(levelNameClassString, friendInfo.level, name, groupedTable[grouped], " "..statusTable[status]), friendInfo.area, classc.r, classc.g, classc.b, zonec.r, zonec.g, zonec.b)
end
end
if numBNetOnline > 0 then
GameTooltip:AddLine(" ")
GameTooltip:AddLine("Battle.net")
local friendIndices = {}
for i = 1, numBNetFavoriteOnline do tinsert(friendIndices, i) end
for i = numBNetFavorite + 1, numBNetOnline + (numBNetFavorite - numBNetFavoriteOnline) do tinsert(friendIndices, i) end
for i, v in ipairs(friendIndices) do
local accountInfo = C_BattleNet.GetFriendAccountInfo(v)
local gameAccountInfo = accountInfo.gameAccountInfo
local characterName = gameAccountInfo.characterName
local client = gameAccountInfo.clientProgram
if client == BNET_CLIENT_WOW then
local status = 0
if accountInfo.isAFK then
status = 1
elseif accountInfo.isDND then
status = 2
else
status = 3
end
local class = gameAccountInfo.className
for k, v in pairs(LOCALIZED_CLASS_NAMES_MALE) do if class == v then class = k end end
local classc = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class].colorStr
local grouped
if UnitInParty(characterName) or UnitInRaid(characterName) then
grouped = 1
else
grouped = 2
end
GameTooltip:AddDoubleLine(accountInfo.accountName, format(clientLevelNameString, client, gameAccountInfo.characterLevel, classc or "ffffffff", characterName, groupedTable[grouped], 255, 0, 0, statusTable[status]), 238, 238, 238, 238, 238, 238)
if IsShiftKeyDown() then
local zoneName = gameAccountInfo.areaName
local zonec
if GetRealZoneText() == zoneName then
zonec = activezone
else
zonec = inactivezone
end
local realmName = gameAccountInfo.realmName
local realmc
if GetRealmName() == realmName then
realmc = activezone
else
realmc = inactivezone
end
GameTooltip:AddDoubleLine(" "..zoneName, realmName, zonec.r, zonec.g, zonec.b, realmc.r, realmc.g, realmc.b)
end
else
if client ~= BNET_CLIENT_APP and client ~= "BSAp" then
characterName = BNet_GetValidatedCharacterName(characterName, accountInfo.battleTag, client)
GameTooltip:AddDoubleLine(accountInfo.accountName, format("%s (%s)", client, characterName), 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
else
GameTooltip:AddLine(accountInfo.accountName, 1.0, 1.0, 1.0)
end
end
end
end
GameTooltip:Show()
-- else
-- GameTooltip:Hide()
end
end
local menuList = {
{ text = OPTIONS_MENU, isTitle = true,notCheckable=true},
{ text = INVITE, hasArrow = true,notCheckable=true, },
{ text = CHAT_MSG_WHISPER_INFORM, hasArrow = true,notCheckable=true, },
{ text = PLAYER_STATUS, hasArrow = true, notCheckable=true,
menuList = {
{ text = "|cff2BC226"..AVAILABLE.."|r", notCheckable=true, func = function() if IsChatAFK() then SendChatMessage("", "AFK") elseif IsChatDND() then SendChatMessage("", "DND") end end },
{ text = "|cffE7E716"..DND.."|r", notCheckable=true, func = function() if not IsChatDND() then SendChatMessage("", "DND") end end },
{ text = "|cffFF0000"..AFK.."|r", notCheckable=true, func = function() if not IsChatAFK() then SendChatMessage("", "AFK") end end },
},
},
{ text = BN_BROADCAST_TOOLTIP, notCheckable=true, func = function() T.ShowPopup("TUKUI_SET_BN_BROADCAST") end },
}
local function inviteClick(self, arg1, arg2, checked)
menuFrame:Hide()
if type(arg1) ~= 'number' then
InviteUnit(arg1)
else
BNInviteFriend(arg1);
end
end
local function whisperClick(self,name,bnet)
menuFrame:Hide()
if bnet then
ChatFrame_SendSmartTell(name)
else
SetItemRef( "player:"..name, ("|Hplayer:%1$s|h[%1$s]|h"):format(name), "LeftButton" )
end
end
-- Stat:RegisterEvent("BN_FRIEND_INFO_CHANGED")
-- Stat:RegisterEvent("BN_FRIEND_TOON_ONLINE")
-- Stat:RegisterEvent("BN_FRIEND_TOON_OFFLINE")
-- Stat:RegisterEvent("BN_TOON_NAME_UPDATED")