diff --git a/VPet-Simulator.Tool/VPet-Simulator.Tool.csproj b/VPet-Simulator.Tool/VPet-Simulator.Tool.csproj index d6f7f47..34cee4d 100644 --- a/VPet-Simulator.Tool/VPet-Simulator.Tool.csproj +++ b/VPet-Simulator.Tool/VPet-Simulator.Tool.csproj @@ -8,6 +8,7 @@ 1.0.0.0 VPet-Simulator.Tool Copyright © 2022 + preview diff --git a/VPet-Simulator.Windows.Interface/VPet-Simulator.Windows.Interface.csproj b/VPet-Simulator.Windows.Interface/VPet-Simulator.Windows.Interface.csproj index e893214..28cecf0 100644 --- a/VPet-Simulator.Windows.Interface/VPet-Simulator.Windows.Interface.csproj +++ b/VPet-Simulator.Windows.Interface/VPet-Simulator.Windows.Interface.csproj @@ -7,6 +7,7 @@ true true true + preview true diff --git a/VPet.Solution/Models/ModLoader.cs b/VPet.Solution/Models/ModLoader.cs index 5463972..2fcfb49 100644 --- a/VPet.Solution/Models/ModLoader.cs +++ b/VPet.Solution/Models/ModLoader.cs @@ -107,6 +107,14 @@ public class ModLoader ItemID = 0; CacheDate = modlps.GetDateTime("cachedate", DateTime.MinValue); var imagePath = Path.Combine(path, "icon.png"); + //加载翻译 + foreach (var line in modlps.FindAllLine("lang")) + { + var lps = new LPS(); + foreach (var sub in line) + lps.Add(new Line(sub.Name, sub.Info)); + LocalizeCore.AddCulture(line.Info, lps); + } if (File.Exists(imagePath)) { try diff --git a/VPet.Solution/Models/SettingEditor/ModSettingModel.cs b/VPet.Solution/Models/SettingEditor/ModSettingModel.cs index b2b3cda..7619f7b 100644 --- a/VPet.Solution/Models/SettingEditor/ModSettingModel.cs +++ b/VPet.Solution/Models/SettingEditor/ModSettingModel.cs @@ -4,6 +4,7 @@ using LinePutScript.Localization.WPF; using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -296,6 +297,15 @@ public class ModModel : ObservableClass PropertyChanged += ModModel_PropertyChanged; ReflectionUtils.SetValue(loader, this); RefreshState(); + Name = Name.Translate(); + Description = Description.Translate(); + LocalizeCore.BindingNotify.PropertyChanged += BindingNotify_PropertyChanged; + } + + private void BindingNotify_PropertyChanged(object sender, PropertyChangedEventArgs e) + { + Name = Name.Translate(); + Description = Description.Translate(); } public void RefreshState() diff --git a/VPet.Solution/VPet.Solution.csproj b/VPet.Solution/VPet.Solution.csproj index 549c352..1db3f59 100644 --- a/VPet.Solution/VPet.Solution.csproj +++ b/VPet.Solution/VPet.Solution.csproj @@ -14,7 +14,6 @@ 4 true true - enable latest diff --git a/VPet.Solution/ViewModels/MainWindowVM.cs b/VPet.Solution/ViewModels/MainWindowVM.cs index 5d52748..923b148 100644 --- a/VPet.Solution/ViewModels/MainWindowVM.cs +++ b/VPet.Solution/ViewModels/MainWindowVM.cs @@ -1,4 +1,7 @@ -using System; +using HKW.HKWUtils.Observable; +using LinePutScript.Localization.WPF; +using Panuon.WPF.UI; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,4 +9,50 @@ using System.Threading.Tasks; namespace VPet.Solution.ViewModels; -public class MainWindowVM : ObservableClass { } +public class MainWindowVM : ObservableClass +{ + public MainWindowVM() + { + LocalizeCore.StoreTranslation = true; + LocalizeCore.LoadDefaultCulture(); + CurrentCulture = LocalizeCore.CurrentCulture; + 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() + { + Utils.OpenLink( + "https://steamcommunity.com/games/1920960/announcements/detail/3681184905256253203" + ); + } + + #region Property + public IEnumerable AvailableCultures => LocalizeCore.AvailableCultures; + #region CurrentCulture + private string _currentCulture = string.Empty; + public string CurrentCulture + { + get => _currentCulture; + set + { + SetProperty(ref _currentCulture, value); + LocalizeCore.LoadCulture(_currentCulture); + } + } + #endregion + #endregion + + #region Command + public ObservableCommand FirstStartFailedCommand { get; } = new(); + public ObservableCommand OpenLocalTextCommand { get; } = new(); + #endregion +} diff --git a/VPet.Solution/ViewModels/SettingEditor/SettingWindowVM.cs b/VPet.Solution/ViewModels/SettingEditor/SettingWindowVM.cs index f9ef59a..14265f6 100644 --- a/VPet.Solution/ViewModels/SettingEditor/SettingWindowVM.cs +++ b/VPet.Solution/ViewModels/SettingEditor/SettingWindowVM.cs @@ -72,6 +72,11 @@ public class SettingWindowVM : ObservableClass /// 保存全部 /// public ObservableCommand SaveAllSettingCommand { get; } = new(); + + /// + /// 重置全部 + /// + public ObservableCommand ResetAllSettingCommand { get; } = new(); #endregion public SettingWindowVM() { @@ -85,6 +90,24 @@ public class SettingWindowVM : ObservableClass ResetSettingCommand.ExecuteCommand += ResetSettingCommand_ExecuteCommand; SaveSettingCommand.ExecuteCommand += SaveSettingCommand_ExecuteCommand; SaveAllSettingCommand.ExecuteCommand += SaveAllSettingCommand_ExecuteCommand; + ResetAllSettingCommand.ExecuteCommand += ResetAllSettingCommand_ExecuteCommand; + } + + private void ResetAllSettingCommand_ExecuteCommand() + { + if ( + MessageBox.Show( + SettingWindow.Instance, + "确定全部重置吗".Translate(), + "", + MessageBoxButton.YesNo, + MessageBoxImage.Warning + ) + is not MessageBoxResult.Yes + ) + return; + for (var i = 0; i < _settings.Count; i++) + _settings[i] = new SettingModel(); } private void OpenFileInExplorerCommand_ExecuteCommand(SettingModel parameter) diff --git a/VPet.Solution/Views/MainWindow.xaml b/VPet.Solution/Views/MainWindow.xaml index f4921fb..4743f82 100644 --- a/VPet.Solution/Views/MainWindow.xaml +++ b/VPet.Solution/Views/MainWindow.xaml @@ -18,36 +18,54 @@ WindowStartupLocation="CenterScreen" mc:Ignorable="d"> - - - - -