From eda4c49301db3e541b15a8ef5e8dcaf0a08ecb2b Mon Sep 17 00:00:00 2001 From: Mhoram Kerbin Date: Mon, 22 Aug 2022 12:10:31 +0200 Subject: [PATCH] Change functionality of cancel route to reduce route Previously the canceling of a route was only possible when all resources at the destination were unused. This patch changes this behavior, so that the cancel route button now reduces the route as much as possible. This QoL change helps with managing complicated route-setups where resources are partially used by Hoppers somewhere in a sequential transfer route. This is done by calculating the maximal reducible amount of resources and using this number for the cancellation. --- .../WOLF/WOLF/GUI/WOLF_GuiManageTransfers.cs | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/Source/WOLF/WOLF/GUI/WOLF_GuiManageTransfers.cs b/Source/WOLF/WOLF/GUI/WOLF_GuiManageTransfers.cs index e855ea933..ff1885935 100644 --- a/Source/WOLF/WOLF/GUI/WOLF_GuiManageTransfers.cs +++ b/Source/WOLF/WOLF/GUI/WOLF_GuiManageTransfers.cs @@ -330,19 +330,38 @@ protected override void DrawWindowContents(int windowId) GUILayout.BeginHorizontal(); if (GUILayout.Button(UIHelper.deleteSymbol, UIHelper.buttonStyle, GUILayout.Width(22), GUILayout.Height(22))) { - var result = _selectedRoute.RemoveResource(resource.Key, resource.Value); - if (result is BrokenNegotiationResult) + var amount = resource.Value; + foreach (var destinationResource in _selectedRoute.DestinationDepot.GetResources()) { - foreach (var brokenResource in (result as BrokenNegotiationResult).BrokenDependencies) + if (destinationResource.ResourceName == resource.Key) { - Messenger.DisplayMessage(string.Format(CANNOT_CANCEL_TRANSFER_MESSAGE, brokenResource)); + if (destinationResource.Incoming - destinationResource.Outgoing < amount) + { + amount = destinationResource.Incoming - destinationResource.Outgoing; + } + break; } } - else if (result is FailedNegotiationResult) + if (amount <= 0) { - foreach (var missingResource in (result as FailedNegotiationResult).MissingResources) + Messenger.DisplayMessage(string.Format(CANNOT_CANCEL_TRANSFER_MESSAGE, resource.Key)); + } + else + { + var result = _selectedRoute.RemoveResource(resource.Key, amount); + if (result is BrokenNegotiationResult) + { + foreach (var brokenResource in (result as BrokenNegotiationResult).BrokenDependencies) + { + Messenger.DisplayMessage(string.Format(CANNOT_CANCEL_TRANSFER_MESSAGE, brokenResource)); + } + } + else if (result is FailedNegotiationResult) { - Messenger.DisplayMessage(string.Format("Could not add {0} back to origin depot. This is probably a bug.", missingResource.Key)); + foreach (var missingResource in (result as FailedNegotiationResult).MissingResources) + { + Messenger.DisplayMessage(string.Format("Could not add {0} back to origin depot. This is probably a bug.", missingResource.Key)); + } } } }