# VPet.Solution

## 新增
- 设置编辑页面的保存按钮高亮提示
## 修复
- 设置编辑的模组信息载入问题
This commit is contained in:
Hakoyu 2024-02-20 18:45:02 +08:00
parent 47857aab8f
commit 72197f0195
7 changed files with 148 additions and 47 deletions

View File

@ -38,12 +38,12 @@ public class ModSettingModel : ObservableClass<ModSettingModel>
LocalMods ??= GetLocalMods(); LocalMods ??= GetLocalMods();
foreach (var item in setting[ModLineName]) foreach (var item in setting[ModLineName])
{ {
var modName = item.Name; var modID = item.Name;
if (LocalMods.TryGetValue(modName, out var loader) && loader.IsSuccesses) if (LocalMods.TryGetValue(modID, out var loader) && loader.IsSuccesses)
{ {
var modModel = new ModModel(loader); var modModel = new ModModel(loader);
modModel.IsPass = setting[PassModLineName].Contains(modName); modModel.IsMsg = setting[MsgModLineName].GetBool(modModel.ID);
modModel.IsMsg = setting[MsgModLineName].Contains(modModel.Name); modModel.IsPass = setting[PassModLineName].Contains(modID);
Mods.Add(modModel); Mods.Add(modModel);
} }
else else
@ -51,8 +51,8 @@ public class ModSettingModel : ObservableClass<ModSettingModel>
Mods.Add( Mods.Add(
new() new()
{ {
Name = modName, Name = modID,
ModPath = "未知, 可能是{0}".Translate(Path.Combine(ModDirectory, modName)) ModPath = "未知, 可能是{0}".Translate(Path.Combine(ModDirectory, modID))
} }
); );
} }
@ -60,15 +60,17 @@ public class ModSettingModel : ObservableClass<ModSettingModel>
foreach (var modPath in setting[WorkShopLineName]) foreach (var modPath in setting[WorkShopLineName])
{ {
var loader = new ModLoader(modPath.Name); var loader = new ModLoader(modPath.Name);
if (loader.IsSuccesses is false) if (loader.IsSuccesses)
{
var modModel = new ModModel(loader);
modModel.IsMsg = setting[MsgModLineName].GetBool(modModel.ID);
modModel.IsPass = setting[PassModLineName].Contains(modModel.ID.ToLower());
Mods.Add(modModel);
}
else
{ {
Mods.Add(new() { Name = loader.Name, ModPath = loader.ModPath }); Mods.Add(new() { Name = loader.Name, ModPath = loader.ModPath });
return;
} }
var modModel = new ModModel(loader);
modModel.IsPass = setting[PassModLineName].Contains(modModel.Name);
modModel.IsMsg = setting[MsgModLineName].Contains(modModel.Name);
Mods.Add(modModel);
} }
} }
@ -107,10 +109,10 @@ public class ModSettingModel : ObservableClass<ModSettingModel>
return; return;
foreach (var mod in Mods) foreach (var mod in Mods)
{ {
setting[ModLineName].Add(new Sub(mod.Name.ToLower())); setting[ModLineName].Add(new Sub(mod.ID.ToLower()));
setting[MsgModLineName].Add(new Sub(mod.Name, "True")); setting[MsgModLineName].Add(new Sub(mod.ID, "True"));
if (mod.IsPass) if (mod.IsPass)
setting[PassModLineName].Add(new Sub(mod.Name.ToLower())); setting[PassModLineName].Add(new Sub(mod.ID.ToLower()));
} }
} }
#endregion #endregion
@ -118,6 +120,15 @@ public class ModSettingModel : ObservableClass<ModSettingModel>
public class ModModel : ObservableClass<ModModel> public class ModModel : ObservableClass<ModModel>
{ {
#region ID
private string _id;
public string ID
{
get => _id;
set => SetProperty(ref _id, value);
}
#endregion
#region Name #region Name
private string _name; private string _name;
@ -311,6 +322,7 @@ public class ModModel : ObservableClass<ModModel>
PropertyChanged += ModModel_PropertyChanged; PropertyChanged += ModModel_PropertyChanged;
ReflectionUtils.SetValue(loader, this); ReflectionUtils.SetValue(loader, this);
RefreshState(); RefreshState();
ID = Name;
Name = Name.Translate(); Name = Name.Translate();
Description = Description.Translate(); Description = Description.Translate();
LocalizeCore.BindingNotify.PropertyChanged += BindingNotify_PropertyChanged; LocalizeCore.BindingNotify.PropertyChanged += BindingNotify_PropertyChanged;

View File

@ -23,18 +23,18 @@ public class SettingModel : ObservableClass<SettingModel>
/// </summary> /// </summary>
public string FilePath { get; set; } public string FilePath { get; set; }
//#region IsChanged #region IsChanged
//private bool _isChanged; private bool _isChanged;
///// <summary> /// <summary>
///// 已更改 /// 已更改
///// </summary> /// </summary>
//public bool IsChanged public bool IsChanged
//{ {
// get => _isChanged; get => _isChanged;
// set => SetProperty(ref _isChanged, value); set => SetProperty(ref _isChanged, value);
//} }
//#endregion #endregion
#region GraphicsSetting #region GraphicsSetting
private GraphicsSettingModel _graphicsSetting; private GraphicsSettingModel _graphicsSetting;
@ -117,24 +117,24 @@ public class SettingModel : ObservableClass<SettingModel>
DiagnosticSetting.GetAutoCalFromSetting(setting); DiagnosticSetting.GetAutoCalFromSetting(setting);
ModSetting = LoadModSetting(setting); ModSetting = LoadModSetting(setting);
//MergeNotify(); MergePropertyChangedNotify();
} }
//private void MergeNotify() private void MergePropertyChangedNotify()
//{ {
// var accessor = ObjectAccessor.Create(this); var accessor = ObjectAccessor.Create(this);
// foreach (var property in typeof(SettingModel).GetProperties()) foreach (var property in typeof(SettingModel).GetProperties())
// { {
// var value = accessor[property.Name]; var value = accessor[property.Name];
// if (value is INotifyPropertyChanged model) if (value is INotifyPropertyChanged model)
// model.PropertyChanged += Notify_PropertyChanged; model.PropertyChanged += Notify_PropertyChanged;
// } }
//} }
//private void Notify_PropertyChanged(object sender, PropertyChangedEventArgs e) private void Notify_PropertyChanged(object sender, PropertyChangedEventArgs e)
//{ {
// IsChanged = true; IsChanged = true;
//} }
private ModSettingModel LoadModSetting(Setting setting) private ModSettingModel LoadModSetting(Setting setting)
{ {
@ -176,6 +176,7 @@ public class SettingModel : ObservableClass<SettingModel>
_setting[CustomizedSettingModel.TargetName].Add(new Sub(link.Name, link.Link)); _setting[CustomizedSettingModel.TargetName].Add(new Sub(link.Name, link.Link));
ModSetting.Save(_setting); ModSetting.Save(_setting);
File.WriteAllText(FilePath, _setting.ToString()); File.WriteAllText(FilePath, _setting.ToString());
IsChanged = false;
} }
private void SaveSetting(object settingModel) private void SaveSetting(object settingModel)

View File

@ -369,6 +369,11 @@ public static class Extensions
return; return;
if (_windowCloseStates.TryGetValue(window, out var state) is false) if (_windowCloseStates.TryGetValue(window, out var state) is false)
return; return;
if (state.HasFlag(WindowCloseState.SkipNext))
{
_windowCloseStates[window] = state &= WindowCloseState.SkipNext;
return;
}
if (state is WindowCloseState.Close) if (state is WindowCloseState.Close)
return; return;
e.Cancel = true; e.Cancel = true;
@ -378,11 +383,13 @@ public static class Extensions
} }
} }
[Flags]
public enum WindowCloseState public enum WindowCloseState
{ {
Close, SkipNext = 0,
Hidden, Close = 1 << 0,
Collapsed Hidden = 1 << 1,
Collapsed = 1 << 2
} }
/// <summary> /// <summary>

View File

@ -61,7 +61,9 @@ public class MainWindowVM : ObservableClass<MainWindowVM>
{ {
SetProperty(ref _currentCulture, value); SetProperty(ref _currentCulture, value);
LocalizeCore.LoadCulture(_currentCulture); LocalizeCore.LoadCulture(_currentCulture);
if (_mainSetting is not null) if (
_mainSetting is not null && _mainSetting.GraphicsSetting.Language != _currentCulture
)
{ {
_mainSetting.GraphicsSetting.Language = _currentCulture; _mainSetting.GraphicsSetting.Language = _currentCulture;
_mainSetting.Save(); _mainSetting.Save();

View File

@ -25,7 +25,30 @@ public class SettingWindowVM : ObservableClass<SettingWindowVM>
public SettingModel CurrentSetting public SettingModel CurrentSetting
{ {
get => _currentSetting; get => _currentSetting;
set { SetProperty(ref _currentSetting, value); } set
{
if (_currentSetting?.IsChanged is true)
{
var result = MessageBox.Show(
"当前设置未保存 确定要保存吗".Translate(),
"",
MessageBoxButton.YesNoCancel
);
if (result is MessageBoxResult.Yes)
{
_currentSetting.Save();
}
else if (result is MessageBoxResult.No)
{
_currentSetting.IsChanged = false;
}
else if (result is MessageBoxResult.Cancel)
{
return;
}
}
SetProperty(ref _currentSetting, value);
}
} }
private readonly ObservableCollection<SettingModel> _settings = new(); private readonly ObservableCollection<SettingModel> _settings = new();

View File

@ -15,8 +15,33 @@
MinWidth="400" MinWidth="400"
MinHeight="200" MinHeight="200"
d:DataContext="{d:DesignInstance Type=vm:SettingWindowVM}" d:DataContext="{d:DesignInstance Type=vm:SettingWindowVM}"
Closing="SettingWindow_Closing"
WindowStartupLocation="CenterScreen" WindowStartupLocation="CenterScreen"
mc:Ignorable="d"> mc:Ignorable="d">
<Window.Resources>
<Style
x:Key="RemindStyle"
BasedOn="{StaticResource Button_BaseStyle}"
TargetType="Button">
<Style.Triggers>
<DataTrigger Binding="{Binding Tag, RelativeSource={RelativeSource Mode=Self}}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard x:Name="RemindSaveStoryboard">
<Storyboard RepeatBehavior="Forever">
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="Background.Color">
<DiscreteColorKeyFrame KeyTime="0:0:1" Value="Aqua" />
<DiscreteColorKeyFrame KeyTime="0:0:1.5" Value="#00FFFFFF" />
</ColorAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<RemoveStoryboard BeginStoryboardName="RemindSaveStoryboard" />
</DataTrigger.ExitActions>
</DataTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="100" /> <ColumnDefinition Width="Auto" MinWidth="100" />
@ -115,7 +140,8 @@
Command="{Binding SaveSettingCommand}" Command="{Binding SaveSettingCommand}"
CommandParameter="{Binding SelectedItem, ElementName=ListBox_Saves}" CommandParameter="{Binding SelectedItem, ElementName=ListBox_Saves}"
Content="{ll:Str 保存}" Content="{ll:Str 保存}"
Style="{StaticResource Button_BaseStyle}" /> Style="{StaticResource RemindStyle}"
Tag="{Binding CurrentSetting.IsChanged}" />
<Button <Button
Grid.Column="3" Grid.Column="3"
Margin="0" Margin="0"

View File

@ -1,4 +1,5 @@
using HKW.HKWUtils; using HKW.HKWUtils;
using LinePutScript.Localization.WPF;
using Panuon.WPF.UI; using Panuon.WPF.UI;
using System.ComponentModel; using System.ComponentModel;
using System.Windows; using System.Windows;
@ -31,6 +32,35 @@ public partial class SettingWindow : WindowX
Instance = this; Instance = this;
} }
private void SettingWindow_Closing(object sender, CancelEventArgs e)
{
if (ViewModel?.CurrentSetting?.IsChanged is true)
{
if (ViewModel?.CurrentSetting?.IsChanged is true)
{
this.SetCloseState(WindowCloseState.Hidden | WindowCloseState.SkipNext);
var result = MessageBox.Show(
"当前设置未保存 确定要保存吗".Translate(),
"",
MessageBoxButton.YesNoCancel
);
if (result is MessageBoxResult.Yes)
{
ViewModel.CurrentSetting.Save();
Close();
}
else if (result is MessageBoxResult.No)
{
ViewModel.CurrentSetting.IsChanged = false;
}
else if (result is MessageBoxResult.Cancel)
{
e.Cancel = true;
}
}
}
}
private void Frame_Main_ContentRendered(object sender, EventArgs e) private void Frame_Main_ContentRendered(object sender, EventArgs e)
{ {
if (sender is not Frame frame) if (sender is not Frame frame)