hover is back + resolve any preview without blocking category

This commit is contained in:
Asval
2026-11-30 18:06:04 +01:00
parent db36e95004
commit 07c975ab7e
7 changed files with 145 additions and 204 deletions

View File

@@ -199,3 +199,10 @@ public enum EExplorerViewMode
Grid,
List
}
public enum EExplorerPreviewMode
{
None,
MeshesOnHover,
All
}

View File

@@ -555,6 +555,59 @@
Stretch="Uniform"
Fill="{DynamicResource {x:Static adonisUi:Brushes.ForegroundBrush}}" />
</ToggleButton>
<ToggleButton Style="{StaticResource ExplorerViewToggleButton}"
Margin="5,0,0,0"
ToolTip="No Thumbnails"
IsChecked="{Binding ExplorerPreviewMode,
Source={x:Static local:Settings.UserSettings.Default},
Converter={x:Static converters:EnumToBoolConverter.Instance},
ConverterParameter={x:Static local:EExplorerPreviewMode.None},
Mode=TwoWay}">
<Path Data="{StaticResource AssetIcon}"
Width="14"
Height="14"
Stretch="Uniform"
Fill="{DynamicResource {x:Static adonisUi:Brushes.ForegroundBrush}}" />
</ToggleButton>
<ToggleButton Style="{StaticResource ExplorerViewToggleButton}"
ToolTip="Mesh Thumbnails On Hover"
IsChecked="{Binding ExplorerPreviewMode,
Source={x:Static local:Settings.UserSettings.Default},
Converter={x:Static converters:EnumToBoolConverter.Instance},
ConverterParameter={x:Static local:EExplorerPreviewMode.MeshesOnHover},
Mode=TwoWay}">
<Path Data="{StaticResource CursorIcon}"
Width="14"
Height="14"
Stretch="Uniform"
Fill="{DynamicResource {x:Static adonisUi:Brushes.ForegroundBrush}}" />
</ToggleButton>
<ToggleButton Style="{StaticResource ExplorerViewToggleButton}"
ToolTip="All Thumbnails"
IsChecked="{Binding ExplorerPreviewMode,
Source={x:Static local:Settings.UserSettings.Default},
Converter={x:Static converters:EnumToBoolConverter.Instance},
ConverterParameter={x:Static local:EExplorerPreviewMode.All},
Mode=TwoWay}">
<Path Data="{StaticResource TextureIconAlt}"
Width="14"
Height="14"
Stretch="Uniform"
Fill="{DynamicResource {x:Static adonisUi:Brushes.ForegroundBrush}}" />
</ToggleButton>
<ToggleButton Style="{StaticResource ExplorerViewToggleButton}"
Margin="5,0,0,0"
IsChecked="{Binding IsAssetsExplorerVisible, Converter={x:Static converters:InvertBooleanConverter.Instance}, Mode=TwoWay}">
<ToggleButton.ToolTip>
<ToolTip Content="{Binding SwitchAssetExplorer, Source={x:Static local:Settings.UserSettings.Default}}"
ContentStringFormat="File Properties ({0})" />
</ToggleButton.ToolTip>
<Path Data="{StaticResource JsonIcon}"
Width="14"
Height="14"
Stretch="Uniform"
Fill="{DynamicResource {x:Static adonisUi:Brushes.ForegroundBrush}}" />
</ToggleButton>
</StackPanel>
</Grid>
@@ -609,77 +662,6 @@
Visibility="{Binding IsAssetsExplorerVisible, Converter={x:Static converters:InvertBoolToVisibilityConverter.Instance}, ConverterParameter=Hidden}" />
</Grid>
<Border Grid.Row="0"
VerticalAlignment="Bottom"
HorizontalAlignment="Right"
Margin="12,12,20,12"
Opacity="0.5"
Visibility="{Binding FeaturePreviewNewAssetExplorer, Source={x:Static settings:UserSettings.Default}, Converter={StaticResource BoolToVisibilityConverter}}"
Background="{DynamicResource {x:Static adonisUi:Brushes.Layer2BackgroundBrush}}"
CornerRadius="8"
Padding="4"
Effect="{DynamicResource ShadowEffect}">
<Border.Triggers>
<EventTrigger RoutedEvent="MouseEnter">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity"
To="1"
Duration="0:0:0.2" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="MouseLeave">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity"
To="0.5"
Duration="0:0:0.2" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Border.Triggers>
<StackPanel Orientation="Horizontal"
HorizontalAlignment="Center">
<ToggleButton Width="32"
Height="32"
Cursor="Hand"
Margin="0,0,2,0"
IsChecked="{Binding IsAssetsExplorerVisible, Mode=TwoWay}"
Style="{StaticResource AssetsExplorerToggleButtonStyle}" />
<ToggleButton Width="32"
Height="32"
Cursor="Hand"
Focusable="False"
IsChecked="{Binding PreviewTexturesAssetExplorer, Source={x:Static settings:UserSettings.Default}, Mode=TwoWay}">
<ToggleButton.Style>
<Style TargetType="ToggleButton"
BasedOn="{StaticResource ModernToggleButtonStyle}">
<Setter Property="ToolTip"
Value="Preview Thumbnails (OFF)" />
<Style.Triggers>
<Trigger Property="IsChecked"
Value="True">
<Setter Property="Background"
Value="MediumPurple" />
<Setter Property="ToolTip"
Value="Preview Thumbnails (ON)" />
</Trigger>
</Style.Triggers>
</Style>
</ToggleButton.Style>
<Viewbox Width="16"
Height="16">
<Canvas Width="24"
Height="24">
<Path Data="{StaticResource TextureIconAlt}"
Fill="{DynamicResource {x:Static adonisUi:Brushes.ForegroundBrush}}" />
</Canvas>
</Viewbox>
</ToggleButton>
</StackPanel>
</Border>
<Expander Grid.Row="1" Margin="0 5 0 5" ExpandDirection="Down"
IsExpanded="{Binding IsLoggerExpanded, Source={x:Static settings:UserSettings.Default}}">
<Grid>

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
@@ -7,6 +8,7 @@ using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Threading;
using FModel.Extensions;
using FModel.Settings;
@@ -26,6 +28,9 @@ public sealed class AssetExplorerPreviewResolver : IDisposable
private int _startedAssetResolutionVersion;
private bool _resolvingAssets;
private bool _closing;
private ConcurrentQueue<GameFileViewModel> _previews = new();
private GameFileViewModel _hoveredPreview;
private int _resolvingPreviews;
public AssetExplorerPreviewResolver(ApplicationViewModel applicationView, ListBox grid, ListBox list, ListBox packages)
{
@@ -42,6 +47,8 @@ public sealed class AssetExplorerPreviewResolver : IDisposable
view.AddHandler(ScrollViewer.ScrollChangedEvent, new ScrollChangedEventHandler(OnScrollChanged));
}
grid.MouseMove += OnMouseMove;
list.MouseMove += OnMouseMove;
ScheduleAssetResolution();
}
@@ -63,6 +70,8 @@ public sealed class AssetExplorerPreviewResolver : IDisposable
view.RemoveHandler(ScrollViewer.ScrollChangedEvent, new ScrollChangedEventHandler(OnScrollChanged));
}
_views.Grid.MouseMove -= OnMouseMove;
_views.List.MouseMove -= OnMouseMove;
SnooperViewModel.Instance.CloseMeshPreviews();
}
@@ -119,12 +128,16 @@ public sealed class AssetExplorerPreviewResolver : IDisposable
{
var version = _startedAssetResolutionVersion = _assetResolutionVersion;
var explorer = Explorer;
var resolve = explorer.IsVisible && _settings.PreviewTexturesAssetExplorer ? EResolveCompute.All : EResolveCompute.Category;
var withPreviews = explorer.IsVisible && _settings.ExplorerPreviewMode is not EExplorerPreviewMode.None;
var visible = GetVisibleAssets(explorer, file => file.NeedsResolution(resolve))
.Select(file => (File: file, Resolve: resolve))
var previews = new ConcurrentQueue<GameFileViewModel>(withPreviews ? GetVisibleAssets(explorer, NeedsPreview) : []);
Volatile.Write(ref _previews, previews);
ResolvePreviews();
var visible = GetVisibleAssets(explorer, file => file.NeedsResolution(EResolveCompute.Category))
.Select(file => (File: file, Preview: withPreviews))
.Concat(GetVisibleAssets(_views.Packages, file => file.NeedsResolution(EResolveCompute.Category))
.Select(file => (File: file, Resolve: EResolveCompute.Category)))
.Select(file => (File: file, Preview: false)))
.DistinctBy(request => request.File)
.ToArray();
if (visible.Length == 0)
@@ -137,12 +150,17 @@ public sealed class AssetExplorerPreviewResolver : IDisposable
{
try
{
foreach (var (file, flags) in visible)
foreach (var (file, preview) in visible)
{
if (Volatile.Read(ref _assetResolutionVersion) != version)
break;
file.Resolve(flags, provider);
file.Resolve(EResolveCompute.Category, provider);
if (!preview || !NeedsPreview(file))
continue;
previews.Enqueue(file);
ResolvePreviews();
}
}
finally
@@ -175,9 +193,60 @@ public sealed class AssetExplorerPreviewResolver : IDisposable
}
}
private bool NeedsPreview(GameFileViewModel file) => !file.NeedsResolution(EResolveCompute.Category) && file.NeedsResolution(EResolveCompute.Preview) &&
!(file.RendersPreview && _settings.ExplorerPreviewMode is EExplorerPreviewMode.MeshesOnHover);
private bool HasPreviews => !Volatile.Read(ref _previews).IsEmpty || Volatile.Read(ref _hoveredPreview) != null;
private void ResolvePreviews()
{
if (!HasPreviews || Interlocked.Exchange(ref _resolvingPreviews, 1) != 0)
return;
_ = Task.Run(() =>
{
var provider = _applicationView.CUE4Parse?.Provider;
do
{
while (!_closing && TakePreview() is { } file)
{
file.Resolve(EResolveCompute.Preview, provider);
}
Volatile.Write(ref _resolvingPreviews, 0);
}
while (!_closing && HasPreviews && Interlocked.Exchange(ref _resolvingPreviews, 1) == 0);
});
}
private GameFileViewModel TakePreview()
{
if (Interlocked.Exchange(ref _hoveredPreview, null) is { } hovered && hovered.NeedsResolution(EResolveCompute.Preview))
return hovered;
while (Volatile.Read(ref _previews).TryDequeue(out var file))
{
if (file.NeedsResolution(EResolveCompute.Preview))
return file;
}
return null;
}
private void OnMouseMove(object sender, MouseEventArgs e)
{
if (_settings.ExplorerPreviewMode is not EExplorerPreviewMode.MeshesOnHover || sender is not ListBox list || e.OriginalSource is not DependencyObject element ||
ItemsControl.ContainerFromElement(list, element) is not ListBoxItem { DataContext: GameFileViewModel { RendersPreview: true } file } ||
file.NeedsResolution(EResolveCompute.Category) || !file.NeedsResolution(EResolveCompute.Preview))
return;
Volatile.Write(ref _hoveredPreview, file);
ResolvePreviews();
}
private void OnSettingsChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(UserSettings.PreviewTexturesAssetExplorer))
if (e.PropertyName == nameof(UserSettings.ExplorerPreviewMode))
ScheduleAssetResolution();
}

View File

@@ -691,11 +691,11 @@ public sealed class UserSettings : ViewModel
set => SetProperty(ref _featurePreviewNewAssetExplorer, value);
}
private bool _previewTexturesAssetExplorer = true;
public bool PreviewTexturesAssetExplorer
private EExplorerPreviewMode _explorerPreviewMode = EExplorerPreviewMode.All;
public EExplorerPreviewMode ExplorerPreviewMode
{
get => _previewTexturesAssetExplorer;
set => SetProperty(ref _previewTexturesAssetExplorer, value);
get => _explorerPreviewMode;
set => SetProperty(ref _explorerPreviewMode, value);
}
private EExplorerViewMode _explorerViewMode = EExplorerViewMode.Grid;

View File

@@ -161,6 +161,8 @@ public class GameFileViewModel(GameFile asset) : ViewModel
private set => SetProperty(ref _isRenderedPreview, value);
}
public bool RendersPreview => AssetCategory is EAssetCategory.Material or EAssetCategory.Nascar || AssetCategory.IsOfCategory(EAssetCategory.Mesh);
private int _numTextures = 0;
public int NumTextures
{
@@ -235,8 +237,7 @@ public class GameFileViewModel(GameFile asset) : ViewModel
if ((resolve & EResolveCompute.Category) != 0)
ResolveCategory((AbstractUePackage) pkg, pointer, export);
if (AssetCategory is not (EAssetCategory.Texture or EAssetCategory.AnimatedTexture or EAssetCategory.ItemDefinitionBase or EAssetCategory.Material or EAssetCategory.Nascar) &&
!AssetCategory.IsOfCategory(EAssetCategory.Mesh))
if (AssetCategory is not (EAssetCategory.Texture or EAssetCategory.AnimatedTexture or EAssetCategory.ItemDefinitionBase) && !RendersPreview)
{
Resolved |= EResolveCompute.Preview;
}

File diff suppressed because one or more lines are too long

View File

@@ -2173,125 +2173,6 @@
<Setter Property="SelectedFoldingMarkerBackgroundBrush" Value="#2A2B34" />
</Style>
<DropShadowEffect x:Key="ShadowEffect"
Color="Black"
BlurRadius="6"
ShadowDepth="0"
Opacity="0.3" />
<Style x:Key="ModernToggleButtonStyle"
TargetType="ToggleButton">
<Setter Property="Background"
Value="{DynamicResource {x:Static adonisUi:Brushes.Layer1BackgroundBrush}}" />
<Setter Property="BorderBrush"
Value="{DynamicResource {x:Static adonisUi:Brushes.Layer3BackgroundBrush}}" />
<Setter Property="BorderThickness"
Value="1" />
<Setter Property="Padding"
Value="4" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToggleButton">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="8"
Padding="{TemplateBinding Padding}">
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked"
Value="True">
<Setter Property="Background"
Value="{DynamicResource {x:Static adonisUi:Brushes.AccentBrush}}" />
</Trigger>
<Trigger Property="IsMouseOver"
Value="True">
<Setter Property="Background"
Value="{DynamicResource {x:Static adonisUi:Brushes.Layer3BackgroundBrush}}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="AssetsExplorerToggleButtonStyle"
TargetType="ToggleButton">
<Setter Property="Background"
Value="{DynamicResource {x:Static adonisUi:Brushes.Layer1BackgroundBrush}}" />
<Setter Property="BorderBrush"
Value="{DynamicResource {x:Static adonisUi:Brushes.Layer3BackgroundBrush}}" />
<Setter Property="BorderThickness"
Value="1" />
<Setter Property="Padding"
Value="4" />
<Setter Property="ToolTip">
<Setter.Value>
<ToolTip Content="{Binding SwitchAssetExplorer, Source={x:Static settings:UserSettings.Default}}"
ContentStringFormat="Assets Explorer ({0})" />
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToggleButton">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="8">
<Viewbox Width="18"
Height="18">
<Canvas Width="24"
Height="24">
<Path x:Name="IconPath"
Data="{StaticResource FolderIconAlt}"
Fill="{DynamicResource {x:Static adonisUi:Brushes.ForegroundBrush}}" />
</Canvas>
</Viewbox>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked"
Value="True">
<Setter TargetName="IconPath"
Property="Data"
Value="{StaticResource FolderIconAlt}" />
<Setter Property="Background"
Value="{DynamicResource {x:Static adonisUi:Brushes.AccentBrush}}" />
</Trigger>
<Trigger Property="IsChecked"
Value="False">
<Setter TargetName="IconPath"
Property="Data"
Value="{StaticResource AssetIcon}" />
<Setter Property="Background"
Value="{DynamicResource {x:Static adonisUi:Brushes.Layer1BackgroundBrush}}" />
</Trigger>
<Trigger Property="IsChecked"
Value="False">
<Setter TargetName="IconPath"
Property="Data"
Value="{StaticResource AssetIcon}" />
<Setter Property="Background"
Value="{DynamicResource {x:Static adonisUi:Brushes.Layer1BackgroundBrush}}" />
<Setter Property="ToolTip">
<Setter.Value>
<ToolTip Content="{Binding SwitchAssetExplorer, Source={x:Static settings:UserSettings.Default}}"
ContentStringFormat="File Properties ({0})" />
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsMouseOver"
Value="True">
<Setter Property="Background"
Value="{DynamicResource {x:Static adonisUi:Brushes.Layer3BackgroundBrush}}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!-- Just to keep border color during toggle -->
<Style x:Key="ExplorerViewToggleButton"
TargetType="{x:Type ToggleButton}"