Add default button member to menus.
This commit is contained in:
parent
bc1a1c6876
commit
97ce43ed21
@ -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<float>{{12,4},{72,24}},"New Game",[&](MenuFuncData data){
|
||||
auto newGameButton=mainMenuWindow->ADD("New Game Button",MenuComponent)(geom2d::rect<float>{{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<float>{{12,36},{72,24}},"Load Game",[](MenuFuncData data){
|
||||
auto loadGameButton=mainMenuWindow->ADD("Load Game Button",MenuComponent)(geom2d::rect<float>{{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);
|
||||
}
|
||||
}
|
@ -112,6 +112,23 @@ void Menu::InitializeMenus(){
|
||||
if(menus.count(type)==0){
|
||||
ERR("WARNING! Menu Type "<<type<<" does not exist!")
|
||||
}
|
||||
if(menus[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<<std::format("WARNING! Menu {} does not have a default button! Automatically choosing {}",int(type),component->GetName())<<std::endl;
|
||||
foundComponent=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!foundComponent){
|
||||
std::cout<<std::format("WARNING! Menu {} does not have a default button and has no default components to set it automatically!",int(type))<<std::endl;
|
||||
}
|
||||
}
|
||||
for(auto&[key,value]:menus[type]->components){
|
||||
value->AfterCreate();
|
||||
}
|
||||
@ -166,7 +183,7 @@ void Menu::Update(AiL*game){
|
||||
HoverMenuSelect(game);
|
||||
}
|
||||
|
||||
if(!UsingMouseNavigation()&&geom2d::line<float>(lastActiveMousePos,game->GetMousePos()).length()>="ThemeGlobal.MouseActivationDistance"_F||UsingMouseNavigation()){
|
||||
if(!UsingMouseNavigation()&&geom2d::line<float>(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_ptr<MenuComponent>button){
|
||||
defaultButton=button;
|
||||
}
|
||||
|
||||
void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){
|
||||
std::weak_ptr<MenuComponent>prevSelection=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;
|
||||
|
@ -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_ptr<MenuComponent>button);
|
||||
private:
|
||||
Menu(vf2d pos,vf2d size);
|
||||
std::weak_ptr<MenuComponent>defaultButton;
|
||||
static MenuType lastMenuTypeCreated;
|
||||
static std::string lastRegisteredComponent;
|
||||
void HoverMenuSelect(AiL*game);
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user