Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/DevBranch' into DevBranch
Browse files Browse the repository at this point in the history
  • Loading branch information
se5a committed May 26, 2024
2 parents a433e5f + 6ef3b91 commit 853229f
Showing 1 changed file with 49 additions and 13 deletions.
62 changes: 49 additions & 13 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 All @@ -14,8 +15,8 @@ public class CreateTransferWindow : PulsarGuiWindow
public Entity? TransferLeft { get; private set; }
public Entity? TransferRight { get; private set; }

public Dictionary<ICargoable, int> TransferLeftGoods { get; private set; } = new ();
public Dictionary<ICargoable, int> TransferRightGoods { get; private set; } = new ();
public Dictionary<ICargoable, (long, long)> TransferLeftGoods { get; private set; } = new ();
public Dictionary<ICargoable, (long, long)> TransferRightGoods { get; private set; } = new ();

internal static CreateTransferWindow GetInstance()
{
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 @@ -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();
Expand All @@ -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<ICargoable, int> list, Entity entity)
private void DisplayTradeList(Dictionary<ICargoable, (long, long)> list, Entity entity)
{
var contentSize = ImGui.GetContentRegionAvail();
foreach(var (cargoable, amount) in list)
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.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);
}
}

Expand All @@ -173,7 +209,7 @@ private void DisplayTransferSelection()
if(ImGui.Button(potentialTarget.Name))
{
SetRight(potentialTarget.Entity);
}
}
}
}

Expand Down

0 comments on commit 853229f

Please sign in to comment.