Skip to content

Commit 388e985

Browse files
committed
Rewrite the config UI into blizzard's new style
1 parent a6cae11 commit 388e985

23 files changed

+1378
-779
lines changed

MythicPlusTweaks.toc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ SharedUtil.lua
2727
KeystoneUtil.lua
2828
core.lua
2929

30+
settingsTemplates.xml
31+
config.lua
32+
3033
modules\dungeonTeleports.lua
3134
modules\dungeonIconTooltip.lua
3235
modules\dungeonIconText.lua

SharedUtil.lua

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ local Data = MPT.Data;
77

88
-- whether to support affix-specific scores
99
Util.AFFIX_SPECIFIC_SCORES = false;
10+
local challengesAddonName = 'Blizzard_ChallengesUI';
1011

1112
local scoreRarityColors = {
1213
colors = { ITEM_STANDARD_COLOR, ITEM_GOOD_COLOR, ITEM_SUPERIOR_COLOR, ITEM_EPIC_COLOR, ITEM_LEGENDARY_COLOR },
@@ -16,6 +17,72 @@ local scoreRarityColors = {
1617
dungeonOverallScore = { 0, 125, 188, 225, 275 },
1718
};
1819

20+
Util.addonLoadedRegistry = {};
21+
22+
function Util:Init()
23+
self:ResetRegistry();
24+
25+
local eventFrame = CreateFrame('FRAME');
26+
eventFrame:RegisterEvent('ADDON_LOADED');
27+
eventFrame:SetScript('OnEvent', function(_, _, addonName)
28+
if addonName == challengesAddonName and self.challengesUILoadCallbacks.registered then
29+
self:RunOnLoadCallbacks();
30+
end
31+
if self.addonLoadedRegistry[addonName] then
32+
for _, callback in ipairs(self.addonLoadedRegistry[addonName]) do
33+
securecallfunction(callback);
34+
end
35+
self.addonLoadedRegistry[addonName] = nil;
36+
end
37+
end);
38+
end
39+
40+
function Util:ContinueOnAddonLoaded(addonName, callback)
41+
if C_AddOns.IsAddOnLoaded(addonName) then
42+
callback();
43+
return;
44+
end
45+
46+
self.addonLoadedRegistry[addonName] = self.addonLoadedRegistry[addonName] or {};
47+
table.insert(self.addonLoadedRegistry[addonName], callback);
48+
end
49+
50+
function Util:ResetRegistry()
51+
self.challengesUILoadCallbacks = {
52+
minPriority = 1,
53+
maxPriority = 1,
54+
registered = false,
55+
};
56+
end
57+
58+
function Util:RunOnLoadCallbacks()
59+
local registry = self.challengesUILoadCallbacks;
60+
for priority = registry.minPriority, registry.maxPriority do
61+
if registry[priority] then
62+
for _, callback in ipairs(registry[priority]) do
63+
securecallfunction(callback);
64+
end
65+
end
66+
end
67+
self:ResetRegistry();
68+
end
69+
70+
--- @param callback function
71+
--- @param priority ?number - lower numbers are called first
72+
function Util:OnChallengesUILoad(callback, priority)
73+
local actualPriority = priority or 10;
74+
local registry = self.challengesUILoadCallbacks;
75+
registry[actualPriority] = registry[actualPriority] or {};
76+
table.insert(registry[actualPriority], callback);
77+
registry.minPriority = math.min(registry.minPriority, actualPriority);
78+
registry.maxPriority = math.max(registry.maxPriority, actualPriority);
79+
registry.registered = true;
80+
81+
if C_AddOns.IsAddOnLoaded(challengesAddonName) then
82+
self:RunOnLoadCallbacks();
83+
end
84+
end
85+
1986
function Util:ToggleMythicPlusFrame()
2087
local shouldShow = not (ChallengesFrame and ChallengesFrame:IsVisible());
2188
PVEFrame_ToggleFrame('ChallengesFrame');

0 commit comments

Comments
 (0)