Refactoring: Stackable: Moved HUD notifications to a separate function.

It should be OK that the new function calls OnInventoryChange() in Clonks on destruction now.
liquid_container
Mark 2016-03-11 17:10:41 +01:00
parent a61eac6ff3
commit 176856e276
1 changed files with 21 additions and 22 deletions

View File

@ -68,13 +68,7 @@ protected func Construction()
func Destruction()
{
var container = Contained();
if (container)
{
// has an extra slot
if (container->~HasExtraSlot())
container->~NotifyHUD();
}
NotifyContainer();
return _inherited(...);
}
@ -162,21 +156,7 @@ public func UpdateStackDisplay()
UpdatePicture();
UpdateMass();
UpdateName();
// notify hud
var container = Contained();
if (container)
{
// has an extra slot
if (container->~HasExtraSlot())
{
container->~NotifyHUD();
}
// is a clonk with new inventory system
else
{
container->~OnInventoryChange();
}
}
NotifyContainer();
}
private func UpdatePicture()
@ -198,6 +178,25 @@ private func UpdateMass()
SetMass(GetID()->GetMass() * Max(GetStackCount(), 1) / InitialStackCount());
}
private func NotifyContainer()
{
// notify hud
var container = Contained();
if (container)
{
// has an extra slot
if (container->~HasExtraSlot())
{
container->~NotifyHUD();
}
// is a clonk with new inventory system
else
{
container->~OnInventoryChange();
}
}
}
/*
Try to merge packs BEFORE entering the container.
That means that a container can not prevent objects stacking into it.