Files
tbd-station-14/Content.Client/Pointing/PointingSystem.cs
Leon Friedrich 22d72f56b5 Guidebook Revival (#13320)
* Fix some bugs in stations and do a little cleanup.

* Begin backporting the guidebook.

* wow that's a lot of work.

* More work, gives the monkey some more interactions.

* disco monkye.

* monky

* jobs entry.

* more writing.

* disco

* im being harassed

* fix spacing.

* i hate writing.

* Update Resources/Prototypes/Entities/Mobs/NPCs/animals.yml

Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com>

* builds again

* a

* pilfer changes from AL

* fix and remove unused code

* pilfer actual guide changes from AL

* localization

* more error logs & safety checks

* replace controls button with command

* add test

* todos

* pidgin parsing

* remove old parser

* Move files and change tree sorting

* add localization and public methods.

* Add help component/verb

* rename ITag to IDocumentTag

* Fix yml and tweak tooltips

* autoclose tooltip

* Split container

* Fancier-tree

* Hover color

* txt to xml

* oops

* Curse you hidden merge conflicts

* Rename parsing manager

* Stricter arg parsing

tag args must now be of the form key="value"

* Change default args

* Moar tests

* nullable enable

* Even fancier tree

* extremely fancy trees

* better indent icons

* stricter xml and subheadings

* tweak embed margin

* Fix parsing bugs

* quick fixes.

* spain.

* ogh

* hn bmvdsyc

Co-authored-by: moonheart08 <moonheart08@users.noreply.github.com>
2023-01-16 02:42:22 -06:00

120 lines
4.4 KiB
C#

using Content.Client.Pointing.Components;
using Content.Shared.Mobs.Systems;
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 : SharedPointingSystem
{
[Dependency] private readonly AnimationPlayerSystem _player = default!;
[Dependency] private readonly MobStateSystem _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)
{
if (args.Target.IsClientSide())
return;
// Really this could probably be a properly predicted event, but that requires reworking pointing. For now
// I'm just adding this verb exclusively to clients so that the verb-loading pop-in on the verb menu isn't
// as bad. Important for this verb seeing as its usually an option on just about any entity.
if (HasComp<PointingArrowComponent>(args.Target))
{
// this is a pointing arrow. no pointing here...
return;
}
// Can the user point? Checking mob state directly instead of some action blocker, as many action blockers are blocked for
// ghosts and there is no obvious choice for pointing (unless ghosts CanEmote?).
if (_mobState.IsIncapacitated(args.User))
return;
// We won't check in range or visibility, as this verb is currently only executable via the context menu,
// and that should already have checked that, as well as handling the FOV-toggle stuff.
Verb verb = new()
{
Text = Loc.GetString("pointing-verb-get-data-text"),
IconTexture = "/Textures/Interface/VerbIcons/point.svg.192dpi.png",
ClientExclusive = true,
Act = () => RaiseNetworkEvent(new PointingAttemptEvent(args.Target))
};
args.Verbs.Add(verb);
}
private void OnArrowStartup(EntityUid uid, PointingArrowComponent arrow, ComponentStartup args)
{
if (EntityManager.TryGetComponent(uid, out SpriteComponent? sprite))
{
sprite.DrawDepth = (int) DrawDepth.Overlays;
}
_player.Play(uid, PointingAnimation, AnimationKey);
}
private void OnRogueArrowStartup(EntityUid uid, RoguePointingArrowComponent arrow, ComponentStartup args)
{
if (EntityManager.TryGetComponent(uid, out SpriteComponent? sprite))
{
sprite.DrawDepth = (int) DrawDepth.Overlays;
sprite.NoRotation = false;
}
}
}