Pointing arrow changes (#11097)

This commit is contained in:
metalgearsloth
2022-09-17 00:37:15 +10:00
committed by GitHub
parent 9aa8a674bf
commit 14d48f4306
10 changed files with 115 additions and 151 deletions

View File

@@ -1,12 +1,7 @@
using Content.Shared.Pointing.Components;
using Robust.Client.GameObjects;
using DrawDepth = Content.Shared.DrawDepth.DrawDepth;
namespace Content.Client.Pointing.Components
{
[RegisterComponent]
[ComponentReference(typeof(SharedPointingArrowComponent))]
public sealed class PointingArrowComponent : SharedPointingArrowComponent
{
}
public sealed class PointingArrowComponent : SharedPointingArrowComponent {}
}

View File

@@ -2,23 +2,66 @@ using Content.Client.Pointing.Components;
using Content.Shared.MobState.EntitySystems;
using Content.Shared.Pointing;
using Content.Shared.Verbs;
using Robust.Client.Animations;
using Robust.Client.GameObjects;
using Robust.Shared.Animations;
using DrawDepth = Content.Shared.DrawDepth.DrawDepth;
namespace Content.Client.Pointing;
public sealed class PointingSystem : EntitySystem
public sealed class PointingSystem : SharedPointingSystem
{
[Dependency] private readonly AnimationPlayerSystem _player = default!;
[Dependency] private readonly SharedMobStateSystem _mobState = default!;
private const string AnimationKey = "pointingarrow";
/// <summary>
/// How far it goes in any direction.
/// </summary>
private const float Offset = 0.25f;
/// <summary>
/// How long it takes to go from the bottom of the animation to the top.
/// </summary>
private const float UpTime = 0.5f;
/// <summary>
/// Starts at the bottom then goes up and comes back down. Seems to look nicer than starting in the middle.
/// </summary>
private static readonly Animation PointingAnimation = new Animation()
{
Length = TimeSpan.FromSeconds(2 * UpTime),
AnimationTracks =
{
new AnimationTrackComponentProperty()
{
ComponentType = typeof(SpriteComponent),
Property = nameof(SpriteComponent.Offset),
InterpolationMode = AnimationInterpolationMode.Linear,
KeyFrames =
{
new AnimationTrackProperty.KeyFrame(Vector2.Zero, 0f),
new AnimationTrackProperty.KeyFrame(new Vector2(0f, Offset), UpTime),
new AnimationTrackProperty.KeyFrame(Vector2.Zero, UpTime),
}
}
}
};
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<GetVerbsEvent<Verb>>(AddPointingVerb);
SubscribeLocalEvent<PointingArrowComponent, ComponentStartup>(OnArrowStartup);
SubscribeLocalEvent<PointingArrowComponent, AnimationCompletedEvent>(OnArrowAnimation);
SubscribeLocalEvent<RoguePointingArrowComponent, ComponentStartup>(OnRogueArrowStartup);
}
private void OnArrowAnimation(EntityUid uid, PointingArrowComponent component, AnimationCompletedEvent args)
{
_player.Play(uid, PointingAnimation, AnimationKey);
}
private void AddPointingVerb(GetVerbsEvent<Verb> args)
@@ -58,6 +101,8 @@ public sealed class PointingSystem : EntitySystem
{
sprite.DrawDepth = (int) DrawDepth.Overlays;
}
_player.Play(uid, PointingAnimation, AnimationKey);
}
private void OnRogueArrowStartup(EntityUid uid, RoguePointingArrowComponent arrow, ComponentStartup args)
@@ -65,6 +110,7 @@ public sealed class PointingSystem : EntitySystem
if (EntityManager.TryGetComponent(uid, out SpriteComponent? sprite))
{
sprite.DrawDepth = (int) DrawDepth.Overlays;
sprite.NoRotation = false;
}
}
}

View File

@@ -1,62 +0,0 @@
using System;
using Content.Shared.Pointing.Components;
using JetBrains.Annotations;
using Robust.Client.Animations;
using Robust.Client.GameObjects;
using Robust.Shared.Animations;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
namespace Content.Client.Pointing
{
[UsedImplicitly]
public sealed class RoguePointingArrowVisualizer : AppearanceVisualizer
{
[Obsolete("Subscribe to AppearanceChangeEvent instead.")]
public override void OnChangeData(AppearanceComponent component)
{
base.OnChangeData(component);
if (component.TryGetData<double>(RoguePointingArrowVisuals.Rotation, out var degrees))
{
SetRotation(component, Angle.FromDegrees(degrees));
}
}
private void SetRotation(AppearanceComponent component, Angle rotation)
{
var sprite = IoCManager.Resolve<IEntityManager>().GetComponent<ISpriteComponent>(component.Owner);
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(sprite.Owner, out AnimationPlayerComponent? animation))
{
sprite.Rotation = rotation;
return;
}
if (animation.HasRunningAnimation("rotate"))
{
animation.Stop("rotate");
}
animation.Play(new Animation
{
Length = TimeSpan.FromSeconds(0.125),
AnimationTracks =
{
new AnimationTrackComponentProperty
{
ComponentType = typeof(ISpriteComponent),
Property = nameof(ISpriteComponent.Rotation),
InterpolationMode = AnimationInterpolationMode.Linear,
KeyFrames =
{
new AnimationTrackProperty.KeyFrame(sprite.Rotation, 0),
new AnimationTrackProperty.KeyFrame(rotation, 0.125f)
}
}
}
}, "rotate");
}
}
}