-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMythicKeystoneStatus.lua
More file actions
executable file
·549 lines (424 loc) · 17.2 KB
/
MythicKeystoneStatus.lua
File metadata and controls
executable file
·549 lines (424 loc) · 17.2 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
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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
local L = LibStub("AceLocale-3.0"):GetLocale("MythicKeystoneStatus")
MythicKeystoneStatus = LibStub("AceAddon-3.0"):NewAddon("MythicKeystoneStatus", "AceConsole-3.0", "AceEvent-3.0", "AceTimer-3.0" );
local LDB = LibStub("LibDataBroker-1.1", true)
local LDBIcon = LDB and LibStub("LibDBIcon-1.0", true)
local LibQTip = LibStub('LibQTip-1.0')
local frame = nil
local keystoneStoneDungeons = nil
local updateDelay = 3
local textures = {}
textures.alliance = "|TInterface\\FriendsFrame\\PlusManz-Alliance:18|t"
textures.horde = "|TInterface\\FriendsFrame\\PlusManz-Horde:18|t"
local yellow = { r = 1.0, g = 1.0, b = 0.2 }
local gray = { r = 0.5, g = 0.5, b = 0.5 }
local green = { r = 0.2, g = 1.0, b = 0.2 }
local red = { r = 1.0, g = 0.2, b = 0.2 }
local addonName = "MythicKeystoneStatus"
local ldbObject = LDB:NewDataObject(addonName, {
type = "data source",
--text = L["Mythic Keystone Status"],
label = L["Keystone"],
tocname = "MKS",
icon = "Interface\\TARGETINGFRAME\\UI-RaidTargetingIcon_1.png",
OnClick = function(clickedframe, button)
MythicKeystoneStatus:ShowOptions()
end,
OnEnter = function(self)
frame = self
MythicKeystoneStatus:ShowToolTip()
end
})
local function GetKeystoneDungeonList()
local dungeons = {}
local maps = C_ChallengeMode.GetMapTable();
for i = 1, #maps do
local mapInfo = maps[i]
local mapChallengeModeID = maps[i]
local mapName, _, _, mapTexture = C_ChallengeMode.GetMapUIInfo(mapChallengeModeID)
tinsert(dungeons, { id = mapChallengeModeID, name = mapName, texture = mapTexture})
end
table.sort(dungeons, function(a, b) return a.name < b.name end);
return dungeons
end
local function GetCharacterInfo()
if (UnitLevel("player") < 110) then return end
local characterInfo = {}
local _, class = UnitClass("player")
characterInfo.name = UnitName("player")
characterInfo.realm = GetRealmName()
characterInfo.lastUpdate = time()
characterInfo.class = class
characterInfo.level = UnitLevel("player")
characterInfo.faction = UnitFactionGroup("player")
characterInfo.keystoneStatus = GetKeystoneStatus()
return characterInfo
end
local function GetCharacter()
local characters = MythicKeystoneStatus.db.global.characters or {}
local name = UnitName("player")
local realm = GetRealmName()
local info = characters[name .. "-" .. realm] or GetCharacterInfo()
return info
end
local function PutCharacter(character)
local characters = MythicKeystoneStatus.db.global.characters or {}
characters[character.name .. "-" .. character.realm] = character
MythicKeystoneStatus.db.global.characters = characters
end
local function UpdateCharacter()
if (UnitLevel("player") < 120) then return end
local currentCharacter = GetCharacterInfo()
if currentCharacter.keystoneStatus then
PutCharacter(currentCharacter)
end
if (currentCharacter.keystoneStatus and currentCharacter.keystoneStatus.weeklyBest) then
ldbObject.text = "+" .. currentCharacter.keystoneStatus.weeklyBest.level
else
ldbObject.text = ""
end
MythicKeystoneStatus.updateTimer = nil
end
local function DelayedUpdate()
if MythicKeystoneStatus:TimeLeft(MythicKeystoneStatus.updateTimer) == 0 then
MythicKeystoneStatus.updateTimer = MythicKeystoneStatus:ScheduleTimer(UpdateCharacter, updateDelay)
end
end
local function GetActiveKeystone()
local keystoneInfo = nil
local mapID = C_MythicPlus.GetOwnedKeystoneChallengeMapID()
if mapID then
local keystoneLevel = C_MythicPlus.GetOwnedKeystoneLevel()
local keystoneDungeon = C_ChallengeMode.GetMapUIInfo(mapID);
keystoneInfo = { dungeon = keystoneDungeon, level = keystoneLevel, link = keystoneLink }
end
return keystoneInfo;
end
local function Update()
local character = GetCharacter()
if (character) then
character.keystoneStatus.activeKeystone = GetActiveKeystone()
PutCharacter(character)
end
end
function MythicKeystoneStatus:OnInitialize()
local defaults = MythicKeystoneStatus:GetDefaultOptions()
self.db = LibStub("AceDB-3.0"):New("MythicKeystoneStatusDB", defaults, true)
LDBIcon:Register(addonName, ldbObject, self.db.global.options.MinimapButton)
MythicKeystoneStatus:InitializeOptions()
end
function MythicKeystoneStatus:ToggleMinimapButton(info, value)
local options = MythicKeystoneStatus:GetOptions()
options.MinimapButton.hide = not value
if options.MinimapButton.hide then
LDBIcon:Hide(addonName)
else
LDBIcon:Show(addonName)
end
MythicKeystoneStatus:SetOptions(options)
--LDBIcon:Refresh(addonName)
--LDBIcon:Refresh(addonName)
end
function MythicKeystoneStatus:OnEnable()
C_MythicPlus.RequestMapInfo();
local dungeons = GetKeystoneDungeonList()
self:RegisterEvent("MYTHIC_PLUS_NEW_WEEKLY_RECORD")
self:RegisterEvent("MYTHIC_PLUS_NEW_SEASON_RECORD")
DelayedUpdate()
--self.updateTimer = MythicKeystoneStatus:ScheduleTimer(UpdateCharacter, updateDelay)
end
function MythicKeystoneStatus:OnDisable()
self:UnregisterEvent("MYTHIC_PLUS_NEW_WEEKLY_RECORD")
self:UnregisterEvent("MYTHIC_PLUS_NEW_SEASON_RECORD")
end
function MythicKeystoneStatus:MYTHIC_PLUS_NEW_WEEKLY_RECORD(event, payload)
DelayedUpdate()
-- MythicKeystoneStatus:Print(string.format("New weekly record for %s [+%d] %s",C_ChallengeMode.GetMapUIInfo(payload.mapChallengeModeID), payload.level, GetTimeStringFromSeconds(payload.completionMilliseconds/1000)))
end
function MythicKeystoneStatus:MYTHIC_PLUS_NEW_SEASON_RECORD(event, payload)
DelayedUpdate()
--MythicKeystoneStatus:Print(string.format("New season record for %s [+%d] %s",C_ChallengeMode.GetMapUIInfo(payload.mapChallengeModeID), payload.level, GetTimeStringFromSeconds(payload.completionMilliseconds/1000)))
end
local function GetWeeklyQuestResetTime()
local now = time()
local region = GetCurrentRegion()
local dayOffset = { 2, 1, 0, 6, 5, 4, 3 }
local regionDayOffset = {{ 2, 1, 0, 6, 5, 4, 3 }, { 4, 3, 2, 1, 0, 6, 5 }, { 3, 2, 1, 0, 6, 5, 4 }, { 4, 3, 2, 1, 0, 6, 5 }, { 4, 3, 2, 1, 0, 6, 5 } }
local nextDailyReset = GetQuestResetTime()
local utc = date("!*t", now + nextDailyReset)
local reset = regionDayOffset[region][utc.wday] * 86400 + nextDailyReset
return time() + reset
end
local function GetCharacters(realm)
local sortedCharacters = {}
local characters = MythicKeystoneStatus.db.global.characters or {}
for key,value in pairs(characters) do
if ((not realm) or (realm == characters[i].realm) and value.level >= 110) then
tinsert(sortedCharacters, value)
end
end
table.sort(sortedCharacters, function(a, b) return a.name < b.name end)
return sortedCharacters
end
function GetKeystoneStatus()
local keystoneStatus = {}
local dungeons = GetKeystoneDungeonList()
for i = 1, #dungeons do
local mapID = dungeons[i].id
local status = {}
status.weeklyBest = {}
status.seasonBest = {}
status.weeklyBest.time, status.weeklyBest.level, _, _, status.weeklyBest.Memebers = C_MythicPlus.GetWeeklyBestForMap(mapID);
local intimeInfo, overtimeInfo = C_MythicPlus.GetSeasonBestForMap(mapID);
if intimeInfo then
status.seasonBest.time = intimeInfo.durationSec
status.seasonBest.level = intimeInfo.level
status.seasonBest.recordSet = intimeInfo.completionDate
status.seasonBest.members = intimeInfo.members
status.seasonBest.overtime = false
elseif overtimeInfo then
status.seasonBest.time = overtimeInfo.durationSec
status.seasonBest.level = overtimeInfo.level
status.seasonBest.recordSet = overtimeInfo.members
status.seasonBest.overtime = true
end
if (status.weeklyBest.level) then
if (not keystoneStatus.weeklyBest) or (keystoneStatus.weeklyBest.level < status.weeklyBest.level) or
( (keystoneStatus.weeklyBest.level == status.weeklyBest.level) and (keystoneStatus.weeklyBest.time > status.weeklyBest.time) ) then
keystoneStatus.weeklyBest = {level = status.weeklyBest.level, time = status.weeklyBest.time, overtime = false, dungeon = dungeons[i].name}
end
end
if (status.seasonBest.level) then
if (not keystoneStatus.seasonBest) or (keystoneStatus.seasonBest.level < status.seasonBest.level) or
( (keystoneStatus.seasonBest.level == status.seasonBest.level) and (keystoneStatus.seasonBest.time > status.seasonBest.time) ) then
keystoneStatus.seasonBest = {level = status.seasonBest.level, time = status.seasonBest.time, overtime = status.seasonBest.overtime, dungeon = dungeons[i].name}
end
end
keystoneStatus[dungeons[i].name] = status
end
keystoneStatus.activeKeystone = GetActiveKeystone()
return keystoneStatus
end
function MythicKeystoneStatus:ShowSubTooltip(cell, info)
if not info then
return
end
local character = info.character
local type = info.type
local title = nil
local subTooltip = MythicKeystoneStatus.subTooltip
local dungeons = GetKeystoneDungeonList()
if LibQTip:IsAcquired("MKSsubTooltip") and subTooltip then
subTooltip:Clear()
else
subTooltip = LibQTip:Acquire("MKSsubTooltip", 3, "LEFT", "LEFT", "RIGHT")
MythicKeystoneStatus.subTooltip = subTooltip
end
subTooltip:ClearAllPoints()
local tooltip = MythicKeystoneStatus.tooltip
local x, y = tooltip:GetParent():GetCenter()
if (tooltip:GetLeft() < x) then
subTooltip:SetPoint("LEFT", MythicKeystoneStatus.tooltip, "RIGHT", 20, 0)
else
subTooltip:SetPoint("RIGHT", MythicKeystoneStatus.tooltip, "LEFT", -20, 0)
end
if (tooltip:GetBottom() < y) then
subTooltip:SetPoint("BOTTOM", MythicKeystoneStatus.tooltip, "BOTTOM", 30, 0)
else
subTooltip:SetPoint("TOP", MythicKeystoneStatus.tooltip, "TOP", 30, 0)
end
--subTooltip:SetClampedToScreen(true)
--subTooltip:SetPoint("TOP", MythicKeystoneStatus.tooltip, "TOP", 30, 0)
--subTooltip:SetPoint("RIGHT", MythicKeystoneStatus.tooltip, "LEFT", -20, 0)
--subTooltip:SetPoint("BOTTOM", MythicKeystoneStatus.tooltip, "BOTTOM", 30, 0)
--subTooltip:SetPoint("LEFT", MythicKeystoneStatus.tooltip, "RIGHT", 20, 0)
if (type == "WEEKLY") then
title = L["Weekly Best"]
else
title = L["Season Best"]
end
line = subTooltip:AddLine()
subTooltip:SetCell(line, 1, title, nil, "LEFT", 3)
subTooltip:SetCellTextColor(line, 1, yellow.r, yellow.g, yellow.b)
subTooltip:AddSeparator(6,0,0,0,0)
line = subTooltip:AddLine(L["Dungeon"], L["Time"], L["Level"])
subTooltip:SetLineTextColor(line, yellow.r, yellow.g, yellow.b)
subTooltip:AddSeparator(3,0,0,0,0)
for i = 1, #dungeons do
local line = subTooltip:AddLine()
local dungeon = character.keystoneStatus[dungeons[i].name]
subTooltip:SetCell(line, 1, "|T"..dungeons[i].texture..":0|t " .. dungeons[i].name, nil, "LEFT", nil, nil, nil, 10)
if type == "WEEKLY" then
status = dungeon.weeklyBest
else
status = dungeon.seasonBest
end
if status then
if status.time then
subTooltip:SetCell(line, 2, GetTimeStringFromSeconds(status.time), nil, "LEFT")
else
subTooltip:SetLineTextColor(line, gray.r, gray.g, gray.b)
end
if status.level then
subTooltip:SetCell(line, 3, "+"..status.level, nil, "RIGHT")
end
if status.overtime then
subTooltip:SetCellTextColor(line, 2, red.r, red.g, red.b)
subTooltip:SetCellTextColor(line, 3, red.r, red.g, red.b)
else
subTooltip:SetCellTextColor(line, 3, green.r, green.g, green.b)
end
end
end
subTooltip:Show()
end
function HideSubTooltip()
local subTooltip = MythicKeystoneStatus.subTooltip
if subTooltip then
LibQTip:Release(subTooltip)
subTooltip = nil
end
GameTooltip:Hide()
MythicKeystoneStatus.subTooltip = subTooltip
end
local function GetDungeonNameOffset()
local offset = 0
local options = MythicKeystoneStatus:GetOptions()
if (options.showDungeonNames) then
offset = 1
end
return offset
end
local function GetSeasonBestOffset()
local offset = 0
local options = MythicKeystoneStatus:GetOptions()
if (options.showSeasonBest) then
offset = 1 + GetDungeonNameOffset()
end
return offset
end
local function ShowCharacter(characterInfo)
local lastReset = GetWeeklyQuestResetTime() - 604800
local tooltip = MythicKeystoneStatus.tooltip
local line = tooltip:AddLine()
local factionIcon = ""
local dungeons = GetKeystoneDungeonList()
local keystoneStatus = characterInfo.keystoneStatus
local characterName = characterInfo.name
local dungeonNameOffset = GetDungeonNameOffset()
local seasonBestOffset = GetSeasonBestOffset()
local options = MythicKeystoneStatus:GetOptions()
if (options.expandCharacterNames) then
characterName = characterInfo.name .. "-" .. characterInfo.realm
end
if characterInfo.faction and characterInfo.faction == "Alliance" then
factionIcon = textures.alliance
elseif characterInfo.faction and characterInfo.faction == "Horde" then
factionIcon = textures.horde
end
tooltip:SetCell(line, 1, factionIcon.." "..characterName)
if characterInfo.class then
local color = RAID_CLASS_COLORS[characterInfo.class]
tooltip:SetCellTextColor(line, 1, color.r, color.g, color.b)
end
if (characterInfo.lastUpdate > lastReset) and (keystoneStatus.weeklyBest) then
if (options.showDungeonNames) then
tooltip:SetCell(line, 2, keystoneStatus.weeklyBest.dungeon, nil, "RIGHT", nil, nil, 10)
end
tooltip:SetCell(line, 2 + dungeonNameOffset, "+" .. keystoneStatus.weeklyBest.level, nil, "RIGHT")
end
if keystoneStatus.weeklyBest then
if keystoneStatus.weeklyBest.overtime then
tooltip:SetCellTextColor(line, 2 + dungeonNameOffset, red.r, red.g, red.b)
else
tooltip:SetCellTextColor(line, 2 + dungeonNameOffset, green.r, green.g, green.b)
end
end
tooltip:SetCellScript(line, 2 + dungeonNameOffset, "OnEnter", function(self)
local info = { character = characterInfo, type = "WEEKLY" }
MythicKeystoneStatus:ShowSubTooltip(self, info)
end)
tooltip:SetCellScript(line, 2 + dungeonNameOffset, "OnLeave", HideSubTooltip)
if (options.showSeasonBest) then
if (keystoneStatus.seasonBest) then
if (options.showDungeonNames) then
tooltip:SetCell(line, 4, keystoneStatus.seasonBest.dungeon, nil, "RIGHT", nil, nil, 10)
end
tooltip:SetCell(line, 3 + (2 * dungeonNameOffset), "+" .. keystoneStatus.seasonBest.level, nil, "RIGHT")
end
tooltip:SetCellTextColor(line, 3 + (2 * dungeonNameOffset), green.r, green.g, green.b)
tooltip:SetCellScript(line, 3 + (2 * dungeonNameOffset), "OnEnter", function(self)
local info = { character = characterInfo, type= "SEASON" }
MythicKeystoneStatus:ShowSubTooltip(self, info)
end)
tooltip:SetCellScript(line, 3 + (2 * dungeonNameOffset), "OnLeave", HideSubTooltip)
end
if (characterInfo.lastUpdate > lastReset) and (keystoneStatus.activeKeystone) then
tooltip:SetCell(line, 3 + seasonBestOffset + dungeonNameOffset, keystoneStatus.activeKeystone.dungeon, nil, "RIGHT", nil, nil, 10)
tooltip:SetCell(line, 4 + seasonBestOffset + dungeonNameOffset, "+" .. keystoneStatus.activeKeystone.level, nil, "RIGHT")
end
if keystoneStatus.seasonBest then
if keystoneStatus.seasonBest.overtime then
tooltip:SetCellTextColor(line, 4 + seasonBestOffset + dungeonNameOffset, red.r, red.g, red.b)
else
tooltip:SetCellTextColor(line, 4 + seasonBestOffset + dungeonNameOffset, green.r, green.g, green.b)
end
end
end
function MythicKeystoneStatus:ShowToolTip()
C_MythicPlus.RequestMapInfo();
local tooltip = MythicKeystoneStatus.tooltip
local dungeons = GetKeystoneDungeonList()
local characters = GetCharacters()
local columnCount = 5
local dungeonNameOffset = GetDungeonNameOffset()
local seasonBestOffset = GetSeasonBestOffset()
local weeklyBestTitle = L["Weekly"]
local seasonBestTitle = L["Season"]
local options = MythicKeystoneStatus:GetOptions()
if (options.showDungeonNames) then
weeklyBestTitle = L["Weekly Best"]
seasonBestTitle = L["Season Best"]
end
columnCount = 4 + dungeonNameOffset + seasonBestOffset
if LibQTip:IsAcquired("MythicKeystoneStatusTooltip") and tooltip then
tooltip:Clear()
else
tooltip = LibQTip:Acquire("MythicKeystoneStatusTooltip", columnCount, "LEFT", "RIGHT", "RIGHT", "RIGHT", "RIGHT")
MythicKeystoneStatus.tooltip = tooltip
end
line = tooltip:AddHeader(" ")
tooltip:SetCell(1, 1, "|TInterface\\TARGETINGFRAME\\UI-RaidTargetingIcon_1:16|t "..L["Mythic Keystone Status"], nil, "LEFT", tooltip:GetColumnCount())
tooltip:AddSeparator(6,0,0,0,0)
line = tooltip:AddLine()
tooltip:SetCell(line, 1, L["Character"])
tooltip:SetCellTextColor(line, 1, yellow.r, yellow.g, yellow.b)
tooltip:SetCell(line, 2, weeklyBestTitle, nil, "RIGHT", 1 + dungeonNameOffset)
tooltip:SetCellTextColor(line, 2, yellow.r, yellow.g, yellow.b)
if (options.showSeasonBest) then
tooltip:SetCell(line, 3 + dungeonNameOffset, seasonBestTitle, nil, "RIGHT", 1 + dungeonNameOffset)
tooltip:SetCellTextColor(line, 3 + dungeonNameOffset, yellow.r, yellow.g, yellow.b)
column = 6
end
tooltip:SetCell(line, 3 + seasonBestOffset + dungeonNameOffset, L["Active Keystone"], nil, "RIGHT", 2)
tooltip:SetCellTextColor(line, 3 + seasonBestOffset + dungeonNameOffset, yellow.r, yellow.g, yellow.b)
tooltip:AddSeparator(3,0,0,0,0)
for i=1, #characters do
local character = characters[i]
if character.keystoneStatus then
if character.keystoneStatus.weeklyBest or character.keystoneStatus.seasonBest or character.keystoneStatus.activeKeystone then
ShowCharacter(character)
end
end
end
if (options.showTips) then
tooltip:AddSeparator(6,0,0,0,0)
line = tooltip:AddLine()
tooltip:SetCell(line, 1, L["TIP: Hover over level number for more details"], nil, "LEFT", columnCount)
end
if (frame) then
tooltip:SetAutoHideDelay(0.01, frame)
tooltip:SmartAnchorTo(frame)
end
tooltip:UpdateScrolling()
tooltip:Show()
end