From fda1aaac4038f7008426322e095308e795275c62 Mon Sep 17 00:00:00 2001 From: Peter Date: Tue, 15 Oct 2024 21:36:24 +1100 Subject: [PATCH 1/2] feat: added zoom to level layout in UI Users can zoom in and out using CTRL + Scroll Wheel on the level Layout screen. --- editor/Controls/FloorEditor.cs | 45 +++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/editor/Controls/FloorEditor.cs b/editor/Controls/FloorEditor.cs index 5f45d57..9dfa48b 100644 --- a/editor/Controls/FloorEditor.cs +++ b/editor/Controls/FloorEditor.cs @@ -3,9 +3,11 @@ using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; +using System.Transactions; using System.Windows.Forms; using sth1edwv.GameObjects; using sth1edwv.Properties; +using static sth1edwv.Controls.FloorEditor; namespace sth1edwv.Controls { @@ -19,6 +21,7 @@ public sealed partial class FloorEditor : ScrollableControl private int _width; private int _height; private int _tileSize; + private int _zoom; private TileSet _tileSet; private Level _level; private bool _levelBounds; @@ -35,6 +38,7 @@ public FloorEditor() Paint += OnPaint; MouseDown += OnMouseDown; MouseMove += OnMouseMove; + _zoom = 1; } public void SetData(Level level) @@ -65,7 +69,7 @@ private void UpdateSize() return; } // Set bounds for scrolling - _tileSize = 8 + (TileGaps ? 1 : 0); + _tileSize = (8 * _zoom) + (TileGaps ? 1 : 0); _blockSize = _tileSize * 4 + (BlockGaps ? 1 : 0); AutoScrollMinSize = new Size(_width * _blockSize, _height * _blockSize); } @@ -79,9 +83,10 @@ private void OnPaint(object sender, PaintEventArgs e) public void Draw(Graphics g, Rectangle clipRectangle) { + g.InterpolationMode = InterpolationMode.NearestNeighbor; g.PixelOffsetMode = PixelOffsetMode.HighQuality; - using var f = new Font(SystemFonts.MessageBoxFont.FontFamily, 8.0f); + using var f = new Font(SystemFonts.MessageBoxFont.FontFamily, (8.0f * _zoom)); g.Clear(SystemColors.Window); if (_level == null) @@ -110,7 +115,8 @@ public void Draw(Graphics g, Rectangle clipRectangle) { var x = blockX * _blockSize + tileX * _tileSize; var y = blockY * _blockSize + tileY * _tileSize; - g.DrawImageUnscaled(_tileSet.GetImageWithRings(tileIndex, _palette), x, y); + var tile = _tileSet.GetImageWithRings(tileIndex, _palette); + g.DrawImage(tile, x, y, (tile.Width * _zoom), (tile.Height * _zoom)); } } } @@ -136,9 +142,11 @@ void DrawObject(int x, int y, string label) { x *= _blockSize; y *= _blockSize; + var zoomedWidth = image.Width * _zoom; + var zoomedHeight = image.Height * _zoom; g.DrawRectangle(Pens.Blue, x, y, _blockSize, _blockSize); - g.DrawImageUnscaled(image, x + _blockSize / 2 - image.Width / 2, - y + _blockSize / 2 - image.Height / 2); + g.DrawImage(image, x + _blockSize / 2 - zoomedWidth / 2, + y + _blockSize / 2 - zoomedHeight / 2, zoomedWidth, zoomedHeight); var dims = g.MeasureString(label, f).ToSize(); @@ -166,7 +174,7 @@ void DrawObject(int x, int y, string label) if (LevelBounds) { - var left = _level.LeftPixels + _level.LeftPixels / 32 * (_blockSize - 32) + 8; + var left = _level.LeftPixels + _level.LeftPixels / 32 * (_blockSize - 32) + (8 * _zoom); var top = _level.TopPixels + _level.TopPixels / 32 * (_blockSize - 32); var right = _level.RightEdgeFactor * _blockSize * 8 + 256 / 32 * _blockSize; var bottom = _level.BottomEdgeFactor * _blockSize * 8 + 192 / 32 * _blockSize + _level.ExtraHeight; @@ -305,6 +313,31 @@ private void OnMouseMove(object sender, MouseEventArgs e) SetBlockIndex(index, BlockChooser.SelectedIndex); } + protected override void OnMouseWheel(System.Windows.Forms.MouseEventArgs e) + { + if ((ModifierKeys & Keys.Control) != 0) + { + // Ctrl key pressed allows zooming + if (e.Delta > 0) + { + _zoom++; + if (_zoom > 10) _zoom = 10; + } + else + { + _zoom--; + if(_zoom < 1) _zoom = 1; + } + + UpdateSize(); + Invalidate(); + } + else + { + base.OnMouseWheel(e); + } + } + public bool LevelBounds { get => _levelBounds; From 2a991d6269fc3f8319371af9e839cbe289488e5f Mon Sep 17 00:00:00 2001 From: Maxim Date: Tue, 15 Oct 2024 18:38:25 +0100 Subject: [PATCH 2/2] Enhanced zooming - Try to keep the pointed pixel where it is - Add a combo to the toolbar to show and change the zoom level - Default to a zoom level close to the user's DPI scaling factor --- editor/Controls/FloorEditor.cs | 121 ++++++++++++++++++++++++------- editor/Controls/FloorEditor.resx | 120 ++++++++++++++++++++++++++++++ editor/Form1.Designer.cs | 51 ++++++++----- editor/Form1.cs | 66 +++++++++-------- 4 files changed, 280 insertions(+), 78 deletions(-) create mode 100644 editor/Controls/FloorEditor.resx diff --git a/editor/Controls/FloorEditor.cs b/editor/Controls/FloorEditor.cs index 9dfa48b..9c46384 100644 --- a/editor/Controls/FloorEditor.cs +++ b/editor/Controls/FloorEditor.cs @@ -3,11 +3,9 @@ using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; -using System.Transactions; using System.Windows.Forms; using sth1edwv.GameObjects; using sth1edwv.Properties; -using static sth1edwv.Controls.FloorEditor; namespace sth1edwv.Controls { @@ -17,11 +15,11 @@ public sealed partial class FloorEditor : ScrollableControl private Palette _palette; private BlockMapping _blockMapping; private LevelObjectSet _objects; - private int _blockSize; - private int _width; - private int _height; - private int _tileSize; - private int _zoom; + private int _blockSize; // The size of one block in screen pixels + private int _width; // Data width in blocks + private int _height; // Data height in blocks + private int _tileSize; // The size of one tile in screen pixels + private int _zoom; // Scaling factor for zooming private TileSet _tileSet; private Level _level; private bool _levelBounds; @@ -29,6 +27,7 @@ public sealed partial class FloorEditor : ScrollableControl private bool _blockNumbers; private bool _blockGaps; private bool _tileGaps; + private bool _doDraw = true; public FloorEditor() { @@ -38,7 +37,8 @@ public FloorEditor() Paint += OnPaint; MouseDown += OnMouseDown; MouseMove += OnMouseMove; - _zoom = 1; + // Default to the nearest zoom level to the screen scaling factor + _zoom = (int)Math.Round(DeviceDpi / 96.0); } public void SetData(Level level) @@ -76,6 +76,11 @@ private void UpdateSize() private void OnPaint(object sender, PaintEventArgs e) { + if (!_doDraw) + { + // We have suspended drawing to reduce flicker + return; + } // We apply the scroll offset to the graphics to make it draw in the right place e.Graphics.TranslateTransform(AutoScrollPosition.X, AutoScrollPosition.Y); Draw(e.Graphics, e.ClipRectangle); @@ -86,7 +91,16 @@ public void Draw(Graphics g, Rectangle clipRectangle) g.InterpolationMode = InterpolationMode.NearestNeighbor; g.PixelOffsetMode = PixelOffsetMode.HighQuality; - using var f = new Font(SystemFonts.MessageBoxFont.FontFamily, (8.0f * _zoom)); + // Figure out the font size + var defaultFont = SystemFonts.MessageBoxFont ?? SystemFonts.DefaultFont; + var size = g.MeasureString("0", defaultFont); + var fontScale = 1.0f; + if (size.Height > _blockSize * 0.5) + { + fontScale = _blockSize * 0.5f/ size.Height; + } + + using var f = new Font((SystemFonts.MessageBoxFont ?? SystemFonts.DefaultFont).FontFamily, defaultFont.SizeInPoints * fontScale); g.Clear(SystemColors.Window); if (_level == null) @@ -174,10 +188,11 @@ void DrawObject(int x, int y, string label) if (LevelBounds) { - var left = _level.LeftPixels + _level.LeftPixels / 32 * (_blockSize - 32) + (8 * _zoom); - var top = _level.TopPixels + _level.TopPixels / 32 * (_blockSize - 32); - var right = _level.RightEdgeFactor * _blockSize * 8 + 256 / 32 * _blockSize; - var bottom = _level.BottomEdgeFactor * _blockSize * 8 + 192 / 32 * _blockSize + _level.ExtraHeight; + // Compute the bounds in pixel space first... + var left = PixelToScreen(_level.LeftPixels); + var top = PixelToScreen(_level.TopPixels); + var right = PixelToScreen((_level.RightEdgeFactor * 8 + 14) * 32); + var bottom = PixelToScreen((_level.BottomEdgeFactor * 8 + 6) * 32 + _level.ExtraHeight); var rect = new Rectangle(left, top, right - left, bottom - top); // Draw the grey region using var brush = new SolidBrush(Color.FromArgb(128, Color.Black)); @@ -190,6 +205,28 @@ void DrawObject(int x, int y, string label) } } + private int PixelToScreen(int i) + { + // First compute the block and tile offsets + var block = i / 32; + i %= 32; + var tile = i / 8; + var pixels = i % 8; + // Then add them back together based on the current draw state + return block * _blockSize + tile * _tileSize + pixels * _zoom; + } + + private int ScreenToPixel(int i) + { + // First compute the block and tile offsets + var block = i / _blockSize; + i %= _blockSize; + var tile = i / _tileSize; + var pixels = i / _tileSize / _zoom; + // Then add them back together based on the current draw state + return block * 32 + tile * 8 + pixels; + } + private void OnMouseDown(object sender, MouseEventArgs e) { LastClickedBlockIndex = GetClickedBlockIndex(e.X, e.Y); @@ -313,24 +350,13 @@ private void OnMouseMove(object sender, MouseEventArgs e) SetBlockIndex(index, BlockChooser.SelectedIndex); } - protected override void OnMouseWheel(System.Windows.Forms.MouseEventArgs e) + protected override void OnMouseWheel(MouseEventArgs e) { if ((ModifierKeys & Keys.Control) != 0) { // Ctrl key pressed allows zooming - if (e.Delta > 0) - { - _zoom++; - if (_zoom > 10) _zoom = 10; - } - else - { - _zoom--; - if(_zoom < 1) _zoom = 1; - } - - UpdateSize(); - Invalidate(); + var newZoom = _zoom + (e.Delta > 0 ? 1 : -1); + ChangeZoom(newZoom, e.X, e.Y); } else { @@ -338,6 +364,41 @@ protected override void OnMouseWheel(System.Windows.Forms.MouseEventArgs e) } } + private void ChangeZoom(int newZoom, int screenX, int screenY) + { + newZoom = Math.Clamp(newZoom, 1, 10); + if (newZoom == _zoom) + { + // No change + return; + } + + if (_level == null) + { + // Nothing to do, just accept it + _zoom = newZoom; + return; + } + + // Remember the scroll position in terms of the mouse position + var x = ScreenToPixel(screenX - AutoScrollPosition.X); + var y = ScreenToPixel(screenY - AutoScrollPosition.Y); + + _zoom = newZoom; + + _doDraw = false; + UpdateSize(); + + // Then restore the position post-zoom + x = PixelToScreen(x) - screenX; + y = PixelToScreen(y) - screenY; + AutoScrollPosition = new Point(x, y); + + _doDraw = true; + Invalidate(); + FloorChanged?.Invoke(); + } + public bool LevelBounds { get => _levelBounds; @@ -380,6 +441,12 @@ public enum Modes public Modes DrawingMode { get; set; } public int LastClickedBlockIndex { get; set; } + public int Zoom + { + get => _zoom; + set => ChangeZoom(value, Width / 2, Height / 2); + } + public event Action FloorChanged; } } diff --git a/editor/Controls/FloorEditor.resx b/editor/Controls/FloorEditor.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/editor/Controls/FloorEditor.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/editor/Form1.Designer.cs b/editor/Form1.Designer.cs index a9f0b77..c68df9c 100644 --- a/editor/Form1.Designer.cs +++ b/editor/Form1.Designer.cs @@ -98,6 +98,7 @@ private void InitializeComponent() toolStripSeparator3 = new ToolStripSeparator(); buttonResizeFloor = new ToolStripButton(); SharingButton = new ToolStripButton(); + comboZoom = new ToolStripComboBox(); tabControl1 = new TabControl(); tabPage1 = new TabPage(); splitContainer3 = new SplitContainer(); @@ -485,10 +486,10 @@ private void InitializeComponent() // tabPageLayout.Controls.Add(panel1); tabPageLayout.Controls.Add(toolStripLayout); - tabPageLayout.Location = new Point(4, 24); + tabPageLayout.Location = new Point(4, 22); tabPageLayout.Name = "tabPageLayout"; tabPageLayout.Padding = new Padding(3); - tabPageLayout.Size = new Size(1004, 496); + tabPageLayout.Size = new Size(1004, 498); tabPageLayout.TabIndex = 2; tabPageLayout.Text = "Layout"; tabPageLayout.UseVisualStyleBackColor = true; @@ -500,7 +501,7 @@ private void InitializeComponent() panel1.Dock = DockStyle.Fill; panel1.Location = new Point(3, 81); panel1.Name = "panel1"; - panel1.Size = new Size(998, 412); + panel1.Size = new Size(998, 414); panel1.TabIndex = 4; // // splitContainer7 @@ -518,7 +519,7 @@ private void InitializeComponent() // splitContainer7.Panel2 // splitContainer7.Panel2.Controls.Add(layoutBlockChooser); - splitContainer7.Size = new Size(998, 412); + splitContainer7.Size = new Size(998, 414); splitContainer7.SplitterDistance = 706; splitContainer7.TabIndex = 3; // @@ -534,11 +535,12 @@ private void InitializeComponent() floorEditor1.LevelBounds = false; floorEditor1.Location = new Point(0, 0); floorEditor1.Name = "floorEditor1"; - floorEditor1.Size = new Size(706, 412); + floorEditor1.Size = new Size(706, 414); floorEditor1.TabIndex = 0; floorEditor1.Text = "floorEditor1"; floorEditor1.TileGaps = false; floorEditor1.WithObjects = true; + floorEditor1.Zoom = 1; floorEditor1.FloorChanged += floorEditor1_FloorChanged; // // layoutBlockChooser @@ -551,7 +553,7 @@ private void InitializeComponent() layoutBlockChooser.Scaling = 1; layoutBlockChooser.SelectedIndex = -1; layoutBlockChooser.ShowTransparency = false; - layoutBlockChooser.Size = new Size(288, 412); + layoutBlockChooser.Size = new Size(288, 414); layoutBlockChooser.TabIndex = 0; // // levelEditorContextMenu @@ -602,7 +604,7 @@ private void InitializeComponent() // toolStripLayout // toolStripLayout.ImageScalingSize = new Size(32, 32); - toolStripLayout.Items.AddRange(new ToolStripItem[] { toolStripLabel1, buttonShowObjects, buttonBlockNumbers, buttonBlockGaps, buttonTileGaps, buttonLevelBounds, toolStripSeparator1, toolStripButtonSaveRenderedLevel, buttonCopyFloor, buttonPasteFloor, toolStripSeparator2, toolStripLabel2, buttonDraw, buttonSelect, buttonFloodFill, toolStripSeparator3, buttonResizeFloor, SharingButton }); + toolStripLayout.Items.AddRange(new ToolStripItem[] { toolStripLabel1, buttonShowObjects, buttonBlockNumbers, buttonBlockGaps, buttonTileGaps, buttonLevelBounds, toolStripSeparator1, toolStripButtonSaveRenderedLevel, buttonCopyFloor, buttonPasteFloor, toolStripSeparator2, toolStripLabel2, buttonDraw, buttonSelect, buttonFloodFill, toolStripSeparator3, buttonResizeFloor, SharingButton, comboZoom }); toolStripLayout.LayoutStyle = ToolStripLayoutStyle.Flow; toolStripLayout.Location = new Point(3, 3); toolStripLayout.Name = "toolStripLayout"; @@ -767,6 +769,14 @@ private void InitializeComponent() SharingButton.Text = "Sharing..."; SharingButton.Click += SharingButton_Click; // + // comboZoom + // + comboZoom.DropDownStyle = ComboBoxStyle.DropDownList; + comboZoom.Items.AddRange(new object[] { "100%", "200%", "300%", "400%", "500%", "600%", "700%", "800%", "900%", "1000%" }); + comboZoom.Name = "comboZoom"; + comboZoom.Size = new Size(121, 23); + comboZoom.SelectedIndexChanged += LevelRenderModeChanged; + // // tabControl1 // tabControl1.Controls.Add(tabPage5); @@ -783,10 +793,10 @@ private void InitializeComponent() // tabPage1 // tabPage1.Controls.Add(splitContainer3); - tabPage1.Location = new Point(4, 22); + tabPage1.Location = new Point(4, 24); tabPage1.Name = "tabPage1"; tabPage1.Padding = new Padding(3); - tabPage1.Size = new Size(1323, 530); + tabPage1.Size = new Size(1323, 528); tabPage1.TabIndex = 9; tabPage1.Text = "Other art"; tabPage1.UseVisualStyleBackColor = true; @@ -804,7 +814,7 @@ private void InitializeComponent() // splitContainer3.Panel2 // splitContainer3.Panel2.Controls.Add(tabControlArt); - splitContainer3.Size = new Size(1317, 524); + splitContainer3.Size = new Size(1317, 522); splitContainer3.SplitterDistance = 260; splitContainer3.TabIndex = 1; // @@ -815,7 +825,7 @@ private void InitializeComponent() listBoxArt.ItemHeight = 13; listBoxArt.Location = new Point(0, 0); listBoxArt.Name = "listBoxArt"; - listBoxArt.Size = new Size(260, 524); + listBoxArt.Size = new Size(260, 522); listBoxArt.TabIndex = 0; listBoxArt.SelectedIndexChanged += listBoxArt_SelectedIndexChanged; // @@ -829,7 +839,7 @@ private void InitializeComponent() tabControlArt.Location = new Point(0, 0); tabControlArt.Name = "tabControlArt"; tabControlArt.SelectedIndex = 0; - tabControlArt.Size = new Size(1053, 524); + tabControlArt.Size = new Size(1053, 522); tabControlArt.TabIndex = 1; // // tabPageArtLayout @@ -839,7 +849,7 @@ private void InitializeComponent() tabPageArtLayout.Location = new Point(4, 22); tabPageArtLayout.Name = "tabPageArtLayout"; tabPageArtLayout.Padding = new Padding(3); - tabPageArtLayout.Size = new Size(1045, 498); + tabPageArtLayout.Size = new Size(1045, 496); tabPageArtLayout.TabIndex = 2; tabPageArtLayout.Text = "Layout"; tabPageArtLayout.UseVisualStyleBackColor = true; @@ -886,7 +896,7 @@ private void InitializeComponent() tabPageArtTiles.Location = new Point(4, 24); tabPageArtTiles.Name = "tabPageArtTiles"; tabPageArtTiles.Padding = new Padding(3); - tabPageArtTiles.Size = new Size(1045, 496); + tabPageArtTiles.Size = new Size(1045, 494); tabPageArtTiles.TabIndex = 0; tabPageArtTiles.Text = "Tiles"; tabPageArtTiles.UseVisualStyleBackColor = true; @@ -897,7 +907,7 @@ private void InitializeComponent() otherArtTileSetViewer.Location = new Point(3, 3); otherArtTileSetViewer.Margin = new Padding(4, 3, 4, 3); otherArtTileSetViewer.Name = "otherArtTileSetViewer"; - otherArtTileSetViewer.Size = new Size(1039, 490); + otherArtTileSetViewer.Size = new Size(1039, 488); otherArtTileSetViewer.TabIndex = 0; otherArtTileSetViewer.TilesPerRow = 4; otherArtTileSetViewer.Changed += otherArtTileSetViewer_Changed; @@ -905,10 +915,10 @@ private void InitializeComponent() // tabPageArtPalette // tabPageArtPalette.Controls.Add(palettesLayoutPanel); - tabPageArtPalette.Location = new Point(4, 22); + tabPageArtPalette.Location = new Point(4, 24); tabPageArtPalette.Name = "tabPageArtPalette"; tabPageArtPalette.Padding = new Padding(3); - tabPageArtPalette.Size = new Size(1045, 498); + tabPageArtPalette.Size = new Size(1045, 494); tabPageArtPalette.TabIndex = 1; tabPageArtPalette.Text = "Palettes"; tabPageArtPalette.UseVisualStyleBackColor = true; @@ -922,7 +932,7 @@ private void InitializeComponent() palettesLayoutPanel.FlowDirection = FlowDirection.TopDown; palettesLayoutPanel.Location = new Point(3, 3); palettesLayoutPanel.Name = "palettesLayoutPanel"; - palettesLayoutPanel.Size = new Size(1039, 492); + palettesLayoutPanel.Size = new Size(1039, 488); palettesLayoutPanel.TabIndex = 1; palettesLayoutPanel.WrapContents = false; // @@ -932,7 +942,7 @@ private void InitializeComponent() tabPageExtraData.Location = new Point(4, 24); tabPageExtraData.Name = "tabPageExtraData"; tabPageExtraData.Padding = new Padding(3); - tabPageExtraData.Size = new Size(1045, 496); + tabPageExtraData.Size = new Size(1045, 494); tabPageExtraData.TabIndex = 3; tabPageExtraData.Text = "Extra data"; tabPageExtraData.UseVisualStyleBackColor = true; @@ -946,7 +956,7 @@ private void InitializeComponent() extraDataLayoutPanel.FlowDirection = FlowDirection.TopDown; extraDataLayoutPanel.Location = new Point(3, 3); extraDataLayoutPanel.Name = "extraDataLayoutPanel"; - extraDataLayoutPanel.Size = new Size(1039, 490); + extraDataLayoutPanel.Size = new Size(1039, 488); extraDataLayoutPanel.TabIndex = 0; extraDataLayoutPanel.WrapContents = false; // @@ -1273,6 +1283,7 @@ private void InitializeComponent() private TabPage tabPageArtPalette; private FlowLayoutPanel extraDataLayoutPanel; private FlowLayoutPanel palettesLayoutPanel; + private ToolStripComboBox comboZoom; } } diff --git a/editor/Form1.cs b/editor/Form1.cs index eb69ff7..6319239 100644 --- a/editor/Form1.cs +++ b/editor/Form1.cs @@ -32,7 +32,7 @@ public Form1() InitializeComponent(); Text += $" :: v{Assembly.GetCallingAssembly().GetCustomAttribute()?.InformationalVersion}"; - + _solidityImages = new ImageList { ColorDepth = ColorDepth.Depth16Bit, @@ -40,13 +40,13 @@ public Form1() }; _solidityImages.Images.AddStrip(Resources.SolidityImages); - typeof(DataGridView).InvokeMember("DoubleBuffered", - BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty, + typeof(DataGridView).InvokeMember("DoubleBuffered", + BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty, null, dataGridViewBlocks, [true]); - typeof(DataGridView).InvokeMember("DoubleBuffered", - BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty, + typeof(DataGridView).InvokeMember("DoubleBuffered", + BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty, null, extraDataLayoutPanel, [true]); @@ -59,7 +59,8 @@ private void openROMToolStripMenuItem_Click(object sender, EventArgs e) return; } - using var d = new OpenFileDialog{Filter = "*.sms|*.sms"}; + using var d = new OpenFileDialog(); + d.Filter = "*.sms|*.sms"; if (d.ShowDialog(this) != DialogResult.OK) { return; @@ -126,8 +127,8 @@ private void SelectedLevelChanged(object sender, EventArgs e) level?.BlockMapping.UpdateUsageForLevel(level); level?.BlockMapping.UpdateGlobalUsage(_cartridge.Levels); - dataGridViewBlocks.DataSource = level == null - ? null + dataGridViewBlocks.DataSource = level == null + ? null : new BindingListView(level.BlockMapping.Blocks.Select(x => new BlockRow(x, level.TilePalette)).ToList()); dataGridViewBlocks.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells; @@ -168,12 +169,13 @@ private void LevelRenderModeChanged(object sender, EventArgs e) floorEditor1.LevelBounds = buttonLevelBounds.Checked; floorEditor1.BlockNumbers = buttonBlockNumbers.Checked; floorEditor1.WithObjects = buttonShowObjects.Checked; + floorEditor1.Zoom = comboZoom.SelectedIndex + 1; } private Block GetSelectedBlock() { - return dataGridViewBlocks.SelectedRows.Count == 0 - ? null + return dataGridViewBlocks.SelectedRows.Count == 0 + ? null : (dataGridViewBlocks.SelectedRows[0].DataBoundItem as ObjectView)?.Object.Block; } @@ -276,7 +278,8 @@ private void toolStripButtonSaveRenderedLevel_Click(object sender, EventArgs e) using var bmp = new Bitmap(floorEditor1.AutoScrollMinSize.Width, floorEditor1.AutoScrollMinSize.Height); using var g = Graphics.FromImage(bmp); floorEditor1.Draw(g, new Rectangle(0, 0, bmp.Width, bmp.Height)); - using var d = new SaveFileDialog { Filter = "*.png|*.png" }; + using var d = new SaveFileDialog(); + d.Filter = "*.png|*.png"; if (d.ShowDialog(this) == DialogResult.OK) { bmp.Save(d.FileName); @@ -298,16 +301,16 @@ private void Form1_Load(object sender, EventArgs e) switch (column.DataPropertyName) { case nameof(Block.SolidityIndex): - { - column.SortMode = DataGridViewColumnSortMode.Automatic; - if (column is DataGridViewComboBoxColumn c) { - c.DataSource = Enumerable - .Range(0, _solidityImages.Images.Count) - .ToList(); + column.SortMode = DataGridViewColumnSortMode.Automatic; + if (column is DataGridViewComboBoxColumn c) + { + c.DataSource = Enumerable + .Range(0, _solidityImages.Images.Count) + .ToList(); + } + break; } - break; - } } } } @@ -421,13 +424,13 @@ private void propertyGridLevel_PropertyValueChanged(object s, PropertyValueChang private void DrawingButtonCheckedChanged(object sender, EventArgs e) { - foreach (var button in new[]{buttonDraw, buttonSelect, buttonFloodFill}) + foreach (var button in new[] { buttonDraw, buttonSelect, buttonFloodFill }) { button.Checked = button == sender; } - floorEditor1.DrawingMode = buttonDraw.Checked ? FloorEditor.Modes.Draw - : buttonSelect.Checked ? FloorEditor.Modes.Select + floorEditor1.DrawingMode = buttonDraw.Checked ? FloorEditor.Modes.Draw + : buttonSelect.Checked ? FloorEditor.Modes.Select : FloorEditor.Modes.FloodFill; } @@ -510,7 +513,7 @@ private void selectBlockToolStripMenuItem_Click(object sender, EventArgs e) layoutBlockChooser.SelectedIndex = level.Floor.BlockIndices[floorEditor1.LastClickedBlockIndex]; } - private LevelObject getClickedLevelObject() + private LevelObject GetClickedLevelObject() { if (listBoxLevels.SelectedItem is not Level level) { @@ -525,7 +528,7 @@ private LevelObject getClickedLevelObject() private void editObjectToolStripMenuItem_Click(object sender, EventArgs e) { - var levelObject = getClickedLevelObject(); + var levelObject = GetClickedLevelObject(); if (levelObject != null) { using var editor = new ObjectEditor(levelObject); @@ -584,7 +587,7 @@ private void listBoxArt_SelectedIndexChanged(object sender, EventArgs e) foreach (var kvp in artItem.SpriteTileSets) { var tileSet = kvp.Value; - var page = new TabPage(kvp.Key) { Tag = tileSet, Padding = new Padding(3), UseVisualStyleBackColor = true}; + var page = new TabPage(kvp.Key) { Tag = tileSet, Padding = new Padding(3), UseVisualStyleBackColor = true }; var viewer = new TileSetViewer { Dock = DockStyle.Fill, TilesPerRow = tileSet.TilesPerRow }; page.Controls.Add(viewer); var palette = firstPalette.GetData().Count >= 32 @@ -633,7 +636,7 @@ void CheckExtraDataPage() CheckExtraDataPage(); // Make an editor for it - extraDataLayoutPanel.Controls.Add(new Label{Text = asset.Name, AutoSize = true}); + extraDataLayoutPanel.Controls.Add(new Label { Text = asset.Name, AutoSize = true }); var editor = new TileMapDataEditor(asset, artItem.TileSet, firstPalette); editor.DataChanged += _ => UpdateSpace(); extraDataLayoutPanel.Controls.Add(editor); @@ -644,7 +647,7 @@ void CheckExtraDataPage() CheckExtraDataPage(); // Make an editor for it - extraDataLayoutPanel.Controls.Add(new Label{Text = asset.Name, AutoSize = true}); + extraDataLayoutPanel.Controls.Add(new Label { Text = asset.Name, AutoSize = true }); extraDataLayoutPanel.Controls.Add(new RawValueEditor(asset)); } @@ -744,8 +747,8 @@ private void buttonLoadTileset_Click(object sender, EventArgs e) if (MessageBox.Show( this, $"Failed to load image: {ex.Message}. Do you want to try again, replacing the tiles?", - "Art mismatch", - MessageBoxButtons.YesNo, + "Art mismatch", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { // Make the tileset @@ -839,6 +842,7 @@ private void spriteTileSetViewer_Changed(TileSet obj) private void floorEditor1_FloorChanged() { UpdateSpace(); + comboZoom.SelectedIndex = floorEditor1.Zoom - 1; } private void addObjectToolStripMenuItem_Click(object sender, EventArgs e) @@ -873,7 +877,7 @@ private void addObjectToolStripMenuItem_Click(object sender, EventArgs e) private void deleteObjectToolStripMenuItem_Click(object sender, EventArgs e) { - var levelObject = getClickedLevelObject(); + var levelObject = GetClickedLevelObject(); if (levelObject != null && listBoxLevels.SelectedItem is Level level) { level.Objects.Remove(levelObject); @@ -908,7 +912,7 @@ private void textBoxSDSCTitle_TextChanged(object sender, EventArgs e) private void levelEditorContextMenu_Opening(object sender, System.ComponentModel.CancelEventArgs e) { // Disable object items if no object is selected - editObjectToolStripMenuItem.Enabled = deleteObjectToolStripMenuItem.Enabled = getClickedLevelObject() != null; + editObjectToolStripMenuItem.Enabled = deleteObjectToolStripMenuItem.Enabled = GetClickedLevelObject() != null; } } } \ No newline at end of file