From 210a46a5f99e37e68863a8bd471d46f29fa24df4 Mon Sep 17 00:00:00 2001 From: "sigonasr2, Sig, Sigo" Date: Wed, 17 Jan 2024 21:00:51 +0000 Subject: [PATCH] Continue fixing up new menu navigation structure Co-authored-by: sigonasr2 --- Adventures in Lestoria/LoadGameWindow.cpp | 33 ++++++++++++++++++++++- Adventures in Lestoria/MainMenuWindow.cpp | 17 ++++++------ Adventures in Lestoria/Menu.cpp | 16 ++++++++--- Adventures in Lestoria/Menu.h | 7 +++-- Adventures in Lestoria/SaveFileWindow.cpp | 9 ++++--- 5 files changed, 63 insertions(+), 19 deletions(-) diff --git a/Adventures in Lestoria/LoadGameWindow.cpp b/Adventures in Lestoria/LoadGameWindow.cpp index faeaf73f..d8c493f3 100644 --- a/Adventures in Lestoria/LoadGameWindow.cpp +++ b/Adventures in Lestoria/LoadGameWindow.cpp @@ -30,7 +30,7 @@ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -Portions of this software are copyright © 2023 The FreeType +Portions of this software are copyright � 2023 The FreeType Project (www.freetype.org). Please see LICENSE_FT.txt for more information. All rights reserved. */ @@ -45,4 +45,35 @@ void Menu::InitializeLoadGameWindow(){ loadGameWindow->ADD("Game Files Label",MenuLabel)(geom2d::rect{{-8,-12},{112,12}},"Load Game",1.0f,ComponentAttr::SHADOW|ComponentAttr::OUTLINE|ComponentAttr::BACKGROUND)END; loadGameWindow->ADD("Game Files List",ScrollableWindowComponent)(geom2d::rect{{-8,4},{112,116}})END; 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 + if(SaveFile::GetSaveFileCount()>0){ + Menu::menus[type]->SetSelection(Component(type,"Game Files List")->GetComponents()[0]); + }else{ + Menu::menus[type]->SetSelection("Go Back Button"); + } + }, + { //Button Key + {game->KEY_START,{"Load File",[](MenuType type){ + Menu::menus[type]->GetSelection().lock()->Click(); + }}}, + {game->KEY_SELECT,{"Return to Title Screen",[](MenuType type){ + Component(type,"Back Button")->Click(); + }}}, + } + ,{ //Button Navigation Rules + {"Game Files List",{ + .up=[](MenuType type){ + 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()){ + + } + }, + .down="Back Button",}}, + {"Go Back Button",{ + .left="Continue Button", + .right="Continue Button",}}, + }); } \ No newline at end of file diff --git a/Adventures in Lestoria/MainMenuWindow.cpp b/Adventures in Lestoria/MainMenuWindow.cpp index b86ee43b..3c188f66 100644 --- a/Adventures in Lestoria/MainMenuWindow.cpp +++ b/Adventures in Lestoria/MainMenuWindow.cpp @@ -82,18 +82,19 @@ void Menu::InitializeMainMenuWindow(){ return true; })END; - if(SaveFile::GetSaveFileCount()>0){ - mainMenuWindow->SetDefaultButton(loadGameButton); - }else{ - mainMenuWindow->SetDefaultButton(newGameButton); - } - mainMenuWindow->SetupKeyboardNavigation( - { + [](MenuType type){ //On Open + if(SaveFile::GetSaveFileCount()>0){ + Menu::menus[type]->SetSelection("Load Game Button"); + }else{ + Menu::menus[type]->SetSelection("New Game Button"); + } + }, + { //Button Key {game->KEY_CONFIRM,{"Select",[](MenuType type){}}}, {game->KEY_BACK,{"Back",[](MenuType type){}}}, } - ,{ + ,{ //Button Navigation Rules {"New Game Button",{ .up="Quit Game Button", .down="Load Game Button",}}, diff --git a/Adventures in Lestoria/Menu.cpp b/Adventures in Lestoria/Menu.cpp index 6c4f4e7a..a7ff9e67 100644 --- a/Adventures in Lestoria/Menu.cpp +++ b/Adventures in Lestoria/Menu.cpp @@ -150,7 +150,7 @@ void Menu::CheckClickAndPerformMenuSelect(AiL*game){ } void Menu::HoverMenuSelect(AiL*game){ - if(!game->IsFocused()||selection.expired()||selection.lock()->disabled)return; + if(!game->IsFocused()||selection.expired()||selection.lock()->disabled||selection.lock()->grayedOut)return; if(selection.lock()->draggable){ if(buttonHoldTime<"ThemeGlobal.MenuHoldTime"_F){ @@ -311,7 +311,7 @@ void Menu::Draw(AiL*game){ void Menu::OpenMenu(MenuType menu,bool cover){ menus[menu]->cover=cover; - menus[menu]->selection=menus[menu]->defaultButton; + menus[menu]->onOpenFunc(menu); stack.push_back(menus[menu]); } @@ -324,6 +324,10 @@ void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){ if(!selection.expired()){ std::string selectionButtonName=selection.lock()->GetName(); + if(!selection.lock()->parentComponent.expired()){ //If a component has a parent, then we use the parent as the identifier for what should happen next. + selectionButtonName=selection.lock()->parentComponent.lock()->GetName(); + } + if(navigationGroups.count(selectionButtonName)){ Navigation nav=navigationGroups[selectionButtonName]; @@ -613,11 +617,17 @@ void Menu::SetSelection(std::weak_ptrbutton){ selection=button; } -void Menu::SetupKeyboardNavigation(MenuInputGroups inputGroups,ButtonNavigationGroups navigationGroups){ +void Menu::SetupKeyboardNavigation(MenuDataFunc onOpen,MenuInputGroups inputGroups,ButtonNavigationGroups navigationGroups){ + this->onOpenFunc=onOpen; this->inputGroups=inputGroups; this->navigationGroups=navigationGroups; } const std::weak_ptrMenu::GetSelection()const{ return selection; +} + + +void Menu::SetSelection(std::string_view button){ + selection=Component(type,button); } \ No newline at end of file diff --git a/Adventures in Lestoria/Menu.h b/Adventures in Lestoria/Menu.h index 2e19322f..1fad63af 100644 --- a/Adventures in Lestoria/Menu.h +++ b/Adventures in Lestoria/Menu.h @@ -141,7 +141,6 @@ class Menu:public IAttributable{ friend class EntityStats; float buttonHoldTime=0; - std::weak_ptrselection; vi2d lastActiveMousePos={}; int componentCount=0; @@ -217,12 +216,11 @@ public: static Renderable&GetPatchPart(int x,int y); void RecalculateComponentCount(); - void SetDefaultButton(std::weak_ptrbutton); + void SetSelection(std::string_view button); void SetSelection(std::weak_ptrbutton); const std::weak_ptrGetSelection()const; private: Menu(vf2d pos,vf2d size); - std::weak_ptrdefaultButton; static MenuType lastMenuTypeCreated; static std::string lastRegisteredComponent; void HoverMenuSelect(AiL*game); @@ -231,7 +229,7 @@ private: //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 SetupKeyboardNavigation(MenuDataFunc onOpen,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); @@ -245,6 +243,7 @@ private: MenuType type; MenuInputGroups inputGroups; ButtonNavigationGroups navigationGroups; + MenuOpenFunc onOpenFunc; 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 524f661a..c203698c 100644 --- a/Adventures in Lestoria/SaveFileWindow.cpp +++ b/Adventures in Lestoria/SaveFileWindow.cpp @@ -55,15 +55,18 @@ void Menu::InitializeSaveFileWindow(){ saveFileWindow->SetupKeyboardNavigation( - { - {game->KEY_START,{"Confirm Name",[](MenuType type){ + [](MenuType type){ //On Open + Menu::menus[type]->SetSelection("Continue Button"); + }, + { //Button Key + {game->KEY_START,{"Confirm Filename",[](MenuType type){ Component(type,"Continue Button")->Click(); }}}, {game->KEY_SELECT,{"Return to Title Screen",[](MenuType type){ Component(type,"Back Button")->Click(); }}}, } - ,{ + ,{ //Button Navigation Rules {"Continue Button",{ .left="Back Button", .right="Back Button",}},