Add keybinds for rotating and flipping objects (#30540)

* add keybinds for rotating and flipping objects

* no popup for verbs
This commit is contained in:
slarticodefast
2024-08-13 15:36:41 +02:00
committed by GitHub
parent 7153e43946
commit 6a462221ff
6 changed files with 115 additions and 15 deletions

View File

@@ -74,6 +74,9 @@ namespace Content.Client.Input
human.AddFunction(ContentKeyFunctions.OpenBackpack); human.AddFunction(ContentKeyFunctions.OpenBackpack);
human.AddFunction(ContentKeyFunctions.OpenBelt); human.AddFunction(ContentKeyFunctions.OpenBelt);
human.AddFunction(ContentKeyFunctions.MouseMiddle); human.AddFunction(ContentKeyFunctions.MouseMiddle);
human.AddFunction(ContentKeyFunctions.RotateObjectClockwise);
human.AddFunction(ContentKeyFunctions.RotateObjectCounterclockwise);
human.AddFunction(ContentKeyFunctions.FlipObject);
human.AddFunction(ContentKeyFunctions.ArcadeUp); human.AddFunction(ContentKeyFunctions.ArcadeUp);
human.AddFunction(ContentKeyFunctions.ArcadeDown); human.AddFunction(ContentKeyFunctions.ArcadeDown);
human.AddFunction(ContentKeyFunctions.ArcadeLeft); human.AddFunction(ContentKeyFunctions.ArcadeLeft);

View File

@@ -195,6 +195,9 @@ namespace Content.Client.Options.UI.Tabs
AddButton(ContentKeyFunctions.MovePulledObject); AddButton(ContentKeyFunctions.MovePulledObject);
AddButton(ContentKeyFunctions.ReleasePulledObject); AddButton(ContentKeyFunctions.ReleasePulledObject);
AddButton(ContentKeyFunctions.Point); AddButton(ContentKeyFunctions.Point);
AddButton(ContentKeyFunctions.RotateObjectClockwise);
AddButton(ContentKeyFunctions.RotateObjectCounterclockwise);
AddButton(ContentKeyFunctions.FlipObject);
AddHeader("ui-options-header-ui"); AddHeader("ui-options-header-ui");
AddButton(ContentKeyFunctions.FocusChat); AddButton(ContentKeyFunctions.FocusChat);

View File

@@ -1,7 +1,12 @@
using Content.Server.Popups; using Content.Server.Popups;
using Content.Shared.Popups; using Content.Shared.ActionBlocker;
using Content.Shared.Input;
using Content.Shared.Interaction;
using Content.Shared.Rotatable; using Content.Shared.Rotatable;
using Content.Shared.Verbs; using Content.Shared.Verbs;
using Robust.Shared.Input.Binding;
using Robust.Shared.Map;
using Robust.Shared.Player;
using Robust.Shared.Physics; using Robust.Shared.Physics;
using Robust.Shared.Physics.Components; using Robust.Shared.Physics.Components;
using Robust.Shared.Utility; using Robust.Shared.Utility;
@@ -14,11 +19,19 @@ namespace Content.Server.Rotatable
public sealed class RotatableSystem : EntitySystem public sealed class RotatableSystem : EntitySystem
{ {
[Dependency] private readonly PopupSystem _popup = default!; [Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly ActionBlockerSystem _actionBlocker = default!;
[Dependency] private readonly SharedInteractionSystem _interaction = default!;
public override void Initialize() public override void Initialize()
{ {
SubscribeLocalEvent<FlippableComponent, GetVerbsEvent<Verb>>(AddFlipVerb); SubscribeLocalEvent<FlippableComponent, GetVerbsEvent<Verb>>(AddFlipVerb);
SubscribeLocalEvent<RotatableComponent, GetVerbsEvent<Verb>>(AddRotateVerbs); SubscribeLocalEvent<RotatableComponent, GetVerbsEvent<Verb>>(AddRotateVerbs);
CommandBinds.Builder
.Bind(ContentKeyFunctions.RotateObjectClockwise, new PointerInputCmdHandler(HandleRotateObjectClockwise))
.Bind(ContentKeyFunctions.RotateObjectCounterclockwise, new PointerInputCmdHandler(HandleRotateObjectCounterclockwise))
.Bind(ContentKeyFunctions.FlipObject, new PointerInputCmdHandler(HandleFlipObject))
.Register<RotatableSystem>();
} }
private void AddFlipVerb(EntityUid uid, FlippableComponent component, GetVerbsEvent<Verb> args) private void AddFlipVerb(EntityUid uid, FlippableComponent component, GetVerbsEvent<Verb> args)
@@ -26,12 +39,16 @@ namespace Content.Server.Rotatable
if (!args.CanAccess || !args.CanInteract) if (!args.CanAccess || !args.CanInteract)
return; return;
// Check if the object is anchored.
if (EntityManager.TryGetComponent(uid, out PhysicsComponent? physics) && physics.BodyType == BodyType.Static)
return;
Verb verb = new() Verb verb = new()
{ {
Act = () => TryFlip(uid, component, args.User), Act = () => Flip(uid, component),
Text = Loc.GetString("flippable-verb-get-data-text"), Text = Loc.GetString("flippable-verb-get-data-text"),
Category = VerbCategory.Rotate, Category = VerbCategory.Rotate,
Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/flip.svg.192dpi.png")), Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/VerbIcons/flip.svg.192dpi.png")),
Priority = -3, // show flip last Priority = -3, // show flip last
DoContactInteraction = true DoContactInteraction = true
}; };
@@ -51,12 +68,12 @@ namespace Content.Server.Rotatable
physics.BodyType == BodyType.Static) physics.BodyType == BodyType.Static)
return; return;
Verb resetRotation = new () Verb resetRotation = new()
{ {
DoContactInteraction = true, DoContactInteraction = true,
Act = () => EntityManager.GetComponent<TransformComponent>(uid).LocalRotation = Angle.Zero, Act = () => EntityManager.GetComponent<TransformComponent>(uid).LocalRotation = Angle.Zero,
Category = VerbCategory.Rotate, Category = VerbCategory.Rotate,
Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/refresh.svg.192dpi.png")), Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/VerbIcons/refresh.svg.192dpi.png")),
Text = "Reset", Text = "Reset",
Priority = -2, // show CCW, then CW, then reset Priority = -2, // show CCW, then CW, then reset
CloseMenu = false, CloseMenu = false,
@@ -68,7 +85,7 @@ namespace Content.Server.Rotatable
{ {
Act = () => EntityManager.GetComponent<TransformComponent>(uid).LocalRotation -= component.Increment, Act = () => EntityManager.GetComponent<TransformComponent>(uid).LocalRotation -= component.Increment,
Category = VerbCategory.Rotate, Category = VerbCategory.Rotate,
Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/rotate_cw.svg.192dpi.png")), Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/VerbIcons/rotate_cw.svg.192dpi.png")),
Priority = -1, Priority = -1,
CloseMenu = false, // allow for easy double rotations. CloseMenu = false, // allow for easy double rotations.
}; };
@@ -79,7 +96,7 @@ namespace Content.Server.Rotatable
{ {
Act = () => EntityManager.GetComponent<TransformComponent>(uid).LocalRotation += component.Increment, Act = () => EntityManager.GetComponent<TransformComponent>(uid).LocalRotation += component.Increment,
Category = VerbCategory.Rotate, Category = VerbCategory.Rotate,
Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/rotate_ccw.svg.192dpi.png")), Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/VerbIcons/rotate_ccw.svg.192dpi.png")),
Priority = 0, Priority = 0,
CloseMenu = false, // allow for easy double rotations. CloseMenu = false, // allow for easy double rotations.
}; };
@@ -89,15 +106,8 @@ namespace Content.Server.Rotatable
/// <summary> /// <summary>
/// Replace a flippable entity with it's flipped / mirror-symmetric entity. /// Replace a flippable entity with it's flipped / mirror-symmetric entity.
/// </summary> /// </summary>
public void TryFlip(EntityUid uid, FlippableComponent component, EntityUid user) public void Flip(EntityUid uid, FlippableComponent component)
{ {
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 oldTransform = EntityManager.GetComponent<TransformComponent>(uid);
var entity = EntityManager.SpawnEntity(component.MirrorEntity, oldTransform.Coordinates); var entity = EntityManager.SpawnEntity(component.MirrorEntity, oldTransform.Coordinates);
var newTransform = EntityManager.GetComponent<TransformComponent>(entity); var newTransform = EntityManager.GetComponent<TransformComponent>(entity);
@@ -105,5 +115,73 @@ namespace Content.Server.Rotatable
newTransform.Anchored = false; newTransform.Anchored = false;
EntityManager.DeleteEntity(uid); EntityManager.DeleteEntity(uid);
} }
public bool HandleRotateObjectClockwise(ICommonSession? playerSession, EntityCoordinates coordinates, EntityUid entity)
{
if (playerSession?.AttachedEntity is not { Valid: true } player || !Exists(player))
return false;
if (!TryComp<RotatableComponent>(entity, out var rotatableComp))
return false;
if (!_actionBlocker.CanInteract(player, entity) || !_interaction.InRangeAndAccessible(player, entity))
return false;
// Check if the object is anchored, and whether we are still allowed to rotate it.
if (!rotatableComp.RotateWhileAnchored && EntityManager.TryGetComponent(entity, out PhysicsComponent? physics) &&
physics.BodyType == BodyType.Static)
{
_popup.PopupEntity(Loc.GetString("rotatable-component-try-rotate-stuck"), entity, player);
return false;
}
Transform(entity).LocalRotation -= rotatableComp.Increment;
return true;
}
public bool HandleRotateObjectCounterclockwise(ICommonSession? playerSession, EntityCoordinates coordinates, EntityUid entity)
{
if (playerSession?.AttachedEntity is not { Valid: true } player || !Exists(player))
return false;
if (!TryComp<RotatableComponent>(entity, out var rotatableComp))
return false;
if (!_actionBlocker.CanInteract(player, entity) || !_interaction.InRangeAndAccessible(player, entity))
return false;
// Check if the object is anchored, and whether we are still allowed to rotate it.
if (!rotatableComp.RotateWhileAnchored && EntityManager.TryGetComponent(entity, out PhysicsComponent? physics) &&
physics.BodyType == BodyType.Static)
{
_popup.PopupEntity(Loc.GetString("rotatable-component-try-rotate-stuck"), entity, player);
return false;
}
Transform(entity).LocalRotation += rotatableComp.Increment;
return true;
}
public bool HandleFlipObject(ICommonSession? playerSession, EntityCoordinates coordinates, EntityUid entity)
{
if (playerSession?.AttachedEntity is not { Valid: true } player || !Exists(player))
return false;
if (!TryComp<FlippableComponent>(entity, out var flippableComp))
return false;
if (!_actionBlocker.CanInteract(player, entity) || !_interaction.InRangeAndAccessible(player, entity))
return false;
// Check if the object is anchored.
if (EntityManager.TryGetComponent(entity, out PhysicsComponent? physics) && physics.BodyType == BodyType.Static)
{
_popup.PopupEntity(Loc.GetString("flippable-component-try-flip-is-stuck"), entity, player);
return false;
}
Flip(entity, flippableComp);
return true;
}
} }
} }

View File

@@ -43,6 +43,9 @@ namespace Content.Shared.Input
public static readonly BoundKeyFunction MovePulledObject = "MovePulledObject"; public static readonly BoundKeyFunction MovePulledObject = "MovePulledObject";
public static readonly BoundKeyFunction ReleasePulledObject = "ReleasePulledObject"; public static readonly BoundKeyFunction ReleasePulledObject = "ReleasePulledObject";
public static readonly BoundKeyFunction MouseMiddle = "MouseMiddle"; public static readonly BoundKeyFunction MouseMiddle = "MouseMiddle";
public static readonly BoundKeyFunction RotateObjectClockwise = "RotateObjectClockwise";
public static readonly BoundKeyFunction RotateObjectCounterclockwise = "RotateObjectCounterclockwise";
public static readonly BoundKeyFunction FlipObject = "FlipObject";
public static readonly BoundKeyFunction ToggleRoundEndSummaryWindow = "ToggleRoundEndSummaryWindow"; public static readonly BoundKeyFunction ToggleRoundEndSummaryWindow = "ToggleRoundEndSummaryWindow";
public static readonly BoundKeyFunction OpenEntitySpawnWindow = "OpenEntitySpawnWindow"; public static readonly BoundKeyFunction OpenEntitySpawnWindow = "OpenEntitySpawnWindow";
public static readonly BoundKeyFunction OpenSandboxWindow = "OpenSandboxWindow"; public static readonly BoundKeyFunction OpenSandboxWindow = "OpenSandboxWindow";

View File

@@ -156,6 +156,9 @@ ui-options-function-try-pull-object = Pull object
ui-options-function-move-pulled-object = Move pulled object ui-options-function-move-pulled-object = Move pulled object
ui-options-function-release-pulled-object = Release pulled object ui-options-function-release-pulled-object = Release pulled object
ui-options-function-point = Point at location ui-options-function-point = Point at location
ui-options-function-rotate-object-clockwise = Rotate clockwise
ui-options-function-rotate-object-counterclockwise = Rotate counterclockwise
ui-options-function-flip-object = Flip
ui-options-function-focus-chat-input-window = Focus chat ui-options-function-focus-chat-input-window = Focus chat
ui-options-function-focus-local-chat-window = Focus chat (IC) ui-options-function-focus-local-chat-window = Focus chat (IC)

View File

@@ -269,6 +269,16 @@ binds:
type: State type: State
key: MouseMiddle key: MouseMiddle
canFocus: true canFocus: true
- function: RotateObjectClockwise
type: State
key: R
- function: RotateObjectCounterclockwise
type: State
key: R
mod1: Shift
- function: FlipObject
type: State
key: F
- function: TextCursorLeft - function: TextCursorLeft
type: State type: State
key: Left key: Left