@ -50,6 +50,12 @@ void InputHelper::Initialize(MenuInputGroups&inputGroups){
this - > inputGroups . clear ( ) ;
for ( auto & data : inputGroups ) {
if ( data . first . GetLabelVisible ( ) ) { //If the label is not visible, we don't care to include it in our list.
if ( std : : holds_alternative < ButtonName > ( data . second . first ) ) {
const ButtonName & name = std : : get < ButtonName > ( data . second . first ) ;
groupedInputs [ name ] . push_back ( data . first . GetGroup ( ) ) ;
if ( groupedInputs [ name ] . size ( ) > 1 ) continue ; //Skip adding to the list of input groups because this input already has been added.
}
this - > inputGroups [ data . first . GetGroup ( ) ] = data . second . first ;
}
}
@ -69,11 +75,18 @@ void InputHelper::Draw(){
case KEY : {
float buttonImgWidth = 0.f ;
float buttonDescriptionWidth = 0.f ;
std : : vector < std : : variant < Decal * , std : : string > > buttonImgs ; //Store decals for buttons that actually have images, and strings for buttons that have labels.
std : : vector < std : : vector < std : : v ariant < Decal * , std : : string > > > buttonImgs ; //Store decals for buttons that actually have images, and strings for buttons that have labels. One button can have multiple icons. Store them all together .
std : : vector < std : : string > buttonDescriptions ;
# pragma region Populate all buttons to display
for ( auto & [ group , display ] : inputGroups ) {
auto & primaryKey = group . GetPrimaryKey ( mode ) ;
size_t groupedInputCount = 1 ;
std : : vector < InputGroup > inputGroupsToCheck ;
if ( std : : holds_alternative < std : : string > ( display ) & & groupedInputs . count ( std : : get < std : : string > ( display ) ) ) {
inputGroupsToCheck = groupedInputs . at ( std : : get < std : : string > ( display ) ) ;
} else {
inputGroupsToCheck . push_back ( group ) ;
}
std : : string displayName ;
@ -87,20 +100,27 @@ void InputHelper::Draw(){
displayName = std : : get < std : : function < std : : string ( MenuFuncData ) > > ( display ) ( MenuFuncData { * Menu : : stack . back ( ) , game , Menu : : stack . back ( ) - > GetSelection ( ) , parentComponent } ) ;
}
else ERR ( " WARNING! display contains a variant alternative that does not exist. THIS SHOULD NOT BE HAPPENING! " ) ;
if ( displayName . length ( ) > 0 & & primaryKey . has_value ( ) ) {
if ( primaryKey . value ( ) . HasIcon ( ) ) {
buttonImgWidth + = primaryKey . value ( ) . GetIcon ( ) . Sprite ( ) - > width + " Interface.InputHelperSpacing " _I ;
buttonImgs . push_back ( primaryKey . value ( ) . GetIcon ( ) . Decal ( ) ) ;
} else {
buttonImgWidth + = game - > GetTextSizeProp ( primaryKey . value ( ) . GetDisplayName ( ) ) . x + " Interface.InputHelperSpacing " _I ;
buttonImgs . push_back ( primaryKey . value ( ) . GetDisplayName ( ) ) ;
buttonImgs . push_back ( { } ) ;
std : : vector < std : : variant < Decal * , std : : string > > & iconList = buttonImgs . back ( ) ;
for ( InputGroup & group : inputGroupsToCheck ) {
auto & primaryKey = group . GetPrimaryKey ( mode ) ;
if ( displayName . length ( ) > 0 & & primaryKey . has_value ( ) ) {
if ( primaryKey . value ( ) . HasIcon ( ) ) {
buttonImgWidth + = primaryKey . value ( ) . GetIcon ( ) . Sprite ( ) - > width + " Interface.InputHelperSpacing " _I ;
iconList . push_back ( primaryKey . value ( ) . GetIcon ( ) . Decal ( ) ) ;
} else {
buttonImgWidth + = game - > GetTextSizeProp ( primaryKey . value ( ) . GetDisplayName ( ) ) . x + " Interface.InputHelperSpacing " _I ;
iconList . push_back ( primaryKey . value ( ) . GetDisplayName ( ) ) ;
}
}
vf2d descriptionSize = game - > GetTextSizeProp ( displayName ) ;
buttonDescriptionWidth + = descriptionSize . x + " Interface.InputHelperSpacing " _I ;
buttonDescriptions . push_back ( displayName ) ;
}
vf2d descriptionSize = game - > GetTextSizeProp ( displayName ) ;
buttonDescriptionWidth + = descriptionSize . x + " Interface.InputHelperSpacing " _I ;
buttonDescriptions . push_back ( displayName ) ;
}
# pragma endregion
@ -119,27 +139,28 @@ void InputHelper::Draw(){
# pragma region Draw all button inputs and descriptions
float xOffset = " Interface.InputHelperSpacing " _I ;
for ( size_t index = 0 ; auto & button : buttonImgs ) {
if ( std : : holds_alternative < Decal * > ( button ) ) {
Decal * img = std : : get < Decal * > ( button ) ;
game - > DrawDecal ( vf2d { xOffset , float ( WINDOW_SIZE . y - img - > sprite - > height ) - 4 } , img ) ;
xOffset + = 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 ) ;
game - > FillRectDecal ( vf2d { xOffset - 2 , float ( WINDOW_SIZE . y - textSize . y - 6 ) } , vf2d { textSize . x + 4 , textSize . y } , " Interface.InputButtonBackCol " _Pixel ) ;
game - > FillRectDecal ( vf2d { xOffset - 1 , float ( WINDOW_SIZE . y - textSize . y - 6 ) - 1.f } , vf2d { textSize . x + 2 , textSize . y } , " Interface.InputButtonBackCol " _Pixel ) ;
game - > FillRectDecal ( vf2d { xOffset - 1 , float ( WINDOW_SIZE . y - textSize . y - 6 ) } , vf2d { textSize . x + 2 , textSize . y + 1.f } , " Interface.InputButtonBackCol " _Pixel ) ;
game - > DrawStringPropDecal ( vf2d { xOffset , float ( WINDOW_SIZE . y - textSize . y - 6 ) } , label , " Interface.InputButtonTextCol " _Pixel ) ;
xOffset + = 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! " ) ;
for ( size_t index = 0 ; auto & buttonList : buttonImgs ) {
for ( std : : variant < Decal * , std : : string > button : buttonList ) {
if ( std : : holds_alternative < Decal * > ( button ) ) {
Decal * img = std : : get < Decal * > ( button ) ;
game - > DrawDecal ( vf2d { xOffset , float ( WINDOW_SIZE . y - img - > sprite - > height ) - 4 } , img ) ;
xOffset + = 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 ) ;
game - > FillRectDecal ( vf2d { xOffset - 2 , float ( WINDOW_SIZE . y - textSize . y - 6 ) } , vf2d { textSize . x + 4 , textSize . y } , " Interface.InputButtonBackCol " _Pixel ) ;
game - > FillRectDecal ( vf2d { xOffset - 1 , float ( WINDOW_SIZE . y - textSize . y - 6 ) - 1.f } , vf2d { textSize . x + 2 , textSize . y } , " Interface.InputButtonBackCol " _Pixel ) ;
game - > FillRectDecal ( vf2d { xOffset - 1 , float ( WINDOW_SIZE . y - textSize . y - 6 ) } , vf2d { textSize . x + 2 , textSize . y + 1.f } , " Interface.InputButtonBackCol " _Pixel ) ;
game - > DrawStringPropDecal ( vf2d { xOffset , float ( WINDOW_SIZE . y - textSize . y - 6 ) } , label , " Interface.InputButtonTextCol " _Pixel ) ;
xOffset + = 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! " ) ;
}
std : : string_view description = buttonDescriptions [ index ] ;
vf2d descriptionTextSize = game - > GetTextSizeProp ( description ) * vf2d { buttonDescriptionScaleX , 1.f } ;
game - > DrawShadowStringPropDecal ( vf2d { xOffset , float ( WINDOW_SIZE . y - descriptionTextSize . y - 6 ) } , description , WHITE , BLACK , vf2d { buttonDescriptionScaleX , 1.f } ) ;
xOffset + = descriptionTextSize . x + " Interface.InputHelperSpacing " _I * buttonDescriptionScaleX ;
index + + ;
}
# pragma endregion