diff --git a/Project-Aurora/Project-Aurora/Settings/Layers/Controls/Control_TimerLayer.xaml b/Project-Aurora/Project-Aurora/Settings/Layers/Controls/Control_TimerLayer.xaml
index 2b5486a7d..5b6ad0b24 100644
--- a/Project-Aurora/Project-Aurora/Settings/Layers/Controls/Control_TimerLayer.xaml
+++ b/Project-Aurora/Project-Aurora/Settings/Layers/Controls/Control_TimerLayer.xaml
@@ -37,13 +37,13 @@
-
+
-
+
-
+
diff --git a/Project-Aurora/Project-Aurora/Settings/Layers/Controls/Control_TimerLayer.xaml.cs b/Project-Aurora/Project-Aurora/Settings/Layers/Controls/Control_TimerLayer.xaml.cs
index 5807bbebc..21fa2fe8d 100644
--- a/Project-Aurora/Project-Aurora/Settings/Layers/Controls/Control_TimerLayer.xaml.cs
+++ b/Project-Aurora/Project-Aurora/Settings/Layers/Controls/Control_TimerLayer.xaml.cs
@@ -1,20 +1,18 @@
-using System.Windows.Controls;
-using AuroraRgb.Controls;
+using AuroraRgb.Controls;
-namespace AuroraRgb.Settings.Layers.Controls {
+namespace AuroraRgb.Settings.Layers.Controls;
- public partial class Control_TimerLayer : UserControl {
+public partial class Control_TimerLayer
+{
+ public Control_TimerLayer(TimerLayerHandler context) {
+ InitializeComponent();
+ DataContext = context;
- public Control_TimerLayer(TimerLayerHandler context) {
- InitializeComponent();
- DataContext = context;
-
- triggerKeyList.Keybinds = context.Properties._TriggerKeys;
- }
+ triggerKeyList.Keybinds = context.Properties.TriggerKeys;
+ }
- private void triggerKeyList_KeybindsChanged(object? sender) {
- if (sender is KeyBindList kbl)
- (DataContext as TimerLayerHandler).Properties._TriggerKeys = kbl.Keybinds;
- }
+ private void triggerKeyList_KeybindsChanged(object? sender) {
+ if (sender is KeyBindList kbl && DataContext is TimerLayerHandler timerLayerHandler)
+ timerLayerHandler.Properties.TriggerKeys = kbl.Keybinds;
}
-}
+}
\ No newline at end of file
diff --git a/Project-Aurora/Project-Aurora/Settings/Layers/TimerLayerHandler.cs b/Project-Aurora/Project-Aurora/Settings/Layers/TimerLayerHandler.cs
index 58f093c56..7894b636e 100644
--- a/Project-Aurora/Project-Aurora/Settings/Layers/TimerLayerHandler.cs
+++ b/Project-Aurora/Project-Aurora/Settings/Layers/TimerLayerHandler.cs
@@ -5,208 +5,246 @@
using System.Windows.Controls;
using AuroraRgb.EffectsEngine;
using AuroraRgb.Modules;
+using AuroraRgb.Modules.Inputs;
using AuroraRgb.Profiles;
using AuroraRgb.Settings.Layers.Controls;
using AuroraRgb.Settings.Overrides;
using AuroraRgb.Utils;
using Newtonsoft.Json;
-namespace AuroraRgb.Settings.Layers {
+namespace AuroraRgb.Settings.Layers;
- public sealed class TimerLayerHandlerProperties : LayerHandlerProperties2Color {
+public sealed class TimerLayerHandlerProperties : LayerHandlerProperties2Color {
- public TimerLayerHandlerProperties()
- { }
- public TimerLayerHandlerProperties(bool assign_default) : base(assign_default) { }
+ public TimerLayerHandlerProperties()
+ { }
+ public TimerLayerHandlerProperties(bool assignDefault) : base(assignDefault) { }
- public Keybind[]? _TriggerKeys { get; set; }
- [JsonIgnore]
- public Keybind[] TriggerKeys { get { return Logic._TriggerKeys ?? _TriggerKeys ?? []; } }
+ private Keybind[]? _triggerKeys;
+ [JsonProperty("_TriggerKeys")]
+ public Keybind[] TriggerKeys
+ {
+ get => Logic._triggerKeys ?? _triggerKeys ?? [];
+ set => _triggerKeys = value;
+ }
- [LogicOverridable("Duration")]
- public int? _Duration { get; set; }
- [JsonIgnore]
- public int Duration { get { return Logic._Duration ?? _Duration ?? 0; } }
+ private int? _duration;
+ [LogicOverridable("Duration")]
+ [JsonProperty("_Duration")]
+ public int Duration
+ {
+ get => Logic._duration ?? _duration ?? 0;
+ set => _duration = value;
+ }
- [LogicOverridable("Animation Type")]
- public TimerLayerAnimationType? _AnimationType { get; set; }
- [JsonIgnore]
- public TimerLayerAnimationType AnimationType { get { return Logic._AnimationType ?? _AnimationType ?? TimerLayerAnimationType.OnOff; } }
+ private TimerLayerAnimationType? _animationType;
+ [JsonProperty("_AnimationType")]
+ [LogicOverridable("Animation Type")]
+ public TimerLayerAnimationType AnimationType
+ {
+ get => Logic._animationType ?? _animationType ?? TimerLayerAnimationType.OnOff;
+ set => _animationType = value;
+ }
- [LogicOverridable("Repeat Action")]
- public TimerLayerRepeatPressAction? _RepeatAction { get; set; }
- [JsonIgnore]
- public TimerLayerRepeatPressAction RepeatAction { get { return Logic._RepeatAction ?? _RepeatAction ?? TimerLayerRepeatPressAction.Reset; } }
+ private TimerLayerRepeatPressAction? _repeatAction;
+ [JsonProperty("_RepeatAction")]
+ [LogicOverridable("Repeat Action")]
+ public TimerLayerRepeatPressAction RepeatAction
+ {
+ get => Logic._repeatAction ?? _repeatAction ?? TimerLayerRepeatPressAction.Reset;
+ set => _repeatAction = value;
+ }
- public override void Default() {
- base.Default();
- _TriggerKeys = new Keybind[] { };
- _Duration = 5000;
- _AnimationType = TimerLayerAnimationType.OnOff;
- _RepeatAction = TimerLayerRepeatPressAction.Reset;
- }
+ public override void Default() {
+ base.Default();
+ _triggerKeys = [];
+ _duration = 5000;
+ _animationType = TimerLayerAnimationType.OnOff;
+ _repeatAction = TimerLayerRepeatPressAction.Reset;
+ }
+}
+
+public class TimerLayerHandler : LayerHandler {
+ private readonly CustomTimer _timer;
+ private bool _isActive;
+ private bool _invalidated;
+
+ public TimerLayerHandler(): base("Timer Layer")
+ {
+ _timer = new CustomTimer();
+ _timer.Trigger += Timer_Elapsed;
+ }
+
+ protected override async Task Initialize()
+ {
+ await base.Initialize();
+
+ (await InputsModule.InputEvents).KeyDown += InputEvents_KeyDown;
}
- public class TimerLayerHandler : LayerHandler {
+ public override void Dispose() {
+ InputsModule.InputEvents.Result.KeyDown -= InputEvents_KeyDown;
+ _timer.Dispose();
+ base.Dispose();
+ }
- private CustomTimer timer;
- private bool isActive;
+ protected override UserControl CreateControl() {
+ return new Control_TimerLayer(this);
+ }
- public TimerLayerHandler()
+ public override EffectLayer Render(IGameState gameState) {
+ if (_invalidated)
{
- timer = new CustomTimer();
- timer.Trigger += Timer_Elapsed;
+ EffectLayer.Clear();
}
- protected override async Task Initialize()
+ if (!_isActive)
{
- await base.Initialize();
-
- (await InputsModule.InputEvents).KeyDown += InputEvents_KeyDown;
+ EffectLayer.Set(Properties.Sequence, Properties.PrimaryColor);
+ return EffectLayer;
}
- public override void Dispose() {
- InputsModule.InputEvents.Result.KeyDown -= InputEvents_KeyDown;
- base.Dispose();
+ switch (Properties.AnimationType)
+ {
+ case TimerLayerAnimationType.OnOff:
+ EffectLayer.Set(Properties.Sequence, Properties.SecondaryColor);
+ break;
+
+ case TimerLayerAnimationType.Fade:
+ EffectLayer.Set(Properties.Sequence,
+ ColorUtils.BlendColors(Properties.SecondaryColor, Properties.PrimaryColor, _timer.InterpolationValue));
+ break;
+
+ case TimerLayerAnimationType.Progress:
+ case TimerLayerAnimationType.ProgressGradual:
+ EffectLayer.PercentEffect(Properties.SecondaryColor, Properties.PrimaryColor, Properties.Sequence,
+ _timer.InterpolationValue, 1,
+ Properties.AnimationType == TimerLayerAnimationType.Progress
+ ? PercentEffectType.Progressive
+ : PercentEffectType.Progressive_Gradual);
+ break;
}
- protected override UserControl CreateControl() {
- return new Control_TimerLayer(this);
- }
+ return EffectLayer;
+ }
- public override EffectLayer Render(IGameState gamestate) {
- EffectLayer layer = new EffectLayer("TimerLayer");
- if (isActive) {
- switch (Properties.AnimationType) {
- case TimerLayerAnimationType.OnOff:
- layer.Set(Properties.Sequence, Properties.SecondaryColor);
- break;
-
- case TimerLayerAnimationType.Fade:
- layer.Set(Properties.Sequence, ColorUtils.BlendColors(Properties.SecondaryColor, Properties.PrimaryColor, timer.InterpolationValue));
- break;
-
- case TimerLayerAnimationType.Progress:
- case TimerLayerAnimationType.ProgressGradual:
- layer.PercentEffect(Properties.SecondaryColor, Properties.PrimaryColor, Properties.Sequence, timer.InterpolationValue, 1, Properties.AnimationType == TimerLayerAnimationType.Progress ? PercentEffectType.Progressive : PercentEffectType.Progressive_Gradual);
- break;
- }
- } else
- layer.Set(Properties.Sequence, Properties.PrimaryColor);
- return layer;
- }
+ protected override void PropertiesChanged(object? sender, PropertyChangedEventArgs args)
+ {
+ base.PropertiesChanged(sender, args);
+
+ _invalidated = true;
+ }
- private void Timer_Elapsed(object? sender) {
- isActive = false;
+ private void Timer_Elapsed(object? sender) {
+ _isActive = false;
+ }
+
+ private void InputEvents_KeyDown(object? sender, KeyboardKeyEventArgs e)
+ {
+ if (!Array.Exists(Properties.TriggerKeys, keybind => keybind.IsPressed()))
+ {
+ return;
}
- private void InputEvents_KeyDown(object? sender, EventArgs e) {
- foreach (var keybind in Properties.TriggerKeys) {
- if (keybind.IsPressed()) {
- switch (Properties.RepeatAction) {
- // Restart the timer from scratch
- case TimerLayerRepeatPressAction.Reset:
- timer.Reset(Properties.Duration);
- isActive = true;
- break;
-
- case TimerLayerRepeatPressAction.Extend:
- timer.Extend(Properties.Duration);
- isActive = true;
- break;
-
- case TimerLayerRepeatPressAction.Cancel:
- if (isActive)
- timer.Stop();
- else
- timer.Reset(Properties.Duration);
- isActive = !isActive;
- break;
+ switch (Properties.RepeatAction) {
+ // Restart the timer from scratch
+ case TimerLayerRepeatPressAction.Reset:
+ _timer.Reset(Properties.Duration);
+ _isActive = true;
+ break;
+
+ case TimerLayerRepeatPressAction.Extend:
+ _timer.Extend(Properties.Duration);
+ _isActive = true;
+ break;
+
+ case TimerLayerRepeatPressAction.Cancel:
+ if (_isActive)
+ _timer.Stop();
+ else
+ _timer.Reset(Properties.Duration);
+ _isActive = !_isActive;
+ break;
- case TimerLayerRepeatPressAction.Ignore:
- if (!isActive) {
- timer.Reset(Properties.Duration);
- isActive = true;
- }
- break;
- }
- return;
+ case TimerLayerRepeatPressAction.Ignore:
+ if (!_isActive) {
+ _timer.Reset(Properties.Duration);
+ _isActive = true;
}
- }
+ break;
}
}
+}
- class CustomTimer {
-
- public delegate void TriggerHandler(object? sender);
- public event TriggerHandler Trigger;
+internal sealed class CustomTimer : IDisposable {
+ public delegate void TriggerHandler(object? sender);
+ public event TriggerHandler? Trigger;
- private Timer timer;
- private double max = 0;
- private DateTime startAt;
+ private readonly Timer _timer;
+ private double _max;
+ private DateTime _startAt;
- public CustomTimer() {
- timer = new Timer();
- timer.AutoReset = false;
- timer.Elapsed += Timer_Elapsed;
- }
+ public CustomTimer() {
+ _timer = new Timer();
+ _timer.AutoReset = false;
+ _timer.Elapsed += Timer_Elapsed;
+ }
- private void Timer_Elapsed(object? sender, ElapsedEventArgs e) {
- Trigger?.Invoke(this);
- timer.Enabled = false;
- }
+ private void Timer_Elapsed(object? sender, ElapsedEventArgs e) {
+ Trigger?.Invoke(this);
+ _timer.Enabled = false;
+ }
- /// Stops the timer and restarts it with the given time.
- private void SetTimer(double t) {
- timer.Stop();
- timer.Interval = t;
- timer.Start();
- }
+ /// Stops the timer and restarts it with the given time.
+ private void SetTimer(double t) {
+ _timer.Stop();
+ _timer.Interval = t;
+ _timer.Start();
+ }
- public void Reset(double t) {
- SetTimer(t);
- startAt = DateTime.UtcNow;
- max = t;
- }
+ public void Reset(double t) {
+ SetTimer(t);
+ _startAt = DateTime.UtcNow;
+ _max = t;
+ }
- public void Stop() {
- timer.Stop();
- }
+ public void Stop() {
+ _timer.Stop();
+ }
- public void Extend(double t) {
- // If the timer's not running, behave like Reset
- if (!timer.Enabled)
- Reset(t);
+ public void Extend(double t) {
+ // If the timer's not running, behave like Reset
+ if (!_timer.Enabled)
+ Reset(t);
- // If timer is running
- else {
- max += t; // extend max
- SetTimer(max - Current);
- }
+ // If timer is running
+ else {
+ _max += t; // extend max
+ SetTimer(_max - Current);
}
+ }
- /// Gets how many milliseconds has elapsed since starting timer.
- public int Current => (int)(DateTime.UtcNow - startAt).TotalMilliseconds;
+ /// Gets how many milliseconds has elapsed since starting timer.
+ public int Current => (int)(DateTime.UtcNow - _startAt).TotalMilliseconds;
- /// Gets how far through the timer is as a value between 0 and 1 (for use with the fade animation mode).
- public double InterpolationValue => Current / max;
+ /// Gets how far through the timer is as a value between 0 and 1 (for use with the fade animation mode).
+ public double InterpolationValue => Current / _max;
- public void Disponse() {
- timer.Dispose();
- }
+ public void Dispose() {
+ _timer.Dispose();
}
+}
- public enum TimerLayerAnimationType {
- [Description("On/Off")] OnOff,
- Fade,
- Progress,
- [Description("Progress (Gradual)")] ProgressGradual
- }
-
- public enum TimerLayerRepeatPressAction {
- [Description("Restart")] Reset,
- [Description("Extend")] Extend,
- [Description("Cancel")] Cancel,
- [Description("Ignore")] Ignore
- }
+public enum TimerLayerAnimationType {
+ [Description("On/Off")] OnOff,
+ Fade,
+ Progress,
+ [Description("Progress (Gradual)")] ProgressGradual
}
+
+public enum TimerLayerRepeatPressAction {
+ [Description("Restart")] Reset,
+ [Description("Extend")] Extend,
+ [Description("Cancel")] Cancel,
+ [Description("Ignore")] Ignore
+}
\ No newline at end of file