2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.ActionBlocker;
|
2021-06-19 10:03:24 +02:00
|
|
|
using Content.Shared.Interaction.Events;
|
2021-06-13 14:52:40 +02:00
|
|
|
using Content.Shared.Notification.Managers;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Rotatable;
|
|
|
|
|
using Content.Shared.Verbs;
|
2019-11-06 17:22:26 +01:00
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
using Robust.Shared.Localization;
|
|
|
|
|
using Robust.Shared.Maths;
|
2021-03-08 04:09:59 +11:00
|
|
|
using Robust.Shared.Physics;
|
2019-11-06 17:22:26 +01:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.Rotation.Components
|
2019-11-06 17:22:26 +01:00
|
|
|
{
|
|
|
|
|
[RegisterComponent]
|
2021-05-05 06:29:26 +03:00
|
|
|
[ComponentReference(typeof(SharedRotatableComponent))]
|
|
|
|
|
public class RotatableComponent : SharedRotatableComponent
|
2019-11-06 17:22:26 +01:00
|
|
|
{
|
|
|
|
|
private void TryRotate(IEntity user, Angle angle)
|
|
|
|
|
{
|
2021-03-16 15:50:20 +01:00
|
|
|
if (!RotateWhileAnchored && Owner.TryGetComponent(out IPhysBody? physics))
|
2019-11-06 17:22:26 +01:00
|
|
|
{
|
2021-03-08 04:09:59 +11:00
|
|
|
if (physics.BodyType == BodyType.Static)
|
2019-11-06 17:22:26 +01:00
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
Owner.PopupMessage(user, Loc.GetString("rotatable-component-try-rotate-stuck"));
|
2019-11-06 17:22:26 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Owner.Transform.LocalRotation += angle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Verb]
|
|
|
|
|
public sealed class RotateVerb : Verb<RotatableComponent>
|
|
|
|
|
{
|
2020-05-23 03:09:44 +02:00
|
|
|
protected override void GetData(IEntity user, RotatableComponent component, VerbData data)
|
2019-11-06 17:22:26 +01:00
|
|
|
{
|
2021-06-19 10:03:24 +02:00
|
|
|
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(user) || (!component.RotateWhileAnchored && component.Owner.TryGetComponent(out IPhysBody? physics) && physics.BodyType == BodyType.Static))
|
2020-06-22 18:54:56 +02:00
|
|
|
{
|
|
|
|
|
data.Visibility = VerbVisibility.Invisible;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-23 03:09:44 +02:00
|
|
|
data.CategoryData = VerbCategories.Rotate;
|
2021-06-21 02:13:54 +02:00
|
|
|
data.Text = Loc.GetString("rotate-verb-get-data-text");
|
2021-03-14 14:40:01 +01:00
|
|
|
data.IconTexture = "/Textures/Interface/VerbIcons/rotate_cw.svg.192dpi.png";
|
2019-11-06 17:22:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Activate(IEntity user, RotatableComponent component)
|
|
|
|
|
{
|
2020-05-16 22:42:17 +01:00
|
|
|
component.TryRotate(user, Angle.FromDegrees(-90));
|
2019-11-06 17:22:26 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Verb]
|
|
|
|
|
public sealed class RotateCounterVerb : Verb<RotatableComponent>
|
|
|
|
|
{
|
2020-05-23 03:09:44 +02:00
|
|
|
protected override void GetData(IEntity user, RotatableComponent component, VerbData data)
|
2019-11-06 17:22:26 +01:00
|
|
|
{
|
2021-06-19 10:03:24 +02:00
|
|
|
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(user) || (!component.RotateWhileAnchored && component.Owner.TryGetComponent(out IPhysBody? physics) && physics.BodyType == BodyType.Static))
|
2020-06-22 18:54:56 +02:00
|
|
|
{
|
|
|
|
|
data.Visibility = VerbVisibility.Invisible;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-23 03:09:44 +02:00
|
|
|
data.CategoryData = VerbCategories.Rotate;
|
2021-06-21 02:13:54 +02:00
|
|
|
data.Text = Loc.GetString("rotate-counter-verb-get-data-text");
|
2021-03-14 14:40:01 +01:00
|
|
|
data.IconTexture = "/Textures/Interface/VerbIcons/rotate_ccw.svg.192dpi.png";
|
2019-11-06 17:22:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Activate(IEntity user, RotatableComponent component)
|
|
|
|
|
{
|
2020-05-16 22:42:17 +01:00
|
|
|
component.TryRotate(user, Angle.FromDegrees(90));
|
2019-11-06 17:22:26 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|