From 77a8e16104ad932b9426756a47813db20ce62a7a Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Thu, 23 Jun 2022 14:36:47 +1000 Subject: [PATCH] Add cargo shuttle (#8686) --- .../CargoOrderConsoleBoundUserInterface.cs} | 105 +- .../CargoShuttleConsoleBoundUserInterface.cs | 57 + .../Components/CargoOrderDatabaseComponent.cs | 56 - .../{ => Systems}/CargoSystem.Telepad.cs | 2 +- .../Cargo/{ => Systems}/CargoSystem.cs | 2 +- Content.Client/Cargo/UI/CargoConsoleMenu.xaml | 27 +- .../Cargo/UI/CargoConsoleMenu.xaml.cs | 104 +- .../Cargo/UI/CargoProductRow.xaml.cs | 1 + Content.Client/Cargo/UI/CargoShuttleMenu.xaml | 47 + .../Cargo/UI/CargoShuttleMenu.xaml.cs | 128 ++ .../Cargo/UI/GalacticBankSelectionMenu.cs | 45 - Content.Client/Entry/EntryPoint.cs | 1 - .../BUI/RadarConsoleBoundUserInterface.cs | 1 + .../BUI/ShuttleConsoleBoundUserInterface.cs | 2 + .../Shuttles/Systems/DockingSystem.cs | 18 +- Content.Client/Shuttles/UI/DockingControl.cs | 12 +- .../Shuttles/UI/RadarConsoleWindow.xaml.cs | 6 + Content.Client/Shuttles/UI/RadarControl.cs | 33 +- .../Shuttles/UI/ShuttleConsoleWindow.xaml.cs | 72 +- Content.IntegrationTests/Tests/CargoTest.cs | 39 + .../AtmosphereSystem.Commands.cs | 2 - Content.Server/Cargo/CargoBankAccount.cs | 33 - Content.Server/Cargo/CargoOrderDatabase.cs | 129 -- .../Cargo/Components/CargoConsoleComponent.cs | 205 -- .../Components/CargoOrderConsoleComponent.cs | 17 + .../Components/CargoOrderDatabaseComponent.cs | 26 - .../Cargo/Components/CargoPalletComponent.cs | 7 + .../Components/CargoPilotConsoleComponent.cs | 15 + .../CargoShuttleConsoleComponent.cs | 10 + .../Cargo/Components/CargoTelepadComponent.cs | 5 +- .../Components/StationBankAccountComponent.cs | 19 + .../StationCargoOrderDatabaseComponent.cs | 33 + Content.Server/Cargo/ICargoBankAccount.cs | 10 - .../Cargo/Systems/CargoSystem.Console.cs | 240 -- .../Cargo/Systems/CargoSystem.Orders.cs | 324 +++ .../Cargo/Systems/CargoSystem.Shuttle.cs | 528 +++++ .../Cargo/Systems/CargoSystem.Telepad.cs | 49 +- Content.Server/Cargo/Systems/CargoSystem.cs | 20 + .../GameTicking/Rules/NukeopsRuleSystem.cs | 21 +- .../Gravity/EntitySystems/WeightlessSystem.cs | 7 + .../Physics/Controllers/MoverController.cs | 14 +- .../Shuttles/Events/ConsoleShuttleEvent.cs | 12 + .../Shuttles/Systems/RadarConsoleSystem.cs | 11 +- .../Shuttles/Systems/ShuttleConsoleSystem.cs | 45 +- .../Cargo/BUI/CargoConsoleInterfaceState.cs | 22 + ...goShuttleConsoleBoundUserInterfaceState.cs | 41 + Content.Shared/Cargo/CargoOrderData.cs | 4 +- .../Cargo/Components/CargoShuttleComponent.cs | 31 + .../Components/SharedCargoConsoleComponent.cs | 95 - .../SharedCargoOrderDatabaseComponent.cs | 21 - .../Cargo/Events/CargoCallShuttleMessage.cs | 12 + .../Events/CargoConsoleAddOrderMessage.cs | 23 + .../Events/CargoConsoleApproveOrderMessage.cs | 17 + .../Events/CargoConsoleRemoveOrderMessage.cs | 17 + .../Cargo/Events/CargoRecallShuttleMessage.cs | 12 + .../{ => Prototypes}/CargoProductPrototype.cs | 4 +- .../Cargo/Prototypes/CargoShuttlePrototype.cs | 20 + Content.Shared/Cargo/SharedCargoSystem.cs | 8 + .../RadarConsoleBoundInterfaceState.cs | 18 +- .../ShuttleConsoleBoundInterfaceState.cs | 5 +- .../Components/RadarConsoleComponent.cs | 2 +- Resources/Audio/Effects/Cargo/buzz_sigh.ogg | Bin 0 -> 8972 bytes Resources/Audio/Effects/Cargo/buzz_two.ogg | Bin 0 -> 12724 bytes Resources/Audio/Effects/Cargo/licenses.txt | 7 + Resources/Audio/Effects/Cargo/ping.ogg | Bin 0 -> 8578 bytes Resources/Audio/Effects/error.ogg | Bin 14629 -> 0 bytes .../en-US/cargo/cargo-console-component.ftl | 43 + .../cargo-console-order-component.ftl | 0 .../cargo-order-database-component.ftl | 0 .../components/cargo-console-component.ftl | 27 - .../cargo/galactic-bank-selection-menu.ftl | 1 - .../{components => }/price-gun-component.ftl | 0 Resources/Maps/Salvage/stationstation.yml | 4 +- Resources/Maps/atlas.yml | 16 +- Resources/Maps/bagel.yml | 21 +- Resources/Maps/barratry.yml | 14 +- Resources/Maps/cargo_shuttle.yml | 2011 +++++++++++++++++ Resources/Maps/delta.yml | 54 +- Resources/Maps/marathon.yml | 13 +- Resources/Maps/nss_pillar.yml | 11 +- Resources/Maps/packedstation.yml | 11 +- Resources/Maps/packedstationxmas.yml | 8 +- Resources/Maps/saltern.yml | 20 +- Resources/Maps/splitstation.yml | 9 +- Resources/Maps/ssreach.yml | 4 +- Resources/Maps/waystation.yml | 13 +- .../Catalog/Cargo/cargo_materials.yml | 4 +- .../Datasets/Names/cargo_shuttle.yml | 11 + .../Prototypes/Entities/Mobs/NPCs/animals.yml | 7 +- .../Prototypes/Entities/Mobs/NPCs/pets.yml | 4 + .../Entities/Mobs/NPCs/simplemob.yml | 2 + .../Entities/Mobs/Player/admin_ghost.yml | 9 +- .../Devices/Circuitboards/computer.yml | 4 +- .../Objects/Specific/Cargo/cargo_pallet.yml | 12 + .../Machines/Computers/computers.yml | 56 +- .../Structures/Shuttles/thrusters.yml | 25 + .../Entities/Structures/cargo_console.yml | 51 + .../Entities/Structures/cargo_telepad.yml | 52 - Resources/Prototypes/shuttles.yml | 4 + 99 files changed, 4064 insertions(+), 1356 deletions(-) rename Content.Client/Cargo/{CargoConsoleBoundUserInterface.cs => BUI/CargoOrderConsoleBoundUserInterface.cs} (55%) create mode 100644 Content.Client/Cargo/BUI/CargoShuttleConsoleBoundUserInterface.cs delete mode 100644 Content.Client/Cargo/Components/CargoOrderDatabaseComponent.cs rename Content.Client/Cargo/{ => Systems}/CargoSystem.Telepad.cs (98%) rename Content.Client/Cargo/{ => Systems}/CargoSystem.cs (88%) create mode 100644 Content.Client/Cargo/UI/CargoShuttleMenu.xaml create mode 100644 Content.Client/Cargo/UI/CargoShuttleMenu.xaml.cs delete mode 100644 Content.Client/Cargo/UI/GalacticBankSelectionMenu.cs create mode 100644 Content.IntegrationTests/Tests/CargoTest.cs delete mode 100644 Content.Server/Cargo/CargoBankAccount.cs delete mode 100644 Content.Server/Cargo/CargoOrderDatabase.cs delete mode 100644 Content.Server/Cargo/Components/CargoConsoleComponent.cs create mode 100644 Content.Server/Cargo/Components/CargoOrderConsoleComponent.cs delete mode 100644 Content.Server/Cargo/Components/CargoOrderDatabaseComponent.cs create mode 100644 Content.Server/Cargo/Components/CargoPalletComponent.cs create mode 100644 Content.Server/Cargo/Components/CargoPilotConsoleComponent.cs create mode 100644 Content.Server/Cargo/Components/CargoShuttleConsoleComponent.cs create mode 100644 Content.Server/Cargo/Components/StationBankAccountComponent.cs create mode 100644 Content.Server/Cargo/Components/StationCargoOrderDatabaseComponent.cs delete mode 100644 Content.Server/Cargo/ICargoBankAccount.cs delete mode 100644 Content.Server/Cargo/Systems/CargoSystem.Console.cs create mode 100644 Content.Server/Cargo/Systems/CargoSystem.Orders.cs create mode 100644 Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs create mode 100644 Content.Server/Shuttles/Events/ConsoleShuttleEvent.cs create mode 100644 Content.Shared/Cargo/BUI/CargoConsoleInterfaceState.cs create mode 100644 Content.Shared/Cargo/BUI/CargoShuttleConsoleBoundUserInterfaceState.cs create mode 100644 Content.Shared/Cargo/Components/CargoShuttleComponent.cs delete mode 100644 Content.Shared/Cargo/Components/SharedCargoConsoleComponent.cs delete mode 100644 Content.Shared/Cargo/Components/SharedCargoOrderDatabaseComponent.cs create mode 100644 Content.Shared/Cargo/Events/CargoCallShuttleMessage.cs create mode 100644 Content.Shared/Cargo/Events/CargoConsoleAddOrderMessage.cs create mode 100644 Content.Shared/Cargo/Events/CargoConsoleApproveOrderMessage.cs create mode 100644 Content.Shared/Cargo/Events/CargoConsoleRemoveOrderMessage.cs create mode 100644 Content.Shared/Cargo/Events/CargoRecallShuttleMessage.cs rename Content.Shared/Cargo/{ => Prototypes}/CargoProductPrototype.cs (97%) create mode 100644 Content.Shared/Cargo/Prototypes/CargoShuttlePrototype.cs create mode 100644 Resources/Audio/Effects/Cargo/buzz_sigh.ogg create mode 100644 Resources/Audio/Effects/Cargo/buzz_two.ogg create mode 100644 Resources/Audio/Effects/Cargo/licenses.txt create mode 100644 Resources/Audio/Effects/Cargo/ping.ogg delete mode 100644 Resources/Audio/Effects/error.ogg create mode 100644 Resources/Locale/en-US/cargo/cargo-console-component.ftl rename Resources/Locale/en-US/cargo/{components => }/cargo-console-order-component.ftl (100%) rename Resources/Locale/en-US/cargo/{components => }/cargo-order-database-component.ftl (100%) delete mode 100644 Resources/Locale/en-US/cargo/components/cargo-console-component.ftl delete mode 100644 Resources/Locale/en-US/cargo/galactic-bank-selection-menu.ftl rename Resources/Locale/en-US/cargo/{components => }/price-gun-component.ftl (100%) create mode 100644 Resources/Maps/cargo_shuttle.yml create mode 100644 Resources/Prototypes/Datasets/Names/cargo_shuttle.yml create mode 100644 Resources/Prototypes/Entities/Objects/Specific/Cargo/cargo_pallet.yml create mode 100644 Resources/Prototypes/Entities/Structures/cargo_console.yml delete mode 100644 Resources/Prototypes/Entities/Structures/cargo_telepad.yml create mode 100644 Resources/Prototypes/shuttles.yml 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 @@ - + - - - -