Converted menu storage to pointers.

This commit is contained in:
2023-10-11 16:20:07 -05:00
parent 461265a8a4
commit dd2ff24d85
7 changed files with 33 additions and 30 deletions
+8 -6
View File
@@ -5,7 +5,7 @@
bool Menu::MOUSE_NAVIGATION=true;
std::vector<Menu*>Menu::stack;
std::map<MenuType,Menu>Menu::menus;
std::map<MenuType,Menu*>Menu::menus;
std::string Menu::themeSelection="BlueDefault";
safeunorderedmap<std::string,Theme>Menu::themes;
const vf2d Menu::CENTERED = {-456,-456};
@@ -16,7 +16,9 @@ extern vi2d WINDOW_SIZE;
Menu::Menu(){}
Menu::Menu(vf2d pos,vf2d size)
:pos(pos==CENTERED?WINDOW_SIZE/2-size/2:vi2d{pos}),size(size){}
:pos(pos==CENTERED?WINDOW_SIZE/2-size/2:vi2d{pos}),size(size){
}
void Menu::InitializeMenus(){
stack.reserve(32);
@@ -29,7 +31,7 @@ void Menu::InitializeMenus(){
std::cout<<"WARNING! Menu Type "<<type<<" does not exist!"<<std::endl;
throw;
}
menus[type].components.SetInitialized(); //Lock all known components to prevent invalid access.
menus[type]->components.SetInitialized(); //Lock all known components to prevent invalid access.
}
}
@@ -68,7 +70,7 @@ void Menu::MenuSelect(Crawler*game){
buttons[selection.y][selection.x]->onClick(MenuFuncData{*this,game,buttons[selection.y][selection.x]});
if(buttons[selection.y][selection.x]->menuDest!=MenuType::ENUM_END){
if(stack.size()<32){
stack.push_back(&menus[buttons[selection.y][selection.x]->menuDest]);//Navigate to the next menu.
stack.push_back(menus[buttons[selection.y][selection.x]->menuDest]);//Navigate to the next menu.
}else{
std::cout<<"WARNING! Exceeded menu stack size limit!"<<std::endl;
throw;
@@ -166,14 +168,14 @@ void Menu::Draw(Crawler*game){
void Menu::OpenMenu(MenuType menu){
stack.clear();
stack.push_back(&(menus[menu]));
stack.push_back(menus[menu]);
}
void Menu::KeyboardButtonNavigation(Crawler*game,vf2d menuPos){
if(game->GetKey(RIGHT).bPressed){
if(selection==vi2d{-1,-1})return;
MOUSE_NAVIGATION=false;
selection.x=(selection.x+1)%buttons[selection.y].size();
selection.x=(size_t(selection.x)+1)%buttons[selection.y].size();
}
if(game->GetKey(LEFT).bPressed){
if(selection==vi2d{-1,-1})return;