Skip to content

Commit

Permalink
Merge pull request #16 from Baka632/240501-AddOtherServerSupport
Browse files Browse the repository at this point in the history
为概览页添加其他语言剧情的支持
  • Loading branch information
Baka632 authored May 2, 2024
2 parents b7be663 + aaaa983 commit 4da4bbb
Show file tree
Hide file tree
Showing 23 changed files with 440 additions and 24 deletions.
2 changes: 2 additions & 0 deletions src/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:contract5NotPresent="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractNotPresent(Windows.Foundation.UniversalApiContract,5)"
xmlns:converter="using:ArknightsStoryText.UWP.Helpers.Converter"
xmlns:local="using:ArknightsStoryText.UWP">
<Application.Resources>
<contract5NotPresent:Style BasedOn="{x:Null}" TargetType="AppBarButton" />
<contract5NotPresent:Style BasedOn="{x:Null}" TargetType="AppBarToggleButton" />
<contract5NotPresent:Style BasedOn="{x:Null}" TargetType="CommandBar">
<Setter Property="Background" Value="Transparent" />
</contract5NotPresent:Style>
<converter:AppBackgroundModeToStringConverter x:Key="AppBackgroundModeToStringConverter" />
</Application.Resources>
</Application>
18 changes: 15 additions & 3 deletions src/ArknightsStoryText.UWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,11 @@
<Compile Include="CommonValues.cs" />
<Compile Include="GlobalUsings.cs" />
<Compile Include="Helpers\Converter\ActTypeToStringConverter.cs" />
<Compile Include="Helpers\Converter\AppBackgroundModeToStringConverter.cs" />
<Compile Include="Helpers\Converter\ObjectToFontFamilyOrFontSizeConverter.cs" />
<Compile Include="Helpers\FontHelper.cs" />
<Compile Include="Helpers\StoryInfoComparer.cs" />
<Compile Include="Models\AppBackgroundMode.cs" />
<Compile Include="Models\ArknightsResources.Stories.Models\CharacterIllustrationEnterStyle.cs" />
<Compile Include="Models\ArknightsResources.Stories.Models\Commands\DecisionCommand.cs" />
<Compile Include="Models\ArknightsResources.Stories.Models\Commands\DelayCommand.cs" />
Expand Down Expand Up @@ -176,6 +178,7 @@
<Compile Include="Services\StoryMetadataService.cs" />
<Compile Include="Models\StoryDataPack.cs" />
<Compile Include="ViewModels\MainViewModel.cs" />
<Compile Include="ViewModels\SettingsViewModel.cs" />
<Compile Include="ViewModels\StoryGlanceViewModel.cs" />
<Compile Include="ViewModels\TextMergeViewModel.cs" />
<Compile Include="ViewModels\TextReadViewModel.cs" />
Expand All @@ -184,6 +187,9 @@
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\StoryReader.cs" />
<Compile Include="Views\SettingsDialog.xaml.cs">
<DependentUpon>SettingsDialog.xaml</DependentUpon>
</Compile>
<Compile Include="Views\StoryGlancePage.xaml.cs">
<DependentUpon>StoryGlancePage.xaml</DependentUpon>
</Compile>
Expand All @@ -200,6 +206,8 @@
</AppxManifest>
</ItemGroup>
<ItemGroup>
<Content Include="Assets\App-Logo\Dark-Mode.png" />
<Content Include="Assets\App-Logo\Light-Mode.png" />
<Content Include="Assets\BadgeLogo.scale-100.png" />
<Content Include="Assets\BadgeLogo.scale-125.png" />
<Content Include="Assets\BadgeLogo.scale-150.png" />
Expand Down Expand Up @@ -267,6 +275,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\SettingsDialog.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\StoryGlancePage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand All @@ -282,13 +294,13 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Baka632.Library.Uwp.CSharp">
<Version>1.0.1</Version>
<Version>1.0.3</Version>
</PackageReference>
<PackageReference Include="CommunityToolkit.Mvvm">
<Version>8.2.2</Version>
</PackageReference>
<PackageReference Include="IndexRange">
<Version>1.0.2</Version>
<Version>1.0.3</Version>
</PackageReference>
<PackageReference Include="IsExternalInit">
<Version>1.0.3</Version>
Expand Down Expand Up @@ -316,7 +328,7 @@
<Version>4.2.0</Version>
</PackageReference>
<PackageReference Include="System.Text.Json">
<Version>8.0.1</Version>
<Version>8.0.3</Version>
</PackageReference>
</ItemGroup>
<ItemGroup />
Expand Down
Binary file added src/Assets/App-Logo/Dark-Mode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/Assets/App-Logo/Light-Mode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 14 additions & 1 deletion src/CommonValues.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
namespace ArknightsStoryText.UWP;
using Windows.ApplicationModel;

namespace ArknightsStoryText.UWP;

internal static class CommonValues
{
public const string NotifyUpdateStoriesMessageToken = "Notify_UpdateStories_MessageToken";
public const string NotifyUpdateStoryFileInfosMessageToken = "Notify_UpdateStoryFileInfos_MessageToken";
public const string NotifyPivotNavigationMessageToken = "Notify_PivotNavigation_MessageToken";
public const string AppBackgroundModeSettingsKey = "App_BackgroundMode_SettingsKey";
public const string NotifyAppBackgroundChangedMessageToken = "Notify_AppBackgroundChanged_MessageToken";

/// <summary>
/// 获取应用程序版本
/// </summary>
public static string AppVersion => $"{Package.Current.Id.Version.Major}.{Package.Current.Id.Version.Minor}.{Package.Current.Id.Version.Build}.{Package.Current.Id.Version.Revision}";
/// <summary>
/// 获取带“版本”文字的应用程序版本字符串
/// </summary>
public static string AppVersionWithText => string.Format("AppVersion_WithPlaceholder".GetLocalized(), AppVersion);
}
28 changes: 28 additions & 0 deletions src/Helpers/Converter/AppBackgroundModeToStringConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

using Windows.UI.Xaml.Data;

namespace ArknightsStoryText.UWP.Helpers.Converter;

public sealed class AppBackgroundModeToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value is AppBackgroundMode mode)
{
return mode switch
{
AppBackgroundMode.Mica => "MicaBackground".GetLocalized(),
AppBackgroundMode.Acrylic => "AcrylicBackground".GetLocalized(),
AppBackgroundMode.PureColor => "PureColorBackground".GetLocalized(),
_ => throw new NotImplementedException()
};
}

return DependencyProperty.UnsetValue;
}

public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
20 changes: 20 additions & 0 deletions src/Models/AppBackgroundMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace ArknightsStoryText.UWP.Models;

/// <summary>
/// 应用背景模式的枚举
/// </summary>
public enum AppBackgroundMode
{
/// <summary>
/// 纯色背景
/// </summary>
PureColor,
/// <summary>
/// 亚克力背景
/// </summary>
Acrylic,
/// <summary>
/// 云母背景
/// </summary>
Mica
}
2 changes: 1 addition & 1 deletion src/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Identity
Name="Baka632.ArknightsStoryText.Uwp"
Publisher="CN=Baka632"
Version="4.6.1.0" />
Version="4.8.0.0" />

<mp:PhoneIdentity PhoneProductId="e34e41f8-8622-4faf-9f0b-7b69d6c25374" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>

Expand Down
2 changes: 1 addition & 1 deletion src/Services/StoryReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ void InitCurrentKeys(out List<string> currentKey, string[] options, string[] ref
}
#endregion
return new NoOperationCommand();
//throw new ArgumentException($@"无法分析参数""{nameof(strToAnalyse)}"",原始文件行:第{textLine}行,原始文本:""{strToAnalyse}""");
//throw new ArgumentException($@"无法分析参数""{nameof(strToAnalyse)}"",原始文本:""{strToAnalyse}""");
}

/// <summary>
Expand Down
36 changes: 36 additions & 0 deletions src/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,40 @@
<data name="DeleteStoryTextButton.[using:Windows.UI.Xaml.Controls]ToolTipService.ToolTip" xml:space="preserve">
<value>Remove this story file</value>
</data>
<data name="StoryDescriptionFileNotFound" xml:space="preserve">
<value>&lt;Story description not found&gt;</value>
</data>
<data name="StoryDescriptionEmpty" xml:space="preserve">
<value>&lt;Empty&gt;</value>
</data>
<data name="SettingsAppBarButton.Label" xml:space="preserve">
<value>Settings</value>
</data>
<data name="SettingsDialog.CloseButtonText" xml:space="preserve">
<value>Close</value>
</data>
<data name="SettingsDialogSettingsPivotItem.Header" xml:space="preserve">
<value>Settings</value>
</data>
<data name="SettingsDialogAboutPivotItem.Header" xml:space="preserve">
<value>About</value>
</data>
<data name="AppVersion_WithPlaceholder" xml:space="preserve">
<value>Version: {0}</value>
</data>
<data name="RepoAddress.Text" xml:space="preserve">
<value>Repo address</value>
</data>
<data name="BackgroundTypeComboBox.Header" xml:space="preserve">
<value>App background</value>
</data>
<data name="MicaBackground" xml:space="preserve">
<value>Mica</value>
</data>
<data name="AcrylicBackground" xml:space="preserve">
<value>Acrylic</value>
</data>
<data name="PureColorBackground" xml:space="preserve">
<value>Plain color</value>
</data>
</root>
36 changes: 36 additions & 0 deletions src/Strings/zh-CN/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,40 @@
<data name="DeleteStoryTextButton.[using:Windows.UI.Xaml.Controls]ToolTipService.ToolTip" xml:space="preserve">
<value>移除此剧情文件</value>
</data>
<data name="StoryDescriptionFileNotFound" xml:space="preserve">
<value>&lt;找不到剧情简介&gt;</value>
</data>
<data name="StoryDescriptionEmpty" xml:space="preserve">
<value>&lt;&gt;</value>
</data>
<data name="SettingsAppBarButton.Label" xml:space="preserve">
<value>设置</value>
</data>
<data name="SettingsDialog.CloseButtonText" xml:space="preserve">
<value>关闭</value>
</data>
<data name="SettingsDialogSettingsPivotItem.Header" xml:space="preserve">
<value>设置</value>
</data>
<data name="SettingsDialogAboutPivotItem.Header" xml:space="preserve">
<value>关于</value>
</data>
<data name="AppVersion_WithPlaceholder" xml:space="preserve">
<value>版本:{0}</value>
</data>
<data name="RepoAddress.Text" xml:space="preserve">
<value>仓库地址</value>
</data>
<data name="BackgroundTypeComboBox.Header" xml:space="preserve">
<value>应用背景</value>
</data>
<data name="MicaBackground" xml:space="preserve">
<value>云母</value>
</data>
<data name="AcrylicBackground" xml:space="preserve">
<value>亚克力</value>
</data>
<data name="PureColorBackground" xml:space="preserve">
<value>纯色</value>
</data>
</root>
9 changes: 9 additions & 0 deletions src/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,19 @@ protected override void OnActivated()
{
base.OnActivated();
WeakReferenceMessenger.Default.Register<PivotItemIdentifier, string>(this, CommonValues.NotifyPivotNavigationMessageToken, OnPivotNavigationRequested);
WeakReferenceMessenger.Default.Register<string, string>(this, CommonValues.NotifyAppBackgroundChangedMessageToken, OnAppBackgroundChanged);
}

private void OnPivotNavigationRequested(object recipient, PivotItemIdentifier message)
{
View.MainPagePivot.SelectedIndex = (int)message.Index;
}

private void OnAppBackgroundChanged(object recipient, string message)
{
if (Enum.TryParse(message, out AppBackgroundMode mode))
{
View.SetMainPageBackground(mode);
}
}
}
68 changes: 68 additions & 0 deletions src/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using CommunityToolkit.Mvvm.Messaging;

namespace ArknightsStoryText.UWP.ViewModels;

public sealed partial class SettingsViewModel : ObservableObject
{
public readonly IReadOnlyList<AppBackgroundMode> AppBackgroundModes;

[ObservableProperty]
private int selectedAppBackgroundModeIndex;

public SettingsViewModel()
{
List<AppBackgroundMode> bgModes = new(3);

bool isSupportMica = MicaHelper.IsSupported();
bool isSupportAcrylic = AcrylicHelper.IsSupported();

if (isSupportMica)
{
bgModes.Add(AppBackgroundMode.Mica);
}

if (isSupportAcrylic)
{
bgModes.Add(AppBackgroundMode.Acrylic);
}

// 不管什么情况,系统一定支持纯色背景显示
bgModes.Add(AppBackgroundMode.PureColor);

AppBackgroundModes = bgModes;

if (SettingsHelper.TryGet(CommonValues.AppBackgroundModeSettingsKey, out string bgModeString) && Enum.TryParse(bgModeString, out AppBackgroundMode backgroundMode))
{
// ;-)
}
else
{
if (isSupportMica)
{
backgroundMode = AppBackgroundMode.Mica;
}
else if (isSupportAcrylic)
{
backgroundMode = AppBackgroundMode.Acrylic;
}
else
{
backgroundMode = AppBackgroundMode.PureColor;
}
}

selectedAppBackgroundModeIndex = bgModes.IndexOf(backgroundMode);
}

partial void OnSelectedAppBackgroundModeIndexChanged(int value)
{
if (value >= 0)
{
AppBackgroundMode bgMode = AppBackgroundModes[value];
string bgModeString = bgMode.ToString();
SettingsHelper.Set(CommonValues.AppBackgroundModeSettingsKey, bgModeString);

WeakReferenceMessenger.Default.Send(bgModeString, CommonValues.NotifyAppBackgroundChangedMessageToken);
}
}
}
Loading

0 comments on commit 4da4bbb

Please sign in to comment.