Added small background to input display. Added safeguard to prevent mouse inputs from occurring in keyboard navigation rules.

pull/35/head
sigonasr2 10 months ago
parent 4eec0ce337
commit a206cb10eb
  1. 26
      Adventures in Lestoria/InputHelper.cpp
  2. 5
      Adventures in Lestoria/Menu.cpp
  3. 2
      Adventures in Lestoria/Version.h

@ -75,6 +75,7 @@ void InputHelper::Draw(){
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());
}
@ -87,32 +88,39 @@ void InputHelper::Draw(){
float buttonDescriptionScaleX=1.0f;
if(buttonImgWidth+buttonDescriptionWidth>WINDOW_SIZE.x){
buttonDescriptionScaleX=(WINDOW_SIZE.x-buttonImgWidth)/(buttonDescriptionWidth+buttonImgWidth);
if(buttonImgWidth+buttonDescriptionWidth>WINDOW_SIZE.x-"Interface.InputHelperSpacing"_I){
buttonDescriptionScaleX=(WINDOW_SIZE.x-buttonImgWidth-"Interface.InputHelperSpacing"_I)/(buttonDescriptionWidth);
}
#pragma region Underlying box
if(buttonDescriptions.size()>0){
game->GradientFillRectDecal(vf2d{0.f,WINDOW_SIZE.y-16.f},vf2d{float(WINDOW_SIZE.x),16.f},
{0,0,0,64},{0,0,0,255},{0,0,0,255},{0,0,0,64});
}
#pragma endregion
#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)-8},img);
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-10)},vf2d{textSize.x+4,textSize.y},"Interface.InputButtonBackCol"_Pixel);
game->FillRectDecal(vf2d{xOffset-1,float(WINDOW_SIZE.y-textSize.y-10)-1.f},vf2d{textSize.x+2,textSize.y},"Interface.InputButtonBackCol"_Pixel);
game->FillRectDecal(vf2d{xOffset-1,float(WINDOW_SIZE.y-textSize.y-10)},vf2d{textSize.x+2,textSize.y+1.f},"Interface.InputButtonBackCol"_Pixel);
game->DrawStringPropDecal(vf2d{xOffset,float(WINDOW_SIZE.y-textSize.y-10)},label,"Interface.InputButtonTextCol"_Pixel);
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-10)},description,WHITE,BLACK,vf2d{buttonDescriptionScaleX,1.f});
xOffset+=descriptionTextSize.x+"Interface.InputHelperSpacing"_I;
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++;
}

@ -300,6 +300,7 @@ void Menu::OpenMenu(MenuType menu,bool cover){
void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){
std::weak_ptr<MenuComponent>prevSelection=selection;
if(!Menu::UsingMouseNavigation()){
for(auto&[input,data]:inputGroups){
bool activated=false;
switch(input.GetEngageType()){
@ -319,7 +320,6 @@ void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){
}
if(activated){
SetMouseNavigation(false);
auto&action=data.second;
if(std::holds_alternative<ButtonName>(action))Component<MenuComponent>(type,std::get<ButtonName>(action))->Click();
else
@ -329,6 +329,7 @@ void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){
}
}
}
}
if(!selection.expired()){
std::string selectionButtonName=selection.lock()->GetName();
@ -384,7 +385,7 @@ void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){
if(game->KEY_UP.Released()||game->KEY_RIGHT.Released()||game->KEY_LEFT.Released()||game->KEY_DOWN.Released()||
game->KEY_BACK.Released()||game->KEY_CONFIRM.Released()||game->KEY_START.Released()||game->KEY_SELECT.Released()||
game->KEY_SCROLLDOWN.Released()||game->KEY_SCROLLUP.Released()){
game->KEY_SCROLLDOWN.Released()||game->KEY_SCROLLUP.Released()||game->KEY_SCROLL.Analog()!=0.f){
SetMouseNavigation(game->GetMouse(Mouse::LEFT).bReleased||game->GetMouse(Mouse::RIGHT).bReleased||game->GetMouse(Mouse::MIDDLE).bReleased); //If a click occurs we use mouse controls.
buttonHoldTime=0;
}

@ -39,7 +39,7 @@ All rights reserved.
#define VERSION_MAJOR 0
#define VERSION_MINOR 3
#define VERSION_PATCH 0
#define VERSION_BUILD 6177
#define VERSION_BUILD 6190
#define stringify(a) stringify_(a)
#define stringify_(a) #a

Loading…
Cancel
Save