diff --git a/Adventures in Lestoria/AdventuresInLestoria.cpp b/Adventures in Lestoria/AdventuresInLestoria.cpp index 31e8263e..901e63e9 100644 --- a/Adventures in Lestoria/AdventuresInLestoria.cpp +++ b/Adventures in Lestoria/AdventuresInLestoria.cpp @@ -101,6 +101,7 @@ InputGroup AiL::KEY_SCROLLUP; InputGroup AiL::KEY_SCROLLDOWN; InputGroup AiL::KEY_BACK; InputGroup AiL::KEY_START; +InputGroup AiL::KEY_SELECT; #ifndef __EMSCRIPTEN__ ::discord::Core*Discord{}; @@ -284,6 +285,17 @@ bool AiL::OnUserUpdate(float fElapsedTime){ RenderWorld(GetElapsedTime()); GameState::STATE->Draw(this); RenderMenu(); + if(Menu::stack.size()>0){ + std::weak_ptrcomponent=Menu::stack.back()->GetSelection(); + if(!component.expired()){ + DrawShadowStringDecal({2,2},"Selection: "+component.lock()->GetName()); + } + std::weak_ptrkeyComponent=Menu::stack.back()->GetKeySelection(); + if(!keyComponent.expired()){ + DrawShadowStringDecal({2,14},"Key Selection: "+keyComponent.lock()->GetName()); + } + } + DrawShadowStringDecal({2,26},"MOUSE NAVIGATION: "+std::to_string(Menu::MOUSE_NAVIGATION)); RenderFadeout(); RenderVersionInfo(); #ifndef __EMSCRIPTEN__ diff --git a/Adventures in Lestoria/LoadGameWindow.cpp b/Adventures in Lestoria/LoadGameWindow.cpp index d8c493f3..b62d0ddc 100644 --- a/Adventures in Lestoria/LoadGameWindow.cpp +++ b/Adventures in Lestoria/LoadGameWindow.cpp @@ -38,6 +38,7 @@ All rights reserved. #include "Menu.h" #include "ScrollableWindowComponent.h" +#include "SaveFile.h" void Menu::InitializeLoadGameWindow(){ Menu*loadGameWindow=CreateMenu(LOAD_GAME,CENTERED,vi2d{96,120}); @@ -47,11 +48,11 @@ void Menu::InitializeLoadGameWindow(){ loadGameWindow->ADD("Go Back Button",MenuComponent)(geom2d::rect{{24,124},{48,12}},"Back",[](MenuFuncData menu){Menu::CloseMenu();return true;})END; loadGameWindow->SetupKeyboardNavigation( - [](MenuType type){ //On Open + [](MenuType type,Data&returnData){ //On Open if(SaveFile::GetSaveFileCount()>0){ - Menu::menus[type]->SetSelection(Component(type,"Game Files List")->GetComponents()[0]); + returnData=Component(type,"Game Files List")->GetComponents()[0]; }else{ - Menu::menus[type]->SetSelection("Go Back Button"); + returnData="Go Back Button"; } }, { //Button Key @@ -64,16 +65,17 @@ void Menu::InitializeLoadGameWindow(){ } ,{ //Button Navigation Rules {"Game Files List",{ - .up=[](MenuType type){ + .up=[](MenuType type,Data&returnData){ auto&selection=Menu::menus[type]->GetSelection(); auto&gameFilesList=Component(type,"Game Files List")->GetComponents(); - if(std::find_if(gameFilesList.begin(),gameFilesList.end(),[&](auto&comp){return comp.lock()==selection.lock();})==gameFilesList.begin()){ - + 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="Back Button",}}, - {"Go Back Button",{ - .left="Continue Button", - .right="Continue Button",}}, + .down="Go Back Button",}}, + {"Go Back Button",{}}, }); } \ No newline at end of file diff --git a/Adventures in Lestoria/MainMenuWindow.cpp b/Adventures in Lestoria/MainMenuWindow.cpp index 3c188f66..e9089e94 100644 --- a/Adventures in Lestoria/MainMenuWindow.cpp +++ b/Adventures in Lestoria/MainMenuWindow.cpp @@ -83,11 +83,11 @@ void Menu::InitializeMainMenuWindow(){ })END; mainMenuWindow->SetupKeyboardNavigation( - [](MenuType type){ //On Open + [](MenuType type,Data&returnData){ //On Open if(SaveFile::GetSaveFileCount()>0){ - Menu::menus[type]->SetSelection("Load Game Button"); + returnData="Load Game Button"; }else{ - Menu::menus[type]->SetSelection("New Game Button"); + returnData="New Game Button"; } }, { //Button Key diff --git a/Adventures in Lestoria/Menu.cpp b/Adventures in Lestoria/Menu.cpp index a7ff9e67..01499737 100644 --- a/Adventures in Lestoria/Menu.cpp +++ b/Adventures in Lestoria/Menu.cpp @@ -49,6 +49,7 @@ INCLUDE_ITEM_CATEGORIES INCLUDE_DATA bool Menu::MOUSE_NAVIGATION=true; +vi2d Menu::lastActiveMousePos{}; std::vectorMenu::stack; std::mapMenu::menus; std::string Menu::themeSelection="BlueDefault"; @@ -112,23 +113,6 @@ void Menu::InitializeMenus(){ if(menus.count(type)==0){ ERR("WARNING! Menu Type "<defaultButton.expired()){ - bool foundComponent=false; - if(menus[type]->componentCount>0){ - for(auto&[key,component]:menus[type]->components){ - if(component->selectable){ - menus[type]->defaultButton=component; - std::cout<GetName())<components){ value->AfterCreate(); } @@ -210,7 +194,7 @@ void Menu::Update(AiL*game){ if(component->GetHoverState(game)){ component->hovered=true; itemHovered=true; - selection=component; + SetSelection(std::weak_ptr(component)); } } } @@ -311,14 +295,12 @@ void Menu::Draw(AiL*game){ void Menu::OpenMenu(MenuType menu,bool cover){ menus[menu]->cover=cover; - menus[menu]->onOpenFunc(menu); + Data returnData; + menus[menu]->onOpenFunc(menu,returnData); + menus[menu]->SetSelection(returnData); stack.push_back(menus[menu]); } -void Menu::SetDefaultButton(std::weak_ptrbutton){ - defaultButton=button; -} - void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){ std::weak_ptrprevSelection=selection; @@ -333,33 +315,51 @@ void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){ if(game->KEY_UP.Pressed()){ SetMouseNavigation(false); - if(std::holds_alternative(nav.up)&&std::get(nav.up).length()>0)selection=components[std::get(nav.up)]; + if(std::holds_alternative(nav.up)&&std::get(nav.up).length()>0)SetSelection(std::string_view(std::get(nav.up))); else - if(std::holds_alternative(nav.up))std::get(nav.up)(type); + if(std::holds_alternative(nav.up)){ + Data returnData; + std::get(nav.up)(type,returnData); + SetSelection(returnData); + } } if(game->KEY_DOWN.Pressed()){ SetMouseNavigation(false); - if(std::holds_alternative(nav.down)&&std::get(nav.down).length()>0)selection=components[std::get(nav.down)]; + if(std::holds_alternative(nav.down)&&std::get(nav.down).length()>0)SetSelection(std::string_view(std::get(nav.down))); else - if(std::holds_alternative(nav.down))std::get(nav.down)(type); + if(std::holds_alternative(nav.down)){ + Data returnData; + std::get(nav.down)(type,returnData); + SetSelection(returnData); + } } if(game->KEY_LEFT.Pressed()){ SetMouseNavigation(false); - if(std::holds_alternative(nav.left)&&std::get(nav.left).length()>0)selection=components[std::get(nav.left)]; + if(std::holds_alternative(nav.left)&&std::get(nav.left).length()>0)SetSelection(std::string_view(std::get(nav.left))); else - if(std::holds_alternative(nav.left))std::get(nav.left)(type); + if(std::holds_alternative(nav.left)){ + Data returnData; + std::get(nav.left)(type,returnData); + SetSelection(returnData); + } } if(game->KEY_RIGHT.Pressed()){ SetMouseNavigation(false); - if(std::holds_alternative(nav.right)&&std::get(nav.right).length()>0)selection=components[std::get(nav.right)]; + if(std::holds_alternative(nav.right)&&std::get(nav.right).length()>0)SetSelection(std::string_view(std::get(nav.right))); else - if(std::holds_alternative(nav.right))std::get(nav.right)(type); + if(std::holds_alternative(nav.right)){ + Data returnData; + std::get(nav.right)(type,returnData); + SetSelection(returnData); + } } } } - if(game->KEY_CONFIRM.Pressed()){ - SetMouseNavigation(game->GetMouse(0).bPressed); //If a click occurs we use mouse controls. + if(game->KEY_UP.Pressed()||game->KEY_RIGHT.Pressed()||game->KEY_LEFT.Pressed()||game->KEY_DOWN.Pressed()|| + game->KEY_BACK.Pressed()||game->KEY_CONFIRM.Pressed()||game->KEY_START.Pressed()||game->KEY_SELECT.Pressed()|| + game->KEY_SCROLLDOWN.Pressed()||game->KEY_SCROLLUP.Pressed()){ + SetMouseNavigation(game->GetMouse(Mouse::LEFT).bPressed||game->GetMouse(Mouse::RIGHT).bPressed||game->GetMouse(Mouse::MIDDLE).bPressed); //If a click occurs we use mouse controls. buttonHoldTime=0; } if(&*prevSelection.lock()!=&*selection.lock()){ @@ -374,7 +374,7 @@ void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){ } if(!handled){ // If the new selection of a button on this frame is disabled for some reason and we didn't handle it, we need to go back to what we had selected before. - selection=prevSelection; + SetSelection(prevSelection); } } } @@ -479,6 +479,9 @@ void Menu::SetMouseNavigation(bool mouseNavigation){ if(MOUSE_NAVIGATION&&!mouseNavigation){ //When mouse navigation was enabled and now needs to be disabled, we store the mouse position. lastActiveMousePos=game->GetMousePos(); + if(!keyboardSelection.expired()){ + SetSelection(keyboardSelection); + } } MOUSE_NAVIGATION=mouseNavigation; }; @@ -613,10 +616,6 @@ void Menu::AddChapterListener(std::weak_ptrcomponent){ MenuFuncData::MenuFuncData(Menu&menu,AiL*const game,std::weak_ptrcomponent,std::weak_ptrparentComponent) :menu(menu),game(game),component(component),parentComponent(parentComponent){} -void Menu::SetSelection(std::weak_ptrbutton){ - selection=button; -} - void Menu::SetupKeyboardNavigation(MenuDataFunc onOpen,MenuInputGroups inputGroups,ButtonNavigationGroups navigationGroups){ this->onOpenFunc=onOpen; this->inputGroups=inputGroups; @@ -627,7 +626,33 @@ const std::weak_ptrMenu::GetSelection()const{ return selection; } +const std::weak_ptrMenu::GetKeySelection()const{ + return keyboardSelection; +} + +void Menu::SetSelection(std::weak_ptrbutton){ + selection=button; + if(navigationGroups.count(button.lock()->GetName())|| + !button.lock()->parentComponent.expired()&&navigationGroups.count(button.lock()->parentComponent.lock()->GetName())){ + keyboardSelection=button; + } +} void Menu::SetSelection(std::string_view button){ - selection=Component(type,button); + selection=Component(type,std::string(button)); + if(navigationGroups.count(std::string(button))|| + !selection.lock()->parentComponent.expired()&&navigationGroups.count(selection.lock()->parentComponent.lock()->GetName())){ + keyboardSelection=selection; + } +} + +void Menu::SetSelection(std::variant>button){ + if(std::holds_alternative(button)){ + SetSelection(std::string_view(std::get(button))); + }else + if(std::holds_alternative>(button)){ + SetSelection(std::get>(button)); + }else{ + ERR("WARNING! Specified menu opening function does not hold neither a string nor a pointer to a component to use!"); + } } \ No newline at end of file diff --git a/Adventures in Lestoria/Menu.h b/Adventures in Lestoria/Menu.h index 1fad63af..ff84b270 100644 --- a/Adventures in Lestoria/Menu.h +++ b/Adventures in Lestoria/Menu.h @@ -99,19 +99,20 @@ enum MenuType{ /////////////////////////////////////////////////////////// }; -using MenuDataFunc=std::function; using InputGroupActionDisplayName=std::string; using ButtonName=std::string; -using MenuInputGroups=std::map>>; +using Data=std::variant>; +using MenuDataFunc=std::function; +using MenuInputGroups=std::map>>>; using ButtonNavigationGroups=std::map; struct Navigation{ - std::variantup; - std::variantdown; - std::variantleft; - std::variantright; + std::variantup; + std::variantdown; + std::variantleft; + std::variantright; }; class Menu:public IAttributable{ @@ -141,7 +142,7 @@ class Menu:public IAttributable{ friend class EntityStats; float buttonHoldTime=0; - vi2d lastActiveMousePos={}; + static vi2d lastActiveMousePos; int componentCount=0; std::unique_ptrdraggingComponent; @@ -218,7 +219,9 @@ public: void SetSelection(std::string_view button); void SetSelection(std::weak_ptrbutton); + void SetSelection(std::variant>button); const std::weak_ptrGetSelection()const; + const std::weak_ptrGetKeySelection()const; private: Menu(vf2d pos,vf2d size); static MenuType lastMenuTypeCreated; @@ -243,7 +246,9 @@ private: MenuType type; MenuInputGroups inputGroups; ButtonNavigationGroups navigationGroups; - MenuOpenFunc onOpenFunc; + MenuDataFunc onOpenFunc; + std::weak_ptrselection; + std::weak_ptrkeyboardSelection; static bool MOUSE_NAVIGATION; bool cover; //A black cover for when a menu pops up to fade out the stuff behind it. diff --git a/Adventures in Lestoria/SaveFileWindow.cpp b/Adventures in Lestoria/SaveFileWindow.cpp index c203698c..c2cedef4 100644 --- a/Adventures in Lestoria/SaveFileWindow.cpp +++ b/Adventures in Lestoria/SaveFileWindow.cpp @@ -55,8 +55,8 @@ void Menu::InitializeSaveFileWindow(){ saveFileWindow->SetupKeyboardNavigation( - [](MenuType type){ //On Open - Menu::menus[type]->SetSelection("Continue Button"); + [](MenuType type,Data&returnData){ //On Open + returnData="Continue Button"; }, { //Button Key {game->KEY_START,{"Confirm Filename",[](MenuType type){ diff --git a/Adventures in Lestoria/SoundEffect.cpp b/Adventures in Lestoria/SoundEffect.cpp index 1495fcb6..ff341bef 100644 --- a/Adventures in Lestoria/SoundEffect.cpp +++ b/Adventures in Lestoria/SoundEffect.cpp @@ -61,8 +61,8 @@ void SoundEffect::Initialize(){ utils::datafile&data=DATA["Events"]["SFX"][key][std::format("File[{}]",counter)]; float minPitch=0.9f; float maxPitch=1.1f; - if(data.GetValueCount()>=3){minPitch=data.GetInt(2)/100.f}; - if(data.GetValueCount()>=4){maxPitch=data.GetInt(3)/100.f}; + if(data.GetValueCount()>=3){minPitch=data.GetInt(2)/100.f;} + if(data.GetValueCount()>=4){maxPitch=data.GetInt(3)/100.f;} SOUND_EFFECTS.insert({key,SoundEffect{data.GetString(0),data.GetInt(1)/100.f,minPitch,maxPitch}}); counter++; } diff --git a/Adventures in Lestoria/TODO.txt b/Adventures in Lestoria/TODO.txt index 53019476..cff81930 100644 --- a/Adventures in Lestoria/TODO.txt +++ b/Adventures in Lestoria/TODO.txt @@ -12,6 +12,8 @@ Settings Menu -We have to save keybinds to the save file. - Fix Stage Completed screen, item displays can hit the scrollbar. +- Monster spawn list is not populated in Emscripten? +- Random pitch up down +/-10%. January 31st ============ diff --git a/Adventures in Lestoria/Version.h b/Adventures in Lestoria/Version.h index 25956157..0abb80ca 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 2 #define VERSION_PATCH 1 -#define VERSION_BUILD 5974 +#define VERSION_BUILD 5997 #define stringify(a) stringify_(a) #define stringify_(a) #a