mirror of
https://github.com/LorisYounger/VPet.git
synced 2024-08-30 18:42:36 +00:00
Merge branch 'main' of https://github.com/LorisYounger/VPet
This commit is contained in:
commit
3d555b89d0
@ -106,7 +106,7 @@ public class GraphicsSettingModel : ObservableClass<GraphicsSettingModel>
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Language
|
#region Language
|
||||||
private string _language = Languages.First();
|
private string _language;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 语言
|
/// 语言
|
||||||
@ -118,9 +118,7 @@ public class GraphicsSettingModel : ObservableClass<GraphicsSettingModel>
|
|||||||
set => SetProperty(ref _language, value);
|
set => SetProperty(ref _language, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ObservableCollection<string> Languages { get; } =
|
public static IEnumerable<string> Languages => LocalizeCore.AvailableCultures;
|
||||||
new() { "zh-Hans", "zh-Hant", "en" };
|
|
||||||
// NOTE: 实际上这里面并没有文化 new(LocalizeCore.AvailableCultures);
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ public class ModSettingModel : ObservableClass<ModSettingModel>
|
|||||||
Directory
|
Directory
|
||||||
.EnumerateDirectories(ModDirectory)
|
.EnumerateDirectories(ModDirectory)
|
||||||
.Select(d => new ModLoader(d))
|
.Select(d => new ModLoader(d))
|
||||||
|
.Distinct(CompareUtils<ModLoader>.Create(m => m.Name))
|
||||||
.ToDictionary(m => m.Name, m => m),
|
.ToDictionary(m => m.Name, m => m),
|
||||||
StringComparer.OrdinalIgnoreCase
|
StringComparer.OrdinalIgnoreCase
|
||||||
);
|
);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using FastMember;
|
using FastMember;
|
||||||
using HKW.HKWUtils.Observable;
|
using HKW.HKWUtils.Observable;
|
||||||
using LinePutScript;
|
using LinePutScript;
|
||||||
|
using LinePutScript.Localization.WPF;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
@ -22,6 +23,19 @@ public class SettingModel : ObservableClass<SettingModel>
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string FilePath { get; set; }
|
public string FilePath { get; set; }
|
||||||
|
|
||||||
|
//#region IsChanged
|
||||||
|
//private bool _isChanged;
|
||||||
|
|
||||||
|
///// <summary>
|
||||||
|
///// 已更改
|
||||||
|
///// </summary>
|
||||||
|
//public bool IsChanged
|
||||||
|
//{
|
||||||
|
// get => _isChanged;
|
||||||
|
// set => SetProperty(ref _isChanged, value);
|
||||||
|
//}
|
||||||
|
//#endregion
|
||||||
|
|
||||||
#region GraphicsSetting
|
#region GraphicsSetting
|
||||||
private GraphicsSettingModel _graphicsSetting;
|
private GraphicsSettingModel _graphicsSetting;
|
||||||
public GraphicsSettingModel GraphicsSetting
|
public GraphicsSettingModel GraphicsSetting
|
||||||
@ -89,14 +103,33 @@ public class SettingModel : ObservableClass<SettingModel>
|
|||||||
{
|
{
|
||||||
_setting = setting;
|
_setting = setting;
|
||||||
GraphicsSetting = LoadSetting<GraphicsSettingModel>();
|
GraphicsSetting = LoadSetting<GraphicsSettingModel>();
|
||||||
|
if (string.IsNullOrWhiteSpace(GraphicsSetting.Language))
|
||||||
|
GraphicsSetting.Language = LocalizeCore.CurrentCulture;
|
||||||
InteractiveSetting = LoadSetting<InteractiveSettingModel>();
|
InteractiveSetting = LoadSetting<InteractiveSettingModel>();
|
||||||
SystemSetting = LoadSetting<SystemSettingModel>();
|
SystemSetting = LoadSetting<SystemSettingModel>();
|
||||||
CustomizedSetting = LoadCustomizedSetting(setting);
|
CustomizedSetting = LoadCustomizedSetting(setting);
|
||||||
DiagnosticSetting = LoadSetting<DiagnosticSettingModel>();
|
DiagnosticSetting = LoadSetting<DiagnosticSettingModel>();
|
||||||
DiagnosticSetting.SetAutoCalToSetting(setting);
|
DiagnosticSetting.SetAutoCalToSetting(setting);
|
||||||
ModSetting = LoadModSetting(setting);
|
ModSetting = LoadModSetting(setting);
|
||||||
|
//MergeNotify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//private void MergeNotify()
|
||||||
|
//{
|
||||||
|
// var accessor = ObjectAccessor.Create(this);
|
||||||
|
// foreach (var property in typeof(SettingModel).GetProperties())
|
||||||
|
// {
|
||||||
|
// var value = accessor[property.Name];
|
||||||
|
// if (value is INotifyPropertyChanged model)
|
||||||
|
// model.PropertyChanged += Notify_PropertyChanged;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
//private void Notify_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||||
|
//{
|
||||||
|
// IsChanged = true;
|
||||||
|
//}
|
||||||
|
|
||||||
private ModSettingModel LoadModSetting(Setting setting)
|
private ModSettingModel LoadModSetting(Setting setting)
|
||||||
{
|
{
|
||||||
var settingModel = new ModSettingModel(setting);
|
var settingModel = new ModSettingModel(setting);
|
||||||
|
48
VPet.Solution/Utils/CompareUtils.cs
Normal file
48
VPet.Solution/Utils/CompareUtils.cs
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace HKW.HKWUtils;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 比较工具
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">比较类型</typeparam>
|
||||||
|
public class CompareUtils<T> : IEqualityComparer<T>, IEquatable<CompareUtils<T>>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// (Comparer, CompareUtils)
|
||||||
|
/// </summary>
|
||||||
|
public static Dictionary<Func<T, object>, CompareUtils<T>> Comparers = new();
|
||||||
|
|
||||||
|
public static CompareUtils<T> Create(Func<T, object> comparer)
|
||||||
|
{
|
||||||
|
if (Comparers.TryGetValue(comparer, out var value) is false)
|
||||||
|
value = Comparers[comparer] = new CompareUtils<T>(comparer);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Func<T, object> Comparer { get; set; }
|
||||||
|
|
||||||
|
public CompareUtils(Func<T, object> comparer)
|
||||||
|
{
|
||||||
|
Comparer = comparer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Equals(T x, T y)
|
||||||
|
{
|
||||||
|
return Comparer(x).Equals(Comparer(y));
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetHashCode(T obj)
|
||||||
|
{
|
||||||
|
return Comparer(obj).GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Equals(CompareUtils<T> other)
|
||||||
|
{
|
||||||
|
return Comparer.Equals(other.Comparer);
|
||||||
|
}
|
||||||
|
}
|
@ -107,6 +107,7 @@
|
|||||||
<Compile Include="Models\SettingEditor\ModSettingModel.cs" />
|
<Compile Include="Models\SettingEditor\ModSettingModel.cs" />
|
||||||
<Compile Include="Models\SettingEditor\SystemSettingModel.cs" />
|
<Compile Include="Models\SettingEditor\SystemSettingModel.cs" />
|
||||||
<Compile Include="Utils\ClearFocus.cs" />
|
<Compile Include="Utils\ClearFocus.cs" />
|
||||||
|
<Compile Include="Utils\CompareUtils.cs" />
|
||||||
<Compile Include="Utils\ElementHelper.cs" />
|
<Compile Include="Utils\ElementHelper.cs" />
|
||||||
<Compile Include="Utils\FindTopParent.cs" />
|
<Compile Include="Utils\FindTopParent.cs" />
|
||||||
<Compile Include="Utils\ReflectionUtils.cs" />
|
<Compile Include="Utils\ReflectionUtils.cs" />
|
||||||
|
@ -6,16 +6,28 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using VPet.Solution.Models.SettingEditor;
|
||||||
|
using VPet.Solution.ViewModels.SettingEditor;
|
||||||
|
using VPet_Simulator.Windows.Interface;
|
||||||
|
|
||||||
namespace VPet.Solution.ViewModels;
|
namespace VPet.Solution.ViewModels;
|
||||||
|
|
||||||
public class MainWindowVM : ObservableClass<MainWindowVM>
|
public class MainWindowVM : ObservableClass<MainWindowVM>
|
||||||
{
|
{
|
||||||
|
private readonly SettingModel _mainSetting;
|
||||||
|
|
||||||
public MainWindowVM()
|
public MainWindowVM()
|
||||||
{
|
{
|
||||||
LocalizeCore.StoreTranslation = true;
|
LocalizeCore.StoreTranslation = true;
|
||||||
LocalizeCore.LoadDefaultCulture();
|
LocalizeCore.LoadDefaultCulture();
|
||||||
CurrentCulture = LocalizeCore.CurrentCulture;
|
_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;
|
FirstStartFailedCommand.ExecuteCommand += FirstStartFailedCommand_ExecuteCommand;
|
||||||
OpenLocalTextCommand.ExecuteCommand += OpenLocalTextCommand_ExecuteCommand;
|
OpenLocalTextCommand.ExecuteCommand += OpenLocalTextCommand_ExecuteCommand;
|
||||||
}
|
}
|
||||||
@ -47,6 +59,11 @@ public class MainWindowVM : ObservableClass<MainWindowVM>
|
|||||||
{
|
{
|
||||||
SetProperty(ref _currentCulture, value);
|
SetProperty(ref _currentCulture, value);
|
||||||
LocalizeCore.LoadCulture(_currentCulture);
|
LocalizeCore.LoadCulture(_currentCulture);
|
||||||
|
if (_mainSetting is not null)
|
||||||
|
{
|
||||||
|
_mainSetting.GraphicsSetting.Language = _currentCulture;
|
||||||
|
_mainSetting.Save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -20,13 +20,12 @@ namespace VPet.Solution.ViewModels.SettingEditor;
|
|||||||
public class SettingWindowVM : ObservableClass<SettingWindowVM>
|
public class SettingWindowVM : ObservableClass<SettingWindowVM>
|
||||||
{
|
{
|
||||||
public static SettingWindowVM Current { get; private set; }
|
public static SettingWindowVM Current { get; private set; }
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
private SettingModel _currentSettings;
|
private SettingModel _currentSetting;
|
||||||
public SettingModel CurrentSetting
|
public SettingModel CurrentSetting
|
||||||
{
|
{
|
||||||
get => _currentSettings;
|
get => _currentSetting;
|
||||||
set => SetProperty(ref _currentSettings, value);
|
set { SetProperty(ref _currentSetting, value); }
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly ObservableCollection<SettingModel> _settings = new();
|
private readonly ObservableCollection<SettingModel> _settings = new();
|
||||||
@ -81,8 +80,8 @@ public class SettingWindowVM : ObservableClass<SettingWindowVM>
|
|||||||
public SettingWindowVM()
|
public SettingWindowVM()
|
||||||
{
|
{
|
||||||
Current = this;
|
Current = this;
|
||||||
ShowSettings = _settings;
|
|
||||||
LoadSettings();
|
LoadSettings();
|
||||||
|
ShowSettings = _settings = new(_settings.OrderBy(m => m.Name));
|
||||||
|
|
||||||
PropertyChanged += MainWindowVM_PropertyChanged;
|
PropertyChanged += MainWindowVM_PropertyChanged;
|
||||||
OpenFileCommand.ExecuteCommand += OpenFileCommand_ExecuteCommand;
|
OpenFileCommand.ExecuteCommand += OpenFileCommand_ExecuteCommand;
|
||||||
@ -204,9 +203,13 @@ public class SettingWindowVM : ObservableClass<SettingWindowVM>
|
|||||||
"载入设置出错".Translate(),
|
"载入设置出错".Translate(),
|
||||||
MessageBoxButton.YesNo,
|
MessageBoxButton.YesNo,
|
||||||
MessageBoxImage.Warning
|
MessageBoxImage.Warning
|
||||||
) is MessageBoxResult.Yes
|
)
|
||||||
|
is not MessageBoxResult.Yes
|
||||||
)
|
)
|
||||||
_settings.Add(new SettingModel() { Name = fileName, FilePath = file });
|
return;
|
||||||
|
var setting = new SettingModel() { Name = fileName, FilePath = file };
|
||||||
|
_settings.Add(setting);
|
||||||
|
setting.Save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -220,7 +223,7 @@ public class SettingWindowVM : ObservableClass<SettingWindowVM>
|
|||||||
{
|
{
|
||||||
if (s.EndsWith(".lps") is false)
|
if (s.EndsWith(".lps") is false)
|
||||||
return false;
|
return false;
|
||||||
return Path.GetFileName(s).StartsWith("Setting");
|
return Path.GetFileName(s).StartsWith(nameof(Setting));
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,11 @@ using System.ComponentModel;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
using VPet.Solution.Models.SettingEditor;
|
||||||
using VPet.Solution.ViewModels;
|
using VPet.Solution.ViewModels;
|
||||||
using VPet.Solution.Views.SaveViewer;
|
using VPet.Solution.Views.SaveViewer;
|
||||||
using VPet.Solution.Views.SettingEditor;
|
using VPet.Solution.Views.SettingEditor;
|
||||||
|
using VPet_Simulator.Windows.Interface;
|
||||||
|
|
||||||
namespace VPet.Solution.Views;
|
namespace VPet.Solution.Views;
|
||||||
|
|
||||||
|
@ -70,6 +70,7 @@
|
|||||||
<ComboBox
|
<ComboBox
|
||||||
x:Name="LanguageBox"
|
x:Name="LanguageBox"
|
||||||
Grid.Column="1"
|
Grid.Column="1"
|
||||||
|
ItemsSource="{Binding GraphicsSetting.Languages}"
|
||||||
SelectedItem="{Binding GraphicsSetting.Language}"
|
SelectedItem="{Binding GraphicsSetting.Language}"
|
||||||
Style="{DynamicResource ComboBox_BaseStyle}" />
|
Style="{DynamicResource ComboBox_BaseStyle}" />
|
||||||
</Grid>
|
</Grid>
|
||||||
|
Loading…
Reference in New Issue
Block a user