diff --git a/Project-Aurora/Project-Aurora/Profiles/Desktop/DesktopProfile.cs b/Project-Aurora/Project-Aurora/Profiles/Desktop/DesktopProfile.cs index 0d54def85..2b9cfd920 100755 --- a/Project-Aurora/Project-Aurora/Profiles/Desktop/DesktopProfile.cs +++ b/Project-Aurora/Project-Aurora/Profiles/Desktop/DesktopProfile.cs @@ -374,7 +374,7 @@ public override void Reset() Freeform = new FreeFormObject(0, 0, 1600, 400), Type = KeySequenceType.FreeForm }, - _GradientConfig = new LayerEffectConfig + GradientConfig = new LayerEffectConfig { Angle = 90, Speed = 1, @@ -415,7 +415,7 @@ public override void Reset() Freeform = new FreeFormObject(0, 0, 1600, 400), Type = KeySequenceType.FreeForm }, - _GradientConfig = new LayerEffectConfig + GradientConfig = new LayerEffectConfig { Angle = 0, Speed = 1, diff --git a/Project-Aurora/Project-Aurora/Settings/Layers/Controls/Control_GradientLayer.xaml.cs b/Project-Aurora/Project-Aurora/Settings/Layers/Controls/Control_GradientLayer.xaml.cs index 189143bdf..f38d4c4c2 100644 --- a/Project-Aurora/Project-Aurora/Settings/Layers/Controls/Control_GradientLayer.xaml.cs +++ b/Project-Aurora/Project-Aurora/Settings/Layers/Controls/Control_GradientLayer.xaml.cs @@ -1,4 +1,5 @@ using System; +using System.Globalization; using System.Windows; using System.Windows.Controls; using System.Windows.Media; @@ -13,7 +14,7 @@ namespace Aurora.Settings.Layers.Controls; /// public partial class Control_GradientLayer { - private bool settingsset; + private bool _settingsSet; public Control_GradientLayer() { @@ -27,17 +28,17 @@ public Control_GradientLayer(GradientLayerHandler dataContext) DataContext = dataContext; } - public void SetSettings() + private void SetSettings() { - if (DataContext is not GradientLayerHandler || settingsset) return; + if (DataContext is not GradientLayerHandler || _settingsSet) return; wave_size_slider.Value = ((GradientLayerHandler)DataContext).Properties.GradientConfig.GradientSize; wave_size_label.Text = ((GradientLayerHandler)DataContext).Properties.GradientConfig.GradientSize + " %"; - effect_speed_slider.Value = ((GradientLayerHandler)DataContext).Properties._GradientConfig.Speed; - effect_speed_label.Text = "x " + ((GradientLayerHandler)DataContext).Properties._GradientConfig.Speed; - effect_angle.Text = ((GradientLayerHandler)DataContext).Properties._GradientConfig.Angle.ToString(); - effect_animation_type.SelectedValue = ((GradientLayerHandler)DataContext).Properties._GradientConfig.AnimationType; - effect_animation_reversed.IsChecked = ((GradientLayerHandler)DataContext).Properties._GradientConfig.AnimationReverse; - var brush = ((GradientLayerHandler)DataContext).Properties._GradientConfig.Brush.GetMediaBrush(); + effect_speed_slider.Value = ((GradientLayerHandler)DataContext).Properties.GradientConfig.Speed; + effect_speed_label.Text = "x " + ((GradientLayerHandler)DataContext).Properties.GradientConfig.Speed; + effect_angle.Text = ((GradientLayerHandler)DataContext).Properties.GradientConfig.Angle.ToString(CultureInfo.InvariantCulture); + effect_animation_type.SelectedValue = ((GradientLayerHandler)DataContext).Properties.GradientConfig.AnimationType; + effect_animation_reversed.IsChecked = ((GradientLayerHandler)DataContext).Properties.GradientConfig.AnimationReverse; + var brush = ((GradientLayerHandler)DataContext).Properties.GradientConfig.Brush.GetMediaBrush(); try { gradient_editor.Brush = brush; @@ -49,20 +50,20 @@ public void SetSettings() KeySequence_keys.Sequence = ((GradientLayerHandler)DataContext).Properties._Sequence; - settingsset = true; + _settingsSet = true; } private void Gradient_editor_BrushChanged(object? sender, BrushChangedEventArgs e) { - if (IsLoaded && settingsset && DataContext is GradientLayerHandler && sender is ColorBox.ColorBox colorBox) - ((GradientLayerHandler)DataContext).Properties._GradientConfig.Brush = new EffectBrush(colorBox.Brush); + if (IsLoaded && _settingsSet && DataContext is GradientLayerHandler && sender is ColorBox.ColorBox colorBox) + ((GradientLayerHandler)DataContext).Properties.GradientConfig.Brush = new EffectBrush(colorBox.Brush); } private void Button_SetGradientRainbow_Click(object? sender, RoutedEventArgs e) { - ((GradientLayerHandler)DataContext).Properties._GradientConfig.Brush = new EffectBrush(ColorSpectrum.Rainbow); + ((GradientLayerHandler)DataContext).Properties.GradientConfig.Brush = new EffectBrush(ColorSpectrum.Rainbow); - var brush = ((GradientLayerHandler)DataContext).Properties._GradientConfig.Brush.GetMediaBrush(); + var brush = ((GradientLayerHandler)DataContext).Properties.GradientConfig.Brush.GetMediaBrush(); try { gradient_editor.Brush = brush; @@ -75,9 +76,9 @@ private void Button_SetGradientRainbow_Click(object? sender, RoutedEventArgs e) private void Button_SetGradientRainbowLoop_Click(object? sender, RoutedEventArgs e) { - ((GradientLayerHandler)DataContext).Properties._GradientConfig.Brush = new EffectBrush(ColorSpectrum.RainbowLoop); + ((GradientLayerHandler)DataContext).Properties.GradientConfig.Brush = new EffectBrush(ColorSpectrum.RainbowLoop); - var brush = ((GradientLayerHandler)DataContext).Properties._GradientConfig.Brush.GetMediaBrush(); + var brush = ((GradientLayerHandler)DataContext).Properties.GradientConfig.Brush.GetMediaBrush(); try { gradient_editor.Brush = brush; @@ -89,8 +90,8 @@ private void Button_SetGradientRainbowLoop_Click(object? sender, RoutedEventArgs } private void effect_speed_slider_ValueChanged(object? sender, RoutedPropertyChangedEventArgs e) { - if (!IsLoaded || !settingsset || DataContext is not GradientLayerHandler || sender is not Slider slider) return; - ((GradientLayerHandler)DataContext).Properties._GradientConfig.Speed = (float)slider.Value; + if (!IsLoaded || !_settingsSet || DataContext is not GradientLayerHandler || sender is not Slider slider) return; + ((GradientLayerHandler)DataContext).Properties.GradientConfig.Speed = (float)slider.Value; if (effect_speed_label != null) effect_speed_label.Text = "x " + slider.Value; @@ -98,7 +99,7 @@ private void effect_speed_slider_ValueChanged(object? sender, RoutedPropertyChan private void wave_size_slider_ValueChanged(object? sender, RoutedPropertyChangedEventArgs e) { - if (!IsLoaded || !settingsset || DataContext is not GradientLayerHandler || sender is not Slider) return; + if (!IsLoaded || !_settingsSet || DataContext is not GradientLayerHandler || sender is not Slider) return; ((GradientLayerHandler)DataContext).Properties.GradientConfig.GradientSize = (float)e.NewValue; if (wave_size_label != null) @@ -114,13 +115,13 @@ private void wave_size_slider_ValueChanged(object? sender, RoutedPropertyChanged private void effect_angle_ValueChanged(object? sender, RoutedPropertyChangedEventArgs e) { - if (!IsLoaded || !settingsset || DataContext is not GradientLayerHandler || sender is not IntegerUpDown integerUpDown) return; + if (!IsLoaded || !_settingsSet || DataContext is not GradientLayerHandler || sender is not IntegerUpDown integerUpDown) return; if (float.TryParse(integerUpDown.Text, out var outval)) { integerUpDown.Background = new SolidColorBrush(Color.FromArgb(255, 24, 24, 24)); - ((GradientLayerHandler)DataContext).Properties._GradientConfig.Angle = outval; + ((GradientLayerHandler)DataContext).Properties.GradientConfig.Angle = outval; } else { @@ -132,23 +133,23 @@ private void effect_angle_ValueChanged(object? sender, RoutedPropertyChangedEven private void effect_animation_type_SelectionChanged(object? sender, SelectionChangedEventArgs e) { - if (!IsLoaded || !settingsset || DataContext is not GradientLayerHandler || sender is not ComboBox comboBox) return; + if (!IsLoaded || !_settingsSet || DataContext is not GradientLayerHandler || sender is not ComboBox comboBox) return; - ((GradientLayerHandler)DataContext).Properties._GradientConfig.AnimationType = (AnimationType)comboBox.SelectedValue; + ((GradientLayerHandler)DataContext).Properties.GradientConfig.AnimationType = (AnimationType)comboBox.SelectedValue; TriggerPropertyChanged(); } private void effect_animation_reversed_Checked(object? sender, RoutedEventArgs e) { - if (!IsLoaded || !settingsset || DataContext is not GradientLayerHandler || sender is not CheckBox checkBox) return; + if (!IsLoaded || !_settingsSet || DataContext is not GradientLayerHandler || sender is not CheckBox checkBox) return; - ((GradientLayerHandler)DataContext).Properties._GradientConfig.AnimationReverse = checkBox.IsChecked.HasValue ? checkBox.IsChecked.Value : false; + ((GradientLayerHandler)DataContext).Properties.GradientConfig.AnimationReverse = checkBox.IsChecked.HasValue && checkBox.IsChecked.Value; TriggerPropertyChanged(); } private void KeySequence_keys_SequenceUpdated(object? sender, RoutedPropertyChangedEventArgs e) { - if (!IsLoaded || !settingsset || DataContext is not GradientLayerHandler) return; + if (!IsLoaded || !_settingsSet || DataContext is not GradientLayerHandler) return; ((GradientLayerHandler)DataContext).Properties._Sequence = e.NewValue; TriggerPropertyChanged(); @@ -161,7 +162,7 @@ private void UserControl_Loaded(object? sender, RoutedEventArgs e) Loaded -= UserControl_Loaded; } - protected void TriggerPropertyChanged() + private void TriggerPropertyChanged() { var layerHandler = (GradientLayerHandler) DataContext; layerHandler.Properties.OnPropertiesChanged(this); diff --git a/Project-Aurora/Project-Aurora/Settings/Layers/GradientLayerHandler.cs b/Project-Aurora/Project-Aurora/Settings/Layers/GradientLayerHandler.cs index 82610073d..be12c11ad 100644 --- a/Project-Aurora/Project-Aurora/Settings/Layers/GradientLayerHandler.cs +++ b/Project-Aurora/Project-Aurora/Settings/Layers/GradientLayerHandler.cs @@ -3,93 +3,100 @@ using Aurora.Settings.Overrides; using Newtonsoft.Json; using System.ComponentModel; -using System.Drawing; using System.Windows.Controls; using Aurora.Settings.Layers.Controls; using Common.Utils; -namespace Aurora.Settings.Layers +namespace Aurora.Settings.Layers; + +public class GradientLayerHandlerProperties : LayerHandlerProperties2Color { - public class GradientLayerHandlerProperties : LayerHandlerProperties2Color - { - [LogicOverridable("Gradient")] - public LayerEffectConfig _GradientConfig { get; set; } + private LayerEffectConfig? _gradientConfig; - [JsonIgnore] - public LayerEffectConfig GradientConfig => Logic._GradientConfig ?? _GradientConfig; + [LogicOverridable("Gradient")] + [JsonProperty("_GradientConfig")] + public LayerEffectConfig GradientConfig + { + get => Logic._gradientConfig ?? (_gradientConfig ??= DefaultGradientConfig()); + set => _gradientConfig = value; + } - public GradientLayerHandlerProperties() - { } + public GradientLayerHandlerProperties() + { } - public GradientLayerHandlerProperties(bool assign_default = false) : base(assign_default) { } + public GradientLayerHandlerProperties(bool assignDefault = false) : base(assignDefault) { } - public override void Default() - { - base.Default(); - _GradientConfig = new LayerEffectConfig(CommonColorUtils.GenerateRandomColor(), CommonColorUtils.GenerateRandomColor()) { AnimationType = AnimationType.None }; - } + public override void Default() + { + base.Default(); + _gradientConfig = DefaultGradientConfig(); } - [LogicOverrideIgnoreProperty("_PrimaryColor")] - [LogicOverrideIgnoreProperty("_SecondaryColor")] - public class GradientLayerHandler : LayerHandler + private static LayerEffectConfig DefaultGradientConfig() { - private readonly EffectLayer _tempLayerBitmap = new("GradientLayer - Colors", true); - private bool _invalidated; + return new LayerEffectConfig(CommonColorUtils.GenerateRandomColor(), CommonColorUtils.GenerateRandomColor()) { AnimationType = AnimationType.None }; + } +} - public GradientLayerHandler(): base("GradientLayer") - { - Properties.PropertyChanged += PropertiesChanged; - } +[LogicOverrideIgnoreProperty("_PrimaryColor")] +[LogicOverrideIgnoreProperty("_SecondaryColor")] +public class GradientLayerHandler : LayerHandler +{ + private readonly EffectLayer _tempLayerBitmap = new("GradientLayer - Colors", true); + private bool _invalidated; - protected override void PropertiesChanged(object? sender, PropertyChangedEventArgs args) - { - base.PropertiesChanged(sender, args); - _invalidated = true; - } + public GradientLayerHandler(): base("GradientLayer") + { + Properties.PropertyChanged += PropertiesChanged; + } - protected override UserControl CreateControl() + protected override void PropertiesChanged(object? sender, PropertyChangedEventArgs args) + { + base.PropertiesChanged(sender, args); + _invalidated = true; + } + + protected override UserControl CreateControl() + { + return new Control_GradientLayer(this); + } + public override EffectLayer Render(IGameState gamestate) + { + if (_invalidated) { - return new Control_GradientLayer(this); + EffectLayer.Clear(); + _invalidated = false; } - public override EffectLayer Render(IGameState gamestate) + //If Wave Size 0 Gradiant Stop Moving Animation + if (Properties.GradientConfig.GradientSize == 0) { - if (_invalidated) - { - EffectLayer.Clear(); - _invalidated = false; - } - //If Wave Size 0 Gradiant Stop Moving Animation - if (Properties.GradientConfig.GradientSize == 0) - { - Properties.GradientConfig.ShiftAmount += (Utils.Time.GetMillisecondsSinceEpoch() - Properties.GradientConfig.LastEffectCall) / 1000.0f * 5.0f * Properties.GradientConfig.Speed; - Properties.GradientConfig.ShiftAmount %= Effects.Canvas.BiggestSize; - Properties.GradientConfig.LastEffectCall = Utils.Time.GetMillisecondsSinceEpoch(); + Properties.GradientConfig.ShiftAmount += (Utils.Time.GetMillisecondsSinceEpoch() - Properties.GradientConfig.LastEffectCall) / 1000.0f * 5.0f * Properties.GradientConfig.Speed; + Properties.GradientConfig.ShiftAmount %= Effects.Canvas.BiggestSize; + Properties.GradientConfig.LastEffectCall = Utils.Time.GetMillisecondsSinceEpoch(); - Color selectedColor = Properties.GradientConfig.Brush.GetColorSpectrum().GetColorAt(Properties.GradientConfig.ShiftAmount, Effects.Canvas.BiggestSize); + var selectedColor = Properties.GradientConfig.Brush.GetColorSpectrum().GetColorAt(Properties.GradientConfig.ShiftAmount, Effects.Canvas.BiggestSize); - EffectLayer.Set(Properties.Sequence, selectedColor); - } - else - { - _tempLayerBitmap.DrawGradient(LayerEffects.GradientShift_Custom_Angle, Properties.GradientConfig); - EffectLayer.Clear(); - EffectLayer.DrawTransformed( - Properties.Sequence, - g => - { - g.FillRectangle(_tempLayerBitmap.TextureBrush, _tempLayerBitmap.Dimension); - } - ); - } - return EffectLayer; + EffectLayer.Set(Properties.Sequence, selectedColor); } - - public override void Dispose() + else { - Properties.PropertyChanged -= PropertiesChanged; - EffectLayer.Dispose(); - base.Dispose(); + _tempLayerBitmap.DrawGradient(LayerEffects.GradientShift_Custom_Angle, Properties.GradientConfig); + EffectLayer.Clear(); + EffectLayer.DrawTransformed( + Properties.Sequence, + g => + { + g.FillRectangle(_tempLayerBitmap.TextureBrush, _tempLayerBitmap.Dimension); + } + ); } + return EffectLayer; } -} + + public override void Dispose() + { + Properties.PropertyChanged -= PropertiesChanged; + EffectLayer.Dispose(); + base.Dispose(); + } +} \ No newline at end of file diff --git a/Project-Aurora/Project-Aurora/Settings/Layers/PercentGradientLayerHandler.cs b/Project-Aurora/Project-Aurora/Settings/Layers/PercentGradientLayerHandler.cs index 642fc521a..a771c1af5 100644 --- a/Project-Aurora/Project-Aurora/Settings/Layers/PercentGradientLayerHandler.cs +++ b/Project-Aurora/Project-Aurora/Settings/Layers/PercentGradientLayerHandler.cs @@ -18,7 +18,7 @@ public PercentGradientLayerHandlerProperties(bool empty = false) : base(empty) { [LogicOverridable("Gradient")] public EffectBrush Gradient { - get => Logic._gradient ?? _gradient ?? new EffectBrush().SetBrushType(EffectBrush.BrushType.Linear); + get => Logic._gradient ?? (_gradient ??= new EffectBrush().SetBrushType(EffectBrush.BrushType.Linear)); set => _gradient = value; }