diff --git a/Content.Client/Cargo/CargoConsoleBoundUserInterface.cs b/Content.Client/Cargo/BUI/CargoOrderConsoleBoundUserInterface.cs similarity index 55% rename from Content.Client/Cargo/CargoConsoleBoundUserInterface.cs rename to Content.Client/Cargo/BUI/CargoOrderConsoleBoundUserInterface.cs index ac03a59fe9..1d9f4a4cf5 100644 --- a/Content.Client/Cargo/CargoConsoleBoundUserInterface.cs +++ b/Content.Client/Cargo/BUI/CargoOrderConsoleBoundUserInterface.cs @@ -1,45 +1,46 @@ -using Content.Client.Cargo.Components; using Content.Client.Cargo.UI; +using Content.Shared.Access.Systems; using Content.Shared.Cargo; +using Content.Shared.Cargo.BUI; using Content.Shared.Cargo.Components; +using Content.Shared.Cargo.Events; +using Content.Shared.Cargo.Prototypes; using Robust.Client.GameObjects; -using Robust.Shared.GameObjects; -using Robust.Shared.IoC; -using Robust.Shared.ViewVariables; -using static Content.Shared.Cargo.Components.SharedCargoConsoleComponent; +using Robust.Client.Player; +using Robust.Shared.Prototypes; using static Robust.Client.UserInterface.Controls.BaseButton; -namespace Content.Client.Cargo +namespace Content.Client.Cargo.BUI { - public sealed class CargoConsoleBoundUserInterface : BoundUserInterface + public sealed class CargoOrderConsoleBoundUserInterface : BoundUserInterface { [ViewVariables] private CargoConsoleMenu? _menu; + /// + /// This is the separate popup window for individual orders. + /// [ViewVariables] private CargoConsoleOrderMenu? _orderMenu; [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; } + public string? AccountName { get; private set; } [ViewVariables] public int BankBalance { get; private set; } [ViewVariables] - public (int CurrentCapacity, int MaxCapacity) ShuttleCapacity { get; private set; } + public int OrderCapacity { get; private set; } + [ViewVariables] + public int OrderCount { get; private set; } + + /// + /// Currently selected product + /// private CargoProductPrototype? _product; - public CargoConsoleBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey) + public CargoOrderConsoleBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey) { } @@ -47,30 +48,29 @@ namespace Content.Client.Cargo { base.Open(); - var entMan = IoCManager.Resolve(); - if (!entMan.TryGetComponent(Owner.Owner, out CargoOrderDatabaseComponent? orders)) return; + var entityManager = IoCManager.Resolve(); + var sysManager = entityManager.EntitySysManager; + var spriteSystem = sysManager.GetEntitySystem(); + _menu = new CargoConsoleMenu(IoCManager.Resolve(), spriteSystem); + var localPlayer = IoCManager.Resolve()?.LocalPlayer?.ControlledEntity; - Orders = orders; + string orderRequester; + + if (entityManager.TryGetComponent(localPlayer, out var metadata)) + orderRequester = metadata.EntityName; + else + orderRequester = string.Empty; - _menu = new CargoConsoleMenu(this); _orderMenu = new CargoConsoleOrderMenu(); _menu.OnClose += Close; - _menu.Populate(); - - Orders.OnDatabaseUpdated += _menu.PopulateOrders; - - _menu.CallShuttleButton.OnPressed += (_) => - { - SendMessage(new CargoConsoleShuttleMessage()); - }; _menu.OnItemSelected += (args) => { if (args.Button.Parent is not CargoProductRow row) return; _product = row.Product; - _orderMenu.Requester.Text = ""; + _orderMenu.Requester.Text = orderRequester; _orderMenu.Reason.Text = ""; _orderMenu.Amount.Value = 1; _orderMenu.OpenCentered(); @@ -86,7 +86,15 @@ namespace Content.Client.Cargo }; _menu.OpenCentered(); + } + private void Populate(List orders) + { + if (_menu == null) return; + + _menu.PopulateProducts(); + _menu.PopulateCategories(); + _menu.PopulateOrders(orders); } protected override void UpdateState(BoundUserInterfaceState state) @@ -95,17 +103,16 @@ namespace Content.Client.Cargo if (state is not CargoConsoleInterfaceState cState) return; - if (RequestOnly != cState.RequestOnly) - { - RequestOnly = cState.RequestOnly; - _menu?.UpdateRequestOnly(); - } - BankId = cState.BankId; - BankName = cState.BankName; - BankBalance = cState.BankBalance; - ShuttleCapacity = cState.ShuttleCapacity; - _menu?.UpdateCargoCapacity(); - _menu?.UpdateBankData(); + + OrderCapacity = cState.Capacity; + OrderCount = cState.Count; + BankBalance = cState.Balance; + + AccountName = cState.Name; + + Populate(cState.Orders); + _menu?.UpdateCargoCapacity(OrderCount, OrderCapacity); + _menu?.UpdateBankData(AccountName, BankBalance); } protected override void Dispose(bool disposing) @@ -114,11 +121,6 @@ namespace Content.Client.Cargo if (!disposing) return; - if (Orders != null && _menu != null) - { - Orders.OnDatabaseUpdated -= _menu.PopulateOrders; - } - _menu?.Dispose(); _orderMenu?.Dispose(); } @@ -126,7 +128,7 @@ namespace Content.Client.Cargo private bool AddOrder() { int orderAmt = _orderMenu?.Amount.Value ?? 0; - if (orderAmt < 1 || orderAmt > ShuttleCapacity.MaxCapacity) + if (orderAmt < 1 || orderAmt > OrderCapacity) { return false; } @@ -153,11 +155,12 @@ namespace Content.Client.Cargo if (args.Button.Parent?.Parent is not CargoOrderRow row || row.Order == null) return; - if (ShuttleCapacity.CurrentCapacity == ShuttleCapacity.MaxCapacity) + if (OrderCount >= OrderCapacity) return; SendMessage(new CargoConsoleApproveOrderMessage(row.Order.OrderNumber)); - _menu?.UpdateCargoCapacity(); + // Most of the UI isn't predicted anyway so. + // _menu?.UpdateCargoCapacity(OrderCount + row.Order.Amount, OrderCapacity); } } } diff --git a/Content.Client/Cargo/BUI/CargoShuttleConsoleBoundUserInterface.cs b/Content.Client/Cargo/BUI/CargoShuttleConsoleBoundUserInterface.cs new file mode 100644 index 0000000000..6dd3df5f6e --- /dev/null +++ b/Content.Client/Cargo/BUI/CargoShuttleConsoleBoundUserInterface.cs @@ -0,0 +1,57 @@ +using Content.Client.Cargo.UI; +using Content.Shared.Cargo.BUI; +using Content.Shared.Cargo.Events; +using Robust.Client.GameObjects; +using Robust.Shared.Prototypes; +using Robust.Shared.Timing; + +namespace Content.Client.Cargo.BUI; + +public sealed class CargoShuttleConsoleBoundUserInterface : BoundUserInterface +{ + private CargoShuttleMenu? _menu; + + public CargoShuttleConsoleBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey) {} + + protected override void Open() + { + base.Open(); + _menu = new CargoShuttleMenu(IoCManager.Resolve(), IoCManager.Resolve(), EntitySystem.Get()); + + _menu.ShuttleCallRequested += OnShuttleCall; + _menu.ShuttleRecallRequested += OnShuttleRecall; + _menu.OnClose += Close; + + _menu.OpenCentered(); + } + + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + if (disposing) + { + _menu?.Dispose(); + } + } + + private void OnShuttleRecall() + { + SendMessage(new CargoRecallShuttleMessage()); + } + + private void OnShuttleCall() + { + SendMessage(new CargoCallShuttleMessage()); + } + + protected override void UpdateState(BoundUserInterfaceState state) + { + base.UpdateState(state); + if (state is not CargoShuttleConsoleBoundUserInterfaceState cargoState) return; + _menu?.SetAccountName(cargoState.AccountName); + _menu?.SetShuttleName(cargoState.ShuttleName); + _menu?.SetShuttleETA(cargoState.ShuttleETA); + _menu?.SetOrders(cargoState.Orders); + _menu?.SetCanRecall(cargoState.CanRecall); + } +} diff --git a/Content.Client/Cargo/Components/CargoOrderDatabaseComponent.cs b/Content.Client/Cargo/Components/CargoOrderDatabaseComponent.cs deleted file mode 100644 index 5279e6dc0e..0000000000 --- a/Content.Client/Cargo/Components/CargoOrderDatabaseComponent.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System; -using System.Collections.Generic; -using Content.Shared.Cargo; -using Content.Shared.Cargo.Components; -using Robust.Shared.GameObjects; - -namespace Content.Client.Cargo.Components -{ - [RegisterComponent] - public sealed class CargoOrderDatabaseComponent : SharedCargoOrderDatabaseComponent - { - private readonly List _orders = new(); - - public IReadOnlyList Orders => _orders; - /// - /// Event called when the database is updated. - /// - public event Action? OnDatabaseUpdated; - - // TODO add account selector menu - - /// - /// Removes all orders from the database. - /// - public void Clear() - { - _orders.Clear(); - } - - /// - /// Adds an order to the database. - /// - /// The order to be added. - public void AddOrder(CargoOrderData order) - { - if (!_orders.Contains(order)) - _orders.Add(order); - } - - public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) - { - base.HandleComponentState(curState, nextState); - if (curState is not CargoOrderDatabaseState state) - return; - Clear(); - if (state.Orders == null) - return; - foreach (var order in state.Orders) - { - AddOrder(order); - } - - OnDatabaseUpdated?.Invoke(); - } - } -} diff --git a/Content.Client/Cargo/CargoSystem.Telepad.cs b/Content.Client/Cargo/Systems/CargoSystem.Telepad.cs similarity index 98% rename from Content.Client/Cargo/CargoSystem.Telepad.cs rename to Content.Client/Cargo/Systems/CargoSystem.Telepad.cs index 6074d637ac..4d73caacb2 100644 --- a/Content.Client/Cargo/CargoSystem.Telepad.cs +++ b/Content.Client/Cargo/Systems/CargoSystem.Telepad.cs @@ -3,7 +3,7 @@ using Robust.Client.Animations; using Robust.Client.GameObjects; using Robust.Client.Graphics; -namespace Content.Client.Cargo; +namespace Content.Client.Cargo.Systems; public sealed partial class CargoSystem { diff --git a/Content.Client/Cargo/CargoSystem.cs b/Content.Client/Cargo/Systems/CargoSystem.cs similarity index 88% rename from Content.Client/Cargo/CargoSystem.cs rename to Content.Client/Cargo/Systems/CargoSystem.cs index ce26dc7ecf..3ffb0636d0 100644 --- a/Content.Client/Cargo/CargoSystem.cs +++ b/Content.Client/Cargo/Systems/CargoSystem.cs @@ -1,7 +1,7 @@ using Content.Shared.Cargo; using Robust.Client.GameObjects; -namespace Content.Client.Cargo; +namespace Content.Client.Cargo.Systems; public sealed partial class CargoSystem : SharedCargoSystem { diff --git a/Content.Client/Cargo/UI/CargoConsoleMenu.xaml b/Content.Client/Cargo/UI/CargoConsoleMenu.xaml index 9b92e43091..5262f43d6b 100644 --- a/Content.Client/Cargo/UI/CargoConsoleMenu.xaml +++ b/Content.Client/Cargo/UI/CargoConsoleMenu.xaml @@ -1,7 +1,8 @@ - + - - - -