Jaliborc / Bagnon

Single window displays for you items
195 stars 111 forks source link

Fixed the bug regarding the ESC key is not working properly to close the frames #1880

Closed zstenger93 closed 5 months ago

zstenger93 commented 7 months ago

I left a comment as well in the code at this line:

tinsert(UISpecialFrames, f:GetName())

This is not working at all since the name of the frame is not being set (or not properly) the way the frame is being created right now. To top it all, what other people described is that it's closing the main bag only when the bank is open, but not the bank nor in other situations.

I added the following to RegisterSignals()

self:SetScript('OnKeyDown', function(_, key)
        if key == 'ESCAPE' or key == 27 then
            self:SetPropagateKeyboardInput(false)
            self:Hide()
        else
            self:SetPropagateKeyboardInput(true)
        end
    end)

You need to use self:SetPropagateKeyboardInput(true) to allow the key inputs when the bag is open otherwise it's not working with SetScript()

I tested it in/out of combat, and with the bank slots too. It works perfectly, though a more proper fix would be better I guess 🚀

So now it looks like the following:

function Frame:RegisterSignals()
    self:RegisterSignal('UPDATE_ALL', 'Update')
    self:RegisterSignal('RULES_LOADED', 'FindRules')
    self:RegisterSignal('SKINS_LOADED', 'UpdateBackdrop')
    self:RegisterFrameSignal('BAG_FRAME_TOGGLED', 'Layout')
    self:RegisterFrameSignal('ELEMENT_RESIZED', 'Layout')
    self:SetScript('OnKeyDown', function(_, key)
        if key == 'ESCAPE' or key == 27 then
            self:SetPropagateKeyboardInput(false)
            self:Hide()
        else
            self:SetPropagateKeyboardInput(true)
        end
    end)
    self:Update()
end

You can add the same for the classic variations as well. I did not do so because I'm not playing them, and no time to test all of them either.