Skip to content

Commit 0c27ec9

Browse files
committed
the keybind properly clicks the top popup frame (that isn't blacklisted), fixing a bug that sometimes causes a different popup to be clicked instead if there were multiple open at the same time
1 parent 9dea8a1 commit 0c27ec9

File tree

1 file changed

+74
-65
lines changed

1 file changed

+74
-65
lines changed

main.lua

Lines changed: 74 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -213,77 +213,27 @@ function DialogKey:OnGossipFrameUpdate(GossipFrame)
213213
end
214214
end
215215

216-
--- @return StaticPopupTemplate|nil
217-
function DialogKey:GetFirstVisiblePopup()
216+
--- @return Button[]|nil
217+
function DialogKey:GetValidPopupButtons()
218+
local buttons = {}
219+
local popupFrames = {}
218220
for i = 1, 4 do
219221
local popup = _G["StaticPopup"..i]
220222
if popup and popup:IsVisible() then
221223
table.insert(popupFrames, popup)
222224
end
223225
end
224-
end
225-
226-
--- @param frame Button
227-
function DialogKey:GuardDisabled(frame)
228-
if not self.db.ignoreDisabledButtons then return true; end
229-
230-
return frame:IsEnabled() and frame:IsMouseClickEnabled();
231-
end
232-
233-
--- @return Button|nil
234-
function DialogKey:GetFirstVisibleCustomFrame()
235-
for _, frameName in ipairs(ns.orderedCustomFrames) do
236-
local frame = self:GetFrameByName(frameName)
237-
if frame and frame:IsVisible() and frame:IsObjectType('Button') and self:GuardDisabled(frame) then
238-
return frame ---@diagnostic disable-line: return-type-mismatch
226+
table.sort(popupFrames, function(a, b) return a:GetTop() > b:GetTop() end)
227+
for _, popupFrame in ipairs(popupFrames) do
228+
local button = self:GetPopupButton(popupFrame)
229+
if button then
230+
table.insert(buttons, button)
239231
end
240232
end
241-
end
242233

243-
--- @return Button|nil
244-
function DialogKey:GetFirstVisibleCraftingOrderFrame()
245-
if not self.db.handleCraftingOrders then return; end
246-
local frames = {
247-
"ProfessionsFrame.OrdersPage.OrderView.OrderInfo.StartOrderButton",
248-
"ProfessionsFrame.OrdersPage.OrderView.CreateButton",
249-
"ProfessionsFrame.OrdersPage.OrderView.CompleteOrderButton",
250-
};
251-
for _, frameName in ipairs(frames) do
252-
--- @type Button?
253-
local frame = self:GetFrameByName(frameName) ---@diagnostic disable-line: assign-type-mismatch
254-
if frame and frame:IsVisible() and self:GuardDisabled(frame) then
255-
return frame
256-
end
257-
end
258-
end
259-
260-
function DialogKey:ShouldIgnoreInput()
261-
if InCombatLockdown() then return true end
262-
263-
if self.db.ignoreWithModifier and (IsShiftKeyDown() or IsControlKeyDown() or IsAltKeyDown()) then return true end
264-
-- Ignore input while typing, unless at the Send Mail confirmation while typing into it!
265-
local focus = GetCurrentKeyBoardFocus()
266-
if focus and not (self:GetFirstVisiblePopup() and (focus:GetName() == "SendMailNameEditBox" or focus:GetName() == "SendMailSubjectEditBox")) then return true end
267-
268-
if
269-
-- Ignore input if there's nothing for DialogKey to click
270-
not GossipFrame:IsVisible() and not QuestFrame:IsVisible() and not self:GetFirstVisiblePopup()
271-
-- Ignore input if the Auction House sell frame is not open
272-
and (not AuctionHouseFrame or not AuctionHouseFrame:IsVisible())
273-
and not self:GetFirstVisibleCraftingOrderFrame()
274-
-- Ignore input if no custom frames are visible
275-
and not self:GetFirstVisibleCustomFrame()
276-
-- Ignore input if no player choice buttons are visible
277-
and not next(self.playerChoiceButtons)
278-
then
279-
return true
280-
end
281-
282-
return false
234+
return next(buttons) and buttons or nil
283235
end
284236

285-
-- Primary functions --
286-
287237
-- Takes a global string like '%s has challenged you to a duel.' and converts it to a format suitable for string.find
288238
local summon_match = CONFIRM_SUMMON:gsub("%%d", ".+"):format(".+", ".+", ".+")
289239
local duel_match = DUEL_REQUESTED:format(".+")
@@ -338,7 +288,66 @@ function DialogKey:GetPopupButton(popupFrame)
338288
end
339289
end
340290

341-
return popupFrame.button1:IsVisible() and popupFrame.button1
291+
return popupFrame.button1:IsVisible() and popupFrame.button1 or nil
292+
end
293+
294+
--- @param frame Button
295+
function DialogKey:GuardDisabled(frame)
296+
if not self.db.ignoreDisabledButtons then return true; end
297+
298+
return frame:IsEnabled() and frame:IsMouseClickEnabled();
299+
end
300+
301+
--- @return Button|nil
302+
function DialogKey:GetFirstVisibleCustomFrame()
303+
for _, frameName in ipairs(ns.orderedCustomFrames) do
304+
local frame = self:GetFrameByName(frameName)
305+
if frame and frame:IsVisible() and frame:IsObjectType('Button') and self:GuardDisabled(frame) then
306+
return frame ---@diagnostic disable-line: return-type-mismatch
307+
end
308+
end
309+
end
310+
311+
--- @return Button|nil
312+
function DialogKey:GetFirstVisibleCraftingOrderFrame()
313+
if not self.db.handleCraftingOrders then return; end
314+
local frames = {
315+
"ProfessionsFrame.OrdersPage.OrderView.OrderInfo.StartOrderButton",
316+
"ProfessionsFrame.OrdersPage.OrderView.CreateButton",
317+
"ProfessionsFrame.OrdersPage.OrderView.CompleteOrderButton",
318+
};
319+
for _, frameName in ipairs(frames) do
320+
--- @type Button?
321+
local frame = self:GetFrameByName(frameName) ---@diagnostic disable-line: assign-type-mismatch
322+
if frame and frame:IsVisible() and self:GuardDisabled(frame) then
323+
return frame
324+
end
325+
end
326+
end
327+
328+
function DialogKey:ShouldIgnoreInput()
329+
if InCombatLockdown() then return true end
330+
331+
if self.db.ignoreWithModifier and (IsShiftKeyDown() or IsControlKeyDown() or IsAltKeyDown()) then return true end
332+
-- Ignore input while typing, unless at the Send Mail confirmation while typing into it!
333+
local focus = GetCurrentKeyBoardFocus()
334+
if focus and not (self:GetValidPopupButtons() and (focus:GetName() == "SendMailNameEditBox" or focus:GetName() == "SendMailSubjectEditBox")) then return true end
335+
336+
if
337+
-- Ignore input if there's nothing for DialogKey to click
338+
not GossipFrame:IsVisible() and not QuestFrame:IsVisible() and not self:GetValidPopupButtons()
339+
-- Ignore input if the Auction House sell frame is not open
340+
and (not AuctionHouseFrame or not AuctionHouseFrame:IsVisible())
341+
and not self:GetFirstVisibleCraftingOrderFrame()
342+
-- Ignore input if no custom frames are visible
343+
and not self:GetFirstVisibleCustomFrame()
344+
-- Ignore input if no player choice buttons are visible
345+
and not next(self.playerChoiceButtons)
346+
then
347+
return true
348+
end
349+
350+
return false
342351
end
343352

344353
-- Clears all override bindings associated with an owner, clears all override bindings if no owner is passed
@@ -393,10 +402,10 @@ function DialogKey:HandleKey(key)
393402
-- DialogKey pressed, interact with popups, accepts..
394403
if doAction then
395404
-- Popups
396-
local popupFrame = self:GetFirstVisiblePopup()
397-
local popupButton = popupFrame and self:GetPopupButton(popupFrame)
398-
if popupButton then
399-
self:SetClickbuttonBinding(popupButton, key)
405+
local popupButtons = self:GetValidPopupButtons()
406+
if popupButtons then
407+
-- todo: set a binding for each popup button?
408+
self:SetClickbuttonBinding(popupButtons[1], key)
400409
return
401410
end
402411

0 commit comments

Comments
 (0)