mirror of
https://github.com/LorisYounger/VPet.git
synced 2024-08-30 18:42:36 +00:00
# VPet.Solution
## 新增 - 设置编辑页面的保存按钮高亮提示 ## 修复 - 设置编辑的模组信息载入问题
This commit is contained in:
parent
47857aab8f
commit
72197f0195
@ -38,12 +38,12 @@ public class ModSettingModel : ObservableClass<ModSettingModel>
|
||||
LocalMods ??= GetLocalMods();
|
||||
foreach (var item in setting[ModLineName])
|
||||
{
|
||||
var modName = item.Name;
|
||||
if (LocalMods.TryGetValue(modName, out var loader) && loader.IsSuccesses)
|
||||
var modID = item.Name;
|
||||
if (LocalMods.TryGetValue(modID, out var loader) && loader.IsSuccesses)
|
||||
{
|
||||
var modModel = new ModModel(loader);
|
||||
modModel.IsPass = setting[PassModLineName].Contains(modName);
|
||||
modModel.IsMsg = setting[MsgModLineName].Contains(modModel.Name);
|
||||
modModel.IsMsg = setting[MsgModLineName].GetBool(modModel.ID);
|
||||
modModel.IsPass = setting[PassModLineName].Contains(modID);
|
||||
Mods.Add(modModel);
|
||||
}
|
||||
else
|
||||
@ -51,8 +51,8 @@ public class ModSettingModel : ObservableClass<ModSettingModel>
|
||||
Mods.Add(
|
||||
new()
|
||||
{
|
||||
Name = modName,
|
||||
ModPath = "未知, 可能是{0}".Translate(Path.Combine(ModDirectory, modName))
|
||||
Name = modID,
|
||||
ModPath = "未知, 可能是{0}".Translate(Path.Combine(ModDirectory, modID))
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -60,15 +60,17 @@ public class ModSettingModel : ObservableClass<ModSettingModel>
|
||||
foreach (var modPath in setting[WorkShopLineName])
|
||||
{
|
||||
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 });
|
||||
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;
|
||||
foreach (var mod in Mods)
|
||||
{
|
||||
setting[ModLineName].Add(new Sub(mod.Name.ToLower()));
|
||||
setting[MsgModLineName].Add(new Sub(mod.Name, "True"));
|
||||
setting[ModLineName].Add(new Sub(mod.ID.ToLower()));
|
||||
setting[MsgModLineName].Add(new Sub(mod.ID, "True"));
|
||||
if (mod.IsPass)
|
||||
setting[PassModLineName].Add(new Sub(mod.Name.ToLower()));
|
||||
setting[PassModLineName].Add(new Sub(mod.ID.ToLower()));
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
@ -118,6 +120,15 @@ public class ModSettingModel : ObservableClass<ModSettingModel>
|
||||
|
||||
public class ModModel : ObservableClass<ModModel>
|
||||
{
|
||||
#region ID
|
||||
private string _id;
|
||||
public string ID
|
||||
{
|
||||
get => _id;
|
||||
set => SetProperty(ref _id, value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Name
|
||||
private string _name;
|
||||
|
||||
@ -311,6 +322,7 @@ public class ModModel : ObservableClass<ModModel>
|
||||
PropertyChanged += ModModel_PropertyChanged;
|
||||
ReflectionUtils.SetValue(loader, this);
|
||||
RefreshState();
|
||||
ID = Name;
|
||||
Name = Name.Translate();
|
||||
Description = Description.Translate();
|
||||
LocalizeCore.BindingNotify.PropertyChanged += BindingNotify_PropertyChanged;
|
||||
|
@ -23,18 +23,18 @@ public class SettingModel : ObservableClass<SettingModel>
|
||||
/// </summary>
|
||||
public string FilePath { get; set; }
|
||||
|
||||
//#region IsChanged
|
||||
//private bool _isChanged;
|
||||
#region IsChanged
|
||||
private bool _isChanged;
|
||||
|
||||
///// <summary>
|
||||
///// 已更改
|
||||
///// </summary>
|
||||
//public bool IsChanged
|
||||
//{
|
||||
// get => _isChanged;
|
||||
// set => SetProperty(ref _isChanged, value);
|
||||
//}
|
||||
//#endregion
|
||||
/// <summary>
|
||||
/// 已更改
|
||||
/// </summary>
|
||||
public bool IsChanged
|
||||
{
|
||||
get => _isChanged;
|
||||
set => SetProperty(ref _isChanged, value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GraphicsSetting
|
||||
private GraphicsSettingModel _graphicsSetting;
|
||||
@ -117,24 +117,24 @@ public class SettingModel : ObservableClass<SettingModel>
|
||||
DiagnosticSetting.GetAutoCalFromSetting(setting);
|
||||
|
||||
ModSetting = LoadModSetting(setting);
|
||||
//MergeNotify();
|
||||
MergePropertyChangedNotify();
|
||||
}
|
||||
|
||||
//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 MergePropertyChangedNotify()
|
||||
{
|
||||
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 void Notify_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
IsChanged = true;
|
||||
}
|
||||
|
||||
private ModSettingModel LoadModSetting(Setting setting)
|
||||
{
|
||||
@ -176,6 +176,7 @@ public class SettingModel : ObservableClass<SettingModel>
|
||||
_setting[CustomizedSettingModel.TargetName].Add(new Sub(link.Name, link.Link));
|
||||
ModSetting.Save(_setting);
|
||||
File.WriteAllText(FilePath, _setting.ToString());
|
||||
IsChanged = false;
|
||||
}
|
||||
|
||||
private void SaveSetting(object settingModel)
|
||||
|
@ -369,6 +369,11 @@ public static class Extensions
|
||||
return;
|
||||
if (_windowCloseStates.TryGetValue(window, out var state) is false)
|
||||
return;
|
||||
if (state.HasFlag(WindowCloseState.SkipNext))
|
||||
{
|
||||
_windowCloseStates[window] = state &= WindowCloseState.SkipNext;
|
||||
return;
|
||||
}
|
||||
if (state is WindowCloseState.Close)
|
||||
return;
|
||||
e.Cancel = true;
|
||||
@ -378,11 +383,13 @@ public static class Extensions
|
||||
}
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum WindowCloseState
|
||||
{
|
||||
Close,
|
||||
Hidden,
|
||||
Collapsed
|
||||
SkipNext = 0,
|
||||
Close = 1 << 0,
|
||||
Hidden = 1 << 1,
|
||||
Collapsed = 1 << 2
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -61,7 +61,9 @@ public class MainWindowVM : ObservableClass<MainWindowVM>
|
||||
{
|
||||
SetProperty(ref _currentCulture, value);
|
||||
LocalizeCore.LoadCulture(_currentCulture);
|
||||
if (_mainSetting is not null)
|
||||
if (
|
||||
_mainSetting is not null && _mainSetting.GraphicsSetting.Language != _currentCulture
|
||||
)
|
||||
{
|
||||
_mainSetting.GraphicsSetting.Language = _currentCulture;
|
||||
_mainSetting.Save();
|
||||
|
@ -25,7 +25,30 @@ public class SettingWindowVM : ObservableClass<SettingWindowVM>
|
||||
public SettingModel 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();
|
||||
|
@ -15,8 +15,33 @@
|
||||
MinWidth="400"
|
||||
MinHeight="200"
|
||||
d:DataContext="{d:DesignInstance Type=vm:SettingWindowVM}"
|
||||
Closing="SettingWindow_Closing"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
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.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" MinWidth="100" />
|
||||
@ -115,7 +140,8 @@
|
||||
Command="{Binding SaveSettingCommand}"
|
||||
CommandParameter="{Binding SelectedItem, ElementName=ListBox_Saves}"
|
||||
Content="{ll:Str 保存}"
|
||||
Style="{StaticResource Button_BaseStyle}" />
|
||||
Style="{StaticResource RemindStyle}"
|
||||
Tag="{Binding CurrentSetting.IsChanged}" />
|
||||
<Button
|
||||
Grid.Column="3"
|
||||
Margin="0"
|
||||
|
@ -1,4 +1,5 @@
|
||||
using HKW.HKWUtils;
|
||||
using LinePutScript.Localization.WPF;
|
||||
using Panuon.WPF.UI;
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
@ -31,6 +32,35 @@ public partial class SettingWindow : WindowX
|
||||
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)
|
||||
{
|
||||
if (sender is not Frame frame)
|
||||
|
Loading…
Reference in New Issue
Block a user