diff --git a/UndertaleModLib/Models/UndertaleRoom.cs b/UndertaleModLib/Models/UndertaleRoom.cs index 1be0e33c4..649f5ce47 100644 --- a/UndertaleModLib/Models/UndertaleRoom.cs +++ b/UndertaleModLib/Models/UndertaleRoom.cs @@ -3,6 +3,7 @@ using System.Collections.ObjectModel; using System.ComponentModel; using System.Diagnostics; +using System.Drawing; using System.IO; using System.Linq; using System.Text; @@ -42,7 +43,8 @@ public enum RoomEntryFlags : uint public float GravityX { get; set; } = 0; public float GravityY { get; set; } = 10; public float MetersPerPixel { get; set; } = 0.1f; - public double Grid { get; set; } = 16d; + public double GridWidth { get; set; } = 16d; + public double GridHeight { get; set; } = 16d; public double GridThicknessPx { get; set; } = 1d; public UndertalePointerList Backgrounds { get; private set; } = new UndertalePointerList(); public UndertalePointerList Views { get; private set; } = new UndertalePointerList(); @@ -237,6 +239,30 @@ public void SetupRoom() } foreach (UndertaleRoom.Background bgnd in Backgrounds) bgnd.ParentRoom = this; + + // Automagically set the grid size to whatever most tiles are sized + + Dictionary tileSizes = new Dictionary(); + + // Loop through each tile and save how many times their sizes are used + foreach (UndertaleRoom.Tile tile in Tiles) + { + Point scale = new((int)tile.Width, (int)tile.Height); + if (tileSizes.ContainsKey(scale)) + { + tileSizes[scale]++; + } else { + tileSizes.Add(scale, 1); + } + } + + // If tiles exist at all, grab the most used tile size and use that as our grid size + if (tileSizes.Count > 0) + { + var largestKey = tileSizes.Aggregate((x, y) => x.Value > y.Value ? x : y).Key; + GridWidth = largestKey.X; + GridHeight = largestKey.Y; + } } public override string ToString() diff --git a/UndertaleModTool/Converters/GridConverter.cs b/UndertaleModTool/Converters/GridConverter.cs index 80784b86b..4f2e28a20 100644 --- a/UndertaleModTool/Converters/GridConverter.cs +++ b/UndertaleModTool/Converters/GridConverter.cs @@ -9,14 +9,14 @@ namespace UndertaleModTool { - public class GridConverter : IValueConverter + public class GridConverter : IMultiValueConverter { - public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) + public object Convert(object[] values, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) { - return "0,0,"+value.ToString()+","+value.ToString(); + return new Rect(0, 0, (double)values[0], (double)values[1]); } - public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) + public object[] ConvertBack(object value, System.Type[] targetType, object parameter, System.Globalization.CultureInfo culture) { return null; } diff --git a/UndertaleModTool/Editors/UndertaleRoomEditor.xaml b/UndertaleModTool/Editors/UndertaleRoomEditor.xaml index 6933273c3..36217cfde 100644 --- a/UndertaleModTool/Editors/UndertaleRoomEditor.xaml +++ b/UndertaleModTool/Editors/UndertaleRoomEditor.xaml @@ -351,11 +351,14 @@ - Grid - + Grid Width + - Grid Thickness - + Grid Height + + + Grid Thickness + @@ -610,7 +613,7 @@ - + @@ -624,7 +627,7 @@ - + @@ -903,8 +906,8 @@ - - + +