Also put the flip verb in the rotation category. No credit to give here, i've made the icon from scratch. <!-- Please read these guidelines before opening your PR: https://docs.spacestation14.io/en/getting-started/pr-guideline --> <!-- The text between the arrows are comments - they will not be visible on your PR. --> ## About the PR <!-- What does it change? What other things could this impact? --> **Media** <!-- PRs which make ingame changes (adding clothing, items, new features, etc) are required to have media attached that showcase the changes. Small fixes/refactors are exempt. Any media may be used in SS14 progress reports, with clear credit given. If you're unsure whether your PR will require media, ask a maintainer. Check the box below to confirm that you have in fact seen this (put an X in the brackets, like [X]): --> - [x] I have added screenshots/videos to this PR showcasing its changes ingame  **Changelog** <!-- Here you can fill out a changelog that will automatically be added to the game when your PR is merged. Only put changes that are visible and important to the player on the changelog. Don't consider the entry type suffix (e.g. add) to be "part" of the sentence: bad: - add: a new tool for engineers good: - add: added a new tool for engineers Putting a name after the 🆑 symbol will change the name that shows in the changelog (otherwise it takes your GitHub username) Like so: 🆑 PJB --> 🆑 - add: The flip verb now has a icon and can be found under the rotation category.
110 lines
4.6 KiB
C#
110 lines
4.6 KiB
C#
using Content.Server.Popups;
|
|
using Content.Shared.Popups;
|
|
using Content.Shared.Rotatable;
|
|
using Content.Shared.Verbs;
|
|
using Robust.Shared.Physics;
|
|
using Robust.Shared.Physics.Components;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Server.Rotatable
|
|
{
|
|
/// <summary>
|
|
/// Handles verbs for the <see cref="RotatableComponent"/> and <see cref="FlippableComponent"/> components.
|
|
/// </summary>
|
|
public sealed class RotatableSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly PopupSystem _popup = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
SubscribeLocalEvent<FlippableComponent, GetVerbsEvent<Verb>>(AddFlipVerb);
|
|
SubscribeLocalEvent<RotatableComponent, GetVerbsEvent<Verb>>(AddRotateVerbs);
|
|
}
|
|
|
|
private void AddFlipVerb(EntityUid uid, FlippableComponent component, GetVerbsEvent<Verb> args)
|
|
{
|
|
if (!args.CanAccess || !args.CanInteract)
|
|
return;
|
|
|
|
Verb verb = new()
|
|
{
|
|
Act = () => TryFlip(uid, component, args.User),
|
|
Text = Loc.GetString("flippable-verb-get-data-text"),
|
|
Category = VerbCategory.Rotate,
|
|
Icon = new SpriteSpecifier.Texture(new ResourcePath("/Textures/Interface/VerbIcons/flip.svg.192dpi.png")),
|
|
Priority = -3, // show flip last
|
|
DoContactInteraction = true
|
|
};
|
|
args.Verbs.Add(verb);
|
|
}
|
|
|
|
private void AddRotateVerbs(EntityUid uid, RotatableComponent component, GetVerbsEvent<Verb> args)
|
|
{
|
|
if (!args.CanAccess
|
|
|| !args.CanInteract
|
|
|| Transform(uid).NoLocalRotation) // Good ol prototype inheritance, eh?
|
|
return;
|
|
|
|
// Check if the object is anchored, and whether we are still allowed to rotate it.
|
|
if (!component.RotateWhileAnchored &&
|
|
EntityManager.TryGetComponent(uid, out PhysicsComponent? physics) &&
|
|
physics.BodyType == BodyType.Static)
|
|
return;
|
|
|
|
Verb resetRotation = new ()
|
|
{
|
|
DoContactInteraction = true,
|
|
Act = () => EntityManager.GetComponent<TransformComponent>(uid).LocalRotation = Angle.Zero,
|
|
Category = VerbCategory.Rotate,
|
|
Icon = new SpriteSpecifier.Texture(new ResourcePath("/Textures/Interface/VerbIcons/refresh.svg.192dpi.png")),
|
|
Text = "Reset",
|
|
Priority = -2, // show CCW, then CW, then reset
|
|
CloseMenu = false,
|
|
};
|
|
args.Verbs.Add(resetRotation);
|
|
|
|
// rotate clockwise
|
|
Verb rotateCW = new()
|
|
{
|
|
Act = () => EntityManager.GetComponent<TransformComponent>(uid).LocalRotation -= component.Increment,
|
|
Category = VerbCategory.Rotate,
|
|
Icon = new SpriteSpecifier.Texture(new ResourcePath("/Textures/Interface/VerbIcons/rotate_cw.svg.192dpi.png")),
|
|
Priority = -1,
|
|
CloseMenu = false, // allow for easy double rotations.
|
|
};
|
|
args.Verbs.Add(rotateCW);
|
|
|
|
// rotate counter-clockwise
|
|
Verb rotateCCW = new()
|
|
{
|
|
Act = () => EntityManager.GetComponent<TransformComponent>(uid).LocalRotation += component.Increment,
|
|
Category = VerbCategory.Rotate,
|
|
Icon = new SpriteSpecifier.Texture(new ResourcePath("/Textures/Interface/VerbIcons/rotate_ccw.svg.192dpi.png")),
|
|
Priority = 0,
|
|
CloseMenu = false, // allow for easy double rotations.
|
|
};
|
|
args.Verbs.Add(rotateCCW);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Replace a flippable entity with it's flipped / mirror-symmetric entity.
|
|
/// </summary>
|
|
public void TryFlip(EntityUid uid, FlippableComponent component, EntityUid user)
|
|
{
|
|
if (EntityManager.TryGetComponent(uid, out PhysicsComponent? physics) &&
|
|
physics.BodyType == BodyType.Static)
|
|
{
|
|
_popup.PopupEntity(Loc.GetString("flippable-component-try-flip-is-stuck"), uid, user);
|
|
return;
|
|
}
|
|
|
|
var oldTransform = EntityManager.GetComponent<TransformComponent>(uid);
|
|
var entity = EntityManager.SpawnEntity(component.MirrorEntity, oldTransform.Coordinates);
|
|
var newTransform = EntityManager.GetComponent<TransformComponent>(entity);
|
|
newTransform.LocalRotation = oldTransform.LocalRotation;
|
|
newTransform.Anchored = false;
|
|
EntityManager.DeleteEntity(uid);
|
|
}
|
|
}
|
|
}
|