@ -47,17 +47,17 @@ INCLUDE_GFX
bool Input : : usingGamepad ;
bool Input : : usingGamepad ;
uint64_t Input : : ingameControlsHandle { 0 } ;
uint64_t Input : : ingameControlsHandle { 0 } ;
uint64_t Input : : menuControlsHandle { 0 } ;
uint8_t activeSteamControllerIndex { 0 } ;
uint8_t activeSteamControllerIndex { 0 } ;
safemap < std : : string , InputGroup * > InputGroup : : menuNamesToInputGroups ;
safemap < std : : string , InputGroup * > InputGroup : : menuNamesToInputGroups ;
std : : vector < std : : string > InputGroup : : menuInputGroups ;
std : : vector < std : : string > InputGroup : : menuInputGroups ;
std : : vector < std : : string > InputGroup : : gameplayInputGroups ;
std : : vector < std : : string > InputGroup : : gameplayInputGroups ;
std : : array < InputHandle_t , 16 > Input : : steamControllers ;
std : : array < InputHandle_t , STEAM_INPUT_MAX_COUNT > Input : : steamControllers ;
std : : unordered_map < Steam : : SteamInput , std : : pair < NumOfOrigins , std : : array < EInputActionOrigin , STEAM_INPUT_MAX_ORIGINS > > > Input : : steamGameInputToOrigin ;
uint8_t Input : : activeSteamControllerIndex ;
uint8_t Input : : activeSteamControllerIndex ;
uint8_t Input : : controllerCount { 0 } ;
uint8_t Input : : controllerCount { 0 } ;
std : : vector < Steam : : SteamInput > Input : : leftStickActionSets { Steam : : MOVE } ;
std : : vector < Steam : : SteamInput > Input : : leftStickActionSets { Steam : : MOVE } ;
std : : vector < Steam : : SteamInput > Input : : rightStickActionSets { Steam : : MANUAL_AIM , Steam : : SCROLL } ;
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 > > , 16 > Input : : enumToActionName ;
std : : unordered_map < EInputActionOrigin , std : : string > Input : : steamIconToGameIcon {
std : : unordered_map < EInputActionOrigin , std : : string > Input : : steamIconToGameIcon {
@ -144,9 +144,8 @@ Input::Input(InputType type,int key)
: type ( type ) , key ( key ) { }
: type ( type ) , key ( key ) { }
void Input : : Initialize ( ) {
void Input : : Initialize ( ) {
for ( int i = 0 ; i < 16 ; i + + ) {
for ( int i = 0 ; i < STEAM_INPUT_MAX_COUNT ; i + + ) {
enumToActionName [ i ] [ Steam : : MOVE ] = { " Move " , { } } ;
enumToActionName [ i ] [ Steam : : MOVE ] = { " Move " , { } } ;
enumToActionName [ i ] [ Steam : : MANUAL_AIM ] = { " Manual Aim " , { } } ;
enumToActionName [ i ] [ Steam : : BASIC_ATTACK ] = { " Basic_Attack " , { } } ;
enumToActionName [ i ] [ Steam : : BASIC_ATTACK ] = { " Basic_Attack " , { } } ;
enumToActionName [ i ] [ Steam : : DEFENSIVE ] = { " Defensive " , { } } ;
enumToActionName [ i ] [ Steam : : DEFENSIVE ] = { " Defensive " , { } } ;
enumToActionName [ i ] [ Steam : : MENU_PAUSE ] = { " Menu/Pause " , { } } ;
enumToActionName [ i ] [ Steam : : MENU_PAUSE ] = { " Menu/Pause " , { } } ;
@ -196,8 +195,6 @@ void Input::UpdateSteamInput(){
HWButton prevState = data . second ;
HWButton prevState = data . second ;
InputDigitalActionHandle_t inputHnd = SteamInput ( ) - > GetDigitalActionHandle ( data . first . c_str ( ) ) ;
InputDigitalActionHandle_t inputHnd = SteamInput ( ) - > GetDigitalActionHandle ( data . first . c_str ( ) ) ;
InputDigitalActionData_t buttonData = SteamInput ( ) - > GetDigitalActionData ( steamControllers [ i ] , inputHnd ) ;
InputDigitalActionData_t buttonData = SteamInput ( ) - > GetDigitalActionData ( steamControllers [ i ] , inputHnd ) ;
if ( ! buttonData . bActive ) continue ; //Ignore inputs that are not active.
if ( buttonData . bActive ) { std : : cout < < input < < " is active " < < std : : endl ; }
data . second . bPressed = data . second . bReleased = false ;
data . second . bPressed = data . second . bReleased = false ;
if ( ! data . second . bHeld & & buttonData . bState ) {
if ( ! data . second . bHeld & & buttonData . bState ) {
@ -211,6 +208,14 @@ void Input::UpdateSteamInput(){
data . second . bHeld = buttonData . bState ;
data . second . bHeld = buttonData . bState ;
}
}
}
}
if ( controllerCount > 0 ) { //Setup display icons for steam controllers.
for ( auto & [ input , data ] : enumToActionName [ activeSteamControllerIndex ] ) {
InputDigitalActionHandle_t inputHnd = SteamInput ( ) - > GetDigitalActionHandle ( data . first . c_str ( ) ) ;
InputDigitalActionData_t buttonData = SteamInput ( ) - > GetDigitalActionData ( steamControllers [ activeSteamControllerIndex ] , inputHnd ) ;
//Store the origins that steam knows about inside the gameplay input arrays provided. These are pairs where the first item is the number of origins for this input and the second item is the array itself.
steamGameInputToOrigin [ input ] . first = SteamInput ( ) - > GetDigitalActionOrigins ( steamControllers [ activeSteamControllerIndex ] , ingameControlsHandle , inputHnd , steamGameInputToOrigin [ input ] . second . data ( ) ) ;
}
}
}
}
}
}
@ -358,6 +363,7 @@ float Input::Analog(){
float axisVal = GetAnalogStickVal ( i , input , Axis : : X ) ;
float axisVal = GetAnalogStickVal ( i , input , Axis : : X ) ;
if ( axisVal ! = 0.f ) {
if ( axisVal ! = 0.f ) {
usingGamepad = true ;
usingGamepad = true ;
activeSteamControllerIndex = i ;
return axisVal ;
return axisVal ;
}
}
}
}
@ -367,6 +373,7 @@ float Input::Analog(){
float axisVal = GetAnalogStickVal ( i , input , Axis : : Y ) ;
float axisVal = GetAnalogStickVal ( i , input , Axis : : Y ) ;
if ( axisVal ! = 0.f ) {
if ( axisVal ! = 0.f ) {
usingGamepad = true ;
usingGamepad = true ;
activeSteamControllerIndex = i ;
return axisVal ;
return axisVal ;
}
}
}
}
@ -376,6 +383,7 @@ float Input::Analog(){
float axisVal = GetAnalogStickVal ( i , input , Axis : : X ) ;
float axisVal = GetAnalogStickVal ( i , input , Axis : : X ) ;
if ( axisVal ! = 0.f ) {
if ( axisVal ! = 0.f ) {
usingGamepad = true ;
usingGamepad = true ;
activeSteamControllerIndex = i ;
return axisVal ;
return axisVal ;
}
}
}
}
@ -385,6 +393,7 @@ float Input::Analog(){
float axisVal = GetAnalogStickVal ( i , input , Axis : : Y ) ;
float axisVal = GetAnalogStickVal ( i , input , Axis : : Y ) ;
if ( axisVal ! = 0.f ) {
if ( axisVal ! = 0.f ) {
usingGamepad = true ;
usingGamepad = true ;
activeSteamControllerIndex = i ;
return axisVal ;
return axisVal ;
}
}
}
}
@ -410,6 +419,10 @@ float Input::Analog(){
}
}
std : : string Input : : GetDisplayName ( ) const {
std : : string Input : : GetDisplayName ( ) const {
if ( type = = STEAM ) {
return std : : format ( " STEAM:{} " , key ) ;
}
if ( ! GenericKey : : keyLiteral . count ( { type , key } ) ) return " " ;
return GenericKey : : keyLiteral . at ( { type , key } ) . displayName ;
return GenericKey : : keyLiteral . at ( { type , key } ) . displayName ;
}
}
@ -652,7 +665,13 @@ void InputGroup::DrawInput(const std::variant<AiL*const,TileTransformedView*cons
void InputGroup : : DrawPrimaryInput ( const std : : variant < AiL * const , TileTransformedView * const , ViewPort * const > renderer , const vf2d pos , const std : : string_view displayText , const uint8_t alpha , InputType type , vf2d textScale ) const {
void InputGroup : : DrawPrimaryInput ( const std : : variant < AiL * const , TileTransformedView * const , ViewPort * const > renderer , const vf2d pos , const std : : string_view displayText , const uint8_t alpha , InputType type , vf2d textScale ) const {
std : : optional < Input > primaryKey ;
std : : optional < Input > primaryKey ;
switch ( type ) {
switch ( type ) {
case CONTROLLER : primaryKey = GetPrimaryKey ( CONTROLLER ) ; break ;
case CONTROLLER : {
if ( SteamInput ( ) ) {
primaryKey = GetPrimaryKey ( STEAM ) ;
} else {
primaryKey = GetPrimaryKey ( CONTROLLER ) ;
}
} break ;
case MOUSE : primaryKey = GetPrimaryKey ( MOUSE ) ; break ;
case MOUSE : primaryKey = GetPrimaryKey ( MOUSE ) ; break ;
default : primaryKey = GetPrimaryKey ( KEY ) ; break ;
default : primaryKey = GetPrimaryKey ( KEY ) ; break ;
}
}
@ -660,7 +679,7 @@ void InputGroup::DrawPrimaryInput(const std::variant<AiL*const,TileTransformedVi
vf2d buttonImgSize { } ;
vf2d buttonImgSize { } ;
std : : vector < std : : variant < Decal * , std : : string > > buttonImgs ;
std : : vector < std : : variant < Decal * , std : : string > > buttonImgs ;
if ( type ! = CONTROLLER & & type ! = MOUSE ) {
if ( type ! = STEAM & & type ! = CONTROLLER & & type ! = MOUSE ) {
for ( const Input & input : keyOrder ) {
for ( const Input & input : keyOrder ) {
if ( input . GetType ( ) = = MOUSE ) {
if ( input . GetType ( ) = = MOUSE ) {
if ( input . HasExtendedIcons ( ) ) {
if ( input . HasExtendedIcons ( ) ) {
@ -688,10 +707,15 @@ void InputGroup::DrawPrimaryInput(const std::variant<AiL*const,TileTransformedVi
buttonImgs . push_back ( primaryKey . value ( ) . GetIcon ( GameSettings : : GetIconType ( ) ) . Decal ( ) ) ;
buttonImgs . push_back ( primaryKey . value ( ) . GetIcon ( GameSettings : : GetIconType ( ) ) . Decal ( ) ) ;
} else
} else
if ( primaryKey . value ( ) . HasIcon ( ) ) {
if ( primaryKey . value ( ) . HasIcon ( ) ) {
buttonImgSize . x + = primaryKey . value ( ) . GetIcon ( ) . Sprite ( ) - > width * textScale . x + " Interface.InputHelperSpacing " _F ;
float alteredIconScale = 1.f ;
buttonImgSize . y = std : : max ( buttonImgSize . y , float ( primaryKey . value ( ) . GetIcon ( ) . Sprite ( ) - > height ) ) ;
if ( type = = STEAM ) alteredIconScale / = 2.85f ; //They are initially 32x32.
buttonImgSize . x + = primaryKey . value ( ) . GetIcon ( ) . Sprite ( ) - > width * alteredIconScale * textScale . x + " Interface.InputHelperSpacing " _F ;
buttonImgSize . y = std : : max ( buttonImgSize . y , float ( primaryKey . value ( ) . GetIcon ( ) . Sprite ( ) - > height * alteredIconScale ) ) ;
buttonImgs . push_back ( primaryKey . value ( ) . GetIcon ( ) . Decal ( ) ) ;
buttonImgs . push_back ( primaryKey . value ( ) . GetIcon ( ) . Decal ( ) ) ;
} else {
} else
{
buttonImgSize . x + = game - > GetTextSizeProp ( primaryKey . value ( ) . GetDisplayName ( ) ) . x * textScale . x + " Interface.InputHelperSpacing " _F ;
buttonImgSize . x + = game - > GetTextSizeProp ( primaryKey . value ( ) . GetDisplayName ( ) ) . x * textScale . x + " Interface.InputHelperSpacing " _F ;
buttonImgSize . y = std : : max ( buttonImgSize . y , float ( game - > GetTextSizeProp ( primaryKey . value ( ) . GetDisplayName ( ) ) . y ) + " Interface.InputHelperSpacing " _F ) ;
buttonImgSize . y = std : : max ( buttonImgSize . y , float ( game - > GetTextSizeProp ( primaryKey . value ( ) . GetDisplayName ( ) ) . y ) + " Interface.InputHelperSpacing " _F ) ;
buttonImgs . push_back ( primaryKey . value ( ) . GetDisplayName ( ) ) ;
buttonImgs . push_back ( primaryKey . value ( ) . GetDisplayName ( ) ) ;
@ -706,7 +730,10 @@ void InputGroup::DrawPrimaryInput(const std::variant<AiL*const,TileTransformedVi
# pragma region Render Macro
# pragma region Render Macro
# define Render(rendererType) \
# define Render(rendererType) \
std : : get < rendererType * const > ( renderer ) - > DrawDecal ( pos + offset - vf2d { 0.f , 2.f } , img , textScale , { 255 , 255 , 255 , alpha } ) ;
float alteredIconScale = 1.f ; \
\
if ( type = = STEAM ) alteredIconScale / = 2.85f ; /*They are initially 32x32.*/ \
std : : get < rendererType * const > ( renderer ) - > DrawDecal ( pos + offset - vf2d { 0.f , 2.f } , img , alteredIconScale * textScale , { 255 , 255 , 255 , alpha } ) ;
# pragma endregion
# pragma endregion
if ( std : : holds_alternative < AiL * const > ( renderer ) ) {
if ( std : : holds_alternative < AiL * const > ( renderer ) ) {
Render ( AiL ) ;
Render ( AiL ) ;
@ -775,12 +802,21 @@ void InputGroup::DrawPrimaryInput(const std::variant<AiL*const,TileTransformedVi
}
}
const bool Input : : HasIcon ( ) const {
const bool Input : : HasIcon ( ) const {
if ( type = = STEAM ) {
return Input : : steamGameInputToOrigin . count ( Steam : : SteamInput ( key ) ) & &
Input : : steamGameInputToOrigin . at ( Steam : : SteamInput ( key ) ) . first > 0 ;
}
return GenericKey : : keyLiteral . at ( { type , key } ) . iconName . length ( ) > 0 ;
return GenericKey : : keyLiteral . at ( { type , key } ) . iconName . length ( ) > 0 ;
}
}
const bool Input : : HasExtendedIcons ( ) const {
const bool Input : : HasExtendedIcons ( ) const {
if ( type = = STEAM ) return false ;
return GenericKey : : keyLiteral . at ( { type , key } ) . iconName . length ( ) > 0 & & GenericKey : : keyLiteral . at ( { type , key } ) . iconName2 . length ( ) > 0 & & GenericKey : : keyLiteral . at ( { type , key } ) . iconName3 . length ( ) > 0 ;
return GenericKey : : keyLiteral . at ( { type , key } ) . iconName . length ( ) > 0 & & GenericKey : : keyLiteral . at ( { type , key } ) . iconName2 . length ( ) > 0 & & GenericKey : : keyLiteral . at ( { type , key } ) . iconName3 . length ( ) > 0 ;
}
}
const Renderable & Input : : GetIcon ( ) const {
const Renderable & Input : : GetIcon ( ) const {
if ( type = = STEAM ) {
EInputActionOrigin action = Input : : steamGameInputToOrigin . at ( Steam : : SteamInput ( key ) ) . second [ 0 ] ;
return GFX . at ( SteamInput ( ) - > GetGlyphPNGForActionOrigin ( action , k_ESteamInputGlyphSize_Small , 0 ) ) ;
}
return GFX . at ( GenericKey : : keyLiteral . at ( { type , key } ) . iconName ) ;
return GFX . at ( GenericKey : : keyLiteral . at ( { type , key } ) . iconName ) ;
}
}
const Renderable & Input : : GetIcon ( IconType type ) const {
const Renderable & Input : : GetIcon ( IconType type ) const {