Implemented overworld gamepad control functions. Added ability to have certain inputer helper labels to be hidden away. When click functions are called on MenuComponents, it should also apply the menu navigation rules of the button.

pull/35/head
sigonasr2 10 months ago
parent 7cd3600f42
commit 4eec0ce337
  1. 6
      Adventures in Lestoria/AdventuresInLestoria.cpp
  2. 1
      Adventures in Lestoria/AdventuresInLestoria.h
  3. 4
      Adventures in Lestoria/InputHelper.cpp
  4. 124
      Adventures in Lestoria/LoadGameWindow.cpp
  5. 2
      Adventures in Lestoria/Menu.cpp
  6. 12
      Adventures in Lestoria/MenuComponent.cpp
  7. 25
      Adventures in Lestoria/OverworldMapLevelWindow.cpp
  8. 4
      Adventures in Lestoria/ScrollableWindowComponent.h
  9. 11
      Adventures in Lestoria/State_OverworldMap.cpp
  10. 2
      Adventures in Lestoria/Version.h

@ -105,6 +105,7 @@ InputGroup AiL::KEY_START;
InputGroup AiL::KEY_SELECT;
InputGroup AiL::KEY_SCROLL;
InputGroup AiL::KEY_CHANGE_LOADOUT;
#ifndef __EMSCRIPTEN__
::discord::Core*Discord{};
@ -2381,7 +2382,7 @@ void AiL::InitializeDefaultKeybinds(){
KEY_DOWN.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::DPAD_D)});
KEY_CONFIRM.AddKeybind({MOUSE,Mouse::LEFT});
KEY_CONFIRM.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::FACE_R)});
KEY_CONFIRM.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::START)});
//KEY_CONFIRM.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::START)});
KEY_CONFIRM.AddKeybind({KEY,Z});
KEY_CONFIRM.AddKeybind({KEY,SPACE});
KEY_CONFIRM.AddKeybind({KEY,ENTER});
@ -2403,6 +2404,9 @@ void AiL::InitializeDefaultKeybinds(){
KEY_SCROLLDOWN.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::R1)});
KEY_SCROLLDOWN.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::R2)});
KEY_CHANGE_LOADOUT.AddKeybind({KEY,X});
KEY_CHANGE_LOADOUT.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::FACE_U)});
KEY_START.AddKeybind({KEY,RETURN});
KEY_START.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::START)});
KEY_SELECT.AddKeybind({KEY,ESCAPE});

@ -88,6 +88,7 @@ public:
static InputGroup KEY_SELECT;
static InputGroup KEY_SCROLL;
static InputGroup KEY_CHANGE_LOADOUT;
static float SIZE_CHANGE_SPEED;
double levelTime;

@ -70,7 +70,7 @@ void InputHelper::Draw(){
#pragma region Populate all buttons to display
for(auto&[group,displayName]:inputGroups){
auto&primaryKey=group.GetPrimaryKey(mode);
if(primaryKey.has_value()){
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());
@ -88,7 +88,7 @@ void InputHelper::Draw(){
float buttonDescriptionScaleX=1.0f;
if(buttonImgWidth+buttonDescriptionWidth>WINDOW_SIZE.x){
buttonDescriptionScaleX=(WINDOW_SIZE.x-buttonImgWidth)/buttonDescriptionWidth;
buttonDescriptionScaleX=(WINDOW_SIZE.x-buttonImgWidth)/(buttonDescriptionWidth+buttonImgWidth);
}
#pragma region Draw all button inputs and descriptions

@ -52,72 +52,72 @@ void Menu::InitializeLoadGameWindow(){
#define ScrollWindow(amount) \
[](MenuType type){ \
auto scrollWindow=Component<ScrollableWindowComponent>(type,"Game Files List"); \
float scrollAmt=amount*game->GetElapsedTime()*"Interface.AnalogScrollSpeed"_F; \
\
scrollWindow->SetScrollAmount(scrollWindow->GetTargetScrollAmount()-vf2d{0,amount*game->GetElapsedTime()*"Interface.AnalogScrollSpeed"_F}); \
\
scrollWindow->Scroll(amount); \
float scrollAmt=amount*game->GetElapsedTime()*"Interface.AnalogScrollSpeed"_F;\
/*Height of these buttons is 48.*/ \
scrollWindow->IncreaseSelectionIndex(scrollAmt/48.f); \
}
#pragma endregion
loadGameWindow->SetupKeyboardNavigation(
[](MenuType type,Data&returnData){ //On Open
if(SaveFile::GetSaveFileCount()>0){
returnData=Component<ScrollableWindowComponent>(type,"Game Files List")->GetComponents()[0];
}else{
returnData="Go Back Button";
#pragma region Keyboard Navigation Rules
loadGameWindow->SetupKeyboardNavigation(
[](MenuType type,Data&returnData){ //On Open
if(SaveFile::GetSaveFileCount()>0){
returnData=Component<ScrollableWindowComponent>(type,"Game Files List")->GetComponents()[0];
}else{
returnData="Go Back Button";
}
},
{ //Button Key
{{game->KEY_BACK},{"Back to Title Screen",[](MenuType type){
Component<MenuComponent>(type,"Go Back Button")->Click();
}}},
{{game->KEY_SCROLL,Analog},{"Scroll",ScrollWindow(game->KEY_SCROLL.Analog())}},
{{game->KEY_SCROLLUP,Held},{"Scroll Up",ScrollWindow(-1.0f)}},
{{game->KEY_SCROLLDOWN,Held},{"Scroll Down",ScrollWindow(1.0f)}},
}
},
{ //Button Key
{{game->KEY_BACK},{"Back to Title Screen",[](MenuType type){
Component<MenuComponent>(type,"Go Back Button")->Click();
}}},
{{game->KEY_SCROLL,Analog},{"Scroll",ScrollWindow(game->KEY_SCROLL.Analog())}},
{{game->KEY_SCROLLUP,Held},{"Scroll Up",ScrollWindow(-1.0f)}},
{{game->KEY_SCROLLDOWN,Held},{"Scroll Down",ScrollWindow(1.0f)}},
}
,{ //Button Navigation Rules
{"Game Files List",{
.up=[](MenuType type,Data&returnData){
auto&selection=Menu::menus[type]->GetSelection();
auto&gameFilesList=Component<ScrollableWindowComponent>(type,"Game Files List")->GetComponents();
auto component=std::find_if(gameFilesList.begin(),gameFilesList.end(),[&](auto&comp){return comp.lock()==selection.lock();});
if(component==gameFilesList.begin()){
returnData="Go Back Button";
}else{
returnData=*(--component);
}
},
.down=[](MenuType type,Data&returnData){
auto&selection=Menu::menus[type]->GetSelection();
auto&gameFilesList=Component<ScrollableWindowComponent>(type,"Game Files List")->GetComponents();
auto component=std::find_if(gameFilesList.begin(),gameFilesList.end(),[&](auto&comp){return comp.lock()==selection.lock();});
if(component==gameFilesList.end()-1){
returnData="Go Back Button";
}else{
returnData=*(++component);
}
},}},
{"Go Back Button",{
.up=[](MenuType type,Data&returnData){
auto&selection=Menu::menus[type]->GetSelection();
auto&gameFilesList=Component<ScrollableWindowComponent>(type,"Game Files List")->GetComponents();
if(gameFilesList.size()==0){
returnData="Go Back Button";
return;
}
returnData=*(gameFilesList.end()-1);
},
.down=[](MenuType type,Data&returnData){
auto&selection=Menu::menus[type]->GetSelection();
auto&gameFilesList=Component<ScrollableWindowComponent>(type,"Game Files List")->GetComponents();
if(gameFilesList.size()==0){
returnData="Go Back Button";
return;
}
returnData=*(gameFilesList.begin());
},
}},
});
,{ //Button Navigation Rules
{"Game Files List",{
.up=[](MenuType type,Data&returnData){
auto&selection=Menu::menus[type]->GetSelection();
auto&gameFilesList=Component<ScrollableWindowComponent>(type,"Game Files List")->GetComponents();
auto component=std::find_if(gameFilesList.begin(),gameFilesList.end(),[&](auto&comp){return comp.lock()==selection.lock();});
if(component==gameFilesList.begin()){
returnData="Go Back Button";
}else{
returnData=*(--component);
}
},
.down=[](MenuType type,Data&returnData){
auto&selection=Menu::menus[type]->GetSelection();
auto&gameFilesList=Component<ScrollableWindowComponent>(type,"Game Files List")->GetComponents();
auto component=std::find_if(gameFilesList.begin(),gameFilesList.end(),[&](auto&comp){return comp.lock()==selection.lock();});
if(component==gameFilesList.end()-1){
returnData="Go Back Button";
}else{
returnData=*(++component);
}
},}},
{"Go Back Button",{
.up=[](MenuType type,Data&returnData){
auto&selection=Menu::menus[type]->GetSelection();
auto&gameFilesList=Component<ScrollableWindowComponent>(type,"Game Files List")->GetComponents();
if(gameFilesList.size()==0){
returnData="Go Back Button";
return;
}
returnData=*(gameFilesList.end()-1);
},
.down=[](MenuType type,Data&returnData){
auto&selection=Menu::menus[type]->GetSelection();
auto&gameFilesList=Component<ScrollableWindowComponent>(type,"Game Files List")->GetComponents();
if(gameFilesList.size()==0){
returnData="Go Back Button";
return;
}
returnData=*(gameFilesList.begin());
},
}},
});
#pragma endregion
}

@ -292,7 +292,7 @@ void Menu::OpenMenu(MenuType menu,bool cover){
if(menus[menu]->onOpenFunc){
Data returnData;
menus[menu]->onOpenFunc(menu,returnData);
menus[menu]->SetSelection(returnData,true);
if(std::holds_alternative<ButtonName>(returnData)&&std::get<ButtonName>(returnData).length()>0||std::holds_alternative<std::weak_ptr<MenuComponent>>(returnData))menus[menu]->SetSelection(returnData,true);
}
stack.push_back(menus[menu]);
}

@ -246,5 +246,15 @@ void MenuComponent::OnPlayerMoneyUpdate(uint32_t newMoney){}
void MenuComponent::OnChapterUpdate(uint8_t newChapter){}
void MenuComponent::Click(){
onClick(MenuFuncData{*Menu::menus[parentMenu],game,Menu::menus[parentMenu]->components[name]});
bool buttonStillValid=onClick(MenuFuncData{*Menu::menus[parentMenu],game,Menu::menus[parentMenu]->components[name]});
if(buttonStillValid){
if(menuDest!=MenuType::ENUM_END){
if(Menu::stack.size()<32){
Menu::stack.push_back(Menu::menus[menuDest]);//Navigate to the next menu.
}else{
ERR("WARNING! Exceeded menu stack size limit!")
}
}
}
}

@ -62,4 +62,29 @@ void Menu::InitializeOverworldMapLevelWindow(){
levelSelectWindow->ADD("Change Loadout Button",MenuComponent)(geom2d::rect<float>{{0,152},{windowSize.x-1,12}},"Change Loadout",ITEM_LOADOUT,[](MenuFuncData data){return true;})END;
levelSelectWindow->ADD("Enter Button",MenuComponent)(geom2d::rect<float>{{0,166},{windowSize.x-1,16}},"Enter",[](MenuFuncData data){State_OverworldMap::StartLevel();return true;})END;
#pragma region Keyboard Navigation Rules
levelSelectWindow->SetupKeyboardNavigation(
[](MenuType type,Data&returnData){ /*On Open*/},
{ //Button Key
{{game->KEY_MENU},{"Game Menu",[](MenuType type){}}},
{{game->KEY_CONFIRM},{"Start Stage",[](MenuType type){
Component<MenuComponent>(type,"Enter Button")->Click();
}}},
{{game->KEY_CHANGE_LOADOUT},{"Change Loadout",[](MenuType type){
Component<MenuComponent>(type,"Change Loadout Button")->Click();
}}},
{{game->KEY_SCROLL,Analog},{"Scroll Encounters",[](MenuType type){
Component<EncountersSpawnListScrollableWindowComponent>(type,"Spawns List")->Scroll(game->KEY_SCROLL.Analog());
}}},
{{game->KEY_SCROLLUP,Held},{"",[](MenuType type){
Component<EncountersSpawnListScrollableWindowComponent>(type,"Spawns List")->Scroll(1.f);
}}},
{{game->KEY_SCROLLDOWN,Held},{"",[](MenuType type){
Component<EncountersSpawnListScrollableWindowComponent>(type,"Spawns List")->Scroll(-1.f);
}}},
}
,{ //Button Navigation Rules
});
#pragma endregion
}

@ -92,6 +92,10 @@ public:
virtual inline void SetScrollAmount(vf2d scrollOffset){
this->targetScrollOffset=scrollOffset;
}
//Provide an amount to scroll by in units/sec.
virtual inline void Scroll(float amt){
SetScrollAmount(GetTargetScrollAmount()-vf2d{0,amt*game->GetElapsedTime()*"Interface.AnalogScrollSpeed"_F});
}
//Use this when you need to add more scrolling offset to a previous amount as GetScrollAmount() is used to get the internal scroll offset specifically.
virtual inline vf2d GetTargetScrollAmount()const{
return targetScrollOffset;

@ -95,17 +95,6 @@ void State_OverworldMap::OnUserUpdate(AiL*game){
Menu::OpenMenu(OVERWORLD_MENU);
}
if(game->GetKey(S).bPressed){
Menu::OpenMenu(MERCHANT);
}
if(game->GetKey(B).bPressed){
Menu::OpenMenu(BLACKSMITH);
}
if(game->GetKey(C).bPressed){
Menu::OpenMenu(CRAFT_CONSUMABLE);
}
#pragma region Audio Test
if(game->GetKey(K1).bPressed){
Audio::Play("sfx100v2_loop_water_01.mp3"_SFX);

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

Loading…
Cancel
Save