2021-06-09 22:19:39 +02:00
|
|
|
|
using Content.Client.Cargo.Components;
|
|
|
|
|
|
using Content.Client.Cargo.UI;
|
|
|
|
|
|
using Content.Shared.Cargo;
|
|
|
|
|
|
using Content.Shared.Cargo.Components;
|
2021-02-11 01:13:03 -08:00
|
|
|
|
using Robust.Client.GameObjects;
|
|
|
|
|
|
using Robust.Shared.GameObjects;
|
2021-12-03 14:17:01 +01:00
|
|
|
|
using Robust.Shared.IoC;
|
2019-11-21 16:37:15 -08:00
|
|
|
|
using Robust.Shared.ViewVariables;
|
2021-06-09 22:19:39 +02:00
|
|
|
|
using static Content.Shared.Cargo.Components.SharedCargoConsoleComponent;
|
2021-03-10 14:48:29 +01:00
|
|
|
|
using static Robust.Client.UserInterface.Controls.BaseButton;
|
2019-11-21 16:37:15 -08:00
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
|
namespace Content.Client.Cargo
|
2019-11-21 16:37:15 -08:00
|
|
|
|
{
|
2022-02-16 00:23:23 -07:00
|
|
|
|
public sealed class CargoConsoleBoundUserInterface : BoundUserInterface
|
2019-11-21 16:37:15 -08:00
|
|
|
|
{
|
|
|
|
|
|
[ViewVariables]
|
2021-03-10 14:48:29 +01:00
|
|
|
|
private CargoConsoleMenu? _menu;
|
|
|
|
|
|
|
2019-11-21 16:37:15 -08:00
|
|
|
|
[ViewVariables]
|
2021-03-10 14:48:29 +01:00
|
|
|
|
private CargoConsoleOrderMenu? _orderMenu;
|
2019-11-21 16:37:15 -08:00
|
|
|
|
|
|
|
|
|
|
[ViewVariables]
|
2021-03-10 14:48:29 +01:00
|
|
|
|
public GalacticMarketComponent? Market { get; private set; }
|
|
|
|
|
|
|
2019-11-21 16:37:15 -08:00
|
|
|
|
[ViewVariables]
|
2021-03-10 14:48:29 +01:00
|
|
|
|
public CargoOrderDatabaseComponent? Orders { get; private set; }
|
|
|
|
|
|
|
2019-11-21 16:37:15 -08:00
|
|
|
|
[ViewVariables]
|
|
|
|
|
|
public bool RequestOnly { get; private set; }
|
2021-03-10 14:48:29 +01:00
|
|
|
|
|
2019-11-21 16:37:15 -08:00
|
|
|
|
[ViewVariables]
|
|
|
|
|
|
public int BankId { get; private set; }
|
2021-03-10 14:48:29 +01:00
|
|
|
|
|
2019-11-21 16:37:15 -08:00
|
|
|
|
[ViewVariables]
|
2021-03-10 14:48:29 +01:00
|
|
|
|
public string? BankName { get; private set; }
|
|
|
|
|
|
|
2019-11-21 16:37:15 -08:00
|
|
|
|
[ViewVariables]
|
|
|
|
|
|
public int BankBalance { get; private set; }
|
2021-03-10 14:48:29 +01:00
|
|
|
|
|
2020-07-02 07:45:40 -05:00
|
|
|
|
[ViewVariables]
|
|
|
|
|
|
public (int CurrentCapacity, int MaxCapacity) ShuttleCapacity { get; private set; }
|
2019-11-21 16:37:15 -08:00
|
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
|
private CargoProductPrototype? _product;
|
2019-11-21 16:37:15 -08:00
|
|
|
|
|
|
|
|
|
|
public CargoConsoleBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void Open()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Open();
|
|
|
|
|
|
|
2021-12-08 12:09:43 +01:00
|
|
|
|
var entMan = IoCManager.Resolve<IEntityManager>();
|
|
|
|
|
|
if (!entMan.TryGetComponent(Owner.Owner, out GalacticMarketComponent? market) ||
|
|
|
|
|
|
!entMan.TryGetComponent(Owner.Owner, out CargoOrderDatabaseComponent? orders)) return;
|
2019-11-21 16:37:15 -08:00
|
|
|
|
|
|
|
|
|
|
Market = market;
|
|
|
|
|
|
Orders = orders;
|
|
|
|
|
|
|
|
|
|
|
|
_menu = new CargoConsoleMenu(this);
|
|
|
|
|
|
_orderMenu = new CargoConsoleOrderMenu();
|
|
|
|
|
|
|
|
|
|
|
|
_menu.OnClose += Close;
|
|
|
|
|
|
|
|
|
|
|
|
_menu.Populate();
|
|
|
|
|
|
|
|
|
|
|
|
Market.OnDatabaseUpdated += _menu.PopulateProducts;
|
|
|
|
|
|
Market.OnDatabaseUpdated += _menu.PopulateCategories;
|
|
|
|
|
|
Orders.OnDatabaseUpdated += _menu.PopulateOrders;
|
|
|
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
|
_menu.CallShuttleButton.OnPressed += (_) =>
|
2019-11-21 16:37:15 -08:00
|
|
|
|
{
|
2021-03-10 14:48:29 +01:00
|
|
|
|
SendMessage(new CargoConsoleShuttleMessage());
|
2019-11-21 16:37:15 -08:00
|
|
|
|
};
|
|
|
|
|
|
_menu.OnItemSelected += (args) =>
|
|
|
|
|
|
{
|
2020-11-26 14:33:31 +01:00
|
|
|
|
if (args.Button.Parent is not CargoProductRow row)
|
2019-11-21 16:37:15 -08:00
|
|
|
|
return;
|
|
|
|
|
|
_product = row.Product;
|
2021-03-10 14:48:29 +01:00
|
|
|
|
_orderMenu.Requester.Text = "";
|
|
|
|
|
|
_orderMenu.Reason.Text = "";
|
2019-11-21 16:37:15 -08:00
|
|
|
|
_orderMenu.Amount.Value = 1;
|
2020-08-06 18:06:24 -07:00
|
|
|
|
_orderMenu.OpenCentered();
|
2019-11-21 16:37:15 -08:00
|
|
|
|
};
|
|
|
|
|
|
_menu.OnOrderApproved += ApproveOrder;
|
|
|
|
|
|
_menu.OnOrderCanceled += RemoveOrder;
|
2021-03-10 14:48:29 +01:00
|
|
|
|
_orderMenu.SubmitButton.OnPressed += (_) =>
|
2019-11-21 16:37:15 -08:00
|
|
|
|
{
|
2021-05-31 23:45:28 -05:00
|
|
|
|
if (AddOrder())
|
|
|
|
|
|
{
|
|
|
|
|
|
_orderMenu.Close();
|
|
|
|
|
|
}
|
2019-11-21 16:37:15 -08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
_menu.OpenCentered();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void UpdateState(BoundUserInterfaceState state)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.UpdateState(state);
|
|
|
|
|
|
|
2020-11-26 14:33:31 +01:00
|
|
|
|
if (state is not CargoConsoleInterfaceState cState)
|
2019-11-21 16:37:15 -08:00
|
|
|
|
return;
|
2020-09-13 14:23:52 +02:00
|
|
|
|
if (RequestOnly != cState.RequestOnly)
|
2019-11-21 16:37:15 -08:00
|
|
|
|
{
|
2020-09-13 14:23:52 +02:00
|
|
|
|
RequestOnly = cState.RequestOnly;
|
2021-03-10 14:48:29 +01:00
|
|
|
|
_menu?.UpdateRequestOnly();
|
2019-11-21 16:37:15 -08:00
|
|
|
|
}
|
2020-09-13 14:23:52 +02:00
|
|
|
|
BankId = cState.BankId;
|
|
|
|
|
|
BankName = cState.BankName;
|
|
|
|
|
|
BankBalance = cState.BankBalance;
|
|
|
|
|
|
ShuttleCapacity = cState.ShuttleCapacity;
|
2021-03-10 14:48:29 +01:00
|
|
|
|
_menu?.UpdateCargoCapacity();
|
|
|
|
|
|
_menu?.UpdateBankData();
|
2019-11-21 16:37:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Dispose(disposing);
|
2021-03-10 14:48:29 +01:00
|
|
|
|
|
2019-11-21 16:37:15 -08:00
|
|
|
|
if (!disposing) return;
|
2021-03-10 14:48:29 +01:00
|
|
|
|
|
|
|
|
|
|
if (Market != null && _menu != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Market.OnDatabaseUpdated -= _menu.PopulateProducts;
|
|
|
|
|
|
Market.OnDatabaseUpdated -= _menu.PopulateCategories;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (Orders != null && _menu != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Orders.OnDatabaseUpdated -= _menu.PopulateOrders;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-11-21 16:37:15 -08:00
|
|
|
|
_menu?.Dispose();
|
|
|
|
|
|
_orderMenu?.Dispose();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-31 23:45:28 -05:00
|
|
|
|
private bool AddOrder()
|
2019-11-21 16:37:15 -08:00
|
|
|
|
{
|
2021-05-31 23:45:28 -05:00
|
|
|
|
int orderAmt = _orderMenu?.Amount.Value ?? 0;
|
|
|
|
|
|
if (orderAmt < 1 || orderAmt > ShuttleCapacity.MaxCapacity)
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
|
SendMessage(new CargoConsoleAddOrderMessage(
|
|
|
|
|
|
_orderMenu?.Requester.Text ?? "",
|
|
|
|
|
|
_orderMenu?.Reason.Text ?? "",
|
|
|
|
|
|
_product?.ID ?? "",
|
2021-05-31 23:45:28 -05:00
|
|
|
|
orderAmt));
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
2019-11-21 16:37:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
|
private void RemoveOrder(ButtonEventArgs args)
|
2019-11-21 16:37:15 -08:00
|
|
|
|
{
|
2021-03-10 14:48:29 +01:00
|
|
|
|
if (args.Button.Parent?.Parent is not CargoOrderRow row || row.Order == null)
|
2019-11-21 16:37:15 -08:00
|
|
|
|
return;
|
2021-03-10 14:48:29 +01:00
|
|
|
|
|
|
|
|
|
|
SendMessage(new CargoConsoleRemoveOrderMessage(row.Order.OrderNumber));
|
2019-11-21 16:37:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
|
private void ApproveOrder(ButtonEventArgs args)
|
2019-11-21 16:37:15 -08:00
|
|
|
|
{
|
2021-03-10 14:48:29 +01:00
|
|
|
|
if (args.Button.Parent?.Parent is not CargoOrderRow row || row.Order == null)
|
2019-11-21 16:37:15 -08:00
|
|
|
|
return;
|
2021-03-10 14:48:29 +01:00
|
|
|
|
|
2020-07-02 07:45:40 -05:00
|
|
|
|
if (ShuttleCapacity.CurrentCapacity == ShuttleCapacity.MaxCapacity)
|
|
|
|
|
|
return;
|
2021-03-10 14:48:29 +01:00
|
|
|
|
|
|
|
|
|
|
SendMessage(new CargoConsoleApproveOrderMessage(row.Order.OrderNumber));
|
2020-07-02 07:45:40 -05:00
|
|
|
|
_menu?.UpdateCargoCapacity();
|
2019-11-21 16:37:15 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|