diff --git a/FModel/MainWindow.xaml b/FModel/MainWindow.xaml index b8413665..abf9e32a 100644 --- a/FModel/MainWindow.xaml +++ b/FModel/MainWindow.xaml @@ -10,12 +10,10 @@ xmlns:adonisUi="clr-namespace:AdonisUI;assembly=AdonisUI" xmlns:adonisControls="clr-namespace:AdonisUI.Controls;assembly=AdonisUI" xmlns:adonisExtensions="clr-namespace:AdonisUI.Extensions;assembly=AdonisUI" - AllowDrop="True" - Drop="OnDrop" - PreviewDragOver="OnPreviewDragOver" WindowStartupLocation="CenterScreen" Closing="OnClosing" Loaded="OnLoaded" PreviewKeyDown="OnWindowKeyDown" Height="{Binding Source={x:Static SystemParameters.MaximizedPrimaryScreenHeight}, Converter={converters:RatioConverter}, ConverterParameter='0.95'}" - Width="{Binding Source={x:Static SystemParameters.MaximizedPrimaryScreenWidth}, Converter={converters:RatioConverter}, ConverterParameter='0.90'}"> + Width="{Binding Source={x:Static SystemParameters.MaximizedPrimaryScreenWidth}, Converter={converters:RatioConverter}, ConverterParameter='0.90'}" + AllowDrop="True"> @@ -712,5 +710,7 @@ + diff --git a/FModel/MainWindow.xaml.cs b/FModel/MainWindow.xaml.cs index 07df9024..b36da622 100644 --- a/FModel/MainWindow.xaml.cs +++ b/FModel/MainWindow.xaml.cs @@ -375,50 +375,4 @@ public partial class MainWindow childFolder.IsExpanded = true; childFolder.IsSelected = true; } - - private void OnPreviewDragOver(object sender, DragEventArgs e) - { - if (e.Data.GetDataPresent(DataFormats.FileDrop)) - { - var files = (string[]) e.Data.GetData(DataFormats.FileDrop); - if (_applicationView.Status.IsReady && files.Any(file => Path.GetExtension(file).Equals(".usmap", StringComparison.OrdinalIgnoreCase))) - { - e.Effects = DragDropEffects.Copy; - e.Handled = true; - return; - } - } - - e.Effects = DragDropEffects.None; - e.Handled = true; - } - - private async void OnDrop(object sender, DragEventArgs e) - { - if (!e.Data.GetDataPresent(DataFormats.FileDrop)) - return; - - var files = (string[]) e.Data.GetData(DataFormats.FileDrop); - var usmapFile = files.FirstOrDefault(file => Path.GetExtension(file).Equals(".usmap", StringComparison.OrdinalIgnoreCase)); - - if (usmapFile is null) - return; - - UserSettings.IsEndpointValid(EEndpointType.Mapping, out var oldMappingsEndpoint); - try - { - var newMappingsEndpoint = new EndpointSettings() { Overwrite = true, FilePath = usmapFile }; - UserSettings.Default.CurrentDir.Endpoints[(int) EEndpointType.Mapping] = newMappingsEndpoint; - await _applicationView.CUE4Parse.InitMappings(); - _applicationView.SettingsView.MappingEndpoint = newMappingsEndpoint; - } - catch (Exception ex) - { - UserSettings.Default.CurrentDir.Endpoints[(int) EEndpointType.Mapping] = oldMappingsEndpoint; - FLogger.Append(ELog.Error, () => - { - FLogger.Text($"Failed to load mapping file: {ex.Message}", Constants.WHITE, true); - }); - } - } } diff --git a/FModel/Views/Resources/Controls/UsmapDropOverlay.xaml b/FModel/Views/Resources/Controls/UsmapDropOverlay.xaml new file mode 100644 index 00000000..3f5f3a26 --- /dev/null +++ b/FModel/Views/Resources/Controls/UsmapDropOverlay.xaml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/FModel/Views/Resources/Controls/UsmapDropOverlay.xaml.cs b/FModel/Views/Resources/Controls/UsmapDropOverlay.xaml.cs new file mode 100644 index 00000000..d525d67c --- /dev/null +++ b/FModel/Views/Resources/Controls/UsmapDropOverlay.xaml.cs @@ -0,0 +1,106 @@ +using System; +using System.IO; +using System.Linq; +using System.Windows; +using System.Windows.Controls; +using FModel.Services; +using FModel.Settings; +using FModel.ViewModels; + +namespace FModel.Views.Resources.Controls; + +public partial class UsmapDropOverlay : UserControl +{ + private ApplicationViewModel _applicationView => ApplicationService.ApplicationView; + private bool _isDraggingUsmap = false; + + public UsmapDropOverlay() + { + InitializeComponent(); + Loaded += OnLoaded; + } + + private void OnLoaded(object sender, RoutedEventArgs e) + { + var window = Window.GetWindow(this); + if (window is null) + return; + + window.PreviewDragEnter += OnPreviewDragEnter; + window.PreviewDragOver += OnPreviewDragOver; + window.PreviewDragLeave += OnPreviewDragLeave; + window.Drop += OnDrop; + } + + private void OnPreviewDragEnter(object sender, DragEventArgs e) + { + _isDraggingUsmap = CheckIsUsmap(e); + if (_isDraggingUsmap) + { + Visibility = Visibility.Visible; + e.Effects = DragDropEffects.Copy; + } + else + { + e.Effects = DragDropEffects.None; + } + e.Handled = true; + } + + private void OnPreviewDragOver(object sender, DragEventArgs e) + { + if (!_isDraggingUsmap) + { + e.Effects = DragDropEffects.None; + e.Handled = true; + } + else + { + e.Effects = DragDropEffects.Copy; + e.Handled = true; + return; + } + } + + private void OnPreviewDragLeave(object sender, DragEventArgs e) => + Visibility = Visibility.Collapsed; + + private async void OnDrop(object sender, DragEventArgs e) + { + Visibility = Visibility.Collapsed; + if (!e.Data.GetDataPresent(DataFormats.FileDrop)) + return; + + var files = (string[]) e.Data.GetData(DataFormats.FileDrop); + var usmapFile = files.FirstOrDefault(file => Path.GetExtension(file).Equals(".usmap", StringComparison.OrdinalIgnoreCase)); + + if (usmapFile is null) + return; + + UserSettings.IsEndpointValid(EEndpointType.Mapping, out var oldMappingsEndpoint); + try + { + var newMappingsEndpoint = new EndpointSettings() { Overwrite = true, FilePath = usmapFile }; + UserSettings.Default.CurrentDir.Endpoints[(int) EEndpointType.Mapping] = newMappingsEndpoint; + await _applicationView.CUE4Parse.InitMappings(); + _applicationView.SettingsView.MappingEndpoint = newMappingsEndpoint; + } + catch (Exception ex) + { + UserSettings.Default.CurrentDir.Endpoints[(int) EEndpointType.Mapping] = oldMappingsEndpoint; + FLogger.Append(ELog.Error, () => + { + FLogger.Text($"Failed to load mapping file: {ex.Message}", Constants.WHITE, true); + }); + } + } + + private bool CheckIsUsmap(DragEventArgs e) + { + if (!e.Data.GetDataPresent(DataFormats.FileDrop)) + return false; + + var files = (string[]) e.Data.GetData(DataFormats.FileDrop); + return _applicationView.Status.IsReady && files.Any(f => Path.GetExtension(f).Equals(".usmap", StringComparison.OrdinalIgnoreCase)); + } +} diff --git a/FModel/Views/Resources/Icons.xaml b/FModel/Views/Resources/Icons.xaml index 45e0b5e1..39f1aa86 100644 --- a/FModel/Views/Resources/Icons.xaml +++ b/FModel/Views/Resources/Icons.xaml @@ -98,6 +98,7 @@ M5,3L4.35,6.34H17.94L17.5,8.5H3.92L3.26,11.83H16.85L16.09,15.64L10.61,17.45L5.86,15.64L6.19,14H2.85L2.06,18L9.91,21L18.96,18L20.16,11.97L20.4,10.76L21.94,3H5Z M14 2H6C4.9 2 4 2.9 4 4V20C4 21.1 4.9 22 6 22H18C19.1 22 20 21.1 20 20V8L14 2M15 16L13 20H10L12 16H9V11H15V16M13 9V3.5L18.5 9H13Z M12,2A2,2 0 0,1 14,4C14,4.74 13.6,5.39 13,5.73V7H14A7,7 0 0,1 21,14H22A1,1 0 0,1 23,15V18A1,1 0 0,1 22,19H21V20A2,2 0 0,1 19,22H5A2,2 0 0,1 3,20V19H2A1,1 0 0,1 1,18V15A1,1 0 0,1 2,14H3A7,7 0 0,1 10,7H11V5.73C10.4,5.39 10,4.74 10,4A2,2 0 0,1 12,2M7.5,13A2.5,2.5 0 0,0 5,15.5A2.5,2.5 0 0,0 7.5,18A2.5,2.5 0 0,0 10,15.5A2.5,2.5 0 0,0 7.5,13M16.5,13A2.5,2.5 0 0,0 14,15.5A2.5,2.5 0 0,0 16.5,18A2.5,2.5 0 0,0 19,15.5A2.5,2.5 0 0,0 16.5,13Z + M14,12L10,8V11H2V13H10V16M20,18V6C20,4.89 19.1,4 18,4H6A2,2 0 0,0 4,6V9H6V6H18V18H6V15H4V18A2,2 0 0,0 6,20H18A2,2 0 0,0 20,18Z M13,9V3.5L18.5,9M6,2C4.89,2 4,2.89 4,4V20A2,2 0 0,0 6,22H18A2,2 0 0,0 20,20V8L14,2H6 ZM12,11A3,3 0 1,0 12,17A3,3 0 0,0 12,11 ZM12,12.5L14,16H13L12,14.5L11,16H10L12,12.5Z diff --git a/FModel/Views/SettingsView.xaml b/FModel/Views/SettingsView.xaml index 658a38bb..7094e30c 100644 --- a/FModel/Views/SettingsView.xaml +++ b/FModel/Views/SettingsView.xaml @@ -10,7 +10,8 @@ xmlns:adonisExtensions="clr-namespace:AdonisUI.Extensions;assembly=AdonisUI" WindowStartupLocation="CenterScreen" ResizeMode="NoResize" IconVisibility="Collapsed" SizeToContent="Height" MinHeight="{Binding Source={x:Static SystemParameters.MaximizedPrimaryScreenHeight}, Converter={converters:RatioConverter}, ConverterParameter='0.10'}" - Width="{Binding Source={x:Static SystemParameters.MaximizedPrimaryScreenWidth}, Converter={converters:RatioConverter}, ConverterParameter='0.45'}"> + Width="{Binding Source={x:Static SystemParameters.MaximizedPrimaryScreenWidth}, Converter={converters:RatioConverter}, ConverterParameter='0.45'}" + AllowDrop="True">