From 3c882bc06338cb223dc752f937c0173c3bbd2f81 Mon Sep 17 00:00:00 2001 From: VladiStep Date: Wed, 20 Apr 2022 15:42:37 +0300 Subject: [PATCH 1/3] Added missing "Frame index" and "Image speed" fields for game object instances; added "DataFieldOneTimeConverter"; added missing "IsSharedSizeScope" attribute --- UndertaleModLib/Models/UndertaleRoom.cs | 6 +++- .../Converters/DataFieldOneTimeConverter.cs | 35 +++++++++++++++++++ .../Editors/UndertaleRoomEditor.xaml | 35 ++++++++++++++----- 3 files changed, 67 insertions(+), 9 deletions(-) create mode 100644 UndertaleModTool/Converters/DataFieldOneTimeConverter.cs diff --git a/UndertaleModLib/Models/UndertaleRoom.cs b/UndertaleModLib/Models/UndertaleRoom.cs index bd648362e..2c2e13391 100644 --- a/UndertaleModLib/Models/UndertaleRoom.cs +++ b/UndertaleModLib/Models/UndertaleRoom.cs @@ -698,6 +698,10 @@ public class GameObject : UndertaleObjectLenCheck, RoomObject, INotifyPropertyCh /// The image index of this object. Game Maker: Studio 2 only. /// public int ImageIndex { get; set; } + /// + /// A wrapper of that prevents entering index that's out of bounds. + /// + public int SafeImageIndex { get => ImageIndex; set { ImageIndex = Math.Clamp(value, 0, (ObjectDefinition?.Sprite?.Textures?.Count ?? 1) - 1); OnPropertyChanged(); } } public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged([CallerMemberName] string name = null) @@ -1362,7 +1366,7 @@ public class SpriteInstance : UndertaleObject, INotifyPropertyChanged public float AnimationSpeed { get; set; } public AnimationSpeedType AnimationSpeedType { get; set; } public float FrameIndex { get; set; } - public float SafeFrameIndex { get => FrameIndex; set { FrameIndex = Math.Clamp(value, 0, Sprite.Textures.Count - 1); OnPropertyChanged(); } } + public float SafeFrameIndex { get => FrameIndex; set { FrameIndex = Math.Clamp(value, 0, (Sprite?.Textures?.Count ?? 1) - 1); OnPropertyChanged(); } } public float Rotation { get; set; } public float OppositeRotation => 360F - Rotation; public int XOffset => Sprite is not null ? X - Sprite.OriginX : X; diff --git a/UndertaleModTool/Converters/DataFieldOneTimeConverter.cs b/UndertaleModTool/Converters/DataFieldOneTimeConverter.cs new file mode 100644 index 000000000..502ec5160 --- /dev/null +++ b/UndertaleModTool/Converters/DataFieldOneTimeConverter.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Data; +using UndertaleModLib; + +namespace UndertaleModTool +{ + public class DataFieldOneTimeConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is not UndertaleData data || parameter is not string par) + return null; + + FieldInfo info = data.GetType().GetField(par); + object resObj = info?.GetValue(data); + + if (resObj is bool res) + return res ? Visibility.Visible : Visibility.Collapsed; + else + return null; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/UndertaleModTool/Editors/UndertaleRoomEditor.xaml b/UndertaleModTool/Editors/UndertaleRoomEditor.xaml index fd24f0faf..4148abb92 100644 --- a/UndertaleModTool/Editors/UndertaleRoomEditor.xaml +++ b/UndertaleModTool/Editors/UndertaleRoomEditor.xaml @@ -31,6 +31,7 @@ + @@ -355,7 +356,7 @@ - + @@ -422,7 +423,7 @@ - + @@ -500,9 +501,9 @@ - + - + @@ -514,6 +515,7 @@ + @@ -558,13 +560,30 @@ Rotation - Pre Create code - + + + + + + + + + + + Frame index + + + Image speed + + + + Pre Create code + - + @@ -873,7 +892,7 @@ - + From 67830209a12670e27582bfef4927806d3f0c773e Mon Sep 17 00:00:00 2001 From: VladiStep Date: Wed, 20 Apr 2022 15:57:55 +0300 Subject: [PATCH 2/3] Room editor uses "ImageIndex" of game object instance; applied "CachedImageLoaderWithIndex" to "UndertaleRoomRenderer" --- .../Controls/UndertaleRoomRenderer.xaml | 15 +++++++++++++-- .../Converters/UndertaleCachedImageLoader.cs | 7 ++++++- UndertaleModTool/Editors/UndertaleRoomEditor.xaml | 7 ++++++- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/UndertaleModTool/Controls/UndertaleRoomRenderer.xaml b/UndertaleModTool/Controls/UndertaleRoomRenderer.xaml index 244b4f67e..2c60f59f7 100644 --- a/UndertaleModTool/Controls/UndertaleRoomRenderer.xaml +++ b/UndertaleModTool/Controls/UndertaleRoomRenderer.xaml @@ -26,6 +26,7 @@ + @@ -146,9 +147,14 @@ + + + + + + @@ -180,9 +186,14 @@ + + + + + + diff --git a/UndertaleModTool/Converters/UndertaleCachedImageLoader.cs b/UndertaleModTool/Converters/UndertaleCachedImageLoader.cs index f9c516ba1..17cad5078 100644 --- a/UndertaleModTool/Converters/UndertaleCachedImageLoader.cs +++ b/UndertaleModTool/Converters/UndertaleCachedImageLoader.cs @@ -300,7 +300,12 @@ public object Convert(object[] values, Type targetType, object parameter, Cultur if (textures is null) return null; - int index = (int)(float)values[1]; + int index = -1; + if (values[1] is int indexInt) + index = indexInt; + else if (values[1] is float indexFloat) + index = (int)indexFloat; + if (index > textures.Count - 1 || index < 0) return null; else diff --git a/UndertaleModTool/Editors/UndertaleRoomEditor.xaml b/UndertaleModTool/Editors/UndertaleRoomEditor.xaml index 4148abb92..8d32ff931 100644 --- a/UndertaleModTool/Editors/UndertaleRoomEditor.xaml +++ b/UndertaleModTool/Editors/UndertaleRoomEditor.xaml @@ -1093,9 +1093,14 @@ + + + + + + From 746251090c0d0157d9b8710910eaa9e3ec07f701 Mon Sep 17 00:00:00 2001 From: VladiStep Date: Wed, 20 Apr 2022 16:45:23 +0300 Subject: [PATCH 3/3] Rephrased XML comment Co-authored-by: Miepee <38186597+Miepee@users.noreply.github.com> --- UndertaleModLib/Models/UndertaleRoom.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UndertaleModLib/Models/UndertaleRoom.cs b/UndertaleModLib/Models/UndertaleRoom.cs index 2c2e13391..34a1b874d 100644 --- a/UndertaleModLib/Models/UndertaleRoom.cs +++ b/UndertaleModLib/Models/UndertaleRoom.cs @@ -699,7 +699,7 @@ public class GameObject : UndertaleObjectLenCheck, RoomObject, INotifyPropertyCh /// public int ImageIndex { get; set; } /// - /// A wrapper of that prevents entering index that's out of bounds. + /// A wrapper of that prevents using an out of bounds index. /// public int SafeImageIndex { get => ImageIndex; set { ImageIndex = Math.Clamp(value, 0, (ObjectDefinition?.Sprite?.Textures?.Count ?? 1) - 1); OnPropertyChanged(); } }