VPet/VPet.Solution/ViewModels/MainWindowVM.cs

76 lines
2.4 KiB
C#
Raw Normal View History

2024-03-30 07:00:02 +00:00
using LinePutScript.Localization.WPF;
2024-03-07 10:41:18 +00:00
using Panuon.WPF.UI;
2024-03-30 07:00:02 +00:00
using System.Text;
using VPet.Solution.Models.SettingEditor;
using VPet.Solution.ViewModels.SettingEditor;
2023-12-18 14:53:56 +00:00
namespace VPet.Solution.ViewModels;
public class MainWindowVM : ObservableClass<MainWindowVM>
{
2024-03-07 10:41:18 +00:00
private readonly SettingModel? _mainSetting;
public MainWindowVM()
{
LocalizeCore.StoreTranslation = true;
LocalizeCore.LoadDefaultCulture();
2024-03-07 10:41:18 +00:00
_mainSetting = SettingWindowVM.Current.ShowSettings.FirstOrDefault(m =>
m.Name == nameof(Setting)
);
if (string.IsNullOrWhiteSpace(_mainSetting?.GraphicsSetting?.Language))
CurrentCulture = LocalizeCore.CurrentCulture;
else
CurrentCulture = _mainSetting.GraphicsSetting.Language;
FirstStartFailedCommand.ExecuteCommand += FirstStartFailedCommand_ExecuteCommand;
OpenLocalTextCommand.ExecuteCommand += OpenLocalTextCommand_ExecuteCommand;
}
private void OpenLocalTextCommand_ExecuteCommand()
{
var sb = new StringBuilder();
foreach (var a in LocalizeCore.StoreTranslationList)
sb.AppendLine(a.Replace("\r\n", "\\r\\n"));
MessageBoxX.Show(sb.ToString());
}
private void FirstStartFailedCommand_ExecuteCommand()
{
2024-01-25 14:40:50 +00:00
if (LocalizeCore.CurrentCulture == "zh-Hans")
HKWUtils.OpenLink("https://www.bilibili.com/read/cv26510496/");
2024-01-25 14:40:50 +00:00
else
HKWUtils.OpenLink(
"https://steamcommunity.com/games/1920960/announcements/detail/3681184905256253203"
);
}
#region Property
2024-03-07 10:41:18 +00:00
public static IEnumerable<string> AvailableCultures => LocalizeCore.AvailableCultures;
#region CurrentCulture
private string _currentCulture = string.Empty;
public string CurrentCulture
{
get => _currentCulture;
set
{
SetProperty(ref _currentCulture, value);
LocalizeCore.LoadCulture(_currentCulture);
if (
2024-03-07 10:41:18 +00:00
_mainSetting is not null
&& _mainSetting.GraphicsSetting.Language != _currentCulture
)
{
_mainSetting.GraphicsSetting.Language = _currentCulture;
_mainSetting.Save();
}
}
}
#endregion
#endregion
#region Command
public ObservableCommand FirstStartFailedCommand { get; } = new();
public ObservableCommand OpenLocalTextCommand { get; } = new();
#endregion
}