2021-02-12 07:02:14 -08:00
|
|
|
using System;
|
2021-07-04 18:11:52 +02:00
|
|
|
using Content.Client.Wires.Visualizers;
|
2022-01-30 13:49:56 +13:00
|
|
|
using Content.Shared.Doors.Components;
|
2020-08-19 12:23:42 +02:00
|
|
|
using JetBrains.Annotations;
|
2019-04-15 21:11:38 -06:00
|
|
|
using Robust.Client.Animations;
|
|
|
|
|
using Robust.Client.GameObjects;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-12-03 11:33:40 +01:00
|
|
|
using Robust.Shared.IoC;
|
2021-03-05 01:08:38 +01:00
|
|
|
using Robust.Shared.Serialization;
|
|
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2022-01-30 13:49:56 +13:00
|
|
|
using Robust.Shared.Timing;
|
2019-03-16 20:40:07 +01:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Client.Doors
|
2019-03-16 20:40:07 +01:00
|
|
|
{
|
2020-08-19 12:23:42 +02:00
|
|
|
[UsedImplicitly]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class AirlockVisualizer : AppearanceVisualizer, ISerializationHooks
|
2019-03-16 20:40:07 +01:00
|
|
|
{
|
2021-12-08 12:09:43 +01:00
|
|
|
[Dependency] private readonly IEntityManager _entMan = default!;
|
2022-01-30 13:49:56 +13:00
|
|
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
2021-12-08 12:09:43 +01:00
|
|
|
|
2019-03-17 13:24:26 +01:00
|
|
|
private const string AnimationKey = "airlock_animation";
|
|
|
|
|
|
2021-08-05 19:43:58 -07:00
|
|
|
[DataField("animationTime")]
|
2021-03-05 01:08:38 +01:00
|
|
|
private float _delay = 0.8f;
|
|
|
|
|
|
2021-08-05 19:43:58 -07:00
|
|
|
[DataField("denyAnimationTime")]
|
|
|
|
|
private float _denyDelay = 0.3f;
|
2021-03-05 01:08:38 +01:00
|
|
|
|
2021-08-05 19:43:58 -07:00
|
|
|
/// <summary>
|
|
|
|
|
/// Whether the maintenance panel is animated or stays static.
|
|
|
|
|
/// False for windoors.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DataField("animatedPanel")]
|
|
|
|
|
private bool _animatedPanel = true;
|
2021-03-05 01:08:38 +01:00
|
|
|
|
2021-11-11 20:06:38 +11:00
|
|
|
/// <summary>
|
|
|
|
|
/// Means the door is simply open / closed / opening / closing. No wires or access.
|
|
|
|
|
/// </summary>
|
2021-10-10 03:43:50 -07:00
|
|
|
[DataField("simpleVisuals")]
|
|
|
|
|
private bool _simpleVisuals = false;
|
|
|
|
|
|
2021-08-05 19:43:58 -07:00
|
|
|
/// <summary>
|
|
|
|
|
/// Whether the BaseUnlit layer should still be visible when the airlock
|
|
|
|
|
/// is opened.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DataField("openUnlitVisible")]
|
|
|
|
|
private bool _openUnlitVisible = false;
|
2021-03-05 01:08:38 +01:00
|
|
|
|
2022-02-09 03:13:35 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Whether the door should have an emergency access layer
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DataField("emergencyAccessLayer")]
|
|
|
|
|
private bool _emergencyAccessLayer = true;
|
|
|
|
|
|
2021-02-12 07:02:14 -08:00
|
|
|
private Animation CloseAnimation = default!;
|
|
|
|
|
private Animation OpenAnimation = default!;
|
|
|
|
|
private Animation DenyAnimation = default!;
|
2019-03-20 00:42:52 +01:00
|
|
|
|
2021-12-08 13:11:49 +01:00
|
|
|
void ISerializationHooks.AfterDeserialization()
|
2021-12-08 12:09:43 +01:00
|
|
|
{
|
|
|
|
|
IoCManager.InjectDependencies(this);
|
|
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
CloseAnimation = new Animation {Length = TimeSpan.FromSeconds(_delay)};
|
2019-03-20 00:42:52 +01:00
|
|
|
{
|
|
|
|
|
var flick = new AnimationTrackSpriteFlick();
|
|
|
|
|
CloseAnimation.AnimationTracks.Add(flick);
|
|
|
|
|
flick.LayerKey = DoorVisualLayers.Base;
|
|
|
|
|
flick.KeyFrames.Add(new AnimationTrackSpriteFlick.KeyFrame("closing", 0f));
|
|
|
|
|
|
2021-10-10 03:43:50 -07:00
|
|
|
if (!_simpleVisuals)
|
2021-08-05 19:43:58 -07:00
|
|
|
{
|
2021-10-10 03:43:50 -07:00
|
|
|
var flickUnlit = new AnimationTrackSpriteFlick();
|
|
|
|
|
CloseAnimation.AnimationTracks.Add(flickUnlit);
|
|
|
|
|
flickUnlit.LayerKey = DoorVisualLayers.BaseUnlit;
|
|
|
|
|
flickUnlit.KeyFrames.Add(new AnimationTrackSpriteFlick.KeyFrame("closing_unlit", 0f));
|
|
|
|
|
|
|
|
|
|
if (_animatedPanel)
|
|
|
|
|
{
|
|
|
|
|
var flickMaintenancePanel = new AnimationTrackSpriteFlick();
|
|
|
|
|
CloseAnimation.AnimationTracks.Add(flickMaintenancePanel);
|
|
|
|
|
flickMaintenancePanel.LayerKey = WiresVisualizer.WiresVisualLayers.MaintenancePanel;
|
|
|
|
|
flickMaintenancePanel.KeyFrames.Add(new AnimationTrackSpriteFlick.KeyFrame("panel_closing", 0f));
|
|
|
|
|
}
|
2021-08-05 19:43:58 -07:00
|
|
|
}
|
2019-03-20 00:42:52 +01:00
|
|
|
}
|
|
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
OpenAnimation = new Animation {Length = TimeSpan.FromSeconds(_delay)};
|
2019-03-20 00:42:52 +01:00
|
|
|
{
|
|
|
|
|
var flick = new AnimationTrackSpriteFlick();
|
|
|
|
|
OpenAnimation.AnimationTracks.Add(flick);
|
|
|
|
|
flick.LayerKey = DoorVisualLayers.Base;
|
|
|
|
|
flick.KeyFrames.Add(new AnimationTrackSpriteFlick.KeyFrame("opening", 0f));
|
|
|
|
|
|
2021-10-10 03:43:50 -07:00
|
|
|
if (!_simpleVisuals)
|
2021-08-05 19:43:58 -07:00
|
|
|
{
|
2021-10-10 03:43:50 -07:00
|
|
|
var flickUnlit = new AnimationTrackSpriteFlick();
|
|
|
|
|
OpenAnimation.AnimationTracks.Add(flickUnlit);
|
|
|
|
|
flickUnlit.LayerKey = DoorVisualLayers.BaseUnlit;
|
|
|
|
|
flickUnlit.KeyFrames.Add(new AnimationTrackSpriteFlick.KeyFrame("opening_unlit", 0f));
|
|
|
|
|
|
|
|
|
|
if (_animatedPanel)
|
|
|
|
|
{
|
|
|
|
|
var flickMaintenancePanel = new AnimationTrackSpriteFlick();
|
|
|
|
|
OpenAnimation.AnimationTracks.Add(flickMaintenancePanel);
|
|
|
|
|
flickMaintenancePanel.LayerKey = WiresVisualizer.WiresVisualLayers.MaintenancePanel;
|
|
|
|
|
flickMaintenancePanel.KeyFrames.Add(new AnimationTrackSpriteFlick.KeyFrame("panel_opening", 0f));
|
|
|
|
|
}
|
2021-08-05 19:43:58 -07:00
|
|
|
}
|
2019-03-20 00:42:52 +01:00
|
|
|
}
|
2019-09-01 22:57:22 +02:00
|
|
|
|
2021-10-10 03:43:50 -07:00
|
|
|
if (!_simpleVisuals)
|
2019-09-01 22:57:22 +02:00
|
|
|
{
|
2021-10-10 03:43:50 -07:00
|
|
|
DenyAnimation = new Animation {Length = TimeSpan.FromSeconds(_denyDelay)};
|
|
|
|
|
{
|
|
|
|
|
var flick = new AnimationTrackSpriteFlick();
|
|
|
|
|
DenyAnimation.AnimationTracks.Add(flick);
|
|
|
|
|
flick.LayerKey = DoorVisualLayers.BaseUnlit;
|
|
|
|
|
flick.KeyFrames.Add(new AnimationTrackSpriteFlick.KeyFrame("deny_unlit", 0f));
|
|
|
|
|
}
|
2019-09-01 22:57:22 +02:00
|
|
|
}
|
2019-03-20 00:42:52 +01:00
|
|
|
}
|
|
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
public override void InitializeEntity(EntityUid entity)
|
2019-03-16 20:40:07 +01:00
|
|
|
{
|
2021-12-08 12:09:43 +01:00
|
|
|
if (!_entMan.HasComponent<AnimationPlayerComponent>(entity))
|
2019-03-17 13:24:26 +01:00
|
|
|
{
|
2021-12-08 12:09:43 +01:00
|
|
|
_entMan.AddComponent<AnimationPlayerComponent>(entity);
|
2019-03-17 13:24:26 +01:00
|
|
|
}
|
|
|
|
|
}
|
2019-03-16 20:40:07 +01:00
|
|
|
|
2019-03-17 13:24:26 +01:00
|
|
|
public override void OnChangeData(AppearanceComponent component)
|
|
|
|
|
{
|
2022-01-30 13:49:56 +13:00
|
|
|
// only start playing animations once.
|
|
|
|
|
if (!_gameTiming.IsFirstTimePredicted)
|
|
|
|
|
return;
|
|
|
|
|
|
2020-11-14 00:42:35 +11:00
|
|
|
base.OnChangeData(component);
|
2020-07-02 15:31:06 +02:00
|
|
|
|
2021-12-08 12:09:43 +01:00
|
|
|
var sprite = _entMan.GetComponent<ISpriteComponent>(component.Owner);
|
|
|
|
|
var animPlayer = _entMan.GetComponent<AnimationPlayerComponent>(component.Owner);
|
2022-01-30 13:49:56 +13:00
|
|
|
if (!component.TryGetData(DoorVisuals.State, out DoorState state))
|
2019-03-16 20:40:07 +01:00
|
|
|
{
|
2022-01-30 13:49:56 +13:00
|
|
|
state = DoorState.Closed;
|
2019-03-16 20:40:07 +01:00
|
|
|
}
|
|
|
|
|
|
2022-01-30 13:49:56 +13:00
|
|
|
var door = _entMan.GetComponent<DoorComponent>(component.Owner);
|
2019-10-13 16:39:21 +02:00
|
|
|
var unlitVisible = true;
|
2020-07-02 15:31:06 +02:00
|
|
|
var boltedVisible = false;
|
2020-08-30 19:16:29 +10:00
|
|
|
var weldedVisible = false;
|
2022-02-09 03:13:35 +00:00
|
|
|
var emergencyLightsVisible = false;
|
2021-02-12 07:02:14 -08:00
|
|
|
|
|
|
|
|
if (animPlayer.HasRunningAnimation(AnimationKey))
|
|
|
|
|
{
|
|
|
|
|
animPlayer.Stop(AnimationKey);
|
|
|
|
|
}
|
2019-03-16 20:40:07 +01:00
|
|
|
switch (state)
|
|
|
|
|
{
|
2022-01-30 13:49:56 +13:00
|
|
|
case DoorState.Open:
|
2021-02-12 07:02:14 -08:00
|
|
|
sprite.LayerSetState(DoorVisualLayers.Base, "open");
|
2021-08-05 19:43:58 -07:00
|
|
|
unlitVisible = _openUnlitVisible;
|
2021-10-10 03:43:50 -07:00
|
|
|
if (_openUnlitVisible && !_simpleVisuals)
|
2021-08-05 19:43:58 -07:00
|
|
|
{
|
|
|
|
|
sprite.LayerSetState(DoorVisualLayers.BaseUnlit, "open_unlit");
|
|
|
|
|
}
|
2021-02-12 07:02:14 -08:00
|
|
|
break;
|
2022-01-30 13:49:56 +13:00
|
|
|
case DoorState.Closed:
|
2019-03-16 20:40:07 +01:00
|
|
|
sprite.LayerSetState(DoorVisualLayers.Base, "closed");
|
2021-10-10 03:43:50 -07:00
|
|
|
if (!_simpleVisuals)
|
|
|
|
|
{
|
|
|
|
|
sprite.LayerSetState(DoorVisualLayers.BaseUnlit, "closed_unlit");
|
|
|
|
|
sprite.LayerSetState(DoorVisualLayers.BaseBolted, "bolted_unlit");
|
|
|
|
|
}
|
2019-03-16 20:40:07 +01:00
|
|
|
break;
|
2022-01-30 13:49:56 +13:00
|
|
|
case DoorState.Opening:
|
2021-02-12 07:02:14 -08:00
|
|
|
animPlayer.Play(OpenAnimation, AnimationKey);
|
2019-03-17 13:24:26 +01:00
|
|
|
break;
|
2022-01-30 13:49:56 +13:00
|
|
|
case DoorState.Closing:
|
|
|
|
|
if (door.CurrentlyCrushing.Count == 0)
|
|
|
|
|
animPlayer.Play(CloseAnimation, AnimationKey);
|
|
|
|
|
else
|
|
|
|
|
sprite.LayerSetState(DoorVisualLayers.Base, "closed");
|
2019-03-16 20:40:07 +01:00
|
|
|
break;
|
2022-01-30 13:49:56 +13:00
|
|
|
case DoorState.Denying:
|
|
|
|
|
animPlayer.Play(DenyAnimation, AnimationKey);
|
2019-09-01 22:57:22 +02:00
|
|
|
break;
|
2022-01-30 13:49:56 +13:00
|
|
|
case DoorState.Welded:
|
2020-08-30 19:16:29 +10:00
|
|
|
weldedVisible = true;
|
|
|
|
|
break;
|
2019-03-16 20:40:07 +01:00
|
|
|
default:
|
|
|
|
|
throw new ArgumentOutOfRangeException();
|
|
|
|
|
}
|
2019-10-13 16:39:21 +02:00
|
|
|
|
|
|
|
|
if (component.TryGetData(DoorVisuals.Powered, out bool powered) && !powered)
|
|
|
|
|
{
|
|
|
|
|
unlitVisible = false;
|
|
|
|
|
}
|
2020-07-02 15:31:06 +02:00
|
|
|
if (component.TryGetData(DoorVisuals.BoltLights, out bool lights) && lights)
|
|
|
|
|
{
|
|
|
|
|
boltedVisible = true;
|
|
|
|
|
}
|
2019-10-13 16:39:21 +02:00
|
|
|
|
2022-02-09 03:13:35 +00:00
|
|
|
if (component.TryGetData(DoorVisuals.EmergencyLights, out bool eaLights) && eaLights)
|
|
|
|
|
{
|
|
|
|
|
emergencyLightsVisible = true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-10 03:43:50 -07:00
|
|
|
if (!_simpleVisuals)
|
|
|
|
|
{
|
2022-01-30 13:49:56 +13:00
|
|
|
sprite.LayerSetVisible(DoorVisualLayers.BaseUnlit, unlitVisible && state != DoorState.Closed && state != DoorState.Welded);
|
2021-10-10 03:43:50 -07:00
|
|
|
sprite.LayerSetVisible(DoorVisualLayers.BaseWelded, weldedVisible);
|
|
|
|
|
sprite.LayerSetVisible(DoorVisualLayers.BaseBolted, unlitVisible && boltedVisible);
|
2022-02-09 03:13:35 +00:00
|
|
|
if (_emergencyAccessLayer)
|
|
|
|
|
{
|
2022-02-16 00:23:23 -07:00
|
|
|
sprite.LayerSetVisible(DoorVisualLayers.BaseEmergencyAccess,
|
|
|
|
|
emergencyLightsVisible
|
|
|
|
|
&& state != DoorState.Open
|
|
|
|
|
&& state != DoorState.Opening
|
2022-02-09 03:13:35 +00:00
|
|
|
&& state != DoorState.Closing
|
|
|
|
|
&& unlitVisible);
|
|
|
|
|
}
|
2021-10-10 03:43:50 -07:00
|
|
|
}
|
2019-03-16 20:40:07 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-04 11:57:33 +01:00
|
|
|
public enum DoorVisualLayers : byte
|
2019-03-16 20:40:07 +01:00
|
|
|
{
|
2019-06-02 13:40:56 +02:00
|
|
|
Base,
|
2020-07-02 15:31:06 +02:00
|
|
|
BaseUnlit,
|
2020-08-30 19:16:29 +10:00
|
|
|
BaseWelded,
|
|
|
|
|
BaseBolted,
|
2022-02-09 03:13:35 +00:00
|
|
|
BaseEmergencyAccess,
|
2019-03-16 20:40:07 +01:00
|
|
|
}
|
|
|
|
|
}
|