Skip to content

Commit 879ae99

Browse files
committed
Added some detection and automatic fixing of situations that could stop ESC from opening the menu
1 parent 72f0fea commit 879ae99

File tree

1 file changed

+43
-8
lines changed

1 file changed

+43
-8
lines changed

NoAutoclose.lua

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ local UpdateScaleForFit = UpdateScaleForFit or UIPanelUpdateScaleForFit or Frame
2121
local CHECK_FIT_DEFAULT_EXTRA_WIDTH = 20;
2222
local CHECK_FIT_DEFAULT_EXTRA_HEIGHT = 20;
2323

24+
local FRAME_POSITION_KEYS = {
25+
left = 'left',
26+
center = 'center',
27+
right = 'right',
28+
doublewide = 'doublewide',
29+
fullscreen = 'fullscreen',
30+
};
31+
2432
local function table_invert(t)
2533
local s = {};
2634
for k,v in pairs(t) do
@@ -31,17 +39,18 @@ local function table_invert(t)
3139
end
3240

3341
local function setTrue(table, key)
34-
TextureLoadingGroupMixin.AddTexture({textures = table}, key);
42+
TextureLoadingGroupMixin.AddTexture({ textures = table }, key);
3543
end
3644

3745
local function setNil(table, key)
38-
TextureLoadingGroupMixin.RemoveTexture({textures = table}, key);
46+
TextureLoadingGroupMixin.RemoveTexture({ textures = table }, key);
3947
end
4048

4149
EventUtil.ContinueOnAddOnLoaded(addonName, function()
4250
ns:Init();
4351
end);
4452

53+
ns.lastPrint = 0;
4554
ns.escHandlerMap = {};
4655
ns.handlerFrameIndex = 0;
4756
ns.sharedAttributesFrame = CreateFrame('Frame', nil, nil, 'SecureHandlerBaseTemplate');
@@ -135,6 +144,32 @@ function ns:OnHideUIPanel(frame)
135144
end
136145
end
137146

147+
function ns:DetectStaleUiPanels()
148+
local inCombat = InCombatLockdown();
149+
local shownFrames = {};
150+
for position, _ in pairs(FRAME_POSITION_KEYS) do
151+
-- Blizzard could fix this in 5 minutes, but well...
152+
local frame = GetUIPanel(position);
153+
if frame and not frame:IsShown() then
154+
tinsert(shownFrames, frame);
155+
end
156+
end
157+
if not next(shownFrames) then return; end
158+
159+
if inCombat then
160+
if (GetTime() - self.lastPrint) > 5 then
161+
self.lastPrint = GetTime();
162+
print('NoAutoClose: Detected an issue that can cause ESC to stop working properly. This cannot be fixed while in combat, once you leave combat it should be automatically fixed.');
163+
end
164+
165+
return;
166+
end
167+
for _, frame in pairs(shownFrames) do
168+
frame:Show();
169+
HideUIPanel(frame);
170+
end
171+
end
172+
138173
function ns:ReworkSettingsOpenAndClose()
139174
if not SettingsPanel then return; end
140175

@@ -192,15 +227,12 @@ end
192227
--- @param func function
193228
--- @param ... any # arguments
194229
function ns:AddToCombatLockdownQueue(func, ...)
195-
if #self.combatLockdownQueue == 0 then
196-
self.eventFrame:RegisterEvent('PLAYER_REGEN_ENABLED');
197-
end
198-
199230
tinsert(self.combatLockdownQueue, { func = func, args = { ... } });
200231
end
201232

202233
function ns:PLAYER_REGEN_ENABLED()
203-
self.eventFrame:UnregisterEvent('PLAYER_REGEN_ENABLED');
234+
self:DetectStaleUiPanels();
235+
204236
if #self.combatLockdownQueue == 0 then return; end
205237

206238
for _, item in pairs(self.combatLockdownQueue) do
@@ -210,8 +242,9 @@ function ns:PLAYER_REGEN_ENABLED()
210242
end
211243

212244
function ns:PLAYER_REGEN_DISABLED()
245+
self:DetectStaleUiPanels();
246+
213247
-- if any frame has become protected since it was last shown, we need to configure the secure esc handler
214-
--
215248
for frameName, _ in pairs(self.hookedFrames) do
216249
local frame = _G[frameName];
217250
if frame and frame.IsProtected and frame:IsProtected() then
@@ -331,13 +364,15 @@ function ns:Init()
331364
hooksecurefunc('RegisterUIPanel', function() self:ADDON_LOADED(); end);
332365
hooksecurefunc('DisplayInterfaceActionBlockedMessage', function() self:OnDisplayInterfaceActionBlockedMessage(); end);
333366
hooksecurefunc('RestoreUIPanelArea', function(frame) self:SetDefaultPosition(frame); end);
367+
hooksecurefunc('CloseWindows', function() self:DetectStaleUiPanels(); end);
334368
self:ReworkSettingsOpenAndClose();
335369

336370
self.eventFrame = CreateFrame('Frame');
337371
self.eventFrame:HookScript('OnEvent', function(_, event, ...) self[event](self, event, ...); end);
338372
self.eventFrame:RegisterEvent('ADDON_LOADED');
339373
self.eventFrame:RegisterEvent('PLAYER_INTERACTION_MANAGER_FRAME_SHOW');
340374
self.eventFrame:RegisterEvent('PLAYER_INTERACTION_MANAGER_FRAME_HIDE');
375+
self.eventFrame:RegisterEvent('PLAYER_REGEN_ENABLED');
341376
self.eventFrame:RegisterEvent('PLAYER_REGEN_DISABLED');
342377

343378
self.combatLockdownQueue = {};

0 commit comments

Comments
 (0)