2023-02-26 18:48:57 +11:00
|
|
|
using Content.Server.Popups;
|
2021-10-05 14:29:03 +11:00
|
|
|
using Content.Shared.Popups;
|
|
|
|
|
using Content.Shared.Rotatable;
|
|
|
|
|
using Content.Shared.Verbs;
|
|
|
|
|
using Robust.Shared.Physics;
|
2023-01-03 17:45:18 +11:00
|
|
|
using Robust.Shared.Physics.Components;
|
2023-02-26 18:48:57 +11:00
|
|
|
using Robust.Shared.Utility;
|
2021-10-05 14:29:03 +11:00
|
|
|
|
|
|
|
|
namespace Content.Server.Rotatable
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handles verbs for the <see cref="RotatableComponent"/> and <see cref="FlippableComponent"/> components.
|
|
|
|
|
/// </summary>
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class RotatableSystem : EntitySystem
|
2021-10-05 14:29:03 +11:00
|
|
|
{
|
2023-02-26 18:48:57 +11:00
|
|
|
[Dependency] private readonly PopupSystem _popup = default!;
|
|
|
|
|
|
2021-10-05 14:29:03 +11:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
2022-02-10 15:30:59 +13:00
|
|
|
SubscribeLocalEvent<FlippableComponent, GetVerbsEvent<Verb>>(AddFlipVerb);
|
|
|
|
|
SubscribeLocalEvent<RotatableComponent, GetVerbsEvent<Verb>>(AddRotateVerbs);
|
2021-10-05 14:29:03 +11:00
|
|
|
}
|
|
|
|
|
|
2022-02-10 15:30:59 +13:00
|
|
|
private void AddFlipVerb(EntityUid uid, FlippableComponent component, GetVerbsEvent<Verb> args)
|
2021-10-05 14:29:03 +11:00
|
|
|
{
|
2023-02-26 18:48:57 +11:00
|
|
|
if (!args.CanAccess || !args.CanInteract)
|
2021-10-05 14:29:03 +11:00
|
|
|
return;
|
|
|
|
|
|
2023-02-26 18:48:57 +11:00
|
|
|
Verb verb = new()
|
|
|
|
|
{
|
|
|
|
|
Act = () => TryFlip(uid, component, args.User),
|
|
|
|
|
Text = Loc.GetString("flippable-verb-get-data-text"),
|
2023-03-05 00:36:09 +00:00
|
|
|
Category = VerbCategory.Rotate,
|
2023-04-20 20:16:01 +10:00
|
|
|
Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/flip.svg.192dpi.png")),
|
2023-03-05 00:36:09 +00:00
|
|
|
Priority = -3, // show flip last
|
2023-02-26 18:48:57 +11:00
|
|
|
DoContactInteraction = true
|
|
|
|
|
};
|
2021-10-05 14:29:03 +11:00
|
|
|
args.Verbs.Add(verb);
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-10 15:30:59 +13:00
|
|
|
private void AddRotateVerbs(EntityUid uid, RotatableComponent component, GetVerbsEvent<Verb> args)
|
2021-10-05 14:29:03 +11:00
|
|
|
{
|
2022-06-03 22:09:51 +12:00
|
|
|
if (!args.CanAccess
|
|
|
|
|
|| !args.CanInteract
|
|
|
|
|
|| Transform(uid).NoLocalRotation) // Good ol prototype inheritance, eh?
|
2021-10-05 14:29:03 +11:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Check if the object is anchored, and whether we are still allowed to rotate it.
|
|
|
|
|
if (!component.RotateWhileAnchored &&
|
2023-02-26 18:48:57 +11:00
|
|
|
EntityManager.TryGetComponent(uid, out PhysicsComponent? physics) &&
|
2021-10-05 14:29:03 +11:00
|
|
|
physics.BodyType == BodyType.Static)
|
|
|
|
|
return;
|
|
|
|
|
|
2021-12-31 02:20:22 +00:00
|
|
|
Verb resetRotation = new ()
|
|
|
|
|
{
|
2022-10-26 14:15:48 +13:00
|
|
|
DoContactInteraction = true,
|
2023-02-26 18:48:57 +11:00
|
|
|
Act = () => EntityManager.GetComponent<TransformComponent>(uid).LocalRotation = Angle.Zero,
|
2021-12-31 02:20:22 +00:00
|
|
|
Category = VerbCategory.Rotate,
|
2023-04-20 20:16:01 +10:00
|
|
|
Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/refresh.svg.192dpi.png")),
|
2021-12-31 02:20:22 +00:00
|
|
|
Text = "Reset",
|
|
|
|
|
Priority = -2, // show CCW, then CW, then reset
|
|
|
|
|
CloseMenu = false,
|
|
|
|
|
};
|
2021-10-09 09:23:34 -07:00
|
|
|
args.Verbs.Add(resetRotation);
|
|
|
|
|
|
2021-10-05 14:29:03 +11:00
|
|
|
// rotate clockwise
|
2021-12-31 02:20:22 +00:00
|
|
|
Verb rotateCW = new()
|
|
|
|
|
{
|
2023-02-26 18:48:57 +11:00
|
|
|
Act = () => EntityManager.GetComponent<TransformComponent>(uid).LocalRotation -= component.Increment,
|
2021-12-31 02:20:22 +00:00
|
|
|
Category = VerbCategory.Rotate,
|
2023-04-20 20:16:01 +10:00
|
|
|
Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/rotate_cw.svg.192dpi.png")),
|
2021-12-31 02:20:22 +00:00
|
|
|
Priority = -1,
|
|
|
|
|
CloseMenu = false, // allow for easy double rotations.
|
|
|
|
|
};
|
2021-10-05 14:29:03 +11:00
|
|
|
args.Verbs.Add(rotateCW);
|
|
|
|
|
|
|
|
|
|
// rotate counter-clockwise
|
2021-12-31 02:20:22 +00:00
|
|
|
Verb rotateCCW = new()
|
|
|
|
|
{
|
2023-02-26 18:48:57 +11:00
|
|
|
Act = () => EntityManager.GetComponent<TransformComponent>(uid).LocalRotation += component.Increment,
|
2021-12-31 02:20:22 +00:00
|
|
|
Category = VerbCategory.Rotate,
|
2023-04-20 20:16:01 +10:00
|
|
|
Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/rotate_ccw.svg.192dpi.png")),
|
2021-12-31 02:20:22 +00:00
|
|
|
Priority = 0,
|
|
|
|
|
CloseMenu = false, // allow for easy double rotations.
|
|
|
|
|
};
|
2021-10-05 14:29:03 +11:00
|
|
|
args.Verbs.Add(rotateCCW);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Replace a flippable entity with it's flipped / mirror-symmetric entity.
|
|
|
|
|
/// </summary>
|
2023-02-26 18:48:57 +11:00
|
|
|
public void TryFlip(EntityUid uid, FlippableComponent component, EntityUid user)
|
2021-10-05 14:29:03 +11:00
|
|
|
{
|
2023-02-26 18:48:57 +11:00
|
|
|
if (EntityManager.TryGetComponent(uid, out PhysicsComponent? physics) &&
|
2021-10-05 14:29:03 +11:00
|
|
|
physics.BodyType == BodyType.Static)
|
|
|
|
|
{
|
2023-02-26 18:48:57 +11:00
|
|
|
_popup.PopupEntity(Loc.GetString("flippable-component-try-flip-is-stuck"), uid, user);
|
2021-10-05 14:29:03 +11:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-26 18:48:57 +11:00
|
|
|
var oldTransform = EntityManager.GetComponent<TransformComponent>(uid);
|
2021-12-08 13:00:43 +01:00
|
|
|
var entity = EntityManager.SpawnEntity(component.MirrorEntity, oldTransform.Coordinates);
|
|
|
|
|
var newTransform = EntityManager.GetComponent<TransformComponent>(entity);
|
2021-11-13 01:54:03 +00:00
|
|
|
newTransform.LocalRotation = oldTransform.LocalRotation;
|
|
|
|
|
newTransform.Anchored = false;
|
2023-02-26 18:48:57 +11:00
|
|
|
EntityManager.DeleteEntity(uid);
|
2021-10-05 14:29:03 +11:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|