mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
use NameValue
This commit is contained in:
@@ -74,11 +74,11 @@ internal sealed partial class AppOptions : DbStoreOptions
|
||||
set => SetOption(ref currentCulture, SettingEntry.Culture, value, value => value.Name);
|
||||
}
|
||||
|
||||
public List<Region> Regions { get; } = KnownRegions.Get();
|
||||
public List<NameValue<Region>> Regions { get; } = KnownRegions.Get();
|
||||
|
||||
public Region Region
|
||||
{
|
||||
get => GetOption(ref region, SettingEntry.Region, v => Region.FromRegion(v), Regions[0]).Value;
|
||||
get => GetOption(ref region, SettingEntry.Region, v => Region.FromRegion(v), Regions[0].Value).Value;
|
||||
set => SetOption(ref region, SettingEntry.Region, value, value => value.ToStringOrEmpty());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Model;
|
||||
using Snap.Hutao.Web.Hoyolab;
|
||||
|
||||
namespace Snap.Hutao.Service;
|
||||
@@ -14,16 +15,21 @@ internal static class KnownRegions
|
||||
private static readonly Region RegionOSASIA = new("os_asia");
|
||||
private static readonly Region RegionOSCHT = new("os_cht");
|
||||
|
||||
public static List<Region> Get()
|
||||
public static List<NameValue<Region>> Get()
|
||||
{
|
||||
return
|
||||
[
|
||||
RegionCNGF01,
|
||||
RegionCNQD01,
|
||||
RegionOSUSA,
|
||||
RegionOSEURO,
|
||||
RegionOSASIA,
|
||||
RegionOSCHT,
|
||||
ToNameValue(RegionCNGF01),
|
||||
ToNameValue(RegionCNQD01),
|
||||
ToNameValue(RegionOSUSA),
|
||||
ToNameValue(RegionOSEURO),
|
||||
ToNameValue(RegionOSASIA),
|
||||
ToNameValue(RegionOSCHT),
|
||||
];
|
||||
}
|
||||
|
||||
private static NameValue<Region> ToNameValue(in Region region)
|
||||
{
|
||||
return new(region.DisplayName, region);
|
||||
}
|
||||
}
|
||||
@@ -311,7 +311,7 @@
|
||||
HeaderIcon="{shcm:FontIcon Glyph=}">
|
||||
<shc:SizeRestrictedContentControl>
|
||||
<ComboBox
|
||||
DisplayMemberPath="DisplayName"
|
||||
DisplayMemberPath="Name"
|
||||
ItemsSource="{Binding AppOptions.Regions}"
|
||||
SelectedItem="{Binding SelectedRegion, Mode=TwoWay}"/>
|
||||
</shc:SizeRestrictedContentControl>
|
||||
|
||||
@@ -62,7 +62,7 @@ internal sealed partial class SettingViewModel : Abstraction.ViewModel
|
||||
|
||||
private NameValue<BackdropType>? selectedBackdropType;
|
||||
private NameValue<CultureInfo>? selectedCulture;
|
||||
private Region? selectedRegion;
|
||||
private NameValue<Region>? selectedRegion;
|
||||
private IPInformation? ipInformation;
|
||||
private FolderViewModel? cacheFolderView;
|
||||
private FolderViewModel? dataFolderView;
|
||||
@@ -106,9 +106,9 @@ internal sealed partial class SettingViewModel : Abstraction.ViewModel
|
||||
}
|
||||
}
|
||||
|
||||
public Region? SelectedRegion
|
||||
public NameValue<Region>? SelectedRegion
|
||||
{
|
||||
get => selectedRegion ??= AppOptions.Region;
|
||||
get => selectedRegion ??= AppOptions.Regions.Single(t => t.Value.Value == AppOptions.Region.Value);
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref selectedRegion, value) && value is not null)
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
|
||||
namespace Snap.Hutao.Web.Hoyolab;
|
||||
|
||||
internal readonly partial struct Region
|
||||
{
|
||||
public readonly string DisplayName;
|
||||
|
||||
public readonly string Value;
|
||||
|
||||
public readonly bool IsOversea;
|
||||
|
||||
public Region(string value, bool? isOversea = default)
|
||||
{
|
||||
Must.Argument(HoyolabRegex.RegionRegex().IsMatch(value), SH.WebHoyolabInvalidRegion);
|
||||
@@ -13,12 +20,6 @@ internal readonly partial struct Region
|
||||
IsOversea = isOversea ?? EvaluateIsOversea(value.AsSpan()[0]);
|
||||
}
|
||||
|
||||
public readonly string DisplayName { get; }
|
||||
|
||||
public readonly string Value { get; }
|
||||
|
||||
public readonly bool IsOversea { get; }
|
||||
|
||||
public static implicit operator Region(string value)
|
||||
{
|
||||
return FromRegion(value);
|
||||
|
||||
Reference in New Issue
Block a user