From a206cb10eb92acbed58bd4d71e87da39e292ba8d Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Sat, 20 Jan 2024 15:20:26 -0600 Subject: [PATCH] Added small background to input display. Added safeguard to prevent mouse inputs from occurring in keyboard navigation rules. --- Adventures in Lestoria/InputHelper.cpp | 26 ++++++++----- Adventures in Lestoria/Menu.cpp | 53 +++++++++++++------------- Adventures in Lestoria/Version.h | 2 +- 3 files changed, 45 insertions(+), 36 deletions(-) diff --git a/Adventures in Lestoria/InputHelper.cpp b/Adventures in Lestoria/InputHelper.cpp index 60a1bdcc..200038c0 100644 --- a/Adventures in Lestoria/InputHelper.cpp +++ b/Adventures in Lestoria/InputHelper.cpp @@ -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(button)){ Decal*img=std::get(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(button)){ std::string label=std::get(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++; } diff --git a/Adventures in Lestoria/Menu.cpp b/Adventures in Lestoria/Menu.cpp index 87b7dba2..b6d1b3f2 100644 --- a/Adventures in Lestoria/Menu.cpp +++ b/Adventures in Lestoria/Menu.cpp @@ -300,32 +300,33 @@ void Menu::OpenMenu(MenuType menu,bool cover){ void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){ std::weak_ptrprevSelection=selection; - for(auto&[input,data]:inputGroups){ - bool activated=false; - switch(input.GetEngageType()){ - case Released:{ - activated=input.GetGroup().Released(); - }break; - case Pressed:{ - activated=input.GetGroup().Pressed(); - }break; - case Held:{ - activated=input.GetGroup().Held(); - }break; - case Analog:{ - activated=input.GetGroup().Analog()!=0.f; - }break; - [[unlikely]]default:ERR(std::format("WARNING! Unhandled input engage type {}! THIS SHOULD NOT BE HAPPENING!",int(input.GetEngageType()))); - } + if(!Menu::UsingMouseNavigation()){ + for(auto&[input,data]:inputGroups){ + bool activated=false; + switch(input.GetEngageType()){ + case Released:{ + activated=input.GetGroup().Released(); + }break; + case Pressed:{ + activated=input.GetGroup().Pressed(); + }break; + case Held:{ + activated=input.GetGroup().Held(); + }break; + case Analog:{ + activated=input.GetGroup().Analog()!=0.f; + }break; + [[unlikely]]default:ERR(std::format("WARNING! Unhandled input engage type {}! THIS SHOULD NOT BE HAPPENING!",int(input.GetEngageType()))); + } - if(activated){ - SetMouseNavigation(false); - auto&action=data.second; - if(std::holds_alternative(action))Component(type,std::get(action))->Click(); - else - if(std::holds_alternative>(action))std::get>(action)(type); - else{ - ERR("WARNING! Navigation data has an unrecognized type or is empty! This should not be happening!") + if(activated){ + auto&action=data.second; + if(std::holds_alternative(action))Component(type,std::get(action))->Click(); + else + if(std::holds_alternative>(action))std::get>(action)(type); + else{ + ERR("WARNING! Navigation data has an unrecognized type or is empty! This should not be happening!") + } } } } @@ -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; } diff --git a/Adventures in Lestoria/Version.h b/Adventures in Lestoria/Version.h index 386297ab..56b61b81 100644 --- a/Adventures in Lestoria/Version.h +++ b/Adventures in Lestoria/Version.h @@ -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