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:
2023-12-27 20:40:01 -06:00
parent f2e3405b5b
commit bd066ee787
22 changed files with 430 additions and 217 deletions
+5 -3
View File
@@ -318,7 +318,7 @@ void Menu::Draw(Crawler*game){
MenuComponent*selectedComponent=buttons[selection.y][selection.x];
vf2d drawOffset{};
if(selectedComponent->parentComponent!=nullptr){
ScrollableWindowComponent*scrollableComponent=dynamic_cast<ScrollableWindowComponent*>(selectedComponent->parentComponent);
ScrollableWindowComponent*scrollableComponent=DYNAMIC_CAST<ScrollableWindowComponent*>(selectedComponent->parentComponent);
if(scrollableComponent!=nullptr){
drawOffset+=scrollableComponent->GetScrollAmount();
}
@@ -582,14 +582,16 @@ void Menu::SetMouseNavigation(bool mouseNavigation){
void Menu::InventorySlotsUpdated(ITCategory cat){
//Update the inventory with a new inventory slot, since there's one additional item to interact with now.
for(MenuComponent*component:inventoryListeners.at(cat)){
component->OnInventorySlotsUpdate(cat);
InventoryScrollableWindowComponent*comp=DYNAMIC_CAST<InventoryScrollableWindowComponent*>(component); //HACK ALERT! We're assuming that these must be these classes otherwise they have no reason to even be using these listeners. Make sure that the lowest base class that requires these implements these functions!!!
comp->OnInventorySlotsUpdate(cat);
}
}
void Menu::MerchantInventorySlotsUpdated(ITCategory cat){
//Update the inventory with a new inventory slot, since there's one additional item to interact with now.
for(MenuComponent*component:merchantInventoryListeners.at(cat)){
component->OnInventorySlotsUpdate(cat);
InventoryScrollableWindowComponent*comp=DYNAMIC_CAST<InventoryScrollableWindowComponent*>(component); //HACK ALERT! We're assuming that these must be these classes otherwise they have no reason to even be using these listeners. Make sure that the lowest base class that requires these implements these functions!!!
comp->OnInventorySlotsUpdate(cat);
}
}