forked from Mirrors/openclonk
Production menus are now updated if the production queue gets an "outside" change
parent
1d994a32b9
commit
a9a317d5c1
|
@ -175,6 +175,13 @@ private func GetQueueIndex(object item)
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func HasCommander(object producer)
|
||||||
|
{
|
||||||
|
if (menu_commander == producer)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/* Callbacks from the menu items, to be translated into commands for the producer. */
|
/* Callbacks from the menu items, to be translated into commands for the producer. */
|
||||||
|
|
||||||
// Called when an item has been selected (left mouse button).
|
// Called when an item has been selected (left mouse button).
|
||||||
|
@ -184,13 +191,13 @@ public func OnItemSelection(object item)
|
||||||
if (IsProductItem(item))
|
if (IsProductItem(item))
|
||||||
{
|
{
|
||||||
menu_commander->AddToQueue(item->GetSymbol(), 1);
|
menu_commander->AddToQueue(item->GetSymbol(), 1);
|
||||||
UpdateMenuQueue(menu_commander);
|
//UpdateMenuQueue(menu_commander);
|
||||||
}
|
}
|
||||||
// If item is from queue, remove one from queue.
|
// If item is from queue, remove one from queue.
|
||||||
if (IsQueueItem(item))
|
if (IsQueueItem(item))
|
||||||
{
|
{
|
||||||
menu_commander->RemoveFromQueue(GetQueueIndex(item), 1);
|
menu_commander->RemoveFromQueue(GetQueueIndex(item), 1);
|
||||||
UpdateMenuQueue(menu_commander);
|
//UpdateMenuQueue(menu_commander);
|
||||||
}
|
}
|
||||||
return _inherited(item, ...);
|
return _inherited(item, ...);
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,6 +161,9 @@ public func AddToQueue(id product_id, int amount)
|
||||||
// Otherwise create a new entry in the queue.
|
// Otherwise create a new entry in the queue.
|
||||||
else
|
else
|
||||||
queue[pos] = { Product = product_id, Amount = amount };
|
queue[pos] = { Product = product_id, Amount = amount };
|
||||||
|
// Notify all production menus open for this producer.
|
||||||
|
for (var menu in FindObjects(Find_ID(Library_ProductionMenu), Find_Func("HasCommander", this)))
|
||||||
|
menu->UpdateMenuQueue(this);
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,14 +180,18 @@ public func RemoveFromQueue(int pos, int amount)
|
||||||
return;
|
return;
|
||||||
// Reduce and check amount.
|
// Reduce and check amount.
|
||||||
queue[pos].Amount -= amount;
|
queue[pos].Amount -= amount;
|
||||||
if (queue[pos].Amount > 0)
|
// If amount <= 0, remove item from queue.
|
||||||
return;
|
|
||||||
// If amount < 0, remove item from queue.
|
|
||||||
// From pos onwards queue items should be shift downwards.
|
// From pos onwards queue items should be shift downwards.
|
||||||
|
if (queue[pos].Amount <= 0)
|
||||||
|
{
|
||||||
for (var i = pos; i < GetLength(queue); i++)
|
for (var i = pos; i < GetLength(queue); i++)
|
||||||
queue[i] = queue[i+1];
|
queue[i] = queue[i+1];
|
||||||
// Reduce queue size by one.
|
// Reduce queue size by one.
|
||||||
SetLength(queue, length - 1);
|
SetLength(queue, length - 1);
|
||||||
|
}
|
||||||
|
// Notify all production menus open for this producer.
|
||||||
|
for (var menu in FindObjects(Find_ID(Library_ProductionMenu), Find_Func("HasCommander", this)))
|
||||||
|
menu->UpdateMenuQueue(this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue