From 02f4609eae19e60857c894d3af06c09f64cace7a Mon Sep 17 00:00:00 2001 From: Robert Date: Sat, 18 Sep 2021 13:38:09 +0200 Subject: [PATCH] Sidebar - Show message when profile is broken Events - Keep the old event type around for if you change your mind --- .../Models/Profile/RenderProfileElement.cs | 17 +----------- .../Services/Storage/ProfileService.cs | 12 ++++++++- .../DisplayConditionsView.xaml | 17 ++++++++++-- .../DisplayConditionsViewModel.cs | 20 +++++++++++--- .../Event/EventConditionView.xaml | 6 ++--- .../Event/EventConditionViewModel.cs | 1 + .../SidebarProfileConfigurationView.xaml | 26 +++++++++++++++++-- .../Screens/Sidebar/SidebarViewModel.cs | 6 +++++ 8 files changed, 78 insertions(+), 27 deletions(-) diff --git a/src/Artemis.Core/Models/Profile/RenderProfileElement.cs b/src/Artemis.Core/Models/Profile/RenderProfileElement.cs index e33de9fc7..6428c82e4 100644 --- a/src/Artemis.Core/Models/Profile/RenderProfileElement.cs +++ b/src/Artemis.Core/Models/Profile/RenderProfileElement.cs @@ -377,7 +377,7 @@ namespace Artemis.Core public ICondition? DisplayCondition { get => _displayCondition; - private set => SetAndNotify(ref _displayCondition, value); + set => SetAndNotify(ref _displayCondition, value); } private ICondition? _displayCondition; @@ -404,21 +404,6 @@ namespace Artemis.Core DisplayConditionMet = DisplayCondition.IsMet; } - /// - /// Replaces the current with the provided or - /// - /// - /// The condition to change the to - public void ChangeDisplayCondition(ICondition? condition) - { - if (condition == DisplayCondition) - return; - - ICondition? old = DisplayCondition; - DisplayCondition = condition; - old?.Dispose(); - } - #endregion } } \ No newline at end of file diff --git a/src/Artemis.Core/Services/Storage/ProfileService.cs b/src/Artemis.Core/Services/Storage/ProfileService.cs index d981c27ff..13674ddfd 100644 --- a/src/Artemis.Core/Services/Storage/ProfileService.cs +++ b/src/Artemis.Core/Services/Storage/ProfileService.cs @@ -327,7 +327,17 @@ namespace Artemis.Core.Services if (profileConfiguration.Profile != null) return profileConfiguration.Profile; - ProfileEntity profileEntity = _profileRepository.Get(profileConfiguration.Entity.ProfileId); + ProfileEntity profileEntity; + try + { + profileEntity = _profileRepository.Get(profileConfiguration.Entity.ProfileId); + } + catch (Exception e) + { + profileConfiguration.SetBrokenState("Failed to activate profile", e); + throw; + } + if (profileEntity == null) throw new ArtemisCoreException($"Cannot find profile named: {profileConfiguration.Name} ID: {profileConfiguration.Entity.ProfileId}"); diff --git a/src/Artemis.UI/Screens/ProfileEditor/DisplayConditions/DisplayConditionsView.xaml b/src/Artemis.UI/Screens/ProfileEditor/DisplayConditions/DisplayConditionsView.xaml index beb277709..36e087d64 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/DisplayConditions/DisplayConditionsView.xaml +++ b/src/Artemis.UI/Screens/ProfileEditor/DisplayConditions/DisplayConditionsView.xaml @@ -15,7 +15,6 @@ d:DesignHeight="450" d:DesignWidth="800" d:DataContext="{d:DesignInstance {x:Type displayConditions:DisplayConditionsViewModel}}"> - @@ -100,6 +99,20 @@ s:View.Model="{Binding ActiveItem}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" - IsTabStop="False"/> + IsTabStop="False" + Visibility="{Binding ActiveItem, Converter={StaticResource NullToVisibilityConverter}}"/> + + + + Display conditions disabled + + + + This element will always display. + + \ No newline at end of file diff --git a/src/Artemis.UI/Screens/ProfileEditor/DisplayConditions/DisplayConditionsViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/DisplayConditions/DisplayConditionsViewModel.cs index 134025bf3..56030d322 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/DisplayConditions/DisplayConditionsViewModel.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/DisplayConditions/DisplayConditionsViewModel.cs @@ -11,6 +11,8 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions private readonly IConditionVmFactory _conditionVmFactory; private readonly IProfileEditorService _profileEditorService; private DisplayConditionType _displayConditionType; + private StaticCondition _staticCondition; + private EventCondition _eventCondition; public DisplayConditionsViewModel(IProfileEditorService profileEditorService, IConditionVmFactory conditionVmFactory) { @@ -47,12 +49,19 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions if (_profileEditorService.SelectedProfileElement == null) return; + // Keep the old condition around in case the user changes their mind + if (_profileEditorService.SelectedProfileElement.DisplayCondition is StaticCondition staticCondition) + _staticCondition = staticCondition; + else if (_profileEditorService.SelectedProfileElement.DisplayCondition is EventCondition eventCondition) + _eventCondition = eventCondition; + + // If we have the old condition around put it back if (DisplayConditionType == DisplayConditionType.Static) - _profileEditorService.SelectedProfileElement.ChangeDisplayCondition(new StaticCondition(_profileEditorService.SelectedProfileElement)); + _profileEditorService.SelectedProfileElement.DisplayCondition = _staticCondition ?? new StaticCondition(_profileEditorService.SelectedProfileElement); else if (DisplayConditionType == DisplayConditionType.Events) - _profileEditorService.SelectedProfileElement.ChangeDisplayCondition(new EventCondition(_profileEditorService.SelectedProfileElement)); + _profileEditorService.SelectedProfileElement.DisplayCondition = _eventCondition ?? new EventCondition(_profileEditorService.SelectedProfileElement); else - _profileEditorService.SelectedProfileElement.ChangeDisplayCondition(null); + _profileEditorService.SelectedProfileElement.DisplayCondition = null; _profileEditorService.SaveSelectedProfileElement(); Update(_profileEditorService.SelectedProfileElement); @@ -87,6 +96,11 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions private void ProfileEditorServiceOnSelectedProfileElementChanged(object sender, RenderProfileElementEventArgs e) { + if (_staticCondition != null && e.PreviousRenderProfileElement?.DisplayCondition != _staticCondition) + _staticCondition.Dispose(); + if (_eventCondition != null && e.PreviousRenderProfileElement?.DisplayCondition != _eventCondition) + _eventCondition.Dispose(); + Update(e.RenderProfileElement); } } diff --git a/src/Artemis.UI/Screens/ProfileEditor/DisplayConditions/Event/EventConditionView.xaml b/src/Artemis.UI/Screens/ProfileEditor/DisplayConditions/Event/EventConditionView.xaml index ca4f75c29..90c7225da 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/DisplayConditions/Event/EventConditionView.xaml +++ b/src/Artemis.UI/Screens/ProfileEditor/DisplayConditions/Event/EventConditionView.xaml @@ -50,7 +50,7 @@ IsChecked="{Binding TriggerConditionally}" Content="Conditional trigger" VerticalAlignment="Center" - ToolTip="When enabled, the layer will only trigger if the script evaluates to true" + ToolTip="When enabled, the element will only trigger if the script evaluates to true" Style="{StaticResource MaterialDesignDarkCheckBox}" /> - + @@ -105,7 +105,7 @@ - When enabled, the layer will only trigger if the script evaluates to true + This element will trigger any time the event fires. diff --git a/src/Artemis.UI/Screens/ProfileEditor/DisplayConditions/Event/EventConditionViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/DisplayConditions/Event/EventConditionViewModel.cs index ec3219de3..bdb5eacfb 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/DisplayConditions/Event/EventConditionViewModel.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/DisplayConditions/Event/EventConditionViewModel.cs @@ -84,6 +84,7 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions.Event { EventCondition.UpdateEventNode(); DisplayName = EventCondition.EventPath?.Segments.LastOrDefault()?.GetPropertyDescription()?.Name ?? "Invalid event"; + _profileEditorService.SaveSelectedProfileElement(); } public void ScriptGridMouseUp(object sender, MouseButtonEventArgs e) diff --git a/src/Artemis.UI/Screens/Sidebar/SidebarProfileConfigurationView.xaml b/src/Artemis.UI/Screens/Sidebar/SidebarProfileConfigurationView.xaml index 3c54f19fc..4cd8e5f90 100644 --- a/src/Artemis.UI/Screens/Sidebar/SidebarProfileConfigurationView.xaml +++ b/src/Artemis.UI/Screens/Sidebar/SidebarProfileConfigurationView.xaml @@ -19,6 +19,7 @@ + @@ -183,7 +184,13 @@ -