Skip to content

Commit 9faf37c

Browse files
committed
Add "Repeat Last Connected Tile" keyboard command and menu option
1 parent ac1d402 commit 9faf37c

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

src/TSMapEditor/UI/KeyboardCommand.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ public Action Action
134134
}
135135
}
136136

137+
public void ClearSubscriptions()
138+
{
139+
Triggered = null;
140+
}
141+
137142
public void DoTrigger()
138143
{
139144
Triggered?.Invoke(this, EventArgs.Empty);

src/TSMapEditor/UI/KeyboardCommands.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public KeyboardCommands()
4848
AdjustTileHeightUp,
4949
AdjustTileHeightDown,
5050
PlaceConnectedTile,
51+
RepeatConnectedTile,
5152

5253
AircraftMenu,
5354
BuildingMenu,
@@ -89,6 +90,12 @@ public void WriteToSettings()
8990
}
9091
}
9192

93+
public void ClearCommandSubscriptions()
94+
{
95+
foreach (var command in Commands)
96+
command.ClearSubscriptions();
97+
}
98+
9299

93100
public static KeyboardCommands Instance { get; set; }
94101

@@ -130,7 +137,8 @@ public void WriteToSettings()
130137
public KeyboardCommand ToggleFullscreen { get; } = new KeyboardCommand("ToggleFullscreen", "Toggle Full Screen", new KeyboardCommandInput(Keys.F11, KeyboardModifiers.None));
131138
public KeyboardCommand AdjustTileHeightUp { get; } = new KeyboardCommand("AdjustTileHeightUp", "Adjust Tile Height Up", new KeyboardCommandInput(Keys.PageUp, KeyboardModifiers.None), forActionsOnly:true);
132139
public KeyboardCommand AdjustTileHeightDown { get; } = new KeyboardCommand("AdjustTileHeightDown", "Adjust Tile Height Down", new KeyboardCommandInput(Keys.PageDown, KeyboardModifiers.None), forActionsOnly:true);
133-
public KeyboardCommand PlaceConnectedTile { get; } = new KeyboardCommand("PlaceConnectedTile", "Place Connected Tile", new KeyboardCommandInput(Keys.D, KeyboardModifiers.Ctrl));
140+
public KeyboardCommand PlaceConnectedTile { get; } = new KeyboardCommand("PlaceConnectedTile", "Place Connected Tile", new KeyboardCommandInput(Keys.D, KeyboardModifiers.Alt));
141+
public KeyboardCommand RepeatConnectedTile { get; } = new KeyboardCommand("RepeatConnectedTile", "Repeat Last Connected Tile", new KeyboardCommandInput(Keys.D, KeyboardModifiers.Ctrl));
134142

135143
public KeyboardCommand AircraftMenu { get; } = new KeyboardCommand("AircraftMenu", "Aircraft Menu", new KeyboardCommandInput(Keys.D1, KeyboardModifiers.None));
136144
public KeyboardCommand BuildingMenu { get; } = new KeyboardCommand("BuildingMenu", "Building Menu", new KeyboardCommandInput(Keys.D2, KeyboardModifiers.None));

src/TSMapEditor/UI/TopBar/TopBarMenu.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ public override void Initialize()
142142
}
143143
else
144144
{
145+
editContextMenu.AddItem("Repeat Last Connected Tile", RepeatLastConnectedTile, null, null, null, KeyboardCommands.Instance.RepeatConnectedTile.GetKeyDisplayString());
145146
editContextMenu.AddItem("Draw Connected Tiles...", () => windowController.SelectConnectedTileWindow.Open(), null, null, null, KeyboardCommands.Instance.PlaceConnectedTile.GetKeyDisplayString());
146147
}
147148
}
@@ -258,6 +259,7 @@ public override void Initialize()
258259
KeyboardCommands.Instance.ConfigureTerrainGenerator.Triggered += (s, e) => windowController.TerrainGeneratorConfigWindow.Open();
259260
KeyboardCommands.Instance.PlaceTunnel.Triggered += (s, e) => mapUI.EditorState.CursorAction = placeTubeCursorAction;
260261
KeyboardCommands.Instance.PlaceConnectedTile.Triggered += (s, e) => windowController.SelectConnectedTileWindow.Open();
262+
KeyboardCommands.Instance.RepeatConnectedTile.Triggered += (s, e) => RepeatLastConnectedTile();
261263
KeyboardCommands.Instance.Save.Triggered += (s, e) => SaveMap();
262264

263265
windowController.TerrainGeneratorConfigWindow.ConfigApplied += TerrainGeneratorConfigWindow_ConfigApplied;
@@ -341,6 +343,14 @@ private void WriteMapPreview()
341343
messageBox.YesClickedAction = _ => mapUI.AddPreviewToMap();
342344
}
343345

346+
private void RepeatLastConnectedTile()
347+
{
348+
if (windowController.SelectConnectedTileWindow.SelectedObject == null)
349+
windowController.SelectConnectedTileWindow.Open();
350+
else
351+
SelectConnectedTileWindow_ObjectSelected(this, EventArgs.Empty);
352+
}
353+
344354
private void OpenWithTextEditor()
345355
{
346356
string textEditorPath = UserSettings.Instance.TextEditorPath;

src/TSMapEditor/UI/UIManager.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,7 @@ private void InitKeyboard()
316316
private void ClearKeyboard()
317317
{
318318
Keyboard.OnKeyPressed -= Keyboard_OnKeyPressed;
319-
320-
KeyboardCommands.Instance.Undo.Triggered -= UndoAction;
321-
KeyboardCommands.Instance.Redo.Triggered -= RedoAction;
322-
KeyboardCommands.Instance.Copy.Triggered -= CopyRectanglularAreaAction;
323-
KeyboardCommands.Instance.CopyCustomShape.Triggered -= CopyCustomShapedAreaAction;
324-
KeyboardCommands.Instance.Paste.Triggered -= PasteAction;
319+
KeyboardCommands.Instance.ClearCommandSubscriptions();
325320
}
326321

327322
private void InitMapUI()

0 commit comments

Comments
 (0)