From 1a7a7e05829def3aded4e16b32f31cd2effbb722 Mon Sep 17 00:00:00 2001 From: Robert Date: Tue, 16 Mar 2021 19:47:27 +0100 Subject: [PATCH] Data bindings UI - Update evaluation status of conditional data bindings Profiles - Don't fail to activate a module when its last profile fails to load --- .../JsonConverters/ForgivingIntConverter.cs | 4 ++-- src/Artemis.Core/Services/ModuleService.cs | 17 ++++++++----- .../ConditionalDataBindingModeView.xaml | 7 +++--- .../ConditionalDataBindingModeViewModel.cs | 24 ++++++++++++++++--- .../DataBindingConditionViewModel.cs | 5 ++++ 5 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src/Artemis.Core/JsonConverters/ForgivingIntConverter.cs b/src/Artemis.Core/JsonConverters/ForgivingIntConverter.cs index 54edb8ed6..05845fc2e 100644 --- a/src/Artemis.Core/JsonConverters/ForgivingIntConverter.cs +++ b/src/Artemis.Core/JsonConverters/ForgivingIntConverter.cs @@ -20,14 +20,14 @@ namespace Artemis.Core.JsonConverters { JValue? jsonValue = serializer.Deserialize(reader); if (jsonValue == null) - throw new FormatException(); + throw new JsonReaderException("Failed to deserialize forgiving int value"); if (jsonValue.Type == JTokenType.Float) return (int) Math.Round(jsonValue.Value()); if (jsonValue.Type == JTokenType.Integer) return jsonValue.Value(); - throw new FormatException(); + throw new JsonReaderException("Failed to deserialize forgiving int value"); } } } \ No newline at end of file diff --git a/src/Artemis.Core/Services/ModuleService.cs b/src/Artemis.Core/Services/ModuleService.cs index f71cfac76..a6f85bcfd 100644 --- a/src/Artemis.Core/Services/ModuleService.cs +++ b/src/Artemis.Core/Services/ModuleService.cs @@ -47,15 +47,20 @@ namespace Artemis.Core.Services { module.Activate(false); - // If this is a profile module, activate the last active profile after module activation - if (module is ProfileModule profileModule) - await _profileService.ActivateLastProfileAnimated(profileModule); + try + { + // If this is a profile module, activate the last active profile after module activation + if (module is ProfileModule profileModule) + await _profileService.ActivateLastProfileAnimated(profileModule); + } + catch (Exception e) + { + _logger.Warning(e, $"Failed to activate last profile on module {module}"); + } } catch (Exception e) { - _logger.Error(new ArtemisPluginFeatureException( - module, "Failed to activate module and last profile.", e), "Failed to activate module and last profile" - ); + _logger.Error(new ArtemisPluginFeatureException(module, "Failed to activate module.", e), "Failed to activate module"); throw; } } diff --git a/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/DataBindings/ConditionalDataBinding/ConditionalDataBindingModeView.xaml b/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/DataBindings/ConditionalDataBinding/ConditionalDataBindingModeView.xaml index bed240696..493b65c76 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/DataBindings/ConditionalDataBinding/ConditionalDataBindingModeView.xaml +++ b/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/DataBindings/ConditionalDataBinding/ConditionalDataBindingModeView.xaml @@ -15,7 +15,7 @@ - + @@ -26,7 +26,8 @@ Background="{StaticResource PrimaryHueMidBrush}" BorderBrush="{StaticResource PrimaryHueMidBrush}" HorizontalAlignment="Right" - Command="{s:Action AddCondition}"> + Command="{s:Action AddCondition}" + Margin="0 5"> ADD CONDITION @@ -38,7 +39,7 @@ dd:DragDrop.UseDefaultDragAdorner="True" HorizontalContentAlignment="Stretch" VirtualizingPanel.ScrollUnit="Pixel" - Margin="0 5 0 0"> + Margin="-10 0 -10 -5"> diff --git a/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/DataBindings/ConditionalDataBinding/ConditionalDataBindingModeViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/DataBindings/ConditionalDataBinding/ConditionalDataBindingModeViewModel.cs index 620bdaee2..e3b54179a 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/DataBindings/ConditionalDataBinding/ConditionalDataBindingModeViewModel.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/DataBindings/ConditionalDataBinding/ConditionalDataBindingModeViewModel.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using Artemis.Core; +using Artemis.Core.Services; using Artemis.UI.Extensions; using Artemis.UI.Ninject.Factories; using Artemis.UI.Shared.Services; @@ -10,16 +11,20 @@ using Stylet; namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.ConditionalDataBinding { - public sealed class ConditionalDataBindingModeViewModel : Conductor>.Collection.AllActive, IDataBindingModeViewModel + public sealed class ConditionalDataBindingModeViewModel : Conductor>.Collection.AllActive, + IDataBindingModeViewModel { private readonly IDataBindingsVmFactory _dataBindingsVmFactory; + private readonly ICoreService _coreService; private readonly IProfileEditorService _profileEditorService; private bool _updating; public ConditionalDataBindingModeViewModel(ConditionalDataBinding conditionalDataBinding, + ICoreService coreService, IProfileEditorService profileEditorService, IDataBindingsVmFactory dataBindingsVmFactory) { + _coreService = coreService; _profileEditorService = profileEditorService; _dataBindingsVmFactory = dataBindingsVmFactory; @@ -41,8 +46,21 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.Conditio protected override void OnInitialActivate() { - base.OnInitialActivate(); Initialize(); + _coreService.FrameRendered += CoreServiceOnFrameRendered; + base.OnInitialActivate(); + } + + protected override void OnClose() + { + _coreService.FrameRendered -= CoreServiceOnFrameRendered; + base.OnClose(); + } + + private void CoreServiceOnFrameRendered(object? sender, FrameRenderedEventArgs e) + { + foreach (DataBindingConditionViewModel dataBindingConditionViewModel in Items) + dataBindingConditionViewModel.Evaluate(); } private void UpdateItems() @@ -109,7 +127,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.Conditio } #region IDisposable - + /// public void Dispose() { diff --git a/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/DataBindings/ConditionalDataBinding/DataBindingConditionViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/DataBindings/ConditionalDataBinding/DataBindingConditionViewModel.cs index e5980c115..81d9dfe6a 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/DataBindings/ConditionalDataBinding/DataBindingConditionViewModel.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/DataBindings/ConditionalDataBinding/DataBindingConditionViewModel.cs @@ -56,6 +56,11 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.Conditio _profileEditorService.UpdateSelectedProfileElement(); } + public void Evaluate() + { + ActiveItem?.Evaluate(); + } + #region IDisposable ///