/
HoverTips.lua
executable file
·310 lines (272 loc) · 10.9 KB
/
HoverTips.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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
local orig1, orig2 = {}, {}
local GameTooltip = GameTooltip
-- TODO: battlepet & battlePetAbil? requires our own tooltips inheriting BattlePetTooltipTemplate & SharedPetBattleAbilityTooltipTemplate
local linkTypes = {
item = true,
enchant = true,
spell = true,
quest = true,
unit = true,
talent = true,
achievement = true,
glyph = true,
instancelock = true,
currency = true,
BNplayer = true,
keystone = true,
battlepet = true,
}
local function ShowPlayerTooltip(frame, linkContent)
local playerName = strsplit(":", linkContent);
-- TODO: reload guild roster at appropriate times so this info exists?
local foundInGuild = false;
for i = 1, GetNumGuildMembers(1) do
local name, rank, rankIndex, level, class, zone, note, officernote, online, status, classFileName, achievementPoints, achievementRank, isMobile = GetGuildRosterInfo(i);
if (name == playerName) then
local guildName = GetGuildInfo("player");
local guildColor = ChatTypeInfo["GUILD"];
local officerColor = ChatTypeInfo["OFFICER"];
local C = HIGHLIGHT_FONT_COLOR;
local G = GRAY_FONT_COLOR;
GameTooltip:SetOwner(frame, "ANCHOR_TOPLEFT");
if (isMobile) then
GameTooltip:SetText(ChatFrame_GetMobileEmbeddedTexture(73/255, 177/255, 73/255).." "..name, C.r, G.g, G.b);
elseif (not online) then
GameTooltip:AddDoubleLine(name, PLAYER_OFFLINE, C.r, C.g, C.b, G.r, G.g, G.b);
else
GameTooltip:SetText(name, C.r, C.g, C.b);
end
GameTooltip:AddLine(format(GUILD_TEMPLATE, rank, guildName), C.r, C.g, C.b);
GameTooltip:AddLine(format(FRIENDS_LEVEL_TEMPLATE, level, class), C.r, C.g, C.b);
GameTooltip:AddLine(zone, C.r, C.g, C.b);
if (note and note ~= "") then
GameTooltip:AddLine(note, guildColor.r, guildColor.g, guildColor.b);
end
if (officernote and officernote ~= "") then
GameTooltip:AddLine(officernote, officerColor.r, officerColor.g, officerColor.b);
end
GameTooltip:Show();
foundInGuild = true;
break;
end
end
for i = 1, GetNumFriends() do
local name, level, class, area, connected, status, note = GetFriendInfo(i);
if (name == playerName) then
if (not foundInGuild) then
local C = HIGHLIGHT_FONT_COLOR;
local G = GRAY_FONT_COLOR;
GameTooltip:SetOwner(frame, "ANCHOR_TOPLEFT");
if (not connected) then
GameTooltip:AddDoubleLine(name, PLAYER_OFFLINE, C.r, C.g, C.b, G.r, G.g, G.b);
elseif (status and status ~= "") then
GameTooltip:AddDoubleLine(name, status, C.r, C.g, C.b, G.r, G.g, G.b);
else
GameTooltip:SetText(name, C.r, C.g, C.b);
end
if (connected) then
GameTooltip:AddLine(format(FRIENDS_LEVEL_TEMPLATE, level, class), C.r, C.g, C.b);
GameTooltip:AddLine(area, C.r, C.g, C.b);
end
end
if (note and note ~= "") then
GameTooltip:AddLine(note);
end
GameTooltip:Show();
break;
end
end
-- TODO: if not friend, check party/raid/bg?
end
-- for debug
function HoverTips_PrintFriends()
for i = 1, BNGetNumFriends() do
local presenceID, presenceName, battleTag, isBattleTagPresence, toonName, toonID, client, isOnline, lastOnline, isAFK, isDND, broadcastText, noteText, isFriend, broadcastTime = BNGetFriendInfo(i);
print(format("|HBNplayer:%s:%s:%s:%s:%s|h[%s] (%s)|h", presenceName, presenceID, 0, 0, 0, presenceName, toonName or UNKNOWN));
end
end
local BROADCAST_FONT_COLOR = {r=0.345, g=0.667, b=0.867};
local ChatIcons = {
[BNET_CLIENT_WOW] = "|TInterface\\ChatFrame\\UI-ChatIcon-WOW:16|t",
[BNET_CLIENT_SC2] = "|TInterface\\ChatFrame\\UI-ChatIcon-SC2:16|t",
[BNET_CLIENT_D3] = "|TInterface\\ChatFrame\\UI-ChatIcon-D3:16|t",
[BNET_CLIENT_WTCG] = "|TInterface\\ChatFrame\\UI-ChatIcon-WTCG:16|t",
[BNET_CLIENT_APP] = "|TInterface\\ChatFrame\\UI-ChatIcon-Battlenet:16|t",
[BNET_CLIENT_HEROES] = "|TInterface\\ChatFrame\\UI-ChatIcon-HotS:16|t",
[BNET_CLIENT_OVERWATCH] = "|TInterface\\ChatFrame\\UI-ChatIcon-Overwatch:16|t",
[BNET_CLIENT_CLNT] = "|TInterface\\ChatFrame\\UI-ChatIcon-Battlenet:16|t",
broadcast = "|TInterface\\FriendsFrame\\BroadcastIcon:16|t",
note = "|TInterface\\FriendsFrame\\UI-FriendsFrame-Note:12:14|t",
offline = "|TInterface\\FriendsFrame\\StatusIcon-Offline:16|t",
online = "|TInterface\\FriendsFrame\\StatusIcon-Online:16|t",
afk = "|TInterface\\FriendsFrame\\StatusIcon-Away:16|t",
dnd = "|TInterface\\FriendsFrame\\StatusIcon-DnD:16|t",
};
local function ShowBattleNetTooltip(frame, linkContent)
GameTooltip:SetOwner(frame, "ANCHOR_TOPLEFT");
local name, presenceID, lineid, chatType, chatTarget = strsplit(":", linkContent);
local presenceID, presenceName, battleTag, isBattleTagPresence, toonName, toonID, client, isOnline, lastOnline, isAFK, isDND, broadcastText, noteText, isFriend, broadcastTime = BNGetFriendInfoByID(presenceID);
local text;
-- friend name (realID name or battletag)
local nameText = UNKNOWN;
local characterName = toonName;
if ( presenceName ) then
nameText = presenceName;
-- if no character name but we have a BattleTag, use that
if ( isOnline and not characterName and battleTag ) then
characterName = battleTag;
end
end
local color = FRIENDS_GRAY_COLOR;
if (isOnline) then
color = FRIENDS_BNET_NAME_COLOR;
end
local statusIcon = ChatIcons.offline;
if (isAFK) then
statusIcon = ChatIcons.afk;
elseif (isDND) then
statusIcon = ChatIcons.dnd;
elseif (isOnline) then
statusIcon = ChatIcons.online;
end
GameTooltip:AddDoubleLine(nameText, statusIcon, color.r, color.g, color.b);
-- current toon
if ( toonID ) then
local hasFocus, _, client, realmName, realmID, faction, race, class, guild, zoneName, level, gameText, broadcast, broadcastTime, online, bnetIDGameAccount, bnetIDAccount = BNGetGameAccountInfo(presenceID);
level = level or "";
race = race or "";
class = class or "";
local c = FRIENDS_GRAY_COLOR;
if ( client == BNET_CLIENT_WOW ) then
if ( CanCooperateWithToon(toonID, HasTravelPass()) ) then
text = string.format(FRIENDS_TOOLTIP_WOW_TOON_TEMPLATE, characterName, level, race, class);
else
text = string.format(FRIENDS_TOOLTIP_WOW_TOON_TEMPLATE, characterName..CANNOT_COOPERATE_LABEL, level, race, class);
end
GameTooltip:AddLine(ChatIcons[client] .. text, c.r,c.g,c.b);
local FRIENDS_TOOLTIP_WOW_INFO_TEMPLATE = " " .. NORMAL_FONT_COLOR_CODE .. FRIENDS_LIST_ZONE .. "|r%1$s|n " .. NORMAL_FONT_COLOR_CODE .. FRIENDS_LIST_REALM .. "|r%2$s";
GameTooltip:AddLine(string.format(FRIENDS_TOOLTIP_WOW_INFO_TEMPLATE, zoneName, realmName), c.r,c.g,c.b);
else
if (ChatIcons[client]) then
GameTooltip:AddLine(ChatIcons[client] .. characterName, c.r,c.g,c.b);
else
GameTooltip:AddLine(characterName, c.r,c.g,c.b);
end
if (gameText) then
GameTooltip:AddLine(" "..gameText, c.r,c.g,c.b);
end
end
end
-- note
if ( noteText and noteText ~= "" ) then
local c = NORMAL_FONT_COLOR;
GameTooltip:AddLine(ChatIcons.note .. noteText, c.r,c.g,c.b);
end
-- broadcast
if ( broadcastText and broadcastText ~= "" ) then
broadcastText = broadcastText .. "|n " .. FRIENDS_BROADCAST_TIME_COLOR_CODE .. string.format(BNET_BROADCAST_SENT_TIME, FriendsFrame_GetLastOnline(broadcastTime));
local c = BROADCAST_FONT_COLOR;
GameTooltip:AddLine(ChatIcons.broadcast .. broadcastText, c.r,c.g,c.b);
end
-- last online (if offline)
if (not isOnline ) then
if ( lastOnline == 0 ) then
text = FRIENDS_LIST_OFFLINE;
else
text = string.format(BNET_LAST_ONLINE_TIME, FriendsFrame_GetLastOnline(lastOnline)); -- TODO error here
end
local c = FRIENDS_GRAY_COLOR;
GameTooltip:AddLine(text, c.r,c.g,c.b);
end
GameTooltip:Show();
end
local function ShowJournalTooltip(frame, linkContent)
local jtype, id, difficulty = strsplit(":", linkContent);
jtype = tonumber(jtype);
id = tonumber(id);
difficulty = tonumber(difficulty);
local instanceID, encounterID, sectionID, tierIndex = EJ_HandleLinkPath(jtype, id);
if (instanceID == nil and encounterID == nil and sectionID == nil) then
-- we can get this for dungeon tier links which appear when you level up
-- but there's nothing sensible to put in a tooltip for them
return;
end
EJ_SetDifficulty(difficulty);
local C = HIGHLIGHT_FONT_COLOR;
if (encounterID == nil) then
local name, description = EJ_GetInstanceInfo(instanceID);
GameTooltip:SetOwner(frame, "ANCHOR_TOPLEFT");
GameTooltip:SetText(name, C.r, C.g, C.b);
GameTooltip:AddLine(description, nil, nil, nil, true);
GameTooltip:Show();
elseif (sectionID == nil) then
local instance = EJ_GetInstanceInfo(instanceID);
local name, description = EJ_GetEncounterInfo(encounterID);
GameTooltip:SetOwner(frame, "ANCHOR_TOPLEFT");
GameTooltip:SetText(name, C.r, C.g, C.b);
GameTooltip:AddLine(instance, C.r, C.g, C.b);
GameTooltip:AddLine(description, nil, nil, nil, true);
GameTooltip:Show();
else
local instance = EJ_GetInstanceInfo(instanceID);
local encounter = EJ_GetEncounterInfo(encounterID);
local name, description = EJ_GetSectionInfo(sectionID);
GameTooltip:SetOwner(frame, "ANCHOR_TOPLEFT");
GameTooltip:SetText(name, C.r, C.g, C.b);
GameTooltip:AddLine(encounter .." - ".. instance, C.r, C.g, C.b);
GameTooltip:AddLine(description, nil, nil, nil, true);
GameTooltip:Show();
end
end
local function ShowBattlePetTooltip(frame, linkContent)
GameTooltip:SetOwner(frame, "ANCHOR_TOPRIGHT")
local petInfo = {}
for _, string in pairs({strsplit(":", linkContent)}) do
tinsert(petInfo, tonumber(string))
end
BattlePetToolTip_Show(unpack(petInfo))
end
local function OnHyperlinkEnter(frame, link, ...)
local linkType, linkContent = link:match("^([^:]+):(.+)")
if (linkType) then
if (linkType == FDA_LINK_TYPE and FDA_ShowCurrentArtifactTooltipForRace) then
local raceIndex = tonumber(linkContent);
if (raceIndex) then
GameTooltip:SetOwner(frame, "ANCHOR_TOPLEFT")
FDA_ShowCurrentArtifactTooltipForRace(GameTooltip, raceIndex);
end
elseif (linkType == FDA_SOLVE_LINK_TYPE and FDA_ShowSolveTooltipForRace) then
local raceIndex = tonumber(linkContent);
if (raceIndex) then
GameTooltip:SetOwner(frame, "ANCHOR_TOPLEFT")
FDA_ShowSolveTooltipForRace(raceIndex);
end
elseif (linkType == "player") then
ShowPlayerTooltip(frame, linkContent);
elseif (linkType == "BNplayer") then
ShowBattleNetTooltip(frame, linkContent);
elseif (linkType == "journal") then
ShowJournalTooltip(frame, linkContent);
elseif (linkType == "battlepet") then
ShowBattlePetTooltip(frame, linkContent)
elseif linkTypes[linkType] then
GameTooltip:SetOwner(frame, "ANCHOR_TOPLEFT")
GameTooltip:SetHyperlink(link)
GameTooltip:Show()
end
end
if orig1[frame] then return orig1[frame](frame, link, ...) end
end
local function OnHyperlinkLeave(frame, ...)
GameTooltip:Hide()
BattlePetTooltip:Hide()
if orig2[frame] then return orig2[frame](frame, ...) end
end
local _G = getfenv(0)
for i=1, NUM_CHAT_WINDOWS do
local frame = _G["ChatFrame"..i]
orig1[frame] = frame:GetScript("OnHyperlinkEnter")
frame:SetScript("OnHyperlinkEnter", OnHyperlinkEnter)
orig2[frame] = frame:GetScript("OnHyperlinkLeave")
frame:SetScript("OnHyperlinkLeave", OnHyperlinkLeave)
end