//We don't have to actually populate the inventory list because now when an item gets added, it will automatically add the correct component in for us.
//We must lock the values before calling sort. Sort seems to try and create new accesses.
buttons.SetInitialized();
keyboardButtons.SetInitialized();
//We make an assumption that menu components are supposed to be in left-to-right order. Sometimes we may add things out-of-order, so this fixes the problem by sorting the items afterwards.
//Update the inventory with a new inventory slot, since there's one additional item to interact with now.
std::vector<std::string>&inv=Inventory::get(cat);
MenuTypeinventoryWindow;
if(cat=="Consumables"){
inventoryWindow=INVENTORY;
}else
if(cat=="Equipment"){
//TODO: Update different inventories depending on what the item's category is.
std::cout<<"WARNING! Unimplemented inventory slot addition for category "<<cat<<"!"<<std::endl;
return;//Currenly a no-op
}else
if(cat=="Accesories"){
//TODO: Update different inventories depending on what the item's category is.
std::cout<<"WARNING! Unimplemented inventory slot addition for category "<<cat<<"!"<<std::endl;
return;//Currenly a no-op
}else
if(cat=="Materials"){
//TODO: Update different inventories depending on what the item's category is.
std::cout<<"WARNING! Unimplemented inventory slot addition for category "<<cat<<"!"<<std::endl;
return;//Currenly a no-op
}else{
throw;
std::cout<<"WARNING! Attempting to add an inventory to a category that does not exist. THIS SHOULD NOT BE HAPPENING!"<<std::endl;
}
//HACK ALERT!! We make a very bold assumption here that every inventory window will contain a ScrollableWindowComponent called "inventory"! Because it's a safemap, if it doesn't exist it will let us know as such, we won't include any extra checks here.
std::map<int/*Y*/,std::vector<MenuComponent*>>buttons;//Buttons are stored in rows followed by their column order.
std::map<int/*Y*/,std::vector<MenuComponent*>>keyboardButtons;//Button ordered storage for keyboard/menu
std::vector<MenuComponent*>displayComponents;//Components that are only for displaying purposes.
vi2dselection={-1,-1};
vi2dlastActiveMousePos={};
@ -50,11 +47,13 @@ public:
staticstd::map<MenuType,Menu*>menus;
vf2dpos;//Specify the upper-left corner of the window. Using CENTERED will always put this where the upper-left corner would center the window.
vf2dsize;//Size in tiles (24x24), every menu will be tile-based
safemap<int/*Y*/,std::vector<MenuComponent*>>buttons;//Buttons are stored in rows followed by their column order.
safemap<int/*Y*/,std::vector<MenuComponent*>>keyboardButtons;//Button ordered storage for keyboard/menu
staticTheme&GetCurrentTheme();
boolUsingMouseNavigation();
voidSetMouseNavigation(boolmouseNavigation);
staticvoidInventorySlotsUpdated(ITCategorycat);//Called whenever an inventory item gets added to the player's inventory, thus increasing the total number of slots in our bag.
private:
Menu(vf2dpos,vf2dsize);
voidHoverMenuSelect(Crawler*game);
@ -65,6 +64,7 @@ private:
staticvoidInitializeTestMenu();
staticvoidInitializeTestSubMenu();
staticvoidInitializeInventoryWindow();
staticvoidInitializeCharacterInfoWindow();
//X (0-3), Y (0-2) for specific 9-patch tile (tiled version).
booldisabled=false;//If set to true, this component will not be rendered or updated.
boolrenderInMain=true;//If set to false, this component is the responsibility of some other windowing system and won't be rendered or updated via the main window loop.
boolvalid=true;//If set to false, this would cause the component to be removed.
std::cout<<"WARNING! Attempted to erase key "<<button->GetPos().y<<" from button map, but the list still exists!";
throw;
}
}
}
virtualvoidRemoveEmptySlots(){
//Algorithm will iterate through all slots, finding blank slots. Each time a blank slot is found, all items will shift over by one, and then the last item will be removed. Repeat until all slots iterated through.
for(inti=0;i<components.size();i++){
MenuComponent*button=components[i];
button->Update(game);//We have to call update to update the validation state.
//HACK ALERT!! This only gets called on inventories...And only on inventory items, which would have the valid flag set. We only care about components that are inventory slots.
if(!button->valid){
for(intj=i;j<components.size()-1;j++){
//Take the item in the next slot and move it to this slot.
std::cout<<"WARNING! Trying to get non-existent key "<<key<<"!"<<std::endl;
throw;
@ -35,6 +35,10 @@ public:
size_tsize(){
returnmap.size();
}
//Unlocks the map so items can be added to it again. USE WITH CAUTION! And make sure to lock the map again.
voidUnlock(){
initialized=false;
}
//Clears the entire map and unlocks the map so items can be added to it again.
voidReset(){
initialized=false;
@ -46,6 +50,9 @@ public:
autoend()const{
returnmap.end();
}
size_terase(constT&key){
returnmap.erase(key);
}
};
//A class that has an initialization lock so that when the lock is activated, any further gets that are missing items in it will report themselves for easier debugging detection.