Skip to content

Commit

Permalink
Added initial support for gamepad and keyboard input for PDA window (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Aug 10, 2023
1 parent 9566601 commit 3063652
Show file tree
Hide file tree
Showing 7 changed files with 266 additions and 28 deletions.
81 changes: 73 additions & 8 deletions src/xrEngine/xr_level_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,46 @@ game_action actions[] = {
{ "custom14", kCUSTOM14, _sp },
{ "custom15", kCUSTOM15, _sp },

{ "pda_tab1", kPDA_TAB1, _sp },
{ "pda_tab2", kPDA_TAB2, _sp },
{ "pda_tab3", kPDA_TAB3, _sp },
{ "pda_tab4", kPDA_TAB4, _sp },
{ "pda_tab5", kPDA_TAB5, _sp },
{ "pda_tab6", kPDA_TAB6, _sp },

{ "kick", kKICK, _sp },

{ "editor", kEDITOR, _both },

// Contextual actions:
// UI
{ "ui_move", kUI_MOVE, _sp, EKeyContext::UI },
{ "ui_move_left", kUI_MOVE_LEFT, _sp, EKeyContext::UI },
{ "ui_move_right", kUI_MOVE_RIGHT, _sp, EKeyContext::UI },
{ "ui_move_up", kUI_MOVE_UP, _sp, EKeyContext::UI },
{ "ui_move_down", kUI_MOVE_DOWN, _sp, EKeyContext::UI },

{ "ui_move_accept", kUI_ACCEPT, _sp, EKeyContext::UI },
{ "ui_move_back", kUI_BACK, _sp, EKeyContext::UI },

// PDA:
{ "pda_map_move", kPDA_MAP_MOVE, _sp, EKeyContext::PDA },
{ "pda_map_move_left", kPDA_MAP_MOVE_LEFT, _sp, EKeyContext::PDA },
{ "pda_map_move_right", kPDA_MAP_MOVE_RIGHT, _sp, EKeyContext::PDA },
{ "pda_map_move_up", kPDA_MAP_MOVE_UP, _sp, EKeyContext::PDA },
{ "pda_map_move_down", kPDA_MAP_MOVE_DOWN, _sp, EKeyContext::PDA },

{ "pda_map_zoom_in", kPDA_MAP_ZOOM_IN, _sp, EKeyContext::PDA },
{ "pda_map_zoom_out", kPDA_MAP_ZOOM_OUT, _sp, EKeyContext::PDA },
{ "pda_map_zoom_reset", kPDA_MAP_ZOOM_RESET, _sp, EKeyContext::PDA },

{ "pda_map_show_actor", kPDA_MAP_SHOW_ACTOR, _sp, EKeyContext::PDA },
{ "pda_map_show_legend", kPDA_MAP_SHOW_LEGEND, _sp, EKeyContext::PDA },

{ "pda_tab_prev", kPDA_TAB_PREV, _sp, EKeyContext::PDA },
{ "pda_tab_next", kPDA_TAB_NEXT, _sp, EKeyContext::PDA },
{ "pda_tab1", kPDA_TAB1, _sp, EKeyContext::PDA },
{ "pda_tab2", kPDA_TAB2, _sp, EKeyContext::PDA },
{ "pda_tab3", kPDA_TAB3, _sp, EKeyContext::PDA },
{ "pda_tab4", kPDA_TAB4, _sp, EKeyContext::PDA },
{ "pda_tab5", kPDA_TAB5, _sp, EKeyContext::PDA },
{ "pda_tab6", kPDA_TAB6, _sp, EKeyContext::PDA },

{ "pda_filter_toggle", kPDA_FILTER_TOGGLE, _sp, EKeyContext::PDA },

{ nullptr, kLASTACTION, _both }
};

Expand Down Expand Up @@ -923,7 +952,43 @@ class CCC_DefControls : public CCC_UnBindAll
{ kQUICK_USE_3, { SDL_SCANCODE_F3, SDL_SCANCODE_UNKNOWN, XR_CONTROLLER_BUTTON_DPAD_RIGHT } },
{ kQUICK_USE_4, { SDL_SCANCODE_F4, SDL_SCANCODE_UNKNOWN, XR_CONTROLLER_BUTTON_DPAD_DOWN } },

{ kEDITOR, { SDL_SCANCODE_F10, SDL_SCANCODE_UNKNOWN, XR_CONTROLLER_BUTTON_INVALID } },
// Contextual actions:
// UI
{ kUI_MOVE, { SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, XR_CONTROLLER_AXIS_RIGHT } },
{ kUI_MOVE_LEFT, { SDL_SCANCODE_A, SDL_SCANCODE_LEFT, XR_CONTROLLER_BUTTON_DPAD_LEFT } },
{ kUI_MOVE_RIGHT, { SDL_SCANCODE_D, SDL_SCANCODE_RIGHT, XR_CONTROLLER_BUTTON_DPAD_RIGHT } },
{ kUI_MOVE_UP, { SDL_SCANCODE_W, SDL_SCANCODE_UP, XR_CONTROLLER_BUTTON_DPAD_UP } },
{ kUI_MOVE_DOWN, { SDL_SCANCODE_S, SDL_SCANCODE_DOWN, XR_CONTROLLER_BUTTON_DPAD_DOWN } },

{ kUI_ACCEPT, { SDL_SCANCODE_RETURN, SDL_SCANCODE_F, XR_CONTROLLER_BUTTON_A } },
{ kUI_BACK, { SDL_SCANCODE_ESCAPE, SDL_SCANCODE_G, XR_CONTROLLER_BUTTON_B } },

// PDA:
{ kPDA_MAP_MOVE, { SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, XR_CONTROLLER_AXIS_RIGHT } },
{ kPDA_MAP_MOVE_LEFT, { SDL_SCANCODE_A, SDL_SCANCODE_LEFT, XR_CONTROLLER_BUTTON_INVALID } },
{ kPDA_MAP_MOVE_RIGHT, { SDL_SCANCODE_D, SDL_SCANCODE_RIGHT, XR_CONTROLLER_BUTTON_INVALID } },
{ kPDA_MAP_MOVE_UP, { SDL_SCANCODE_W, SDL_SCANCODE_UP, XR_CONTROLLER_BUTTON_INVALID } },
{ kPDA_MAP_MOVE_DOWN, { SDL_SCANCODE_S, SDL_SCANCODE_DOWN, XR_CONTROLLER_BUTTON_INVALID } },

{ kPDA_MAP_ZOOM_IN, { SDL_SCANCODE_Z, SDL_SCANCODE_KP_PLUS, XR_CONTROLLER_AXIS_TRIGGER_RIGHT } },
{ kPDA_MAP_ZOOM_OUT, { SDL_SCANCODE_C, SDL_SCANCODE_KP_MINUS, XR_CONTROLLER_AXIS_TRIGGER_LEFT } },
{ kPDA_MAP_ZOOM_RESET, { SDL_SCANCODE_X, SDL_SCANCODE_KP_0, XR_CONTROLLER_BUTTON_INVALID } },

{ kPDA_MAP_SHOW_ACTOR, { SDL_SCANCODE_R, SDL_SCANCODE_KP_COMMA, XR_CONTROLLER_BUTTON_RIGHTSTICK } },
{ kPDA_MAP_SHOW_LEGEND, { SDL_SCANCODE_V, SDL_SCANCODE_KP_MULTIPLY, XR_CONTROLLER_BUTTON_INVALID } },

{ kPDA_TAB_PREV, { SDL_SCANCODE_Q, SDL_SCANCODE_UNKNOWN, XR_CONTROLLER_BUTTON_LEFTSHOULDER } },
{ kPDA_TAB_NEXT, { SDL_SCANCODE_E, SDL_SCANCODE_UNKNOWN, XR_CONTROLLER_BUTTON_RIGHTSHOULDER } },
{ kPDA_TAB1, { SDL_SCANCODE_1, SDL_SCANCODE_KP_1, XR_CONTROLLER_BUTTON_INVALID } },
{ kPDA_TAB2, { SDL_SCANCODE_2, SDL_SCANCODE_KP_2, XR_CONTROLLER_BUTTON_INVALID } },
{ kPDA_TAB3, { SDL_SCANCODE_3, SDL_SCANCODE_KP_3, XR_CONTROLLER_BUTTON_INVALID } },
{ kPDA_TAB4, { SDL_SCANCODE_4, SDL_SCANCODE_KP_4, XR_CONTROLLER_BUTTON_INVALID } },
{ kPDA_TAB5, { SDL_SCANCODE_5, SDL_SCANCODE_KP_5, XR_CONTROLLER_BUTTON_INVALID } },
{ kPDA_TAB6, { SDL_SCANCODE_6, SDL_SCANCODE_KP_6, XR_CONTROLLER_BUTTON_INVALID } },

{ kPDA_FILTER_TOGGLE, { SDL_SCANCODE_B, SDL_SCANCODE_UNKNOWN, XR_CONTROLLER_BUTTON_Y } },

{ kEDITOR, { SDL_SCANCODE_F10, SDL_SCANCODE_UNKNOWN, XR_CONTROLLER_BUTTON_INVALID } },
};

public:
Expand Down
37 changes: 34 additions & 3 deletions src/xrEngine/xr_level_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,45 @@ enum EGameActions : u32
kCUSTOM14,
kCUSTOM15,

kKICK, // alpet: kick dynamic objects

kEDITOR,

// Contextual actions:
// UI
kUI_MOVE,
kUI_MOVE_LEFT,
kUI_MOVE_RIGHT,
kUI_MOVE_UP,
kUI_MOVE_DOWN,

kUI_ACCEPT,
kUI_BACK,

// PDA:
kPDA_MAP_MOVE, // gamepad axis
kPDA_MAP_MOVE_LEFT,
kPDA_MAP_MOVE_RIGHT,
kPDA_MAP_MOVE_UP,
kPDA_MAP_MOVE_DOWN,

kPDA_MAP_ZOOM_IN,
kPDA_MAP_ZOOM_OUT,
kPDA_MAP_ZOOM_RESET,

kPDA_MAP_SHOW_ACTOR,
kPDA_MAP_SHOW_LEGEND,

kPDA_TAB_PREV,
kPDA_TAB_NEXT,
kPDA_TAB1,
kPDA_TAB2,
kPDA_TAB3,
kPDA_TAB4,
kPDA_TAB5,
kPDA_TAB6,

kKICK, // alpet: kick dynamic objects

kEDITOR,
kPDA_FILTER_TOGGLE,

kLASTACTION,
kNOTBINDED
Expand All @@ -142,6 +171,8 @@ enum EGameActions : u32
enum class EKeyContext
{
Undefined = 0, // default behaviour
UI, // UI overall
PDA,
};

constexpr char GAME_ACTION_MARK = 27; // escape symbol
Expand Down
60 changes: 46 additions & 14 deletions src/xrGame/ui/UIMapWnd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,18 +414,18 @@ bool CUIMapWnd::OnKeyboardAction(int dik, EUIMessages keyboard_action)
{
case WINDOW_KEY_PRESSED:
{
switch (dik)
switch (GetBindedAction(dik, EKeyContext::PDA))
{
case SDL_SCANCODE_KP_MINUS:
// SetZoom(GetZoom()/1.5f);
UpdateZoom(false);
// ResetActionPlanner();
case kPDA_MAP_ZOOM_RESET:
ViewGlobalMap();
return true;

case SDL_SCANCODE_KP_PLUS:
// SetZoom(GetZoom()*1.5f);
UpdateZoom(true);
// ResetActionPlanner();
case kPDA_MAP_SHOW_ACTOR:
ViewActor();
return true;

case kPDA_MAP_SHOW_LEGEND:
OnBtnLegend_Push(this, nullptr);
return true;
} // switch (dik)
break;
Expand All @@ -435,18 +435,30 @@ bool CUIMapWnd::OnKeyboardAction(int dik, EUIMessages keyboard_action)
{
Fvector2 pos_delta{};

switch (GetBindedAction(dik))
switch (GetBindedAction(dik, EKeyContext::PDA))
{
case kUP:
case kPDA_MAP_ZOOM_OUT:
// SetZoom(GetZoom()/1.5f);
UpdateZoom(false);
// ResetActionPlanner();
return true;

case kPDA_MAP_ZOOM_IN:
// SetZoom(GetZoom()*1.5f);
UpdateZoom(true);
// ResetActionPlanner();
return true;

case kPDA_MAP_MOVE_UP:
pos_delta.y += m_map_move_step;
break;
case kDOWN:
case kPDA_MAP_MOVE_DOWN:
pos_delta.y -= m_map_move_step;
break;
case kLEFT:
case kPDA_MAP_MOVE_LEFT:
pos_delta.x += m_map_move_step;
break;
case kRIGHT:
case kPDA_MAP_MOVE_RIGHT:
pos_delta.x -= m_map_move_step;
break;
}
Expand All @@ -463,6 +475,26 @@ bool CUIMapWnd::OnKeyboardAction(int dik, EUIMessages keyboard_action)
return inherited::OnKeyboardAction(dik, keyboard_action);
}

bool CUIMapWnd::OnControllerAction(int axis, float x, float y, EUIMessages controller_action)
{
switch (GetBindedAction(axis, EKeyContext::PDA))
{
default:
return OnKeyboardAction(axis, controller_action);

case kPDA_MAP_MOVE:
{
if (controller_action != WINDOW_KEY_HOLD)
break;
const auto pos_delta = Fvector2{ m_map_move_step, m_map_move_step }.mul(Fvector2{ -x, -y }.normalize());
MoveMap(pos_delta);
return true;
}
} // switch (GetBindedAction(axis, EKeyContext::PDA))

return inherited::OnControllerAction(axis, x, y, controller_action);
}

bool CUIMapWnd::OnMouseAction(float x, float y, EUIMessages mouse_action)
{
if (inherited::OnMouseAction(x, y, mouse_action) /*|| m_btn_nav_parent->OnMouseAction(x,y,mouse_action)*/)
Expand Down
1 change: 1 addition & 0 deletions src/xrGame/ui/UIMapWnd.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ class CUIMapWnd final : public CUIWindow, public CUIWndCallback
void Hint(const shared_str& text);
virtual bool OnMouseAction(float x, float y, EUIMessages mouse_action);
virtual bool OnKeyboardAction(int dik, EUIMessages keyboard_action);
bool OnControllerAction(int axis, float x, float y, EUIMessages controller_action) override;

virtual void SendMessage(CUIWindow* pWnd, s16 msg, void* pData = NULL);

Expand Down
27 changes: 25 additions & 2 deletions src/xrGame/ui/UIPdaWnd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ void CUIPdaWnd::SendMessage(CUIWindow* pWnd, s16 msg, void* pData)
{
if (pWnd == UITabControl)
{
SetActiveSubdialog(UITabControl->GetActiveId());
const auto& id = UITabControl->GetActiveId();
SetActiveSubdialog(id);
if (pInput->IsCurrentInputTypeController())
UI().GetUICursor().WarpToWindow(UITabControl->GetButtonById(id));
}
break;
}
Expand Down Expand Up @@ -399,11 +402,31 @@ void RearrangeTabButtons(CUITabControl* pTab)

bool CUIPdaWnd::OnKeyboardAction(int dik, EUIMessages keyboard_action)
{
if (IsBinded(kACTIVE_JOBS, dik))
if (IsBinded(kUI_BACK, dik, EKeyContext::UI))
{
if (WINDOW_KEY_PRESSED == keyboard_action)
HideDialog();
return true;
}

switch (GetBindedAction(dik, EKeyContext::PDA))
{
case kPDA_TAB_PREV:
if (WINDOW_KEY_PRESSED == keyboard_action)
UITabControl->SetNextActiveTab(false, true);
return true;

case kPDA_TAB_NEXT:
if (WINDOW_KEY_PRESSED == keyboard_action)
UITabControl->SetNextActiveTab(true, true);
return true;
}

// Context has a priority over default actions
if (IsBinded(kACTIVE_JOBS, dik))
{
if (WINDOW_KEY_PRESSED == keyboard_action)
HideDialog();
return true;
}

Expand Down
83 changes: 82 additions & 1 deletion src/xrGame/ui/UITaskWnd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,88 @@ void CUITaskWnd::Update()

void CUITaskWnd::Draw() { inherited::Draw(); }
void CUITaskWnd::DrawHint() { m_pMapWnd->DrawHint(); }

void CUITaskWnd::DropFilterSelection()
{
m_selected_filter = -1;
GetUICursor().WarpToWindow(nullptr, pInput->IsCurrentInputTypeController());
}

bool CUITaskWnd::OnKeyboardAction(int dik, EUIMessages keyboard_action)
{

if (keyboard_action == WINDOW_KEY_PRESSED)
{
if (IsBinded(kPDA_FILTER_TOGGLE, dik, EKeyContext::PDA) && m_selected_filter == -1)
{
m_selected_filter = 0;
GetUICursor().WarpToWindow(m_filters[m_selected_filter]);
GetUICursor().PauseAutohiding(true);
return true;
}

if (m_selected_filter >= 0)
{
if (IsBinded(kQUIT, dik))
{
DropFilterSelection();
return false; // allow PDA to hide
}

switch (GetBindedAction(dik, EKeyContext::UI))
{
case kUI_BACK:
DropFilterSelection();
return true;

case kUI_ACCEPT:
m_filters[m_selected_filter]->OnMouseDown(MOUSE_1);
return true;

case kUI_MOVE_LEFT:
case kUI_MOVE_DOWN:
if (m_selected_filter > 0)
m_selected_filter--;
else
m_selected_filter = int(m_filters.size() - 1);
break;

case kUI_MOVE_RIGHT:
case kUI_MOVE_UP:
if (m_selected_filter < int(m_filters.size() - 1))
m_selected_filter++;
else
m_selected_filter = 0;
break;
} // switch (GetBindedAction(dik, EKeyContext::UI))

if (IsBinded(kPDA_FILTER_TOGGLE, dik, EKeyContext::PDA))
{
DropFilterSelection();
return true;
}

GetUICursor().WarpToWindow(m_filters[m_selected_filter]);
return true;
}
}

return inherited::OnKeyboardAction(dik, keyboard_action);
}

bool CUITaskWnd::OnControllerAction(int axis, float x, float y, EUIMessages controller_action)
{
switch (GetBindedAction(axis, EKeyContext::UI))
{
default:
return OnKeyboardAction(axis, controller_action);
case kUI_MOVE:
if (m_selected_filter >= 0)
return true; // just screw it for now
}
return inherited::OnControllerAction(axis, x, y, controller_action);
}

void CUITaskWnd::SendMessage(CUIWindow* pWnd, s16 msg, void* pData)
{
if (msg == PDA_TASK_SET_TARGET_MAP && pData)
Expand Down Expand Up @@ -384,7 +466,6 @@ void CUITaskWnd::OnMapSpotFilterClicked(CUIWindow* ui, void* d)
{
if (m_filters[i] == ui)
m_filters_state[i] = m_filters[i]->GetCheck();

}
ReloadTaskInfo();
}
Expand Down
Loading

0 comments on commit 3063652

Please sign in to comment.