diff --git a/Pulsar4X/Pulsar4X.Client/EntityManagement/CreateTransferWindow.cs b/Pulsar4X/Pulsar4X.Client/EntityManagement/CreateTransferWindow.cs index 6006bd040..33b65cabf 100644 --- a/Pulsar4X/Pulsar4X.Client/EntityManagement/CreateTransferWindow.cs +++ b/Pulsar4X/Pulsar4X.Client/EntityManagement/CreateTransferWindow.cs @@ -4,6 +4,7 @@ using ImGuiNET; using Pulsar4X.Datablobs; using Pulsar4X.Engine; +using Pulsar4X.Engine.Orders; using Pulsar4X.Extensions; using Pulsar4X.Interfaces; @@ -14,8 +15,8 @@ public class CreateTransferWindow : PulsarGuiWindow public Entity? TransferLeft { get; private set; } public Entity? TransferRight { get; private set; } - public Dictionary TransferLeftGoods { get; private set; } = new (); - public Dictionary TransferRightGoods { get; private set; } = new (); + public Dictionary TransferLeftGoods { get; private set; } = new (); + public Dictionary TransferRightGoods { get; private set; } = new (); internal static CreateTransferWindow GetInstance() { @@ -72,6 +73,23 @@ internal override void Display() ImGui.Columns(1); + if(TransferLeftGoods.Count > 0 || TransferRightGoods.Count > 0) + { + ImGui.Separator(); + if(ImGui.Button("Create")) + { + if(TransferLeft != null && TransferRight != null && TransferLeftGoods.Count > 0) + { + var itemsToTransfer = new List<(ICargoable, long)>(); + foreach(var item in TransferLeftGoods) + { + itemsToTransfer.Add((item.Key, item.Value.Item1)); + } + CargoUnloadToOrder.CreateCommand(_uiState.Faction.Id, TransferLeft, TransferRight, itemsToTransfer); + } + } + } + ImGui.EndChild(); } ImGui.SameLine(); @@ -112,11 +130,11 @@ private void DisplayStorageList(Entity entity) { if(entity == TransferLeft && !TransferLeftGoods.ContainsKey(cargoables[id])) { - TransferLeftGoods.Add(cargoables[id], 0); + TransferLeftGoods.Add(cargoables[id], (0, value)); } else if(entity == TransferRight && !TransferRightGoods.ContainsKey(cargoables[id])) { - TransferRightGoods.Add(cargoables[id], 0); + TransferRightGoods.Add(cargoables[id], (0, value)); } } ImGui.SameLine(); @@ -126,29 +144,47 @@ private void DisplayStorageList(Entity entity) string amount = Stringify.Number(value); var amountSize = ImGui.CalcTextSize(amount); - + ImGui.SetCursorPosX(contentSize.X - amountSize.X); ImGui.Text(value.ToString()); - + } } } } } - private void DisplayTradeList(Dictionary list, Entity entity) + private void DisplayTradeList(Dictionary list, Entity entity) { var contentSize = ImGui.GetContentRegionAvail(); - foreach(var (cargoable, amount) in list) + var currentX = ImGui.GetCursorPosX(); + var toRemove = new List(); + foreach(var (cargoable, value) in list) { + var amount = (int)value.Item1; + if(ImGui.SmallButton("-###remove" + cargoable.Name)) + { + toRemove.Add(cargoable); + } + ImGui.SameLine(); ImGui.Text(cargoable.Name); ImGui.SameLine(); - byte[] buffer = new byte[16]; - ImGui.SetNextItemWidth(96); - ImGui.SetCursorPosX(contentSize.X - 96); - ImGui.InputText("###input" + cargoable.Name, buffer, 16); + ImGui.SetCursorPosX(currentX + contentSize.X - 96); + ImGui.InputInt("###input" + cargoable.Name, ref amount); cargoable.ShowTooltip(); + + if(amount > value.Item2) + amount = (int)value.Item2; + if(amount < 0) + amount = 0; + + list[cargoable] = ((long)amount, value.Item2); + } + + foreach(var item in toRemove) + { + list.Remove(item); } } @@ -173,7 +209,7 @@ private void DisplayTransferSelection() if(ImGui.Button(potentialTarget.Name)) { SetRight(potentialTarget.Entity); - } + } } }