mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
add mask when no backdrop
This commit is contained in:
@@ -28,13 +28,13 @@ internal sealed partial class BackgroundImageService : IBackgroundImageService
|
||||
|
||||
private HashSet<string> currentBackgroundPathSet;
|
||||
|
||||
public async ValueTask<ValueResult<bool, BackgroundImage>> GetNextBackgroundImageAsync(BackgroundImage? previous)
|
||||
public async ValueTask<ValueResult<bool, BackgroundImage?>> GetNextBackgroundImageAsync(BackgroundImage? previous)
|
||||
{
|
||||
HashSet<string> backgroundSet = await SkipOrInitBackgroundAsync().ConfigureAwait(false);
|
||||
|
||||
if (backgroundSet.Count <= 0)
|
||||
{
|
||||
return new(false, default!);
|
||||
return new(true, default!);
|
||||
}
|
||||
|
||||
string path = System.Random.Shared.GetItems([..backgroundSet], 1)[0];
|
||||
@@ -109,6 +109,9 @@ internal sealed partial class BackgroundImageService : IBackgroundImageService
|
||||
case BackgroundImageType.HutaoOfficialLauncher:
|
||||
await SetCurrentBackgroundPathSetAsync(client => client.GetLauncherWallpaperAsync()).ConfigureAwait(false);
|
||||
break;
|
||||
default:
|
||||
currentBackgroundPathSet = [];
|
||||
break;
|
||||
}
|
||||
|
||||
currentBackgroundPathSet ??= [];
|
||||
|
||||
@@ -5,5 +5,5 @@ namespace Snap.Hutao.Service.BackgroundImage;
|
||||
|
||||
internal interface IBackgroundImageService
|
||||
{
|
||||
ValueTask<ValueResult<bool, BackgroundImage>> GetNextBackgroundImageAsync(BackgroundImage? previous);
|
||||
ValueTask<ValueResult<bool, BackgroundImage?>> GetNextBackgroundImageAsync(BackgroundImage? previous);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Control;
|
||||
using Snap.Hutao.Core.Windowing;
|
||||
|
||||
namespace Snap.Hutao.View.Converter.Specialized;
|
||||
|
||||
internal sealed class BackdropTypeToOpacityConverter : ValueConverter<BackdropType, double>
|
||||
{
|
||||
public override double Convert(BackdropType from)
|
||||
{
|
||||
return from is BackdropType.None ? 1 : 0;
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@
|
||||
xmlns:shch="using:Snap.Hutao.Control.Helper"
|
||||
xmlns:shcm="using:Snap.Hutao.Control.Markup"
|
||||
xmlns:shv="using:Snap.Hutao.View"
|
||||
xmlns:shvcs="using:Snap.Hutao.View.Converter.Specialized"
|
||||
xmlns:shvh="using:Snap.Hutao.View.Helper"
|
||||
xmlns:shvm="using:Snap.Hutao.ViewModel"
|
||||
xmlns:shvp="using:Snap.Hutao.View.Page"
|
||||
@@ -27,9 +28,16 @@
|
||||
<Thickness x:Key="NavigationViewContentGridBorderThickness">0,1,0,0</Thickness>
|
||||
<x:Double x:Key="NavigationViewItemOnLeftIconBoxHeight">24</x:Double>
|
||||
<SolidColorBrush x:Key="NavigationViewExpandedPaneBackground" Color="Transparent"/>
|
||||
<shvcs:BackdropTypeToOpacityConverter x:Key="BackdropTypeToOpacityConverter"/>
|
||||
</UserControl.Resources>
|
||||
<!-- Background="{ThemeResource SolidBackgroundFillColorBaseBrush}" -->
|
||||
|
||||
<Grid Transitions="{ThemeResource EntranceThemeTransitions}">
|
||||
<Border Background="{ThemeResource SolidBackgroundFillColorBaseBrush}" Opacity="{Binding AppOptions.BackdropType, Converter={StaticResource BackdropTypeToOpacityConverter}, Mode=OneWay}">
|
||||
<Border.OpacityTransition>
|
||||
<ScalarTransition Duration="0:0:1"/>
|
||||
</Border.OpacityTransition>
|
||||
</Border>
|
||||
|
||||
<Image
|
||||
x:Name="BackgroundImagePresenter"
|
||||
HorizontalAlignment="Center"
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using CommunityToolkit.WinUI.Animations;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Media.Animation;
|
||||
using Snap.Hutao.Control.Animation;
|
||||
using Snap.Hutao.Control.Theme;
|
||||
using Snap.Hutao.Service.BackgroundImage;
|
||||
using Snap.Hutao.Service.Navigation;
|
||||
using Snap.Hutao.View.Page;
|
||||
using Snap.Hutao.ViewModel;
|
||||
|
||||
@@ -8,7 +8,9 @@ using Microsoft.UI.Xaml.Media.Animation;
|
||||
using Snap.Hutao.Control.Animation;
|
||||
using Snap.Hutao.Control.Theme;
|
||||
using Snap.Hutao.Message;
|
||||
using Snap.Hutao.Service;
|
||||
using Snap.Hutao.Service.BackgroundImage;
|
||||
using System.Globalization;
|
||||
|
||||
namespace Snap.Hutao.ViewModel;
|
||||
|
||||
@@ -17,11 +19,15 @@ namespace Snap.Hutao.ViewModel;
|
||||
internal sealed partial class MainViewModel : Abstraction.ViewModel, IMainViewModelInitialization, IRecipient<BackgroundImageTypeChangedMessage>
|
||||
{
|
||||
private readonly IBackgroundImageService backgroundImageService;
|
||||
private readonly ILogger<MainViewModel> logger;
|
||||
private readonly ITaskContext taskContext;
|
||||
private readonly AppOptions appOptions;
|
||||
|
||||
private BackgroundImage? previousBackgroundImage;
|
||||
private Image? backgroundImagePresenter;
|
||||
|
||||
public AppOptions AppOptions { get => appOptions; }
|
||||
|
||||
public void Initialize(IBackgroundImagePresenterAccessor accessor)
|
||||
{
|
||||
backgroundImagePresenter = accessor.BackgroundImagePresenter;
|
||||
@@ -40,9 +46,9 @@ internal sealed partial class MainViewModel : Abstraction.ViewModel, IMainViewMo
|
||||
return;
|
||||
}
|
||||
|
||||
(bool isOk, BackgroundImage backgroundImage) = await backgroundImageService.GetNextBackgroundImageAsync(previousBackgroundImage).ConfigureAwait(false);
|
||||
(bool shouldRefresh, BackgroundImage? backgroundImage) = await backgroundImageService.GetNextBackgroundImageAsync(previousBackgroundImage).ConfigureAwait(false);
|
||||
|
||||
if (isOk)
|
||||
if (shouldRefresh)
|
||||
{
|
||||
previousBackgroundImage = backgroundImage;
|
||||
await taskContext.SwitchToMainThreadAsync();
|
||||
@@ -57,8 +63,18 @@ internal sealed partial class MainViewModel : Abstraction.ViewModel, IMainViewMo
|
||||
.StartAsync(backgroundImagePresenter)
|
||||
.ConfigureAwait(true);
|
||||
|
||||
backgroundImagePresenter.Source = backgroundImage.ImageSource;
|
||||
double targetOpacity = ThemeHelper.IsDarkMode(backgroundImagePresenter.ActualTheme) ? 1 - backgroundImage.Luminance : backgroundImage.Luminance;
|
||||
backgroundImagePresenter.Source = backgroundImage?.ImageSource;
|
||||
double targetOpacity = backgroundImage is not null
|
||||
? ThemeHelper.IsDarkMode(backgroundImagePresenter.ActualTheme)
|
||||
? 1 - backgroundImage.Luminance
|
||||
: backgroundImage.Luminance
|
||||
: 0;
|
||||
|
||||
logger.LogInformation(
|
||||
"Background image: [Accent color: {AccentColor}] [Luminance: {Luminance}] [Opacity: {TargetOpacity}]",
|
||||
backgroundImage?.AccentColor.ToString(CultureInfo.CurrentCulture),
|
||||
backgroundImage?.Luminance,
|
||||
targetOpacity);
|
||||
|
||||
await AnimationBuilder
|
||||
.Create()
|
||||
|
||||
Reference in New Issue
Block a user