mirror of
https://github.com/4sval/FModel.git
synced 2026-05-05 20:36:46 -05:00
Usmap drag & drop UI feedback
This commit is contained in:
parent
8e66371fca
commit
39e4f62010
|
|
@ -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">
|
||||
<Window.TaskbarItemInfo>
|
||||
<TaskbarItemInfo ProgressValue="1.0">
|
||||
<TaskbarItemInfo.ProgressState>
|
||||
|
|
@ -712,5 +710,7 @@
|
|||
</StackPanel>
|
||||
</StatusBarItem>
|
||||
</StatusBar>
|
||||
<controls:UsmapDropOverlay Grid.RowSpan="99"
|
||||
Panel.ZIndex="1000" />
|
||||
</Grid>
|
||||
</adonisControls:AdonisWindow>
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
58
FModel/Views/Resources/Controls/UsmapDropOverlay.xaml
Normal file
58
FModel/Views/Resources/Controls/UsmapDropOverlay.xaml
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
<UserControl x:Class="FModel.Views.Resources.Controls.UsmapDropOverlay"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:FModel.Views.Resources.Controls"
|
||||
xmlns:adonisUi="clr-namespace:AdonisUI;assembly=AdonisUI"
|
||||
Visibility="Collapsed"
|
||||
Background="Transparent"
|
||||
mc:Ignorable="d"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
d:DesignHeight="450"
|
||||
d:DesignWidth="800">
|
||||
<Grid Background="#AA000000"
|
||||
IsHitTestVisible="False"
|
||||
Grid.Row="0"
|
||||
Grid.RowSpan="99">
|
||||
<Border BorderThickness="2"
|
||||
CornerRadius="10"
|
||||
Margin="60"
|
||||
Background="#1FFFFFFF">
|
||||
<Border.BorderBrush>
|
||||
<VisualBrush>
|
||||
<VisualBrush.Visual>
|
||||
<Rectangle Stroke="{DynamicResource {x:Static adonisUi:Brushes.AccentBrush}}"
|
||||
StrokeThickness="2"
|
||||
StrokeDashArray="4 2"
|
||||
StrokeDashCap="Round"
|
||||
Width="{Binding RelativeSource={RelativeSource AncestorType=Border}, Path=ActualWidth}"
|
||||
Height="{Binding RelativeSource={RelativeSource AncestorType=Border}, Path=ActualHeight}"
|
||||
RadiusX="10"
|
||||
RadiusY="10" />
|
||||
</VisualBrush.Visual>
|
||||
</VisualBrush>
|
||||
</Border.BorderBrush>
|
||||
<StackPanel VerticalAlignment="Center">
|
||||
<Viewbox Width="80"
|
||||
Height="80"
|
||||
Margin="0,0,0,24"
|
||||
HorizontalAlignment="Center">
|
||||
<Path Fill="{DynamicResource {x:Static adonisUi:Brushes.AccentForegroundBrush}}"
|
||||
Data="{StaticResource ImportIcon}" />
|
||||
</Viewbox>
|
||||
<TextBlock Text="Drop .usmap to import"
|
||||
Foreground="White"
|
||||
FontSize="24"
|
||||
FontWeight="Bold"
|
||||
HorizontalAlignment="Center" />
|
||||
<TextBlock Text="Mapping file will be applied immediately"
|
||||
Foreground="LightGray"
|
||||
FontSize="14"
|
||||
HorizontalAlignment="Center"
|
||||
Margin="0,10,0,0" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
106
FModel/Views/Resources/Controls/UsmapDropOverlay.xaml.cs
Normal file
106
FModel/Views/Resources/Controls/UsmapDropOverlay.xaml.cs
Normal file
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
@ -98,6 +98,7 @@
|
|||
<Geometry x:Key="CssIcon">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</Geometry>
|
||||
<Geometry x:Key="CsvIcon">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</Geometry>
|
||||
<Geometry x:Key="AIIcon">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</Geometry>
|
||||
<Geometry x:Key="ImportIcon">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</Geometry>
|
||||
|
||||
<!-- For specific games-->
|
||||
<Geometry x:Key="BorderlandsIcon">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</Geometry>
|
||||
|
|
|
|||
|
|
@ -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">
|
||||
<adonisControls:AdonisWindow.Style>
|
||||
<Style TargetType="adonisControls:AdonisWindow" BasedOn="{StaticResource {x:Type adonisControls:AdonisWindow}}" >
|
||||
<Setter Property="Title" Value="Settings" />
|
||||
|
|
@ -160,7 +161,7 @@
|
|||
IsChecked="{Binding KeepDirectoryStructure, Source={x:Static local:Settings.UserSettings.Default}, Mode=TwoWay}" Margin="0 5 0 10"
|
||||
Style="{DynamicResource {x:Static adonisUi:Styles.ToggleSwitch}}" />
|
||||
|
||||
<TextBlock Grid.Row="10" Grid.Column="0" Text="Local Mapping File" VerticalAlignment="Center" Margin="0 5 0 0" />
|
||||
<TextBlock Grid.Row="10" Grid.Column="0" Text="Local Mapping File (drag & drop)" VerticalAlignment="Center" Margin="0 5 0 0" />
|
||||
<CheckBox Grid.Row="10" Grid.Column="2" Margin="0 5 0 0"
|
||||
DataContext="{Binding DataContext, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:Views.SettingsView}}}"
|
||||
Content="{Binding IsChecked, RelativeSource={RelativeSource Self}, Converter={x:Static converters:BoolToToggleConverter.Instance}}"
|
||||
|
|
@ -701,5 +702,8 @@
|
|||
HorizontalAlignment="Right" VerticalAlignment="Bottom" Content="OK" Click="OnClick" />
|
||||
</Grid>
|
||||
</Border>
|
||||
<controls:UsmapDropOverlay Grid.RowSpan="99"
|
||||
Grid.ColumnSpan="99"
|
||||
Panel.ZIndex="1000" />
|
||||
</Grid>
|
||||
</adonisControls:AdonisWindow>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user