Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port das teclas de atalho para rotacionar e flippar objetos #168

Merged
merged 4 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Content.Client/Input/ContentContexts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ public static void SetupContexts(IInputContextContainer contexts)
human.AddFunction(ContentKeyFunctions.OfferItem);
human.AddFunction(ContentKeyFunctions.ToggleStanding);
human.AddFunction(ContentKeyFunctions.MouseMiddle);
human.AddFunction(ContentKeyFunctions.RotateObjectClockwise);
human.AddFunction(ContentKeyFunctions.RotateObjectCounterclockwise);
human.AddFunction(ContentKeyFunctions.FlipObject);
human.AddFunction(ContentKeyFunctions.ArcadeUp);
human.AddFunction(ContentKeyFunctions.ArcadeDown);
human.AddFunction(ContentKeyFunctions.ArcadeLeft);
Expand Down
4 changes: 3 additions & 1 deletion Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tenta arrumar isso pra mim depois, não vou deixar isso segurar tua PR. Faz push e me avisa q eu pego, nem precisa fazer outro PR.

Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ private void HandleHoldLookUp(BaseButton.ButtonToggledEventArgs args)
_cfg.SetCVar(CCVars.HoldLookUp, args.Pressed);
_cfg.SaveToFile();
}

private void HandleDefaultWalk(BaseButton.ButtonToggledEventArgs args)
{
_cfg.SetCVar(CCVars.DefaultWalk, args.Pressed);
Expand Down Expand Up @@ -220,6 +219,9 @@ void AddCheckBox(string checkBoxName, bool currentState, Action<BaseButton.Butto
AddButton(ContentKeyFunctions.MovePulledObject);
AddButton(ContentKeyFunctions.ReleasePulledObject);
AddButton(ContentKeyFunctions.Point);
AddButton(ContentKeyFunctions.RotateObjectClockwise);
AddButton(ContentKeyFunctions.RotateObjectCounterclockwise);
AddButton(ContentKeyFunctions.FlipObject);

AddHeader("ui-options-header-ui");
AddButton(ContentKeyFunctions.FocusChat);
Expand Down
108 changes: 93 additions & 15 deletions Content.Server/Rotatable/RotatableSystem.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
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.Verbs;
using Robust.Shared.Input.Binding;
using Robust.Shared.Map;
using Robust.Shared.Player;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Utility;
Expand All @@ -14,24 +19,36 @@ namespace Content.Server.Rotatable
public sealed class RotatableSystem : EntitySystem
{
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly ActionBlockerSystem _actionBlocker = default!;
[Dependency] private readonly SharedInteractionSystem _interaction = default!;

public override void Initialize()
{
SubscribeLocalEvent<FlippableComponent, GetVerbsEvent<Verb>>(AddFlipVerb);
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)
{
if (!args.CanAccess || !args.CanInteract)
return;

// Check if the object is anchored.
if (EntityManager.TryGetComponent(uid, out PhysicsComponent? physics) && physics.BodyType == BodyType.Static)
return;

Verb verb = new()
{
Act = () => TryFlip(uid, component, args.User),
Act = () => Flip(uid, component),
Text = Loc.GetString("flippable-verb-get-data-text"),
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
DoContactInteraction = true
};
Expand All @@ -51,12 +68,12 @@ private void AddRotateVerbs(EntityUid uid, RotatableComponent component, GetVerb
physics.BodyType == BodyType.Static)
return;

Verb resetRotation = new ()
Verb resetRotation = new()
{
DoContactInteraction = true,
Act = () => EntityManager.GetComponent<TransformComponent>(uid).LocalRotation = Angle.Zero,
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",
Priority = -2, // show CCW, then CW, then reset
CloseMenu = false,
Expand All @@ -68,7 +85,7 @@ private void AddRotateVerbs(EntityUid uid, RotatableComponent component, GetVerb
{
Act = () => EntityManager.GetComponent<TransformComponent>(uid).LocalRotation -= component.Increment,
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,
CloseMenu = false, // allow for easy double rotations.
};
Expand All @@ -79,7 +96,7 @@ private void AddRotateVerbs(EntityUid uid, RotatableComponent component, GetVerb
{
Act = () => EntityManager.GetComponent<TransformComponent>(uid).LocalRotation += component.Increment,
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,
CloseMenu = false, // allow for easy double rotations.
};
Expand All @@ -89,21 +106,82 @@ private void AddRotateVerbs(EntityUid uid, RotatableComponent component, GetVerb
/// <summary>
/// Replace a flippable entity with it's flipped / mirror-symmetric entity.
/// </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 entity = EntityManager.SpawnEntity(component.MirrorEntity, oldTransform.Coordinates);
var newTransform = EntityManager.GetComponent<TransformComponent>(entity);
newTransform.LocalRotation = oldTransform.LocalRotation;
newTransform.Anchored = false;
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;
}
}
}
3 changes: 3 additions & 0 deletions Content.Shared/Input/ContentKeyFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public static class ContentKeyFunctions
public static readonly BoundKeyFunction MovePulledObject = "MovePulledObject";
public static readonly BoundKeyFunction ReleasePulledObject = "ReleasePulledObject";
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 OpenEntitySpawnWindow = "OpenEntitySpawnWindow";
public static readonly BoundKeyFunction OpenSandboxWindow = "OpenSandboxWindow";
Expand Down
3 changes: 3 additions & 0 deletions Resources/Locale/en-US/escape-menu/ui/options-menu.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ ui-options-function-try-pull-object = Pull object
ui-options-function-move-pulled-object = Move pulled object
ui-options-function-release-pulled-object = Release pulled object
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-local-chat-window = Focus chat (IC)
Expand Down
3 changes: 3 additions & 0 deletions Resources/Locale/pt-BR/escape-menu/ui/options-menu.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ ui-options-function-try-pull-object = Puxar objeto
ui-options-function-move-pulled-object = Mover objeto puxado
ui-options-function-release-pulled-object = Soltar objeto puxado
ui-options-function-point = Apontar para local
ui-options-function-rotate-object-clockwise = Rotacionar no sentido horário
ui-options-function-rotate-object-counterclockwise = Rotacionar no sentido anti-horário
ui-options-function-flip-object = Inverter

ui-options-function-focus-chat-input-window = Foco no Chat
ui-options-function-focus-local-chat-window = Foco no Chat (IC)
Expand Down
12 changes: 12 additions & 0 deletions Resources/keybinds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,18 @@ binds:
type: State
key: MouseMiddle
canFocus: true
- function: RotateObjectClockwise
type: State
key: R
mod1: Shift
- function: RotateObjectCounterclockwise
type: State
key: R
mod1: Control
- function: FlipObject
type: State
key: F
mod1: Shift
- function: TextCursorLeft
type: State
key: Left
Expand Down