-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathCore.lua
More file actions
2678 lines (2334 loc) · 86.4 KB
/
Core.lua
File metadata and controls
2678 lines (2334 loc) · 86.4 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
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
local addonName, ns = ...
local LibStub = LibStub
local AceAddon = LibStub("AceAddon-3.0")
local AceDB = LibStub("AceDB-3.0")
local L = LibStub("AceLocale-3.0"):GetLocale(addonName)
local MR = AceAddon:NewAddon(addonName, "AceEvent-3.0", "AceBucket-3.0", "AceTimer-3.0")
ns.MR = MR
MR.ns = ns
local MODULES_WITH_OPTIONAL_CURRENCY_COMPLETION = {
currencies = true,
pvp_currencies = true,
}
local DEFAULTS = {
profile = {
locked = false,
scale = 1.0,
minimized = false,
frameAlpha = 1.0,
hideFramesInInstances = false,
rememberManagedWindowsVisibility = false,
managedWindowsBundleHidden = false,
transparentMode = false,
keepIconsVisibleInTextMode = true,
keepHeadersVisibleInTextMode = true,
autoHidePanelHeaders = false,
width = 260,
height = 400,
fontSize = 11,
fontMedia = nil,
fontFlags = "OUTLINE",
backgroundMedia = nil,
minimap = { hide = false },
managedWindowRestoreState = nil,
firstSeen = false,
welcomeSuppressed = false,
position = { point = "CENTER", x = 0, y = 0 },
collapsedPosition = nil,
renownOpen = false,
raresOpen = false,
concentrationTrackerOpen = false,
raresPos = nil,
raresLocked = false,
raresWidth = 300,
raresHeight = 360,
currencyBrowserWidth = 360,
currencyBrowserHeight = 460,
raresFontSize = 9,
raresShimmer = true,
raresHiddenZones = {},
raresCompact = false,
raresMinimized = false,
raresScale = 1.0,
raresAlpha = 1.0,
raresHideKilled = false,
raresShowAllZones = false,
raresColors = {},
renownPos = nil,
renownLocked = false,
renownWidth = 280,
renownBarH = 18,
renownAlpha = 1.0,
renownShowRep = true,
renownShowIcons = true,
renownShimmer = true,
renownHideMaxed = false,
renownHiddenFactions = {},
renownColors = {},
renownOrder = {},
renownCompact = false,
renownMinimized = false,
renownScale = 1.0,
renownShowLevel = true,
renownFontSize = 9,
gatheringLocOpen = false,
gatheringLocPos = nil,
gatheringLocked = false,
gatheringWidth = 350,
gatheringHeight = 450,
gatheringMinimized = false,
gatheringAlpha = 1.0,
gatheringFontSize = 9,
gatheringScale = 1.0,
gatheringProfColors = {},
gatheringCollapsedProfessions = {},
gatheringHideCompleted = false,
headerColors = {},
headerBackgroundColors = {},
rowColors = {},
syncWindowScale = false,
syncWindowFontSize = false,
peekOnHover = false,
animatedMinimize = false,
mainHeaderPosition = "top",
showMainCharacterBar = true,
characterWindowLayout = false,
selectedExpansion = "midnight",
altBoardSelectedExpansion = "midnight",
altBoardHiddenCharacters = {},
altBoardCharacterNotes = {},
altBoardShowHidden = false,
altBoardView = "character",
altBoardCollapsedModules = {},
concentrationTrackerAlpha = 1.0,
concentrationTrackerCompact = false,
concentrationTrackerHiddenCharacters = {},
expansionModuleStates = {},
expansionModuleOrder = {},
},
char = {
progress = {},
professions = {},
professionConcentration = {},
customTasks = {},
customTaskNextId = 1,
customTaskDiffProgress = {},
currencyBrowserHiddenDefaults = {},
currencyBrowserCustom = {},
currencyBrowserCustomOrder = {},
currencyBrowserCollapsedHeaders = {},
lastWeek = 0,
lastSyncAt = 0,
manualOverrides = {},
welcomeSeen = false,
raresKills = {},
lastDailyAt = 0,
hideComplete = true,
panelOpen = true,
modules = {},
moduleOrder = {},
settingsMigrated = false,
windowLayout = {},
mediaSettings = {},
expansionModuleStates = {},
expansionModuleOrder = {},
},
global = {
customTasks = {},
customTaskNextId = 1,
customTaskProgress = {},
customTaskManualOverrides = {},
customTaskDiffProgress = {},
},
}
MR.modules = {}
MR.moduleByKey = {}
MR.expansions = {
midnight = {
key = "midnight",
label = L["Expansion_Midnight"] or "Midnight",
shortLabel = L["Expansion_Midnight"] or "Midnight",
},
}
local function DeepCopy(value)
if type(value) ~= "table" then
return value
end
local copy = {}
for k, v in pairs(value) do
copy[k] = DeepCopy(v)
end
return copy
end
local function MergeMissing(dst, src)
if type(dst) ~= "table" or type(src) ~= "table" then
return dst
end
for k, v in pairs(src) do
if dst[k] == nil then
dst[k] = DeepCopy(v)
elseif type(dst[k]) == "table" and type(v) == "table" then
MergeMissing(dst[k], v)
end
end
return dst
end
local function RestoreDefaults(dst, src)
if type(dst) ~= "table" or type(src) ~= "table" then
return dst
end
wipe(dst)
for k, v in pairs(src) do
dst[k] = DeepCopy(v)
end
return dst
end
local function IsTableEmpty(t)
return type(t) ~= "table" or next(t) == nil
end
local function IsInRestrictedCombat()
return InCombatLockdown and InCombatLockdown()
end
function MR:RegisterExpansion(def)
assert(type(def) == "table", "MR expansion registration requires a table")
assert(def.key, "MR expansion missing .key")
local existing = self.expansions[def.key] or {}
self.expansions[def.key] = {
key = def.key,
label = def.label or existing.label or def.key,
shortLabel = def.shortLabel or existing.shortLabel or def.label or def.key,
order = def.order or existing.order or 100,
}
end
function MR:QueueCombatDeferredUpdate(flag)
if not flag then
return
end
self._combatDeferred = self._combatDeferred or {}
self._combatDeferred[flag] = true
if self.RegisterEvent then
self:RegisterEvent("PLAYER_REGEN_ENABLED", "OnCombatEnded")
end
end
function MR:ShouldDeferForCombat(flag)
if not IsInRestrictedCombat() then
return false
end
self:QueueCombatDeferredUpdate(flag)
return true
end
function MR:QueueDeferredProgressUpdate(moduleKey, rowKey, value, maxVal)
self._combatDeferredProgress = self._combatDeferredProgress or {}
self._combatDeferredProgress[#self._combatDeferredProgress + 1] = {
moduleKey = moduleKey,
rowKey = rowKey,
value = value,
maxVal = maxVal,
}
self:QueueCombatDeferredUpdate("refreshUI")
end
function MR:FlushCombatDeferredUpdates()
if IsInRestrictedCombat() then
return
end
local pending = self._combatDeferred
local deferredProgress = self._combatDeferredProgress
self._combatDeferred = nil
self._combatDeferredProgress = nil
if pending and pending.weeklyReset and self.DoWeeklyReset then
self:DoWeeklyReset()
pending.weeklyReset = nil
end
if pending and pending.dailyReset and self.DoDailyReset then
self:DoDailyReset()
pending.dailyReset = nil
end
if pending and pending.instanceVisibility and self.UpdateInstanceFrameVisibility then
self:UpdateInstanceFrameVisibility()
pending.instanceVisibility = nil
end
if pending and pending.playerProfessions and self.RefreshPlayerProfessions then
self:RefreshPlayerProfessions()
pending.playerProfessions = nil
end
if pending and pending.professionConcentration and self.RefreshProfessionConcentration then
self:RefreshProfessionConcentration()
pending.professionConcentration = nil
end
if deferredProgress then
for _, entry in ipairs(deferredProgress) do
local progressBucket = self.GetProgressBucket and self:GetProgressBucket(entry.moduleKey, entry.rowKey) or self.db.char.progress
if not progressBucket[entry.moduleKey] then
progressBucket[entry.moduleKey] = {}
end
progressBucket[entry.moduleKey][entry.rowKey] = math.max(0, math.min(entry.value, entry.maxVal))
end
end
if pending and pending.scan and self.Scan then
self:Scan()
pending.scan = nil
end
if pending and pending.refreshUI and self.RefreshUI then
self:RefreshUI()
end
if pending and pending.gatheringFrame and self.RefreshGatheringLocationsFrame then
self:RefreshGatheringLocationsFrame()
end
if pending and pending.rares and self.RefreshRares then
self:RefreshRares()
end
if pending and pending.renown and self.RefreshRenown then
self:RefreshRenown()
end
end
function MR:OnCombatEnded()
if self.UnregisterEvent then
self:UnregisterEvent("PLAYER_REGEN_ENABLED")
end
self:FlushCombatDeferredUpdates()
end
function MR:GetModuleExpansionKey(modOrKey)
local mod = modOrKey
if type(modOrKey) == "string" then
mod = self.moduleByKey[modOrKey]
end
return (mod and mod.expansionKey) or "midnight"
end
function MR:GetExpansionInfo(key)
key = key or "midnight"
return self.expansions[key] or {
key = key,
label = key,
shortLabel = key,
order = 999,
}
end
local _questNameCache = {}
local _questNamePending = {}
function MR:GetQuestName(questId, fallback)
if not questId then
return fallback
end
if _questNameCache[questId] then
return _questNameCache[questId]
end
if C_QuestLog and C_QuestLog.GetTitleForQuestID then
local title = C_QuestLog.GetTitleForQuestID(questId)
if title and title ~= "" then
_questNameCache[questId] = title
_questNamePending[questId] = nil
return title
end
end
if not _questNamePending[questId] then
if C_QuestLog and C_QuestLog.RequestLoadQuestByID then
C_QuestLog.RequestLoadQuestByID(questId)
end
_questNamePending[questId] = true
end
return fallback
end
function MR:GetAvailableExpansions()
local seen = {}
local result = {}
for key, info in pairs(self.expansions or {}) do
seen[key] = true
result[#result + 1] = self:GetExpansionInfo(key)
end
for _, mod in ipairs(self.modules) do
local key = self:GetModuleExpansionKey(mod)
if not seen[key] then
seen[key] = true
result[#result + 1] = self:GetExpansionInfo(key)
end
end
table.sort(result, function(a, b)
local ao = a.order or 999
local bo = b.order or 999
if ao ~= bo then
return ao < bo
end
return (a.label or a.key) < (b.label or b.key)
end)
return result
end
function MR:GetSelectableExpansions()
local counts = {}
for _, mod in ipairs(self.modules) do
local key = self:GetModuleExpansionKey(mod)
counts[key] = (counts[key] or 0) + 1
end
local result = {}
for key, count in pairs(counts) do
if count > 0 then
result[#result + 1] = self:GetExpansionInfo(key)
end
end
table.sort(result, function(a, b)
local ao = a.order or 999
local bo = b.order or 999
if ao ~= bo then
return ao < bo
end
return (a.label or a.key) < (b.label or b.key)
end)
return result
end
function MR:GetSelectedExpansionKey(forAltBoard)
if not (self and self.db and self.db.profile) then
return "midnight"
end
local key = forAltBoard and self.db.profile.altBoardSelectedExpansion or self.db.profile.selectedExpansion
if key and self.expansions[key] then
return key
end
return "midnight"
end
function MR:SetSelectedExpansionKey(key, forAltBoard)
key = key or "midnight"
if not self.expansions[key] then
key = "midnight"
end
if forAltBoard then
self.db.profile.altBoardSelectedExpansion = key
if self.altBoardFrame and self.altBoardFrame:IsShown() then
if self.RequestWarbandBoardRefresh then
self:RequestWarbandBoardRefresh(true)
elseif self.RefreshWarbandBoard then
self:RefreshWarbandBoard()
end
end
return
end
self.db.profile.selectedExpansion = key
self._orderedModulesCache = nil
if self.RefreshUI then
self:RefreshUI()
end
end
function MR:GetVisibleExpansionModules(expansionKey)
expansionKey = expansionKey or self:GetSelectedExpansionKey()
local result = {}
for _, mod in ipairs(self.modules) do
if self:GetModuleExpansionKey(mod) == expansionKey then
result[#result + 1] = mod
end
end
return result
end
function MR:RegisterModule(def)
assert(def.key, "MR module missing .key")
assert(def.label, "MR module missing .label")
assert(def.rows, "MR module missing .rows")
def.expansionKey = def.expansionKey or "midnight"
if self.moduleByKey[def.key] then
error(("MR duplicate module key: %s"):format(tostring(def.key)))
end
table.insert(self.modules, def)
self.moduleByKey[def.key] = def
self._orderedModulesCache = nil
if self.RebuildTurnInCompletions then
self:RebuildTurnInCompletions()
end
if self.BuildSpellIndex then
self:BuildSpellIndex()
end
if self.db then
if self.Scan then
self:Scan()
elseif self.RefreshUI then
self:RefreshUI()
end
end
end
function MR:GetWeeklyRewardActivityBuckets()
local buckets = {
dungeon = {},
raid = {},
world = {},
}
if not (C_WeeklyRewards and C_WeeklyRewards.GetActivities) then
return buckets
end
local activities = C_WeeklyRewards.GetActivities()
if not activities then
return buckets
end
for _, activity in ipairs(activities) do
if activity.type == 1 then
table.insert(buckets.dungeon, activity)
elseif activity.type == 3 then
table.insert(buckets.raid, activity)
elseif activity.type == 6 then
table.insert(buckets.world, activity)
elseif activity.type == 4 and #buckets.world == 0 then
table.insert(buckets.world, activity)
end
end
return buckets
end
function MR:GetProgress(moduleKey, rowKey)
if moduleKey == "custom_tasks" and self.IsCustomTaskAccountWideCompletion and self:IsCustomTaskAccountWideCompletion(rowKey) then
local progress = self.db and self.db.global and self.db.global.customTaskProgress
local m = progress and progress[moduleKey]
return m and m[rowKey] or 0
end
local source = self.GetMainFrameProgressSource and self:GetMainFrameProgressSource() or self.db.char
local progress = source and source.progress or self.db.char.progress
local m = progress and progress[moduleKey]
return m and m[rowKey] or 0
end
function MR:GetProgressBucket(moduleKey, rowKey)
if moduleKey == "custom_tasks" and self.IsCustomTaskAccountWideCompletion and self:IsCustomTaskAccountWideCompletion(rowKey) then
self.db.global = self.db.global or {}
self.db.global.customTaskProgress = self.db.global.customTaskProgress or {}
return self.db.global.customTaskProgress
end
return self.db.char.progress
end
function MR:GetManualOverrideBucket(moduleKey, rowKey)
if moduleKey == "custom_tasks" and self.IsCustomTaskAccountWideCompletion and self:IsCustomTaskAccountWideCompletion(rowKey) then
self.db.global = self.db.global or {}
self.db.global.customTaskManualOverrides = self.db.global.customTaskManualOverrides or {}
return self.db.global.customTaskManualOverrides
end
return self.db.char.manualOverrides
end
function MR:SetProgress(moduleKey, rowKey, value, maxVal, bypassInstanceSuspend)
local progressBucket = self.GetProgressBucket and self:GetProgressBucket(moduleKey, rowKey) or self.db.char.progress
if self.ShouldSuspendBackgroundWorkInCurrentInstance and self:ShouldSuspendBackgroundWorkInCurrentInstance() and not bypassInstanceSuspend then
if not progressBucket[moduleKey] then
progressBucket[moduleKey] = {}
end
progressBucket[moduleKey][rowKey] = math.max(0, math.min(value, maxVal))
return
end
if self:ShouldDeferForCombat("refreshUI") then
self:QueueDeferredProgressUpdate(moduleKey, rowKey, value, maxVal)
return
end
if not progressBucket[moduleKey] then
progressBucket[moduleKey] = {}
end
progressBucket[moduleKey][rowKey] = math.max(0, math.min(value, maxVal))
self:RefreshUI()
end
function MR:ApplyScaleToAll(v)
self.db.profile.scale = v
self.db.profile.raresScale = v
self.db.profile.renownScale = v
self.db.profile.gatheringScale = v
if self.frame then self.frame:SetScale(v) end
local rf = self.raresFrame
if rf and rf:IsShown() then rf:SetScale(v) end
local rnf = self.renownFrame
if rnf and rnf:IsShown() then rnf:SetScale(v) end
local gf = self.gatheringLocationsFrame
if gf and gf:IsShown() then gf:SetScale(v) end
if self.detachedFrames then
for _, frame in pairs(self.detachedFrames) do
frame:SetScale(v)
end
end
if self.RepopulateRaresConfig then self:RepopulateRaresConfig() end
if self.RepopulateGatheringConfig then self:RepopulateGatheringConfig() end
if self.RepopulateRenownConfig then self:RepopulateRenownConfig() end
if self.RepopulateConfigFrame then self:RepopulateConfigFrame() end
end
function MR:ApplyFontSizeToAll(v)
self.db.profile.fontSize = v
self.db.profile.raresFontSize = v
self.db.profile.gatheringFontSize = v
self.db.profile.renownFontSize = v
if self.ApplyFontSize then self.ApplyFontSize(v) end
if self.RebuildRaresFrame then self:RebuildRaresFrame() end
if self.RebuildGatheringLocationsFrame then self:RebuildGatheringLocationsFrame() end
if self.RebuildRenownFrame then self:RebuildRenownFrame() end
if self.RepopulateRaresConfig then self:RepopulateRaresConfig() end
if self.RepopulateGatheringConfig then self:RepopulateGatheringConfig() end
if self.RepopulateRenownConfig then self:RepopulateRenownConfig() end
if self.RepopulateConfigFrame then self:RepopulateConfigFrame() end
end
function MR:BumpProgress(moduleKey, rowKey, delta, maxVal, bypassInstanceSuspend)
local current = self:GetProgress(moduleKey, rowKey)
self:SetProgress(moduleKey, rowKey, current + delta, maxVal, bypassInstanceSuspend)
end
local function CleanDisplayLabel(text)
if type(text) ~= "string" then
return tostring(text or "")
end
return text:gsub("|c%x%x%x%x%x%x%x%x(.-)%|r", "%1"):gsub("|[cCrR]%x*", "")
end
function MR:SetWaypoint(target)
local mapID = target and target.zone
local x = target and target.x and (target.x / 100)
local y = target and target.y and (target.y / 100)
local tomTom = _G and rawget(_G, "TomTom")
if not mapID or not x or not y then
return false, "Invalid coordinates"
end
local title = target.waypointTitle or CleanDisplayLabel(target.label)
if tomTom and tomTom.AddWaypoint then
local ok = pcall(function()
tomTom:AddWaypoint(mapID, x, y, {
title = title,
persistent = false,
minimap = true,
world = true,
})
end)
if ok then return true, "TomTom" end
end
if UiMapPoint and UiMapPoint.CreateFromCoordinates and C_Map and C_Map.SetUserWaypoint then
local point = UiMapPoint.CreateFromCoordinates(mapID, x, y)
if point then
C_Map.SetUserWaypoint(point)
if C_SuperTrack and C_SuperTrack.SetSuperTrackedUserWaypoint then
C_SuperTrack.SetSuperTrackedUserWaypoint(true)
end
return true, "Blizzard" end
end
return false, "No waypoint API available"
end
function MR:GetManualOverride(modKey, rowKey)
if modKey == "custom_tasks" and self.IsCustomTaskAccountWideCompletion and self:IsCustomTaskAccountWideCompletion(rowKey) then
local m = self.db and self.db.global and self.db.global.customTaskManualOverrides
return (m and m[modKey] and m[modKey][rowKey]) or 0
end
local source = self.GetMainFrameProgressSource and self:GetMainFrameProgressSource() or self.db.char
local m = source and source.manualOverrides or self.db.char.manualOverrides
return (m and m[modKey] and m[modKey][rowKey]) or 0
end
function MR:SetManualOverride(modKey, rowKey, val, maxVal)
local overrides = self.GetManualOverrideBucket and self:GetManualOverrideBucket(modKey, rowKey) or self.db.char.manualOverrides
if not overrides then return end
if not overrides[modKey] then overrides[modKey] = {} end
if val <= 0 then
overrides[modKey][rowKey] = nil
self:SetProgress(modKey, rowKey, 0, maxVal or 1)
self:Scan()
else
overrides[modKey][rowKey] = maxVal and math.min(val, maxVal) or val
self:SetProgress(modKey, rowKey, overrides[modKey][rowKey], maxVal)
end
end
function MR:GetOrderedModules(expansionKey)
expansionKey = expansionKey or self:GetSelectedExpansionKey()
if expansionKey == self:GetSelectedExpansionKey() and self._orderedModulesCache then
return self._orderedModulesCache
end
local modules = self:GetVisibleExpansionModules(expansionKey)
local saved = self:GetActiveModuleOrderStorage(expansionKey)
if not saved or #saved == 0 then
if expansionKey == self:GetSelectedExpansionKey() then
self._orderedModulesCache = modules
end
return modules
end
local result, seen = {}, {}
for _, mod in ipairs(modules) do seen[mod.key] = mod end
for _, key in ipairs(saved) do
if seen[key] then table.insert(result, seen[key]); seen[key] = nil end
end
for _, mod in ipairs(modules) do
if seen[mod.key] then table.insert(result, mod) end
end
if expansionKey == self:GetSelectedExpansionKey() then
self._orderedModulesCache = result
end
return result
end
function MR:GetActiveModuleStorage(expansionKey)
if not (self and self.db) then
return nil
end
expansionKey = expansionKey or self:GetSelectedExpansionKey()
if self:IsCharacterWindowLayoutEnabled() then
self.db.char.expansionModuleStates = self.db.char.expansionModuleStates or {}
if expansionKey == "midnight" then
self.db.char.modules = self.db.char.modules or {}
self.db.char.expansionModuleStates[expansionKey] = self.db.char.modules
else
self.db.char.expansionModuleStates[expansionKey] = self.db.char.expansionModuleStates[expansionKey] or {}
end
return self.db.char.expansionModuleStates[expansionKey]
end
self.db.profile.expansionModuleStates = self.db.profile.expansionModuleStates or {}
if expansionKey == "midnight" then
self.db.profile.modules = self.db.profile.modules or {}
self.db.profile.expansionModuleStates[expansionKey] = self.db.profile.modules
else
self.db.profile.expansionModuleStates[expansionKey] = self.db.profile.expansionModuleStates[expansionKey] or {}
end
return self.db.profile.expansionModuleStates[expansionKey]
end
function MR:GetActiveModuleOrderStorage(expansionKey)
if not (self and self.db) then
return nil
end
expansionKey = expansionKey or self:GetSelectedExpansionKey()
if self:IsCharacterWindowLayoutEnabled() then
self.db.char.expansionModuleOrder = self.db.char.expansionModuleOrder or {}
if expansionKey == "midnight" then
self.db.char.moduleOrder = self.db.char.moduleOrder or {}
self.db.char.expansionModuleOrder[expansionKey] = self.db.char.moduleOrder
else
self.db.char.expansionModuleOrder[expansionKey] = self.db.char.expansionModuleOrder[expansionKey] or {}
end
return self.db.char.expansionModuleOrder[expansionKey]
end
self.db.profile.expansionModuleOrder = self.db.profile.expansionModuleOrder or {}
if expansionKey == "midnight" then
self.db.profile.moduleOrder = self.db.profile.moduleOrder or {}
self.db.profile.expansionModuleOrder[expansionKey] = self.db.profile.moduleOrder
else
self.db.profile.expansionModuleOrder[expansionKey] = self.db.profile.expansionModuleOrder[expansionKey] or {}
end
return self.db.profile.expansionModuleOrder[expansionKey]
end
function MR:SetModuleOrder(orderedKeys)
if self:IsCharacterWindowLayoutEnabled() then
local expansionKey = self:GetSelectedExpansionKey()
self.db.char.expansionModuleOrder = self.db.char.expansionModuleOrder or {}
self.db.char.expansionModuleOrder[expansionKey] = orderedKeys
if expansionKey == "midnight" then
self.db.char.moduleOrder = orderedKeys
end
else
local expansionKey = self:GetSelectedExpansionKey()
self.db.profile.expansionModuleOrder = self.db.profile.expansionModuleOrder or {}
self.db.profile.expansionModuleOrder[expansionKey] = orderedKeys
if expansionKey == "midnight" then
self.db.profile.moduleOrder = orderedKeys
end
end
self._orderedModulesCache = nil
end
function MR:IsModuleEnabled(key)
local mod = self.moduleByKey[key]
if mod and mod.profSkillLine and not self.playerProfessions[mod.profSkillLine] then
return false
end
local storage = self:GetActiveModuleStorage()
local s = storage and storage[key]
return not (s and s.enabled == false)
end
function MR:IsModuleOpen(key)
local storage = self:GetActiveModuleStorage()
local s = storage and storage[key]
if s == nil then
local mod = self.moduleByKey[key]
return not mod or mod.defaultOpen ~= false
end
return s.open ~= false
end
function MR:IsModuleDetached(key)
local storage = self:GetActiveModuleStorage()
local s = storage and storage[key]
return s and s.detached == true or false
end
function MR:SetModuleOpen(key, open)
local storage = self:GetActiveModuleStorage()
if not storage[key] then storage[key] = {} end
storage[key].open = open
end
function MR:SetModuleDetached(key, detached)
local storage = self:GetActiveModuleStorage()
if not storage[key] then storage[key] = {} end
storage[key].detached = detached and true or false
end
function MR:GetDetachedModulePosition(key)
local storage = self:GetActiveModuleStorage()
local s = storage and storage[key]
return s and s.detachedPos or nil
end
function MR:SetDetachedModulePosition(key, point, relPoint, x, y)
local storage = self:GetActiveModuleStorage()
if not storage[key] then storage[key] = {} end
storage[key].detachedPos = {
point = point,
relPoint = relPoint,
x = x,
y = y,
}
end
function MR:GetDetachedModuleSize(key)
local storage = self:GetActiveModuleStorage()
local s = storage and storage[key]
return s and s.detachedSize or nil
end
function MR:SetDetachedModuleSize(key, width, height)
local storage = self:GetActiveModuleStorage()
if not storage[key] then storage[key] = {} end
storage[key].detachedSize = {
width = width,
height = height,
}
end
function MR:SetModuleEnabled(key, enabled, skipRefresh)
local storage = self:GetActiveModuleStorage()
if not storage[key] then storage[key] = {} end
storage[key].enabled = enabled
if not skipRefresh then
self:RefreshUI()
end
end
function MR:RequestUIRefresh(delay)
if not self.ScheduleTimer then
self:RefreshUI()
return
end
delay = tonumber(delay) or 0.05
self._refreshRequestPending = true
if self._refreshRequestTimer and self.CancelTimer then
self:CancelTimer(self._refreshRequestTimer)
self._refreshRequestTimer = nil
end
self._refreshRequestTimer = self:ScheduleTimer(function()
self._refreshRequestTimer = nil
if self._refreshRequestPending then
self._refreshRequestPending = nil
self:RefreshUI()
end
end, delay)
end
function MR:RequestConfigRefresh()
self:RequestUIRefresh(0.04)
end
function MR:IsModuleHideComplete(modKey)
local storage = self:GetActiveModuleStorage()
local s = storage and storage[modKey]
if s and s.hideComplete ~= nil then return s.hideComplete end
if MODULES_WITH_OPTIONAL_CURRENCY_COMPLETION[modKey] then
return false
end
return self.db.char.hideComplete
end
function MR:SetModuleHideComplete(modKey, value, skipRefresh)
local storage = self:GetActiveModuleStorage()
if not storage[modKey] then storage[modKey] = {} end
if storage[modKey].hideComplete == value then
return
end
storage[modKey].hideComplete = value
if not skipRefresh then
self:RefreshUI()
end
end
function MR:IsRowEnabled(modKey, rowKey)
local storage = self:GetActiveModuleStorage()
local s = storage and storage[modKey]
if not s or not s.hiddenRows then return true end
return s.hiddenRows[rowKey] ~= false
end
function MR:SetRowEnabled(modKey, rowKey, enabled, skipRefresh)
local storage = self:GetActiveModuleStorage()
if not storage[modKey] then storage[modKey] = {} end
if not storage[modKey].hiddenRows then
storage[modKey].hiddenRows = {}
end
storage[modKey].hiddenRows[rowKey] = enabled and true or false
if not skipRefresh then
self:RefreshUI()
end
end
function MR:IsCharacterWindowLayoutEnabled()
return self.db and self.db.profile and self.db.profile.characterWindowLayout == true
end
function MR:GetWindowLayoutValue(key)
if not (self and self.db and key) then return nil end
if self:IsCharacterWindowLayoutEnabled() then
local charLayout = self.db.char and self.db.char.windowLayout
if charLayout and charLayout[key] ~= nil then
return charLayout[key]
end
end
return self.db.profile[key]
end
function MR:SetWindowLayoutValue(key, value)
if not (self and self.db and key) then return end
if self:IsCharacterWindowLayoutEnabled() then
if not self.db.char.windowLayout then
self.db.char.windowLayout = {}
end
self.db.char.windowLayout[key] = value
else
self.db.profile[key] = value
end
end
function MR:GetManagedWindowOpen(key)
if not key then
return false
end
return self:GetWindowLayoutValue(key) == true
end
function MR:SetManagedWindowOpen(key, value)
if not key then