From aed7d0c8c564216bffb202f0a1b443586831e2ca Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Mon, 1 Jul 2024 16:11:30 +1000 Subject: [PATCH 1/2] Add FTL arrival visuals (#29402) * Add FTL arrival visuals * weh * Update Content.Shared/Shuttles/Components/FTLComponent.cs Co-authored-by: Tayrtahn --------- Co-authored-by: Tayrtahn (cherry picked from commit b6cf2ce5243d66f5b79f3b3d1b7bf327b1e1761c) --- Content.Client/Shuttles/FtlArrivalOverlay.cs | 82 ++++++++++++++++++ .../Systems/ShuttleSystem.EmergencyConsole.cs | 3 +- .../Shuttles/Systems/ShuttleSystem.cs | 21 +++++ .../Systems/ShuttleSystem.FasterThanLight.cs | 20 ++++- .../Shuttles/Systems/ShuttleSystem.cs | 2 + .../Shuttles/Components/FTLComponent.cs | 16 ++-- .../Components/FtlVisualizerComponent.cs | 23 +++++ .../Prototypes/Entities/Effects/shuttle.yml | 12 +++ .../Effects/medi_holo.rsi/medi_holo.png | Bin 0 -> 1286 bytes .../Textures/Effects/medi_holo.rsi/meta.json | 26 ++++++ 10 files changed, 196 insertions(+), 9 deletions(-) create mode 100644 Content.Client/Shuttles/FtlArrivalOverlay.cs create mode 100644 Content.Client/Shuttles/Systems/ShuttleSystem.cs rename {Content.Server => Content.Shared}/Shuttles/Components/FTLComponent.cs (81%) create mode 100644 Content.Shared/Shuttles/Components/FtlVisualizerComponent.cs create mode 100644 Resources/Prototypes/Entities/Effects/shuttle.yml create mode 100644 Resources/Textures/Effects/medi_holo.rsi/medi_holo.png create mode 100644 Resources/Textures/Effects/medi_holo.rsi/meta.json diff --git a/Content.Client/Shuttles/FtlArrivalOverlay.cs b/Content.Client/Shuttles/FtlArrivalOverlay.cs new file mode 100644 index 00000000000..f24a1e96488 --- /dev/null +++ b/Content.Client/Shuttles/FtlArrivalOverlay.cs @@ -0,0 +1,82 @@ +using System.Numerics; +using Content.Shared.Shuttles.Components; +using Robust.Client.GameObjects; +using Robust.Client.Graphics; +using Robust.Shared.Enums; +using Robust.Shared.Map.Components; +using Robust.Shared.Prototypes; +using Robust.Shared.Timing; + +namespace Content.Client.Shuttles; + +/// +/// Plays a visualization whenever a shuttle is arriving from FTL. +/// +public sealed class FtlArrivalOverlay : Overlay +{ + public override OverlaySpace Space => OverlaySpace.WorldSpaceBelowEntities; + + private EntityLookupSystem _lookups; + private SharedMapSystem _maps; + private SharedTransformSystem _transforms; + private SpriteSystem _sprites; + [Dependency] private readonly IEntityManager _entManager = default!; + [Dependency] private readonly IGameTiming _timing = default!; + [Dependency] private readonly IPrototypeManager _protos = default!; + + private readonly HashSet> _visualizers = new(); + + private ShaderInstance _shader; + + public FtlArrivalOverlay() + { + IoCManager.InjectDependencies(this); + _lookups = _entManager.System(); + _transforms = _entManager.System(); + _maps = _entManager.System(); + _sprites = _entManager.System(); + + _shader = _protos.Index("unshaded").Instance(); + } + + protected override bool BeforeDraw(in OverlayDrawArgs args) + { + _visualizers.Clear(); + _lookups.GetEntitiesOnMap(args.MapId, _visualizers); + + return _visualizers.Count > 0; + } + + protected override void Draw(in OverlayDrawArgs args) + { + args.WorldHandle.UseShader(_shader); + + foreach (var (uid, comp) in _visualizers) + { + var grid = comp.Grid; + + if (!_entManager.TryGetComponent(grid, out MapGridComponent? mapGrid)) + continue; + + var texture = _sprites.GetFrame(comp.Sprite, TimeSpan.FromSeconds(comp.Elapsed), loop: false); + comp.Elapsed += (float) _timing.FrameTime.TotalSeconds; + + // Need to manually transform the viewport in terms of the visualizer entity as the grid isn't in position. + var (_, _, worldMatrix, invMatrix) = _transforms.GetWorldPositionRotationMatrixWithInv(uid); + args.WorldHandle.SetTransform(worldMatrix); + var localAABB = invMatrix.TransformBox(args.WorldBounds); + + var tilesEnumerator = _maps.GetLocalTilesEnumerator(grid, mapGrid, localAABB); + + while (tilesEnumerator.MoveNext(out var tile)) + { + var bounds = _lookups.GetLocalBounds(tile, mapGrid.TileSize); + + args.WorldHandle.DrawTextureRect(texture, bounds); + } + } + + args.WorldHandle.UseShader(null); + args.WorldHandle.SetTransform(Matrix3x2.Identity); + } +} diff --git a/Content.Client/Shuttles/Systems/ShuttleSystem.EmergencyConsole.cs b/Content.Client/Shuttles/Systems/ShuttleSystem.EmergencyConsole.cs index d5154a87bef..73c11de2795 100644 --- a/Content.Client/Shuttles/Systems/ShuttleSystem.EmergencyConsole.cs +++ b/Content.Client/Shuttles/Systems/ShuttleSystem.EmergencyConsole.cs @@ -38,9 +38,8 @@ public bool EnableShuttlePosition private bool _enableShuttlePosition; private EmergencyShuttleOverlay? _overlay; - public override void Initialize() + private void InitializeEmergency() { - base.Initialize(); SubscribeNetworkEvent(OnShuttlePosMessage); } diff --git a/Content.Client/Shuttles/Systems/ShuttleSystem.cs b/Content.Client/Shuttles/Systems/ShuttleSystem.cs new file mode 100644 index 00000000000..a2c048ff90e --- /dev/null +++ b/Content.Client/Shuttles/Systems/ShuttleSystem.cs @@ -0,0 +1,21 @@ +using Robust.Client.Graphics; + +namespace Content.Client.Shuttles.Systems; + +public sealed partial class ShuttleSystem +{ + [Dependency] private readonly IOverlayManager _overlays = default!; + + public override void Initialize() + { + base.Initialize(); + InitializeEmergency(); + _overlays.AddOverlay(new FtlArrivalOverlay()); + } + + public override void Shutdown() + { + base.Shutdown(); + _overlays.RemoveOverlay(); + } +} diff --git a/Content.Server/Shuttles/Systems/ShuttleSystem.FasterThanLight.cs b/Content.Server/Shuttles/Systems/ShuttleSystem.FasterThanLight.cs index 11cc16e0cd0..daf51038c14 100644 --- a/Content.Server/Shuttles/Systems/ShuttleSystem.FasterThanLight.cs +++ b/Content.Server/Shuttles/Systems/ShuttleSystem.FasterThanLight.cs @@ -81,6 +81,8 @@ public sealed partial class ShuttleSystem private void InitializeFTL() { SubscribeLocalEvent(OnStationPostInit); + SubscribeLocalEvent(OnFtlShutdown); + _bodyQuery = GetEntityQuery(); _buckleQuery = GetEntityQuery(); _beaconQuery = GetEntityQuery(); @@ -97,6 +99,12 @@ private void InitializeFTL() _cfg.OnValueChanged(CCVars.HyperspaceKnockdownTime, time => _hyperspaceKnockdownTime = TimeSpan.FromSeconds(time), true); } + private void OnFtlShutdown(Entity ent, ref ComponentShutdown args) + { + Del(ent.Comp.VisualizerEntity); + ent.Comp.VisualizerEntity = null; + } + private void OnStationPostInit(ref StationPostInitEvent ev) { // Add all grid maps as ftl destinations that anyone can FTL to. @@ -422,8 +430,16 @@ private void UpdateFTLTravelling(Entity entity) var comp = entity.Comp1; comp.StateTime = StartEndTime.FromCurTime(_gameTiming, DefaultArrivalTime); comp.State = FTLState.Arriving; - // TODO: Arrival effects - // For now we'll just use the ss13 bubbles but we can do fancier. + + if (entity.Comp1.VisualizerProto != null) + { + comp.VisualizerEntity = SpawnAtPosition(entity.Comp1.VisualizerProto, entity.Comp1.TargetCoordinates); + var visuals = Comp(comp.VisualizerEntity.Value); + visuals.Grid = entity.Owner; + Dirty(comp.VisualizerEntity.Value, visuals); + _transform.SetLocalRotation(comp.VisualizerEntity.Value, entity.Comp1.TargetAngle); + _pvs.AddGlobalOverride(comp.VisualizerEntity.Value); + } _thruster.DisableLinearThrusters(shuttle); _thruster.EnableLinearThrustDirection(shuttle, DirectionFlag.South); diff --git a/Content.Server/Shuttles/Systems/ShuttleSystem.cs b/Content.Server/Shuttles/Systems/ShuttleSystem.cs index 6fe2324d51e..a10d0d56144 100644 --- a/Content.Server/Shuttles/Systems/ShuttleSystem.cs +++ b/Content.Server/Shuttles/Systems/ShuttleSystem.cs @@ -11,6 +11,7 @@ using Content.Shared.Throwing; using JetBrains.Annotations; using Robust.Server.GameObjects; +using Robust.Server.GameStates; using Robust.Shared.Audio; using Robust.Shared.Audio.Systems; using Robust.Shared.Configuration; @@ -40,6 +41,7 @@ public sealed partial class ShuttleSystem : SharedShuttleSystem [Dependency] private readonly FixtureSystem _fixtures = default!; [Dependency] private readonly MapLoaderSystem _loader = default!; [Dependency] private readonly MetaDataSystem _metadata = default!; + [Dependency] private readonly PvsOverrideSystem _pvs = default!; [Dependency] private readonly SharedAudioSystem _audio = default!; [Dependency] private readonly SharedPhysicsSystem _physics = default!; [Dependency] private readonly SharedTransformSystem _transform = default!; diff --git a/Content.Server/Shuttles/Components/FTLComponent.cs b/Content.Shared/Shuttles/Components/FTLComponent.cs similarity index 81% rename from Content.Server/Shuttles/Components/FTLComponent.cs rename to Content.Shared/Shuttles/Components/FTLComponent.cs index c9b84064234..9acca7c1d45 100644 --- a/Content.Server/Shuttles/Components/FTLComponent.cs +++ b/Content.Shared/Shuttles/Components/FTLComponent.cs @@ -2,16 +2,16 @@ using Content.Shared.Tag; using Content.Shared.Timing; using Robust.Shared.Audio; +using Robust.Shared.GameStates; using Robust.Shared.Map; using Robust.Shared.Prototypes; -using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; -namespace Content.Server.Shuttles.Components; +namespace Content.Shared.Shuttles.Components; /// /// Added to a component when it is queued or is travelling via FTL. /// -[RegisterComponent] +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] public sealed partial class FTLComponent : Component { // TODO Full game save / add datafields @@ -29,13 +29,19 @@ public sealed partial class FTLComponent : Component [ViewVariables(VVAccess.ReadWrite)] public float TravelTime = 0f; + [DataField] + public EntProtoId? VisualizerProto = "FtlVisualizerEntity"; + + [DataField, AutoNetworkedField] + public EntityUid? VisualizerEntity; + /// /// Coordinates to arrive it: May be relative to another grid (for docking) or map coordinates. /// - [ViewVariables(VVAccess.ReadWrite), DataField] + [DataField, AutoNetworkedField] public EntityCoordinates TargetCoordinates; - [DataField] + [DataField, AutoNetworkedField] public Angle TargetAngle; /// diff --git a/Content.Shared/Shuttles/Components/FtlVisualizerComponent.cs b/Content.Shared/Shuttles/Components/FtlVisualizerComponent.cs new file mode 100644 index 00000000000..628a4f828b2 --- /dev/null +++ b/Content.Shared/Shuttles/Components/FtlVisualizerComponent.cs @@ -0,0 +1,23 @@ +using Robust.Shared.GameStates; +using Robust.Shared.Utility; + +namespace Content.Shared.Shuttles.Components; + +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] +public sealed partial class FtlVisualizerComponent : Component +{ + /// + /// Clientside time tracker for the animation. + /// + [ViewVariables(VVAccess.ReadWrite)] + public float Elapsed; + + [DataField(required: true)] + public SpriteSpecifier.Rsi Sprite; + + /// + /// Target grid to pull FTL visualization from. + /// + [DataField, AutoNetworkedField] + public EntityUid Grid; +} diff --git a/Resources/Prototypes/Entities/Effects/shuttle.yml b/Resources/Prototypes/Entities/Effects/shuttle.yml new file mode 100644 index 00000000000..d4538116ac9 --- /dev/null +++ b/Resources/Prototypes/Entities/Effects/shuttle.yml @@ -0,0 +1,12 @@ +- type: entity + id: FtlVisualizerEntity + noSpawn: true + description: Visualizer for shuttles arriving. You shouldn't see this! + components: + - type: FtlVisualizer + sprite: + sprite: /Textures/Effects/medi_holo.rsi + state: medi_holo + - type: Tag + tags: + - HideContextMenu diff --git a/Resources/Textures/Effects/medi_holo.rsi/medi_holo.png b/Resources/Textures/Effects/medi_holo.rsi/medi_holo.png new file mode 100644 index 0000000000000000000000000000000000000000..9b024faa2d799b09ede0769fb89521a2c66e6b29 GIT binary patch literal 1286 zcmV+h1^N1kP)5Ot-`|VJ$T9$<&?@>gayZ*Tuo?pzy z+r{3C$N+d#F!?wE@4xWf|`9J;Z?ayYjDYg=5pyA&PlRxNhpP!wb?ViK? zKvLe1?*Yb$48TZ-$cM*oA6{4810b>>?OgwVowEt1>LI8_QxL3#i!XPgv9ne{?ahy- zI7owZxtB_RQ{zI;$Fu{JZ}Ok8_1U}U(+}c%Kn8RLO6k^sb*KONhIDJdbHNSBKw}Sb z1B7U$KsUe`H^3M-z!*2c7&pKeH^3M-z!*2cnC=W%tZrW&`u+AFq~C@0uOj+O&UjrI zKqoym!JM`X{bAB$6U=D~G;aV*C}$#RTW;S8{VPsX)3zynn>7FV}i=HydwH6-jIYLg%6FUQ7i&VXY>Y(R&I3BC;CAjN>hN;s)(^wkhKD^EJLF%N0NFZwV_icluA7#`g#=z)9 z=9hK#A>uVO#Rg#X(O+g`8E066pkwmgq<+QZ!Keb=f0Gh+-Q4?}L zy+sH1gjoSlKQ#s9oQ@9Zm+I#!$e1P!NWD@?!P5@HiTqG&>PlrPR4zsA^89)JjmpPP z)(W5-Z*5?cv%FDTay4{}ECVznUy_C-6F;R1SgjU~UA!+~|HKjMB<@7xkJOvpOH9%S)pWF9X zVBH_U#q)n0PeI1)45)oB4z;ZHE%6m#j2mFgU;sA_NN-S>(x{b&7OO@tM+2Nm5Z1>Z z9J{m$iYxOyOt@Ue>bSc8JG|*bV wG)bFqSnikFRtszWlCV!f)_>r-vk8vz7wA2u47-?TCIA2c07*qoM6N<$f_7g|Z2$lO literal 0 HcmV?d00001 diff --git a/Resources/Textures/Effects/medi_holo.rsi/meta.json b/Resources/Textures/Effects/medi_holo.rsi/meta.json new file mode 100644 index 00000000000..1be502223e5 --- /dev/null +++ b/Resources/Textures/Effects/medi_holo.rsi/meta.json @@ -0,0 +1,26 @@ +{ + "version": 1, + "license": "CC-BY-SA-3.0", + "copyright": "https://github.com/tgstation/tgstation/tree/217b39cc85e45302d407d5c1ab60809bd9e18987", + "size": { + "x": 32, + "y": 32 + }, + "states": [ + { + "name": "medi_holo", + "delays": [ + [ + 0.1, + 0.1, + 0.1, + 0.1, + 0.1, + 0.1, + 0.1, + 0.1 + ] + ] + } + ] +} \ No newline at end of file From 318a9ba77ea28026e9063ef4acfdd011316fd9e1 Mon Sep 17 00:00:00 2001 From: Fansana Date: Mon, 30 Dec 2024 18:47:50 +0100 Subject: [PATCH 2/2] fix test --- Resources/Prototypes/Maps/saltern.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/Prototypes/Maps/saltern.yml b/Resources/Prototypes/Maps/saltern.yml index a7761d05cd4..c22aa7aa809 100644 --- a/Resources/Prototypes/Maps/saltern.yml +++ b/Resources/Prototypes/Maps/saltern.yml @@ -15,7 +15,7 @@ !type:NanotrasenNameGenerator prefixCreator: '14' - type: StationEmergencyShuttle - emergencyShuttlePath: /Maps/Shuttles/DeltaV/NTES_Delta.yml + emergencyShuttlePath: /Maps/Shuttles/emergency.yml - type: StationJobs overflowJobs: - Passenger