Corrected bug for removing sub-component items that were not selectable (and thus, were never added to button navigation lists)
This commit is contained in:
parent
a139072d68
commit
195cc31a7b
@ -56,7 +56,28 @@ void Menu::InitializeConsumableInventoryWindow(){
|
|||||||
|
|
||||||
inventoryWindow->I(A::LOADOUT_SLOT)=0;
|
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);
|
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.
|
//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.
|
||||||
|
@ -44,11 +44,14 @@ class InventoryScrollableWindowComponent:public ScrollableWindowComponent{
|
|||||||
private:
|
private:
|
||||||
std::string itemNameLabelName;
|
std::string itemNameLabelName;
|
||||||
std::string itemDescriptionLabelName;
|
std::string itemDescriptionLabelName;
|
||||||
|
bool inventoryButtonsActive=true;
|
||||||
|
std::function<bool(MenuFuncData)>inventoryButtonClickAction;
|
||||||
protected:
|
protected:
|
||||||
ITCategory inventoryType;
|
ITCategory inventoryType;
|
||||||
public:
|
public:
|
||||||
inline InventoryScrollableWindowComponent(MenuType parent,geom2d::rect<float>rect,ITCategory invType,std::string itemNameLabelName,std::string itemDescriptionLabelName,ComponentAttr attributes=ComponentAttr::BACKGROUND|ComponentAttr::OUTLINE)
|
inline InventoryScrollableWindowComponent(MenuType parent,geom2d::rect<float>rect,ITCategory invType,std::string itemNameLabelName,std::string itemDescriptionLabelName,std::function<bool(MenuFuncData)>inventoryButtonClickAction,bool inventoryButtonsActive=true,ComponentAttr attributes=ComponentAttr::BACKGROUND|ComponentAttr::OUTLINE)
|
||||||
:ScrollableWindowComponent(parent,rect,attributes),inventoryType(invType),itemNameLabelName(itemNameLabelName),itemDescriptionLabelName(itemDescriptionLabelName){
|
:ScrollableWindowComponent(parent,rect,attributes),inventoryType(invType),itemNameLabelName(itemNameLabelName),itemDescriptionLabelName(itemDescriptionLabelName),
|
||||||
|
inventoryButtonClickAction(inventoryButtonClickAction),inventoryButtonsActive(inventoryButtonsActive){
|
||||||
Menu::AddInventoryListener(this,invType);
|
Menu::AddInventoryListener(this,invType);
|
||||||
}
|
}
|
||||||
virtual inline void Update(Crawler*game)override{
|
virtual inline void Update(Crawler*game)override{
|
||||||
@ -67,22 +70,24 @@ public:
|
|||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
virtual inline void RemoveButton(MenuComponent*button){
|
virtual inline void RemoveButton(MenuComponent*button){
|
||||||
std::vector<MenuComponent*>&buttonList=Menu::menus[button->parentMenu]->buttons.at(button->GetPos().y);
|
if(button->selectable){
|
||||||
std::vector<MenuComponent*>&keyboardButtonList=Menu::menus[button->parentMenu]->keyboardButtons.at(button->GetPos().y);
|
std::vector<MenuComponent*>&buttonList=Menu::menus[button->parentMenu]->buttons.at(button->GetPos().y);
|
||||||
size_t removedCount=0;
|
std::vector<MenuComponent*>&keyboardButtonList=Menu::menus[button->parentMenu]->keyboardButtons.at(button->GetPos().y);
|
||||||
removedCount+=std::erase(buttonList,button);
|
size_t removedCount=0;
|
||||||
removedCount+=std::erase(keyboardButtonList,button);
|
removedCount+=std::erase(buttonList,button);
|
||||||
if(removedCount!=2){
|
removedCount+=std::erase(keyboardButtonList,button);
|
||||||
std::cout<<"WARNING! Attempted to remove buttons from button listing, but not found!";
|
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 "<<button->GetPos().y<<" from button map, but the list still exists!")
|
|
||||||
}
|
}
|
||||||
}
|
if(buttonList.size()==0){
|
||||||
if(keyboardButtonList.size()==0){
|
if(!Menu::menus[button->parentMenu]->buttons.erase(button->GetPos().y)){
|
||||||
if(!Menu::menus[button->parentMenu]->keyboardButtons.erase(button->GetPos().y)){
|
ERR("WARNING! Attempted to erase key "<<button->GetPos().y<<" from button map, but the list still exists!")
|
||||||
ERR("WARNING! Attempted to erase key "<<button->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 "<<button->GetPos().y<<" from button map, but the list still exists!")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -122,29 +127,7 @@ protected:
|
|||||||
int buttonSize="ThemeGlobal.InventoryButtonSize"_I;
|
int buttonSize="ThemeGlobal.InventoryButtonSize"_I;
|
||||||
int totalSpacing="ThemeGlobal.InventoryItemSpacing"_I+buttonSize;
|
int totalSpacing="ThemeGlobal.InventoryItemSpacing"_I+buttonSize;
|
||||||
|
|
||||||
MenuFunc useItemFunc=[&](MenuFuncData data){
|
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};
|
||||||
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};
|
|
||||||
AddComponent(Menu::menus[parentMenu],"item_"+cat+"_"+std::to_string(itemIndex),button);
|
AddComponent(Menu::menus[parentMenu],"item_"+cat+"_"+std::to_string(itemIndex),button);
|
||||||
}else
|
}else
|
||||||
if(components.size()>invSize){ //There are empty spots, so let's clean up.
|
if(components.size()>invSize){ //There are empty spots, so let's clean up.
|
||||||
|
@ -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);
|
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);
|
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 Outline",monsterLootOutline);
|
||||||
levelCompleteWindow->AddComponent("Monster Loot Label",monsterLootLabel);
|
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);
|
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);
|
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 Outline",stageLootOutline);
|
||||||
levelCompleteWindow->AddComponent("Stage Loot Label",stageLootLabel);
|
levelCompleteWindow->AddComponent("Stage Loot Label",stageLootLabel);
|
||||||
|
@ -191,7 +191,7 @@ void Menu::HoverMenuSelect(Crawler*game){
|
|||||||
|
|
||||||
void Menu::MenuSelect(Crawler*game){
|
void Menu::MenuSelect(Crawler*game){
|
||||||
if(selection==vi2d{-1,-1}||buttons[selection.y][selection.x]->disabled)return;
|
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(buttonStillValid){
|
||||||
if(buttons[selection.y][selection.x]->menuDest!=MenuType::ENUM_END){
|
if(buttons[selection.y][selection.x]->menuDest!=MenuType::ENUM_END){
|
||||||
if(stack.size()<32){
|
if(stack.size()<32){
|
||||||
|
@ -41,6 +41,7 @@ SUCH DAMAGE.
|
|||||||
|
|
||||||
class Crawler;
|
class Crawler;
|
||||||
class MenuComponent;
|
class MenuComponent;
|
||||||
|
class ScrollableWindowComponent;
|
||||||
|
|
||||||
enum MenuType{
|
enum MenuType{
|
||||||
TEST,
|
TEST,
|
||||||
@ -149,6 +150,7 @@ struct MenuFuncData{
|
|||||||
Menu&menu;
|
Menu&menu;
|
||||||
Crawler*game;
|
Crawler*game;
|
||||||
MenuComponent*component;
|
MenuComponent*component;
|
||||||
|
ScrollableWindowComponent*parentComponent;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::function<bool(MenuFuncData)> MenuFunc;
|
typedef std::function<bool(MenuFuncData)> MenuFunc;
|
@ -54,8 +54,8 @@ private:
|
|||||||
std::string itemDescriptionLabelName;
|
std::string itemDescriptionLabelName;
|
||||||
public:
|
public:
|
||||||
int selected=-1; //0-2 representing which loadout slot this item consumes. -1 means not selected.
|
int selected=-1; //0-2 representing which loadout slot this item consumes. -1 means not selected.
|
||||||
inline MenuItemButton(MenuType parent,geom2d::rect<float>rect,std::vector<Item>&invRef,int invIndex,MenuFunc onClick,MenuType itemDescriptionMenu,std::string itemNameLabelName,std::string itemDescriptionLabelName)
|
inline MenuItemButton(MenuType parent,geom2d::rect<float>rect,std::vector<Item>&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),invRef(invRef),inventoryIndex(invIndex),itemDescriptionMenu(itemDescriptionMenu),itemNameLabelName(itemNameLabelName),itemDescriptionLabelName(itemDescriptionLabelName){
|
:MenuIconButton(parent,rect,invRef.size()>invIndex?invRef[invIndex].Decal():nullptr,onClick,attributes),invRef(invRef),inventoryIndex(invIndex),itemDescriptionMenu(itemDescriptionMenu),itemNameLabelName(itemNameLabelName),itemDescriptionLabelName(itemDescriptionLabelName){
|
||||||
draggable=false;
|
draggable=false;
|
||||||
valid=invRef.size()>invIndex;
|
valid=invRef.size()>invIndex;
|
||||||
}
|
}
|
||||||
|
@ -229,4 +229,7 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
virtual void Cleanup()override{}
|
virtual void Cleanup()override{}
|
||||||
|
inline std::vector<MenuComponent*>&GetComponents(){
|
||||||
|
return components;
|
||||||
|
}
|
||||||
};
|
};
|
@ -35,7 +35,7 @@ SUCH DAMAGE.
|
|||||||
#define VERSION_MAJOR 0
|
#define VERSION_MAJOR 0
|
||||||
#define VERSION_MINOR 2
|
#define VERSION_MINOR 2
|
||||||
#define VERSION_PATCH 1
|
#define VERSION_PATCH 1
|
||||||
#define VERSION_BUILD 2981
|
#define VERSION_BUILD 2987
|
||||||
|
|
||||||
#define stringify(a) stringify_(a)
|
#define stringify(a) stringify_(a)
|
||||||
#define stringify_(a) #a
|
#define stringify_(a) #a
|
||||||
|
Loading…
x
Reference in New Issue
Block a user