From 91fea886231ec7933f3663ed25c1fe661925b64a Mon Sep 17 00:00:00 2001 From: DismissedLight <1686188646@qq.com> Date: Thu, 19 Oct 2023 22:32:01 +0800 Subject: [PATCH] launch page redo --- .../Control/Behavior/AutoHeightBehavior.cs | 48 ------ .../Control/Behavior/AutoWidthBehavior.cs | 48 ------ .../RuntimeEnvironmentException.cs | 2 +- .../CurrentWindowReferenceExtension.cs | 14 ++ .../Core/LifeCycle/ICurrentWindowReference.cs | 2 +- .../Factory/ContentDialogFactory.cs | 10 +- .../Resource/Localization/SH.Designer.cs | 45 ++++++ .../Snap.Hutao/Resource/Localization/SH.resx | 15 ++ .../Snap.Hutao/Service/Game/LaunchOptions.cs | 40 ++--- .../Snap.Hutao/View/Page/LaunchGamePage.xaml | 140 ++++++++---------- .../Snap.Hutao/View/Page/WikiWeaponPage.xaml | 77 +++++----- 11 files changed, 196 insertions(+), 245 deletions(-) delete mode 100644 src/Snap.Hutao/Snap.Hutao/Control/Behavior/AutoHeightBehavior.cs delete mode 100644 src/Snap.Hutao/Snap.Hutao/Control/Behavior/AutoWidthBehavior.cs create mode 100644 src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/CurrentWindowReferenceExtension.cs diff --git a/src/Snap.Hutao/Snap.Hutao/Control/Behavior/AutoHeightBehavior.cs b/src/Snap.Hutao/Snap.Hutao/Control/Behavior/AutoHeightBehavior.cs deleted file mode 100644 index a5bc4497..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Control/Behavior/AutoHeightBehavior.cs +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -using CommunityToolkit.WinUI.Behaviors; -using Microsoft.UI.Xaml; - -namespace Snap.Hutao.Control.Behavior; - -/// -/// 按给定比例自动调整高度的行为 -/// -[HighQuality] -[DependencyProperty("TargetWidth", typeof(double), 1.0D)] -[DependencyProperty("TargetHeight", typeof(double), 1.0D)] -internal sealed partial class AutoHeightBehavior : BehaviorBase -{ - private readonly SizeChangedEventHandler sizeChangedEventHandler; - - public AutoHeightBehavior() - { - sizeChangedEventHandler = OnSizeChanged; - } - - /// - protected override bool Initialize() - { - UpdateElement(); - AssociatedObject.SizeChanged += sizeChangedEventHandler; - return true; - } - - /// - protected override bool Uninitialize() - { - AssociatedObject.SizeChanged -= sizeChangedEventHandler; - return true; - } - - private void OnSizeChanged(object sender, SizeChangedEventArgs e) - { - UpdateElement(); - } - - private void UpdateElement() - { - AssociatedObject.Height = AssociatedObject.ActualWidth * (TargetHeight / TargetWidth); - } -} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Control/Behavior/AutoWidthBehavior.cs b/src/Snap.Hutao/Snap.Hutao/Control/Behavior/AutoWidthBehavior.cs deleted file mode 100644 index 4829479a..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Control/Behavior/AutoWidthBehavior.cs +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -using CommunityToolkit.WinUI.Behaviors; -using Microsoft.UI.Xaml; - -namespace Snap.Hutao.Control.Behavior; - -/// -/// 按给定比例自动调整高度的行为 -/// -[HighQuality] -[DependencyProperty("TargetWidth", typeof(double), 1.0D)] -[DependencyProperty("TargetHeight", typeof(double), 1.0D)] -internal sealed partial class AutoWidthBehavior : BehaviorBase -{ - private readonly SizeChangedEventHandler sizeChangedEventHandler; - - public AutoWidthBehavior() - { - sizeChangedEventHandler = OnSizeChanged; - } - - /// - protected override bool Initialize() - { - UpdateElement(); - AssociatedObject.SizeChanged += sizeChangedEventHandler; - return true; - } - - /// - protected override bool Uninitialize() - { - AssociatedObject.SizeChanged -= sizeChangedEventHandler; - return true; - } - - private void OnSizeChanged(object sender, SizeChangedEventArgs e) - { - UpdateElement(); - } - - private void UpdateElement() - { - AssociatedObject.Width = AssociatedObject.Height * (TargetWidth / TargetHeight); - } -} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Core/ExceptionService/RuntimeEnvironmentException.cs b/src/Snap.Hutao/Snap.Hutao/Core/ExceptionService/RuntimeEnvironmentException.cs index 14f65023..b96e87b3 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/ExceptionService/RuntimeEnvironmentException.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/ExceptionService/RuntimeEnvironmentException.cs @@ -16,7 +16,7 @@ internal sealed class RuntimeEnvironmentException : Exception /// 消息 /// 内部错误 public RuntimeEnvironmentException(string message, Exception? innerException) - : base($"{message}\n{innerException.Message}", innerException) + : base($"{message}\n{innerException?.Message}", innerException) { } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/CurrentWindowReferenceExtension.cs b/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/CurrentWindowReferenceExtension.cs new file mode 100644 index 00000000..b2db3d7e --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/CurrentWindowReferenceExtension.cs @@ -0,0 +1,14 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +using Microsoft.UI.Xaml; + +namespace Snap.Hutao.Core.LifeCycle; + +internal static class CurrentWindowReferenceExtension +{ + public static XamlRoot GetXamlRoot(this ICurrentWindowReference reference) + { + return reference.Window.Content.XamlRoot; + } +} diff --git a/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/ICurrentWindowReference.cs b/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/ICurrentWindowReference.cs index 0999b288..72a79f6d 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/ICurrentWindowReference.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/LifeCycle/ICurrentWindowReference.cs @@ -8,4 +8,4 @@ namespace Snap.Hutao.Core.LifeCycle; internal interface ICurrentWindowReference { public Window Window { get; set; } -} +} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Factory/ContentDialogFactory.cs b/src/Snap.Hutao/Snap.Hutao/Factory/ContentDialogFactory.cs index ad934866..d71f0964 100644 --- a/src/Snap.Hutao/Snap.Hutao/Factory/ContentDialogFactory.cs +++ b/src/Snap.Hutao/Snap.Hutao/Factory/ContentDialogFactory.cs @@ -23,7 +23,7 @@ internal sealed partial class ContentDialogFactory : IContentDialogFactory await taskContext.SwitchToMainThreadAsync(); ContentDialog dialog = new() { - XamlRoot = currentWindowReference.Window.Content.XamlRoot, + XamlRoot = currentWindowReference.GetXamlRoot(), Title = title, Content = content, DefaultButton = ContentDialogButton.Primary, @@ -39,7 +39,7 @@ internal sealed partial class ContentDialogFactory : IContentDialogFactory await taskContext.SwitchToMainThreadAsync(); ContentDialog dialog = new() { - XamlRoot = currentWindowReference.Window.Content.XamlRoot, + XamlRoot = currentWindowReference.GetXamlRoot(), Title = title, Content = content, DefaultButton = defaultButton, @@ -56,7 +56,7 @@ internal sealed partial class ContentDialogFactory : IContentDialogFactory await taskContext.SwitchToMainThreadAsync(); ContentDialog dialog = new() { - XamlRoot = currentWindowReference.Window.Content.XamlRoot, + XamlRoot = currentWindowReference.GetXamlRoot(), Title = title, Content = new ProgressBar() { IsIndeterminate = true }, }; @@ -69,7 +69,7 @@ internal sealed partial class ContentDialogFactory : IContentDialogFactory { await taskContext.SwitchToMainThreadAsync(); TContentDialog contentDialog = serviceProvider.CreateInstance(parameters); - contentDialog.XamlRoot = currentWindowReference.Window.Content.XamlRoot; + contentDialog.XamlRoot = currentWindowReference.GetXamlRoot(); return contentDialog; } @@ -77,7 +77,7 @@ internal sealed partial class ContentDialogFactory : IContentDialogFactory where TContentDialog : ContentDialog { TContentDialog contentDialog = serviceProvider.CreateInstance(parameters); - contentDialog.XamlRoot = currentWindowReference.Window.Content.XamlRoot; + contentDialog.XamlRoot = currentWindowReference.GetXamlRoot(); return contentDialog; } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.Designer.cs b/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.Designer.cs index 10a70e1b..dcd4766d 100644 --- a/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.Designer.cs +++ b/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.Designer.cs @@ -5190,6 +5190,24 @@ namespace Snap.Hutao.Resource.Localization { } } + /// + /// 查找类似 在游戏启动时修改其默认行为 的本地化字符串。 + /// + internal static string ViewPageLaunchGameArgumentsDescription { + get { + return ResourceManager.GetString("ViewPageLaunchGameArgumentsDescription", resourceCulture); + } + } + + /// + /// 查找类似 启动参数 的本地化字符串。 + /// + internal static string ViewPageLaunchGameArgumentsHeader { + get { + return ResourceManager.GetString("ViewPageLaunchGameArgumentsHeader", resourceCulture); + } + } + /// /// 查找类似 常规 的本地化字符串。 /// @@ -5208,6 +5226,15 @@ namespace Snap.Hutao.Resource.Localization { } } + /// + /// 查找类似 文件 的本地化字符串。 + /// + internal static string ViewPageLaunchGameFileHeader { + get { + return ResourceManager.GetString("ViewPageLaunchGameFileHeader", resourceCulture); + } + } + /// /// 查找类似 在指定的显示器上运行 的本地化字符串。 /// @@ -5253,6 +5280,24 @@ namespace Snap.Hutao.Resource.Localization { } } + /// + /// 查找类似 进程 的本地化字符串。 + /// + internal static string ViewPageLaunchGameProcessHeader { + get { + return ResourceManager.GetString("ViewPageLaunchGameProcessHeader", resourceCulture); + } + } + + /// + /// 查找类似 注册表 的本地化字符串。 + /// + internal static string ViewPageLaunchGameRegistryHeader { + get { + return ResourceManager.GetString("ViewPageLaunchGameRegistryHeader", resourceCulture); + } + } + /// /// 查找类似 增量包 的本地化字符串。 /// diff --git a/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.resx b/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.resx index 4537ef07..52f3b2ef 100644 --- a/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.resx +++ b/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.resx @@ -1883,12 +1883,21 @@ 宽度 + + 在游戏启动时修改其默认行为 + + + 启动参数 + 常规 所有选项仅会在启动游戏成功后保存 + + 文件 + 在指定的显示器上运行 @@ -1904,6 +1913,12 @@ 游戏选项 + + 进程 + + + 注册表 + 增量包 diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Game/LaunchOptions.cs b/src/Snap.Hutao/Snap.Hutao/Service/Game/LaunchOptions.cs index 9e9ac01e..71fe1fcd 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Game/LaunchOptions.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Game/LaunchOptions.cs @@ -53,13 +53,7 @@ internal sealed class LaunchOptions : DbStoreOptions public bool IsFullScreen { get => GetOption(ref isFullScreen, SettingEntry.LaunchIsFullScreen); - set - { - if (SetOption(ref isFullScreen, SettingEntry.LaunchIsFullScreen, value) && value) - { - IsBorderless = false; - } - } + set => SetOption(ref isFullScreen, SettingEntry.LaunchIsFullScreen, value); } /// @@ -68,14 +62,7 @@ internal sealed class LaunchOptions : DbStoreOptions public bool IsBorderless { get => GetOption(ref isBorderless, SettingEntry.LaunchIsBorderless); - set - { - if (SetOption(ref isBorderless, SettingEntry.LaunchIsBorderless, value) && value) - { - IsExclusive = false; - IsFullScreen = false; - } - } + set => SetOption(ref isBorderless, SettingEntry.LaunchIsBorderless, value); } /// @@ -84,13 +71,7 @@ internal sealed class LaunchOptions : DbStoreOptions public bool IsExclusive { get => GetOption(ref isExclusive, SettingEntry.LaunchIsExclusive); - set - { - if (SetOption(ref isExclusive, SettingEntry.LaunchIsExclusive, value) && value) - { - IsFullScreen = true; - } - } + set => SetOption(ref isExclusive, SettingEntry.LaunchIsExclusive, value); } /// @@ -153,7 +134,7 @@ internal sealed class LaunchOptions : DbStoreOptions private static void InitializeMonitors(List> monitors) { // This list can't use foreach - // https://github.com/microsoft/microsoft-ui-xaml/issues/6454 + // https://github.com/microsoft/CsWinRT/issues/747 IReadOnlyList displayAreas = DisplayArea.FindAll(); for (int i = 0; i < displayAreas.Count; i++) { @@ -165,12 +146,15 @@ internal sealed class LaunchOptions : DbStoreOptions private static void InitializeScreenFps(out int fps) { - HDC hDC = GetDC(HWND.Null); - fps = GetDeviceCaps(hDC, GET_DEVICE_CAPS_INDEX.VREFRESH); - if (ReleaseDC(HWND.Null, hDC) == 0) + HDC hDC = default; + try { - // not released - throw new Win32Exception(); + hDC = GetDC(HWND.Null); + fps = GetDeviceCaps(hDC, GET_DEVICE_CAPS_INDEX.VREFRESH); + } + finally + { + _ = ReleaseDC(HWND.Null, hDC); } } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/View/Page/LaunchGamePage.xaml b/src/Snap.Hutao/Snap.Hutao/View/Page/LaunchGamePage.xaml index c0917667..74de57d6 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Page/LaunchGamePage.xaml +++ b/src/Snap.Hutao/Snap.Hutao/View/Page/LaunchGamePage.xaml @@ -68,7 +68,8 @@ IsOpen="True" Message="{shcm:ResourceString Name=ViewPageLaunchGameConfigurationSaveHint}" Severity="Informational"/> - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - + Width="156" + Padding="10,6,0,0" + Value="{Binding Options.ScreenWidth, Mode=TwoWay}"/> + + + + + + + + + + + + + + + + + + + diff --git a/src/Snap.Hutao/Snap.Hutao/View/Page/WikiWeaponPage.xaml b/src/Snap.Hutao/Snap.Hutao/View/Page/WikiWeaponPage.xaml index 10410981..b02bcd8c 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Page/WikiWeaponPage.xaml +++ b/src/Snap.Hutao/Snap.Hutao/View/Page/WikiWeaponPage.xaml @@ -126,49 +126,48 @@ - - - - - - - - - - - - - - - - - - - - - - + + - - + + - + + + + + + + + + + + + + + + + + + + + + Margin="16" + HorizontalAlignment="Right" + VerticalAlignment="Bottom" + Style="{StaticResource SubtitleTextBlockStyle}" + Text="{Binding Selected.Name}"/> - - +