From def057d5dac75b0b6c371ae11b7975e8db1c639a Mon Sep 17 00:00:00 2001 From: VladiStep Date: Fri, 17 Jun 2022 18:57:20 +0300 Subject: [PATCH 1/2] Any "UndertaleResource" can be opened in a new tab with MMB (in the asset list). --- UndertaleModTool/MainWindow.xaml | 9 ++++++--- UndertaleModTool/MainWindow.xaml.cs | 24 +++++++++++++++++++++++- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/UndertaleModTool/MainWindow.xaml b/UndertaleModTool/MainWindow.xaml index f81a1f37a..d5841a941 100644 --- a/UndertaleModTool/MainWindow.xaml +++ b/UndertaleModTool/MainWindow.xaml @@ -178,9 +178,12 @@ - + diff --git a/UndertaleModTool/MainWindow.xaml.cs b/UndertaleModTool/MainWindow.xaml.cs index fd810c783..41d60ffd1 100644 --- a/UndertaleModTool/MainWindow.xaml.cs +++ b/UndertaleModTool/MainWindow.xaml.cs @@ -1531,7 +1531,7 @@ private void TreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEv { if (e.NewValue is TreeViewItem) { - string item = (e.NewValue as TreeViewItem)?.Header?.ToString(); + string item = (e.NewValue as TreeViewItem).Header?.ToString(); if (item == "Data") { @@ -1567,7 +1567,29 @@ private void MainTree_MouseDoubleClick(object sender, MouseButtonEventArgs e) OpenInTab(Highlighted); } + private void MainTree_MouseDown(object sender, MouseButtonEventArgs e) + { + if (e.ButtonState == MouseButtonState.Pressed && e.ChangedButton == System.Windows.Input.MouseButton.Middle) + { + DependencyObject obj = MainTree.InputHitTest(e.GetPosition(MainTree)) as DependencyObject; + if (obj is not TextBlock) + return; + + TreeViewItem item = GetNearestParent(obj); + if (item is null) + return; + + item.IsSelected = true; + if (item.DataContext is not UndertaleResource) + return; + + if (Highlighted is UndertaleRoom room && Selected is not UndertaleRoom) + UndertaleRoomEditor.CheckAndRearrangeLayers(room); + + OpenInTab(Highlighted, true); + } + } private void MainTree_KeyUp(object sender, KeyEventArgs e) { if (e.Key == Key.Return) From 586c9461428854959ce7b8f914dabccde9f70d11 Mon Sep 17 00:00:00 2001 From: VladiStep Date: Sat, 18 Jun 2022 15:10:38 +0300 Subject: [PATCH 2/2] Addressed @Miepee comment --- UndertaleModTool/MainWindow.xaml.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/UndertaleModTool/MainWindow.xaml.cs b/UndertaleModTool/MainWindow.xaml.cs index 41d60ffd1..16e58e114 100644 --- a/UndertaleModTool/MainWindow.xaml.cs +++ b/UndertaleModTool/MainWindow.xaml.cs @@ -1571,6 +1571,9 @@ private void MainTree_MouseDown(object sender, MouseButtonEventArgs e) { if (e.ButtonState == MouseButtonState.Pressed && e.ChangedButton == System.Windows.Input.MouseButton.Middle) { + // Gets the clicked visual element by the mouse position (relative to "MainTree"). + // This is used instead of "VisualTreeHelper.HitTest()" because that ignores the visibility of elements, + // which led to "ghost" hits on empty space. DependencyObject obj = MainTree.InputHitTest(e.GetPosition(MainTree)) as DependencyObject; if (obj is not TextBlock) return;