Skip to content

Commit

Permalink
add new experimental settings
Browse files Browse the repository at this point in the history
  • Loading branch information
MikiraSora committed Sep 12, 2024
1 parent 30969ba commit d2e7653
Show file tree
Hide file tree
Showing 10 changed files with 419 additions and 102 deletions.
15 changes: 15 additions & 0 deletions OngekiFumenEditor/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,21 @@
<setting name="EnableShowPlayerLocation" serializeAs="String">
<value>False</value>
</setting>
<setting name="ColorHoldLeft" serializeAs="String">
<value>Red</value>
</setting>
<setting name="ColorHoldCenter" serializeAs="String">
<value>Lime</value>
</setting>
<setting name="ColorHoldRight" serializeAs="String">
<value>Blue</value>
</setting>
<setting name="ColorHoldWallRight" serializeAs="String">
<value>35, 4, 117</value>
</setting>
<setting name="ColorHoldWallLeft" serializeAs="String">
<value>136, 3, 152</value>
</setting>
</OngekiFumenEditor.Properties.EditorGlobalSetting>
<OngekiFumenEditor.Properties.AudioPlayerToolViewerSetting>
<setting name="ResampleSize" serializeAs="String">
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<UserControl
x:Class="OngekiFumenEditor.Kernel.SettingPages.FumenVisualEditor.Views.FumenVisualEditorColorSettingView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cal="http://caliburnmicro.com"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:markup="clr-namespace:OngekiFumenEditor.UI.Markup"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:res="clr-namespace:OngekiFumenEditor.Properties"
xmlns:valueconverters="clr-namespace:OngekiFumenEditor.Kernel.SettingPages.FumenVisualEditor.ValueConverters"
xmlns:vm="clr-namespace:OngekiFumenEditor.Kernel.SettingPages.FumenVisualEditor.ViewModels"
d:Background="White"
d:DataContext="{d:DesignInstance IsDesignTimeCreatable=True,
Type=vm:FumenVisualEditorColorSettingViewModel}"
d:DesignWidth="800"
mc:Ignorable="d">
<ItemsControl
ItemsSource="{Binding ColorsProperties}"
ScrollViewer.CanContentScroll="True"
VirtualizingPanel.IsVirtualizing="True"
VirtualizingPanel.VirtualizationMode="Recycling">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid Margin="5">
<Label VerticalAlignment="Center" Content="{Binding Name}" />
<StackPanel
HorizontalAlignment="Right"
VerticalAlignment="Center"
Orientation="Horizontal">
<Border
Width="25"
Margin="5,0"
Background="{Binding Brush}"
CornerRadius="7" />
<Label VerticalAlignment="Center" Content="{Binding ColorString}" />
<Button
Margin="5,0"
Padding="10,2"
cal:Message.Attach="OnSelectColor($executionContext)"
Content="选择" />
</StackPanel>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Windows.Controls;

namespace OngekiFumenEditor.Kernel.SettingPages.FumenVisualEditor.Views
{
/// <summary>
/// FumenVisualEditorGlobalSettingView.xaml 的交互逻辑
/// </summary>
public partial class FumenVisualEditorColorSettingView : UserControl
{
public FumenVisualEditorColorSettingView()
{
InitializeComponent();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ public CommonHorizonalDrawingTarget()
{
lineDrawing = IoC.Get<ISimpleLineDrawing>();
stringDrawing = IoC.Get<IStringDrawing>();


}

public override IEnumerable<string> DrawTargetID { get; } = new[]
{
"MET","SFL","BPM","EST","CLK","LBK","[LBK_End]","[SFL_End]","[CMT]","[INTP_SFL]","[INTP_SFL_End]","[KEY_SFL]"
};
public override IEnumerable<string> DrawTargetID { get; } =
[
"MET","SFL","BPM","EST","CLK","LBK","[LBK_End]","[SFL_End]","[CMT]","[INTP_SFL]","[INTP_SFL_End]","[KEY_SFL]"
];

private static Dictionary<string, FSColor> colors = new()
private Dictionary<string, FSColor> colors = new()
{
{"MET", FSColor.LightGreen },
{"SFL", FSColor.LightCyan },
Expand Down
Loading

0 comments on commit d2e7653

Please sign in to comment.