diff --git a/Crawler/InventoryConsumableWindow.cpp b/Crawler/InventoryConsumableWindow.cpp index 1cf56d9c..804836c9 100644 --- a/Crawler/InventoryConsumableWindow.cpp +++ b/Crawler/InventoryConsumableWindow.cpp @@ -56,7 +56,28 @@ void Menu::InitializeConsumableInventoryWindow(){ inventoryWindow->I(A::LOADOUT_SLOT)=0; - InventoryScrollableWindowComponent*inventory=NEW InventoryScrollableWindowComponent(INVENTORY,{{1,20},{windowSize.x,float(totalSpacing*3-itemSpacing)}},"Consumables","itemName","itemDescription"); + InventoryScrollableWindowComponent*inventory=NEW InventoryScrollableWindowComponent(INVENTORY,{{1,20},{windowSize.x,float(totalSpacing*3-itemSpacing)}},"Consumables","itemName","itemDescription", + [&](MenuFuncData data){ + MenuItemButton*button=(MenuItemButton*)data.component; + data.game->ClearLoadoutItem(data.menu.I(A::LOADOUT_SLOT)); + for(MenuComponent*component:data.parentComponent->GetComponents()){ //HACK ALERT! If we are accessing a parent component, it's because we are dealing with a scrolling window component, which has sub-components. So this should be a safe cast to make. + if(component->GetName().starts_with("item")){ + MenuItemButton*button2=(MenuItemButton*)component;//HACK ALERT! This is probably an item since we populated item lists using this name for the components. So we assume these are MenuItemButton classes. + if(button2==button){ + if(button2->selected!=-1){ + data.game->ClearLoadoutItem(button2->selected); + } + button2->selected=-1; + } + if(button2->selected==data.menu.I(A::LOADOUT_SLOT)){ + button2->selected=-1; + } + } + } + button->selected=data.menu.I(A::LOADOUT_SLOT); + data.game->SetLoadoutItem(button->selected,button->GetItem().Name()); + return true; + }); inventoryWindow->AddComponent("inventory",inventory); //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. diff --git a/Crawler/InventoryScrollableWindowComponent.h b/Crawler/InventoryScrollableWindowComponent.h index 2232e03a..2edea183 100644 --- a/Crawler/InventoryScrollableWindowComponent.h +++ b/Crawler/InventoryScrollableWindowComponent.h @@ -44,11 +44,14 @@ class InventoryScrollableWindowComponent:public ScrollableWindowComponent{ private: std::string itemNameLabelName; std::string itemDescriptionLabelName; + bool inventoryButtonsActive=true; + std::functioninventoryButtonClickAction; protected: ITCategory inventoryType; public: - inline InventoryScrollableWindowComponent(MenuType parent,geom2d::rectrect,ITCategory invType,std::string itemNameLabelName,std::string itemDescriptionLabelName,ComponentAttr attributes=ComponentAttr::BACKGROUND|ComponentAttr::OUTLINE) - :ScrollableWindowComponent(parent,rect,attributes),inventoryType(invType),itemNameLabelName(itemNameLabelName),itemDescriptionLabelName(itemDescriptionLabelName){ + inline InventoryScrollableWindowComponent(MenuType parent,geom2d::rectrect,ITCategory invType,std::string itemNameLabelName,std::string itemDescriptionLabelName,std::functioninventoryButtonClickAction,bool inventoryButtonsActive=true,ComponentAttr attributes=ComponentAttr::BACKGROUND|ComponentAttr::OUTLINE) + :ScrollableWindowComponent(parent,rect,attributes),inventoryType(invType),itemNameLabelName(itemNameLabelName),itemDescriptionLabelName(itemDescriptionLabelName), + inventoryButtonClickAction(inventoryButtonClickAction),inventoryButtonsActive(inventoryButtonsActive){ Menu::AddInventoryListener(this,invType); } virtual inline void Update(Crawler*game)override{ @@ -67,22 +70,24 @@ public: } protected: virtual inline void RemoveButton(MenuComponent*button){ - std::vector&buttonList=Menu::menus[button->parentMenu]->buttons.at(button->GetPos().y); - std::vector&keyboardButtonList=Menu::menus[button->parentMenu]->keyboardButtons.at(button->GetPos().y); - size_t removedCount=0; - removedCount+=std::erase(buttonList,button); - removedCount+=std::erase(keyboardButtonList,button); - if(removedCount!=2){ - std::cout<<"WARNING! Attempted to remove buttons from button listing, but not found!"; - } - if(buttonList.size()==0){ - if(!Menu::menus[button->parentMenu]->buttons.erase(button->GetPos().y)){ - ERR("WARNING! Attempted to erase key "<GetPos().y<<" from button map, but the list still exists!") + if(button->selectable){ + std::vector&buttonList=Menu::menus[button->parentMenu]->buttons.at(button->GetPos().y); + std::vector&keyboardButtonList=Menu::menus[button->parentMenu]->keyboardButtons.at(button->GetPos().y); + size_t removedCount=0; + removedCount+=std::erase(buttonList,button); + removedCount+=std::erase(keyboardButtonList,button); + if(removedCount!=2){ + std::cout<<"WARNING! Attempted to remove buttons from button listing, but not found!"; } - } - if(keyboardButtonList.size()==0){ - if(!Menu::menus[button->parentMenu]->keyboardButtons.erase(button->GetPos().y)){ - ERR("WARNING! Attempted to erase key "<GetPos().y<<" from button map, but the list still exists!") + if(buttonList.size()==0){ + if(!Menu::menus[button->parentMenu]->buttons.erase(button->GetPos().y)){ + ERR("WARNING! Attempted to erase key "<GetPos().y<<" from button map, but the list still exists!") + } + } + if(keyboardButtonList.size()==0){ + if(!Menu::menus[button->parentMenu]->keyboardButtons.erase(button->GetPos().y)){ + ERR("WARNING! Attempted to erase key "<GetPos().y<<" from button map, but the list still exists!") + } } } } @@ -121,30 +126,8 @@ protected: int buttonSize="ThemeGlobal.InventoryButtonSize"_I; int totalSpacing="ThemeGlobal.InventoryItemSpacing"_I+buttonSize; - - MenuFunc useItemFunc=[&](MenuFuncData data){ - MenuItemButton*button=(MenuItemButton*)data.component; - data.game->ClearLoadoutItem(data.menu.I(A::LOADOUT_SLOT)); - for(MenuComponent*component:components){ - if(component->GetName().starts_with("item")){ - MenuItemButton*button2=(MenuItemButton*)component;//HACK ALERT! This is probably an item since we populated item lists using this name for the components. So we assume these are MenuItemButton classes. - if(button2==button){ - if(button2->selected!=-1){ - data.game->ClearLoadoutItem(button2->selected); - } - button2->selected=-1; - } - if(button2->selected==data.menu.I(A::LOADOUT_SLOT)){ - button2->selected=-1; - } - } - } - button->selected=data.menu.I(A::LOADOUT_SLOT); - data.game->SetLoadoutItem(button->selected,button->GetItem().Name()); - return true; - }; - MenuItemButton*button=NEW MenuItemButton{parentMenu,{{float(totalSpacing*x),float(totalSpacing*y)},{float(buttonSize),float(buttonSize)}},Inventory::get(cat),itemIndex,useItemFunc,parentMenu,itemNameLabelName,itemDescriptionLabelName}; + MenuItemButton*button=NEW MenuItemButton{parentMenu,{{float(totalSpacing*x),float(totalSpacing*y)},{float(buttonSize),float(buttonSize)}},Inventory::get(cat),itemIndex,inventoryButtonClickAction,parentMenu,itemNameLabelName,itemDescriptionLabelName,inventoryButtonsActive?IconButtonAttr::SELECTABLE:IconButtonAttr::NOT_SELECTABLE}; AddComponent(Menu::menus[parentMenu],"item_"+cat+"_"+std::to_string(itemIndex),button); }else if(components.size()>invSize){ //There are empty spots, so let's clean up. diff --git a/Crawler/LevelCompleteWindow.cpp b/Crawler/LevelCompleteWindow.cpp index c8f061f8..db73cdf8 100644 --- a/Crawler/LevelCompleteWindow.cpp +++ b/Crawler/LevelCompleteWindow.cpp @@ -51,7 +51,7 @@ void Menu::InitializeLevelCompleteWindow(){ MenuComponent*monsterLootOutline=NEW MenuComponent(LEVEL_COMPLETE,{{0,32},{windowSize.size.x-80.f,72}},"",DO_NOTHING,ButtonAttr::UNSELECTABLE); MenuLabel*monsterLootLabel=NEW MenuLabel(LEVEL_COMPLETE,{{0,32},{windowSize.size.x-80.f,12}},"Monster Loot",1,ComponentAttr::LEFT_ALIGN|ComponentAttr::SHADOW|ComponentAttr::OUTLINE); - InventoryScrollableWindowComponent*monsterLootWindow=NEW InventoryScrollableWindowComponent(LEVEL_COMPLETE,{{0,44},{windowSize.size.x-80.f,60}},"Monster Loot","Monster Loot Popup Item Name","Monster Loot Popup Item Description"); + InventoryScrollableWindowComponent*monsterLootWindow=NEW InventoryScrollableWindowComponent(LEVEL_COMPLETE,{{0,44},{windowSize.size.x-80.f,60}},"Monster Loot","Monster Loot Popup Item Name","Monster Loot Popup Item Description",DO_NOTHING); levelCompleteWindow->AddComponent("Monster Loot Outline",monsterLootOutline); levelCompleteWindow->AddComponent("Monster Loot Label",monsterLootLabel); @@ -59,7 +59,7 @@ void Menu::InitializeLevelCompleteWindow(){ MenuComponent*stageLootOutline=NEW MenuComponent(LEVEL_COMPLETE,{{0,108},{windowSize.size.x-80.f,72}},"",DO_NOTHING,ButtonAttr::UNSELECTABLE); MenuLabel*stageLootLabel=NEW MenuLabel(LEVEL_COMPLETE,{{0,108},{windowSize.size.x-80.f,12}},"Stage Loot",1,ComponentAttr::LEFT_ALIGN|ComponentAttr::SHADOW|ComponentAttr::OUTLINE); - InventoryScrollableWindowComponent*stageLootWindow=NEW InventoryScrollableWindowComponent(LEVEL_COMPLETE,{{0,120},{windowSize.size.x-80.f,60}},"Stage Loot","Stage Loot Popup Item Name","Stage Loot Popup Item Description"); + InventoryScrollableWindowComponent*stageLootWindow=NEW InventoryScrollableWindowComponent(LEVEL_COMPLETE,{{0,120},{windowSize.size.x-80.f,60}},"Stage Loot","Stage Loot Popup Item Name","Stage Loot Popup Item Description",DO_NOTHING); levelCompleteWindow->AddComponent("Stage Loot Outline",stageLootOutline); levelCompleteWindow->AddComponent("Stage Loot Label",stageLootLabel); diff --git a/Crawler/Menu.cpp b/Crawler/Menu.cpp index ae5254cc..c997b2ab 100644 --- a/Crawler/Menu.cpp +++ b/Crawler/Menu.cpp @@ -191,7 +191,7 @@ void Menu::HoverMenuSelect(Crawler*game){ void Menu::MenuSelect(Crawler*game){ if(selection==vi2d{-1,-1}||buttons[selection.y][selection.x]->disabled)return; - bool buttonStillValid=buttons[selection.y][selection.x]->onClick(MenuFuncData{*this,game,buttons[selection.y][selection.x]}); + bool buttonStillValid=buttons[selection.y][selection.x]->onClick(MenuFuncData{*this,game,buttons[selection.y][selection.x],(ScrollableWindowComponent*)buttons[selection.y][selection.x]->parentComponent}); if(buttonStillValid){ if(buttons[selection.y][selection.x]->menuDest!=MenuType::ENUM_END){ if(stack.size()<32){ diff --git a/Crawler/Menu.h b/Crawler/Menu.h index a9ca3b0d..42b3395f 100644 --- a/Crawler/Menu.h +++ b/Crawler/Menu.h @@ -41,6 +41,7 @@ SUCH DAMAGE. class Crawler; class MenuComponent; +class ScrollableWindowComponent; enum MenuType{ TEST, @@ -149,6 +150,7 @@ struct MenuFuncData{ Menu&menu; Crawler*game; MenuComponent*component; + ScrollableWindowComponent*parentComponent; }; typedef std::function MenuFunc; \ No newline at end of file diff --git a/Crawler/MenuItemButton.h b/Crawler/MenuItemButton.h index c8a99bf7..867733ac 100644 --- a/Crawler/MenuItemButton.h +++ b/Crawler/MenuItemButton.h @@ -54,8 +54,8 @@ private: std::string itemDescriptionLabelName; public: int selected=-1; //0-2 representing which loadout slot this item consumes. -1 means not selected. - inline MenuItemButton(MenuType parent,geom2d::rectrect,std::vector&invRef,int invIndex,MenuFunc onClick,MenuType itemDescriptionMenu,std::string itemNameLabelName,std::string itemDescriptionLabelName) - :MenuIconButton(parent,rect,invRef.size()>invIndex?invRef[invIndex].Decal():nullptr,onClick),invRef(invRef),inventoryIndex(invIndex),itemDescriptionMenu(itemDescriptionMenu),itemNameLabelName(itemNameLabelName),itemDescriptionLabelName(itemDescriptionLabelName){ + inline MenuItemButton(MenuType parent,geom2d::rectrect,std::vector&invRef,int invIndex,MenuFunc onClick,MenuType itemDescriptionMenu,std::string itemNameLabelName,std::string itemDescriptionLabelName,IconButtonAttr attributes=IconButtonAttr::SELECTABLE) + :MenuIconButton(parent,rect,invRef.size()>invIndex?invRef[invIndex].Decal():nullptr,onClick,attributes),invRef(invRef),inventoryIndex(invIndex),itemDescriptionMenu(itemDescriptionMenu),itemNameLabelName(itemNameLabelName),itemDescriptionLabelName(itemDescriptionLabelName){ draggable=false; valid=invRef.size()>invIndex; } diff --git a/Crawler/ScrollableWindowComponent.h b/Crawler/ScrollableWindowComponent.h index e2b2e91c..d87aace7 100644 --- a/Crawler/ScrollableWindowComponent.h +++ b/Crawler/ScrollableWindowComponent.h @@ -229,4 +229,7 @@ public: return true; }; virtual void Cleanup()override{} + inline std::vector&GetComponents(){ + return components; + } }; \ No newline at end of file diff --git a/Crawler/Version.h b/Crawler/Version.h index a07c04d2..3f2c8046 100644 --- a/Crawler/Version.h +++ b/Crawler/Version.h @@ -35,7 +35,7 @@ SUCH DAMAGE. #define VERSION_MAJOR 0 #define VERSION_MINOR 2 #define VERSION_PATCH 1 -#define VERSION_BUILD 2981 +#define VERSION_BUILD 2987 #define stringify(a) stringify_(a) #define stringify_(a) #a