diff --git a/src/game/client/swarm/asw_input.h b/src/game/client/swarm/asw_input.h index 4cea8dc8c..8f0980cda 100644 --- a/src/game/client/swarm/asw_input.h +++ b/src/game/client/swarm/asw_input.h @@ -145,6 +145,7 @@ class CASWInput : public CInput, public IClientEntityListener void SetCameraFixed( bool bFixed ) { m_bCameraFixed = bFixed; } void UpdateASWControls(); + void EngageControllerMode(); private: float m_fCurrentCameraPitch; @@ -160,8 +161,6 @@ class CASWInput : public CInput, public IClientEntityListener void CalculateCameraShift( C_ASW_Player *pPlayer, float flDeltaX, float flDeltaY, float &flShiftX, float &flShiftY ); void SmoothCamera( C_ASW_Player *pPlayer, Vector &vecCameraLocation ); - void EngageControllerMode(); - int m_iOrderingMarine; // entindex of marine we're ordering around Vector m_vecCrosshairAimingPos; diff --git a/src/game/client/swarm/rd_steam_input.cpp b/src/game/client/swarm/rd_steam_input.cpp index 2b10b6c90..b72cbc5f9 100644 --- a/src/game/client/swarm/rd_steam_input.cpp +++ b/src/game/client/swarm/rd_steam_input.cpp @@ -29,7 +29,6 @@ using namespace BaseModUI; ConVar rd_gamepad_soft_keyboard( "rd_gamepad_soft_keyboard", "1", FCVAR_ARCHIVE, "Automatically open Steam Deck style keyboard when focusing a text field." ); ConVar rd_force_controller_glyph_set( "rd_force_controller_glyph_set", "-1", FCVAR_ARCHIVE, "Use a specific controller button set for UI hints. 3=xbox, 10=switch, 13=ps5, 14=steam deck", true, -1, true, k_ESteamInputType_Count - 1 ); ConVar rd_gamepad_player_color( "rd_gamepad_player_color", "1", FCVAR_ARCHIVE, "Set controller LED color to player color when controlling a marine." ); -ConVar rd_gamepad_ignore_menus( "rd_gamepad_ignore_menus", "-1", FCVAR_NONE, "Ignore Steam Input menu actions. If this is -1, it will automatically be set to 1 if the game sees an xbox controller and 0 otherwise." ); ConVar rd_gamepad_rumble_intensity( "rd_gamepad_rumble_intensity", "0.0", FCVAR_ARCHIVE, "Multiplies controller rumble intensity. 1.0 is \"normal\". Currently, there is no rumble." ); CRD_Steam_Input g_RD_Steam_Input; @@ -722,7 +721,6 @@ CRD_Steam_Controller::CRD_Steam_Controller( InputHandle_t hController ) : m_hController{ hController }, m_bConnected{ false }, m_bJustChangedActionSet{ false }, - m_hLastActionSet{ NULL }, m_SplitScreenPlayerIndex{ -1 }, m_LastPlayerColor{} { @@ -746,8 +744,6 @@ void CRD_Steam_Controller::OnDisconnected() Assert( m_bConnected ); m_bConnected = false; - m_hLastActionSet = NULL; - m_LastActionSetLayers.Purge(); // CERT: "When the controller is disconnected, the game must pause unless it's a multiplayer game." if ( engine->IsInGame() && gpGlobals->maxClients == 1 && !engine->IsPaused() ) @@ -770,32 +766,24 @@ void CRD_Steam_Controller::OnFrame( ISteamInput *pSteamInput ) C_ASW_Player *pPlayer = m_SplitScreenPlayerIndex == -1 ? NULL : C_ASW_Player::GetLocalASWPlayer( m_SplitScreenPlayerIndex ); - CUtlVector layers; - InputActionSetHandle_t hSet = g_RD_Steam_Input.DetermineActionSet( &layers, m_SplitScreenPlayerIndex ); - m_bJustChangedActionSet = m_hLastActionSet != hSet; - m_hLastActionSet = hSet; + InputActionSetHandle_t hLastActionSet = pSteamInput->GetCurrentActionSet( m_hController ); + InputActionSetHandle_t ActiveLayers[STEAM_INPUT_MAX_ACTIVE_LAYERS]; + int nActiveLayers = pSteamInput->GetActiveActionSetLayers( m_hController, ActiveLayers ); - if ( m_bJustChangedActionSet || layers.Count() != m_LastActionSetLayers.Count() || V_memcmp( layers.Base(), m_LastActionSetLayers.Base(), layers.Count() * sizeof( layers[0] ) ) ) - { - m_LastActionSetLayers.RemoveAll(); - m_LastActionSetLayers.AddVectorToTail( layers ); + CUtlVector RequestedLayers; + InputActionSetHandle_t hSet = g_RD_Steam_Input.DetermineActionSet( &RequestedLayers, m_SplitScreenPlayerIndex ); + m_bJustChangedActionSet = hLastActionSet != hSet; + if ( m_bJustChangedActionSet || RequestedLayers.Count() != nActiveLayers || V_memcmp( RequestedLayers.Base(), ActiveLayers, nActiveLayers * sizeof( ActiveLayers[0] ) ) ) + { pSteamInput->DeactivateAllActionSetLayers( m_hController ); pSteamInput->ActivateActionSet( m_hController, hSet ); - FOR_EACH_VEC( layers, i ) + FOR_EACH_VEC( RequestedLayers, i ) { - pSteamInput->ActivateActionSetLayer( m_hController, layers[i] ); + pSteamInput->ActivateActionSetLayer( m_hController, RequestedLayers[i] ); } } -#ifdef DBGFLAG_ASSERT - Assert( pSteamInput->GetCurrentActionSet( m_hController ) == hSet ); - InputActionSetHandle_t ActiveLayers[STEAM_INPUT_MAX_ACTIVE_LAYERS]; - int nActiveLayers = pSteamInput->GetActiveActionSetLayers( m_hController, ActiveLayers ); - Assert( nActiveLayers == layers.Count() ); - Assert( !V_memcmp( ActiveLayers, layers.Base(), layers.Count() * sizeof( layers[0] ) ) ); -#endif - if ( rd_gamepad_player_color.GetBool() ) { Color PlayerColor{}; @@ -817,6 +805,9 @@ void CRD_Steam_Controller::OnDigitalAction( InputDigitalActionHandle_t hAction, { Assert( m_bConnected ); + if ( ASWInput() && bState ) + ASWInput()->EngageControllerMode(); + for ( CRD_Steam_Input_Bind *pBind = CRD_Steam_Input_Bind::s_pBinds; pBind; pBind = pBind->m_pNext ) { if ( pBind->m_hAction != hAction ) @@ -825,6 +816,9 @@ void CRD_Steam_Controller::OnDigitalAction( InputDigitalActionHandle_t hAction, if ( m_bJustChangedActionSet && pBind->m_bIgnoreOnActionSetChange && bState ) return; + if ( pBind->m_bIgnoreCommandOnXboxControllers && SteamInput()->GetGamepadIndexForController( m_hController ) != -1 ) + return; + char szCommand[1024]; bool bIsToggle = pBind->m_szBind[0] == '+'; @@ -847,16 +841,20 @@ void CRD_Steam_Controller::OnAnalogAction( InputAnalogActionHandle_t hAction, EI { Assert( m_bConnected ); + if ( ASWInput() && ( x != 0 || y != 0 ) ) + ASWInput()->EngageControllerMode(); + // analog actions are handled per-frame, not per-input. } CRD_Steam_Input_Bind *CRD_Steam_Input_Bind::s_pBinds = NULL; CRD_Steam_Input_Bind *CRD_Steam_Input_Bind::s_pLastBind = NULL; -CRD_Steam_Input_Bind::CRD_Steam_Input_Bind( const char *szActionName, const char *szBind, const char *szForceActionSet, bool bIgnoreOnActionSetChange ) : +CRD_Steam_Input_Bind::CRD_Steam_Input_Bind( const char *szActionName, const char *szBind, const char *szForceActionSet, bool bIgnoreCommandOnXboxControllers, bool bIgnoreOnActionSetChange ) : m_szActionName{ szActionName }, m_szBind{ szBind }, m_szForceActionSet{ szForceActionSet }, + m_bIgnoreCommandOnXboxControllers{ bIgnoreCommandOnXboxControllers }, m_bIgnoreOnActionSetChange{ bIgnoreOnActionSetChange } { m_pNext = NULL; diff --git a/src/game/client/swarm/rd_steam_input.h b/src/game/client/swarm/rd_steam_input.h index 285781a86..3762a1e90 100644 --- a/src/game/client/swarm/rd_steam_input.h +++ b/src/game/client/swarm/rd_steam_input.h @@ -78,8 +78,6 @@ class CRD_Steam_Controller final const InputHandle_t m_hController; bool m_bConnected; bool m_bJustChangedActionSet; - InputActionSetHandle_t m_hLastActionSet; - CUtlVector m_LastActionSetLayers; int m_SplitScreenPlayerIndex; Color m_LastPlayerColor; }; @@ -87,7 +85,7 @@ class CRD_Steam_Controller final class CRD_Steam_Input_Bind final { public: - CRD_Steam_Input_Bind( const char *szActionName, const char *szBind, const char *szForceActionSet, bool bIgnoreOnActionSetChange = false ); + CRD_Steam_Input_Bind( const char *szActionName, const char *szBind, const char *szForceActionSet, bool bIgnoreCommandOnXboxControllers = false, bool bIgnoreOnActionSetChange = false ); private: const char *m_szActionName; @@ -95,6 +93,7 @@ class CRD_Steam_Input_Bind final const char *m_szForceActionSet; InputDigitalActionHandle_t m_hAction; InputActionSetHandle_t m_hForceActionSet; + bool m_bIgnoreCommandOnXboxControllers; bool m_bIgnoreOnActionSetChange; CRD_Steam_Input_Bind *m_pNext; diff --git a/src/game/client/swarm/rd_steam_input_binds.cpp b/src/game/client/swarm/rd_steam_input_binds.cpp index 007b40f09..e2fed2e6f 100644 --- a/src/game/client/swarm/rd_steam_input_binds.cpp +++ b/src/game/client/swarm/rd_steam_input_binds.cpp @@ -65,7 +65,7 @@ RD_STEAM_INPUT_BIND( VoteNo, "vote_no", "InGame" ); // UI RD_STEAM_INPUT_BIND( PlayerList, "playerlist", "InGame" ); RD_STEAM_INPUT_BIND( InGameBriefing, "ingamebriefing", "InGame" ); -RD_STEAM_INPUT_BIND( Menu, "gameui_activate", "InGame", true ); +RD_STEAM_INPUT_BIND( Menu, "gameui_activate", "InGame", false, true ); RD_STEAM_INPUT_BIND( RotateCameraLeft, "rotatecameraleft", "InGame" ); RD_STEAM_INPUT_BIND( RotateCameraRight, "rotatecameraright", "InGame" ); RD_STEAM_INPUT_BIND( SelectMarineDeathmatch, "cl_select_loadout", "InGame" ); @@ -91,29 +91,16 @@ RD_STEAM_INPUT_BIND( SelectMarine8, "+selectmarine8", "InGame" ); extern vgui::IInputInternal *g_InputInternal; extern ConVar rd_gamepad_ignore_menus; -static bool GamepadIgnoreMenus() -{ - if ( rd_gamepad_ignore_menus.GetInt() == -1 ) - { - DevMsg( "detected xbox gamepad count: %d; updating rd_gamepad_ignore_menus\n", g_pInputSystem->GetJoystickCount() ); - rd_gamepad_ignore_menus.SetValue( g_pInputSystem->GetJoystickCount() != 0 ); - } - - return rd_gamepad_ignore_menus.GetBool(); -} - static void ButtonPressHelper( ButtonCode_t eButton ) { - if ( !GamepadIgnoreMenus() ) - g_InputInternal->InternalKeyCodePressed( eButton ); - //GetControllerFocus()->OnControllerButtonPressed( eButton ); + g_InputInternal->InternalKeyCodePressed( eButton ); + GetControllerFocus()->OnControllerButtonPressed( eButton ); } static void ButtonReleaseHelper( ButtonCode_t eButton ) { - if ( !GamepadIgnoreMenus() ) - g_InputInternal->InternalKeyCodeReleased( eButton ); - //GetControllerFocus()->OnControllerButtonReleased( eButton ); + g_InputInternal->InternalKeyCodeReleased( eButton ); + GetControllerFocus()->OnControllerButtonReleased( eButton ); } #define RD_STEAM_INPUT_MENU_BIND( ActionName, ConCommandName, eButton, ... ) \ @@ -129,31 +116,31 @@ static void ButtonReleaseHelper( ButtonCode_t eButton ) ConCommand ConCommandName##_release_command( "-" #ConCommandName, &ConCommandName##_release, "helper command for " #eButton, FCVAR_HIDDEN ); \ RD_STEAM_INPUT_BIND( ActionName, "+" #ConCommandName, __VA_ARGS__ ) -RD_STEAM_INPUT_MENU_BIND( MenuConfirm, rd_menu_confirm, KEY_XBUTTON_A, "Menus" ); -RD_STEAM_INPUT_MENU_BIND( MenuBack, rd_menu_back, KEY_XBUTTON_B, "Menus" ); -RD_STEAM_INPUT_MENU_BIND( MenuSpecial1, rd_menu_special_1, KEY_XBUTTON_X, "Menus" ); -RD_STEAM_INPUT_MENU_BIND( MenuSpecial2, rd_menu_special_2, KEY_XBUTTON_Y, "Menus" ); - -RD_STEAM_INPUT_MENU_BIND( MenuL1, rd_menu_left_bumper, KEY_XBUTTON_LEFT_SHOULDER, "Menus" ); -RD_STEAM_INPUT_MENU_BIND( MenuR1, rd_menu_right_bumper, KEY_XBUTTON_RIGHT_SHOULDER, "Menus" ); -RD_STEAM_INPUT_MENU_BIND( MenuL2, rd_menu_left_trigger, KEY_XBUTTON_LTRIGGER, "Menus" ); -RD_STEAM_INPUT_MENU_BIND( MenuR2, rd_menu_right_trigger, KEY_XBUTTON_RTRIGGER, "Menus" ); -RD_STEAM_INPUT_MENU_BIND( MenuL3, rd_menu_left_stick, KEY_XBUTTON_STICK1, "Menus" ); -RD_STEAM_INPUT_MENU_BIND( MenuR3, rd_menu_right_stick, KEY_XBUTTON_STICK2, "Menus" ); -RD_STEAM_INPUT_MENU_BIND( MenuSelect, rd_menu_select, KEY_XBUTTON_BACK, "Menus" ); -RD_STEAM_INPUT_MENU_BIND( MenuStart, rd_menu_start, KEY_XBUTTON_START, "Menus", true ); - -RD_STEAM_INPUT_MENU_BIND( MenuLeft, rd_menu_left, KEY_XBUTTON_LEFT, "Menus" ); -RD_STEAM_INPUT_MENU_BIND( MenuRight, rd_menu_right, KEY_XBUTTON_RIGHT, "Menus" ); -RD_STEAM_INPUT_MENU_BIND( MenuUp, rd_menu_up, KEY_XBUTTON_UP, "Menus" ); -RD_STEAM_INPUT_MENU_BIND( MenuDown, rd_menu_down, KEY_XBUTTON_DOWN, "Menus" ); - -RD_STEAM_INPUT_MENU_BIND( MenuLeftStickLeft, rd_menu_left_stick_left, KEY_XSTICK1_LEFT, "Menus" ); -RD_STEAM_INPUT_MENU_BIND( MenuLeftStickRight, rd_menu_left_stick_right, KEY_XSTICK1_RIGHT, "Menus" ); -RD_STEAM_INPUT_MENU_BIND( MenuLeftStickUp, rd_menu_left_stick_up, KEY_XSTICK1_UP, "Menus" ); -RD_STEAM_INPUT_MENU_BIND( MenuLeftStickDown, rd_menu_left_stick_down, KEY_XSTICK1_DOWN, "Menus" ); - -RD_STEAM_INPUT_MENU_BIND( MenuRightStickLeft, rd_menu_right_stick_left, KEY_XSTICK2_LEFT, "Menus" ); -RD_STEAM_INPUT_MENU_BIND( MenuRightStickRight, rd_menu_right_stick_right, KEY_XSTICK2_RIGHT, "Menus" ); -RD_STEAM_INPUT_MENU_BIND( MenuRightStickUp, rd_menu_right_stick_up, KEY_XSTICK2_UP, "Menus" ); -RD_STEAM_INPUT_MENU_BIND( MenuRightStickDown, rd_menu_right_stick_down, KEY_XSTICK2_DOWN, "Menus" ); +RD_STEAM_INPUT_MENU_BIND( MenuConfirm, rd_menu_confirm, KEY_XBUTTON_A, "Menus", true ); +RD_STEAM_INPUT_MENU_BIND( MenuBack, rd_menu_back, KEY_XBUTTON_B, "Menus", true ); +RD_STEAM_INPUT_MENU_BIND( MenuSpecial1, rd_menu_special_1, KEY_XBUTTON_X, "Menus", true ); +RD_STEAM_INPUT_MENU_BIND( MenuSpecial2, rd_menu_special_2, KEY_XBUTTON_Y, "Menus", true ); + +RD_STEAM_INPUT_MENU_BIND( MenuL1, rd_menu_left_bumper, KEY_XBUTTON_LEFT_SHOULDER, "Menus", true ); +RD_STEAM_INPUT_MENU_BIND( MenuR1, rd_menu_right_bumper, KEY_XBUTTON_RIGHT_SHOULDER, "Menus", true ); +RD_STEAM_INPUT_MENU_BIND( MenuL2, rd_menu_left_trigger, KEY_XBUTTON_LTRIGGER, "Menus", true ); +RD_STEAM_INPUT_MENU_BIND( MenuR2, rd_menu_right_trigger, KEY_XBUTTON_RTRIGGER, "Menus", true ); +RD_STEAM_INPUT_MENU_BIND( MenuL3, rd_menu_left_stick, KEY_XBUTTON_STICK1, "Menus", true ); +RD_STEAM_INPUT_MENU_BIND( MenuR3, rd_menu_right_stick, KEY_XBUTTON_STICK2, "Menus", true ); +RD_STEAM_INPUT_MENU_BIND( MenuSelect, rd_menu_select, KEY_XBUTTON_BACK, "Menus", true ); +RD_STEAM_INPUT_MENU_BIND( MenuStart, rd_menu_start, KEY_XBUTTON_START, "Menus", true, true ); + +RD_STEAM_INPUT_MENU_BIND( MenuLeft, rd_menu_left, KEY_XBUTTON_LEFT, "Menus", true ); +RD_STEAM_INPUT_MENU_BIND( MenuRight, rd_menu_right, KEY_XBUTTON_RIGHT, "Menus", true ); +RD_STEAM_INPUT_MENU_BIND( MenuUp, rd_menu_up, KEY_XBUTTON_UP, "Menus", true ); +RD_STEAM_INPUT_MENU_BIND( MenuDown, rd_menu_down, KEY_XBUTTON_DOWN, "Menus", true ); + +RD_STEAM_INPUT_MENU_BIND( MenuLeftStickLeft, rd_menu_left_stick_left, KEY_XSTICK1_LEFT, "Menus", true ); +RD_STEAM_INPUT_MENU_BIND( MenuLeftStickRight, rd_menu_left_stick_right, KEY_XSTICK1_RIGHT, "Menus", true ); +RD_STEAM_INPUT_MENU_BIND( MenuLeftStickUp, rd_menu_left_stick_up, KEY_XSTICK1_UP, "Menus", true ); +RD_STEAM_INPUT_MENU_BIND( MenuLeftStickDown, rd_menu_left_stick_down, KEY_XSTICK1_DOWN, "Menus", true ); + +RD_STEAM_INPUT_MENU_BIND( MenuRightStickLeft, rd_menu_right_stick_left, KEY_XSTICK2_LEFT, "Menus", true ); +RD_STEAM_INPUT_MENU_BIND( MenuRightStickRight, rd_menu_right_stick_right, KEY_XSTICK2_RIGHT, "Menus", true ); +RD_STEAM_INPUT_MENU_BIND( MenuRightStickUp, rd_menu_right_stick_up, KEY_XSTICK2_UP, "Menus", true ); +RD_STEAM_INPUT_MENU_BIND( MenuRightStickDown, rd_menu_right_stick_down, KEY_XSTICK2_DOWN, "Menus", true ); diff --git a/src/game/client/swarm/vgui/controller_focus.cpp b/src/game/client/swarm/vgui/controller_focus.cpp index d83c82907..4f214a38a 100644 --- a/src/game/client/swarm/vgui/controller_focus.cpp +++ b/src/game/client/swarm/vgui/controller_focus.cpp @@ -434,6 +434,15 @@ void CControllerFocus::UpdateMenuNavigation() flDelay = flRepeatDelay; } } + + FOR_EACH_VEC_BACK( m_FocusAreas, i ) + { + Assert( m_FocusAreas[i].hPanel ); + if ( !m_FocusAreas[i].hPanel ) + { + m_FocusAreas.Remove( i ); + } + } } void CControllerFocus::ClickFocusPanel( bool bDown, bool bRightMouse )