Change implementation of scrollable inventory component displays, make tabs on inventory window functional.

This commit is contained in:
2023-12-10 23:02:16 -06:00
parent 469bea4c5e
commit e4f63a3550
8 changed files with 78 additions and 45 deletions
+14 -7
View File
@@ -50,6 +50,8 @@ using ButtonAttr::UNSELECTABLE;
using ButtonAttr::UNSELECTABLE_VIA_KEYBOARD;
void Menu::InitializeInventoryWindow(){
static std::string lastInventoryTypeOpened="";
Menu*inventoryWindow=CreateMenu(INVENTORY,CENTERED,game->GetScreenSize()-vi2d{52,52});
inventoryWindow->ADD("Inventory Label",MenuLabel)({{0,0},{inventoryWindow->size.x-1,24}},"Inventory",2,SHADOW|OUTLINE|BACKGROUND)END;
@@ -61,11 +63,6 @@ void Menu::InitializeInventoryWindow(){
categories.push_back({category,DATA["ItemCategory"][category].GetInt(0)}); //We assume the first value becomes the sort order we wish to use.
}
std::sort(categories.begin(),categories.end(),[](std::pair<std::string,int>&cat1,std::pair<std::string,int>&cat2){return cat1.second<cat2.second;});
#pragma region Inventory Item Display
auto itemList=inventoryWindow->ADD("Inventory Display",InventoryScrollableWindowComponent)({{72,28},{150,inventoryWindow->size.y-44}},categories[0].first,"","",DO_NOTHING)END;
#pragma endregion
#pragma region Inventory Tabs
bool first=true;
@@ -76,15 +73,25 @@ void Menu::InitializeInventoryWindow(){
auto button=inventoryWindow->ADD(category+" Inventory Tab",MenuComponent)({{2,30+yOffset},{68,16}},category,MenuType::ENUM_END,
[&](MenuFuncData data){
Component<InventoryScrollableWindowComponent>(data.menu.GetType(),"Inventory Display")->SetInventoryType(data.component->S(A::CATEGORY_NAME));
//Close the old inventory window and show the proper one.
Component<InventoryScrollableWindowComponent>(data.menu.GetType(),"Inventory Display - "+lastInventoryTypeOpened)->Enable(false);
Component<MenuComponent>(data.menu.GetType(),lastInventoryTypeOpened+" Inventory Tab")->SetSelected(false);
Component<InventoryScrollableWindowComponent>(data.menu.GetType(),"Inventory Display - "+data.component->S(A::CATEGORY_NAME))->Enable(true);
Component<MenuComponent>(data.menu.GetType(),data.component->S(A::CATEGORY_NAME)+" Inventory Tab")->SetSelected(true);
lastInventoryTypeOpened=data.component->S(A::CATEGORY_NAME);
return true;
},{textScaling,1.f})END;
button->SetSelectionType(HIGHLIGHT);
button->S(A::CATEGORY_NAME)=category;
auto inventoryDisplay=inventoryWindow->ADD("Inventory Display - "+category,InventoryScrollableWindowComponent)({{72,28},{150,inventoryWindow->size.y-44}},category,"","",DO_NOTHING)END;
if(first){
lastInventoryTypeOpened=category;
button->onClick(MenuFuncData{*inventoryWindow,game,button}); //Simulate a click of this button if it's the top one for an initial inventory display.
}
inventoryDisplay->Enable(first);
yOffset+=20;
first=false;