Refactored dynamic cast to do internal error checking. Refactored all inventory and button slot update functions in menu components so they no longer require virtual dispatch when all we require is some passing of lamba functions to update inventories.
This commit is contained in:
@@ -61,7 +61,7 @@ void Menu::InitializeConsumableInventoryWindow(){
|
||||
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=dynamic_cast<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.
|
||||
MenuItemButton*button2=DYNAMIC_CAST<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==nullptr)ERR("Could not cast item to a MenuItemButton*!");
|
||||
if(button2==button){
|
||||
if(button2->selected!=-1){
|
||||
@@ -77,7 +77,7 @@ void Menu::InitializeConsumableInventoryWindow(){
|
||||
button->selected=data.menu.I(A::LOADOUT_SLOT);
|
||||
data.game->SetLoadoutItem(button->selected,button->GetItem().lock()->ActualName());
|
||||
return true;
|
||||
})END;
|
||||
},InventoryCreator::Player_InventoryUpdate)END;
|
||||
Menu::AddInventoryListener(consumableWindow,"Consumables");
|
||||
|
||||
//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.
|
||||
|
||||
Reference in New Issue
Block a user