From 9faf37c70496a77a6b701d2e7a7b6be7e928d040 Mon Sep 17 00:00:00 2001 From: Rampastring Date: Mon, 18 Nov 2024 20:03:11 +0200 Subject: [PATCH] Add "Repeat Last Connected Tile" keyboard command and menu option --- src/TSMapEditor/UI/KeyboardCommand.cs | 5 +++++ src/TSMapEditor/UI/KeyboardCommands.cs | 10 +++++++++- src/TSMapEditor/UI/TopBar/TopBarMenu.cs | 10 ++++++++++ src/TSMapEditor/UI/UIManager.cs | 7 +------ 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/TSMapEditor/UI/KeyboardCommand.cs b/src/TSMapEditor/UI/KeyboardCommand.cs index 1bee649bc..1f0050fac 100644 --- a/src/TSMapEditor/UI/KeyboardCommand.cs +++ b/src/TSMapEditor/UI/KeyboardCommand.cs @@ -134,6 +134,11 @@ public Action Action } } + public void ClearSubscriptions() + { + Triggered = null; + } + public void DoTrigger() { Triggered?.Invoke(this, EventArgs.Empty); diff --git a/src/TSMapEditor/UI/KeyboardCommands.cs b/src/TSMapEditor/UI/KeyboardCommands.cs index 4026589ea..3e6b1ae7b 100644 --- a/src/TSMapEditor/UI/KeyboardCommands.cs +++ b/src/TSMapEditor/UI/KeyboardCommands.cs @@ -48,6 +48,7 @@ public KeyboardCommands() AdjustTileHeightUp, AdjustTileHeightDown, PlaceConnectedTile, + RepeatConnectedTile, AircraftMenu, BuildingMenu, @@ -89,6 +90,12 @@ public void WriteToSettings() } } + public void ClearCommandSubscriptions() + { + foreach (var command in Commands) + command.ClearSubscriptions(); + } + public static KeyboardCommands Instance { get; set; } @@ -130,7 +137,8 @@ public void WriteToSettings() public KeyboardCommand ToggleFullscreen { get; } = new KeyboardCommand("ToggleFullscreen", "Toggle Full Screen", new KeyboardCommandInput(Keys.F11, KeyboardModifiers.None)); public KeyboardCommand AdjustTileHeightUp { get; } = new KeyboardCommand("AdjustTileHeightUp", "Adjust Tile Height Up", new KeyboardCommandInput(Keys.PageUp, KeyboardModifiers.None), forActionsOnly:true); public KeyboardCommand AdjustTileHeightDown { get; } = new KeyboardCommand("AdjustTileHeightDown", "Adjust Tile Height Down", new KeyboardCommandInput(Keys.PageDown, KeyboardModifiers.None), forActionsOnly:true); - public KeyboardCommand PlaceConnectedTile { get; } = new KeyboardCommand("PlaceConnectedTile", "Place Connected Tile", new KeyboardCommandInput(Keys.D, KeyboardModifiers.Ctrl)); + public KeyboardCommand PlaceConnectedTile { get; } = new KeyboardCommand("PlaceConnectedTile", "Place Connected Tile", new KeyboardCommandInput(Keys.D, KeyboardModifiers.Alt)); + public KeyboardCommand RepeatConnectedTile { get; } = new KeyboardCommand("RepeatConnectedTile", "Repeat Last Connected Tile", new KeyboardCommandInput(Keys.D, KeyboardModifiers.Ctrl)); public KeyboardCommand AircraftMenu { get; } = new KeyboardCommand("AircraftMenu", "Aircraft Menu", new KeyboardCommandInput(Keys.D1, KeyboardModifiers.None)); public KeyboardCommand BuildingMenu { get; } = new KeyboardCommand("BuildingMenu", "Building Menu", new KeyboardCommandInput(Keys.D2, KeyboardModifiers.None)); diff --git a/src/TSMapEditor/UI/TopBar/TopBarMenu.cs b/src/TSMapEditor/UI/TopBar/TopBarMenu.cs index ceaea5372..92cf2a8fc 100644 --- a/src/TSMapEditor/UI/TopBar/TopBarMenu.cs +++ b/src/TSMapEditor/UI/TopBar/TopBarMenu.cs @@ -142,6 +142,7 @@ public override void Initialize() } else { + editContextMenu.AddItem("Repeat Last Connected Tile", RepeatLastConnectedTile, null, null, null, KeyboardCommands.Instance.RepeatConnectedTile.GetKeyDisplayString()); editContextMenu.AddItem("Draw Connected Tiles...", () => windowController.SelectConnectedTileWindow.Open(), null, null, null, KeyboardCommands.Instance.PlaceConnectedTile.GetKeyDisplayString()); } } @@ -258,6 +259,7 @@ public override void Initialize() KeyboardCommands.Instance.ConfigureTerrainGenerator.Triggered += (s, e) => windowController.TerrainGeneratorConfigWindow.Open(); KeyboardCommands.Instance.PlaceTunnel.Triggered += (s, e) => mapUI.EditorState.CursorAction = placeTubeCursorAction; KeyboardCommands.Instance.PlaceConnectedTile.Triggered += (s, e) => windowController.SelectConnectedTileWindow.Open(); + KeyboardCommands.Instance.RepeatConnectedTile.Triggered += (s, e) => RepeatLastConnectedTile(); KeyboardCommands.Instance.Save.Triggered += (s, e) => SaveMap(); windowController.TerrainGeneratorConfigWindow.ConfigApplied += TerrainGeneratorConfigWindow_ConfigApplied; @@ -341,6 +343,14 @@ private void WriteMapPreview() messageBox.YesClickedAction = _ => mapUI.AddPreviewToMap(); } + private void RepeatLastConnectedTile() + { + if (windowController.SelectConnectedTileWindow.SelectedObject == null) + windowController.SelectConnectedTileWindow.Open(); + else + SelectConnectedTileWindow_ObjectSelected(this, EventArgs.Empty); + } + private void OpenWithTextEditor() { string textEditorPath = UserSettings.Instance.TextEditorPath; diff --git a/src/TSMapEditor/UI/UIManager.cs b/src/TSMapEditor/UI/UIManager.cs index 354ef7eb3..82c0d978a 100644 --- a/src/TSMapEditor/UI/UIManager.cs +++ b/src/TSMapEditor/UI/UIManager.cs @@ -316,12 +316,7 @@ private void InitKeyboard() private void ClearKeyboard() { Keyboard.OnKeyPressed -= Keyboard_OnKeyPressed; - - KeyboardCommands.Instance.Undo.Triggered -= UndoAction; - KeyboardCommands.Instance.Redo.Triggered -= RedoAction; - KeyboardCommands.Instance.Copy.Triggered -= CopyRectanglularAreaAction; - KeyboardCommands.Instance.CopyCustomShape.Triggered -= CopyCustomShapedAreaAction; - KeyboardCommands.Instance.Paste.Triggered -= PasteAction; + KeyboardCommands.Instance.ClearCommandSubscriptions(); } private void InitMapUI()