* Implement Cargo Console Add to CargoConsoleComponent GalacticBank information for syncing Bank Account Balance. Implement CargoOrderDatabase on the server side and a list of orders in the CargoOrderDatabaseComponent on the client side. This makes it easier to change data on the server side but also utilize the state syncing between components. Implement GalacticMarketComponent. Only productIds get sent. Both client and server create their lists from YAML. Implement basic spawning of items from approved orders in CargoOrderDatabase. * Finish Cargo Console Add validation to make sure Order Amount is one or more. Implement approve and cancel buttons to CargoConsoleMenu orders list row. Add price to CargoConsoleMenu product list row. Implement CargoOrderDataManager to consolidate CargoOrder lists. Refactor CargoOrderDatabaseComponent to use CargoOrderDataManager instead of storing duplicate lists. Implement canceling orders. Implement approving orders. Fix sprite links. Implement Cargo Request Console.
133 lines
4.5 KiB
C#
133 lines
4.5 KiB
C#
using Content.Client.UserInterface.Cargo;
|
|
using Content.Shared.GameObjects.Components.Cargo;
|
|
using Content.Shared.Prototypes.Cargo;
|
|
using Robust.Client.GameObjects.Components.UserInterface;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Shared.GameObjects.Components.UserInterface;
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
namespace Content.Client.GameObjects.Components.Cargo
|
|
{
|
|
public class CargoConsoleBoundUserInterface : BoundUserInterface
|
|
{
|
|
[ViewVariables]
|
|
private CargoConsoleMenu _menu;
|
|
[ViewVariables]
|
|
private CargoConsoleOrderMenu _orderMenu;
|
|
|
|
[ViewVariables]
|
|
public GalacticMarketComponent Market { get; private set; }
|
|
[ViewVariables]
|
|
public CargoOrderDatabaseComponent Orders { get; private set; }
|
|
[ViewVariables]
|
|
public bool RequestOnly { get; private set; }
|
|
[ViewVariables]
|
|
public int BankId { get; private set; }
|
|
[ViewVariables]
|
|
public string BankName { get; private set; }
|
|
[ViewVariables]
|
|
public int BankBalance { get; private set; }
|
|
|
|
private CargoProductPrototype _product;
|
|
|
|
public CargoConsoleBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey)
|
|
{
|
|
}
|
|
|
|
protected override void Open()
|
|
{
|
|
base.Open();
|
|
|
|
if (!Owner.Owner.TryGetComponent(out GalacticMarketComponent market)
|
|
|| !Owner.Owner.TryGetComponent(out CargoOrderDatabaseComponent orders)) return;
|
|
|
|
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;
|
|
|
|
_menu.CallShuttleButton.OnPressed += (args) =>
|
|
{
|
|
SendMessage(new SharedCargoConsoleComponent.CargoConsoleShuttleMessage());
|
|
};
|
|
_menu.OnItemSelected += (args) =>
|
|
{
|
|
if (!(args.Button.Parent is CargoProductRow row))
|
|
return;
|
|
_product = row.Product;
|
|
_orderMenu.Requester.Text = null;
|
|
_orderMenu.Reason.Text = null;
|
|
_orderMenu.Amount.Value = 1;
|
|
_orderMenu.OpenCenteredMinSize();
|
|
};
|
|
_menu.OnOrderApproved += ApproveOrder;
|
|
_menu.OnOrderCanceled += RemoveOrder;
|
|
_orderMenu.SubmitButton.OnPressed += (args) =>
|
|
{
|
|
AddOrder();
|
|
_orderMenu.Close();
|
|
};
|
|
|
|
_menu.OpenCentered();
|
|
|
|
}
|
|
|
|
protected override void UpdateState(BoundUserInterfaceState state)
|
|
{
|
|
base.UpdateState(state);
|
|
|
|
if (!(state is CargoConsoleInterfaceState cstate))
|
|
return;
|
|
if (RequestOnly != cstate.RequestOnly)
|
|
{
|
|
RequestOnly = cstate.RequestOnly;
|
|
_menu.UpdateRequestOnly();
|
|
}
|
|
BankId = cstate.BankId;
|
|
BankName = cstate.BankName;
|
|
BankBalance = cstate.BankBalance;
|
|
_menu.UpdateBankData();
|
|
}
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
base.Dispose(disposing);
|
|
if (!disposing) return;
|
|
Market.OnDatabaseUpdated -= _menu.PopulateProducts;
|
|
Market.OnDatabaseUpdated -= _menu.PopulateCategories;
|
|
Orders.OnDatabaseUpdated -= _menu.PopulateOrders;
|
|
_menu?.Dispose();
|
|
_orderMenu?.Dispose();
|
|
}
|
|
|
|
internal void AddOrder()
|
|
{
|
|
SendMessage(new SharedCargoConsoleComponent.CargoConsoleAddOrderMessage(_orderMenu.Requester.Text,
|
|
_orderMenu.Reason.Text, _product.ID, _orderMenu.Amount.Value));
|
|
}
|
|
|
|
internal void RemoveOrder(BaseButton.ButtonEventArgs args)
|
|
{
|
|
if (!(args.Button.Parent.Parent is CargoOrderRow row))
|
|
return;
|
|
SendMessage(new SharedCargoConsoleComponent.CargoConsoleRemoveOrderMessage(row.Order.OrderNumber));
|
|
}
|
|
|
|
internal void ApproveOrder(BaseButton.ButtonEventArgs args)
|
|
{
|
|
if (!(args.Button.Parent.Parent is CargoOrderRow row))
|
|
return;
|
|
SendMessage(new SharedCargoConsoleComponent.CargoConsoleApproveOrderMessage(row.Order.OrderNumber));
|
|
}
|
|
}
|
|
}
|