From 484c6c662cc0e3edb8056a26005d70afa2f11b26 Mon Sep 17 00:00:00 2001 From: Cowan Date: Mon, 11 Nov 2019 13:07:05 -0800 Subject: [PATCH 01/13] Added shifting of selected area in tile palette. --- .../Modules/SourcePaletteTilesetView.cs | 38 ++++++++++++++++--- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs b/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs index ad0fdf58b..e09c05ee3 100644 --- a/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs +++ b/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs @@ -75,7 +75,13 @@ public IReadOnlyGrid SelectedTiles { get { return this.selectedTiles; } } + public void TranslateSelectedArea(int offsetX, int offsetY) + { + int newX = MathF.Clamp(this.selectedArea.X + offsetX, 0, this.DisplayedTileCount.X - this.selectedArea.Width); + int newY = MathF.Clamp(this.selectedArea.Y + offsetY, 0, this.DisplayedTileCount.Y - this.selectedArea.Height); + this.SelectedArea = new Rectangle(newX, newY, this.selectedArea.Width, this.selectedArea.Height); + } protected override void OnTilesetChanged() { @@ -203,7 +209,7 @@ protected override void OnPaintTiles(PaintEventArgs e) protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); - if (e.Button == MouseButtons.Left && Control.ModifierKeys == Keys.Shift && !this.isUserScrolling) + if (e.Button == MouseButtons.Left && ModifierKeys == Keys.Shift && !this.isUserScrolling) { int tileIndex = this.PickTileIndexAt(e.X, e.Y); if (tileIndex != -1) @@ -333,7 +339,29 @@ protected override void OnMouseLeave(EventArgs e) this.InvalidateTile(this.HoveredTileIndex, 5); base.OnMouseLeave(e); } - + protected override void OnKeyDown(KeyEventArgs e) + { + base.OnKeyDown(e); + if (ModifierKeys == Keys.Control) + { + if (e.KeyCode == Keys.Up) + { + this.TranslateSelectedArea(0, -1); + } + if (e.KeyCode == Keys.Down) + { + this.TranslateSelectedArea(0, 1); + } + if (e.KeyCode == Keys.Left) + { + this.TranslateSelectedArea(-1, 0); + } + if (e.KeyCode == Keys.Right) + { + this.TranslateSelectedArea(1, 0); + } + } + } private void UpdateSelectedTiles() { // Allocate and clear a tile rect space of the appropriate size. @@ -370,13 +398,11 @@ private void UpdateSelectedTiles() private void RaiseSelectedAreaEditingFinished() { - if (this.SelectedAreaEditingFinished != null) - this.SelectedAreaEditingFinished(this, EventArgs.Empty); + this.SelectedAreaEditingFinished?.Invoke(this, EventArgs.Empty); } private void RaiseSelectedAreaChanged() { - if (this.SelectedAreaChanged != null) - this.SelectedAreaChanged(this, EventArgs.Empty); + this.SelectedAreaChanged?.Invoke(this, EventArgs.Empty); } } } \ No newline at end of file From 4b6090c43da3af6728f9e15dab7159ca23d327f2 Mon Sep 17 00:00:00 2001 From: Cowan Date: Mon, 11 Nov 2019 14:29:16 -0800 Subject: [PATCH 02/13] Got selected area translation working in tilemap cam view. --- .../TilemapEditorCamViewState.cs | 32 +++++++++++++++++-- .../Plugins/Tilemaps/Editor/EditorPlugin.cs | 9 +++++- .../Modules/SourcePaletteTilesetView.cs | 17 ++++++++-- .../Modules/TilemapToolSourcePalette.cs | 5 +++ 4 files changed, 57 insertions(+), 6 deletions(-) diff --git a/Source/Plugins/Tilemaps/Editor/CamViewStates/TilemapEditorCamViewState.cs b/Source/Plugins/Tilemaps/Editor/CamViewStates/TilemapEditorCamViewState.cs index 8fb005e23..15a7bb419 100644 --- a/Source/Plugins/Tilemaps/Editor/CamViewStates/TilemapEditorCamViewState.cs +++ b/Source/Plugins/Tilemaps/Editor/CamViewStates/TilemapEditorCamViewState.cs @@ -605,7 +605,29 @@ private void DeselectToolInInspector() if (this.selectedTool == null) return; DualityEditorApp.Deselect(this, new ObjectSelection(new object[] { this.selectedTool.Settings })); } - + + private void MoveTilePaletteSelection(Keys keyPressed) + { + TilemapToolSourcePalette sourcePalette = TilemapsEditorPlugin.Instance.PeekTilePalette(); + + if (keyPressed == Keys.Up) + { + sourcePalette.TranslateSelectedArea(0, -1); + } + if (keyPressed == Keys.Down) + { + sourcePalette.TranslateSelectedArea(0, 1); + } + if (keyPressed == Keys.Left) + { + sourcePalette.TranslateSelectedArea(-1, 0); + } + if (keyPressed == Keys.Right) + { + sourcePalette.TranslateSelectedArea(1, 0); + } + } + protected override string UpdateStatusText() { // Display which Tilemap we're currently using @@ -755,9 +777,13 @@ protected override void OnMouseUp(MouseEventArgs e) protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); - + + if (Control.ModifierKeys == Keys.Shift && (e.KeyCode & (Keys.Up | Keys.Down | Keys.Left | Keys.Right)) != Keys.None) + { + this.MoveTilePaletteSelection(e.KeyCode); + } // Hotkeys for switching the currently selected tilemap - if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down) + else if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down) { Tilemap[] visibleTilemaps = this.QueryVisibleTilemapRenderers() diff --git a/Source/Plugins/Tilemaps/Editor/EditorPlugin.cs b/Source/Plugins/Tilemaps/Editor/EditorPlugin.cs index 6c6e4d5ff..60bd2c5bb 100644 --- a/Source/Plugins/Tilemaps/Editor/EditorPlugin.cs +++ b/Source/Plugins/Tilemaps/Editor/EditorPlugin.cs @@ -187,7 +187,14 @@ public void PopTilePalette() else this.pendingLocalTilePalettes--; } - + /// + /// Gets the if there is one, returns null otherwise. + /// + public TilemapToolSourcePalette PeekTilePalette() + { + return this.tilePalette; + } + public TilesetEditor RequestTilesetEditor() { // Create a new tileset editor, if no is available right now diff --git a/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs b/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs index e09c05ee3..8329cce54 100644 --- a/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs +++ b/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs @@ -75,7 +75,7 @@ public IReadOnlyGrid SelectedTiles { get { return this.selectedTiles; } } - public void TranslateSelectedArea(int offsetX, int offsetY) + internal void TranslateSelectedArea(int offsetX, int offsetY) { int newX = MathF.Clamp(this.selectedArea.X + offsetX, 0, this.DisplayedTileCount.X - this.selectedArea.Width); int newY = MathF.Clamp(this.selectedArea.Y + offsetY, 0, this.DisplayedTileCount.Y - this.selectedArea.Height); @@ -342,7 +342,7 @@ protected override void OnMouseLeave(EventArgs e) protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); - if (ModifierKeys == Keys.Control) + if (ModifierKeys == Keys.Shift) { if (e.KeyCode == Keys.Up) { @@ -362,6 +362,19 @@ protected override void OnKeyDown(KeyEventArgs e) } } } + protected override bool IsInputKey(Keys keyData) + { + switch (keyData) + { + case Keys.Shift | Keys.Right: + case Keys.Shift | Keys.Left: + case Keys.Shift | Keys.Up: + case Keys.Shift | Keys.Down: + return true; + } + return base.IsInputKey(keyData); + } + private void UpdateSelectedTiles() { // Allocate and clear a tile rect space of the appropriate size. diff --git a/Source/Plugins/Tilemaps/Editor/Modules/TilemapToolSourcePalette.cs b/Source/Plugins/Tilemaps/Editor/Modules/TilemapToolSourcePalette.cs index b882d7bbd..5f41f9fe0 100644 --- a/Source/Plugins/Tilemaps/Editor/Modules/TilemapToolSourcePalette.cs +++ b/Source/Plugins/Tilemaps/Editor/Modules/TilemapToolSourcePalette.cs @@ -44,6 +44,11 @@ public TilemapToolSourcePalette() this.ApplyTileIndexDrawMode(); } + public void TranslateSelectedArea(int offsetX, int offsetY) + { + this.tilesetView.TranslateSelectedArea(offsetX, offsetY); + } + internal void SaveUserData(XElement node) { node.SetElementValue("DarkBackground", this.buttonBrightness.Checked); From 677570fb273f38a2b7338568f872de252fbea28f Mon Sep 17 00:00:00 2001 From: Cowan Date: Mon, 11 Nov 2019 16:23:49 -0800 Subject: [PATCH 03/13] Added ability to shrink and expand active tiles. --- .../TilemapEditorCamViewState.cs | 52 +++++++++++++ .../Modules/SourcePaletteTilesetView.cs | 74 ++++++++++++++++++- .../Modules/TilemapToolSourcePalette.cs | 8 ++ 3 files changed, 133 insertions(+), 1 deletion(-) diff --git a/Source/Plugins/Tilemaps/Editor/CamViewStates/TilemapEditorCamViewState.cs b/Source/Plugins/Tilemaps/Editor/CamViewStates/TilemapEditorCamViewState.cs index 15a7bb419..d12273268 100644 --- a/Source/Plugins/Tilemaps/Editor/CamViewStates/TilemapEditorCamViewState.cs +++ b/Source/Plugins/Tilemaps/Editor/CamViewStates/TilemapEditorCamViewState.cs @@ -627,6 +627,48 @@ private void MoveTilePaletteSelection(Keys keyPressed) sourcePalette.TranslateSelectedArea(1, 0); } } + private void ExpandTilePaletteSelection(Keys keyPressed) + { + TilemapToolSourcePalette sourcePalette = TilemapsEditorPlugin.Instance.PeekTilePalette(); + + if (keyPressed == Keys.Up) + { + sourcePalette.ExpandSelectedArea(0, -1); + } + if (keyPressed == Keys.Down) + { + sourcePalette.ExpandSelectedArea(0, 1); + } + if (keyPressed == Keys.Left) + { + sourcePalette.ExpandSelectedArea(-1, 0); + } + if (keyPressed == Keys.Right) + { + sourcePalette.ExpandSelectedArea(1, 0); + } + } + private void ShrinkTilePaletteSelection(Keys keyPressed) + { + TilemapToolSourcePalette sourcePalette = TilemapsEditorPlugin.Instance.PeekTilePalette(); + + if (keyPressed == Keys.Up) + { + sourcePalette.ShrinkTilePaletteSelection(0, 1); + } + if (keyPressed == Keys.Down) + { + sourcePalette.ShrinkTilePaletteSelection(0, -1); + } + if (keyPressed == Keys.Left) + { + sourcePalette.ShrinkTilePaletteSelection(1, 0); + } + if (keyPressed == Keys.Right) + { + sourcePalette.ShrinkTilePaletteSelection(-1, 0); + } + } protected override string UpdateStatusText() { @@ -782,6 +824,16 @@ protected override void OnKeyDown(KeyEventArgs e) { this.MoveTilePaletteSelection(e.KeyCode); } + else if (Control.ModifierKeys == Keys.Alt && + (e.KeyCode & (Keys.Up | Keys.Down | Keys.Left | Keys.Right)) != Keys.None) + { + this.ExpandTilePaletteSelection(e.KeyCode); + } + else if (Control.ModifierKeys == (Keys.Alt | Keys.Shift) && + (e.KeyCode & (Keys.Up | Keys.Down | Keys.Left | Keys.Right)) != Keys.None) + { + this.ShrinkTilePaletteSelection(e.KeyCode); + } // Hotkeys for switching the currently selected tilemap else if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down) { diff --git a/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs b/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs index 8329cce54..08e2c5acb 100644 --- a/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs +++ b/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs @@ -4,9 +4,10 @@ using System.Drawing; using System.Linq; using System.Windows.Forms; - +using Duality.Input; using Duality.Resources; using Duality.Plugins.Tilemaps; +using MouseEventArgs = System.Windows.Forms.MouseEventArgs; namespace Duality.Editor.Plugins.Tilemaps @@ -81,6 +82,39 @@ internal void TranslateSelectedArea(int offsetX, int offsetY) int newY = MathF.Clamp(this.selectedArea.Y + offsetY, 0, this.DisplayedTileCount.Y - this.selectedArea.Height); this.SelectedArea = new Rectangle(newX, newY, this.selectedArea.Width, this.selectedArea.Height); + this.RaiseSelectedAreaEditingFinished(); + } + internal void ExpandSelectedArea(int diffX, int diffY) + { + int newX = MathF.Max(this.selectedArea.X + MathF.Min(diffX, 0), 0); + int newY = MathF.Max(this.selectedArea.Y + MathF.Min(diffY, 0), 0); + + int newWidth = this.selectedArea.Width + MathF.Max(diffX, 0); + newWidth = MathF.Min(newWidth, this.DisplayedTileCount.X - this.selectedArea.X); + newWidth += this.selectedArea.X - newX; + + int newHeight = this.selectedArea.Height + MathF.Max(diffY, 0); + newHeight = MathF.Min(newHeight, this.DisplayedTileCount.Y - this.selectedArea.Y); + newHeight += this.selectedArea.Y - newY; + + this.SelectedArea = new Rectangle(newX, newY, newWidth, newHeight); + this.RaiseSelectedAreaEditingFinished(); + } + public void ShrinkSelectedArea(int diffX, int diffY) + { + int newX = MathF.Min(this.selectedArea.X + MathF.Max(diffX, 0), + this.selectedArea.X + this.selectedArea.Width - 1); + int newY = MathF.Min(this.selectedArea.Y + MathF.Max(diffY, 0), + this.selectedArea.Y + this.selectedArea.Height - 1); + + int newWidth = MathF.Max(this.selectedArea.Width + MathF.Min(diffX, 0), 1); + newWidth -= newX - this.selectedArea.X; + + int newHeight = MathF.Max(this.selectedArea.Height + MathF.Min(diffY, 0), 1); + newHeight -= newY - this.selectedArea.Y; + + this.SelectedArea = new Rectangle(newX, newY, newWidth, newHeight); + this.RaiseSelectedAreaEditingFinished(); } protected override void OnTilesetChanged() @@ -361,6 +395,44 @@ protected override void OnKeyDown(KeyEventArgs e) this.TranslateSelectedArea(1, 0); } } + if (ModifierKeys == Keys.Alt) + { + if (e.KeyCode == Keys.Up) + { + this.ExpandSelectedArea(0, -1); + } + if (e.KeyCode == Keys.Down) + { + this.ExpandSelectedArea(0, 1); + } + if (e.KeyCode == Keys.Left) + { + this.ExpandSelectedArea(-1, 0); + } + if (e.KeyCode == Keys.Right) + { + this.ExpandSelectedArea(1, 0); + } + } + if (ModifierKeys == (Keys.Alt | Keys.Shift)) + { + if (e.KeyCode == Keys.Up) + { + this.ShrinkSelectedArea(0, 1); + } + if (e.KeyCode == Keys.Down) + { + this.ShrinkSelectedArea(0, -1); + } + if (e.KeyCode == Keys.Left) + { + this.ShrinkSelectedArea(1, 0); + } + if (e.KeyCode == Keys.Right) + { + this.ShrinkSelectedArea(-1, 0); + } + } } protected override bool IsInputKey(Keys keyData) { diff --git a/Source/Plugins/Tilemaps/Editor/Modules/TilemapToolSourcePalette.cs b/Source/Plugins/Tilemaps/Editor/Modules/TilemapToolSourcePalette.cs index 5f41f9fe0..8db857f68 100644 --- a/Source/Plugins/Tilemaps/Editor/Modules/TilemapToolSourcePalette.cs +++ b/Source/Plugins/Tilemaps/Editor/Modules/TilemapToolSourcePalette.cs @@ -48,6 +48,14 @@ public void TranslateSelectedArea(int offsetX, int offsetY) { this.tilesetView.TranslateSelectedArea(offsetX, offsetY); } + public void ExpandSelectedArea(int diffX, int diffY) + { + this.tilesetView.ExpandSelectedArea(diffX, diffY); + } + public void ShrinkTilePaletteSelection(int diffX, int diffY) + { + this.tilesetView.ShrinkSelectedArea(diffX, diffY); + } internal void SaveUserData(XElement node) { From a0b43ed9c209ef2c8e54ad95f3ee6a0d11338811 Mon Sep 17 00:00:00 2001 From: Cowan Date: Mon, 11 Nov 2019 17:32:25 -0800 Subject: [PATCH 04/13] Fixed graphics bug. --- .../Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs b/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs index 08e2c5acb..6e420dbb9 100644 --- a/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs +++ b/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs @@ -83,6 +83,7 @@ internal void TranslateSelectedArea(int offsetX, int offsetY) this.SelectedArea = new Rectangle(newX, newY, this.selectedArea.Width, this.selectedArea.Height); this.RaiseSelectedAreaEditingFinished(); + this.Invalidate(); } internal void ExpandSelectedArea(int diffX, int diffY) { @@ -99,6 +100,7 @@ internal void ExpandSelectedArea(int diffX, int diffY) this.SelectedArea = new Rectangle(newX, newY, newWidth, newHeight); this.RaiseSelectedAreaEditingFinished(); + this.Invalidate(); } public void ShrinkSelectedArea(int diffX, int diffY) { @@ -115,6 +117,7 @@ public void ShrinkSelectedArea(int diffX, int diffY) this.SelectedArea = new Rectangle(newX, newY, newWidth, newHeight); this.RaiseSelectedAreaEditingFinished(); + this.Invalidate(); } protected override void OnTilesetChanged() From 31c4e069eafbf2b0ce081a973904cb35012bb3fa Mon Sep 17 00:00:00 2001 From: Cowan Date: Mon, 11 Nov 2019 17:44:15 -0800 Subject: [PATCH 05/13] Added documentation for public API changes. --- .../Tilemaps/Editor/Modules/TilemapToolSourcePalette.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Source/Plugins/Tilemaps/Editor/Modules/TilemapToolSourcePalette.cs b/Source/Plugins/Tilemaps/Editor/Modules/TilemapToolSourcePalette.cs index 8db857f68..7e446f450 100644 --- a/Source/Plugins/Tilemaps/Editor/Modules/TilemapToolSourcePalette.cs +++ b/Source/Plugins/Tilemaps/Editor/Modules/TilemapToolSourcePalette.cs @@ -44,14 +44,23 @@ public TilemapToolSourcePalette() this.ApplyTileIndexDrawMode(); } + /// + /// Translates the selected area in the source palette by a number of tiles in the X and Y axes. + /// public void TranslateSelectedArea(int offsetX, int offsetY) { this.tilesetView.TranslateSelectedArea(offsetX, offsetY); } + /// + /// Expands the selected area in the positive or negative direction along the X and Y axes. + /// public void ExpandSelectedArea(int diffX, int diffY) { this.tilesetView.ExpandSelectedArea(diffX, diffY); } + /// + /// Shrinks the selected area in the positive or negative direction along the X and Y axes. + /// public void ShrinkTilePaletteSelection(int diffX, int diffY) { this.tilesetView.ShrinkSelectedArea(diffX, diffY); From 65fcc5bae43395f7a5bf39f1ba9ab2be7ab6641f Mon Sep 17 00:00:00 2001 From: Cowan Date: Tue, 12 Nov 2019 08:46:39 -0800 Subject: [PATCH 06/13] Fix possible null reference and initialize selected area if empty. --- .../TilemapEditorCamViewState.cs | 3 +++ .../Modules/SourcePaletteTilesetView.cs | 24 +++++++++++++++++++ .../Modules/TilemapToolSourcePalette.cs | 2 +- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/Source/Plugins/Tilemaps/Editor/CamViewStates/TilemapEditorCamViewState.cs b/Source/Plugins/Tilemaps/Editor/CamViewStates/TilemapEditorCamViewState.cs index d12273268..d3594a425 100644 --- a/Source/Plugins/Tilemaps/Editor/CamViewStates/TilemapEditorCamViewState.cs +++ b/Source/Plugins/Tilemaps/Editor/CamViewStates/TilemapEditorCamViewState.cs @@ -609,6 +609,7 @@ private void DeselectToolInInspector() private void MoveTilePaletteSelection(Keys keyPressed) { TilemapToolSourcePalette sourcePalette = TilemapsEditorPlugin.Instance.PeekTilePalette(); + if (sourcePalette == null) return; if (keyPressed == Keys.Up) { @@ -630,6 +631,7 @@ private void MoveTilePaletteSelection(Keys keyPressed) private void ExpandTilePaletteSelection(Keys keyPressed) { TilemapToolSourcePalette sourcePalette = TilemapsEditorPlugin.Instance.PeekTilePalette(); + if (sourcePalette == null) return; if (keyPressed == Keys.Up) { @@ -651,6 +653,7 @@ private void ExpandTilePaletteSelection(Keys keyPressed) private void ShrinkTilePaletteSelection(Keys keyPressed) { TilemapToolSourcePalette sourcePalette = TilemapsEditorPlugin.Instance.PeekTilePalette(); + if (sourcePalette == null) return; if (keyPressed == Keys.Up) { diff --git a/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs b/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs index 6e420dbb9..35cd8f18e 100644 --- a/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs +++ b/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs @@ -78,6 +78,12 @@ public IReadOnlyGrid SelectedTiles } internal void TranslateSelectedArea(int offsetX, int offsetY) { + if (this.selectedArea.IsEmpty) + { + this.InitializeSelectedArea(); + return; + } + int newX = MathF.Clamp(this.selectedArea.X + offsetX, 0, this.DisplayedTileCount.X - this.selectedArea.Width); int newY = MathF.Clamp(this.selectedArea.Y + offsetY, 0, this.DisplayedTileCount.Y - this.selectedArea.Height); @@ -87,6 +93,12 @@ internal void TranslateSelectedArea(int offsetX, int offsetY) } internal void ExpandSelectedArea(int diffX, int diffY) { + if (this.selectedArea.IsEmpty) + { + this.InitializeSelectedArea(); + return; + } + int newX = MathF.Max(this.selectedArea.X + MathF.Min(diffX, 0), 0); int newY = MathF.Max(this.selectedArea.Y + MathF.Min(diffY, 0), 0); @@ -104,6 +116,12 @@ internal void ExpandSelectedArea(int diffX, int diffY) } public void ShrinkSelectedArea(int diffX, int diffY) { + if (this.selectedArea.IsEmpty) + { + this.InitializeSelectedArea(); + return; + } + int newX = MathF.Min(this.selectedArea.X + MathF.Max(diffX, 0), this.selectedArea.X + this.selectedArea.Width - 1); int newY = MathF.Min(this.selectedArea.Y + MathF.Max(diffY, 0), @@ -483,6 +501,12 @@ private void UpdateSelectedTiles() } } } + private void InitializeSelectedArea() + { + Rectangle rect = new Rectangle(0, 0, 1, 1); + this.SelectedArea = rect; + this.RaiseSelectedAreaEditingFinished(); + } private void RaiseSelectedAreaEditingFinished() { diff --git a/Source/Plugins/Tilemaps/Editor/Modules/TilemapToolSourcePalette.cs b/Source/Plugins/Tilemaps/Editor/Modules/TilemapToolSourcePalette.cs index 7e446f450..664b3fd1f 100644 --- a/Source/Plugins/Tilemaps/Editor/Modules/TilemapToolSourcePalette.cs +++ b/Source/Plugins/Tilemaps/Editor/Modules/TilemapToolSourcePalette.cs @@ -45,7 +45,7 @@ public TilemapToolSourcePalette() } /// - /// Translates the selected area in the source palette by a number of tiles in the X and Y axes. + /// Translates the selected area in the source palette by a number of tiles along the X and Y axes. /// public void TranslateSelectedArea(int offsetX, int offsetY) { From 897eaa882e4e25c8118b19d9d9e7859305c1167e Mon Sep 17 00:00:00 2001 From: Cowan Date: Mon, 18 Nov 2019 22:53:11 -0800 Subject: [PATCH 07/13] Changed controls to requested for tile palette only. --- .../Modules/SourcePaletteTilesetView.cs | 96 ++++++++++++------- 1 file changed, 59 insertions(+), 37 deletions(-) diff --git a/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs b/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs index 35cd8f18e..f64535754 100644 --- a/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs +++ b/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs @@ -22,6 +22,17 @@ public class SourcePaletteTilesetView : TilesetView private bool isUserScrolling = false; private int lastMouseX = -1; private int lastMouseY = -1; + private SelectionSide activeSelectionSide = SelectionSide.None; + + private enum SelectionSide + { + None, + Right, + Left, + Up, + Down + } + public event EventHandler SelectedAreaChanged = null; public event EventHandler SelectedAreaEditingFinished = null; @@ -397,68 +408,79 @@ protected override void OnMouseLeave(EventArgs e) protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); - if (ModifierKeys == Keys.Shift) + + if (Control.ModifierKeys == Keys.Shift) { - if (e.KeyCode == Keys.Up) + switch (e.KeyCode) { - this.TranslateSelectedArea(0, -1); - } - if (e.KeyCode == Keys.Down) - { - this.TranslateSelectedArea(0, 1); - } - if (e.KeyCode == Keys.Left) - { - this.TranslateSelectedArea(-1, 0); - } - if (e.KeyCode == Keys.Right) - { - this.TranslateSelectedArea(1, 0); + case Keys.Up when this.activeSelectionSide == SelectionSide.Down: + this.ShrinkSelectedArea(0, -1); + break; + case Keys.Up: + this.ExpandSelectedArea(0, -1); + this.activeSelectionSide = SelectionSide.Up; + break; + case Keys.Down when this.activeSelectionSide == SelectionSide.Up: + this.ShrinkSelectedArea(0, 1); + break; + case Keys.Down: + this.ExpandSelectedArea(0, 1); + this.activeSelectionSide = SelectionSide.Down; + break; + case Keys.Left when this.activeSelectionSide == SelectionSide.Right: + this.ShrinkSelectedArea(-1, 0); + break; + case Keys.Left: + this.ExpandSelectedArea(-1, 0); + this.activeSelectionSide = SelectionSide.Left; + break; + case Keys.Right when this.activeSelectionSide == SelectionSide.Left: + this.ShrinkSelectedArea(1, 0); + break; + case Keys.Right: + this.ExpandSelectedArea(1, 0); + this.activeSelectionSide = SelectionSide.Right; + break; } } - if (ModifierKeys == Keys.Alt) + else { if (e.KeyCode == Keys.Up) { - this.ExpandSelectedArea(0, -1); + this.TranslateSelectedArea(0, -1); } if (e.KeyCode == Keys.Down) { - this.ExpandSelectedArea(0, 1); + this.TranslateSelectedArea(0, 1); } if (e.KeyCode == Keys.Left) { - this.ExpandSelectedArea(-1, 0); + this.TranslateSelectedArea(-1, 0); } if (e.KeyCode == Keys.Right) { - this.ExpandSelectedArea(1, 0); + this.TranslateSelectedArea(1, 0); } + this.activeSelectionSide = SelectionSide.None; } - if (ModifierKeys == (Keys.Alt | Keys.Shift)) + } + + protected override void OnKeyUp(KeyEventArgs e) + { + if (e.KeyCode == Keys.ShiftKey) { - if (e.KeyCode == Keys.Up) - { - this.ShrinkSelectedArea(0, 1); - } - if (e.KeyCode == Keys.Down) - { - this.ShrinkSelectedArea(0, -1); - } - if (e.KeyCode == Keys.Left) - { - this.ShrinkSelectedArea(1, 0); - } - if (e.KeyCode == Keys.Right) - { - this.ShrinkSelectedArea(-1, 0); - } + this.activeSelectionSide = SelectionSide.None; } } protected override bool IsInputKey(Keys keyData) { switch (keyData) { + case Keys.Right: + case Keys.Left: + case Keys.Up: + case Keys.Down: + case Keys.Shift: case Keys.Shift | Keys.Right: case Keys.Shift | Keys.Left: case Keys.Shift | Keys.Up: From fea4665ba57a4f58d68fc22303c22af70572aafc Mon Sep 17 00:00:00 2001 From: Cowan Date: Mon, 25 Nov 2019 00:33:01 -0800 Subject: [PATCH 08/13] Gave tileset editor access to the tile palette controls. There's overlapping controls between the tile palette and the tileset editor. --- .../TilemapEditorCamViewState.cs | 87 +------------ .../Modules/SourcePaletteTilesetView.cs | 121 ++++++++++-------- .../Modules/TilemapToolSourcePalette.cs | 22 +--- 3 files changed, 74 insertions(+), 156 deletions(-) diff --git a/Source/Plugins/Tilemaps/Editor/CamViewStates/TilemapEditorCamViewState.cs b/Source/Plugins/Tilemaps/Editor/CamViewStates/TilemapEditorCamViewState.cs index d3594a425..9ed6e8030 100644 --- a/Source/Plugins/Tilemaps/Editor/CamViewStates/TilemapEditorCamViewState.cs +++ b/Source/Plugins/Tilemaps/Editor/CamViewStates/TilemapEditorCamViewState.cs @@ -606,73 +606,6 @@ private void DeselectToolInInspector() DualityEditorApp.Deselect(this, new ObjectSelection(new object[] { this.selectedTool.Settings })); } - private void MoveTilePaletteSelection(Keys keyPressed) - { - TilemapToolSourcePalette sourcePalette = TilemapsEditorPlugin.Instance.PeekTilePalette(); - if (sourcePalette == null) return; - - if (keyPressed == Keys.Up) - { - sourcePalette.TranslateSelectedArea(0, -1); - } - if (keyPressed == Keys.Down) - { - sourcePalette.TranslateSelectedArea(0, 1); - } - if (keyPressed == Keys.Left) - { - sourcePalette.TranslateSelectedArea(-1, 0); - } - if (keyPressed == Keys.Right) - { - sourcePalette.TranslateSelectedArea(1, 0); - } - } - private void ExpandTilePaletteSelection(Keys keyPressed) - { - TilemapToolSourcePalette sourcePalette = TilemapsEditorPlugin.Instance.PeekTilePalette(); - if (sourcePalette == null) return; - - if (keyPressed == Keys.Up) - { - sourcePalette.ExpandSelectedArea(0, -1); - } - if (keyPressed == Keys.Down) - { - sourcePalette.ExpandSelectedArea(0, 1); - } - if (keyPressed == Keys.Left) - { - sourcePalette.ExpandSelectedArea(-1, 0); - } - if (keyPressed == Keys.Right) - { - sourcePalette.ExpandSelectedArea(1, 0); - } - } - private void ShrinkTilePaletteSelection(Keys keyPressed) - { - TilemapToolSourcePalette sourcePalette = TilemapsEditorPlugin.Instance.PeekTilePalette(); - if (sourcePalette == null) return; - - if (keyPressed == Keys.Up) - { - sourcePalette.ShrinkTilePaletteSelection(0, 1); - } - if (keyPressed == Keys.Down) - { - sourcePalette.ShrinkTilePaletteSelection(0, -1); - } - if (keyPressed == Keys.Left) - { - sourcePalette.ShrinkTilePaletteSelection(1, 0); - } - if (keyPressed == Keys.Right) - { - sourcePalette.ShrinkTilePaletteSelection(-1, 0); - } - } - protected override string UpdateStatusText() { // Display which Tilemap we're currently using @@ -822,23 +755,10 @@ protected override void OnMouseUp(MouseEventArgs e) protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); + TilemapsEditorPlugin.Instance.PeekTilePalette().RaiseKeyDownEvent(e); - if (Control.ModifierKeys == Keys.Shift && (e.KeyCode & (Keys.Up | Keys.Down | Keys.Left | Keys.Right)) != Keys.None) - { - this.MoveTilePaletteSelection(e.KeyCode); - } - else if (Control.ModifierKeys == Keys.Alt && - (e.KeyCode & (Keys.Up | Keys.Down | Keys.Left | Keys.Right)) != Keys.None) - { - this.ExpandTilePaletteSelection(e.KeyCode); - } - else if (Control.ModifierKeys == (Keys.Alt | Keys.Shift) && - (e.KeyCode & (Keys.Up | Keys.Down | Keys.Left | Keys.Right)) != Keys.None) - { - this.ShrinkTilePaletteSelection(e.KeyCode); - } // Hotkeys for switching the currently selected tilemap - else if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down) + if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down) { Tilemap[] visibleTilemaps = this.QueryVisibleTilemapRenderers() @@ -890,7 +810,8 @@ protected override void OnKeyDown(KeyEventArgs e) protected override void OnKeyUp(KeyEventArgs e) { base.OnKeyUp(e); - + TilemapsEditorPlugin.Instance.PeekTilePalette().RaiseKeyUpEvent(e); + if (this.overrideTool != null && this.overrideTool.OverrideKey == e.KeyCode) { this.OverrideTool = null; diff --git a/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs b/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs index f64535754..2733f4508 100644 --- a/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs +++ b/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs @@ -87,66 +87,14 @@ public IReadOnlyGrid SelectedTiles { get { return this.selectedTiles; } } - internal void TranslateSelectedArea(int offsetX, int offsetY) - { - if (this.selectedArea.IsEmpty) - { - this.InitializeSelectedArea(); - return; - } - - int newX = MathF.Clamp(this.selectedArea.X + offsetX, 0, this.DisplayedTileCount.X - this.selectedArea.Width); - int newY = MathF.Clamp(this.selectedArea.Y + offsetY, 0, this.DisplayedTileCount.Y - this.selectedArea.Height); - this.SelectedArea = new Rectangle(newX, newY, this.selectedArea.Width, this.selectedArea.Height); - this.RaiseSelectedAreaEditingFinished(); - this.Invalidate(); - } - internal void ExpandSelectedArea(int diffX, int diffY) + internal void RaiseKeyDownEvent(KeyEventArgs e) { - if (this.selectedArea.IsEmpty) - { - this.InitializeSelectedArea(); - return; - } - - int newX = MathF.Max(this.selectedArea.X + MathF.Min(diffX, 0), 0); - int newY = MathF.Max(this.selectedArea.Y + MathF.Min(diffY, 0), 0); - - int newWidth = this.selectedArea.Width + MathF.Max(diffX, 0); - newWidth = MathF.Min(newWidth, this.DisplayedTileCount.X - this.selectedArea.X); - newWidth += this.selectedArea.X - newX; - - int newHeight = this.selectedArea.Height + MathF.Max(diffY, 0); - newHeight = MathF.Min(newHeight, this.DisplayedTileCount.Y - this.selectedArea.Y); - newHeight += this.selectedArea.Y - newY; - - this.SelectedArea = new Rectangle(newX, newY, newWidth, newHeight); - this.RaiseSelectedAreaEditingFinished(); - this.Invalidate(); + this.OnKeyDown(e); } - public void ShrinkSelectedArea(int diffX, int diffY) + internal void RaiseKeyUpEvent(KeyEventArgs e) { - if (this.selectedArea.IsEmpty) - { - this.InitializeSelectedArea(); - return; - } - - int newX = MathF.Min(this.selectedArea.X + MathF.Max(diffX, 0), - this.selectedArea.X + this.selectedArea.Width - 1); - int newY = MathF.Min(this.selectedArea.Y + MathF.Max(diffY, 0), - this.selectedArea.Y + this.selectedArea.Height - 1); - - int newWidth = MathF.Max(this.selectedArea.Width + MathF.Min(diffX, 0), 1); - newWidth -= newX - this.selectedArea.X; - - int newHeight = MathF.Max(this.selectedArea.Height + MathF.Min(diffY, 0), 1); - newHeight -= newY - this.selectedArea.Y; - - this.SelectedArea = new Rectangle(newX, newY, newWidth, newHeight); - this.RaiseSelectedAreaEditingFinished(); - this.Invalidate(); + this.OnKeyUp(e); } protected override void OnTilesetChanged() @@ -538,5 +486,66 @@ private void RaiseSelectedAreaChanged() { this.SelectedAreaChanged?.Invoke(this, EventArgs.Empty); } + private void TranslateSelectedArea(int offsetX, int offsetY) + { + if (this.selectedArea.IsEmpty) + { + this.InitializeSelectedArea(); + return; + } + + int newX = MathF.Clamp(this.selectedArea.X + offsetX, 0, this.DisplayedTileCount.X - this.selectedArea.Width); + int newY = MathF.Clamp(this.selectedArea.Y + offsetY, 0, this.DisplayedTileCount.Y - this.selectedArea.Height); + + this.SelectedArea = new Rectangle(newX, newY, this.selectedArea.Width, this.selectedArea.Height); + this.RaiseSelectedAreaEditingFinished(); + this.Invalidate(); + } + private void ExpandSelectedArea(int diffX, int diffY) + { + if (this.selectedArea.IsEmpty) + { + this.InitializeSelectedArea(); + return; + } + + int newX = MathF.Max(this.selectedArea.X + MathF.Min(diffX, 0), 0); + int newY = MathF.Max(this.selectedArea.Y + MathF.Min(diffY, 0), 0); + + int newWidth = this.selectedArea.Width + MathF.Max(diffX, 0); + newWidth = MathF.Min(newWidth, this.DisplayedTileCount.X - this.selectedArea.X); + newWidth += this.selectedArea.X - newX; + + int newHeight = this.selectedArea.Height + MathF.Max(diffY, 0); + newHeight = MathF.Min(newHeight, this.DisplayedTileCount.Y - this.selectedArea.Y); + newHeight += this.selectedArea.Y - newY; + + this.SelectedArea = new Rectangle(newX, newY, newWidth, newHeight); + this.RaiseSelectedAreaEditingFinished(); + this.Invalidate(); + } + private void ShrinkSelectedArea(int diffX, int diffY) + { + if (this.selectedArea.IsEmpty) + { + this.InitializeSelectedArea(); + return; + } + + int newX = MathF.Min(this.selectedArea.X + MathF.Max(diffX, 0), + this.selectedArea.X + this.selectedArea.Width - 1); + int newY = MathF.Min(this.selectedArea.Y + MathF.Max(diffY, 0), + this.selectedArea.Y + this.selectedArea.Height - 1); + + int newWidth = MathF.Max(this.selectedArea.Width + MathF.Min(diffX, 0), 1); + newWidth -= newX - this.selectedArea.X; + + int newHeight = MathF.Max(this.selectedArea.Height + MathF.Min(diffY, 0), 1); + newHeight -= newY - this.selectedArea.Y; + + this.SelectedArea = new Rectangle(newX, newY, newWidth, newHeight); + this.RaiseSelectedAreaEditingFinished(); + this.Invalidate(); + } } } \ No newline at end of file diff --git a/Source/Plugins/Tilemaps/Editor/Modules/TilemapToolSourcePalette.cs b/Source/Plugins/Tilemaps/Editor/Modules/TilemapToolSourcePalette.cs index 664b3fd1f..0c0457b33 100644 --- a/Source/Plugins/Tilemaps/Editor/Modules/TilemapToolSourcePalette.cs +++ b/Source/Plugins/Tilemaps/Editor/Modules/TilemapToolSourcePalette.cs @@ -44,26 +44,14 @@ public TilemapToolSourcePalette() this.ApplyTileIndexDrawMode(); } - /// - /// Translates the selected area in the source palette by a number of tiles along the X and Y axes. - /// - public void TranslateSelectedArea(int offsetX, int offsetY) + public void RaiseKeyDownEvent(KeyEventArgs e) { - this.tilesetView.TranslateSelectedArea(offsetX, offsetY); + this.tilesetView.RaiseKeyDownEvent(e); } - /// - /// Expands the selected area in the positive or negative direction along the X and Y axes. - /// - public void ExpandSelectedArea(int diffX, int diffY) - { - this.tilesetView.ExpandSelectedArea(diffX, diffY); - } - /// - /// Shrinks the selected area in the positive or negative direction along the X and Y axes. - /// - public void ShrinkTilePaletteSelection(int diffX, int diffY) + + public void RaiseKeyUpEvent(KeyEventArgs e) { - this.tilesetView.ShrinkSelectedArea(diffX, diffY); + this.tilesetView.RaiseKeyUpEvent(e); } internal void SaveUserData(XElement node) From 650e15f3e5669f9743255783a1b02caa9a4d057d Mon Sep 17 00:00:00 2001 From: Cowan Cumming Date: Sun, 15 Dec 2019 23:23:57 -0800 Subject: [PATCH 09/13] Get rid of conflicting key bindings. --- .../Editor/CamViewStates/TilemapEditorCamViewState.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Plugins/Tilemaps/Editor/CamViewStates/TilemapEditorCamViewState.cs b/Source/Plugins/Tilemaps/Editor/CamViewStates/TilemapEditorCamViewState.cs index 9ed6e8030..8e57bcf2f 100644 --- a/Source/Plugins/Tilemaps/Editor/CamViewStates/TilemapEditorCamViewState.cs +++ b/Source/Plugins/Tilemaps/Editor/CamViewStates/TilemapEditorCamViewState.cs @@ -758,7 +758,7 @@ protected override void OnKeyDown(KeyEventArgs e) TilemapsEditorPlugin.Instance.PeekTilePalette().RaiseKeyDownEvent(e); // Hotkeys for switching the currently selected tilemap - if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down) + if (e.KeyCode == Keys.PageUp || e.KeyCode == Keys.PageDown) { Tilemap[] visibleTilemaps = this.QueryVisibleTilemapRenderers() @@ -771,9 +771,9 @@ protected override void OnKeyDown(KeyEventArgs e) if (visibleTilemaps.Length > 0) { - if (e.KeyCode == Keys.Down) + if (e.KeyCode == Keys.PageDown) selectedIndex = (selectedIndex == -1) ? (visibleTilemaps.Length - 1) : Math.Min(selectedIndex + 1, visibleTilemaps.Length - 1); - else if (e.KeyCode == Keys.Up) + else if (e.KeyCode == Keys.PageUp) selectedIndex = (selectedIndex == -1) ? 0 : Math.Max(selectedIndex - 1, 0); Tilemap newSelection = visibleTilemaps[selectedIndex]; @@ -783,7 +783,7 @@ protected override void OnKeyDown(KeyEventArgs e) e.Handled = true; return; } - else if (e.KeyCode == Keys.Left || e.KeyCode == Keys.Right) + else if (e.KeyCode == Keys.Escape) { DualityEditorApp.Deselect(this, ObjectSelection.Category.GameObjCmp); e.Handled = true; From 8699048f2f94af8b14c6dddbda727d7a9b2542af Mon Sep 17 00:00:00 2001 From: Cowan Cumming Date: Sun, 29 Dec 2019 10:15:56 -0800 Subject: [PATCH 10/13] Used event to update tilemap editor selection. --- .../Editor/CamViewStates/TilemapEditorCamViewState.cs | 8 +++++++- .../Editor/Modules/SourcePaletteTilesetView.cs | 1 + .../Editor/Modules/TilemapToolSourcePalette.cs | 10 +++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Source/Plugins/Tilemaps/Editor/CamViewStates/TilemapEditorCamViewState.cs b/Source/Plugins/Tilemaps/Editor/CamViewStates/TilemapEditorCamViewState.cs index 8e57bcf2f..67bc9ec0a 100644 --- a/Source/Plugins/Tilemaps/Editor/CamViewStates/TilemapEditorCamViewState.cs +++ b/Source/Plugins/Tilemaps/Editor/CamViewStates/TilemapEditorCamViewState.cs @@ -630,6 +630,7 @@ protected override void OnEnterState() DualityEditorApp.ObjectPropertyChanged += this.DualityEditorApp_ObjectPropertyChanged; DualityEditorApp.UpdatingEngine += this.DualityEditorApp_UpdatingEngine; Scene.Entered += this.Scene_Entered; + TilemapsEditorPlugin.Instance.PeekTilePalette().SelectedAreaChanged += this.TilemapToolSourcePalette_SelectedAreaChanged; // Initial update this.UpdateTilemapToolButtons(); @@ -755,7 +756,6 @@ protected override void OnMouseUp(MouseEventArgs e) protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); - TilemapsEditorPlugin.Instance.PeekTilePalette().RaiseKeyDownEvent(e); // Hotkeys for switching the currently selected tilemap if (e.KeyCode == Keys.PageUp || e.KeyCode == Keys.PageDown) @@ -806,6 +806,7 @@ protected override void OnKeyDown(KeyEventArgs e) break; } } + TilemapsEditorPlugin.Instance.PeekTilePalette().RaiseKeyDownEvent(e); } protected override void OnKeyUp(KeyEventArgs e) { @@ -1043,6 +1044,11 @@ private void Scene_Entered(object sender, EventArgs e) { this.UpdateActionToolButtons(); } + private void TilemapToolSourcePalette_SelectedAreaChanged(object sender, EventArgs e) + { + this.Invalidate(); + } + private void actionToolButton_Click(object sender, EventArgs e) { TilemapActionEntry clickedEntry = this.actions.FirstOrDefault(entry => entry.ToolButton == sender); diff --git a/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs b/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs index 2733f4508..9ca23d5b2 100644 --- a/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs +++ b/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs @@ -81,6 +81,7 @@ public Rectangle SelectedArea this.selectedArea.Width, this.selectedArea.Height, 6); + this.SelectedAreaChanged?.Invoke(this, EventArgs.Empty); } } public IReadOnlyGrid SelectedTiles diff --git a/Source/Plugins/Tilemaps/Editor/Modules/TilemapToolSourcePalette.cs b/Source/Plugins/Tilemaps/Editor/Modules/TilemapToolSourcePalette.cs index 0c0457b33..840e71830 100644 --- a/Source/Plugins/Tilemaps/Editor/Modules/TilemapToolSourcePalette.cs +++ b/Source/Plugins/Tilemaps/Editor/Modules/TilemapToolSourcePalette.cs @@ -22,6 +22,7 @@ public partial class TilemapToolSourcePalette : DockContent private bool globalEventsSubscribed = false; private TilesetView.TileIndexDrawMode tileIndexDrawMode = TilesetView.TileIndexDrawMode.Never; + public event EventHandler SelectedAreaChanged; private ContentRef SelectedTileset { @@ -42,6 +43,8 @@ public TilemapToolSourcePalette() this.InitializeComponent(); this.mainToolStrip.Renderer = new Duality.Editor.Controls.ToolStrip.DualitorToolStripProfessionalRenderer(); this.ApplyTileIndexDrawMode(); + + this.tilesetView.SelectedAreaChanged += this.SourcePaletteTilesetView_SelectedAreaChanged; } public void RaiseKeyDownEvent(KeyEventArgs e) @@ -149,7 +152,12 @@ protected override void OnClosed(EventArgs e) base.OnClosed(e); this.OnBecameInvisible(); } - + + private void SourcePaletteTilesetView_SelectedAreaChanged(object sender, EventArgs e) + { + this.SelectedAreaChanged?.Invoke(this, e); + } + private void OnBecameVisible() { if (!this.globalEventsSubscribed) From 9483cc41b61bcef24be3826e170e9a523da5ddac Mon Sep 17 00:00:00 2001 From: Cowan Cumming Date: Thu, 30 Apr 2020 18:03:03 -0700 Subject: [PATCH 11/13] Got palette source updating event to work for tilemap cam view again. --- Samples/FlapOrDie/FlapOrDie.Sample.Core.csproj | 1 + .../Tilemaps/Editor/CamViewStates/TilemapEditorCamViewState.cs | 3 ++- .../Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs | 1 - 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Samples/FlapOrDie/FlapOrDie.Sample.Core.csproj b/Samples/FlapOrDie/FlapOrDie.Sample.Core.csproj index fd2a127a2..643d735ef 100644 --- a/Samples/FlapOrDie/FlapOrDie.Sample.Core.csproj +++ b/Samples/FlapOrDie/FlapOrDie.Sample.Core.csproj @@ -14,6 +14,7 @@ False + diff --git a/Source/Plugins/Tilemaps/Editor/CamViewStates/TilemapEditorCamViewState.cs b/Source/Plugins/Tilemaps/Editor/CamViewStates/TilemapEditorCamViewState.cs index 67bc9ec0a..2b9173a87 100644 --- a/Source/Plugins/Tilemaps/Editor/CamViewStates/TilemapEditorCamViewState.cs +++ b/Source/Plugins/Tilemaps/Editor/CamViewStates/TilemapEditorCamViewState.cs @@ -630,7 +630,7 @@ protected override void OnEnterState() DualityEditorApp.ObjectPropertyChanged += this.DualityEditorApp_ObjectPropertyChanged; DualityEditorApp.UpdatingEngine += this.DualityEditorApp_UpdatingEngine; Scene.Entered += this.Scene_Entered; - TilemapsEditorPlugin.Instance.PeekTilePalette().SelectedAreaChanged += this.TilemapToolSourcePalette_SelectedAreaChanged; + TilemapsEditorPlugin.Instance.TileDrawingSourceChanged += this.TilemapToolSourcePalette_SelectedAreaChanged; // Initial update this.UpdateTilemapToolButtons(); @@ -1046,6 +1046,7 @@ private void Scene_Entered(object sender, EventArgs e) } private void TilemapToolSourcePalette_SelectedAreaChanged(object sender, EventArgs e) { + this.activeTool.UpdatePreview(); this.Invalidate(); } diff --git a/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs b/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs index 9ca23d5b2..2733f4508 100644 --- a/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs +++ b/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs @@ -81,7 +81,6 @@ public Rectangle SelectedArea this.selectedArea.Width, this.selectedArea.Height, 6); - this.SelectedAreaChanged?.Invoke(this, EventArgs.Empty); } } public IReadOnlyGrid SelectedTiles From d234cf559c81a0afdf4c05b1de45c79db343d19f Mon Sep 17 00:00:00 2001 From: Cowan Cumming Date: Thu, 30 Apr 2020 23:42:44 -0700 Subject: [PATCH 12/13] Removed unnecessary change to csproj. --- Samples/FlapOrDie/FlapOrDie.Sample.Core.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/Samples/FlapOrDie/FlapOrDie.Sample.Core.csproj b/Samples/FlapOrDie/FlapOrDie.Sample.Core.csproj index 643d735ef..fd2a127a2 100644 --- a/Samples/FlapOrDie/FlapOrDie.Sample.Core.csproj +++ b/Samples/FlapOrDie/FlapOrDie.Sample.Core.csproj @@ -14,7 +14,6 @@ False - From b729baa20f36bed2053f559033315579b3a78617 Mon Sep 17 00:00:00 2001 From: Cowan Cumming Date: Wed, 13 May 2020 15:22:19 -0700 Subject: [PATCH 13/13] Fixed incorrect coordinates for tileset hotkeys. When the tileset had multiple columns, the coordinates for the single column configuration was being used. --- .../Modules/SourcePaletteTilesetView.cs | 46 +++++++++++-------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs b/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs index 2733f4508..bb99fa1bc 100644 --- a/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs +++ b/Source/Plugins/Tilemaps/Editor/Modules/SourcePaletteTilesetView.cs @@ -448,7 +448,7 @@ private void UpdateSelectedTiles() // none to choose from. Keep the default-initialized ones we got above. Tileset tileset = this.TargetTileset.Res; if (tileset == null) return; - + // Determine a tile rect based on the current selection inside the Tileset. Point selectedDisplayedPos = this.GetDisplayedTilePos( this.selectedArea.X, @@ -494,10 +494,12 @@ private void TranslateSelectedArea(int offsetX, int offsetY) return; } - int newX = MathF.Clamp(this.selectedArea.X + offsetX, 0, this.DisplayedTileCount.X - this.selectedArea.Width); - int newY = MathF.Clamp(this.selectedArea.Y + offsetY, 0, this.DisplayedTileCount.Y - this.selectedArea.Height); + Rectangle prevSelectedArea = this.SelectedArea; + + int newX = MathF.Clamp(prevSelectedArea.X + offsetX, 0, this.DisplayedTileCount.X - prevSelectedArea.Width); + int newY = MathF.Clamp(prevSelectedArea.Y + offsetY, 0, this.DisplayedTileCount.Y - prevSelectedArea.Height); - this.SelectedArea = new Rectangle(newX, newY, this.selectedArea.Width, this.selectedArea.Height); + this.SelectedArea = new Rectangle(newX, newY, prevSelectedArea.Width, prevSelectedArea.Height); this.RaiseSelectedAreaEditingFinished(); this.Invalidate(); } @@ -509,16 +511,18 @@ private void ExpandSelectedArea(int diffX, int diffY) return; } - int newX = MathF.Max(this.selectedArea.X + MathF.Min(diffX, 0), 0); - int newY = MathF.Max(this.selectedArea.Y + MathF.Min(diffY, 0), 0); + Rectangle prevSelectedArea = this.SelectedArea; - int newWidth = this.selectedArea.Width + MathF.Max(diffX, 0); - newWidth = MathF.Min(newWidth, this.DisplayedTileCount.X - this.selectedArea.X); - newWidth += this.selectedArea.X - newX; + int newX = MathF.Max(prevSelectedArea.X + MathF.Min(diffX, 0), 0); + int newY = MathF.Max(prevSelectedArea.Y + MathF.Min(diffY, 0), 0); - int newHeight = this.selectedArea.Height + MathF.Max(diffY, 0); - newHeight = MathF.Min(newHeight, this.DisplayedTileCount.Y - this.selectedArea.Y); - newHeight += this.selectedArea.Y - newY; + int newWidth = prevSelectedArea.Width + MathF.Max(diffX, 0); + newWidth = MathF.Min(newWidth, this.DisplayedTileCount.X - prevSelectedArea.X); + newWidth += prevSelectedArea.X - newX; + + int newHeight = prevSelectedArea.Height + MathF.Max(diffY, 0); + newHeight = MathF.Min(newHeight, this.DisplayedTileCount.Y - prevSelectedArea.Y); + newHeight += prevSelectedArea.Y - newY; this.SelectedArea = new Rectangle(newX, newY, newWidth, newHeight); this.RaiseSelectedAreaEditingFinished(); @@ -532,16 +536,18 @@ private void ShrinkSelectedArea(int diffX, int diffY) return; } - int newX = MathF.Min(this.selectedArea.X + MathF.Max(diffX, 0), - this.selectedArea.X + this.selectedArea.Width - 1); - int newY = MathF.Min(this.selectedArea.Y + MathF.Max(diffY, 0), - this.selectedArea.Y + this.selectedArea.Height - 1); + Rectangle prevSelectedArea = this.SelectedArea; + + int newX = MathF.Min(prevSelectedArea.X + MathF.Max(diffX, 0), + prevSelectedArea.X + prevSelectedArea.Width - 1); + int newY = MathF.Min(prevSelectedArea.Y + MathF.Max(diffY, 0), + prevSelectedArea.Y + prevSelectedArea.Height - 1); - int newWidth = MathF.Max(this.selectedArea.Width + MathF.Min(diffX, 0), 1); - newWidth -= newX - this.selectedArea.X; + int newWidth = MathF.Max(prevSelectedArea.Width + MathF.Min(diffX, 0), 1); + newWidth -= newX - prevSelectedArea.X; - int newHeight = MathF.Max(this.selectedArea.Height + MathF.Min(diffY, 0), 1); - newHeight -= newY - this.selectedArea.Y; + int newHeight = MathF.Max(prevSelectedArea.Height + MathF.Min(diffY, 0), 1); + newHeight -= newY - prevSelectedArea.Y; this.SelectedArea = new Rectangle(newX, newY, newWidth, newHeight); this.RaiseSelectedAreaEditingFinished();