Converted menu storage to pointers.
This commit is contained in:
parent
461265a8a4
commit
dd2ff24d85
@ -10,7 +10,7 @@
|
||||
INCLUDE_GFX
|
||||
typedef Attribute A;
|
||||
|
||||
const Menu Menu::InitializeInventoryWindow(){
|
||||
Menu*Menu::InitializeInventoryWindow(){
|
||||
constexpr int invWidth=5;
|
||||
constexpr int invHeight=3;
|
||||
constexpr int totalItemSlots=invWidth*invHeight;
|
||||
@ -19,7 +19,7 @@ const Menu Menu::InitializeInventoryWindow(){
|
||||
constexpr int buttonSize=24;
|
||||
constexpr int totalSpacing=buttonSize+itemSpacing;
|
||||
|
||||
Menu inventoryWindow(CENTERED,{totalSpacing*invWidth-itemSpacing,totalSpacing*(invHeight+1)-itemSpacing});
|
||||
Menu*inventoryWindow=new Menu(CENTERED,{totalSpacing*invWidth-itemSpacing,totalSpacing*(invHeight+1)-itemSpacing});
|
||||
|
||||
MenuFunc useItemFunc=[](MenuFuncData data){
|
||||
MenuItemButton*button=(MenuItemButton*)data.component;
|
||||
@ -30,14 +30,14 @@ const Menu Menu::InitializeInventoryWindow(){
|
||||
for(int x=0;x<invWidth;x++){
|
||||
int itemIndex=y*invWidth+x;
|
||||
MenuItemButton*button=new MenuItemButton{INVENTORY,{{float(totalSpacing*x),float(totalSpacing*y)},{float(buttonSize),float(buttonSize)}},Inventory::get("Consumables"),itemIndex,useItemFunc};
|
||||
inventoryWindow.AddComponent("item"+std::to_string(itemIndex),button);
|
||||
inventoryWindow->AddComponent("item"+std::to_string(itemIndex),button);
|
||||
}
|
||||
}
|
||||
|
||||
MenuLabel*itemNameLabel=new MenuLabel{INVENTORY,vf2d{0,invHeight*totalSpacing-4},"",false,true};
|
||||
inventoryWindow.AddComponent("itemName",itemNameLabel);
|
||||
MenuLabel*itemDescriptionLabel=new MenuLabel{INVENTORY,vf2d{2+inventoryWindow.size.x/2,invHeight*totalSpacing+4+itemSpacing},"",true,true};
|
||||
inventoryWindow.AddComponent("itemDescription",itemDescriptionLabel);
|
||||
inventoryWindow->AddComponent("itemName",itemNameLabel);
|
||||
MenuLabel*itemDescriptionLabel=new MenuLabel{INVENTORY,vf2d{2+inventoryWindow->size.x/2,invHeight*totalSpacing+4+itemSpacing},"",true,true};
|
||||
inventoryWindow->AddComponent("itemDescription",itemDescriptionLabel);
|
||||
|
||||
return inventoryWindow;
|
||||
}
|
@ -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;
|
||||
|
@ -24,7 +24,7 @@ class Menu:IAttributable{
|
||||
friend class Crawler;
|
||||
friend class Player;
|
||||
static bool MOUSE_NAVIGATION;
|
||||
static std::map<MenuType,Menu>menus;
|
||||
static std::map<MenuType,Menu*>menus;
|
||||
|
||||
float buttonHoldTime=0;
|
||||
std::map<int/*Y*/,std::vector<MenuComponent*>>buttons; //Buttons are stored in rows followed by their column order.
|
||||
@ -35,6 +35,7 @@ class Menu:IAttributable{
|
||||
vf2d size; //Size in tiles (24x24), every menu will be tile-based
|
||||
|
||||
MenuComponent*draggingComponent=nullptr;
|
||||
Renderable r;
|
||||
public:
|
||||
Menu();
|
||||
Menu(vf2d pos,vf2d size);
|
||||
@ -53,9 +54,9 @@ private:
|
||||
void HoverMenuSelect(Crawler*game);
|
||||
void MenuSelect(Crawler*game);
|
||||
void CheckClickAndPerformMenuSelect(Crawler*game);
|
||||
static const Menu InitializeTestMenu();
|
||||
static const Menu InitializeTestSubMenu();
|
||||
static const Menu InitializeInventoryWindow();
|
||||
static Menu*InitializeTestMenu();
|
||||
static Menu*InitializeTestSubMenu();
|
||||
static Menu*InitializeInventoryWindow();
|
||||
//X (0-3), Y (0-2) for specific 9-patch tile (tiled version).
|
||||
static Renderable&GetPatchPart(int x,int y);
|
||||
|
||||
|
@ -1,26 +1,26 @@
|
||||
#include "Crawler.h"
|
||||
#include "MenuComponent.h"
|
||||
|
||||
const Menu Menu::InitializeTestMenu(){
|
||||
Menu testMenu(CENTERED,{24*8,24*6});
|
||||
Menu*Menu::InitializeTestMenu(){
|
||||
Menu*testMenu=new Menu(CENTERED,{24*8,24*6});
|
||||
|
||||
MenuFunc quitWindow=[](MenuFuncData data){
|
||||
data.menu.stack.clear();
|
||||
};
|
||||
|
||||
testMenu.AddComponent("Close",new MenuComponent(TEST,{{24*1,24*1},{24*2,24*1}},"Close",quitWindow));
|
||||
testMenu->AddComponent("Close",new MenuComponent(TEST,{{24*1,24*1},{24*2,24*1}},"Close",quitWindow));
|
||||
|
||||
MenuFunc doNothing=[](MenuFuncData data){};
|
||||
|
||||
testMenu.AddComponent("Test",new MenuComponent(TEST,{{24*4,24*1},{24*3,24*1}},"Test",doNothing));
|
||||
testMenu->AddComponent("Test",new MenuComponent(TEST,{{24*4,24*1},{24*3,24*1}},"Test",doNothing));
|
||||
|
||||
MenuFunc HurtPlayer=[](MenuFuncData data){
|
||||
data.game->GetPlayer()->Hurt(20,data.game->GetPlayer()->OnUpperLevel(),data.game->GetPlayer()->GetZ());
|
||||
};
|
||||
|
||||
testMenu.AddComponent("Hurt Player",new MenuComponent(TEST,{{24*4,24*3},{24*3,24*1}},"Hurt Player",HurtPlayer));
|
||||
testMenu->AddComponent("Hurt Player",new MenuComponent(TEST,{{24*4,24*3},{24*3,24*1}},"Hurt Player",HurtPlayer));
|
||||
|
||||
testMenu.AddComponent("Open SubMenu",new MenuComponent(TEST,{{24*2,24*4.5},{24*4,24*1}},"Open Another\n Menu",TEST_2,doNothing));
|
||||
testMenu->AddComponent("Open SubMenu",new MenuComponent(TEST,{{24*2,24*4.5},{24*4,24*1}},"Open Another\n Menu",TEST_2,doNothing));
|
||||
|
||||
return testMenu;
|
||||
}
|
@ -8,19 +8,19 @@
|
||||
INCLUDE_GFX
|
||||
typedef Attribute A;
|
||||
|
||||
const Menu Menu::InitializeTestSubMenu(){
|
||||
Menu testSubMenu({30,30},{24*4,24*5});
|
||||
Menu*Menu::InitializeTestSubMenu(){
|
||||
Menu*testSubMenu=new Menu({30,30},{24*4,24*5});
|
||||
|
||||
MenuFunc goBack=[](MenuFuncData data){
|
||||
data.menu.stack.pop_back();
|
||||
};
|
||||
|
||||
testSubMenu.AddComponent("BACK",new MenuComponent(TEST_2,{{24*1,24*1},{24*2,24*1}},"Go Back",goBack));
|
||||
testSubMenu->AddComponent("BACK",new MenuComponent(TEST_2,{{24*1,24*1},{24*2,24*1}},"Go Back",goBack));
|
||||
|
||||
int index=0;
|
||||
for(auto&theme:Menu::themes){
|
||||
if(theme.displayName==Menu::themeSelection){
|
||||
testSubMenu.I(A::INDEXED_THEME)=index;
|
||||
testSubMenu->I(A::INDEXED_THEME)=index;
|
||||
break;
|
||||
}
|
||||
index++;
|
||||
@ -43,9 +43,9 @@ const Menu Menu::InitializeTestSubMenu(){
|
||||
}
|
||||
};
|
||||
|
||||
testSubMenu.AddComponent("PREV_THEME",new MenuComponent(TEST_2,{{24*-0.5,24*3},{24*1,24*1}},"<",themePrev));
|
||||
testSubMenu->AddComponent("PREV_THEME",new MenuComponent(TEST_2,{{24*-0.5,24*3},{24*1,24*1}},"<",themePrev));
|
||||
|
||||
testSubMenu.AddComponent("THEME_DISPLAY",new MenuLabel(TEST_2,{{24*0.5,24*3},{24*3,24*1}},"Theme\n"+Menu::themes[themeSelection].GetThemeName()));
|
||||
testSubMenu->AddComponent("THEME_DISPLAY",new MenuLabel(TEST_2,{{24*0.5,24*3},{24*3,24*1}},"Theme\n"+Menu::themes[themeSelection].GetThemeName()));
|
||||
|
||||
MenuFunc themeNext=[](MenuFuncData data){
|
||||
data.menu.I(A::INDEXED_THEME)=(size_t(data.menu.I(A::INDEXED_THEME))+1)%themes.size();
|
||||
@ -60,7 +60,7 @@ const Menu Menu::InitializeTestSubMenu(){
|
||||
}
|
||||
};
|
||||
|
||||
testSubMenu.AddComponent("NEXT_THEME",new MenuComponent(TEST_2,{{24*3.5,24*3},{24*1,24*1}},">",themeNext));
|
||||
testSubMenu->AddComponent("NEXT_THEME",new MenuComponent(TEST_2,{{24*3.5,24*3},{24*1,24*1}},">",themeNext));
|
||||
|
||||
return testSubMenu;
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
#define VERSION_MAJOR 0
|
||||
#define VERSION_MINOR 2
|
||||
#define VERSION_PATCH 0
|
||||
#define VERSION_BUILD 1895
|
||||
#define VERSION_BUILD 1899
|
||||
|
||||
#define stringify(a) stringify_(a)
|
||||
#define stringify_(a) #a
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user