From 88aaefdbb9b44e054eb58b5ccceb76031aeb8d24 Mon Sep 17 00:00:00 2001 From: zivmaor Date: Tue, 11 Apr 2023 02:52:14 +0300 Subject: [PATCH 1/4] Added delete context menu to gameObjects in room editor treeview. Added Functionaly to the new context menu. --- .../Editors/UndertaleRoomEditor.xaml | 5 ++++ .../Editors/UndertaleRoomEditor.xaml.cs | 25 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/UndertaleModTool/Editors/UndertaleRoomEditor.xaml b/UndertaleModTool/Editors/UndertaleRoomEditor.xaml index c11b1b6b6..374dd9107 100644 --- a/UndertaleModTool/Editors/UndertaleRoomEditor.xaml +++ b/UndertaleModTool/Editors/UndertaleRoomEditor.xaml @@ -88,6 +88,11 @@ + + + + + diff --git a/UndertaleModTool/Editors/UndertaleRoomEditor.xaml.cs b/UndertaleModTool/Editors/UndertaleRoomEditor.xaml.cs index 08a63843a..07340b0d9 100644 --- a/UndertaleModTool/Editors/UndertaleRoomEditor.xaml.cs +++ b/UndertaleModTool/Editors/UndertaleRoomEditor.xaml.cs @@ -1482,6 +1482,31 @@ private void MenuItem_NewGMS1Tile_Click(object sender, RoutedEventArgs e) { AddGMS1Tile(this.DataContext as UndertaleRoom); } + private void MenuItem_Delete_Click(Object sender, RoutedEventArgs e) + { + UndertaleRoom room = this.DataContext as UndertaleRoom; + MenuItem menuitem = sender as MenuItem; + UndertaleObject obj = menuitem.DataContext as UndertaleObject; + + // We need to check before deleting the object but can only clear the editor after deleting the object + bool clearEditor = (obj == (ObjectEditor.Content as UndertaleObject)); + + if (obj is GameObject gameObj) + { + if (mainWindow.IsGMS2 == Visibility.Visible) + { + foreach (var layer in room.Layers) + if (layer.InstancesData != null) + layer.InstancesData.Instances.Remove(gameObj); + roomObjDict.Remove(gameObj.InstanceID, out _); + } + + room.GameObjects.Remove(gameObj); + } + + if (clearEditor) + ObjectEditor.Content = null; + } public static void GenerateSpriteCache(UndertaleRoom room) { From bab8c1243f5111590efc40ec1864110de97284c3 Mon Sep 17 00:00:00 2001 From: zivmaor Date: Tue, 11 Apr 2023 03:27:15 +0300 Subject: [PATCH 2/4] Unified treeview item deletion in room editor. --- .../Editors/UndertaleRoomEditor.xaml.cs | 170 ++++++++---------- 1 file changed, 75 insertions(+), 95 deletions(-) diff --git a/UndertaleModTool/Editors/UndertaleRoomEditor.xaml.cs b/UndertaleModTool/Editors/UndertaleRoomEditor.xaml.cs index 07340b0d9..cb424d933 100644 --- a/UndertaleModTool/Editors/UndertaleRoomEditor.xaml.cs +++ b/UndertaleModTool/Editors/UndertaleRoomEditor.xaml.cs @@ -998,81 +998,8 @@ private void RoomObjectsTree_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Delete) { - UndertaleRoom room = this.DataContext as UndertaleRoom; UndertaleObject selectedObj = ObjectEditor.Content as UndertaleObject; - - if (selectedObj is Background bg) - { - bg.Enabled = false; - bg.BackgroundDefinition = null; - - ObjectEditor.Content = null; - } - else if (selectedObj is View view) - { - view.Enabled = false; - - ObjectEditor.Content = null; - } - else if (selectedObj is Tile tile) - { - if (mainWindow.IsGMS2 == Visibility.Visible) - { - foreach (var layer in room.Layers) - if (layer.AssetsData != null) - layer.AssetsData.LegacyTiles.Remove(tile); - roomObjDict.Remove(tile.InstanceID, out _); - } - - room.Tiles.Remove(tile); - - ObjectEditor.Content = null; - } - else if (selectedObj is GameObject gameObj) - { - if (mainWindow.IsGMS2 == Visibility.Visible) - { - foreach (var layer in room.Layers) - if (layer.InstancesData != null) - layer.InstancesData.Instances.Remove(gameObj); - roomObjDict.Remove(gameObj.InstanceID, out _); - } - - room.GameObjects.Remove(gameObj); - - ObjectEditor.Content = null; - } - else if (selectedObj is SpriteInstance sprInst) - { - foreach (var layer in room.Layers) - if (layer.AssetsData != null) - layer.AssetsData.Sprites.Remove(sprInst); - - sprInstDict.Remove(sprInst, out _); - - ObjectEditor.Content = null; - } - else if (selectedObj is Layer layer) - { - if (layer.InstancesData != null) - foreach (var go in layer.InstancesData.Instances) - room.GameObjects.Remove(go); - - foreach (var pair in roomObjDict) - if (pair.Value == layer) - roomObjDict.Remove(pair.Key, out _); - - foreach (var pair in sprInstDict) - if (pair.Value == layer) - sprInstDict.Remove(pair.Key, out _); - - room.Layers.Remove(layer); - - if (layer.LayerType == LayerType.Background) - room.UpdateBGColorLayer(); - - ObjectEditor.Content = null; - } + DeleteItem(selectedObj); } int dir = 0; @@ -1436,6 +1363,78 @@ private void AddGMS1Tile(UndertaleRoom room) SelectObject(tile); } + private void DeleteItem(UndertaleObject obj) + { + UndertaleRoom room = this.DataContext as UndertaleRoom; + + // We need to check before deleting the object but can only clear the editor after deleting the object + bool clearEditor = (obj == (ObjectEditor.Content as UndertaleObject)); + + if (obj is Background bg) + { + bg.Enabled = false; + bg.BackgroundDefinition = null; + } + else if (obj is View view) + { + view.Enabled = false; + } + else if (obj is Tile tile) + { + if (mainWindow.IsGMS2 == Visibility.Visible) + { + foreach (var layer in room.Layers) + if (layer.AssetsData != null) + layer.AssetsData.LegacyTiles.Remove(tile); + roomObjDict.Remove(tile.InstanceID, out _); + } + + room.Tiles.Remove(tile); + } + else if (obj is GameObject gameObj) + { + if (mainWindow.IsGMS2 == Visibility.Visible) + { + foreach (var layer in room.Layers) + if (layer.InstancesData != null) + layer.InstancesData.Instances.Remove(gameObj); + roomObjDict.Remove(gameObj.InstanceID, out _); + } + + room.GameObjects.Remove(gameObj); + } + else if (obj is SpriteInstance sprInst) + { + foreach (var layer in room.Layers) + if (layer.AssetsData != null) + layer.AssetsData.Sprites.Remove(sprInst); + + sprInstDict.Remove(sprInst, out _); + } + else if (obj is Layer layer) + { + if (layer.InstancesData != null) + foreach (var go in layer.InstancesData.Instances) + room.GameObjects.Remove(go); + + foreach (var pair in roomObjDict) + if (pair.Value == layer) + roomObjDict.Remove(pair.Key, out _); + + foreach (var pair in sprInstDict) + if (pair.Value == layer) + sprInstDict.Remove(pair.Key, out _); + + room.Layers.Remove(layer); + + if (layer.LayerType == LayerType.Background) + room.UpdateBGColorLayer(); + } + + if (clearEditor) + ObjectEditor.Content = null; + } + private void MenuItem_NewLayerInstances_Click(object sender, RoutedEventArgs e) { AddLayer(LayerType.Instances, "NewInstancesLayer"); @@ -1484,28 +1483,9 @@ private void MenuItem_NewGMS1Tile_Click(object sender, RoutedEventArgs e) } private void MenuItem_Delete_Click(Object sender, RoutedEventArgs e) { - UndertaleRoom room = this.DataContext as UndertaleRoom; MenuItem menuitem = sender as MenuItem; - UndertaleObject obj = menuitem.DataContext as UndertaleObject; - - // We need to check before deleting the object but can only clear the editor after deleting the object - bool clearEditor = (obj == (ObjectEditor.Content as UndertaleObject)); - - if (obj is GameObject gameObj) - { - if (mainWindow.IsGMS2 == Visibility.Visible) - { - foreach (var layer in room.Layers) - if (layer.InstancesData != null) - layer.InstancesData.Instances.Remove(gameObj); - roomObjDict.Remove(gameObj.InstanceID, out _); - } - - room.GameObjects.Remove(gameObj); - } - - if (clearEditor) - ObjectEditor.Content = null; + if (menuitem.DataContext is UndertaleObject obj) + DeleteItem(obj); } public static void GenerateSpriteCache(UndertaleRoom room) From 5582095f175623e1ec099fe07a7b0122a13dc507 Mon Sep 17 00:00:00 2001 From: zivmaor Date: Tue, 11 Apr 2023 03:42:59 +0300 Subject: [PATCH 3/4] Added context menu delete to all the things that can be deleted in room editor treeview. Everything apart from backgrounds. I couldn't understand how they worked. --- .../Editors/UndertaleRoomEditor.xaml | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/UndertaleModTool/Editors/UndertaleRoomEditor.xaml b/UndertaleModTool/Editors/UndertaleRoomEditor.xaml index 374dd9107..2eaa83893 100644 --- a/UndertaleModTool/Editors/UndertaleRoomEditor.xaml +++ b/UndertaleModTool/Editors/UndertaleRoomEditor.xaml @@ -103,6 +103,11 @@ + + + + + @@ -113,6 +118,11 @@ + + + + + @@ -154,6 +164,11 @@ + + + + + @@ -231,6 +246,7 @@ + @@ -238,7 +254,13 @@ - + + + + + + + @@ -261,6 +283,7 @@ + @@ -268,7 +291,13 @@ - + + + + + + + From 61f5d8e976ec1604503b00c0494e3728e3b16e72 Mon Sep 17 00:00:00 2001 From: VladiStep Date: Tue, 11 Apr 2023 14:39:58 +0300 Subject: [PATCH 4/4] Room objects context menu improvements. --- .../Editors/UndertaleRoomEditor.xaml | 54 ++++++++++++++----- .../Editors/UndertaleRoomEditor.xaml.cs | 6 +++ 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/UndertaleModTool/Editors/UndertaleRoomEditor.xaml b/UndertaleModTool/Editors/UndertaleRoomEditor.xaml index 2eaa83893..71c5df2ec 100644 --- a/UndertaleModTool/Editors/UndertaleRoomEditor.xaml +++ b/UndertaleModTool/Editors/UndertaleRoomEditor.xaml @@ -90,7 +90,7 @@ - + @@ -105,7 +105,7 @@ - + @@ -120,28 +120,41 @@ - + + Foreground="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"> + + + + + + + + + + + @@ -151,24 +164,26 @@ + + + + + - - - - - @@ -205,6 +220,11 @@ + + + + + @@ -246,7 +266,7 @@ - + @@ -257,7 +277,7 @@ - + @@ -283,7 +303,7 @@ - + @@ -294,7 +314,7 @@ - + @@ -302,7 +322,13 @@ - + + + + + + + diff --git a/UndertaleModTool/Editors/UndertaleRoomEditor.xaml.cs b/UndertaleModTool/Editors/UndertaleRoomEditor.xaml.cs index cb424d933..1b30f8b2a 100644 --- a/UndertaleModTool/Editors/UndertaleRoomEditor.xaml.cs +++ b/UndertaleModTool/Editors/UndertaleRoomEditor.xaml.cs @@ -1411,6 +1411,12 @@ private void DeleteItem(UndertaleObject obj) sprInstDict.Remove(sprInst, out _); } + else if (obj is ParticleSystemInstance partSysInst) + { + foreach (var layer in room.Layers) + if (layer.AssetsData != null) + layer.AssetsData.ParticleSystems.Remove(partSysInst); + } else if (obj is Layer layer) { if (layer.InstancesData != null)