@ -60,8 +60,9 @@ uint8_t Input::controllerCount{0};
std : : vector < Steam : : SteamInput > Input : : leftStickActionSets { Steam : : MOVE } ;
std : : vector < Steam : : SteamInput > Input : : rightStickActionSets { Steam : : SCROLL } ;
std : : array < std : : unordered_map < Steam : : SteamInput , std : : pair < std : : string , HWButton > > , 16 > Input : : enumToActionName ;
std : : array < std : : unordered_map < Steam : : SteamInput , std : : pair < std : : string , HWButton > > , STEAM_INPUT_MAX_COUNT > Input : : enumToActionName ;
std : : unordered_map < EInputActionOrigin , std : : string > Input : : steamIconToGameIcon {
# ifndef __EMSCRIPTEN__
{ k_EInputActionOrigin_SteamController_A , " themes/button_d_xb.png " } ,
{ k_EInputActionOrigin_XBoxOne_A , " themes/button_d_xb.png " } ,
{ k_EInputActionOrigin_XBox360_A , " themes/button_d_xb.png " } ,
@ -139,6 +140,7 @@ std::unordered_map<EInputActionOrigin,std::string>Input::steamIconToGameIcon{
{ k_EInputActionOrigin_PS5_RightStick_Move , " themes/button_analogstick.png " } ,
{ k_EInputActionOrigin_SteamDeck_LeftStick_Move , " themes/button_analogstick.png " } ,
{ k_EInputActionOrigin_SteamDeck_RightStick_Move , " themes/button_analogstick.png " } ,
# endif
} ;
Input : : Input ( InputType type , int key )
@ -174,6 +176,7 @@ void Input::Initialize(){
void Input : : LoadSteamButtonIcons ( ) {
GFX . Unlock ( ) ;
# ifndef __EMSCRIPTEN__
for ( int i = 1 ; i < k_EInputActionOrigin_Count ; i + + ) {
const char * imageName { SteamInput ( ) - > GetGlyphPNGForActionOrigin ( EInputActionOrigin ( i ) , k_ESteamInputGlyphSize_Small , 0U ) } ;
if ( imageName ! = nullptr ) {
@ -187,11 +190,12 @@ void Input::LoadSteamButtonIcons(){
}
}
}
# endif
GFX . SetInitialized ( ) ;
}
void Input : : UpdateSteamInput ( ) {
if ( SteamInput ( ) ) {
STEAMINPUT (
uint8_t prevControllerCount = controllerCount ;
controllerCount = SteamInput ( ) - > GetConnectedControllers ( steamControllers . data ( ) ) ;
if ( controllerCount < prevControllerCount & & Menu : : stack . size ( ) = = 0 & & GameState : : STATE = = GameState : : states [ States : : GAME_RUN ] ) Menu : : OpenMenu ( MenuType : : PAUSE ) ; //We unplugged a controller so we will automatically pause the game.
@ -224,7 +228,7 @@ void Input::UpdateSteamInput(){
steamGameInputToAnalogOrigin [ input ] . first = SteamInput ( ) - > GetAnalogActionOrigins ( steamControllers [ activeSteamControllerIndex ] , ingameControlsHandle , analogInputHnd , steamGameInputToAnalogOrigin [ input ] . second . data ( ) ) ;
}
}
}
)
}
bool Input : : Pressed ( ) {
@ -238,14 +242,16 @@ bool Input::Pressed(){
inputPressed = game - > GetMouse ( key ) . bPressed ;
} break ;
case CONTROLLER : {
if ( ! SteamInput ( ) ) {
STEAMINPUT ( ) else {
for ( GamePad * gamepad : GamePad : : getGamepads ( ) ) {
if ( gamepad - > stillConnected & & gamepad - > getButton ( static_cast < GPButtons > ( key ) ) . bPressed ) inputPressed = true ;
}
}
} break ;
case STEAM : {
STEAMINPUT (
if ( enumToActionName [ activeSteamControllerIndex ] [ Steam : : SteamInput ( key ) ] . second . bPressed ) inputPressed = true ;
)
} break ;
case ANALOG : {
//An analog input can never be "pressed". No-op.
@ -255,7 +261,7 @@ bool Input::Pressed(){
}
}
if ( inputPressed ) {
usingGamepad = type = = CONTROLLER | | type = = STEAM ;
SetUsingGamepad ( type = = CONTROLLER | | type = = STEAM ) ;
return true ;
}
return false ;
@ -272,14 +278,16 @@ bool Input::Held(){
inputHeld | = game - > GetMouse ( key ) . bHeld ;
} break ;
case CONTROLLER : {
if ( ! SteamInput ( ) ) {
STEAMINPUT ( ) else {
for ( GamePad * gamepad : GamePad : : getGamepads ( ) ) {
if ( gamepad - > stillConnected ) inputHeld | = gamepad - > getButton ( static_cast < GPButtons > ( key ) ) . bHeld ;
}
}
} break ;
case STEAM : {
STEAMINPUT (
inputHeld | = enumToActionName [ activeSteamControllerIndex ] [ Steam : : SteamInput ( key ) ] . second . bHeld ;
)
} break ;
case ANALOG : {
//An analog input can never be "held". No-op.
@ -289,7 +297,7 @@ bool Input::Held(){
}
}
if ( inputHeld ) {
usingGamepad = type = = CONTROLLER | | type = = STEAM ;
SetUsingGamepad ( type = = CONTROLLER | | type = = STEAM ) ;
return true ;
}
return false ;
@ -306,14 +314,16 @@ bool Input::Released(){
inputReleased | = game - > GetMouse ( key ) . bReleased ;
} break ;
case CONTROLLER : {
if ( ! SteamInput ( ) ) {
STEAMINPUT ( ) else {
for ( GamePad * gamepad : GamePad : : getGamepads ( ) ) {
if ( gamepad - > stillConnected ) inputReleased | = gamepad - > getButton ( static_cast < GPButtons > ( key ) ) . bReleased ;
}
}
} break ;
case STEAM : {
STEAMINPUT (
inputReleased | = enumToActionName [ activeSteamControllerIndex ] [ Steam : : SteamInput ( key ) ] . second . bReleased ;
)
} break ;
case ANALOG : {
//An analog input can never be "released". No-op.
@ -323,7 +333,7 @@ bool Input::Released(){
}
}
if ( inputReleased ) {
usingGamepad = type = = CONTROLLER | | type = = STEAM ;
SetUsingGamepad ( type = = CONTROLLER | | type = = STEAM ) ;
return true ;
}
return false ;
@ -333,18 +343,7 @@ float Input::Analog(){
if ( ! game - > IsFocused ( ) ) return false ;
switch ( type ) {
case ANALOG : {
if ( ! SteamInput ( ) ) {
for ( GamePad * gamepad : GamePad : : getGamepads ( ) ) {
if ( gamepad - > stillConnected ) {
float axisVal = gamepad - > getAxis ( static_cast < GPAxes > ( key ) ) ;
if ( axisVal ! = 0.f ) {
usingGamepad = true ;
return axisVal ;
}
}
}
} else {
STEAMINPUT (
auto GetAnalogStickVal = [ & ] ( uint8_t controller , Steam : : SteamInput input , Axis axis ) {
InputAnalogActionHandle_t inputHnd = SteamInput ( ) - > GetAnalogActionHandle ( enumToActionName [ controller ] [ input ] . first . c_str ( ) ) ;
InputAnalogActionData_t data = SteamInput ( ) - > GetAnalogActionData ( steamControllers [ controller ] , inputHnd ) ;
@ -412,6 +411,16 @@ float Input::Analog(){
case GPAxes : : DY : { } break ; //Unused. No-op
}
}
) else {
for ( GamePad * gamepad : GamePad : : getGamepads ( ) ) {
if ( gamepad - > stillConnected ) {
float axisVal = gamepad - > getAxis ( static_cast < GPAxes > ( key ) ) ;
if ( axisVal ! = 0.f ) {
usingGamepad = true ;
return axisVal ;
}
}
}
}
} break ;
case KEY :
@ -702,10 +711,10 @@ void InputGroup::DrawPrimaryInput(const std::variant<AiL*const,TileTransformedVi
switch ( type ) {
case CONTROLLER : {
if ( SteamInput ( ) ) {
STEAMINPUT (
primaryKey = GetPrimaryKey ( STEAM ) ;
type = STEAM ;
} else {
) else {
primaryKey = GetPrimaryKey ( CONTROLLER ) ;
}
} break ;
@ -879,6 +888,7 @@ const bool Input::HasExtendedIcons()const{
}
const Renderable & Input : : GetIcon ( ) const {
if ( type = = STEAM ) {
# ifndef __EMSCRIPTEN__
EInputActionOrigin action = Input : : steamGameInputToOrigin . at ( Steam : : SteamInput ( key ) ) . second [ 0 ] ;
EInputActionOrigin analogAction = Input : : steamGameInputToAnalogOrigin . at ( Steam : : SteamInput ( key ) ) . second [ 0 ] ;
if ( Input : : steamGameInputToOrigin . count ( Steam : : SteamInput ( key ) ) & &
@ -897,6 +907,7 @@ const Renderable&Input::GetIcon()const{
return GFX . at ( SteamInput ( ) - > GetGlyphPNGForActionOrigin ( analogAction , k_ESteamInputGlyphSize_Small , 0 ) ) ;
}
}
# endif
}
return GFX . at ( GenericKey : : keyLiteral . at ( { type , key } ) . iconName ) ;
}
@ -1060,14 +1071,14 @@ const bool Input::UsingGamepad(){
const bool Input : : AxesActive ( ) {
float xAxis = 0.f , yAxis = 0.f ;
if ( SteamInput ( ) ) {
STEAMINPUT (
if ( fabs ( game - > KEY_SCROLLHORZ_R . Analog ( ) ) > 0.f ) {
return true ;
}
if ( fabs ( game - > KEY_SCROLLVERT_R . Analog ( ) ) > 0.f ) {
return true ;
}
} else {
) else {
for ( GamePad * gamepad : GamePad : : getGamepads ( ) ) {
if ( gamepad - > stillConnected ) {
if ( fabs ( gamepad - > getAxis ( GPAxes : : RX ) ) > 0.f ) {
@ -1085,9 +1096,9 @@ const bool Input::AxesActive(){
void Input : : StartVibration ( const bool override ) {
if ( ! GameSettings : : RumbleEnabled ( override ) ) return ;
if ( UsingGamepad ( ) ) {
if ( SteamInput ( ) ) {
STEAMINPUT (
SteamInput ( ) - > TriggerVibration ( steamControllers [ activeSteamControllerIndex ] , std : : numeric_limits < unsigned short > : : max ( ) , std : : numeric_limits < unsigned short > : : max ( ) ) ;
} else {
) else {
for ( GamePad * gamepad : GamePad : : getGamepads ( ) ) {
if ( gamepad - > stillConnected ) {
gamepad - > startVibration ( ) ;
@ -1097,11 +1108,11 @@ void Input::StartVibration(const bool override){
}
}
void Input : : StopVibration ( ) {
if ( SteamInput ( ) ) {
STEAMINPUT (
for ( int i = 0 ; i < controllerCount ; i + + ) {
SteamInput ( ) - > TriggerVibration ( steamControllers [ i ] , 0U , 0U ) ;
}
} else {
) else {
for ( GamePad * gamepad : GamePad : : getGamepads ( ) ) {
if ( gamepad - > stillConnected ) {
gamepad - > stopVibration ( ) ;
@ -1224,9 +1235,9 @@ const bool InputEngageGroup::GetLabelVisible()const{
}
void Input : : SetLightbar ( const Pixel col ) {
if ( SteamInput ( ) ) {
STEAMINPUT (
for ( int i = 0 ; i < controllerCount ; i + + ) {
SteamInput ( ) - > SetLEDColor ( steamControllers [ i ] , col . r , col . g , col . b , 0 ) ;
}
}
)
}