Skip to content

Commit

Permalink
Add "Repeat Last Connected Tile" keyboard command and menu option
Browse files Browse the repository at this point in the history
  • Loading branch information
Rampastring committed Nov 18, 2024
1 parent ac1d402 commit 9faf37c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/TSMapEditor/UI/KeyboardCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ public Action Action
}
}

public void ClearSubscriptions()
{
Triggered = null;
}

public void DoTrigger()
{
Triggered?.Invoke(this, EventArgs.Empty);
Expand Down
10 changes: 9 additions & 1 deletion src/TSMapEditor/UI/KeyboardCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public KeyboardCommands()
AdjustTileHeightUp,
AdjustTileHeightDown,
PlaceConnectedTile,
RepeatConnectedTile,

AircraftMenu,
BuildingMenu,
Expand Down Expand Up @@ -89,6 +90,12 @@ public void WriteToSettings()
}
}

public void ClearCommandSubscriptions()
{
foreach (var command in Commands)
command.ClearSubscriptions();
}


public static KeyboardCommands Instance { get; set; }

Expand Down Expand Up @@ -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));
Expand Down
10 changes: 10 additions & 0 deletions src/TSMapEditor/UI/TopBar/TopBarMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 1 addition & 6 deletions src/TSMapEditor/UI/UIManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 9faf37c

Please sign in to comment.