From 97ce43ed2144cd819dbe4ea9566df82813dd152a Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Tue, 16 Jan 2024 18:21:22 -0600 Subject: [PATCH] Add default button member to menus. --- Adventures in Lestoria/MainMenuWindow.cpp | 10 +++++++-- Adventures in Lestoria/Menu.cpp | 26 ++++++++++++++++++++--- Adventures in Lestoria/Menu.h | 3 +++ Adventures in Lestoria/Version.h | 2 +- 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/Adventures in Lestoria/MainMenuWindow.cpp b/Adventures in Lestoria/MainMenuWindow.cpp index e06b9f34..ceef1812 100644 --- a/Adventures in Lestoria/MainMenuWindow.cpp +++ b/Adventures in Lestoria/MainMenuWindow.cpp @@ -47,7 +47,7 @@ using A=Attribute; void Menu::InitializeMainMenuWindow(){ Menu*mainMenuWindow=CreateMenu(MAIN_MENU,vi2d{132,120},vi2d{96,96}); - mainMenuWindow->ADD("New Game Button",MenuComponent)(geom2d::rect{{12,4},{72,24}},"New Game",[&](MenuFuncData data){ + auto newGameButton=mainMenuWindow->ADD("New Game Button",MenuComponent)(geom2d::rect{{12,4},{72,24}},"New Game",[&](MenuFuncData data){ game->TextEntryEnable(true); #ifdef __EMSCRIPTEN__ data.menu.S(A::NEXT_MENU)="New Game"; @@ -61,7 +61,7 @@ void Menu::InitializeMainMenuWindow(){ #endif return true; })END; - mainMenuWindow->ADD("Load Game Button",MenuComponent)(geom2d::rect{{12,36},{72,24}},"Load Game",[](MenuFuncData data){ + auto loadGameButton=mainMenuWindow->ADD("Load Game Button",MenuComponent)(geom2d::rect{{12,36},{72,24}},"Load Game",[](MenuFuncData data){ #ifdef __EMSCRIPTEN__ data.menu.S(A::NEXT_MENU)="Load Game"; if(SaveFile::GetUserID().length()==0){ @@ -81,4 +81,10 @@ void Menu::InitializeMainMenuWindow(){ game->EndGame(); return true; })END; + + if(SaveFile::GetSaveFileCount()>0){ + mainMenuWindow->SetDefaultButton(loadGameButton); + }else{ + mainMenuWindow->SetDefaultButton(newGameButton); + } } \ No newline at end of file diff --git a/Adventures in Lestoria/Menu.cpp b/Adventures in Lestoria/Menu.cpp index a414790a..19f3d81b 100644 --- a/Adventures in Lestoria/Menu.cpp +++ b/Adventures in Lestoria/Menu.cpp @@ -112,6 +112,23 @@ 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(); } @@ -166,7 +183,7 @@ void Menu::Update(AiL*game){ HoverMenuSelect(game); } - if(!UsingMouseNavigation()&&geom2d::line(lastActiveMousePos,game->GetMousePos()).length()>="ThemeGlobal.MouseActivationDistance"_F||UsingMouseNavigation()){ + if(!UsingMouseNavigation()&&geom2d::line(lastActiveMousePos,game->GetMousePos()).length()>="ThemeGlobal.MouseActivationDistance"_F){ SetMouseNavigation(true); } @@ -186,7 +203,6 @@ void Menu::Update(AiL*game){ } } }else{ - selection={}; for(auto&[key,component]:components){ if(component->selectable){ if(!component->disabled&&!component->grayedOut){ @@ -294,9 +310,14 @@ void Menu::Draw(AiL*game){ void Menu::OpenMenu(MenuType menu,bool cover){ menus[menu]->cover=cover; + menus[menu]->selection=menus[menu]->defaultButton; stack.push_back(menus[menu]); } +void Menu::SetDefaultButton(std::weak_ptrbutton){ + defaultButton=button; +} + void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){ std::weak_ptrprevSelection=selection; @@ -420,7 +441,6 @@ bool Menu::UsingMouseNavigation(){ 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. - INCLUDE_game lastActiveMousePos=game->GetMousePos(); } MOUSE_NAVIGATION=mouseNavigation; diff --git a/Adventures in Lestoria/Menu.h b/Adventures in Lestoria/Menu.h index 90282157..a0c6103b 100644 --- a/Adventures in Lestoria/Menu.h +++ b/Adventures in Lestoria/Menu.h @@ -186,8 +186,11 @@ public: //X (0-2), Y (0-2) for specific 9-patch tile (tiled version). static Renderable&GetPatchPart(int x,int y); void RecalculateComponentCount(); + + void SetDefaultButton(std::weak_ptrbutton); private: Menu(vf2d pos,vf2d size); + std::weak_ptrdefaultButton; static MenuType lastMenuTypeCreated; static std::string lastRegisteredComponent; void HoverMenuSelect(AiL*game); diff --git a/Adventures in Lestoria/Version.h b/Adventures in Lestoria/Version.h index 73e4191e..911f1f2a 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 5950 +#define VERSION_BUILD 5958 #define stringify(a) stringify_(a) #define stringify_(a) #a