Add shortcut to flip for construction menu (#14152)

Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
08A
2023-05-15 06:13:24 +02:00
committed by GitHub
parent 6aeda003a1
commit 3f93b11e4a
11 changed files with 282 additions and 65 deletions

View File

@@ -46,6 +46,8 @@ namespace Content.Client.Construction
new PointerInputCmdHandler(HandleOpenCraftingMenu))
.Bind(EngineKeyFunctions.Use,
new PointerInputCmdHandler(HandleUse, outsidePrediction: true))
.Bind(ContentKeyFunctions.EditorFlipObject,
new PointerInputCmdHandler(HandleFlip))
.Register<ConstructionSystem>();
SubscribeLocalEvent<ConstructionGhostComponent, ExaminedEvent>(HandleConstructionGhostExamined);
@@ -99,6 +101,7 @@ namespace Content.Client.Construction
public event EventHandler<CraftingAvailabilityChangedArgs>? CraftingAvailabilityChanged;
public event EventHandler<string>? ConstructionGuideAvailable;
public event EventHandler? ToggleCraftingWindow;
public event EventHandler? FlipConstructionPrototype;
private void HandleAckStructure(AckStructureConstructionMessage msg)
{
@@ -118,6 +121,13 @@ namespace Content.Client.Construction
return true;
}
private bool HandleFlip(in PointerInputCmdHandler.PointerInputCmdArgs args)
{
if (args.State == BoundKeyState.Down)
FlipConstructionPrototype?.Invoke(this, EventArgs.Empty);
return true;
}
private void UpdateCraftingAvailability(bool available)
{
if (CraftingEnabled == available)

View File

@@ -148,6 +148,9 @@ namespace Content.Client.Construction.UI
foreach (var recipe in _prototypeManager.EnumeratePrototypes<ConstructionPrototype>())
{
if (recipe.Hide)
continue;
if (!string.IsNullOrEmpty(search))
{
if (!recipe.Name.ToLowerInvariant().Contains(search.Trim().ToLowerInvariant()))
@@ -342,6 +345,7 @@ namespace Content.Client.Construction.UI
{
_constructionSystem = system;
system.ToggleCraftingWindow += SystemOnToggleMenu;
system.FlipConstructionPrototype += SystemFlipConstructionPrototype;
system.CraftingAvailabilityChanged += SystemCraftingAvailabilityChanged;
system.ConstructionGuideAvailable += SystemGuideAvailable;
if (_uiManager.GetActiveUIWidgetOrNull<GameTopMenuBar>() != null)
@@ -358,6 +362,7 @@ namespace Content.Client.Construction.UI
throw new InvalidOperationException();
system.ToggleCraftingWindow -= SystemOnToggleMenu;
system.FlipConstructionPrototype -= SystemFlipConstructionPrototype;
system.CraftingAvailabilityChanged -= SystemCraftingAvailabilityChanged;
system.ConstructionGuideAvailable -= SystemGuideAvailable;
_constructionSystem = null;
@@ -392,6 +397,22 @@ namespace Content.Client.Construction.UI
}
}
private void SystemFlipConstructionPrototype(object? sender, EventArgs eventArgs)
{
if (!_placementManager.IsActive || _placementManager.Eraser)
{
return;
}
if (_selected == null || _selected.Mirror == String.Empty)
{
return;
}
_selected = _prototypeManager.Index<ConstructionPrototype>(_selected.Mirror);
UpdateGhostPlacement();
}
private void SystemGuideAvailable(object? sender, string e)
{
if (!CraftingAvailable)

View File

@@ -37,6 +37,9 @@ namespace Content.Client.Input
// Not in engine, because engine cannot check for sanbox/admin status before starting placement.
common.AddFunction(ContentKeyFunctions.EditorCopyObject);
// Not in engine because the engine doesn't understand what a flipped object is
common.AddFunction(ContentKeyFunctions.EditorFlipObject);
var human = contexts.GetContext("human");
human.AddFunction(EngineKeyFunctions.MoveUp);
human.AddFunction(EngineKeyFunctions.MoveDown);

View File

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