Files
wwdpublic/Content.Client/Buckle/BuckleSystem.cs
VMSolidus e3639f793a Better Lying Down System (From White Dream) (#815)
# Description

Port of https://github.com/WWhiteDreamProject/wwdpublic/pull/2
And now also https://github.com/WWhiteDreamProject/wwdpublic/pull/8
Because Lying Down System is dependent on the Telescope System.

# TODO

- [x] Reconcile the code with core code, do code cleanup. I'll undraft
this when I'm done. Probably not going to be tonight, because I will
have to get some sleep soon to get up early for my calculus classes.

# Changelog

🆑 Spatison (White Dream)
- add: Added lying down system / Добавлена система лежания
- tweak: Lying down now uses do-afters that are visible to other people
to indicate what is going on.
- add: Added telescope system / Добавлена система прицеливания
- tweak: Now you can aim from Hristov / Теперь можно прицеливаться из
Христова

---------

Signed-off-by: VMSolidus <evilexecutive@gmail.com>
Co-authored-by: Spatison <137375981+Spatison@users.noreply.github.com>
Co-authored-by: DEATHB4DEFEAT <77995199+DEATHB4DEFEAT@users.noreply.github.com>
# Conflicts:
#	Content.Client/Input/ContentContexts.cs
#	Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs
#	Content.Shared/Input/ContentKeyFunctions.cs
#	Resources/Prototypes/Entities/Objects/Weapons/Guns/Snipers/snipers.yml
#	Resources/keybinds.yml
2024-10-19 13:02:04 +07:00

63 lines
2.7 KiB
C#

using Content.Client.Rotation;
using Content.Shared.Buckle;
using Content.Shared.Buckle.Components;
using Content.Shared.Rotation;
using Robust.Client.GameObjects;
namespace Content.Client.Buckle;
internal sealed class BuckleSystem : SharedBuckleSystem
{
[Dependency] private readonly RotationVisualizerSystem _rotationVisualizerSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<BuckleComponent, AfterAutoHandleStateEvent>(OnBuckleAfterAutoHandleState);
SubscribeLocalEvent<BuckleComponent, AppearanceChangeEvent>(OnAppearanceChange);
}
private void OnBuckleAfterAutoHandleState(EntityUid uid, BuckleComponent component, ref AfterAutoHandleStateEvent args)
{
ActionBlocker.UpdateCanMove(uid);
if (!TryComp<SpriteComponent>(uid, out var ownerSprite))
return;
// Adjust draw depth when the chair faces north so that the seat back is drawn over the player.
// Reset the draw depth when rotated in any other direction.
// TODO when ECSing, make this a visualizer
// This code was written before rotatable viewports were introduced, so hard-coding Direction.North
// and comparing it against LocalRotation now breaks this in other rotations. This is a FIXME, but
// better to get it working for most people before we look at a more permanent solution.
if (component is { Buckled: true, LastEntityBuckledTo: { } } &&
Transform(component.LastEntityBuckledTo.Value).LocalRotation.GetCardinalDir() == Direction.North &&
TryComp<SpriteComponent>(component.LastEntityBuckledTo, out var buckledSprite))
{
component.OriginalDrawDepth ??= ownerSprite.DrawDepth;
ownerSprite.DrawDepth = buckledSprite.DrawDepth - 1;
return;
}
// If here, we're not turning north and should restore the saved draw depth.
if (component.OriginalDrawDepth.HasValue)
{
ownerSprite.DrawDepth = component.OriginalDrawDepth.Value;
component.OriginalDrawDepth = null;
}
}
private void OnAppearanceChange(EntityUid uid, BuckleComponent component, ref AppearanceChangeEvent args)
{
if (!TryComp<RotationVisualsComponent>(uid, out var rotVisuals)
|| !Appearance.TryGetData<bool>(uid, BuckleVisuals.Buckled, out var buckled, args.Component)
|| !buckled || args.Sprite == null)
return;
// Animate strapping yourself to something at a given angle
// TODO: Dump this when buckle is better
_rotationVisualizerSystem.AnimateSpriteRotation(uid, args.Sprite, rotVisuals.HorizontalRotation, 0.125f);
}
}