completing

This commit is contained in:
DismissedLight
2024-07-25 10:44:01 +08:00
parent fc2d590c42
commit 1c261b7866
7 changed files with 134 additions and 68 deletions

View File

@@ -0,0 +1,6 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Core;
internal readonly struct Void;

View File

@@ -2441,6 +2441,18 @@
<data name="ViewPageLaunchGameConfigurationSaveHint" xml:space="preserve"> <data name="ViewPageLaunchGameConfigurationSaveHint" xml:space="preserve">
<value>所有选项仅会在启动游戏成功后保存</value> <value>所有选项仅会在启动游戏成功后保存</value>
</data> </data>
<data name="ViewPageLaunchGameDisableFogDescription" xml:space="preserve">
<value>移除光照渲染中的迷雾</value>
</data>
<data name="ViewPageLaunchGameDisableFogHeader" xml:space="preserve">
<value>移除迷雾</value>
</data>
<data name="ViewPageLaunchGameDisableFogOff" xml:space="preserve">
<value>保留</value>
</data>
<data name="ViewPageLaunchGameDisableFogOn" xml:space="preserve">
<value>移除</value>
</data>
<data name="ViewPageLaunchGameDiscordActivityDescription" xml:space="preserve"> <data name="ViewPageLaunchGameDiscordActivityDescription" xml:space="preserve">
<value>在我游戏时设置 Discord Activity 状态</value> <value>在我游戏时设置 Discord Activity 状态</value>
</data> </data>
@@ -2525,8 +2537,14 @@
<data name="ViewPageLaunchGameSwitchSchemeWarning" xml:space="preserve"> <data name="ViewPageLaunchGameSwitchSchemeWarning" xml:space="preserve">
<value>版本更新前需要提前转换至与启动器匹配的服务器</value> <value>版本更新前需要提前转换至与启动器匹配的服务器</value>
</data> </data>
<data name="ViewPageLaunchGameTargetFovDescription" xml:space="preserve">
<value>调整相机视野,默认 45</value>
</data>
<data name="ViewPageLaunchGameTargetFovHeader" xml:space="preserve">
<value>调整视野</value>
</data>
<data name="ViewPageLaunchGameUnlockFpsDescription" xml:space="preserve"> <data name="ViewPageLaunchGameUnlockFpsDescription" xml:space="preserve">
<value>请在游戏内关闭「垂直同步」选项,需要高性能的显卡以支持更高的帧率</value> <value>请在游戏内关闭「垂直同步」选项,需要高性能的显卡以支持更高的帧率,将值设置为 -1 以表示无限制帧率</value>
</data> </data>
<data name="ViewPageLaunchGameUnlockFpsHeader" xml:space="preserve"> <data name="ViewPageLaunchGameUnlockFpsHeader" xml:space="preserve">
<value>解锁帧率限制</value> <value>解锁帧率限制</value>

View File

@@ -32,7 +32,7 @@ internal abstract partial class DbStoreOptions : ObservableObject
return input.ToStringOrEmpty(); return input.ToStringOrEmpty();
} }
protected void InitializeOptions(string keyLike, Expression<Func<SettingEntry, bool>> entrySelector, Action<string, string?> entryAction) protected void InitializeOptions(Expression<Func<SettingEntry, bool>> entrySelector, Action<string, string?> entryAction)
{ {
using (IServiceScope scope = serviceProvider.CreateScope()) using (IServiceScope scope = serviceProvider.CreateScope())
{ {

View File

@@ -60,6 +60,63 @@ internal sealed class LaunchOptions : DbStoreOptions
InitializeMonitors(Monitors); InitializeMonitors(Monitors);
InitializeScreenFps(out primaryScreenFps); InitializeScreenFps(out primaryScreenFps);
// Batch initialization, boost up performance
InitializeOptions(entry => entry.Key.StartsWith("Launch."), (key, value) =>
{
_ = key switch
{
SettingEntry.LaunchIsLaunchOptionsEnabled => InitializeBooleanValue(ref isEnabled, value),
SettingEntry.LaunchIsFullScreen => InitializeBooleanValue(ref isFullScreen, value),
SettingEntry.LaunchIsBorderless => InitializeBooleanValue(ref isBorderless, value),
SettingEntry.LaunchIsExclusive => InitializeBooleanValue(ref isExclusive, value),
SettingEntry.LaunchScreenWidth => InitializeInt32Value(ref screenWidth, value),
SettingEntry.LaunchIsScreenWidthEnabled => InitializeBooleanValue(ref isScreenWidthEnabled, value),
SettingEntry.LaunchScreenHeight => InitializeInt32Value(ref screenHeight, value),
SettingEntry.LaunchIsScreenHeightEnabled => InitializeBooleanValue(ref isScreenHeightEnabled, value),
SettingEntry.LaunchUnlockFps => InitializeBooleanValue(ref unlockFps, value),
SettingEntry.LaunchTargetFps => InitializeInt32Value(ref targetFps, value),
SettingEntry.LaunchTargetFov => InitializeFloatValue(ref targetFov, value),
SettingEntry.LaunchDisableFog => InitializeBooleanValue(ref disableFog, value),
SettingEntry.LaunchIsMonitorEnabled => InitializeBooleanValue(ref isMonitorEnabled, value),
SettingEntry.LaunchIsUseCloudThirdPartyMobile => InitializeBooleanValue(ref isUseCloudThirdPartyMobile, value),
SettingEntry.LaunchIsWindowsHDREnabled => InitializeBooleanValue(ref isWindowsHDREnabled, value),
SettingEntry.LaunchUseStarwardPlayTimeStatistics => InitializeBooleanValue(ref useStarwardPlayTimeStatistics, value),
SettingEntry.LaunchUseBetterGenshinImpactAutomation => InitializeBooleanValue(ref useBetterGenshinImpactAutomation, value),
SettingEntry.LaunchSetDiscordActivityWhenPlaying => InitializeBooleanValue(ref setDiscordActivityWhenPlaying, value),
_ => default,
};
});
static Core.Void InitializeBooleanValue(ref bool? storage, string? value)
{
if (value is not null)
{
storage = bool.Parse(value);
}
return default;
}
static Core.Void InitializeInt32Value(ref int? storage, string? value)
{
if (value is not null)
{
storage = int.Parse(value, CultureInfo.InvariantCulture);
}
return default;
}
static Core.Void InitializeFloatValue(ref float? storage, string? value)
{
if (value is not null)
{
storage = float.Parse(value, CultureInfo.InvariantCulture);
}
return default;
}
static void InitializeMonitors(List<NameValue<int>> monitors) static void InitializeMonitors(List<NameValue<int>> monitors)
{ {
try try
@@ -109,21 +166,22 @@ internal sealed class LaunchOptions : DbStoreOptions
set => SetOption(ref gamePathEntries, SettingEntry.GamePathEntries, value, value => JsonSerializer.Serialize(value)); set => SetOption(ref gamePathEntries, SettingEntry.GamePathEntries, value, value => JsonSerializer.Serialize(value));
} }
public bool IsEnabled
{
get => GetOption(ref isEnabled, SettingEntry.LaunchIsLaunchOptionsEnabled, false);
set => SetOption(ref isEnabled, SettingEntry.LaunchIsLaunchOptionsEnabled, value);
}
public bool IsAdvancedLaunchOptionsEnabled public bool IsAdvancedLaunchOptionsEnabled
{ {
get => GetOption(ref isAdvancedLaunchOptionsEnabled, SettingEntry.IsAdvancedLaunchOptionsEnabled); get => GetOption(ref isAdvancedLaunchOptionsEnabled, SettingEntry.IsAdvancedLaunchOptionsEnabled);
set => SetOption(ref isAdvancedLaunchOptionsEnabled, SettingEntry.IsAdvancedLaunchOptionsEnabled, value); set => SetOption(ref isAdvancedLaunchOptionsEnabled, SettingEntry.IsAdvancedLaunchOptionsEnabled, value);
} }
#region Launch Prefixed Options
public bool IsEnabled
{
get => GetOption(ref isEnabled, SettingEntry.LaunchIsLaunchOptionsEnabled, true);
set => SetOption(ref isEnabled, SettingEntry.LaunchIsLaunchOptionsEnabled, value);
}
public bool IsFullScreen public bool IsFullScreen
{ {
get => GetOption(ref isFullScreen, SettingEntry.LaunchIsFullScreen); get => GetOption(ref isFullScreen, SettingEntry.LaunchIsFullScreen, false);
set => SetOption(ref isFullScreen, SettingEntry.LaunchIsFullScreen, value); set => SetOption(ref isFullScreen, SettingEntry.LaunchIsFullScreen, value);
} }
@@ -187,10 +245,7 @@ internal sealed class LaunchOptions : DbStoreOptions
set => SetOption(ref disableFog, SettingEntry.LaunchDisableFog, value); set => SetOption(ref disableFog, SettingEntry.LaunchDisableFog, value);
} }
public List<NameValue<int>> Monitors { get; } = []; public NameValue<int>? Monitor
[AllowNull]
public NameValue<int> Monitor
{ {
get get
{ {
@@ -229,6 +284,27 @@ internal sealed class LaunchOptions : DbStoreOptions
set => SetOption(ref isWindowsHDREnabled, SettingEntry.LaunchIsWindowsHDREnabled, value); set => SetOption(ref isWindowsHDREnabled, SettingEntry.LaunchIsWindowsHDREnabled, value);
} }
public bool UseStarwardPlayTimeStatistics
{
get => GetOption(ref useStarwardPlayTimeStatistics, SettingEntry.LaunchUseStarwardPlayTimeStatistics, false);
set => SetOption(ref useStarwardPlayTimeStatistics, SettingEntry.LaunchUseStarwardPlayTimeStatistics, value);
}
public bool UseBetterGenshinImpactAutomation
{
get => GetOption(ref useBetterGenshinImpactAutomation, SettingEntry.LaunchUseBetterGenshinImpactAutomation, false);
set => SetOption(ref useBetterGenshinImpactAutomation, SettingEntry.LaunchUseBetterGenshinImpactAutomation, value);
}
public bool SetDiscordActivityWhenPlaying
{
get => GetOption(ref setDiscordActivityWhenPlaying, SettingEntry.LaunchSetDiscordActivityWhenPlaying, true);
set => SetOption(ref setDiscordActivityWhenPlaying, SettingEntry.LaunchSetDiscordActivityWhenPlaying, value);
}
#endregion
public List<NameValue<int>> Monitors { get; } = [];
public List<AspectRatio> AspectRatios { get; } = public List<AspectRatio> AspectRatios { get; } =
[ [
new(3840, 2160), new(3840, 2160),
@@ -249,22 +325,4 @@ internal sealed class LaunchOptions : DbStoreOptions
} }
} }
} }
public bool UseStarwardPlayTimeStatistics
{
get => GetOption(ref useStarwardPlayTimeStatistics, SettingEntry.LaunchUseStarwardPlayTimeStatistics, false);
set => SetOption(ref useStarwardPlayTimeStatistics, SettingEntry.LaunchUseStarwardPlayTimeStatistics, value);
}
public bool UseBetterGenshinImpactAutomation
{
get => GetOption(ref useBetterGenshinImpactAutomation, SettingEntry.LaunchUseBetterGenshinImpactAutomation, false);
set => SetOption(ref useBetterGenshinImpactAutomation, SettingEntry.LaunchUseBetterGenshinImpactAutomation, value);
}
public bool SetDiscordActivityWhenPlaying
{
get => GetOption(ref setDiscordActivityWhenPlaying, SettingEntry.LaunchSetDiscordActivityWhenPlaying, true);
set => SetOption(ref setDiscordActivityWhenPlaying, SettingEntry.LaunchSetDiscordActivityWhenPlaying, value);
}
} }

View File

@@ -16,7 +16,7 @@ internal sealed class Int32ToVisibilityConverter : IValueConverter
/// <inheritdoc/> /// <inheritdoc/>
public object Convert(object value, Type targetType, object parameter, string language) public object Convert(object value, Type targetType, object parameter, string language)
{ {
return value is not 0 ? Visibility.Visible : Visibility.Collapsed; return value is not null && value is not 0 ? Visibility.Visible : Visibility.Collapsed;
} }
/// <inheritdoc/> /// <inheritdoc/>

View File

@@ -357,7 +357,7 @@
MinWidth="{ThemeResource SettingsCardContentControlMinWidth2}" MinWidth="{ThemeResource SettingsCardContentControlMinWidth2}"
Padding="10,8,0,0" Padding="10,8,0,0"
Maximum="720" Maximum="720"
Minimum="60" Minimum="-1"
SpinButtonPlacementMode="Inline" SpinButtonPlacementMode="Inline"
Value="{Binding LaunchOptions.TargetFps, Mode=TwoWay}"/> Value="{Binding LaunchOptions.TargetFps, Mode=TwoWay}"/>
<ToggleSwitch <ToggleSwitch
@@ -367,23 +367,22 @@
OnContent="{shuxm:ResourceString Name=ViewPageLaunchGameUnlockFpsOn}"/> OnContent="{shuxm:ResourceString Name=ViewPageLaunchGameUnlockFpsOn}"/>
</StackPanel> </StackPanel>
<cwc:SettingsExpander.Items> <cwc:SettingsExpander.Items>
<cwc:SettingsCard Description="{shuxm:ResourceString Name=ViewPageLaunchGameUnlockFpsKindDescription}" Header="{shuxm:ResourceString Name=ViewPageLaunchGameUnlockFpsKindHeader}"> <cwc:SettingsCard Description="{shuxm:ResourceString Name=ViewPageLaunchGameTargetFovDescription}" Header="{shuxm:ResourceString Name=ViewPageLaunchGameTargetFovHeader}">
<StackPanel VerticalAlignment="Center" Spacing="3"> <NumberBox
<TextBlock MinWidth="{ThemeResource SettingsCardContentControlMinWidth2}"
HorizontalAlignment="Right" Padding="10,8,0,0"
Foreground="{ThemeResource SystemControlErrorTextForegroundBrush}" Maximum="55"
Opacity="0.8" Minimum="45"
Style="{StaticResource CaptionTextBlockStyle}" SmallChange="1"
Text="{Binding LaunchOptions.UnlockerKind.Description, Mode=OneWay}"/> SpinButtonPlacementMode="Inline"
<shuxc:SizeRestrictedContentControl HorizontalAlignment="Right"> Value="{Binding LaunchOptions.TargetFov, Mode=TwoWay}"/>
<ComboBox </cwc:SettingsCard>
DisplayMemberPath="Name" <cwc:SettingsCard Description="{shuxm:ResourceString Name=ViewPageLaunchGameDisableFogDescription}" Header="{shuxm:ResourceString Name=ViewPageLaunchGameDisableFogHeader}">
ItemsSource="{Binding LaunchOptions.UnlockerKinds, Mode=OneWay}" <ToggleSwitch
SelectedItem="{Binding LaunchOptions.UnlockerKind, Mode=TwoWay}"/> MinWidth="{ThemeResource SettingsCardContentControlMinWidth}"
</shuxc:SizeRestrictedContentControl> IsOn="{Binding LaunchOptions.DisableFog, Mode=TwoWay}"
OffContent="{shuxm:ResourceString Name=ViewPageLaunchGameDisableFogOff}"
</StackPanel> OnContent="{shuxm:ResourceString Name=ViewPageLaunchGameDisableFogOn}"/>
</cwc:SettingsCard> </cwc:SettingsCard>
</cwc:SettingsExpander.Items> </cwc:SettingsExpander.Items>
</cwc:SettingsExpander> </cwc:SettingsExpander>

View File

@@ -189,32 +189,17 @@ internal static partial class HutaoEndpoints
public static string StaticRaw(string category, string fileName) public static string StaticRaw(string category, string fileName)
{ {
return Kind switch return $"{ApiSnapGenshin}/static/raw/{category}/{fileName}";
{
ApiKind.AlphaCN => $"{ApiAlphaSnapGenshin}/cn/static/raw/{category}/{fileName}",
ApiKind.AlphaOS => $"{ApiAlphaSnapGenshin}/global/static/raw/{category}/{fileName}",
_ => $"{ApiSnapGenshin}/static/raw/{category}/{fileName}",
};
} }
public static string StaticZip(string fileName) public static string StaticZip(string fileName)
{ {
return Kind switch return $"{ApiSnapGenshin}/static/zip/{fileName}.zip";
{
ApiKind.AlphaCN => $"{ApiAlphaSnapGenshin}/cn/static/zip/{fileName}.zip",
ApiKind.AlphaOS => $"{ApiAlphaSnapGenshin}/global/static/zip/{fileName}.zip",
_ => $"{ApiSnapGenshin}/static/zip/{fileName}.zip",
};
} }
public static string StaticSize() public static string StaticSize()
{ {
return Kind switch return $"{ApiSnapGenshin}/static/size";
{
ApiKind.AlphaCN => $"{ApiAlphaSnapGenshin}/cn/static/size",
ApiKind.AlphaOS => $"{ApiAlphaSnapGenshin}/global/static/size",
_ => $"{ApiSnapGenshin}/static/size",
};
} }
#endregion #endregion