diff --git a/Adventures in Lestoria/AdventuresInLestoria.cpp b/Adventures in Lestoria/AdventuresInLestoria.cpp index b37b22d4..ecc58c54 100644 --- a/Adventures in Lestoria/AdventuresInLestoria.cpp +++ b/Adventures in Lestoria/AdventuresInLestoria.cpp @@ -97,6 +97,10 @@ InputGroup AiL::KEY_DOWN; InputGroup AiL::KEY_ATTACK; InputGroup AiL::KEY_CONFIRM; InputGroup AiL::KEY_MENU; +InputGroup AiL::KEY_SCROLLUP; +InputGroup AiL::KEY_SCROLLDOWN; +InputGroup AiL::KEY_BACK; + #ifndef __EMSCRIPTEN__ ::discord::Core*Discord{}; #endif @@ -2368,13 +2372,28 @@ void AiL::InitializeDefaultKeybinds(){ KEY_DOWN.AddKeybind({KEY,S}); KEY_DOWN.AddKeybind({CONTROLLER,static_cast(GPButtons::DPAD_D)}); KEY_CONFIRM.AddKeybind({MOUSE,Mouse::LEFT}); - KEY_CONFIRM.AddKeybind({CONTROLLER,static_cast(GPButtons::FACE_D)}); KEY_CONFIRM.AddKeybind({CONTROLLER,static_cast(GPButtons::FACE_R)}); KEY_CONFIRM.AddKeybind({CONTROLLER,static_cast(GPButtons::START)}); KEY_CONFIRM.AddKeybind({KEY,SPACE}); KEY_CONFIRM.AddKeybind({KEY,ENTER}); + KEY_CONFIRM.AddKeybind({KEY,Z}); + KEY_BACK.AddKeybind({KEY,X}); + KEY_BACK.AddKeybind({KEY,SHIFT}); + KEY_BACK.AddKeybind({KEY,ESCAPE}); + KEY_BACK.AddKeybind({CONTROLLER,static_cast(GPButtons::FACE_D)}); KEY_MENU.AddKeybind({KEY,ESCAPE}); KEY_MENU.AddKeybind({CONTROLLER,static_cast(GPButtons::START)}); + + KEY_SCROLLUP.AddKeybind({KEY,Q}); + KEY_SCROLLUP.AddKeybind({KEY,PGUP}); + KEY_SCROLLUP.AddKeybind({KEY,NP8}); + KEY_SCROLLUP.AddKeybind({CONTROLLER,static_cast(GPButtons::L2)}); + KEY_SCROLLUP.AddKeybind({CONTROLLER,static_cast(GPButtons::L1)}); + KEY_SCROLLDOWN.AddKeybind({KEY,E}); + KEY_SCROLLDOWN.AddKeybind({KEY,PGDN}); + KEY_SCROLLDOWN.AddKeybind({KEY,NP2}); + KEY_SCROLLDOWN.AddKeybind({CONTROLLER,static_cast(GPButtons::R2)}); + KEY_SCROLLDOWN.AddKeybind({CONTROLLER,static_cast(GPButtons::R1)}); } void AiL::SetBossNameDisplay(std::string name,float time){ diff --git a/Adventures in Lestoria/AdventuresInLestoria.h b/Adventures in Lestoria/AdventuresInLestoria.h index 030d37df..02c94c96 100644 --- a/Adventures in Lestoria/AdventuresInLestoria.h +++ b/Adventures in Lestoria/AdventuresInLestoria.h @@ -73,6 +73,9 @@ class AiL : public olc::PixelGameEngine SplashScreen splash; public: Pathfinding pathfinder; + static InputGroup KEY_SCROLLUP; + static InputGroup KEY_SCROLLDOWN; + static InputGroup KEY_BACK; static InputGroup KEY_CONFIRM; static InputGroup KEY_ATTACK; static InputGroup KEY_LEFT; diff --git a/Adventures in Lestoria/Key.cpp b/Adventures in Lestoria/Key.cpp index e08ab4aa..700ba458 100644 --- a/Adventures in Lestoria/Key.cpp +++ b/Adventures in Lestoria/Key.cpp @@ -338,4 +338,8 @@ void Input::StopVibration(){ gamepad->stopVibration(); } } +} + +const bool operator<(const InputGroup&group1,const InputGroup&group2){ + return &group1<&group2; } \ No newline at end of file diff --git a/Adventures in Lestoria/Key.h b/Adventures in Lestoria/Key.h index 36f66f7c..37de00a2 100644 --- a/Adventures in Lestoria/Key.h +++ b/Adventures in Lestoria/Key.h @@ -84,4 +84,6 @@ public: class GenericKey{ public: static std::map,std::string>keyLiteral; //The displayed text for a given key for a given input type. -}; \ No newline at end of file +}; + +const bool operator<(const InputGroup&group1,const InputGroup&group2); \ No newline at end of file diff --git a/Adventures in Lestoria/MainMenuWindow.cpp b/Adventures in Lestoria/MainMenuWindow.cpp index ceef1812..350cd06d 100644 --- a/Adventures in Lestoria/MainMenuWindow.cpp +++ b/Adventures in Lestoria/MainMenuWindow.cpp @@ -87,4 +87,20 @@ void Menu::InitializeMainMenuWindow(){ }else{ mainMenuWindow->SetDefaultButton(newGameButton); } + + mainMenuWindow->SetupKeyboardNavigation( + { + {game->KEY_BACK,{"",[](MenuType type){}}}, + } + ,{ + {"New Game Button",{ + .up="Quit Game Button", + .down="Load Game Button",}}, + {"Load Game Button",{ + .up="New Game Button", + .down="Quit Game Button",}}, + {"Quit Game Button",{ + .up="Load Game Button", + .down="New Game Button",}}, + }); } \ No newline at end of file diff --git a/Adventures in Lestoria/Menu.cpp b/Adventures in Lestoria/Menu.cpp index 19f3d81b..e7e74d96 100644 --- a/Adventures in Lestoria/Menu.cpp +++ b/Adventures in Lestoria/Menu.cpp @@ -320,6 +320,36 @@ void Menu::SetDefaultButton(std::weak_ptrbutton){ void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){ std::weak_ptrprevSelection=selection; + + std::string selectionButtonName=selection.lock()->GetName(); + if(navigationGroups.count(selectionButtonName)){ + Navigation nav=navigationGroups[selectionButtonName]; + + 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)]; + else + if(std::holds_alternative(nav.up))std::get(nav.up)(type); + } + 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)]; + else + if(std::holds_alternative(nav.down))std::get(nav.down)(type); + } + 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)]; + else + if(std::holds_alternative(nav.left))std::get(nav.left)(type); + } + 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)]; + else + if(std::holds_alternative(nav.right))std::get(nav.right)(type); + } + } if(game->KEY_CONFIRM.Pressed()){ SetMouseNavigation(game->GetMouse(0).bPressed); //If a click occurs we use mouse controls. @@ -574,4 +604,17 @@ 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){} \ No newline at end of file + :menu(menu),game(game),component(component),parentComponent(parentComponent){} + +void Menu::SetSelection(std::weak_ptrbutton){ + selection=button; +} + +void Menu::SetupKeyboardNavigation(MenuInputGroups inputGroups,ButtonNavigationGroups navigationGroups){ + this->inputGroups=inputGroups; + this->navigationGroups=navigationGroups; +} + +const std::weak_ptrMenu::GetSelection()const{ + return selection; +} \ No newline at end of file diff --git a/Adventures in Lestoria/Menu.h b/Adventures in Lestoria/Menu.h index a0c6103b..b61750ff 100644 --- a/Adventures in Lestoria/Menu.h +++ b/Adventures in Lestoria/Menu.h @@ -43,11 +43,25 @@ All rights reserved. #include "Attributable.h" #include "olcUTIL_Geometry2D.h" #include "olcPGEX_ViewPort.h" +#include "Key.h" class AiL; class MenuComponent; class ScrollableWindowComponent; +struct Navigation; + +class Menu; + +struct MenuFuncData{ + Menu&menu; + AiL*const game; + const std::weak_ptr component; + const std::weak_ptr parentComponent={}; + MenuFuncData(Menu&menu,AiL*const game,std::weak_ptr component,std::weak_ptrparentComponent={}); +}; + +using MenuFunc=std::function; //Add a component to a menu using this macro. Follow-up with END at the end of it. #define ADD(key,componentType) _AddComponent(key,std::make_shared #define END ) @@ -85,6 +99,21 @@ enum MenuType{ /////////////////////////////////////////////////////////// }; +using MenuDataFunc=std::function; + +using InputGroupActionDisplayName=std::string; +using ButtonName=std::string; +using MenuInputGroups=std::map>>; +using ButtonNavigationGroups=std::map; + + +struct Navigation{ + std::variantup; + std::variantdown; + std::variantleft; + std::variantright; +}; + class Menu:public IAttributable{ static void InitializeConsumableInventoryWindow(); static void InitializeClassInfoWindow(); @@ -188,6 +217,8 @@ public: void RecalculateComponentCount(); void SetDefaultButton(std::weak_ptrbutton); + void SetSelection(std::weak_ptrbutton); + const std::weak_ptrGetSelection()const; private: Menu(vf2d pos,vf2d size); std::weak_ptrdefaultButton; @@ -198,7 +229,8 @@ private: void CheckClickAndPerformMenuSelect(AiL*game); //Mandatory before any menu operations! This creates and sets up the menu in memory. static Menu*CreateMenu(MenuType type,vf2d pos,vf2d size); - + + void SetupKeyboardNavigation(MenuInputGroups inputGroups,ButtonNavigationGroups navigationGroups); void KeyboardButtonNavigation(AiL*game,vf2d menuPos); static void DrawScaledWindowBackground(AiL*game,vf2d menuPos,vf2d size,Pixel renderColor); static void DrawTiledWindowBackground(AiL*game,vf2d menuPos,vf2d size,Pixel renderColor); @@ -210,6 +242,8 @@ private: Pixel GetRenderColor(); MenuType type; + MenuInputGroups inputGroups; + ButtonNavigationGroups navigationGroups; static bool MOUSE_NAVIGATION; bool cover; //A black cover for when a menu pops up to fade out the stuff behind it. @@ -218,14 +252,4 @@ private: template std::shared_ptrComponent(MenuType menu,std::string componentName){ return DYNAMIC_POINTER_CAST(Menu::menus[menu]->components[componentName]); -} - -struct MenuFuncData{ - Menu&menu; - AiL*const game; - const std::weak_ptr component; - const std::weak_ptr parentComponent={}; - MenuFuncData(Menu&menu,AiL*const game,std::weak_ptr component,std::weak_ptrparentComponent={}); -}; - -using MenuFunc=std::function; \ No newline at end of file +} \ No newline at end of file diff --git a/Adventures in Lestoria/TODO.txt b/Adventures in Lestoria/TODO.txt index bc699c08..8609872d 100644 --- a/Adventures in Lestoria/TODO.txt +++ b/Adventures in Lestoria/TODO.txt @@ -30,4 +30,19 @@ Story proofreading/correcting/storyboarding -- Emscripten _DEBUG flag add as an option when building \ No newline at end of file +- Emscripten _DEBUG flag add as an option when building + + + mainMenuWindow->SetupKeyboardNavigation( + { + {game->KEY_BACK,{"","Quit Game Button"}}, + {game->KEY_BACK,{"",[](MenuFuncData data){}}}, + } + ,{ + {"New Game Button",{ + .up="Quit Game Button", + .down="Load Game Button",}}, + {"Load Game Button",{ + .up="New Game Button", + .down="Quit Game Button",}}, + }); \ No newline at end of file diff --git a/Adventures in Lestoria/Version.h b/Adventures in Lestoria/Version.h index 911f1f2a..7e3a115a 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 5958 +#define VERSION_BUILD 5966 #define stringify(a) stringify_(a) #define stringify_(a) #a