From 7b238e241e50bb23c0f2e410e576ad39eaa3094b Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Sun, 17 May 2020 18:54:15 +0200 Subject: [PATCH] Datamodels - A few small fixes to fix errors during startup Layer properties - Reimplemented property tree Stylet - Add support for binding views to generic VMs --- src/Artemis.Core/Models/Profile/Layer.cs | 4 +- .../LayerProperties/BaseLayerProperty.cs | 5 ++ .../Models/Profile/LayerPropertyGroup.cs | 11 +++- .../Plugins/Abstract/DataModels/DataModel.cs | 2 +- src/Artemis.Core/Services/LayerService.cs | 2 +- .../Services/Storage/ProfileService.cs | 12 +++++ src/Artemis.UI/Ninject/UiModule.cs | 11 +++- .../LayerProperties/LayerPropertiesView.xaml | 15 +++--- .../LayerPropertiesViewModel.cs | 9 ++-- .../LayerProperties/LayerPropertyViewModel.cs | 19 +++++-- .../Timeline/TimelineView.xaml | 12 +++++ .../SKPointPropertyInputViewModel.cs | 3 +- .../SKSizePropertyInputViewModel.cs | 3 +- .../Tree/TreePropertyView.xaml | 52 +++++++++++++++++++ .../Tree/TreePropertyViewModel.cs | 4 -- .../LayerProperties/Tree/TreeView.xaml | 4 +- .../LayerProperties/Tree/TreeViewModel.cs | 20 ++++++- .../Interfaces/IProfileEditorService.cs | 4 +- .../Services/ProfileEditorService.cs | 36 +++++++++++-- src/Artemis.UI/Stylet/ArtemisViewManager.cs | 11 +++- src/Artemis.UI/Stylet/NinjectBootstrapper.cs | 2 +- .../GeneralDataModel.cs | 8 +-- 22 files changed, 207 insertions(+), 42 deletions(-) create mode 100644 src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Timeline/TimelineView.xaml create mode 100644 src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Tree/TreePropertyView.xaml diff --git a/src/Artemis.Core/Models/Profile/Layer.cs b/src/Artemis.Core/Models/Profile/Layer.cs index 3f9dd807a..6f183e770 100644 --- a/src/Artemis.Core/Models/Profile/Layer.cs +++ b/src/Artemis.Core/Models/Profile/Layer.cs @@ -125,7 +125,7 @@ namespace Artemis.Core.Models.Profile General.ApplyToEntity(); Transform.ApplyToEntity(); - LayerBrush.BaseProperties.ApplyToEntity(); + LayerBrush?.BaseProperties.ApplyToEntity(); // LEDs LayerEntity.Leds.Clear(); @@ -212,7 +212,7 @@ namespace Artemis.Core.Models.Profile { General.Override(timeOverride); Transform.Override(timeOverride); - LayerBrush.BaseProperties.Override(timeOverride); + LayerBrush?.BaseProperties.Override(timeOverride); } /// diff --git a/src/Artemis.Core/Models/Profile/LayerProperties/BaseLayerProperty.cs b/src/Artemis.Core/Models/Profile/LayerProperties/BaseLayerProperty.cs index af9a7d590..0abc5379a 100644 --- a/src/Artemis.Core/Models/Profile/LayerProperties/BaseLayerProperty.cs +++ b/src/Artemis.Core/Models/Profile/LayerProperties/BaseLayerProperty.cs @@ -13,6 +13,11 @@ namespace Artemis.Core.Models.Profile.LayerProperties { } + /// + /// The parent group of this layer property, set after construction + /// + public LayerPropertyGroup Parent { get; internal set; } + /// /// Gets whether keyframes are supported on this property /// diff --git a/src/Artemis.Core/Models/Profile/LayerPropertyGroup.cs b/src/Artemis.Core/Models/Profile/LayerPropertyGroup.cs index c06c94647..cb4b87709 100644 --- a/src/Artemis.Core/Models/Profile/LayerPropertyGroup.cs +++ b/src/Artemis.Core/Models/Profile/LayerPropertyGroup.cs @@ -23,6 +23,11 @@ namespace Artemis.Core.Models.Profile _layerPropertyGroups = new List(); } + /// + /// The parent group of this layer property group, set after construction + /// + public LayerPropertyGroup Parent { get; internal set; } + /// /// Gets whether this property group's properties are all initialized /// @@ -67,10 +72,11 @@ namespace Artemis.Core.Models.Profile var propertyDescription = Attribute.GetCustomAttribute(propertyInfo, typeof(PropertyDescriptionAttribute)); if (propertyDescription != null) { - if (!typeof(LayerProperty<>).IsAssignableFrom(propertyInfo.PropertyType)) + if (!typeof(BaseLayerProperty).IsAssignableFrom(propertyInfo.PropertyType)) throw new ArtemisPluginException("Layer property with PropertyDescription attribute must be of type LayerProperty"); - var instance = (BaseLayerProperty) Activator.CreateInstance(propertyInfo.PropertyType); + var instance = (BaseLayerProperty) Activator.CreateInstance(propertyInfo.PropertyType, true); + instance.Parent = this; InitializeProperty(layer, path, instance); propertyInfo.SetValue(this, instance); _layerProperties.Add(instance); @@ -84,6 +90,7 @@ namespace Artemis.Core.Models.Profile throw new ArtemisPluginException("Layer property with PropertyGroupDescription attribute must be of type LayerPropertyGroup"); var instance = (LayerPropertyGroup) Activator.CreateInstance(propertyInfo.PropertyType); + instance.Parent = this; instance.InitializeProperties(layerService, layer, $"{path}{propertyInfo.Name}."); propertyInfo.SetValue(this, instance); _layerPropertyGroups.Add(instance); diff --git a/src/Artemis.Core/Plugins/Abstract/DataModels/DataModel.cs b/src/Artemis.Core/Plugins/Abstract/DataModels/DataModel.cs index 114b1aedb..372e4191b 100644 --- a/src/Artemis.Core/Plugins/Abstract/DataModels/DataModel.cs +++ b/src/Artemis.Core/Plugins/Abstract/DataModels/DataModel.cs @@ -50,7 +50,7 @@ namespace Artemis.Core.Plugins.Abstract.DataModels continue; // If the a nested datamodel, ensure the properties on there are valid - if (propertyInfo.PropertyType == typeof(DataModel)) + if (typeof(DataModel).IsAssignableFrom(propertyInfo.PropertyType)) ValidateType(propertyInfo.PropertyType); else if (!SupportedTypes.Contains(propertyInfo.PropertyType)) { diff --git a/src/Artemis.Core/Services/LayerService.cs b/src/Artemis.Core/Services/LayerService.cs index 6a1c344e3..ae742b682 100644 --- a/src/Artemis.Core/Services/LayerService.cs +++ b/src/Artemis.Core/Services/LayerService.cs @@ -40,7 +40,7 @@ namespace Artemis.Core.Services { RemoveLayerBrush(layer); - var descriptorReference = layer.General.BrushReference.CurrentValue; + var descriptorReference = layer.General.BrushReference?.CurrentValue; if (descriptorReference == null) return null; diff --git a/src/Artemis.Core/Services/Storage/ProfileService.cs b/src/Artemis.Core/Services/Storage/ProfileService.cs index 8729211b5..d886939f3 100644 --- a/src/Artemis.Core/Services/Storage/ProfileService.cs +++ b/src/Artemis.Core/Services/Storage/ProfileService.cs @@ -93,6 +93,7 @@ namespace Artemis.Core.Services.Storage module.ChangeActiveProfile(profile, _surfaceService.ActiveSurface); if (profile != null) { + InitializeCoreProperties(profile); InstantiateProfileLayerBrushes(profile); } } @@ -158,6 +159,17 @@ namespace Artemis.Core.Services.Storage _logger.Debug("Redo profile update - Success"); } + private void InitializeCoreProperties(Profile profile) + { + foreach (var layer in profile.GetAllLayers().Where(l => l.LayerBrush == null)) + { + if (!layer.General.PropertiesInitialized) + layer.General.InitializeProperties(_layerService, layer, null); + if (!layer.Transform.PropertiesInitialized) + layer.Transform.InitializeProperties(_layerService, layer, null); + }; + } + private void InstantiateProfileLayerBrushes(Profile profile) { // Only instantiate brushes for layers without an existing brush instance diff --git a/src/Artemis.UI/Ninject/UiModule.cs b/src/Artemis.UI/Ninject/UiModule.cs index 6280c051a..22d640f81 100644 --- a/src/Artemis.UI/Ninject/UiModule.cs +++ b/src/Artemis.UI/Ninject/UiModule.cs @@ -2,6 +2,7 @@ using Artemis.UI.Ninject.Factories; using Artemis.UI.Screens; using Artemis.UI.Screens.Module.ProfileEditor; +using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput.Abstract; using Artemis.UI.Services.Interfaces; using Artemis.UI.Shared.Services.Dialog; using Artemis.UI.Stylet; @@ -56,7 +57,7 @@ namespace Artemis.UI.Ninject .InheritedFrom() .BindAllBaseClasses(); }); - + // Bind all UI services as singletons Kernel.Bind(x => { @@ -76,6 +77,14 @@ namespace Artemis.UI.Ninject .InheritedFrom() .BindAllInterfaces(); }); + + Kernel.Bind(x => + { + x.FromThisAssembly() + .SelectAllClasses() + .InheritedFrom(typeof(PropertyInputViewModel<>)) + .BindToSelf(); + }); } } } \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertiesView.xaml b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertiesView.xaml index cff17995b..f82d7124f 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertiesView.xaml +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerPropertiesView.xaml @@ -18,8 +18,7 @@ - -