Production menus are now updated if the production queue gets an "outside" change

Maikel de Vries 2011-12-30 20:32:13 +01:00
parent 1d994a32b9
commit a9a317d5c1
2 changed files with 24 additions and 10 deletions

View File

@ -175,6 +175,13 @@ private func GetQueueIndex(object item)
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. */
// Called when an item has been selected (left mouse button).
@ -184,13 +191,13 @@ public func OnItemSelection(object item)
if (IsProductItem(item))
{
menu_commander->AddToQueue(item->GetSymbol(), 1);
UpdateMenuQueue(menu_commander);
//UpdateMenuQueue(menu_commander);
}
// If item is from queue, remove one from queue.
if (IsQueueItem(item))
{
menu_commander->RemoveFromQueue(GetQueueIndex(item), 1);
UpdateMenuQueue(menu_commander);
//UpdateMenuQueue(menu_commander);
}
return _inherited(item, ...);
}

View File

@ -161,6 +161,9 @@ public func AddToQueue(id product_id, int amount)
// Otherwise create a new entry in the queue.
else
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;
}
@ -177,14 +180,18 @@ public func RemoveFromQueue(int pos, int amount)
return;
// Reduce and check amount.
queue[pos].Amount -= amount;
if (queue[pos].Amount > 0)
return;
// If amount < 0, remove item from queue.
// If amount <= 0, remove item from queue.
// From pos onwards queue items should be shift downwards.
for (var i = pos; i < GetLength(queue); i++)
queue[i] = queue[i+1];
// Reduce queue size by one.
SetLength(queue, length - 1);
if (queue[pos].Amount <= 0)
{
for (var i = pos; i < GetLength(queue); i++)
queue[i] = queue[i+1];
// Reduce queue size by one.
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;
}
@ -536,6 +543,6 @@ protected func RejectEntrance(object obj)
index++;
}
}
return true;
}