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
cae830a086
commit
e26fb9b792
@ -1,5 +1,6 @@
|
||||
using HKW.HKWUtils.Observable;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using VPet_Simulator.Core;
|
||||
|
||||
namespace VPet.Solution.Models.SettingEditor;
|
||||
@ -165,11 +166,12 @@ public class InteractiveSettingModel : ObservableClass<InteractiveSettingModel>
|
||||
#endregion
|
||||
|
||||
#region SmartMoveInterval
|
||||
private int _smartMoveInterval;
|
||||
private int _smartMoveInterval = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 智能移动周期 (秒)
|
||||
/// </summary>
|
||||
[DefaultValue(1)]
|
||||
[ReflectionProperty(nameof(VPet_Simulator.Windows.Interface.Setting.SmartMoveInterval))]
|
||||
[ReflectionPropertyConverter(typeof(SecondToMinuteConverter))]
|
||||
public int SmartMoveInterval
|
||||
@ -178,7 +180,7 @@ public class InteractiveSettingModel : ObservableClass<InteractiveSettingModel>
|
||||
set => SetProperty(ref _smartMoveInterval, value);
|
||||
}
|
||||
|
||||
public static ObservableCollection<int> SmartMoveIntervals =
|
||||
public static ObservableCollection<int> SmartMoveIntervals { get; } =
|
||||
new() { 1, 2, 5, 10, 20, 30, 40, 50, 60 };
|
||||
#endregion
|
||||
|
||||
@ -197,13 +199,14 @@ public class InteractiveSettingModel : ObservableClass<InteractiveSettingModel>
|
||||
#endregion
|
||||
|
||||
#region MusicCatch
|
||||
private double _musicCatch;
|
||||
private int _musicCatch;
|
||||
|
||||
/// <summary>
|
||||
/// 当实时播放音量达到该值时运行音乐动作
|
||||
/// </summary>
|
||||
[ReflectionProperty(nameof(VPet_Simulator.Windows.Interface.Setting.MusicCatch))]
|
||||
public double MusicCatch
|
||||
[ReflectionPropertyConverter(typeof(DoubleToInt32Converter))]
|
||||
public int MusicCatch
|
||||
{
|
||||
get => _musicCatch;
|
||||
set => SetProperty(ref _musicCatch, value);
|
||||
@ -211,13 +214,14 @@ public class InteractiveSettingModel : ObservableClass<InteractiveSettingModel>
|
||||
#endregion
|
||||
|
||||
#region MusicMax
|
||||
private double _musicMax;
|
||||
private int _musicMax;
|
||||
|
||||
/// <summary>
|
||||
/// 当实时播放音量达到该值时运行特殊音乐动作
|
||||
/// </summary>
|
||||
[ReflectionProperty(nameof(VPet_Simulator.Windows.Interface.Setting.MusicMax))]
|
||||
public double MusicMax
|
||||
[ReflectionPropertyConverter(typeof(DoubleToInt32Converter))]
|
||||
public int MusicMax
|
||||
{
|
||||
get => _musicMax;
|
||||
set => SetProperty(ref _musicMax, value);
|
||||
@ -281,14 +285,27 @@ public class SecondToMinuteConverter : ReflectionConverterBase<int, int>
|
||||
{
|
||||
public override int Convert(int sourceValue)
|
||||
{
|
||||
if (sourceValue == 30)
|
||||
return 1;
|
||||
else
|
||||
return sourceValue / 60;
|
||||
return sourceValue * 60;
|
||||
}
|
||||
|
||||
public override int ConvertBack(int targetValue)
|
||||
{
|
||||
return targetValue * 60;
|
||||
if (targetValue == 30)
|
||||
return 1;
|
||||
else
|
||||
return targetValue / 60;
|
||||
}
|
||||
}
|
||||
|
||||
public class DoubleToInt32Converter : ReflectionConverterBase<int, double>
|
||||
{
|
||||
public override double Convert(int sourceValue)
|
||||
{
|
||||
return sourceValue;
|
||||
}
|
||||
|
||||
public override int ConvertBack(double targetValue)
|
||||
{
|
||||
return System.Convert.ToInt32(targetValue);
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,7 @@
|
||||
x:Key="TextBlock_BaseStyle"
|
||||
BasedOn="{StaticResource {x:Type TextBlock}}"
|
||||
TargetType="TextBlock">
|
||||
<Setter Property="Margin" Value="10,5,10,5" />
|
||||
<Setter Property="Margin" Value="5" />
|
||||
<Setter Property="VerticalAlignment" Value="Center" />
|
||||
<Setter Property="HorizontalAlignment" Value="Center" />
|
||||
<Setter Property="ToolTip" Value="{Binding Text, RelativeSource={RelativeSource Mode=Self}}" />
|
||||
@ -139,7 +139,7 @@
|
||||
</Style>
|
||||
<Style x:Key="Switch_BaseStyle" TargetType="pu:Switch">
|
||||
<Setter Property="HorizontalAlignment" Value="Left" />
|
||||
<Setter Property="Margin" Value="10,5,10,5" />
|
||||
<Setter Property="Margin" Value="5" />
|
||||
<Setter Property="Background" Value="{x:Null}" />
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource PrimaryDark}" />
|
||||
<Setter Property="BoxHeight" Value="20" />
|
||||
@ -152,7 +152,7 @@
|
||||
</Style>
|
||||
<Style x:Key="Label_BaseStyle" TargetType="Label">
|
||||
<Setter Property="FontSize" Value="14" />
|
||||
<Setter Property="Margin" Value="10,0,10,0" />
|
||||
<Setter Property="Margin" Value="10,5,10,5" />
|
||||
<Setter Property="Height" Value="30" />
|
||||
<Setter Property="HorizontalContentAlignment" Value="Center" />
|
||||
<Setter Property="VerticalContentAlignment" Value="Center" />
|
||||
@ -160,7 +160,7 @@
|
||||
</Style>
|
||||
<Style x:Key="NumberInput_BaseStyle" TargetType="pu:NumberInput">
|
||||
<Setter Property="Height" Value="30" />
|
||||
<Setter Property="Margin" Value="10,5,10,5" />
|
||||
<Setter Property="Margin" Value="5" />
|
||||
<Setter Property="VerticalAlignment" Value="Center" />
|
||||
<Setter Property="Background" Value="{x:Null}" />
|
||||
<Setter Property="FontSize" Value="14" />
|
||||
@ -171,8 +171,8 @@
|
||||
x:Key="Button_BaseStyle"
|
||||
BasedOn="{StaticResource {x:Type Button}}"
|
||||
TargetType="Button">
|
||||
<Setter Property="Margin" Value="10,5,10,5" />
|
||||
<Setter Property="Padding" Value="10,5,10,5" />
|
||||
<Setter Property="Margin" Value="5" />
|
||||
<Setter Property="Padding" Value="5" />
|
||||
<Setter Property="HorizontalAlignment" Value="Center" />
|
||||
<Setter Property="VerticalAlignment" Value="Center" />
|
||||
<Setter Property="pu:ButtonHelper.CornerRadius" Value="4" />
|
||||
@ -184,7 +184,7 @@
|
||||
x:Key="ComboBox_BaseStyle"
|
||||
BasedOn="{StaticResource StandardComboBoxStyle}"
|
||||
TargetType="ComboBox">
|
||||
<Setter Property="Margin" Value="10,5,10,5" />
|
||||
<Setter Property="Margin" Value="5" />
|
||||
</Style>
|
||||
<Style
|
||||
x:Key="Expander_BaseStyle"
|
||||
@ -202,7 +202,7 @@
|
||||
BasedOn="{StaticResource StandardSliderStyle}"
|
||||
TargetType="Slider">
|
||||
<Setter Property="IsSnapToTickEnabled" Value="True" />
|
||||
<Setter Property="Margin" Value="10,5,10,5" />
|
||||
<Setter Property="Margin" Value="5" />
|
||||
<Setter Property="VerticalAlignment" Value="Center" />
|
||||
</Style>
|
||||
</ResourceDictionary>
|
@ -14,6 +14,8 @@ public static class ReflectionUtils
|
||||
private static readonly BindingFlags _propertyBindingFlags =
|
||||
BindingFlags.Instance | BindingFlags.Public;
|
||||
|
||||
private static readonly Dictionary<Type, IReflectionConverter> _reflectionConverters = new();
|
||||
|
||||
/// <summary>
|
||||
/// 类型信息
|
||||
/// <para>
|
||||
@ -102,7 +104,19 @@ public static class ReflectionUtils
|
||||
is ReflectionPropertyConverterAttribute propertyConverterAttribute
|
||||
)
|
||||
{
|
||||
propertyInfo.Converter = propertyConverterAttribute.Converter;
|
||||
if (
|
||||
_reflectionConverters.TryGetValue(
|
||||
propertyConverterAttribute.ConverterType,
|
||||
out var converter
|
||||
)
|
||||
is false
|
||||
)
|
||||
converter = _reflectionConverters[propertyConverterAttribute.ConverterType] =
|
||||
(IReflectionConverter)
|
||||
TypeAccessor
|
||||
.Create(propertyConverterAttribute.ConverterType)
|
||||
.CreateNew();
|
||||
propertyInfo.Converter = converter;
|
||||
}
|
||||
objectInfo.PropertyInfos[property.Name] = propertyInfo;
|
||||
}
|
||||
@ -189,11 +203,11 @@ public class ReflectionPropertyConverterAttribute : Attribute
|
||||
/// <summary>
|
||||
/// 反射转换器
|
||||
/// </summary>
|
||||
public IReflectionConverter Converter { get; }
|
||||
public Type ConverterType { get; }
|
||||
|
||||
public ReflectionPropertyConverterAttribute(Type converterType)
|
||||
{
|
||||
Converter = (IReflectionConverter)TypeAccessor.Create(converterType).CreateNew();
|
||||
ConverterType = converterType;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -77,9 +77,8 @@ public class SettingWindowVM : ObservableClass<SettingWindowVM>
|
||||
{
|
||||
Current = this;
|
||||
ShowSettings = _settings;
|
||||
LoadSettings();
|
||||
|
||||
foreach (var s in LoadSettings())
|
||||
_settings.Add(s);
|
||||
PropertyChanged += MainWindowVM_PropertyChanged;
|
||||
OpenFileCommand.ExecuteCommand += OpenFileCommand_ExecuteCommand;
|
||||
OpenFileInExplorerCommand.ExecuteCommand += OpenFileInExplorerCommand_ExecuteCommand;
|
||||
@ -159,27 +158,47 @@ public class SettingWindowVM : ObservableClass<SettingWindowVM>
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<SettingModel> LoadSettings()
|
||||
private void LoadSettings()
|
||||
{
|
||||
foreach (
|
||||
var file in Directory
|
||||
.EnumerateFiles(Environment.CurrentDirectory)
|
||||
.Where(
|
||||
(s) =>
|
||||
{
|
||||
if (s.EndsWith(".lps") is false)
|
||||
return false;
|
||||
return Path.GetFileName(s).StartsWith("Setting");
|
||||
}
|
||||
)
|
||||
)
|
||||
foreach (var file in GetSettingFiles())
|
||||
{
|
||||
var setting = new Setting(File.ReadAllText(file));
|
||||
yield return new SettingModel(setting)
|
||||
var fileName = Path.GetFileNameWithoutExtension(file);
|
||||
try
|
||||
{
|
||||
Name = Path.GetFileNameWithoutExtension(file),
|
||||
FilePath = file
|
||||
};
|
||||
var setting = new Setting(File.ReadAllText(file));
|
||||
var settingModel = new SettingModel(setting) { Name = fileName, FilePath = file };
|
||||
_settings.Add(settingModel);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (
|
||||
MessageBox.Show(
|
||||
"设置载入失败, 是否强制载入并重置\n[是]: 载入并重置\t[否]: 取消载入\n名称: {0}\n路径: {1}\n{2}".Translate(
|
||||
fileName,
|
||||
file,
|
||||
ex.ToString()
|
||||
),
|
||||
"载入设置出错".Translate(),
|
||||
MessageBoxButton.YesNo,
|
||||
MessageBoxImage.Warning
|
||||
) is MessageBoxResult.Yes
|
||||
)
|
||||
_settings.Add(new SettingModel() { Name = fileName, FilePath = file });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<string> GetSettingFiles()
|
||||
{
|
||||
return Directory
|
||||
.EnumerateFiles(Environment.CurrentDirectory)
|
||||
.Where(
|
||||
(s) =>
|
||||
{
|
||||
if (s.EndsWith(".lps") is false)
|
||||
return false;
|
||||
return Path.GetFileName(s).StartsWith("Setting");
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -54,6 +54,7 @@
|
||||
<!-- TODO: ComboBox使用内部数据 -->
|
||||
<ComboBox
|
||||
Grid.Column="2"
|
||||
Margin="0,5,10,5"
|
||||
pu:ComboBoxHelper.Watermark="{ll:Str '当关闭数据计算时\ 桌宠显示的状态'}"
|
||||
IsEnabled="{Binding IsChecked, ElementName=Switch_EnablePetState, Converter={StaticResource BoolInverter}}"
|
||||
ItemsSource="{Binding InteractiveSetting.ModeTypes}"
|
||||
@ -75,23 +76,24 @@
|
||||
VerticalAlignment="Center"
|
||||
LargeChange="0.1"
|
||||
Maximum="5"
|
||||
Minimum="0.05"
|
||||
SmallChange=".05"
|
||||
Minimum="0.5"
|
||||
SmallChange="0.5"
|
||||
Style="{DynamicResource Slider_BaseStyle}"
|
||||
TickFrequency="0.01"
|
||||
TickFrequency="0.5"
|
||||
Value="{Binding InteractiveSetting.PressLength}" />
|
||||
<pu:NumberInput
|
||||
Grid.Column="2"
|
||||
MinWidth="80"
|
||||
Interval="0.1"
|
||||
Maximum="5"
|
||||
Minimum="0.05"
|
||||
Style="{DynamicResource NumberInput_BaseStyle}"
|
||||
Value="{Binding Value, ElementName=PressLengthSlider}" />
|
||||
<TextBlock
|
||||
<Label
|
||||
Grid.Column="3"
|
||||
Margin="0,5,10,5"
|
||||
Style="{DynamicResource TextBlock_BaseStyle}"
|
||||
Text="{ll:Str 秒}" />
|
||||
Content="{ll:Str 秒}"
|
||||
Style="{DynamicResource Label_BaseStyle}" />
|
||||
</Grid>
|
||||
<Grid MinHeight="40">
|
||||
<Grid.ColumnDefinitions>
|
||||
@ -108,22 +110,23 @@
|
||||
LargeChange="1"
|
||||
Maximum="60"
|
||||
Minimum="5"
|
||||
SmallChange=".5"
|
||||
SmallChange="0.5"
|
||||
Style="{DynamicResource Slider_BaseStyle}"
|
||||
TickFrequency="0.1"
|
||||
Value="{Binding InteractiveSetting.LogicInterval}" />
|
||||
<pu:NumberInput
|
||||
Grid.Column="2"
|
||||
MinWidth="80"
|
||||
Interval="0.5"
|
||||
Maximum="60"
|
||||
Minimum="5"
|
||||
Style="{DynamicResource NumberInput_BaseStyle}"
|
||||
Value="{Binding Value, ElementName=Slider_Cal}" />
|
||||
<TextBlock
|
||||
<Label
|
||||
Grid.Column="3"
|
||||
Margin="0,5,10,5"
|
||||
Style="{DynamicResource TextBlock_BaseStyle}"
|
||||
Text="{ll:Str 秒}" />
|
||||
Content="{ll:Str 秒}"
|
||||
Style="{DynamicResource Label_BaseStyle}" />
|
||||
</Grid>
|
||||
<Grid MinHeight="40" ToolTip="{ll:Str 互动周期决定在交互结束后大约经历多少计算间隔后再次进行自主行动}">
|
||||
<Grid.ColumnDefinitions>
|
||||
@ -143,6 +146,7 @@
|
||||
</Grid.RowDefinitions>
|
||||
<Slider
|
||||
x:Name="Slider_Interaction"
|
||||
d:Value="1000"
|
||||
LargeChange="5"
|
||||
Maximum="1000"
|
||||
Minimum="30"
|
||||
@ -153,16 +157,17 @@
|
||||
Value="{Binding InteractiveSetting.InteractionCycle}" />
|
||||
<pu:NumberInput
|
||||
Grid.Column="1"
|
||||
MinWidth="80"
|
||||
Interval="1"
|
||||
Maximum="1000"
|
||||
Minimum="30"
|
||||
Style="{DynamicResource NumberInput_BaseStyle}"
|
||||
Value="{Binding ElementName=Slider_Interaction, Path=Value}" />
|
||||
<TextBlock
|
||||
<Label
|
||||
Grid.Column="2"
|
||||
Margin="0,5,10,5"
|
||||
Style="{DynamicResource TextBlock_BaseStyle}"
|
||||
Text="{ll:Str 秒}" />
|
||||
Content="{ll:Str 秒}"
|
||||
Style="{DynamicResource Label_BaseStyle}" />
|
||||
<TextBlock
|
||||
Grid.Row="1"
|
||||
Grid.ColumnSpan="3"
|
||||
@ -204,10 +209,10 @@
|
||||
SelectedItem="{Binding InteractiveSetting.SmartMoveInterval}"
|
||||
Style="{DynamicResource StandardComboBoxStyle}"
|
||||
ToolTip="{ll:Str 智能移动判断时间间隔}" />
|
||||
<TextBlock
|
||||
<Label
|
||||
Grid.Column="4"
|
||||
Style="{DynamicResource TextBlock_BaseStyle}"
|
||||
Text="{ll:Str 分钟}" />
|
||||
Content="{ll:Str 分钟}"
|
||||
Style="{DynamicResource Label_BaseStyle}" />
|
||||
</Grid>
|
||||
<!-- TODO: 移动范围设置 -->
|
||||
<!--<Grid MinHeight="40">
|
||||
@ -286,16 +291,18 @@
|
||||
Value="{Binding InteractiveSetting.MusicCatch}" />
|
||||
<pu:NumberInput
|
||||
Grid.Column="2"
|
||||
MinWidth="80"
|
||||
Interval="1"
|
||||
Maximum="100"
|
||||
Minimum="0"
|
||||
Style="{DynamicResource NumberInput_BaseStyle}"
|
||||
ToolTip="{ll:Str 当实时播放音量达到该值时运行特殊音乐动作}"
|
||||
Value="{Binding Value, ElementName=VoiceCatchSilder}" />
|
||||
<TextBlock
|
||||
<Label
|
||||
Grid.Column="3"
|
||||
Margin="0,5,10,5"
|
||||
Text="%" />
|
||||
Content="%"
|
||||
Style="{DynamicResource Label_BaseStyle}" />
|
||||
</Grid>
|
||||
<Grid MinHeight="40">
|
||||
<Grid.ColumnDefinitions>
|
||||
@ -321,6 +328,7 @@
|
||||
Value="{Binding InteractiveSetting.MusicMax}" />
|
||||
<pu:NumberInput
|
||||
Grid.Column="2"
|
||||
MinWidth="80"
|
||||
Foreground="{DynamicResource DARKPrimaryDarker}"
|
||||
Interval="1"
|
||||
Maximum="100"
|
||||
@ -328,10 +336,11 @@
|
||||
Style="{DynamicResource NumberInput_BaseStyle}"
|
||||
ToolTip="{ll:Str 当实时播放音量达到该值时运行特殊音乐动作}"
|
||||
Value="{Binding Value, ElementName=VoiceMaxSilder}" />
|
||||
<TextBlock
|
||||
<Label
|
||||
Grid.Column="3"
|
||||
Margin="0,5,10,5"
|
||||
Text="%" />
|
||||
Content="%"
|
||||
Style="{DynamicResource Label_BaseStyle}" />
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
|
Loading…
Reference in New Issue
Block a user