From b51d6f571a9bee17cc269bdca97fb9c3953e7bde Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Sat, 2 Dec 2023 00:40:07 -0600 Subject: [PATCH] Refactored window removing components for scrollable components. --- Crawler/CharacterMenuWindow.cpp | 38 ++++++++++++++++++-- Crawler/Crawler.cpp | 5 --- Crawler/InventoryScrollableWindowComponent.h | 26 -------------- Crawler/Item.cpp | 6 ++++ Crawler/Item.h | 2 ++ Crawler/MenuItemItemButton.h | 3 ++ Crawler/MonsterAttribute.h | 1 + Crawler/ScrollableWindowComponent.h | 28 +++++++++++++++ Crawler/Version.h | 2 +- 9 files changed, 77 insertions(+), 34 deletions(-) diff --git a/Crawler/CharacterMenuWindow.cpp b/Crawler/CharacterMenuWindow.cpp index ad65ecc6..9b675d66 100644 --- a/Crawler/CharacterMenuWindow.cpp +++ b/Crawler/CharacterMenuWindow.cpp @@ -65,7 +65,14 @@ void Menu::InitializeCharacterMenuWindow(){ MenuComponent*equipSelectionOutline=NEW MenuComponent(CHARACTER_MENU,{{123,36},{120,windowSize.y-37}},"",DO_NOTHING,ButtonAttr::UNSELECTABLE); ScrollableWindowComponent*equipmentList=NEW ScrollableWindowComponent(CHARACTER_MENU,{{123,36},{120,windowSize.y-37-24}}); MenuComponent*equipSelectionBottomOutline=NEW MenuComponent(CHARACTER_MENU,{{123,36+(windowSize.y-37-24)},{120,24}},"",DO_NOTHING,ButtonAttr::UNSELECTABLE); - MenuComponent*equipSelectionSelectButton=NEW MenuComponent(CHARACTER_MENU,{{123+12,36+(windowSize.y-37-24)+6},{96,12}},"Select",DO_NOTHING); + MenuComponent*equipSelectionSelectButton=NEW MenuComponent(CHARACTER_MENU,{{123+12,36+(windowSize.y-37-24)+6},{96,12}},"Select",[](MenuFuncData data){ + Component(data.component->parentMenu,"Equip Selection Outline")->Enable(false); + Component(data.component->parentMenu,"Equip List")->Enable(false); + Component(data.component->parentMenu,"Equip Selection Bottom Outline")->Enable(false); + Component(data.component->parentMenu,"Equip Selection Select Button")->Enable(false); + Component(data.component->parentMenu,"Character Rotating Display")->Enable(true); + return true; + }); equipSelectionOutline->Enable(false); equipmentList->Enable(false); @@ -89,16 +96,43 @@ void Menu::InitializeCharacterMenuWindow(){ } const std::arrayslotNames{"Helmet","Weapon","Armor","Gloves","Pants","Shoes","Ring 1","Ring 2"}; EquipSlot slot=EquipSlot(equipSlot); + MenuItemItemButton*equipmentSlot=NEW MenuItemItemButton(CHARACTER_MENU,{{x,y+36},{24,24}},Item::BLANK,MenuType::ENUM_END, [](MenuFuncData data){ + EquipSlot slot=EquipSlot(data.component->I(Attribute::EQUIP_TYPE)); + + std::vector&equips=Inventory::get("Equipment"); + std::vector&accessories=Inventory::get("Accessories"); + std::vectoravailableEquipment; + std::copy_if(equips.begin(),equips.end(),std::back_inserter(availableEquipment),[&](Item&it){ + return it.GetEquipSlot()&slot; + }); + + ScrollableWindowComponent*equipList=Component(data.component->parentMenu,"Equip List"); + equipList->RemoveAllComponents(); + int counter=0; + for(Item&it:availableEquipment){ + float xOffset=(counter%3)*26; + Item&itemInvRef=Inventory::GetItem(it.Name()); + MenuItemItemButton*equip=NEW MenuItemItemButton(CHARACTER_MENU,{{2+xOffset,2},{24,24}},itemInvRef,MenuType::ENUM_END,[](MenuFuncData data){ + MenuItemItemButton*comp=(MenuItemItemButton*)data.component; + Inventory::EquipItem(comp->GetItem(),EquipSlot(comp->I(Attribute::EQUIP_TYPE))); + return true; + },MenuType::ENUM_END,"",""); + equip->I(Attribute::EQUIP_TYPE)=int(slot); + equipList->AddComponent(Menu::menus[CHARACTER_MENU],"Equip Item "+std::to_string(counter),equip); + counter++; + } + Component(data.component->parentMenu,"Equip Selection Outline")->Enable(true); - Component(data.component->parentMenu,"Equip List")->Enable(true); + equipList->Enable(true); Component(data.component->parentMenu,"Equip Selection Bottom Outline")->Enable(true); Component(data.component->parentMenu,"Equip Selection Select Button")->Enable(true); Component(data.component->parentMenu,"Character Rotating Display")->Enable(false); return true; },MenuType::ENUM_END,"",""); PopupMenuLabel*equipmentLabel=NEW PopupMenuLabel(CHARACTER_MENU,{{labelX,labelY},{29,24}},slotNames[i],{0.5,1},ComponentAttr::SHADOW); + equipmentSlot->I(Attribute::EQUIP_TYPE)=int(slot); equipSlot<<=1; characterMenuWindow->AddComponent("Equip Slot "+slotNames[i],equipmentSlot); characterMenuWindow->AddComponent("Equip Label "+slotNames[i],equipmentLabel); diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index d801edfd..dc7b695c 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -200,11 +200,6 @@ bool Crawler::OnUserCreate(){ ValidateGameStatus(); //Checks to make sure everything has been initialized properly. - Item&it=Inventory::GetItem("Dummy Item 10"); - - Inventory::EquipItem(it,EquipSlot::RING1); - Inventory::EquipItem(it,EquipSlot::RING2); - return true; } diff --git a/Crawler/InventoryScrollableWindowComponent.h b/Crawler/InventoryScrollableWindowComponent.h index b22b85b2..b6c0816c 100644 --- a/Crawler/InventoryScrollableWindowComponent.h +++ b/Crawler/InventoryScrollableWindowComponent.h @@ -73,28 +73,6 @@ public: } } protected: - virtual inline void RemoveButton(MenuComponent*button){ - if(button->selectable){ - std::vector&buttonList=Menu::menus[button->parentMenu]->buttons.at(int(button->GetPos().y)); - std::vector&keyboardButtonList=Menu::menus[button->parentMenu]->keyboardButtons.at(int(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(int(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(int(button->GetPos().y))){ - ERR("WARNING! Attempted to erase key "<GetPos().y<<" from button map, but the list still exists!") - } - } - } - } inline void RemoveEmptySlots(){ //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(int i=0;iparentMenu]->components.at(components[components.size()-1]->name); //Now we have to fix up the keyboard button list. RemoveButton(lastButton); - Menu::menus[components[components.size()-1]->parentMenu]->components.erase(components[components.size()-1]->name); - //Now delete the last slot. - components.erase(components.end()-1); i--; //Subtract one from the index so we don't accidently skip slots. - delete lastButton; } } bounds=CalculateBounds(); //Recalculate the bounds as it's possible the width/height of the component has changed. diff --git a/Crawler/Item.cpp b/Crawler/Item.cpp index e46d0f0c..ee3d30f9 100644 --- a/Crawler/Item.cpp +++ b/Crawler/Item.cpp @@ -474,4 +474,10 @@ EquipSlot Inventory::GetSlotEquippedIn(Item&it){ }; Item*Inventory::GetEquip(EquipSlot slot){ return Inventory::equipment[slot]; +} +EquipSlot Item::GetEquipSlot(){ + return it->Slot(); +} +EquipSlot ItemInfo::Slot(){ + return slot; } \ No newline at end of file diff --git a/Crawler/Item.h b/Crawler/Item.h index bb465e36..acd322ad 100644 --- a/Crawler/Item.h +++ b/Crawler/Item.h @@ -109,6 +109,7 @@ public: std::string Name(); std::string Description(); ITCategory Category(); + EquipSlot GetEquipSlot(); Decal*Decal(); ItemScript&OnUseAction(); const ItemSet&GetItemSet()const; @@ -198,6 +199,7 @@ public: ItemScript&OnUseAction(); float CastTime(); float CooldownTime(); + EquipSlot Slot(); }; class ItemOverlay{ diff --git a/Crawler/MenuItemItemButton.h b/Crawler/MenuItemItemButton.h index 635127ad..1a07a0f4 100644 --- a/Crawler/MenuItemItemButton.h +++ b/Crawler/MenuItemItemButton.h @@ -61,6 +61,9 @@ public: draggable=false; valid=!itemRef.IsBlank(); } + inline Item&GetItem(){ + return itemRef; + } protected: virtual inline void Update(Crawler*game)override{ MenuIconButton::Update(game); diff --git a/Crawler/MonsterAttribute.h b/Crawler/MonsterAttribute.h index 911f8aff..36f2f17e 100644 --- a/Crawler/MonsterAttribute.h +++ b/Crawler/MonsterAttribute.h @@ -69,4 +69,5 @@ enum class Attribute{ CLASS_SELECTION, //A class name that represents what the menu's class is. LOADOUT_SLOT, //Which loadout slot we are selecting an item for. ALLOW_DRAGGING, //Whether or not to allow inventory dragging. + EQUIP_TYPE, }; \ No newline at end of file diff --git a/Crawler/ScrollableWindowComponent.h b/Crawler/ScrollableWindowComponent.h index 09cd8aba..e804a3a1 100644 --- a/Crawler/ScrollableWindowComponent.h +++ b/Crawler/ScrollableWindowComponent.h @@ -70,6 +70,34 @@ public: Menu::menus[parentMenu]->AddComponent(name+upButton->rect.pos.str()+"_"+upButton->rect.size.str(),upButton); Menu::menus[parentMenu]->AddComponent(name+downButton->rect.pos.str()+"_"+downButton->rect.size.str(),downButton); } + virtual inline void RemoveAllComponents(){ + for(MenuComponent*item:components){ + RemoveButton(item); + } + } + virtual inline void RemoveButton(MenuComponent*button){ + std::vector&buttonList=Menu::menus[button->parentMenu]->buttons.at(int(button->GetPos().y)); + std::vector&keyboardButtonList=Menu::menus[button->parentMenu]->keyboardButtons.at(int(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(int(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(int(button->GetPos().y))){ + ERR("WARNING! Attempted to erase key "<GetPos().y<<" from button map, but the list still exists!") + } + } + Menu::menus[button->parentMenu]->components.erase(button->GetName()); + components.erase(std::find(components.begin(),components.end(),button)); + delete button; + } protected: virtual inline void Update(Crawler*game)override{ MenuComponent::Update(game); diff --git a/Crawler/Version.h b/Crawler/Version.h index af2fca7b..3c269339 100644 --- a/Crawler/Version.h +++ b/Crawler/Version.h @@ -39,7 +39,7 @@ All rights reserved. #define VERSION_MAJOR 0 #define VERSION_MINOR 2 #define VERSION_PATCH 1 -#define VERSION_BUILD 3441 +#define VERSION_BUILD 3455 #define stringify(a) stringify_(a) #define stringify_(a) #a