Skip to content

Commit

Permalink
Allowed keyboard and gamepad input for MessageBoxEx
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Aug 12, 2023
1 parent 2ade51c commit 2d67454
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 25 deletions.
25 changes: 1 addition & 24 deletions src/xrGame/ui/UIMessageBoxEx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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 Expand Up @@ -74,30 +75,6 @@ void CUIMessageBoxEx::SendMessage(CUIWindow* pWnd, s16 msg, void* pData /* = NUL

LPCSTR CUIMessageBoxEx::GetHost() { return m_pMessageBox->GetHost(); }
LPCSTR CUIMessageBoxEx::GetPassword() { return m_pMessageBox->GetPassword(); }
bool CUIMessageBoxEx::OnKeyboardAction(int dik, EUIMessages keyboard_action)
{
if (keyboard_action == WINDOW_KEY_PRESSED)
{
auto action = GetBindedAction(dik);
if (action == kENTER || action == kJUMP)
{
m_pMessageBox->OnYesOk();
return true;
/*
}else
if ( IsBinded(kQUIT, dik) )
{
CUIMessageBox::E_MESSAGEBOX_STYLE style = m_pMessageBox->GetBoxStyle();
if(style != CUIMessageBox::MESSAGEBOX_INFO)
HideDialog();
return true;
*/
}
else
return CUIDialogWnd::OnKeyboardAction(dik, keyboard_action);
}
return CUIDialogWnd::OnKeyboardAction(dik, keyboard_action);
}

void CUIMessageBoxEx::SetTextEditURL(LPCSTR text) { m_pMessageBox->SetTextEditURL(text); }
LPCSTR CUIMessageBoxEx::GetTextEditURL() { return m_pMessageBox->GetTextEditURL(); }
1 change: 0 additions & 1 deletion src/xrGame/ui/UIMessageBoxEx.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class CUIMessageBoxEx final : public CUIDialogWnd, public CUIWndCallback
void OnOKClicked(CUIWindow*, void*);
void OnNOClicked(CUIWindow*, void*);

virtual bool OnKeyboardAction(int dik, EUIMessages keyboard_action);
virtual bool NeedCenterCursor() const { return false; }
CUIMessageBox* m_pMessageBox;

Expand Down
80 changes: 80 additions & 0 deletions src/xrUICore/MessageBox/UIMessageBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,86 @@ 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
6 changes: 6 additions & 0 deletions src/xrUICore/MessageBox/UIMessageBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@ 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 All @@ -65,4 +70,5 @@ class XRUICORE_API CUIMessageBox final : public CUIStatic
CUIEditBox* m_UIEditURL;

E_MESSAGEBOX_STYLE m_eMessageBoxStyle;
bool m_allowInputHandling{};
};

0 comments on commit 2d67454

Please sign in to comment.