From 417d3a87a22640003fd7ce95771aa470357b33c1 Mon Sep 17 00:00:00 2001 From: Julian Giebel Date: Sat, 31 Aug 2024 16:40:28 +0200 Subject: [PATCH 01/21] Station Anchor (#26098) * Work on abstracting out chargeup functionality/ui from grav gen * Work on station anchor * Finish implementing station anchors * uhh yeah * ok. * fix tests * whoops * Get the last extraneous yaml fail * PJB review * beast mode... ACTIVATE! --------- Co-authored-by: Ed <96445749+TheShuEd@users.noreply.github.com> Co-authored-by: EmoGarbage404 --- .../Ui/AnomalyGeneratorBoundUserInterface.cs | 2 - Content.Client/Gravity/GravitySystem.cs | 5 +- .../UI/GravityGeneratorBoundUserInterface.cs | 38 --- .../Gravity/UI/GravityGeneratorWindow.xaml.cs | 75 ----- .../PowerChargeBoundUserInterface.cs | 38 +++ .../Power/PowerCharge/PowerChargeComponent.cs | 10 + .../PowerCharge/PowerChargeWindow.xaml} | 16 +- .../PowerCharge/PowerChargeWindow.xaml.cs | 72 ++++ .../Tests/Gravity/WeightlessStatusTests.cs | 3 + .../Tests/GravityGridTest.cs | 3 + .../Gravity/GravityGeneratorComponent.cs | 29 -- .../Gravity/GravityGeneratorSystem.cs | 311 +++--------------- .../Power/Components/PowerChargeComponent.cs | 66 ++++ .../Power/EntitySystems/PowerChargeSystem.cs | 283 ++++++++++++++++ .../Components/StationAnchorComponent.cs | 11 + .../Shuttles/Systems/StationAnchorSystem.cs | 86 +++++ .../SharedGravityGeneratorComponent.cs | 154 +++------ Content.Shared/Power/SharedPowerCharge.cs | 77 +++++ .../Power/SharedPowerChargeComponent.cs | 14 + .../Shuttles/Systems/SharedShuttleSystem.cs | 3 +- .../components/station-anchor-component.ftl | 2 + .../components/power-charging-component.ftl | 22 ++ .../Circuitboards/Machine/production.yml | 16 + .../Structures/Machines/gravity_generator.yml | 14 +- .../Entities/Structures/Machines/lathe.yml | 1 + .../Structures/Shuttles/station_anchor.yml | 112 +++++++ .../Prototypes/Recipes/Lathes/electronics.yml | 11 +- .../Machines/station_anchor.rsi/meta.json | 17 + .../station_anchor.rsi/station_anchor.png | Bin 0 -> 3751 bytes .../station_anchor_unlit.png | Bin 0 -> 3330 bytes 30 files changed, 947 insertions(+), 544 deletions(-) delete mode 100644 Content.Client/Gravity/UI/GravityGeneratorBoundUserInterface.cs delete mode 100644 Content.Client/Gravity/UI/GravityGeneratorWindow.xaml.cs create mode 100644 Content.Client/Power/PowerCharge/PowerChargeBoundUserInterface.cs create mode 100644 Content.Client/Power/PowerCharge/PowerChargeComponent.cs rename Content.Client/{Gravity/UI/GravityGeneratorWindow.xaml => Power/PowerCharge/PowerChargeWindow.xaml} (60%) create mode 100644 Content.Client/Power/PowerCharge/PowerChargeWindow.xaml.cs create mode 100644 Content.Server/Power/Components/PowerChargeComponent.cs create mode 100644 Content.Server/Power/EntitySystems/PowerChargeSystem.cs create mode 100644 Content.Server/Shuttles/Components/StationAnchorComponent.cs create mode 100644 Content.Server/Shuttles/Systems/StationAnchorSystem.cs create mode 100644 Content.Shared/Power/SharedPowerCharge.cs create mode 100644 Content.Shared/Power/SharedPowerChargeComponent.cs create mode 100644 Resources/Locale/en-US/components/station-anchor-component.ftl create mode 100644 Resources/Locale/en-US/power/components/power-charging-component.ftl create mode 100644 Resources/Prototypes/Entities/Structures/Shuttles/station_anchor.yml create mode 100644 Resources/Textures/Structures/Machines/station_anchor.rsi/meta.json create mode 100644 Resources/Textures/Structures/Machines/station_anchor.rsi/station_anchor.png create mode 100644 Resources/Textures/Structures/Machines/station_anchor.rsi/station_anchor_unlit.png diff --git a/Content.Client/Anomaly/Ui/AnomalyGeneratorBoundUserInterface.cs b/Content.Client/Anomaly/Ui/AnomalyGeneratorBoundUserInterface.cs index 5d1985485c4..f088ac1976b 100644 --- a/Content.Client/Anomaly/Ui/AnomalyGeneratorBoundUserInterface.cs +++ b/Content.Client/Anomaly/Ui/AnomalyGeneratorBoundUserInterface.cs @@ -1,7 +1,5 @@ using Content.Shared.Anomaly; -using Content.Shared.Gravity; using JetBrains.Annotations; -using Robust.Client.GameObjects; using Robust.Client.UserInterface; namespace Content.Client.Anomaly.Ui; diff --git a/Content.Client/Gravity/GravitySystem.cs b/Content.Client/Gravity/GravitySystem.cs index 3e87f76ba2b..dd51436a1f5 100644 --- a/Content.Client/Gravity/GravitySystem.cs +++ b/Content.Client/Gravity/GravitySystem.cs @@ -1,4 +1,5 @@ using Content.Shared.Gravity; +using Content.Shared.Power; using Robust.Client.GameObjects; namespace Content.Client.Gravity; @@ -21,7 +22,7 @@ private void OnAppearanceChange(EntityUid uid, SharedGravityGeneratorComponent c if (args.Sprite == null) return; - if (_appearanceSystem.TryGetData(uid, GravityGeneratorVisuals.State, out var state, args.Component)) + if (_appearanceSystem.TryGetData(uid, PowerChargeVisuals.State, out var state, args.Component)) { if (comp.SpriteMap.TryGetValue(state, out var spriteState)) { @@ -30,7 +31,7 @@ private void OnAppearanceChange(EntityUid uid, SharedGravityGeneratorComponent c } } - if (_appearanceSystem.TryGetData(uid, GravityGeneratorVisuals.Charge, out var charge, args.Component)) + if (_appearanceSystem.TryGetData(uid, PowerChargeVisuals.Charge, out var charge, args.Component)) { var layer = args.Sprite.LayerMapGet(GravityGeneratorVisualLayers.Core); switch (charge) diff --git a/Content.Client/Gravity/UI/GravityGeneratorBoundUserInterface.cs b/Content.Client/Gravity/UI/GravityGeneratorBoundUserInterface.cs deleted file mode 100644 index 32b40747d55..00000000000 --- a/Content.Client/Gravity/UI/GravityGeneratorBoundUserInterface.cs +++ /dev/null @@ -1,38 +0,0 @@ -using Content.Shared.Gravity; -using JetBrains.Annotations; -using Robust.Client.UserInterface; - -namespace Content.Client.Gravity.UI -{ - [UsedImplicitly] - public sealed class GravityGeneratorBoundUserInterface : BoundUserInterface - { - [ViewVariables] - private GravityGeneratorWindow? _window; - - public GravityGeneratorBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) - { - } - - protected override void Open() - { - base.Open(); - - _window = this.CreateWindow(); - _window.SetEntity(Owner); - } - - protected override void UpdateState(BoundUserInterfaceState state) - { - base.UpdateState(state); - - var castState = (SharedGravityGeneratorComponent.GeneratorState) state; - _window?.UpdateState(castState); - } - - public void SetPowerSwitch(bool on) - { - SendMessage(new SharedGravityGeneratorComponent.SwitchGeneratorMessage(on)); - } - } -} diff --git a/Content.Client/Gravity/UI/GravityGeneratorWindow.xaml.cs b/Content.Client/Gravity/UI/GravityGeneratorWindow.xaml.cs deleted file mode 100644 index 6f04133b594..00000000000 --- a/Content.Client/Gravity/UI/GravityGeneratorWindow.xaml.cs +++ /dev/null @@ -1,75 +0,0 @@ -using Content.Shared.Gravity; -using Robust.Client.AutoGenerated; -using Robust.Client.GameObjects; -using Robust.Client.UserInterface.Controls; -using Robust.Client.UserInterface.XAML; -using FancyWindow = Content.Client.UserInterface.Controls.FancyWindow; - -namespace Content.Client.Gravity.UI -{ - [GenerateTypedNameReferences] - public sealed partial class GravityGeneratorWindow : FancyWindow - { - private readonly ButtonGroup _buttonGroup = new(); - - public event Action? OnPowerSwitch; - - public GravityGeneratorWindow() - { - RobustXamlLoader.Load(this); - IoCManager.InjectDependencies(this); - - OnButton.Group = _buttonGroup; - OffButton.Group = _buttonGroup; - - OnButton.OnPressed += _ => OnPowerSwitch?.Invoke(true); - OffButton.OnPressed += _ => OnPowerSwitch?.Invoke(false); - } - - public void SetEntity(EntityUid uid) - { - EntityView.SetEntity(uid); - } - - public void UpdateState(SharedGravityGeneratorComponent.GeneratorState state) - { - if (state.On) - OnButton.Pressed = true; - else - OffButton.Pressed = true; - - PowerLabel.Text = Loc.GetString( - "gravity-generator-window-power-label", - ("draw", state.PowerDraw), - ("max", state.PowerDrawMax)); - - PowerLabel.SetOnlyStyleClass(MathHelper.CloseTo(state.PowerDraw, state.PowerDrawMax) ? "Good" : "Caution"); - - ChargeBar.Value = state.Charge; - ChargeText.Text = (state.Charge / 255f).ToString("P0"); - StatusLabel.Text = Loc.GetString(state.PowerStatus switch - { - GravityGeneratorPowerStatus.Off => "gravity-generator-window-status-off", - GravityGeneratorPowerStatus.Discharging => "gravity-generator-window-status-discharging", - GravityGeneratorPowerStatus.Charging => "gravity-generator-window-status-charging", - GravityGeneratorPowerStatus.FullyCharged => "gravity-generator-window-status-fully-charged", - _ => throw new ArgumentOutOfRangeException() - }); - - StatusLabel.SetOnlyStyleClass(state.PowerStatus switch - { - GravityGeneratorPowerStatus.Off => "Danger", - GravityGeneratorPowerStatus.Discharging => "Caution", - GravityGeneratorPowerStatus.Charging => "Caution", - GravityGeneratorPowerStatus.FullyCharged => "Good", - _ => throw new ArgumentOutOfRangeException() - }); - - EtaLabel.Text = state.EtaSeconds >= 0 - ? Loc.GetString("gravity-generator-window-eta-value", ("left", TimeSpan.FromSeconds(state.EtaSeconds))) - : Loc.GetString("gravity-generator-window-eta-none"); - - EtaLabel.SetOnlyStyleClass(state.EtaSeconds >= 0 ? "Caution" : "Disabled"); - } - } -} diff --git a/Content.Client/Power/PowerCharge/PowerChargeBoundUserInterface.cs b/Content.Client/Power/PowerCharge/PowerChargeBoundUserInterface.cs new file mode 100644 index 00000000000..7a36b8ddf59 --- /dev/null +++ b/Content.Client/Power/PowerCharge/PowerChargeBoundUserInterface.cs @@ -0,0 +1,38 @@ +using Content.Shared.Power; +using Robust.Client.UserInterface; + +namespace Content.Client.Power.PowerCharge; + +public sealed class PowerChargeBoundUserInterface : BoundUserInterface +{ + [ViewVariables] + private PowerChargeWindow? _window; + + public PowerChargeBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) + { + } + + public void SetPowerSwitch(bool on) + { + SendMessage(new SwitchChargingMachineMessage(on)); + } + + protected override void Open() + { + base.Open(); + if (!EntMan.TryGetComponent(Owner, out PowerChargeComponent? component)) + return; + + _window = this.CreateWindow(); + _window.UpdateWindow(this, Loc.GetString(component.WindowTitle)); + } + + protected override void UpdateState(BoundUserInterfaceState state) + { + base.UpdateState(state); + if (state is not PowerChargeState chargeState) + return; + + _window?.UpdateState(chargeState); + } +} diff --git a/Content.Client/Power/PowerCharge/PowerChargeComponent.cs b/Content.Client/Power/PowerCharge/PowerChargeComponent.cs new file mode 100644 index 00000000000..ab5baa4e2f5 --- /dev/null +++ b/Content.Client/Power/PowerCharge/PowerChargeComponent.cs @@ -0,0 +1,10 @@ +using Content.Shared.Power; + +namespace Content.Client.Power.PowerCharge; + +/// +[RegisterComponent] +public sealed partial class PowerChargeComponent : SharedPowerChargeComponent +{ + +} diff --git a/Content.Client/Gravity/UI/GravityGeneratorWindow.xaml b/Content.Client/Power/PowerCharge/PowerChargeWindow.xaml similarity index 60% rename from Content.Client/Gravity/UI/GravityGeneratorWindow.xaml rename to Content.Client/Power/PowerCharge/PowerChargeWindow.xaml index 853f437a2bf..4e61255326e 100644 --- a/Content.Client/Gravity/UI/GravityGeneratorWindow.xaml +++ b/Content.Client/Power/PowerCharge/PowerChargeWindow.xaml @@ -1,27 +1,26 @@  -