From 472bcccdb6a9e2ffb577664d68a527fb1631ba9b Mon Sep 17 00:00:00 2001 From: Robert Date: Thu, 1 Jul 2021 23:05:44 +0200 Subject: [PATCH] Profile editor - Add indicator for timeline editor- and normal-mode --- .../Interfaces/IProfileEditorService.cs | 6 ++++ .../Services/ProfileEditorService.cs | 11 +++++++ .../LayerProperties/LayerPropertiesView.xaml | 24 ++++++++++++++- .../LayerPropertiesViewModel.cs | 9 ++++++ .../ProfileEditor/ProfileEditorViewModel.cs | 1 - .../Visualization/ProfileViewModel.cs | 29 ++++++++++++------- 6 files changed, 68 insertions(+), 12 deletions(-) diff --git a/src/Artemis.UI.Shared/Services/Interfaces/IProfileEditorService.cs b/src/Artemis.UI.Shared/Services/Interfaces/IProfileEditorService.cs index 059137ac6..d0fdb6e3e 100644 --- a/src/Artemis.UI.Shared/Services/Interfaces/IProfileEditorService.cs +++ b/src/Artemis.UI.Shared/Services/Interfaces/IProfileEditorService.cs @@ -227,6 +227,12 @@ namespace Artemis.UI.Shared.Services /// event EventHandler PixelsPerSecondChanged; + /// + /// Occurs when the suspend editing boolean is changed + /// + + event EventHandler SuspendEditingChanged; + /// /// Occurs when the profile preview has been updated /// diff --git a/src/Artemis.UI.Shared/Services/ProfileEditorService.cs b/src/Artemis.UI.Shared/Services/ProfileEditorService.cs index c0fa9c665..8a7016168 100644 --- a/src/Artemis.UI.Shared/Services/ProfileEditorService.cs +++ b/src/Artemis.UI.Shared/Services/ProfileEditorService.cs @@ -112,6 +112,9 @@ namespace Artemis.UI.Shared.Services get => _suspendEditing; set { + if (_suspendEditing == value) + return; + _suspendEditing = value; if (value) { @@ -123,6 +126,8 @@ namespace Artemis.UI.Shared.Services if (SelectedProfileConfiguration != null) _profileService.RenderForEditor = true; } + + OnSuspendEditingChanged(); } } @@ -505,6 +510,7 @@ namespace Artemis.UI.Shared.Services public event EventHandler? SelectedDataBindingChanged; public event EventHandler? CurrentTimeChanged; public event EventHandler? PixelsPerSecondChanged; + public event EventHandler? SuspendEditingChanged; public event EventHandler? ProfilePreviewUpdated; protected virtual void OnSelectedProfileChanged(ProfileConfigurationEventArgs e) @@ -537,6 +543,11 @@ namespace Artemis.UI.Shared.Services PixelsPerSecondChanged?.Invoke(this, EventArgs.Empty); } + protected virtual void OnSuspendEditingChanged() + { + SuspendEditingChanged?.Invoke(this, EventArgs.Empty); + } + protected virtual void OnProfilePreviewUpdated() { ProfilePreviewUpdated?.Invoke(this, EventArgs.Empty); diff --git a/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/LayerPropertiesView.xaml b/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/LayerPropertiesView.xaml index e47af2d72..5d6b0615f 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/LayerPropertiesView.xaml +++ b/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/LayerPropertiesView.xaml @@ -77,7 +77,7 @@ - + @@ -444,6 +444,28 @@ Width="319" /> + + + + + + + Timeline suspended + + + The profile is currently running in normal mode and the timeline cannot be edited. + + + Press to toggle between editor mode and normal mode. Auto-switching can be disabled in the options menu. + + + \ No newline at end of file diff --git a/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/LayerPropertiesViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/LayerPropertiesViewModel.cs index 9a1a3610a..54a144305 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/LayerPropertiesViewModel.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/LayerPropertiesViewModel.cs @@ -122,6 +122,8 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties set => ProfileEditorService.CurrentTime = TimeSpan.FromSeconds(value / ProfileEditorService.PixelsPerSecond); } + public bool SuspendedEditing => ProfileEditorService.SuspendEditing; + public int PropertyTreeIndex { get => _propertyTreeIndex; @@ -190,6 +192,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties ProfileEditorService.SelectedProfileElementChanged += SelectedProfileEditorServiceOnSelectedProfileElementChanged; ProfileEditorService.CurrentTimeChanged += ProfileEditorServiceOnCurrentTimeChanged; + ProfileEditorService.SuspendEditingChanged += ProfileEditorServiceOnSuspendEditingChanged; ProfileEditorService.SelectedDataBindingChanged += ProfileEditorServiceOnSelectedDataBindingChanged; ProfileEditorService.PixelsPerSecondChanged += ProfileEditorServiceOnPixelsPerSecondChanged; @@ -200,6 +203,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties { ProfileEditorService.SelectedProfileElementChanged -= SelectedProfileEditorServiceOnSelectedProfileElementChanged; ProfileEditorService.CurrentTimeChanged -= ProfileEditorServiceOnCurrentTimeChanged; + ProfileEditorService.SuspendEditingChanged -= ProfileEditorServiceOnSuspendEditingChanged; ProfileEditorService.SelectedDataBindingChanged -= ProfileEditorServiceOnSelectedDataBindingChanged; ProfileEditorService.PixelsPerSecondChanged -= ProfileEditorServiceOnPixelsPerSecondChanged; @@ -230,6 +234,11 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties NotifyOfPropertyChange(nameof(TimeCaretPosition)); } + private void ProfileEditorServiceOnSuspendEditingChanged(object? sender, EventArgs e) + { + NotifyOfPropertyChange(nameof(SuspendedEditing)); + } + private void ProfileEditorServiceOnPixelsPerSecondChanged(object sender, EventArgs e) { NotifyOfPropertyChange(nameof(TimeCaretPosition)); diff --git a/src/Artemis.UI/Screens/ProfileEditor/ProfileEditorViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/ProfileEditorViewModel.cs index da7eb5ad2..0ade5df53 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/ProfileEditorViewModel.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/ProfileEditorViewModel.cs @@ -326,7 +326,6 @@ namespace Artemis.UI.Screens.ProfileEditor return; _profileEditorService.SuspendEditing = !message.IsFocused; - ProfileViewModel.SuspendedEditing = !message.IsFocused; } #endregion diff --git a/src/Artemis.UI/Screens/ProfileEditor/Visualization/ProfileViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/Visualization/ProfileViewModel.cs index 40d74e2e2..4c96e86f3 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Visualization/ProfileViewModel.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/Visualization/ProfileViewModel.cs @@ -34,7 +34,6 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization private PanZoomViewModel _panZoomViewModel; private Layer _previousSelectedLayer; private int _previousTool; - private bool _suspendedEditing; public ProfileViewModel(IProfileEditorService profileEditorService, IRgbService rgbService, @@ -77,7 +76,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization get => _highlightedLeds; set => SetAndNotify(ref _highlightedLeds, value); } - + public VisualizationToolViewModel ActiveToolViewModel { get => _activeToolViewModel; @@ -119,11 +118,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization set => SetAndNotify(ref _canApplyToLayer, value); } - public bool SuspendedEditing - { - get => _suspendedEditing; - set => SetAndNotify(ref _suspendedEditing, value); - } + public bool SuspendedEditing => _profileEditorService.SuspendEditing; protected override void OnInitialActivate() { @@ -142,12 +137,13 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization ActivateToolByIndex(0); ApplyActiveProfile(); - + _lastUpdate = DateTime.Now; _coreService.FrameRendered += OnFrameRendered; _rgbService.DeviceAdded += RgbServiceOnDevicesModified; _rgbService.DeviceRemoved += RgbServiceOnDevicesModified; + _profileEditorService.SuspendEditingChanged += ProfileEditorServiceOnSuspendEditingChanged; _profileEditorService.SelectedProfileChanged += OnSelectedProfileChanged; _profileEditorService.SelectedProfileElementChanged += OnSelectedProfileElementChanged; _profileEditorService.SelectedProfileElementSaved += OnSelectedProfileElementSaved; @@ -160,6 +156,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization _coreService.FrameRendered -= OnFrameRendered; _rgbService.DeviceAdded -= RgbServiceOnDevicesModified; _rgbService.DeviceRemoved -= RgbServiceOnDevicesModified; + _profileEditorService.SuspendEditingChanged -= ProfileEditorServiceOnSuspendEditingChanged; _profileEditorService.SelectedProfileChanged -= OnSelectedProfileChanged; _profileEditorService.SelectedProfileElementChanged -= OnSelectedProfileElementChanged; _profileEditorService.SelectedProfileElementSaved -= OnSelectedProfileElementSaved; @@ -172,7 +169,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization _settingsService.GetSetting("ProfileEditor.PanY", 0d).Save(); _settingsService.GetSetting("ProfileEditor.Zoom", 0d).Value = PanZoomViewModel.Zoom; _settingsService.GetSetting("ProfileEditor.Zoom", 0d).Save(); - + base.OnClose(); } @@ -214,6 +211,13 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization private void UpdateCanSelectEditTool() { + if (SuspendedEditing) + { + CanApplyToLayer = false; + CanSelectEditTool = false; + return; + } + if (_profileEditorService.SelectedProfileElement is Layer layer) { CanApplyToLayer = true; @@ -229,13 +233,18 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization ActivateToolByIndex(2); } + private void ProfileEditorServiceOnSuspendEditingChanged(object? sender, EventArgs e) + { + NotifyOfPropertyChange(nameof(SuspendedEditing)); + } + #region Buttons private void ActivateToolByIndex(int value) { if (value == 1 && !CanSelectEditTool) return; - + switch (value) { case 0: