2021-07-31 15:17:16 +02:00
|
|
|
using System;
|
|
|
|
|
using Content.Shared.Sound;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Trigger;
|
2020-12-08 11:56:10 +01:00
|
|
|
using JetBrains.Annotations;
|
2019-06-07 16:15:20 +05:00
|
|
|
using Robust.Client.Animations;
|
|
|
|
|
using Robust.Client.GameObjects;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-03-05 01:08:38 +01:00
|
|
|
using Robust.Shared.Serialization;
|
|
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2019-06-07 16:15:20 +05:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Client.Trigger
|
2019-06-07 16:15:20 +05:00
|
|
|
{
|
2020-12-08 11:56:10 +01:00
|
|
|
[UsedImplicitly]
|
2021-03-05 01:08:38 +01:00
|
|
|
public class TimerTriggerVisualizer : AppearanceVisualizer, ISerializationHooks
|
2019-06-07 16:15:20 +05:00
|
|
|
{
|
|
|
|
|
private const string AnimationKey = "priming_animation";
|
|
|
|
|
|
2021-08-13 21:31:37 -07:00
|
|
|
[DataField("countdown_sound", required: true)]
|
2021-07-31 15:17:16 +02:00
|
|
|
private SoundSpecifier _countdownSound = default!;
|
2021-03-05 01:08:38 +01:00
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
private Animation PrimingAnimation = default!;
|
2019-06-07 16:15:20 +05:00
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
void ISerializationHooks.AfterDeserialization()
|
2019-06-07 16:15:20 +05:00
|
|
|
{
|
|
|
|
|
PrimingAnimation = new Animation { Length = TimeSpan.MaxValue };
|
|
|
|
|
{
|
|
|
|
|
var flick = new AnimationTrackSpriteFlick();
|
|
|
|
|
PrimingAnimation.AnimationTracks.Add(flick);
|
|
|
|
|
flick.LayerKey = TriggerVisualLayers.Base;
|
|
|
|
|
flick.KeyFrames.Add(new AnimationTrackSpriteFlick.KeyFrame("primed", 0f));
|
|
|
|
|
|
2021-07-31 19:52:33 +02:00
|
|
|
var sound = new AnimationTrackPlaySound();
|
|
|
|
|
PrimingAnimation.AnimationTracks.Add(sound);
|
|
|
|
|
sound.KeyFrames.Add(new AnimationTrackPlaySound.KeyFrame(_countdownSound.GetSound(), 0));
|
2019-06-07 16:15:20 +05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void InitializeEntity(IEntity entity)
|
|
|
|
|
{
|
|
|
|
|
if (!entity.HasComponent<AnimationPlayerComponent>())
|
|
|
|
|
{
|
|
|
|
|
entity.AddComponent<AnimationPlayerComponent>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnChangeData(AppearanceComponent component)
|
|
|
|
|
{
|
|
|
|
|
var sprite = component.Owner.GetComponent<ISpriteComponent>();
|
|
|
|
|
var animPlayer = component.Owner.GetComponent<AnimationPlayerComponent>();
|
|
|
|
|
if (!component.TryGetData(TriggerVisuals.VisualState, out TriggerVisualState state))
|
|
|
|
|
{
|
|
|
|
|
state = TriggerVisualState.Unprimed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (state)
|
|
|
|
|
{
|
|
|
|
|
case TriggerVisualState.Primed:
|
|
|
|
|
if (!animPlayer.HasRunningAnimation(AnimationKey))
|
|
|
|
|
{
|
|
|
|
|
animPlayer.Play(PrimingAnimation, AnimationKey);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case TriggerVisualState.Unprimed:
|
|
|
|
|
sprite.LayerSetState(0, "icon");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
throw new ArgumentOutOfRangeException();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-04 11:57:33 +01:00
|
|
|
public enum TriggerVisualLayers : byte
|
2019-06-07 16:15:20 +05:00
|
|
|
{
|
|
|
|
|
Base
|
|
|
|
|
}
|
|
|
|
|
}
|