Skip to content

Commit

Permalink
Add create button for the transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
behindcurtain3 committed May 25, 2024
1 parent f9e5b3c commit 6ef3b91
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions Pulsar4X/Pulsar4X.Client/EntityManagement/CreateTransferWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using ImGuiNET;
using Pulsar4X.Datablobs;
using Pulsar4X.Engine;
using Pulsar4X.Engine.Orders;
using Pulsar4X.Extensions;
using Pulsar4X.Interfaces;

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -139,15 +157,20 @@ private void DisplayStorageList(Entity entity)
private void DisplayTradeList(Dictionary<ICargoable, (long, long)> list, Entity entity)
{
var contentSize = ImGui.GetContentRegionAvail();
var currentX = ImGui.GetCursorPosX();
var toRemove = new List<ICargoable>();
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.SetCursorPosX(currentX + contentSize.X - 96);
ImGui.InputInt("###input" + cargoable.Name, ref amount);
cargoable.ShowTooltip();

Expand All @@ -158,6 +181,11 @@ private void DisplayTradeList(Dictionary<ICargoable, (long, long)> list, Entity

list[cargoable] = ((long)amount, value.Item2);
}

foreach(var item in toRemove)
{
list.Remove(item);
}
}

private void DisplayTransferSelection()
Expand Down

0 comments on commit 6ef3b91

Please sign in to comment.