Skip to content

Commit

Permalink
Add editor copy keybinding (space-wizards#8369)
Browse files Browse the repository at this point in the history
  • Loading branch information
ElectroJr authored Jun 5, 2022
1 parent 4fbea3c commit ff9d8f9
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions Content.Client/EscapeMenu/UI/Tabs/KeyRebindTab.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ void AddCheckBox(string checkBoxName, bool currentState, Action<BaseButton.Butto
AddButton(EngineKeyFunctions.EditorGridPlace);
AddButton(EngineKeyFunctions.EditorLinePlace);
AddButton(EngineKeyFunctions.EditorRotateObject);
AddButton(ContentKeyFunctions.EditorCopyObject);

AddHeader("ui-options-header-dev");
AddButton(EngineKeyFunctions.ShowDebugConsole);
Expand Down
3 changes: 3 additions & 0 deletions Content.Client/Input/ContentContexts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public static void SetupContexts(IInputContextContainer contexts)
common.AddFunction(ContentKeyFunctions.Point);
common.AddFunction(ContentKeyFunctions.OpenContextMenu);

// Not in engine, because engine cannot check for sanbox/admin status before starting placement.
common.AddFunction(ContentKeyFunctions.EditorCopyObject);

var human = contexts.GetContext("human");
human.AddFunction(ContentKeyFunctions.SwapHands);
human.AddFunction(ContentKeyFunctions.Drop);
Expand Down
51 changes: 51 additions & 0 deletions Content.Client/Sandbox/SandboxSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.Placement;
using Robust.Client.Placement.Modes;
using Robust.Client.ResourceManagement;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.Input.Binding;
using Robust.Shared.Map;
using Robust.Shared.Network;
using Robust.Shared.Players;
using static Robust.Client.UserInterface.Controls.BoxContainer;

namespace Content.Client.Sandbox
Expand Down Expand Up @@ -117,6 +119,7 @@ public sealed class SandboxSystem : SharedSandboxSystem
{
[Dependency] private readonly IClientConsoleHost _consoleHost = default!;
[Dependency] private readonly IGameHud _gameHud = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IPlacementManager _placementManager = default!;
[Dependency] private readonly IResourceCache _resourceCache = default!;
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
Expand Down Expand Up @@ -148,6 +151,53 @@ public override void Initialize()
InputCmdHandler.FromDelegate(session => ToggleTilesWindow()));
_inputManager.SetInputCommand(ContentKeyFunctions.OpenDecalSpawnWindow,
InputCmdHandler.FromDelegate(session => ToggleDecalsWindow()));

CommandBinds.Builder
.Bind(ContentKeyFunctions.EditorCopyObject, new PointerInputCmdHandler(OnCopy))
.Register<SandboxSystem>();
}

private bool OnCopy(ICommonSession? session, EntityCoordinates coords, EntityUid uid)
{
if (!CanSandbox())
return false;

// Try copy entity.
if (uid.IsValid()
&& EntityManager.TryGetComponent(uid, out MetaDataComponent? comp)
&& !comp.EntityDeleted)
{
if (comp.EntityPrototype == null || comp.EntityPrototype.NoSpawn || comp.EntityPrototype.Abstract)
return false;

if (_placementManager.Eraser)
_placementManager.ToggleEraser();

_placementManager.BeginPlacing(new()
{
EntityType = comp.EntityPrototype.ID,
IsTile = false,
TileType = 0,
PlacementOption = comp.EntityPrototype.PlacementMode
});
return true;
}

// Try copy tile.
if (!_mapManager.TryFindGridAt(coords.ToMap(EntityManager), out var grid) || !grid.TryGetTileRef(coords, out var tileRef))
return false;

if (_placementManager.Eraser)
_placementManager.ToggleEraser();

_placementManager.BeginPlacing(new()
{
EntityType = null,
IsTile = true,
TileType = tileRef.Tile.TypeId,
PlacementOption = nameof(AlignTileAny)
});
return true;
}

private void OnAdminStatus()
Expand Down Expand Up @@ -196,6 +246,7 @@ public override void Shutdown()
// TODO: Gamehud moment
_gameHud.SandboxButtonToggled -= SandboxButtonPressed;
_adminManager.AdminStatusUpdated -= OnAdminStatus;
CommandBinds.Unregister<SandboxSystem>();
}

private void OnSandboxStatus(MsgSandboxStatus ev)
Expand Down
1 change: 1 addition & 0 deletions Content.Shared/Input/ContentKeyFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,6 @@ public static class ContentKeyFunctions
public static readonly BoundKeyFunction Vote7 = "Vote7";
public static readonly BoundKeyFunction Vote8 = "Vote8";
public static readonly BoundKeyFunction Vote9 = "Vote9";
public static readonly BoundKeyFunction EditorCopyObject = "EditorCopyObject";
}
}
1 change: 1 addition & 0 deletions Resources/Locale/en-US/escape-menu/ui/options-menu.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ ui-options-function-editor-cancel-place = Cancel placement
ui-options-function-editor-grid-place = Place in grid
ui-options-function-editor-line-place = Place line
ui-options-function-editor-rotate-object = Rotate
ui-options-function-editor-copy-object = Copy
ui-options-function-open-abilities-menu = Open action menu
ui-options-function-show-debug-console = Open Console
Expand Down
3 changes: 3 additions & 0 deletions Resources/keybinds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ binds:
- function: EditorRotateObject
type: State
key: MouseMiddle
- function: EditorCopyObject
type: State
key: P
- function: SwapHands
type: State
key: X
Expand Down

0 comments on commit ff9d8f9

Please sign in to comment.