-
-
Notifications
You must be signed in to change notification settings - Fork 228
/
Copy pathMythicDungeonTools.lua
4975 lines (4561 loc) · 183 KB
/
MythicDungeonTools.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
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
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- Made by Nnoggie, 2017-2024
local AddonName, MDT = ...
local L = MDT.L
local mainFrameStrata = "HIGH"
local canvasDrawLayer = "BORDER"
local tinsert, tremove, CreateFrame, tonumber, max, min, abs, pairs, ipairs, GetCursorPosition, GameTooltip, MouseIsOver =
table
.insert
, table.remove, CreateFrame, tonumber, math.max, math.min, math.abs, pairs, ipairs, GetCursorPosition, GameTooltip,
MouseIsOver
local sizex = 840
local sizey = 555
local framesInitialized, initFrames
MDT.externalLinks = {
{
name = "GitHub",
tooltip = L["Open an issue on GitHub"],
url = "https://github.com/Nnoggie/MythicDungeonTools/issues",
texture = { "Interface\\AddOns\\MythicDungeonTools\\Textures\\icons", 0.76, 1, 0.75, 1 }
},
{
name = "Discord",
tooltip = L["Provide feedback in Discord"],
url = "https://discord.gg/tdxMPb3",
texture = { "Interface\\AddOns\\MythicDungeonTools\\Textures\\icons", 0.5, .75, 0.75, 1 }
},
}
BINDING_HEADER_MDT = "Mythic Dungeon Tools (MDT)"
BINDING_NAME_MDTTOGGLE = L["Toggle MDT"]
local mythicColor = "|cFFFFFFFF"
MDT.BackdropColor = { 0.058823399245739, 0.058823399245739, 0.058823399245739, 0.9 }
local AceGUI = LibStub("AceGUI-3.0")
local db
local minimapIcon = LibStub("LibDBIcon-1.0")
function MDT:HideMinimapButton()
db.minimap.hide = true
minimapIcon:Hide("MythicDungeonTools")
-- update the checkbox in settings
if MDT.main_frame and MDT.main_frame.minimapCheckbox then MDT.main_frame.minimapCheckbox:SetValue(false) end
print(L["MDT: Use /mdt minimap to show the minimap icon again"])
end
function MDT:ShowMinimapButton()
db.minimap.hide = false
minimapIcon:Show("MythicDungeonTools")
-- update the checkbox in settings
if MDT.main_frame and MDT.main_frame.minimapCheckbox then MDT.main_frame.minimapCheckbox:SetValue(true) end
end
---@diagnostic disable: missing-fields
local LDB = LibStub("LibDataBroker-1.1"):NewDataObject("MythicDungeonTools", {
type = "data source",
text = "Mythic Dungeon Tools",
icon = "Interface\\AddOns\\"..AddonName.."\\Textures\\MDTMinimap",
OnClick = function(button, buttonPressed)
if buttonPressed == "RightButton" then
if db.minimap.lock then
minimapIcon:Unlock("MythicDungeonTools")
else
minimapIcon:Lock("MythicDungeonTools")
end
elseif (buttonPressed == 'MiddleButton') then
if db.minimap.hide then
MDT:ShowMinimapButton()
else
MDT:HideMinimapButton()
end
else
MDT:Async(function() MDT:ShowInterfaceInternal() end, "showInterface")
end
end,
OnTooltipShow = function(tooltip)
if not tooltip or not tooltip.AddLine then return end
tooltip:AddLine(mythicColor.."Mythic Dungeon Tools|r")
tooltip:AddLine(L["Click to toggle AddOn Window"])
tooltip:AddLine(L["Right-click to lock Minimap Button"])
tooltip:AddLine(L["Middle-click to disable Minimap Button"])
end,
})
SLASH_MYTHICDUNGEONTOOLS1 = "/mplus"
SLASH_MYTHICDUNGEONTOOLS2 = "/mdt"
SLASH_MYTHICDUNGEONTOOLS3 = "/mythicdungeontools"
BINDING_NAME_MDTTOGGLE = L["Toggle Window"]
BINDING_NAME_MDTNPC = L["New NPC at Cursor Position"]
BINDING_NAME_MDTWAYPOINT = L["New Patrol Waypoint at Cursor Position"]
BINDING_NAME_MDTUNDODRAWING = L["undoDrawing"]
BINDING_NAME_MDTREDODRAWING = L["redoDrawing"]
---@diagnostic disable-next-line: duplicate-set-field
function SlashCmdList.MYTHICDUNGEONTOOLS(cmd, editbox)
cmd = cmd:lower()
local rqst, arg = strsplit(' ', cmd)
if rqst == "devmode" then
MDT:ToggleDevMode()
elseif rqst == "reset" then
MDT:ResetMainFramePos()
elseif rqst == "dc" then
MDT:ToggleDataCollection()
elseif rqst == "hardreset" then
if arg == "force" then
MDT:HardReset()
else
MDT:Async(function()
MDT:OpenConfirmationFrame(450, 150, L["hardResetPromptTitle"], L["Delete"], L["hardResetPrompt"], MDT.HardReset)
end, "hardReset")
end
elseif rqst == "minimap" then
if db.minimap.hide then
MDT:ShowMinimapButton()
else
MDT:HideMinimapButton()
end
elseif rqst == "test" then
MDT:OpenConfirmationFrame(450, 150, "MDT Test", "Run", "Run all tests?", MDT.test.RunAllTests)
else
MDT:Async(function() MDT:ShowInterfaceInternal() end, "showInterface")
end
end
--MDT.WagoAnalytics = LibStub("WagoAnalytics"):Register("rN4VrAKD")
function MDT:GetLocaleIndex()
local localeToIndex = {
["enUS"] = 1,
["deDE"] = 2,
["esES"] = 3,
["esMX"] = 4,
["frFR"] = 5,
["itIT"] = 6,
["ptBR"] = 7,
["ruRU"] = 8,
["koKR"] = 9,
["zhCN"] = 10,
["zhTW"] = 11,
}
return localeToIndex[GetLocale()] or 1
end
-------------------------
--- Saved Variables ----
-------------------------
local defaultSavedVars = {
global = {
toolbarExpanded = true,
currentSeason = 11, -- not really used for anything anymore
scale = 1,
nonFullscreenScale = 1.4,
enemyForcesFormat = 2,
useForcesCount = false, -- replaces percent in pull buttons with count
enemyStyle = 1,
currentDifficulty = 10,
xoffset = -80,
yoffset = -100,
defaultColor = "228b22",
anchorFrom = "TOP",
anchorTo = "TOP",
tooltipInCorner = false,
minimap = {
hide = false,
compartmentHide = false,
},
toolbar = {
color = { r = 1, g = 1, b = 1, a = 1 },
brushSize = 3,
},
presets = {},
currentPreset = {},
newDataCollectionActive = false,
colorPaletteInfo = {
autoColoring = true,
forceColorBlindMode = false,
colorPaletteIdx = 4,
customPaletteValues = {},
numberCustomColors = 12,
},
currentDungeonIdx = 31,
selectedDungeonList = 1,
latestSeenDungeonList = 0,
knownAffixWeeks = {},
},
}
do
for i = 1, 200 do
defaultSavedVars.global.presets[i] = {
[1] = {
text = L["Default"],
value = {},
objects = {},
colorPaletteInfo = { autoColoring = true, colorPaletteIdx = 4 }
},
[2] = { text = L["<New Preset>"], value = 0 },
}
defaultSavedVars.global.currentPreset[i] = 1
end
end
function MDT:GetDefaultSavedVariables()
return defaultSavedVars
end
-- Init db
local eventFrame
do
eventFrame = CreateFrame("Frame")
eventFrame:RegisterEvent("ADDON_LOADED")
eventFrame:RegisterEvent("GROUP_ROSTER_UPDATE")
eventFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
--TODO Register Affix Changed event
eventFrame:SetScript("OnEvent", function(self, event, ...)
return MDT[event](self, ...)
end)
function MDT.ADDON_LOADED(self, addon)
if addon == "MythicDungeonTools" then
db = LibStub("AceDB-3.0"):New("MythicDungeonToolsDB", defaultSavedVars).global
if not db then return end
---@diagnostic disable-next-line: param-type-mismatch
minimapIcon:Register("MythicDungeonTools", LDB, db.minimap)
if not db.minimap.hide then
minimapIcon:Show("MythicDungeonTools")
end
if db.newDataCollectionActive or MDT:IsOnBetaServer() then
MDT.DataCollection:Init()
MDT.DataCollection:InitHealthTrack()
end
--compartment
if not db.minimap.compartmentHide then
minimapIcon:AddButtonToCompartment("MythicDungeonTools")
end
--fix db corruption
do
for k, v in pairs(db.currentPreset) do
if v <= 0 then db.currentPreset[k] = 1 end
end
end
eventFrame:UnregisterEvent("ADDON_LOADED")
end
end
local last = 0
function MDT.GROUP_ROSTER_UPDATE()
--check not more than once per second (blizzard event spam)
local now = GetTime()
if last < now - 1 then
if not MDT.main_frame then return end
local inGroup = UnitInRaid("player") or IsInGroup()
MDT.main_frame.LinkToChatButton:SetDisabled(not inGroup)
MDT.main_frame.LiveSessionButton:SetDisabled(not inGroup)
if inGroup then
MDT.main_frame.LinkToChatButton.text:SetTextColor(1, 0.8196, 0)
if MDT.liveSessionActive then
MDT.main_frame.LiveSessionButton:SetText(L["*Live*"])
MDT.main_frame.LiveSessionButton.text:SetTextColor(0, 1, 0)
else
MDT.main_frame.LiveSessionButton:SetText(L["Live"])
MDT.main_frame.LiveSessionButton.text:SetTextColor(1, 0.8196, 0)
end
else
MDT.main_frame.LinkToChatButton.text:SetTextColor(0.5, 0.5, 0.5)
MDT.main_frame.LiveSessionButton.text:SetTextColor(0.5, 0.5, 0.5)
end
last = now
end
end
function MDT.PLAYER_ENTERING_WORLD()
--initialize Blizzard_ChallengesUI
C_Timer.After(1, function()
if db.loadOnStartUp and db.devMode then MDT:Async(function() MDT:ShowInterfaceInternal(true) end, "showInterface") end
end)
eventFrame:UnregisterEvent("PLAYER_ENTERING_WORLD")
end
end
--affixID as used in C_ChallengeMode.GetAffixInfo(affixID)
--https://www.wowhead.com/affixes
--lvl 4 affix, lvl 7 affix, tyrannical/fortified, seasonal affix
local affixWeeks = {
[1] = { 9, 148 },
[2] = { 10 },
[3] = { 9 },
[4] = { 10 },
[5] = { 9 },
[6] = { 10 },
[7] = { 9 },
[8] = { 10 },
[9] = { 9 },
[10] = { 10 },
}
MDT.mapInfo = {}
MDT.dungeonTotalCount = {}
MDT.scaleMultiplier = {}
MDT.dungeonMaps = {}
MDT.dungeonEnemies = {}
MDT.mapPOIs = {}
MDT.dungeonSubLevels = {}
MDT.dungeonList = {
-- these were for the old dropdown menu, need to fix this at some point
[14] = "-",
[27] = "-",
[28] = "-",
[39] = "-",
}
function MDT:IsOnBetaServer()
local realm = GetRealmName()
local regionID = GetCurrentRegion()
if regionID <= 5 then return false end
local realms = {
["These Go To Eleven"] = true,
["Turnips Delight"] = true,
["Alleria"] = true,
["Khadgar"] = true,
}
return realms[realm]
end
function MDT:GetNumDungeons()
local count = 0
for _, _ in pairs(MDT.dungeonList) do
count = count + 1
end
return count
end
function MDT:GetDungeonName(idx, forceEnglish)
-- don't fail hard for legacy dungeons
if forceEnglish and MDT.mapInfo[idx].englishName then
return MDT.mapInfo[idx].englishName
end
return MDT.dungeonList[idx]
end
function MDT:GetDungeonSublevels()
return MDT.dungeonSubLevels
end
function MDT:GetSublevelName(dungeonIdx, sublevelIdx)
if not dungeonIdx then dungeonIdx = db.currentDungeonIdx end
return MDT.dungeonSubLevels[dungeonIdx][sublevelIdx]
end
function MDT:GetDB()
return db
end
function MDT:ShowInterface(force)
MDT:Async(function() MDT:ShowInterfaceInternal(force) end, "showInterface")
end
function MDT:ShowInterfaceInternal(force)
if not self:IsCompatibleVersion() then
self:ShowFallbackWindow()
return
end
if self:CheckAddonConflicts() then
self.ShowConflictFrame()
return
end
MDT:DisplayErrors()
if not framesInitialized then initFrames() end
if not framesInitialized then return end
if self.main_frame:IsShown() and not force then
MDT:HideInterface()
else
self.main_frame:Show()
self:CheckCurrentZone()
--edge case if user closed MDT window while in the process of dragging a corrupted blip
if self.draggedBlip then
if MDT.liveSessionActive then
MDT:LiveSession_SendCorruptedPositions(MDT:GetRiftOffsets())
end
self:UpdateMap()
self.draggedBlip = nil
end
MDT:UpdateBottomText()
end
end
function MDT:HideInterface()
if self.main_frame then
self.main_frame:Hide()
end
end
function MDT:ToggleDataCollection()
db.newDataCollectionActive = not db.newDataCollectionActive
print(string.format("%sMDT|r: DataCollection %s. Reload Interface!", mythicColor,
db.newDataCollectionActive and "|cFF00FF00Enabled|r" or "|cFFFF0000Disabled|r"))
end
function MDT:CreateMenu()
-- Close button
self.main_frame.closeButton = CreateFrame("Button", "MDTCloseButton", self.main_frame, "UIPanelCloseButton")
self.main_frame.closeButton:ClearAllPoints()
self.main_frame.closeButton:SetPoint("TOPRIGHT", self.main_frame.sidePanel, "TOPRIGHT", -1, -4)
self.main_frame.closeButton:SetScript("OnClick", function() self:HideInterface() end)
self.main_frame.closeButton:SetFrameLevel(4)
--Maximize Button
self.main_frame.maximizeButton = CreateFrame("Button", "MDTMaximizeButton", self.main_frame,
"MaximizeMinimizeButtonFrameTemplate")
self.main_frame.maximizeButton:ClearAllPoints()
---@diagnostic disable-next-line: param-type-mismatch
self.main_frame.maximizeButton:SetPoint("RIGHT", self.main_frame.closeButton, "LEFT", 0, 0)
self.main_frame.maximizeButton:SetFrameLevel(4)
db.maximized = db.maximized or false
if not db.maximized then self.main_frame.maximizeButton:Minimize() end
self.main_frame.maximizeButton:SetOnMaximizedCallback(self.Maximize)
self.main_frame.maximizeButton:SetOnMinimizedCallback(self.Minimize)
--return to live preset
self.main_frame.liveReturnButton = CreateFrame("Button", "MDTLiveReturnButton", self.main_frame, "UIPanelCloseButton")
local liveReturnButton = self.main_frame.liveReturnButton
liveReturnButton:ClearAllPoints()
liveReturnButton:SetPoint("RIGHT", self.main_frame.topPanel, "RIGHT", 0, 0)
liveReturnButton:Hide()
liveReturnButton.Icon = liveReturnButton:CreateTexture(nil, "OVERLAY", nil, 0)
liveReturnButton.Icon:SetTexture("Interface\\Buttons\\UI-RefreshButton")
liveReturnButton.Icon:SetSize(16, 16)
liveReturnButton.Icon:SetTexCoord(1, 0, 0, 1) --flipped image
---@diagnostic disable-next-line: param-type-mismatch
liveReturnButton.Icon:SetPoint("CENTER", liveReturnButton, "CENTER")
liveReturnButton:SetScript("OnClick", function() self:ReturnToLivePreset() end)
liveReturnButton:SetFrameLevel(4)
liveReturnButton.tooltip = L["Return to the live preset"]
--set preset as new live preset
self.main_frame.setLivePresetButton = CreateFrame("Button", "MDTSetLivePresetButton", self.main_frame,
"UIPanelCloseButton")
local setLivePresetButton = self.main_frame.setLivePresetButton
setLivePresetButton:ClearAllPoints()
---@diagnostic disable-next-line: param-type-mismatch
setLivePresetButton:SetPoint("RIGHT", liveReturnButton, "LEFT", 0, 0)
setLivePresetButton:Hide()
setLivePresetButton.Icon = setLivePresetButton:CreateTexture(nil, "OVERLAY", nil, 0)
setLivePresetButton.Icon:SetTexture("Interface\\ChatFrame\\ChatFrameExpandArrow")
setLivePresetButton.Icon:SetSize(16, 16)
---@diagnostic disable-next-line: param-type-mismatch
setLivePresetButton.Icon:SetPoint("CENTER", setLivePresetButton, "CENTER")
setLivePresetButton:SetScript("OnClick", function() self:SetLivePreset() end)
setLivePresetButton:SetFrameLevel(4)
setLivePresetButton.tooltip = L["Make this preset the live preset"]
--Resize Handle
self.main_frame.resizer = CreateFrame("BUTTON", nil, self.main_frame.sidePanel)
local resizer = self.main_frame.resizer
resizer:SetPoint("BOTTOMRIGHT", self.main_frame.sidePanel, "BOTTOMRIGHT", 7, -7)
resizer:SetSize(25, 25)
resizer:EnableMouse()
resizer:SetScript("OnMouseDown", function()
self.main_frame:StartSizing("BOTTOMRIGHT")
self:StartScaling()
self:HideAllPresetObjects()
self:ReleaseHullTextures()
self.main_frame:SetScript("OnSizeChanged", function()
local height = self.main_frame:GetHeight()
self:SetScale(height / sizey)
end)
end)
resizer:SetScript("OnMouseUp", function()
self.main_frame:StopMovingOrSizing()
self:UpdateEnemyInfoFrame()
self:UpdateMap()
self:UpdateBottomText()
self.main_frame:SetScript("OnSizeChanged", function()
end)
end)
local normal = resizer:CreateTexture(nil, "OVERLAY", nil, 0)
normal:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
normal:SetTexCoord(0, 1, 0, 1)
normal:SetPoint("BOTTOMLEFT", resizer, 0, 6)
normal:SetPoint("TOPRIGHT", resizer, -6, 0)
resizer:SetNormalTexture(normal)
local pushed = resizer:CreateTexture(nil, "OVERLAY", nil, 0)
pushed:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
pushed:SetTexCoord(0, 1, 0, 1)
pushed:SetPoint("BOTTOMLEFT", resizer, 0, 6)
pushed:SetPoint("TOPRIGHT", resizer, -6, 0)
resizer:SetPushedTexture(pushed)
local highlight = resizer:CreateTexture(nil, "OVERLAY", nil, 0)
highlight:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
highlight:SetTexCoord(0, 1, 0, 1)
highlight:SetPoint("BOTTOMLEFT", resizer, 0, 6)
highlight:SetPoint("TOPRIGHT", resizer, -6, 0)
resizer:SetHighlightTexture(highlight)
end
---GetDefaultMapPanelSize
function MDT:GetDefaultMapPanelSize()
return sizex, sizey
end
---GetScale
---Returns scale factor stored in db
function MDT:GetScale()
if not db.scale then db.scale = 1 end
return db.scale
end
local oldScrollValues = {}
---StartScaling
---Stores values when we start scaling the frame
function MDT:StartScaling()
local f = self.main_frame
oldScrollValues.oldScrollH = f.scrollFrame:GetHorizontalScroll()
oldScrollValues.oldScrollV = f.scrollFrame:GetVerticalScroll()
oldScrollValues.oldSizeX = f.scrollFrame:GetWidth()
oldScrollValues.oldSizeY = f.scrollFrame:GetHeight()
self:DungeonEnemies_HideAllBlips()
self:POI_HideAllPoints()
self:KillAllAnimatedLines()
end
---SetScale
---Scales the map frame and it's sub frames to a factor and stores the scale in db
function MDT:SetScale(scale)
local f = self.main_frame
local newSizex = sizex * scale
local newSizey = sizey * scale
f:SetSize(newSizex, newSizey)
f.scrollFrame:SetSize(newSizex, newSizey)
f.mapPanelFrame:SetSize(newSizex, newSizey)
for i = 1, 12 do
f["mapPanelTile"..i]:SetSize((newSizex / 4 + 5 * scale), (newSizex / 4 + 5 * scale))
end
for i = 1, 10 do
for j = 1, 15 do
f["largeMapPanelTile"..i..j]:SetSize(newSizex / 15, newSizex / 15)
end
end
f.scrollFrame:SetVerticalScroll(oldScrollValues.oldScrollV * (newSizey / oldScrollValues.oldSizeY))
f.scrollFrame:SetHorizontalScroll(oldScrollValues.oldScrollH * (newSizex / oldScrollValues.oldSizeX))
f.scrollFrame.cursorY = f.scrollFrame.cursorY * (newSizey / oldScrollValues.oldSizeY)
f.scrollFrame.cursorX = f.scrollFrame.cursorX * (newSizex / oldScrollValues.oldSizeX)
self:ZoomMap(0)
db.scale = scale
db.nonFullscreenScale = scale
end
function MDT:GetFullScreenSizes()
local newSizey = GetScreenHeight() - 60 --top and bottom panel 30 each
local newSizex = newSizey * (sizex / sizey)
local isNarrow
if newSizex + 251 > GetScreenWidth() then --251 sidebar
newSizex = GetScreenWidth() - 251
newSizey = newSizex * (sizey / sizex)
isNarrow = true
end
local scale = newSizey / sizey --use this for adjusting NPC / POI positions later
return newSizex, newSizey, scale, isNarrow
end
function MDT:SkinProgressBar(progressBar)
local bar = progressBar and progressBar.Bar
if not bar then return end
bar.Icon:Hide()
bar.IconBG:Hide()
end
function MDT:IsFrameOffScreen()
local topPanel = MDT.main_frame.topPanel
local bottomPanel = MDT.main_frame.bottomPanel
local width = GetScreenWidth()
local height = GetScreenHeight()
local left = topPanel:GetLeft() -->width
local right = topPanel:GetRight() --<0
local bottom = topPanel:GetBottom() --<0
local top = bottomPanel:GetTop() -->height
return left > width or right < 0 or bottom < 0 or top > height
end
local bottomTips = {
[1] = L["Please report any bugs on https://github.com/Nnoggie/MythicDungeonTools/issues"],
[2] = L["Hold CTRL to single-select enemies."],
[3] = L["Hold SHIFT to create a new pull while selecting enemies."],
[4] = L["Hold SHIFT to delete all presets with the delete preset button."],
[5] = L["Right click a pull for more options."],
[6] = L["Right click an enemy to open the enemy info window."],
[7] = L["Drag the bottom right edge to resize MDT."],
[8] = L["Click the fullscreen button for a maximized view of MDT."],
[9] = L["Use /mdt reset to restore the default position and scale of MDT."],
[10] = L["Mouseover the Live button while in a group to learn more about Live mode."],
[11] = L["You are using MDT. You rock!"],
[12] = L["You can choose from different color palettes in the automatic pull coloring settings menu."],
[13] = L["You can cycle through different floors by holding CTRL and using the mousewheel."],
[14] = L["altKeyGroupsTip"],
[15] = L["Mouseover a patrolling enemy with a blue border to view the patrol path."],
[16] = L["Expand the top toolbar to gain access to drawing and note features."],
[17] = L["ConnectedTip"],
[18] = L["EfficiencyScoreTip"],
[19] = L["ctrlKeyCountTip"],
}
function MDT:UpdateBottomText()
local f = self.main_frame.bottomPanelString
if db.scale < 1 then
f:SetText("")
return
end
f:SetText(bottomTips[math.random(#bottomTips)])
end
function MDT:MakeTopBottomTextures(frame)
frame:SetMovable(true)
if frame.topPanel == nil then
frame.topPanel = CreateFrame("Frame", "MDTTopPanel", frame)
frame.topPanelTex = frame.topPanel:CreateTexture(nil, "BACKGROUND", nil, 0)
frame.topPanelTex:SetAllPoints()
frame.topPanelTex:SetDrawLayer(canvasDrawLayer, -5)
frame.topPanelTex:SetColorTexture(unpack(MDT.BackdropColor))
frame.topPanelString = frame.topPanel:CreateFontString("MDT name")
frame.topPanelString:SetFontObject(GameFontNormalMed3)
frame.topPanelString:SetTextColor(1, 1, 1, 1)
frame.topPanelString:SetJustifyH("CENTER")
frame.topPanelString:SetJustifyV("MIDDLE")
--frame.topPanelString:SetWidth(600)
frame.topPanelString:SetHeight(20)
frame.topPanelString:SetText("Mythic Dungeon Tools")
frame.topPanelString:ClearAllPoints()
frame.topPanelString:SetPoint("CENTER", frame.topPanel, "CENTER", 10, 0)
frame.topPanelString:Show()
frame.topPanelString:SetFont(frame.topPanelString:GetFont() or '', 20, '')
frame.topPanelLogo = frame.topPanel:CreateTexture(nil, "ARTWORK", nil, 7)
frame.topPanelLogo:SetTexture("Interface\\AddOns\\"..AddonName.."\\Textures\\MDTFull")
frame.topPanelLogo:SetWidth(30)
frame.topPanelLogo:SetHeight(30)
frame.topPanelLogo:SetPoint("RIGHT", frame.topPanelString, "LEFT", -5, -1)
frame.topPanelLogo:Show()
end
frame.topPanel:ClearAllPoints()
frame.topPanel:SetHeight(30)
frame.topPanel:SetPoint("BOTTOMLEFT", frame, "TOPLEFT")
frame.topPanel:SetPoint("BOTTOMRIGHT", frame, "TOPRIGHT")
frame.topPanel:EnableMouse(true)
frame.topPanel:RegisterForDrag("LeftButton")
frame.topPanel:SetScript("OnDragStart", function(self, button)
frame:SetMovable(true)
frame:StartMoving()
end)
frame.topPanel:SetScript("OnDragStop", function(self, button)
frame:StopMovingOrSizing()
frame:SetMovable(false)
if MDT:IsFrameOffScreen() then
MDT:ResetMainFramePos(true)
else
local from, _, to, x, y = MDT.main_frame:GetPoint(nil)
db.anchorFrom = from
db.anchorTo = to
db.xoffset, db.yoffset = x, y
end
end)
if frame.bottomPanel == nil then
frame.bottomPanel = CreateFrame("Frame", "MDTBottomPanel", frame)
frame.bottomPanelTex = frame.bottomPanel:CreateTexture(nil, "BACKGROUND", nil, 0)
frame.bottomPanelTex:SetAllPoints()
frame.bottomPanelTex:SetDrawLayer(canvasDrawLayer, -5)
frame.bottomPanelTex:SetColorTexture(unpack(MDT.BackdropColor))
end
frame.bottomPanel:ClearAllPoints()
frame.bottomPanel:SetHeight(30)
frame.bottomPanel:SetPoint("TOPLEFT", frame, "BOTTOMLEFT")
frame.bottomPanel:SetPoint("TOPRIGHT", frame, "BOTTOMRIGHT")
frame.bottomPanelString = frame.bottomPanel:CreateFontString("MDTMid")
frame.bottomPanelString:SetFontObject(GameFontNormalSmall)
frame.bottomPanelString:SetJustifyH("CENTER")
frame.bottomPanelString:SetJustifyV("MIDDLE")
frame.bottomPanelString:SetPoint("CENTER", frame.bottomPanel, "CENTER", 0, 0)
frame.bottomPanelString:SetTextColor(1, 1, 1, 1)
frame.bottomPanelString:Show()
frame.bottomLeftPanelString = frame.bottomPanel:CreateFontString("MDTVersion")
frame.bottomLeftPanelString:SetFontObject(GameFontNormalSmall)
frame.bottomLeftPanelString:SetJustifyH("LEFT")
frame.bottomLeftPanelString:SetJustifyV("MIDDLE")
frame.bottomLeftPanelString:SetPoint("LEFT", frame.bottomPanel, "LEFT", 0, 0)
frame.bottomLeftPanelString:SetTextColor(1, 1, 1, 1)
---@diagnostic disable-next-line: redundant-parameter
frame.bottomLeftPanelString:SetText(" v"..C_AddOns.GetAddOnMetadata(AddonName, "Version"))
frame.bottomLeftPanelString:Show()
local externalButtonGroup = AceGUI:Create("SimpleGroup")
MDT:FixAceGUIShowHide(externalButtonGroup, frame)
externalButtonGroup.frame:ClearAllPoints()
externalButtonGroup.frame:SetParent(frame.bottomPanel)
if not externalButtonGroup.frame.SetBackdrop then
Mixin(externalButtonGroup.frame, BackdropTemplateMixin)
end
externalButtonGroup.frame:SetBackdropColor(0, 0, 0, 0)
externalButtonGroup:SetHeight(40)
externalButtonGroup:SetPoint("LEFT", frame.bottomLeftPanelString, "RIGHT", 0, 0)
externalButtonGroup:SetLayout("Flow")
externalButtonGroup.frame:SetFrameStrata("High")
externalButtonGroup.frame:SetFrameLevel(7)
externalButtonGroup.frame:ClearBackdrop()
frame.externalButtonGroup = externalButtonGroup
for _, dest in ipairs(MDT.externalLinks) do
local button = AceGUI:Create("Icon")
button:SetImage(unpack(dest.texture))
button:SetCallback("OnClick", function(widget, callbackName)
MDT:ExportString(dest.url)
end)
button.tooltipText = dest.tooltip
button:SetWidth(24)
button:SetImageSize(20, 20)
button:SetCallback("OnEnter", function(widget, callbackName)
MDT:ToggleToolbarTooltip(true, widget, "ANCHOR_TOPLEFT")
end)
button:SetCallback("OnLeave", function()
MDT:ToggleToolbarTooltip(false)
end)
externalButtonGroup:AddChild(button)
end
frame.statusString = frame.bottomPanel:CreateFontString("MDTStatusLabel")
frame.statusString:SetFontObject(GameFontNormalSmall)
frame.statusString:SetJustifyH("RIGHT")
frame.statusString:SetJustifyV("MIDDLE")
frame.statusString:SetPoint("RIGHT", frame.bottomPanel, "RIGHT", 0, 0)
frame.statusString:SetTextColor(1, 1, 1, 1)
frame.statusString:Hide()
frame.bottomPanel:EnableMouse(true)
frame.bottomPanel:RegisterForDrag("LeftButton")
frame.bottomPanel:SetScript("OnDragStart", function(self, button)
frame:SetMovable(true)
frame:StartMoving()
end)
frame.bottomPanel:SetScript("OnDragStop", function(self, button)
frame:StopMovingOrSizing()
frame:SetMovable(false)
if MDT:IsFrameOffScreen() then
MDT:ResetMainFramePos(true)
else
---@diagnostic disable-next-line: missing-parameter
local from, _, to, x, y = MDT.main_frame:GetPoint()
db.anchorFrom = from
db.anchorTo = to
db.xoffset, db.yoffset = x, y
end
end)
end
function MDT:MakeCopyHelper(frame)
MDT.copyHelper = CreateFrame("Frame", "MDTCopyHelper", frame)
MDT.copyHelper:SetFrameStrata("TOOLTIP")
MDT.copyHelper:SetFrameLevel(200)
MDT.copyHelper:SetHeight(100)
MDT.copyHelper:SetWidth(300)
MDT.copyHelper.tex = MDT.copyHelper:CreateTexture(nil, "BACKGROUND", nil, 0)
MDT.copyHelper.tex:SetAllPoints()
MDT.copyHelper.tex:SetColorTexture(unpack(MDT.BackdropColor))
MDT.copyHelper.text = MDT.copyHelper:CreateFontString("MDT name")
MDT.copyHelper.text:SetFontObject(GameFontNormalMed3)
MDT.copyHelper.text:SetJustifyH("CENTER")
MDT.copyHelper.text:SetJustifyV("MIDDLE")
MDT.copyHelper.text:SetText(L["errorLabel3"])
MDT.copyHelper.text:ClearAllPoints()
MDT.copyHelper.text:SetPoint("CENTER", MDT.copyHelper, "CENTER")
MDT.copyHelper.text:Show()
MDT.copyHelper.text:SetFont(MDT.copyHelper.text:GetFont() or '', 20, '')
MDT.copyHelper.text:SetTextColor(1, 1, 0)
function MDT.copyHelper:SmartFadeOut(seconds)
seconds = seconds or 0.3
MDT.copyHelper.isFading = true
MDT.copyHelper:SetAlpha(1)
MDT.copyHelper:Show()
UIFrameFadeOut(MDT.copyHelper, seconds, 1, 0)
MDT.copyHelper.text:SetText(L["copiedToClipboard"])
MDT.copyHelper.text:SetTextColor(1, 1, 1)
MDT.copyHelper:SetScript("OnUpdate", nil)
C_Timer.After(seconds, function()
MDT.copyHelper.text:SetText(L["errorLabel3"])
MDT.copyHelper.text:SetTextColor(1, 1, 0)
MDT.copyHelper:Hide()
MDT.copyHelper.isFading = false
end)
end
function MDT.copyHelper:SmartShow(anchorFrame, x, y)
MDT.copyHelper:ClearAllPoints()
MDT.copyHelper:SetPoint("CENTER", anchorFrame, "CENTER", x, y)
MDT.copyHelper:SetAlpha(1)
MDT.copyHelper:Show()
MDT.copyHelper:SetScript("OnUpdate", function()
if IsControlKeyDown() then
MDT.lastCtrlDown = GetTime()
end
end)
end
function MDT.copyHelper:SmartHide()
if not MDT.copyHelper.isFading then MDT.copyHelper:Hide() end
end
--ctrl+c works when ctrl was released up to 0.5s before the c key
function MDT.copyHelper:WasControlKeyDown()
if IsControlKeyDown() then return true end
if not MDT.lastCtrlDown then return false end
return (GetTime() - MDT.lastCtrlDown) < 0.5
end
end
function MDT:MakeSidePanel(frame)
if frame.sidePanel == nil then
frame.sidePanel = CreateFrame("Frame", "MDTSidePanel", frame)
frame.sidePanelTex = frame.sidePanel:CreateTexture(nil, "BACKGROUND", nil, 0)
frame.sidePanelTex:SetAllPoints()
frame.sidePanelTex:SetDrawLayer(canvasDrawLayer, -5)
frame.sidePanelTex:SetColorTexture(unpack(MDT.BackdropColor))
frame.sidePanelTex:Show()
end
frame.sidePanel:EnableMouse(true)
frame.sidePanel:ClearAllPoints()
frame.sidePanel:SetWidth(251)
frame.sidePanel:SetPoint("TOPLEFT", frame, "TOPRIGHT", 0, 30)
frame.sidePanel:SetPoint("BOTTOMLEFT", frame, "BOTTOMRIGHT", 0, -30)
frame.sidePanelString = frame.sidePanel:CreateFontString("MDTSidePanelText")
frame.sidePanelString:SetFont("Fonts\\FRIZQT__.TTF", 10, "")
frame.sidePanelString:SetTextColor(1, 1, 1, 1)
frame.sidePanelString:SetJustifyH("LEFT")
frame.sidePanelString:SetJustifyV("TOP")
frame.sidePanelString:SetWidth(200)
frame.sidePanelString:SetHeight(500)
frame.sidePanelString:SetText("")
frame.sidePanelString:ClearAllPoints()
frame.sidePanelString:SetPoint("TOPLEFT", frame.sidePanel, "TOPLEFT", 33, -120 - 30 - 25)
frame.sidePanelString:Hide()
frame.sidePanel.WidgetGroup = AceGUI:Create("SimpleGroup")
frame.sidePanel.WidgetGroup.frame:SetParent(frame.sidePanel)
frame.sidePanel.WidgetGroup:SetWidth(245)
frame.sidePanel.WidgetGroup:SetHeight(frame:GetHeight() + (frame.topPanel:GetHeight() * 2) - 31)
frame.sidePanel.WidgetGroup:SetPoint("TOP", frame.sidePanel, "TOP", 3, 5)
frame.sidePanel.WidgetGroup:SetLayout("Flow")
frame.sidePanel.WidgetGroup.frame:SetFrameStrata(mainFrameStrata)
if not frame.sidePanel.WidgetGroup.frame.SetBackdrop then
Mixin(frame.sidePanel.WidgetGroup.frame, BackdropTemplateMixin)
end
frame.sidePanel.WidgetGroup.frame:SetBackdropColor(1, 1, 1, 0)
frame.sidePanel.WidgetGroup.frame:Hide()
--dirty hook to make widgetgroup show/hide
local originalShow, originalHide = frame.Show, frame.Hide
function frame:Show(...)
frame.sidePanel.WidgetGroup.frame:Show()
return originalShow(self, ...)
end
function frame:Hide(...)
frame.sidePanel.WidgetGroup.frame:Hide()
MDT.pullTooltip:Hide()
return originalHide(self, ...)
end
--preset selection
frame.sidePanel.WidgetGroup.PresetDropDown = AceGUI:Create("Dropdown")
frame.sidePanel.WidgetGroup.PresetDropDown.pullout.frame:SetParent(frame.sidePanel.WidgetGroup.PresetDropDown.frame)
local dropdown = frame.sidePanel.WidgetGroup.PresetDropDown
dropdown.frame:SetWidth(170)
dropdown.text:SetJustifyH("LEFT")
dropdown:SetCallback("OnValueChanged", function(widget, callbackName, key)
if db.presets[db.currentDungeonIdx][key].value == 0 then
MDT:OpenNewPresetDialog()
MDT.main_frame.sidePanelDeleteButton:SetDisabled(true)
MDT.main_frame.sidePanelDeleteButton.text:SetTextColor(0.5, 0.5, 0.5)
else
if key == 1 then
MDT.main_frame.sidePanelDeleteButton:SetDisabled(true)
MDT.main_frame.sidePanelDeleteButton.text:SetTextColor(0.5, 0.5, 0.5)
else
if not MDT.liveSessionActive then
MDT.main_frame.sidePanelDeleteButton:SetDisabled(false)
MDT.main_frame.sidePanelDeleteButton.text:SetTextColor(1, 0.8196, 0)
else
MDT.main_frame.sidePanelDeleteButton:SetDisabled(true)
MDT.main_frame.sidePanelDeleteButton.text:SetTextColor(0.5, 0.5, 0.5)
end
end
db.currentPreset[db.currentDungeonIdx] = key
--Set affix dropdown to preset week
--frame.sidePanel.affixDropdown:SetAffixWeek(MDT:GetCurrentPreset().week or MDT:GetCurrentAffixWeek())
--UpdateMap is called in SetAffixWeek, no need to call twice
-- im not sure why this was left in here, but it was causing the map to update twice when changing presets
-- MDT:UpdateMap()
frame.sidePanel.affixDropdown:SetAffixWeek(MDT:GetCurrentPreset().week or MDT:GetCurrentAffixWeek() or 1)
end
end)
MDT:UpdatePresetDropDown()
frame.sidePanel.WidgetGroup:AddChild(dropdown)
--Settings cogwheel
frame.settingsCogwheel = AceGUI:Create("Icon")
local settinggsCogwheel = frame.settingsCogwheel
settinggsCogwheel:SetImage("Interface\\AddOns\\MythicDungeonTools\\Textures\\helpIconGrey")
settinggsCogwheel:SetImageSize(25, 25)
settinggsCogwheel:SetWidth(30)
settinggsCogwheel:SetCallback("OnClick", function(...)
self:ToggleSettingsDialog()
end)
frame.sidePanel.WidgetGroup:AddChild(frame.settingsCogwheel)
local function anchorTooltip(anchorFrame)
GameTooltip:SetOwner(anchorFrame, "ANCHOR_BOTTOMLEFT", -7, anchorFrame:GetHeight() + 3)
end
---new profile,rename,export,delete
local buttonWidth = 75
frame.sidePanelNewButton = AceGUI:Create("Button")
frame.sidePanelNewButton:SetText(L["New"])
frame.sidePanelNewButton:SetWidth(buttonWidth)
--button fontInstance
local fontInstance = CreateFont("MDTButtonFont")
if not fontInstance then return end
fontInstance:CopyFontObject(frame.sidePanelNewButton.frame:GetNormalFontObject())
local fontName, height = fontInstance:GetFont()
fontInstance:SetFont(fontName, 10, "")
frame.sidePanelNewButton.frame:SetNormalFontObject(fontInstance)
frame.sidePanelNewButton.frame:SetHighlightFontObject(fontInstance)
frame.sidePanelNewButton.frame:SetDisabledFontObject(fontInstance)
frame.sidePanelNewButton:SetCallback("OnClick", function(widget, callbackName, value)
MDT:OpenNewPresetDialog()
end)
frame.sidePanelNewButton.frame:SetScript("OnEnter", function()
anchorTooltip(frame.sidePanelNewButton.frame)
GameTooltip:AddLine(L["Create a new preset"], 1, 1, 1)
GameTooltip:Show()
end)
frame.sidePanelNewButton.frame:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
frame.sidePanelRenameButton = AceGUI:Create("Button")
frame.sidePanelRenameButton:SetWidth(buttonWidth)
frame.sidePanelRenameButton:SetText(L["Rename"])
frame.sidePanelRenameButton.frame:SetNormalFontObject(fontInstance)
frame.sidePanelRenameButton.frame:SetHighlightFontObject(fontInstance)
frame.sidePanelRenameButton.frame:SetDisabledFontObject(fontInstance)
frame.sidePanelRenameButton:SetCallback("OnClick", function(widget, callbackName, value)
MDT:HideAllDialogs()
local currentPresetName = db.presets[db.currentDungeonIdx][db.currentPreset[db.currentDungeonIdx]].text
MDT.main_frame.RenameFrame:Show()
MDT.main_frame.RenameFrame.RenameButton:SetDisabled(true)
MDT.main_frame.RenameFrame.RenameButton.text:SetTextColor(0.5, 0.5, 0.5)
MDT.main_frame.RenameFrame:ClearAllPoints()
MDT.main_frame.RenameFrame:SetPoint("CENTER", MDT.main_frame, "CENTER", 0, 50)
MDT.main_frame.RenameFrame.Editbox:SetText(currentPresetName)
MDT.main_frame.RenameFrame.Editbox:HighlightText(0, string.len(currentPresetName))
MDT.main_frame.RenameFrame.Editbox:SetFocus()
end)
frame.sidePanelRenameButton.frame:SetScript("OnEnter", function()
anchorTooltip(frame.sidePanelNewButton.frame)
GameTooltip:AddLine(L["Rename the preset"], 1, 1, 1)
GameTooltip:Show()
end)
frame.sidePanelRenameButton.frame:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
frame.sidePanelImportButton = AceGUI:Create("Button")
frame.sidePanelImportButton:SetText(L["Import"])
frame.sidePanelImportButton:SetWidth(buttonWidth)
frame.sidePanelImportButton.frame:SetNormalFontObject(fontInstance)
frame.sidePanelImportButton.frame:SetHighlightFontObject(fontInstance)
frame.sidePanelImportButton.frame:SetDisabledFontObject(fontInstance)
frame.sidePanelImportButton:SetCallback("OnClick", function(widget, callbackName, value)
if InCombatLockdown() then
print('MDT: '..L["Cannot import while in combat"])
return
end
MDT:OpenImportPresetDialog()
end)
frame.sidePanelImportButton.frame:SetScript("OnEnter", function()
anchorTooltip(frame.LinkToChatButton.frame)
GameTooltip:AddLine(L["Import a preset from a text string"], 1, 1, 1)
GameTooltip:Show()
end)
frame.sidePanelImportButton.frame:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
frame.sidePanelExportButton = AceGUI:Create("Button")