From f985682e7865e36b4c7cf85b0560db40ad4a187d Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 6 Oct 2023 21:28:02 +0200 Subject: [PATCH] Profile editor - Fixed easing options not applying Device properties - Fixed layout changes not saving --- .../Services/Interfaces/IRenderService.cs | 5 ----- src/Artemis.Core/Services/RenderService.cs | 11 ----------- .../Device/Tabs/DeviceGeneralTabViewModel.cs | 4 ++-- .../Device/Tabs/DeviceLayoutTabViewModel.cs | 16 ++++++++++------ .../Timeline/Keyframes/TimelineEasingView.axaml | 14 +++++++++----- .../Keyframes/TimelineEasingViewModel.cs | 6 +++++- .../Keyframes/TimelineKeyframeView.axaml | 14 ++++---------- .../Keyframes/TimelineKeyframeViewModel.cs | 9 ++++++--- 8 files changed, 36 insertions(+), 43 deletions(-) diff --git a/src/Artemis.Core/Services/Interfaces/IRenderService.cs b/src/Artemis.Core/Services/Interfaces/IRenderService.cs index 684cd193b..153f4c827 100644 --- a/src/Artemis.Core/Services/Interfaces/IRenderService.cs +++ b/src/Artemis.Core/Services/Interfaces/IRenderService.cs @@ -31,11 +31,6 @@ public interface IRenderService : IArtemisService /// bool IsPaused { get; set; } - /// - /// Gets or sets a boolean indicating whether to flush the RGB.NET LEDs during next update - /// - bool FlushLeds { get; set; } - /// /// The time the last frame took to render /// diff --git a/src/Artemis.Core/Services/RenderService.cs b/src/Artemis.Core/Services/RenderService.cs index 66813052a..d9653279a 100644 --- a/src/Artemis.Core/Services/RenderService.cs +++ b/src/Artemis.Core/Services/RenderService.cs @@ -70,21 +70,10 @@ internal class RenderService : IRenderService, IRenderer, IDisposable /// public TimeSpan FrameTime { get; private set; } - /// - public bool FlushLeds { get; set; } - /// public void Render(SKCanvas canvas, double delta) { _frameStopWatch.Restart(); - - if (FlushLeds) - { - FlushLeds = false; - Surface.Update(true); - return; - } - try { OnFrameRendering(new FrameRenderingEventArgs(canvas, delta, _surfaceManager.Surface)); diff --git a/src/Artemis.UI/Screens/Device/Tabs/DeviceGeneralTabViewModel.cs b/src/Artemis.UI/Screens/Device/Tabs/DeviceGeneralTabViewModel.cs index 20808ad4f..892b270dc 100644 --- a/src/Artemis.UI/Screens/Device/Tabs/DeviceGeneralTabViewModel.cs +++ b/src/Artemis.UI/Screens/Device/Tabs/DeviceGeneralTabViewModel.cs @@ -218,8 +218,7 @@ public class DeviceGeneralTabViewModel : ActivatableViewModelBase Device.RedScale = RedScale / 100f; Device.GreenScale = GreenScale / 100f; Device.BlueScale = BlueScale / 100f; - - _renderService.FlushLeds = true; + Device.RgbDevice.Update(true); } public void ResetScaling() @@ -227,6 +226,7 @@ public class DeviceGeneralTabViewModel : ActivatableViewModelBase RedScale = _initialRedScale * 100; GreenScale = _initialGreenScale * 100; BlueScale = _initialBlueScale * 100; + Device.RgbDevice.Update(true); } private void OnFrameRendering(object? sender, FrameRenderingEventArgs e) diff --git a/src/Artemis.UI/Screens/Device/Tabs/DeviceLayoutTabViewModel.cs b/src/Artemis.UI/Screens/Device/Tabs/DeviceLayoutTabViewModel.cs index 306e7399a..419243e9a 100644 --- a/src/Artemis.UI/Screens/Device/Tabs/DeviceLayoutTabViewModel.cs +++ b/src/Artemis.UI/Screens/Device/Tabs/DeviceLayoutTabViewModel.cs @@ -37,11 +37,7 @@ public class DeviceLayoutTabViewModel : ActivatableViewModelBase this.WhenActivated(d => { Device.PropertyChanged += DeviceOnPropertyChanged; - - Disposable.Create(() => - { - Device.PropertyChanged -= DeviceOnPropertyChanged; - }).DisposeWith(d); + Disposable.Create(() => Device.PropertyChanged -= DeviceOnPropertyChanged).DisposeWith(d); }); } @@ -51,7 +47,7 @@ public class DeviceLayoutTabViewModel : ActivatableViewModelBase public string? ImagePath => Device.Layout?.Image?.LocalPath; - public string CustomLayoutPath => Device.CustomLayoutPath; + public string? CustomLayoutPath => Device.CustomLayoutPath; public bool HasCustomLayout => Device.CustomLayoutPath != null; @@ -61,6 +57,8 @@ public class DeviceLayoutTabViewModel : ActivatableViewModelBase _notificationService.CreateNotification() .WithMessage("Cleared imported layout.") .WithSeverity(NotificationSeverity.Informational); + + _deviceService.SaveDevice(Device); } public async Task BrowseCustomLayout() @@ -77,6 +75,8 @@ public class DeviceLayoutTabViewModel : ActivatableViewModelBase .WithTitle("Imported layout") .WithMessage($"File loaded from {files[0]}") .WithSeverity(NotificationSeverity.Informational); + + _deviceService.SaveDevice(Device); } } @@ -153,6 +153,10 @@ public class DeviceLayoutTabViewModel : ActivatableViewModelBase private void DeviceOnPropertyChanged(object? sender, PropertyChangedEventArgs e) { if (e.PropertyName is nameof(Device.CustomLayoutPath) or nameof(Device.DisableDefaultLayout)) + { Task.Run(() => _deviceService.ApplyDeviceLayout(Device, Device.GetBestDeviceLayout())); + this.RaisePropertyChanged(nameof(CustomLayoutPath)); + this.RaisePropertyChanged(nameof(HasCustomLayout)); + } } } \ No newline at end of file diff --git a/src/Artemis.UI/Screens/ProfileEditor/Panels/Properties/Timeline/Keyframes/TimelineEasingView.axaml b/src/Artemis.UI/Screens/ProfileEditor/Panels/Properties/Timeline/Keyframes/TimelineEasingView.axaml index e925b4edb..ef1a69c32 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Panels/Properties/Timeline/Keyframes/TimelineEasingView.axaml +++ b/src/Artemis.UI/Screens/ProfileEditor/Panels/Properties/Timeline/Keyframes/TimelineEasingView.axaml @@ -3,17 +3,21 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:keyframes="clr-namespace:Artemis.UI.Screens.ProfileEditor.Properties.Timeline.Keyframes" + xmlns:avalonia="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="Artemis.UI.Screens.ProfileEditor.Properties.Timeline.Keyframes.TimelineEasingView" x:DataType="keyframes:TimelineEasingViewModel"> - - + + - - + HorizontalAlignment="Left"/> + + + \ No newline at end of file diff --git a/src/Artemis.UI/Screens/ProfileEditor/Panels/Properties/Timeline/Keyframes/TimelineEasingViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/Panels/Properties/Timeline/Keyframes/TimelineEasingViewModel.cs index cada48d40..3c196c0a1 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Panels/Properties/Timeline/Keyframes/TimelineEasingViewModel.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/Panels/Properties/Timeline/Keyframes/TimelineEasingViewModel.cs @@ -1,8 +1,10 @@ using System.Collections.Generic; +using System.Reactive; using Artemis.Core; using Artemis.UI.Shared; using Avalonia; using Humanizer; +using ReactiveUI; namespace Artemis.UI.Screens.ProfileEditor.Properties.Timeline.Keyframes; @@ -10,11 +12,12 @@ public class TimelineEasingViewModel : ViewModelBase { private readonly ILayerPropertyKeyframe _keyframe; - public TimelineEasingViewModel(Easings.Functions easingFunction, ILayerPropertyKeyframe keyframe) + public TimelineEasingViewModel(Easings.Functions easingFunction, ILayerPropertyKeyframe keyframe, ReactiveCommand selectEasingFunction) { _keyframe = keyframe; EasingFunction = easingFunction; + SelectEasingFunction = selectEasingFunction; Description = easingFunction.Humanize(); EasingPoints = new List(); @@ -27,6 +30,7 @@ public class TimelineEasingViewModel : ViewModelBase } public Easings.Functions EasingFunction { get; } + public ReactiveCommand SelectEasingFunction { get; } public List EasingPoints { get; } public string Description { get; } public bool IsEasingModeSelected => _keyframe.EasingFunction == EasingFunction; diff --git a/src/Artemis.UI/Screens/ProfileEditor/Panels/Properties/Timeline/Keyframes/TimelineKeyframeView.axaml b/src/Artemis.UI/Screens/ProfileEditor/Panels/Properties/Timeline/Keyframes/TimelineKeyframeView.axaml index f72a45823..7977a73d9 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Panels/Properties/Timeline/Keyframes/TimelineKeyframeView.axaml +++ b/src/Artemis.UI/Screens/ProfileEditor/Panels/Properties/Timeline/Keyframes/TimelineKeyframeView.axaml @@ -3,6 +3,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:avalonia="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia" + xmlns:keyframes="clr-namespace:Artemis.UI.Screens.ProfileEditor.Properties.Timeline.Keyframes" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="Artemis.UI.Screens.ProfileEditor.Properties.Timeline.Keyframes.TimelineKeyframeView" ClipToBounds="False"> @@ -34,16 +35,9 @@ - diff --git a/src/Artemis.UI/Screens/ProfileEditor/Panels/Properties/Timeline/Keyframes/TimelineKeyframeViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/Panels/Properties/Timeline/Keyframes/TimelineKeyframeViewModel.cs index da70e2b5f..2f99088af 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Panels/Properties/Timeline/Keyframes/TimelineKeyframeViewModel.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/Panels/Properties/Timeline/Keyframes/TimelineKeyframeViewModel.cs @@ -54,10 +54,12 @@ public class TimelineKeyframeViewModel : ActivatableViewModelBase, ITimelineK Copy = ReactiveCommand.CreateFromTask(ExecuteCopy); Paste = ReactiveCommand.CreateFromTask(ExecutePaste); Delete = ReactiveCommand.Create(ExecuteDelete); + SelectEasingFunction = ReactiveCommand.Create(ExecuteSelectEasingFunction); } public LayerPropertyKeyframe LayerPropertyKeyframe { get; } public ObservableCollection EasingViewModels { get; } + public double X { @@ -93,7 +95,8 @@ public class TimelineKeyframeViewModel : ActivatableViewModelBase, ITimelineK public ReactiveCommand Copy { get; } public ReactiveCommand Paste { get; } public ReactiveCommand Delete { get; } - + public ReactiveCommand SelectEasingFunction { get; } + public bool IsSelected => _isSelected?.Value ?? false; public TimeSpan Position => LayerPropertyKeyframe.Position; public ILayerPropertyKeyframe Keyframe => LayerPropertyKeyframe; @@ -255,10 +258,10 @@ public class TimelineKeyframeViewModel : ActivatableViewModelBase, ITimelineK EasingViewModels.AddRange(Enum.GetValues(typeof(Easings.Functions)) .Cast() - .Select(e => new TimelineEasingViewModel(e, Keyframe))); + .Select(e => new TimelineEasingViewModel(e, Keyframe, SelectEasingFunction))); } - public void SelectEasingFunction(Easings.Functions easingFunction) + private void ExecuteSelectEasingFunction(Easings.Functions easingFunction) { _profileEditorService.ExecuteCommand(new ChangeKeyframeEasing(Keyframe, easingFunction)); }