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:
+5
-3
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user