diff --git a/OngekiFumenEditor/App.config b/OngekiFumenEditor/App.config index 92e5f623..61ab28dc 100644 --- a/OngekiFumenEditor/App.config +++ b/OngekiFumenEditor/App.config @@ -155,6 +155,21 @@ False + + Red + + + Lime + + + Blue + + + 35, 4, 117 + + + 136, 3, 152 + diff --git a/OngekiFumenEditor/Kernel/SettingPages/FumenVisualEditor/Models/ColorPropertyWrapper.cs b/OngekiFumenEditor/Kernel/SettingPages/FumenVisualEditor/Models/ColorPropertyWrapper.cs new file mode 100644 index 00000000..48ef1ea6 --- /dev/null +++ b/OngekiFumenEditor/Kernel/SettingPages/FumenVisualEditor/Models/ColorPropertyWrapper.cs @@ -0,0 +1,75 @@ +using Caliburn.Micro; +using OngekiFumenEditor.Utils; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media; + +namespace OngekiFumenEditor.Kernel.SettingPages.FumenVisualEditor.Models +{ + public class ColorPropertyWrapper : PropertyChangedBase + { + private readonly PropertyInfo propertyInfo; + private readonly object owner; + private SolidColorBrush cachedColorBrush; + private SolidColorBrush cachedReverseColorBrush; + + public ColorPropertyWrapper(PropertyInfo propertyInfo, object owner) + { + this.propertyInfo = propertyInfo; + this.owner = owner; + + RefreshBrush(); + } + + private void RefreshBrush() + { + var color = Color; + cachedColorBrush = new SolidColorBrush(color.ToMediaColor()); + cachedReverseColorBrush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(color.A, (byte)(255 - color.R), (byte)(255 - color.G), (byte)(255 - color.B))); + + NotifyOfPropertyChange(nameof(Brush)); + NotifyOfPropertyChange(nameof(ReverseBrush)); + } + + public System.Drawing.Color Color + { + get => (System.Drawing.Color)propertyInfo.GetValue(owner, null); + set + { + propertyInfo.SetValue(owner, value, null); + RefreshBrush(); + + NotifyOfPropertyChange(nameof(Color)); + NotifyOfPropertyChange(nameof(ColorString)); + } + } + + public SolidColorBrush Brush => cachedColorBrush; + public SolidColorBrush ReverseBrush => cachedReverseColorBrush; + + public string Name => propertyInfo.Name; + + public string ColorString + { + get + { + var r = Color; + return $"{r.R}, {r.G}, {r.B}, {r.A}"; + } + set + { + var split = value.Split(','); + var r = int.Parse(split[0].Trim()); + var g = int.Parse(split[1].Trim()); + var b = int.Parse(split[2].Trim()); + var a = split.Length > 3 ? int.Parse(split[3]) : 255; + + Color = System.Drawing.Color.FromArgb(a, r, g, b); + } + } + } +} diff --git a/OngekiFumenEditor/Kernel/SettingPages/FumenVisualEditor/ViewModels/FumenVisualEditorColorSettingViewModel.cs b/OngekiFumenEditor/Kernel/SettingPages/FumenVisualEditor/ViewModels/FumenVisualEditorColorSettingViewModel.cs new file mode 100644 index 00000000..941a66bf --- /dev/null +++ b/OngekiFumenEditor/Kernel/SettingPages/FumenVisualEditor/ViewModels/FumenVisualEditorColorSettingViewModel.cs @@ -0,0 +1,53 @@ +using Caliburn.Micro; +using Gemini.Modules.Settings; +using OngekiFumenEditor.Kernel.SettingPages.FumenVisualEditor.Models; +using OngekiFumenEditor.Properties; +using OngekiFumenEditor.UI.Dialogs; +using OngekiFumenEditor.Utils; +using System.ComponentModel.Composition; +using System.Linq; + +namespace OngekiFumenEditor.Kernel.SettingPages.FumenVisualEditor.ViewModels +{ + [Export(typeof(ISettingsEditor))] + [PartCreationPolicy(CreationPolicy.Shared)] + public class FumenVisualEditorColorSettingViewModel : PropertyChangedBase, ISettingsEditor + { + public EditorGlobalSetting Setting => EditorGlobalSetting.Default; + + public FumenVisualEditorColorSettingViewModel() + { + ColorsProperties = typeof(EditorGlobalSetting) + .GetProperties() + .Where(x => x.Name.StartsWith("Color") && x.PropertyType == typeof(System.Drawing.Color)) + .Select(x => new ColorPropertyWrapper(x, EditorGlobalSetting.Default)) + .ToArray(); + } + + public string SettingsPagePath => Resources.TabDocument + "\\" + Resources.TabEditor; + + public string SettingsPageName => "渲染色彩管理"; + + public ColorPropertyWrapper[] ColorsProperties { get; private set; } + + public void ApplyChanges() + { + EditorGlobalSetting.Default.Save(); + } + + public void OnSelectColor(ActionExecutionContext context) + { + if (context.Source.DataContext is not ColorPropertyWrapper colorProperty) + return; + + var dialog = new CommonColorPicker(() => + { + return colorProperty.Color.ToMediaColor(); + }, color => + { + colorProperty.Color = color.ToDrawingColor(); + }, $"设置新的 {colorProperty.Name} 颜色"); + dialog.Show(); + } + } +} diff --git a/OngekiFumenEditor/Kernel/SettingPages/FumenVisualEditor/ViewModels/FumenVisualEditorGlobalSettingViewModel.cs b/OngekiFumenEditor/Kernel/SettingPages/FumenVisualEditor/ViewModels/FumenVisualEditorGlobalSettingViewModel.cs index d17ccb29..7f1f49ec 100644 --- a/OngekiFumenEditor/Kernel/SettingPages/FumenVisualEditor/ViewModels/FumenVisualEditorGlobalSettingViewModel.cs +++ b/OngekiFumenEditor/Kernel/SettingPages/FumenVisualEditor/ViewModels/FumenVisualEditorGlobalSettingViewModel.cs @@ -13,11 +13,11 @@ namespace OngekiFumenEditor.Kernel.SettingPages.FumenVisualEditor.ViewModels [PartCreationPolicy(CreationPolicy.Shared)] public class FumenVisualEditorGlobalSettingViewModel : PropertyChangedBase, ISettingsEditor { - public Properties.EditorGlobalSetting Setting => Properties.EditorGlobalSetting.Default; + public EditorGlobalSetting Setting => EditorGlobalSetting.Default; public FumenVisualEditorGlobalSettingViewModel() { - Properties.EditorGlobalSetting.Default.PropertyChanged += SettingPropertyChanged; + EditorGlobalSetting.Default.PropertyChanged += SettingPropertyChanged; } private void SettingPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) @@ -31,7 +31,7 @@ private void SettingPropertyChanged(object sender, System.ComponentModel.Propert public void ApplyChanges() { - Properties.EditorGlobalSetting.Default.Save(); + EditorGlobalSetting.Default.Save(); } public void ClearRecentOpen() diff --git a/OngekiFumenEditor/Kernel/SettingPages/FumenVisualEditor/Views/FumenVisualEditorColorSettingView.xaml b/OngekiFumenEditor/Kernel/SettingPages/FumenVisualEditor/Views/FumenVisualEditorColorSettingView.xaml new file mode 100644 index 00000000..8416308a --- /dev/null +++ b/OngekiFumenEditor/Kernel/SettingPages/FumenVisualEditor/Views/FumenVisualEditorColorSettingView.xaml @@ -0,0 +1,46 @@ + + + + + +