mirror of
https://github.com/LorisYounger/VPet.git
synced 2024-08-30 18:42:36 +00:00
# VPet.Solution
## 更新 - 修改主界面文化时会同步修改`Setting.lps`的文化设置 - 修改设置编辑页面的设置列表排序 ## 修复 - 存在两个相同名称的mod时启动失败的问题 - `设置编辑`-`图像`页面语言列表显示错误的问题
This commit is contained in:
parent
5c5fafee94
commit
e44a649c57
@ -106,7 +106,7 @@ public class GraphicsSettingModel : ObservableClass<GraphicsSettingModel>
|
||||
#endregion
|
||||
|
||||
#region Language
|
||||
private string _language = Languages.First();
|
||||
private string _language;
|
||||
|
||||
/// <summary>
|
||||
/// 语言
|
||||
@ -118,9 +118,7 @@ public class GraphicsSettingModel : ObservableClass<GraphicsSettingModel>
|
||||
set => SetProperty(ref _language, value);
|
||||
}
|
||||
|
||||
public static ObservableCollection<string> Languages { get; } =
|
||||
new() { "zh-Hans", "zh-Hant", "en" };
|
||||
// NOTE: 实际上这里面并没有文化 new(LocalizeCore.AvailableCultures);
|
||||
public static IEnumerable<string> Languages => LocalizeCore.AvailableCultures;
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -27,6 +27,7 @@ public class ModSettingModel : ObservableClass<ModSettingModel>
|
||||
Directory
|
||||
.EnumerateDirectories(ModDirectory)
|
||||
.Select(d => new ModLoader(d))
|
||||
.Distinct(CompareUtils<ModLoader>.Create(m => m.Name))
|
||||
.ToDictionary(m => m.Name, m => m),
|
||||
StringComparer.OrdinalIgnoreCase
|
||||
);
|
||||
|
@ -1,6 +1,7 @@
|
||||
using FastMember;
|
||||
using HKW.HKWUtils.Observable;
|
||||
using LinePutScript;
|
||||
using LinePutScript.Localization.WPF;
|
||||
using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
@ -22,6 +23,19 @@ public class SettingModel : ObservableClass<SettingModel>
|
||||
/// </summary>
|
||||
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
|
||||
private GraphicsSettingModel _graphicsSetting;
|
||||
public GraphicsSettingModel GraphicsSetting
|
||||
@ -89,14 +103,33 @@ public class SettingModel : ObservableClass<SettingModel>
|
||||
{
|
||||
_setting = setting;
|
||||
GraphicsSetting = LoadSetting<GraphicsSettingModel>();
|
||||
if (string.IsNullOrWhiteSpace(GraphicsSetting.Language))
|
||||
GraphicsSetting.Language = LocalizeCore.CurrentCulture;
|
||||
InteractiveSetting = LoadSetting<InteractiveSettingModel>();
|
||||
SystemSetting = LoadSetting<SystemSettingModel>();
|
||||
CustomizedSetting = LoadCustomizedSetting(setting);
|
||||
DiagnosticSetting = LoadSetting<DiagnosticSettingModel>();
|
||||
DiagnosticSetting.SetAutoCalToSetting(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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
@ -105,6 +105,7 @@
|
||||
<Compile Include="Models\SettingEditor\ModSettingModel.cs" />
|
||||
<Compile Include="Models\SettingEditor\SystemSettingModel.cs" />
|
||||
<Compile Include="Utils\ClearFocus.cs" />
|
||||
<Compile Include="Utils\CompareUtils.cs" />
|
||||
<Compile Include="Utils\ElementHelper.cs" />
|
||||
<Compile Include="Utils\FindTopParent.cs" />
|
||||
<Compile Include="Utils\ReflectionUtils.cs" />
|
||||
|
@ -6,16 +6,28 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VPet.Solution.Models.SettingEditor;
|
||||
using VPet.Solution.ViewModels.SettingEditor;
|
||||
using VPet_Simulator.Windows.Interface;
|
||||
|
||||
namespace VPet.Solution.ViewModels;
|
||||
|
||||
public class MainWindowVM : ObservableClass<MainWindowVM>
|
||||
{
|
||||
private readonly SettingModel _mainSetting;
|
||||
|
||||
public MainWindowVM()
|
||||
{
|
||||
LocalizeCore.StoreTranslation = true;
|
||||
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;
|
||||
OpenLocalTextCommand.ExecuteCommand += OpenLocalTextCommand_ExecuteCommand;
|
||||
}
|
||||
@ -46,6 +58,11 @@ public class MainWindowVM : ObservableClass<MainWindowVM>
|
||||
{
|
||||
SetProperty(ref _currentCulture, value);
|
||||
LocalizeCore.LoadCulture(_currentCulture);
|
||||
if (_mainSetting is not null)
|
||||
{
|
||||
_mainSetting.GraphicsSetting.Language = _currentCulture;
|
||||
_mainSetting.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
@ -20,13 +20,12 @@ namespace VPet.Solution.ViewModels.SettingEditor;
|
||||
public class SettingWindowVM : ObservableClass<SettingWindowVM>
|
||||
{
|
||||
public static SettingWindowVM Current { get; private set; }
|
||||
|
||||
#region Properties
|
||||
private SettingModel _currentSettings;
|
||||
private SettingModel _currentSetting;
|
||||
public SettingModel CurrentSetting
|
||||
{
|
||||
get => _currentSettings;
|
||||
set => SetProperty(ref _currentSettings, value);
|
||||
get => _currentSetting;
|
||||
set { SetProperty(ref _currentSetting, value); }
|
||||
}
|
||||
|
||||
private readonly ObservableCollection<SettingModel> _settings = new();
|
||||
@ -81,8 +80,8 @@ public class SettingWindowVM : ObservableClass<SettingWindowVM>
|
||||
public SettingWindowVM()
|
||||
{
|
||||
Current = this;
|
||||
ShowSettings = _settings;
|
||||
LoadSettings();
|
||||
ShowSettings = _settings = new(_settings.OrderBy(m => m.Name));
|
||||
|
||||
PropertyChanged += MainWindowVM_PropertyChanged;
|
||||
OpenFileCommand.ExecuteCommand += OpenFileCommand_ExecuteCommand;
|
||||
@ -204,9 +203,13 @@ public class SettingWindowVM : ObservableClass<SettingWindowVM>
|
||||
"载入设置出错".Translate(),
|
||||
MessageBoxButton.YesNo,
|
||||
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)
|
||||
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.Windows;
|
||||
using System.Windows.Controls;
|
||||
using VPet.Solution.Models.SettingEditor;
|
||||
using VPet.Solution.ViewModels;
|
||||
using VPet.Solution.Views.SaveViewer;
|
||||
using VPet.Solution.Views.SettingEditor;
|
||||
using VPet_Simulator.Windows.Interface;
|
||||
|
||||
namespace VPet.Solution.Views;
|
||||
|
||||
|
@ -70,6 +70,7 @@
|
||||
<ComboBox
|
||||
x:Name="LanguageBox"
|
||||
Grid.Column="1"
|
||||
ItemsSource="{Binding GraphicsSetting.Languages}"
|
||||
SelectedItem="{Binding GraphicsSetting.Language}"
|
||||
Style="{DynamicResource ComboBox_BaseStyle}" />
|
||||
</Grid>
|
||||
|
Loading…
Reference in New Issue
Block a user