@ -39,6 +39,7 @@ All rights reserved.
# include "DEFINES.h"
# include "AdventuresInLestoria.h"
# include "olcPGEX_Gamepad.h"
# include "Menu.h"
INCLUDE_game
INCLUDE_GFX
@ -240,6 +241,50 @@ std::string InputGroup::GetDisplayName(){
return combinationDisplay ;
}
void InputGroup : : DrawInput ( const vf2d pos , const std : : string_view displayText , const uint8_t alpha ) const {
std : : optional < Input > primaryKey ;
if ( Input : : UsingGamepad ( ) ) primaryKey = GetPrimaryKey ( CONTROLLER ) ;
else if ( Menu : : UsingMouseNavigation ( ) ) primaryKey = GetPrimaryKey ( MOUSE ) ;
else primaryKey = GetPrimaryKey ( KEY ) ;
vf2d buttonImgSize { } ;
std : : vector < std : : variant < Decal * , std : : string > > buttonImgs ;
if ( displayText . length ( ) > 0 & & primaryKey . has_value ( ) ) {
if ( primaryKey . value ( ) . HasIcon ( ) ) {
buttonImgSize + = primaryKey . value ( ) . GetIcon ( ) . Sprite ( ) - > Size ( ) + vf2d { " Interface.InputHelperSpacing " _F , " Interface.InputHelperSpacing " _F } ;
buttonImgs . push_back ( primaryKey . value ( ) . GetIcon ( ) . Decal ( ) ) ;
} else {
buttonImgSize + = game - > GetTextSizeProp ( primaryKey . value ( ) . GetDisplayName ( ) ) + vf2d { " Interface.InputHelperSpacing " _F , " Interface.InputHelperSpacing " _F } ;
buttonImgs . push_back ( primaryKey . value ( ) . GetDisplayName ( ) ) ;
}
}
vf2d descriptionTextSize = game - > GetTextSizeProp ( displayText ) ;
vf2d offset = - ( ( buttonImgSize + descriptionTextSize ) / 2.f ) ;
if ( buttonImgs . size ( ) ! = 1 ) ERR ( " WARNING! Did not have two elements when rendering input button group display! THIS SHOULD NOT BE HAPPENING! " )
for ( auto & button : buttonImgs ) {
if ( std : : holds_alternative < Decal * > ( button ) ) {
Decal * img = std : : get < Decal * > ( button ) ;
game - > view . DrawDecal ( pos + offset , img , { 1.f , 1.f } , { 255 , 255 , 255 , alpha } ) ;
offset . x + = img - > sprite - > width + " Interface.InputHelperSpacing " _I ;
} else
if ( std : : holds_alternative < std : : string > ( button ) ) {
std : : string label = std : : get < std : : string > ( button ) ;
vf2d textSize = game - > GetTextSizeProp ( label ) ;
Pixel buttonBackCol = " Interface.InputButtonBackCol " _Pixel ;
Pixel buttonTextCol = " Interface.InputButtonTextCol " _Pixel ;
buttonBackCol . a = alpha ;
buttonTextCol . a = alpha ;
game - > view . FillRectDecal ( pos + offset + vf2d { - 2.f , 0.f } , vf2d { textSize . x + 4 , textSize . y } , buttonBackCol ) ;
game - > view . FillRectDecal ( pos + offset + vf2d { - 1.f , - 1.f } , vf2d { textSize . x + 2 , textSize . y } , buttonBackCol ) ;
game - > view . FillRectDecal ( pos + offset + vf2d { - 1.f , 0.f } , vf2d { textSize . x + 2 , textSize . y + 1.f } , buttonBackCol ) ;
game - > view . DrawStringPropDecal ( pos + offset + vf2d { 0.f , 0.f } , label , buttonTextCol ) ;
offset . x + = textSize . x + " Interface.InputHelperSpacing " _I ;
} else [[unlikely]] ERR ( " WARNING! Hit a state where no data is inside of the button! THIS SHOULD NOT BE HAPPENING! " ) ;
game - > view . DrawShadowStringPropDecal ( pos + offset , displayText , { 255 , 255 , 255 , alpha } , { 0 , 0 , 0 , alpha } ) ;
}
}
const bool Input : : HasIcon ( ) const {
return GenericKey : : keyLiteral . at ( { type , key } ) . iconName . length ( ) > 0 ;
}
@ -247,6 +292,8 @@ const Renderable&Input::GetIcon()const{
return GFX . at ( GenericKey : : keyLiteral . at ( { type , key } ) . iconName ) ;
}
# undef END
std : : map < std : : pair < InputType , int > , GenericKey : : KeyInfo > GenericKey : : keyLiteral = {
{ { KEY , NONE } , { " " } } ,
{ { KEY , A } , { " A " } } ,