Skip to content

Commit

Permalink
CUIMessageBox: reuse button accelerators instead of directly handling…
Browse files Browse the repository at this point in the history
… 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 2d67454
commit
  • Loading branch information
Xottab-DUTY committed Jan 17, 2025
1 parent 18c6823 commit 27a81c8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 86 deletions.
1 change: 0 additions & 1 deletion src/xrGame/ui/UIMessageBoxEx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ CUIMessageBoxEx::CUIMessageBoxEx() : CUIDialogWnd(CUIMessageBoxEx::GetDebugType(
{
m_pMessageBox = xr_new<CUIMessageBox>();
m_pMessageBox->SetWindowName("msg_box");
m_pMessageBox->AllowInputHandling(true);
// m_pMessageBox->SetAutoDelete(true);
AttachChild(m_pMessageBox);
}
Expand Down
103 changes: 23 additions & 80 deletions src/xrUICore/MessageBox/UIMessageBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -212,6 +132,7 @@ bool CUIMessageBox::InitMessageBox(LPCSTR box_template)
strconcat(sizeof(str), str, box_template, ":button_ok");
m_UIButtonYesOk = xr_new<CUI3tButton>();
AttachChild(m_UIButtonYesOk);
m_UIButtonYesOk->SetAccelerator(kQUIT, false, 1); // can be overridden by gamedata
CUIXmlInitBase::Init3tButton(uiXml, str, 0, m_UIButtonYesOk);
break;
}
Expand Down Expand Up @@ -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;
}

Expand Down
5 changes: 0 additions & 5 deletions src/xrUICore/MessageBox/UIMessageBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 27a81c8

Please sign in to comment.