Profile editor - Moved layer property input to the Shared UI project

This commit is contained in:
SpoinkyNL committed 2020-06-02 15:58:19 +02:00
1 parent a5b66441d9
commit f1cbfb36e9
71 files changed
+1211 -434

No files matched your search

@@ -2,37 +2,39 @@
using System.Collections.Generic;
using System.Linq;
using Artemis.Core.Models.Profile.LayerProperties;
using Artemis.Core.Models.Profile.LayerProperties.Attributes;
using Artemis.UI.Exceptions;
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Abstract;
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Timeline;
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree;
using Artemis.UI.Services.Interfaces;
using Artemis.UI.PropertyInput;
using Artemis.UI.Shared.PropertyInput;
using Artemis.UI.Shared.Services.Interfaces;
using Humanizer;
using Ninject;
using Ninject.Parameters;
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
{
public class LayerPropertyViewModel<T> : LayerPropertyViewModel
{
public LayerPropertyViewModel(IProfileEditorService profileEditorService, LayerProperty<T> layerProperty, PropertyDescriptionAttribute propertyDescription)
: base(profileEditorService, layerProperty)
public LayerPropertyViewModel(IProfileEditorService profileEditorService, LayerProperty<T> layerProperty) : base(profileEditorService, layerProperty)
{
LayerProperty = layerProperty;
PropertyDescription = propertyDescription;
TreePropertyViewModel = ProfileEditorService.CreateTreePropertyViewModel(this);
TreePropertyViewModel = CreateTreePropertyViewModel();
TimelinePropertyViewModel = new TimelinePropertyViewModel<T>(this, profileEditorService);
TreePropertyBaseViewModel = TreePropertyViewModel;
TimelinePropertyBaseViewModel = TimelinePropertyViewModel;
// Generate a fallback name if the description does not contain one
if (PropertyDescription.Name == null)
if (LayerProperty.PropertyDescription.Name == null)
{
var propertyInfo = LayerProperty.Parent?.GetType().GetProperties().FirstOrDefault(p => ReferenceEquals(p.GetValue(LayerProperty.Parent), LayerProperty));
if (propertyInfo != null)
PropertyDescription.Name = propertyInfo.Name.Humanize();
LayerProperty.PropertyDescription.Name = propertyInfo.Name.Humanize();
else
PropertyDescription.Name = $"Unknown {typeof(T).Name} property";
LayerProperty.PropertyDescription.Name = $"Unknown {typeof(T).Name} property";
}
LayerProperty.VisibilityChanged += LayerPropertyOnVisibilityChanged;
@@ -69,6 +71,29 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
ProfileEditorService.UpdateProfilePreview();
}
private TreePropertyViewModel<T> CreateTreePropertyViewModel()
{
// Make sure there is a supported property editor VM, unless the type is an enum, then we'll use the EnumPropertyInputViewModel
Type vmType = null;
if (typeof(T).IsEnum)
vmType = typeof(EnumPropertyInputViewModel<>).MakeGenericType(typeof(T));
else
{
var registration = ProfileEditorService.RegisteredPropertyEditors.FirstOrDefault(r => r.SupportedType == typeof(T));
if (registration != null)
vmType = registration.ViewModelType;
}
if (vmType == null)
throw new ArtemisUIException($"Cannot create a tree property view model for type {typeof(T)}, found no matching property editor");
var parameters = new IParameter[]
{
new ConstructorArgument("layerProperty", LayerProperty)
};
return new TreePropertyViewModel<T>(this, (PropertyInputViewModel<T>) ProfileEditorService.Kernel.Get(vmType, parameters), ProfileEditorService);
}
private void LayerPropertyOnVisibilityChanged(object sender, EventArgs e)
{
NotifyOfPropertyChange(nameof(IsVisible));
@@ -86,7 +111,6 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
public IProfileEditorService ProfileEditorService { get; }
public BaseLayerProperty BaseLayerProperty { get; }
public PropertyDescriptionAttribute PropertyDescription { get; protected set; }
public TreePropertyViewModel TreePropertyBaseViewModel { get; set; }
public TimelinePropertyViewModel TimelinePropertyBaseViewModel { get; set; }
}