From 27a81c8d5f73ac3609778b6b9be1844d1c9b2799 Mon Sep 17 00:00:00 2001 From: Xottab-DUTY Date: Fri, 17 Jan 2025 20:24:44 +0300 Subject: [PATCH] CUIMessageBox: reuse button accelerators instead of directly handling input Having accelerators set will allow us to render keybind icons, which is really needed when gamepad is used (#943) Also, input is always allowed now. This commit revisits previous 2d67454f756e42e40710392957d1d6585764ac97 commit --- src/xrGame/ui/UIMessageBoxEx.cpp | 1 - src/xrUICore/MessageBox/UIMessageBox.cpp | 103 +++++------------------ src/xrUICore/MessageBox/UIMessageBox.h | 5 -- 3 files changed, 23 insertions(+), 86 deletions(-) diff --git a/src/xrGame/ui/UIMessageBoxEx.cpp b/src/xrGame/ui/UIMessageBoxEx.cpp index 2cffa9151bc..4f3443a4ddd 100644 --- a/src/xrGame/ui/UIMessageBoxEx.cpp +++ b/src/xrGame/ui/UIMessageBoxEx.cpp @@ -7,7 +7,6 @@ CUIMessageBoxEx::CUIMessageBoxEx() : CUIDialogWnd(CUIMessageBoxEx::GetDebugType( { m_pMessageBox = xr_new(); m_pMessageBox->SetWindowName("msg_box"); - m_pMessageBox->AllowInputHandling(true); // m_pMessageBox->SetAutoDelete(true); AttachChild(m_pMessageBox); } diff --git a/src/xrUICore/MessageBox/UIMessageBox.cpp b/src/xrUICore/MessageBox/UIMessageBox.cpp index ec2246384fd..8da59246eb3 100644 --- a/src/xrUICore/MessageBox/UIMessageBox.cpp +++ b/src/xrUICore/MessageBox/UIMessageBox.cpp @@ -48,86 +48,6 @@ bool CUIMessageBox::OnMouseAction(float x, float y, EUIMessages mouse_action) return inherited::OnMouseAction(x, y, mouse_action); } -bool CUIMessageBox::OnKeyboardAction(int dik, EUIMessages keyboard_action) -{ - if (IsInputHandlingAllowed() && keyboard_action == WINDOW_KEY_PRESSED) - { - const bool quitPressed = IsBinded(kQUIT, dik); - auto action = GetBindedAction(dik, EKeyContext::UI); - - switch (m_eMessageBoxStyle) - { - case MESSAGEBOX_OK: - case MESSAGEBOX_INFO: - { - if (quitPressed) - action = kUI_BACK; - switch (action) - { - case kUI_ACCEPT: - case kUI_BACK: - OnYesOk(); - return true; - } - break; - } - case MESSAGEBOX_DIRECT_IP: - case MESSAGEBOX_RA_LOGIN: - case MESSAGEBOX_PASSWORD: - case MESSAGEBOX_YES_NO: - case MESSAGEBOX_QUIT_GAME: - case MESSAGEBOX_QUIT_WINDOWS: - { - switch (action) - { - case kUI_ACCEPT: - OnYesOk(); - return true; - case kUI_BACK: - m_UIButtonNo->OnClick(); - return true; - } - break; - } - case MESSAGEBOX_YES_NO_CANCEL: - { - switch (action) - { - case kUI_ACCEPT: - OnYesOk(); - return true; - case kUI_ACTION_1: - m_UIButtonNo->OnClick(); - return true; - case kUI_BACK: - m_UIButtonCancel->OnClick(); - return true; - } - break; - } - case MESSAGEBOX_YES_NO_COPY: - { - switch (action) - { - case kUI_ACCEPT: - OnYesOk(); - return true; - case kUI_BACK: - m_UIButtonNo->OnClick(); - return true; - case kUI_ACTION_1: - m_UIButtonCopy->OnClick(); - return true; - } - break; - } - default: - VERIFY(!"Unknown message box type!"); - } // switch (m_eMessageBoxStyle) - } - return CUIStatic::OnKeyboardAction(dik, keyboard_action); -} - bool CUIMessageBox::InitMessageBox(LPCSTR box_template) { Clear(); @@ -212,6 +132,7 @@ bool CUIMessageBox::InitMessageBox(LPCSTR box_template) strconcat(sizeof(str), str, box_template, ":button_ok"); m_UIButtonYesOk = xr_new(); AttachChild(m_UIButtonYesOk); + m_UIButtonYesOk->SetAccelerator(kQUIT, false, 1); // can be overridden by gamedata CUIXmlInitBase::Init3tButton(uiXml, str, 0, m_UIButtonYesOk); break; } @@ -373,6 +294,28 @@ bool CUIMessageBox::InitMessageBox(LPCSTR box_template) break; } } // switch (m_eMessageBoxStyle) + + if (m_UIButtonYesOk) + { + m_UIButtonYesOk->SetAccelerator(kENTER, false, 2); + m_UIButtonYesOk->SetAccelerator(kUI_ACCEPT, false, 3); + } + if (m_UIButtonNo) + { + if (!m_UIButtonCancel) + m_UIButtonNo->SetAccelerator(kQUIT, false, 2); + m_UIButtonNo->SetAccelerator(kUI_BACK, false, 3); + } + if (m_UIButtonCancel) + { + m_UIButtonCancel->SetAccelerator(kQUIT, false, 2); + m_UIButtonCancel->SetAccelerator(kUI_ACTION_1, false, 3); + } + if (m_UIButtonCopy) + { + m_UIButtonCopy->SetAccelerator(kUI_ACTION_1, false, 2); + } + return true; } diff --git a/src/xrUICore/MessageBox/UIMessageBox.h b/src/xrUICore/MessageBox/UIMessageBox.h index 95f72c77417..15236374dc6 100644 --- a/src/xrUICore/MessageBox/UIMessageBox.h +++ b/src/xrUICore/MessageBox/UIMessageBox.h @@ -41,15 +41,10 @@ class XRUICORE_API CUIMessageBox final : public CUIStatic LPCSTR GetTextEditURL(); virtual bool OnMouseAction(float x, float y, EUIMessages mouse_action); - bool OnKeyboardAction(int dik, EUIMessages keyboard_action) override; virtual void SendMessage(CUIWindow* pWnd, s16 msg, void* pData); void OnYesOk(); - [[nodiscard]] - bool IsInputHandlingAllowed() const { return m_allowInputHandling; } - void AllowInputHandling(bool allow) { m_allowInputHandling = allow; } - pcstr GetDebugType() override { return "CUIMessageBox"; } protected: