Add editor copy keybinding (#8369)

This commit is contained in:
Leon Friedrich
2022-06-06 10:58:20 +12:00
committed by GitHub
parent 4fbea3cd13
commit ff9d8f96e0
6 changed files with 60 additions and 0 deletions

View File

@@ -178,6 +178,7 @@ namespace Content.Client.EscapeMenu.UI.Tabs
AddButton(EngineKeyFunctions.EditorGridPlace); AddButton(EngineKeyFunctions.EditorGridPlace);
AddButton(EngineKeyFunctions.EditorLinePlace); AddButton(EngineKeyFunctions.EditorLinePlace);
AddButton(EngineKeyFunctions.EditorRotateObject); AddButton(EngineKeyFunctions.EditorRotateObject);
AddButton(ContentKeyFunctions.EditorCopyObject);
AddHeader("ui-options-header-dev"); AddHeader("ui-options-header-dev");
AddButton(EngineKeyFunctions.ShowDebugConsole); AddButton(EngineKeyFunctions.ShowDebugConsole);

View File

@@ -29,6 +29,9 @@ namespace Content.Client.Input
common.AddFunction(ContentKeyFunctions.Point); common.AddFunction(ContentKeyFunctions.Point);
common.AddFunction(ContentKeyFunctions.OpenContextMenu); 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"); var human = contexts.GetContext("human");
human.AddFunction(ContentKeyFunctions.SwapHands); human.AddFunction(ContentKeyFunctions.SwapHands);
human.AddFunction(ContentKeyFunctions.Drop); human.AddFunction(ContentKeyFunctions.Drop);

View File

@@ -12,12 +12,14 @@ using Robust.Client.Debugging;
using Robust.Client.Graphics; using Robust.Client.Graphics;
using Robust.Client.Input; using Robust.Client.Input;
using Robust.Client.Placement; using Robust.Client.Placement;
using Robust.Client.Placement.Modes;
using Robust.Client.ResourceManagement; using Robust.Client.ResourceManagement;
using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls; using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.Input.Binding; using Robust.Shared.Input.Binding;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Network; using Robust.Shared.Network;
using Robust.Shared.Players;
using static Robust.Client.UserInterface.Controls.BoxContainer; using static Robust.Client.UserInterface.Controls.BoxContainer;
namespace Content.Client.Sandbox namespace Content.Client.Sandbox
@@ -117,6 +119,7 @@ namespace Content.Client.Sandbox
{ {
[Dependency] private readonly IClientConsoleHost _consoleHost = default!; [Dependency] private readonly IClientConsoleHost _consoleHost = default!;
[Dependency] private readonly IGameHud _gameHud = default!; [Dependency] private readonly IGameHud _gameHud = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IPlacementManager _placementManager = default!; [Dependency] private readonly IPlacementManager _placementManager = default!;
[Dependency] private readonly IResourceCache _resourceCache = default!; [Dependency] private readonly IResourceCache _resourceCache = default!;
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!; [Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
@@ -148,6 +151,53 @@ namespace Content.Client.Sandbox
InputCmdHandler.FromDelegate(session => ToggleTilesWindow())); InputCmdHandler.FromDelegate(session => ToggleTilesWindow()));
_inputManager.SetInputCommand(ContentKeyFunctions.OpenDecalSpawnWindow, _inputManager.SetInputCommand(ContentKeyFunctions.OpenDecalSpawnWindow,
InputCmdHandler.FromDelegate(session => ToggleDecalsWindow())); 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() private void OnAdminStatus()
@@ -196,6 +246,7 @@ namespace Content.Client.Sandbox
// TODO: Gamehud moment // TODO: Gamehud moment
_gameHud.SandboxButtonToggled -= SandboxButtonPressed; _gameHud.SandboxButtonToggled -= SandboxButtonPressed;
_adminManager.AdminStatusUpdated -= OnAdminStatus; _adminManager.AdminStatusUpdated -= OnAdminStatus;
CommandBinds.Unregister<SandboxSystem>();
} }
private void OnSandboxStatus(MsgSandboxStatus ev) private void OnSandboxStatus(MsgSandboxStatus ev)

View File

@@ -79,5 +79,6 @@ namespace Content.Shared.Input
public static readonly BoundKeyFunction Vote7 = "Vote7"; public static readonly BoundKeyFunction Vote7 = "Vote7";
public static readonly BoundKeyFunction Vote8 = "Vote8"; public static readonly BoundKeyFunction Vote8 = "Vote8";
public static readonly BoundKeyFunction Vote9 = "Vote9"; public static readonly BoundKeyFunction Vote9 = "Vote9";
public static readonly BoundKeyFunction EditorCopyObject = "EditorCopyObject";
} }
} }

View File

@@ -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-grid-place = Place in grid
ui-options-function-editor-line-place = Place line ui-options-function-editor-line-place = Place line
ui-options-function-editor-rotate-object = Rotate 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-open-abilities-menu = Open action menu
ui-options-function-show-debug-console = Open Console ui-options-function-show-debug-console = Open Console

View File

@@ -101,6 +101,9 @@ binds:
- function: EditorRotateObject - function: EditorRotateObject
type: State type: State
key: MouseMiddle key: MouseMiddle
- function: EditorCopyObject
type: State
key: P
- function: SwapHands - function: SwapHands
type: State type: State
key: X key: X