mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Datamodels - A few small fixes to fix errors during startup
Layer properties - Reimplemented property tree Stylet - Add support for binding views to generic VMs
This commit is contained in:
parent
e036cbbfe4
commit
7b238e241e
@ -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);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@ -13,6 +13,11 @@ namespace Artemis.Core.Models.Profile.LayerProperties
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The parent group of this layer property, set after construction
|
||||
/// </summary>
|
||||
public LayerPropertyGroup Parent { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether keyframes are supported on this property
|
||||
/// </summary>
|
||||
|
||||
@ -23,6 +23,11 @@ namespace Artemis.Core.Models.Profile
|
||||
_layerPropertyGroups = new List<LayerPropertyGroup>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The parent group of this layer property group, set after construction
|
||||
/// </summary>
|
||||
public LayerPropertyGroup Parent { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether this property group's properties are all initialized
|
||||
/// </summary>
|
||||
@ -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);
|
||||
|
||||
@ -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))
|
||||
{
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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<ProfileEditorPanelViewModel>()
|
||||
.BindAllBaseClasses();
|
||||
});
|
||||
|
||||
|
||||
// Bind all UI services as singletons
|
||||
Kernel.Bind(x =>
|
||||
{
|
||||
@ -76,6 +77,14 @@ namespace Artemis.UI.Ninject
|
||||
.InheritedFrom<IValidator>()
|
||||
.BindAllInterfaces();
|
||||
});
|
||||
|
||||
Kernel.Bind(x =>
|
||||
{
|
||||
x.FromThisAssembly()
|
||||
.SelectAllClasses()
|
||||
.InheritedFrom(typeof(PropertyInputViewModel<>))
|
||||
.BindToSelf();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -18,8 +18,7 @@
|
||||
<KeyBinding Command="{s:Action PlayFromStart}" Modifiers="Shift" Key="Space" />
|
||||
</UserControl.InputBindings>
|
||||
<UserControl.Resources>
|
||||
<s:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
|
||||
<Style x:Key="SVStyle" TargetType="{x:Type ScrollViewer}">
|
||||
<Style x:Key="SvStyle" TargetType="{x:Type ScrollViewer}">
|
||||
<Setter Property="OverridesDefaultStyle" Value="True" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
@ -37,6 +36,7 @@
|
||||
<ScrollBar Name="PART_VerticalScrollBar"
|
||||
HorizontalAlignment="Right"
|
||||
Opacity="0.5"
|
||||
Grid.Row="0"
|
||||
Grid.Column="1"
|
||||
Value="{TemplateBinding VerticalOffset}"
|
||||
Maximum="{TemplateBinding ScrollableHeight}"
|
||||
@ -46,7 +46,8 @@
|
||||
VerticalAlignment="Bottom"
|
||||
Orientation="Horizontal"
|
||||
Opacity="0.5"
|
||||
Grid.Row="1"
|
||||
Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Value="{TemplateBinding HorizontalOffset}"
|
||||
Maximum="{TemplateBinding ScrollableWidth}"
|
||||
ViewportSize="{TemplateBinding ViewportWidth}"
|
||||
@ -127,14 +128,14 @@
|
||||
VerticalScrollBarVisibility="Hidden"
|
||||
ScrollChanged="TimelineScrollChanged">
|
||||
<Border BorderThickness="0,0,1,0" BorderBrush="{DynamicResource MaterialDesignDivider}">
|
||||
<ContentControl s:View.Model="{Binding PropertyTree}" />
|
||||
<ContentControl s:View.Model="{Binding TreeViewModel}" />
|
||||
</Border>
|
||||
</ScrollViewer>
|
||||
</materialDesign:DialogHost>
|
||||
</Grid>
|
||||
|
||||
<!-- Right side -->
|
||||
<Grid Grid.Column="1">
|
||||
<Grid Grid.Row="0" Grid.Column="1">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="56" />
|
||||
<RowDefinition Height="*" />
|
||||
@ -169,7 +170,7 @@
|
||||
<!-- Timeline rails -->
|
||||
<ScrollViewer x:Name="TimelineRailsScrollViewer"
|
||||
Grid.Row="1"
|
||||
Style="{StaticResource SVStyle}"
|
||||
Style="{StaticResource SvStyle}"
|
||||
HorizontalScrollBarVisibility="Auto"
|
||||
VerticalScrollBarVisibility="Auto"
|
||||
ScrollChanged="TimelineScrollChanged">
|
||||
@ -183,7 +184,7 @@
|
||||
<Line X1="0" X2="0" Y1="0" Y2="{Binding ActualHeight, ElementName=ContainerGrid}"
|
||||
StrokeThickness="2" Stroke="{StaticResource SecondaryAccentBrush}" />
|
||||
</Canvas>
|
||||
<ContentControl x:Name="PropertyTimeLine" s:View.Model="{Binding PropertyTimeline}" />
|
||||
<ContentControl x:Name="PropertyTimeLine" s:View.Model="{Binding TimelineViewModel}" />
|
||||
</Grid>
|
||||
</ScrollViewer>
|
||||
</Grid>
|
||||
|
||||
@ -31,6 +31,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
|
||||
_settingsService = settingsService;
|
||||
|
||||
PixelsPerSecond = 31;
|
||||
LayerPropertyGroups = new BindableCollection<LayerPropertyGroupViewModel>();
|
||||
}
|
||||
|
||||
public bool Playing { get; set; }
|
||||
@ -59,9 +60,6 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
|
||||
|
||||
protected override void OnInitialActivate()
|
||||
{
|
||||
TreeViewModel = new TreeViewModel(LayerPropertyGroups);
|
||||
TimelineViewModel = new TimelineViewModel(LayerPropertyGroups);
|
||||
|
||||
PopulateProperties(_profileEditorService.SelectedProfileElement);
|
||||
|
||||
_profileEditorService.ProfileElementSelected += ProfileEditorServiceOnProfileElementSelected;
|
||||
@ -114,6 +112,9 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
|
||||
LayerPropertyGroups.Add(new LayerPropertyGroupViewModel(_profileEditorService, layer.General, (PropertyGroupDescriptionAttribute) generalAttribute));
|
||||
LayerPropertyGroups.Add(new LayerPropertyGroupViewModel(_profileEditorService, layer.Transform, (PropertyGroupDescriptionAttribute) transformAttribute));
|
||||
|
||||
if (layer.LayerBrush == null)
|
||||
return;
|
||||
|
||||
// Add the rout group of the brush
|
||||
// The root group of the brush has no attribute so let's pull one out of our sleeve
|
||||
var brushDescription = new PropertyGroupDescriptionAttribute
|
||||
@ -123,6 +124,8 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
|
||||
};
|
||||
LayerPropertyGroups.Add(new LayerPropertyGroupViewModel(_profileEditorService, layer.LayerBrush.BaseProperties, brushDescription));
|
||||
}
|
||||
TreeViewModel = new TreeViewModel(LayerPropertyGroups);
|
||||
TimelineViewModel = new TimelineViewModel(LayerPropertyGroups);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -6,6 +6,7 @@ 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 Humanizer;
|
||||
|
||||
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
|
||||
{
|
||||
@ -17,11 +18,21 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
|
||||
LayerProperty = layerProperty;
|
||||
PropertyDescription = propertyDescription;
|
||||
|
||||
TreePropertyViewModel = new TreePropertyViewModel<T>(this);
|
||||
TreePropertyViewModel = ProfileEditorService.CreateTreePropertyViewModel(this);
|
||||
TimelinePropertyViewModel = new TimelinePropertyViewModel<T>(this);
|
||||
|
||||
TreePropertyBaseViewModel = TreePropertyViewModel;
|
||||
TimelinePropertyBaseViewModel = TimelinePropertyViewModel;
|
||||
|
||||
// Generate a fallback name if the description does not contain one
|
||||
if (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();
|
||||
else
|
||||
PropertyDescription.Name = $"Unknown {typeof(T).Name} property";
|
||||
}
|
||||
}
|
||||
|
||||
public override bool IsVisible => !LayerProperty.IsHidden;
|
||||
@ -54,15 +65,15 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
|
||||
|
||||
public abstract class LayerPropertyViewModel : LayerPropertyBaseViewModel
|
||||
{
|
||||
public IProfileEditorService ProfileEditorService { get; }
|
||||
public BaseLayerProperty BaseLayerProperty { get; }
|
||||
|
||||
protected LayerPropertyViewModel(IProfileEditorService profileEditorService, BaseLayerProperty baseLayerProperty)
|
||||
{
|
||||
ProfileEditorService = profileEditorService;
|
||||
BaseLayerProperty = baseLayerProperty;
|
||||
}
|
||||
|
||||
public IProfileEditorService ProfileEditorService { get; }
|
||||
public BaseLayerProperty BaseLayerProperty { get; }
|
||||
|
||||
public PropertyDescriptionAttribute PropertyDescription { get; protected set; }
|
||||
public TreePropertyViewModel TreePropertyBaseViewModel { get; set; }
|
||||
public TimelinePropertyViewModel TimelinePropertyBaseViewModel { get; set; }
|
||||
|
||||
@ -0,0 +1,12 @@
|
||||
<UserControl x:Class="Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Timeline.TimelineView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Timeline"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<Grid>
|
||||
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@ -8,7 +8,8 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyI
|
||||
{
|
||||
public class SKPointPropertyInputViewModel : PropertyInputViewModel<SKPoint>
|
||||
{
|
||||
public SKPointPropertyInputViewModel(LayerPropertyViewModel<SKPoint> layerPropertyViewModel, IModelValidator validator) : base(layerPropertyViewModel, validator)
|
||||
public SKPointPropertyInputViewModel(LayerPropertyViewModel<SKPoint> layerPropertyViewModel, IModelValidator<SKPointPropertyInputViewModel> validator)
|
||||
: base(layerPropertyViewModel, validator)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@ -8,7 +8,8 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyI
|
||||
{
|
||||
public class SKSizePropertyInputViewModel : PropertyInputViewModel<SKSize>
|
||||
{
|
||||
public SKSizePropertyInputViewModel(LayerPropertyViewModel<SKSize> layerPropertyViewModel, IModelValidator validator) : base(layerPropertyViewModel, validator)
|
||||
public SKSizePropertyInputViewModel(LayerPropertyViewModel<SKSize> layerPropertyViewModel, IModelValidator<SKSizePropertyInputViewModel> validator)
|
||||
: base(layerPropertyViewModel, validator)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,52 @@
|
||||
<UserControl x:Class="Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.TreePropertyView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<Grid Height="22">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<ToggleButton Grid.Column="0"
|
||||
Style="{StaticResource MaterialDesignFlatToggleButton}"
|
||||
ToolTip="Toggle key-framing"
|
||||
Width="18"
|
||||
Height="18"
|
||||
IsChecked="{Binding LayerPropertyViewModel.LayerProperty.KeyframesEnabled}"
|
||||
IsEnabled="{Binding LayerPropertyViewModel.LayerProperty.KeyframesSupported}"
|
||||
VerticalAlignment="Center" Padding="-25">
|
||||
<materialDesign:PackIcon Kind="Stopwatch" Height="13" Width="13" />
|
||||
</ToggleButton>
|
||||
|
||||
<TextBlock Grid.Column="1"
|
||||
Margin="5,0,0,0"
|
||||
Padding="0,0,5,0"
|
||||
VerticalAlignment="Center"
|
||||
TextTrimming="CharacterEllipsis"
|
||||
Text="{Binding LayerPropertyViewModel.PropertyDescription.Name}"
|
||||
ToolTip="{Binding LayerPropertyViewModel.PropertyDescription.Description}"
|
||||
HorizontalAlignment="Left" />
|
||||
|
||||
<ContentControl Grid.Column="2" Margin="20 0" s:View.Model="{Binding PropertyInputViewModel}" />
|
||||
|
||||
<Button Grid.Column="3"
|
||||
Style="{StaticResource MaterialDesignOutlinedButton}"
|
||||
Margin="0,1,0,1.2"
|
||||
Padding="0"
|
||||
Width="80"
|
||||
Height="20"
|
||||
ToolTip="Change the property's data binding"
|
||||
VerticalAlignment="Center"
|
||||
IsEnabled="False">
|
||||
<TextBlock FontSize="10">DATA BINDING</TextBlock>
|
||||
</Button>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@ -30,9 +30,5 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree
|
||||
|
||||
public LayerPropertyBaseViewModel LayerPropertyBaseViewModel { get; }
|
||||
public abstract void Dispose();
|
||||
|
||||
public static void RegisterPropertyInputViewModel()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -103,9 +103,7 @@
|
||||
</StackPanel>
|
||||
</HierarchicalDataTemplate>
|
||||
<DataTemplate DataType="{x:Type layerProperties:LayerPropertyViewModel}">
|
||||
<!-- <ContentControl s:View.Model="{Binding TreePropertyBaseViewModel}" /> -->
|
||||
<TextBlock Text="{Binding PropertyDescription.Name}"
|
||||
ToolTip="{Binding PropertyDescription.Description}" Margin="5 0" VerticalAlignment="Center" />
|
||||
<ContentControl s:View.Model="{Binding TreePropertyBaseViewModel}" />
|
||||
</DataTemplate>
|
||||
</TreeView.Resources>
|
||||
</TreeView>
|
||||
|
||||
@ -1,4 +1,7 @@
|
||||
using Stylet;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree
|
||||
{
|
||||
@ -10,5 +13,20 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree
|
||||
}
|
||||
|
||||
public BindableCollection<LayerPropertyGroupViewModel> LayerPropertyGroups { get; }
|
||||
|
||||
public void PropertyTreePreviewMouseWheel(object sender, MouseWheelEventArgs e)
|
||||
{
|
||||
if (e.Handled || !(sender is TreeView))
|
||||
return;
|
||||
|
||||
e.Handled = true;
|
||||
var eventArg = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta)
|
||||
{
|
||||
RoutedEvent = UIElement.MouseWheelEvent,
|
||||
Source = sender
|
||||
};
|
||||
var parent = ((Control) sender).Parent as UIElement;
|
||||
parent?.RaiseEvent(eventArg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4,8 +4,10 @@ using Artemis.Core.Models.Profile.LayerProperties;
|
||||
using Artemis.Core.Models.Profile.LayerProperties.Attributes;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.UI.Events;
|
||||
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties;
|
||||
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Abstract;
|
||||
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree;
|
||||
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput.Abstract;
|
||||
|
||||
namespace Artemis.UI.Services.Interfaces
|
||||
{
|
||||
@ -56,6 +58,6 @@ namespace Artemis.UI.Services.Interfaces
|
||||
/// </summary>
|
||||
event EventHandler ProfilePreviewUpdated;
|
||||
|
||||
TreePropertyViewModel<T> CreateTreePropertyViewModel<T>();
|
||||
TreePropertyViewModel<T> CreateTreePropertyViewModel<T>(LayerPropertyViewModel<T> layerPropertyViewModel);
|
||||
}
|
||||
}
|
||||
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.Core.Models.Profile.Colors;
|
||||
using Artemis.Core.Models.Profile.LayerProperties;
|
||||
using Artemis.Core.Models.Profile.LayerProperties.Attributes;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
@ -12,9 +13,12 @@ using Artemis.UI.Events;
|
||||
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties;
|
||||
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Abstract;
|
||||
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree;
|
||||
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput;
|
||||
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput.Abstract;
|
||||
using Artemis.UI.Services.Interfaces;
|
||||
using Ninject;
|
||||
using Ninject.Parameters;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.UI.Services
|
||||
{
|
||||
@ -23,7 +27,6 @@ namespace Artemis.UI.Services
|
||||
private readonly ICoreService _coreService;
|
||||
private readonly IProfileService _profileService;
|
||||
private readonly IKernel _kernel;
|
||||
private readonly List<Type> _registeredProfileEditors;
|
||||
private TimeSpan _currentTime;
|
||||
private TimeSpan _lastUpdateTime;
|
||||
|
||||
@ -32,10 +35,20 @@ namespace Artemis.UI.Services
|
||||
_coreService = coreService;
|
||||
_profileService = profileService;
|
||||
_kernel = kernel;
|
||||
_registeredProfileEditors = new List<Type>();
|
||||
|
||||
RegisteredPropertyEditors = new Dictionary<Type, Type>
|
||||
{
|
||||
{typeof(LayerBrushReference), typeof(BrushPropertyInputViewModel)},
|
||||
{typeof(ColorGradient), typeof(ColorGradientPropertyInputViewModel)},
|
||||
{typeof(float), typeof(FloatPropertyInputViewModel)},
|
||||
{typeof(int), typeof(IntPropertyInputViewModel)},
|
||||
{typeof(SKColor), typeof(SKColorPropertyInputViewModel)},
|
||||
{typeof(SKPoint), typeof(SKPointPropertyInputViewModel)},
|
||||
{typeof(SKSize), typeof(SKSizePropertyInputViewModel)}
|
||||
};
|
||||
}
|
||||
|
||||
public ReadOnlyCollection<Type> RegisteredPropertyEditors => _registeredProfileEditors.AsReadOnly();
|
||||
public Dictionary<Type, Type> RegisteredPropertyEditors { get; set; }
|
||||
|
||||
public Profile SelectedProfile { get; private set; }
|
||||
public ProfileElement SelectedProfileElement { get; private set; }
|
||||
@ -56,9 +69,9 @@ namespace Artemis.UI.Services
|
||||
public LayerPropertyBaseViewModel CreateLayerPropertyViewModel(BaseLayerProperty baseLayerProperty, PropertyDescriptionAttribute propertyDescription)
|
||||
{
|
||||
// Go through the pain of instantiating a generic type VM now via reflection to make things a lot simpler down the line
|
||||
var genericType = baseLayerProperty.GetType().GetGenericArguments()[0];
|
||||
var genericType = baseLayerProperty.GetType().BaseType.GetGenericArguments()[0];
|
||||
// Only create entries for types supported by a tree input VM
|
||||
if (!TreePropertyViewModel.IsPropertySupported(genericType))
|
||||
if (!genericType.IsEnum && !RegisteredPropertyEditors.ContainsKey(genericType))
|
||||
return null;
|
||||
var genericViewModel = typeof(LayerPropertyViewModel<>).MakeGenericType(genericType);
|
||||
var parameters = new IParameter[]
|
||||
@ -70,6 +83,19 @@ namespace Artemis.UI.Services
|
||||
return (LayerPropertyBaseViewModel) _kernel.Get(genericViewModel, parameters);
|
||||
}
|
||||
|
||||
public TreePropertyViewModel<T> CreateTreePropertyViewModel<T>(LayerPropertyViewModel<T> layerPropertyViewModel)
|
||||
{
|
||||
var type = typeof(T).IsEnum
|
||||
? typeof(EnumPropertyInputViewModel<>).MakeGenericType(typeof(T))
|
||||
: RegisteredPropertyEditors[typeof(T)];
|
||||
|
||||
var parameters = new IParameter[]
|
||||
{
|
||||
new ConstructorArgument("layerPropertyViewModel", layerPropertyViewModel)
|
||||
};
|
||||
return new TreePropertyViewModel<T>(layerPropertyViewModel, (PropertyInputViewModel<T>) _kernel.Get(type, parameters));
|
||||
}
|
||||
|
||||
public void ChangeSelectedProfile(Profile profile)
|
||||
{
|
||||
ChangeSelectedProfileElement(null);
|
||||
|
||||
@ -1,4 +1,7 @@
|
||||
using Stylet;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Stylet
|
||||
{
|
||||
@ -7,5 +10,11 @@ namespace Artemis.UI.Stylet
|
||||
public ArtemisViewManager(ViewManagerConfig config) : base(config)
|
||||
{
|
||||
}
|
||||
|
||||
protected override string ViewTypeNameForModelTypeName(string modelTypeName)
|
||||
{
|
||||
var cleaned = modelTypeName.Split('`')[0];
|
||||
return base.ViewTypeNameForModelTypeName(cleaned);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -44,7 +44,7 @@ namespace Artemis.UI.Stylet
|
||||
ViewFactory = GetInstance,
|
||||
ViewAssemblies = new List<Assembly> {GetType().Assembly}
|
||||
};
|
||||
kernel.Bind<IViewManager>().ToConstant(new ViewManager(viewManagerConfig));
|
||||
kernel.Bind<IViewManager>().ToConstant(new ArtemisViewManager(viewManagerConfig));
|
||||
|
||||
kernel.Bind<IWindowManagerConfig>().ToConstant(this).InTransientScope();
|
||||
kernel.Bind<IWindowManager>().ToMethod(
|
||||
|
||||
@ -9,6 +9,7 @@ namespace Artemis.Plugins.Modules.General
|
||||
{
|
||||
public GeneralDataModel(Module module) : base(module)
|
||||
{
|
||||
PlayerInfo = new PlayerInfo(module);
|
||||
}
|
||||
|
||||
[DataModelProperty(Name = "A test string", Description = "This is a test string that's not of any use outside testing!")]
|
||||
@ -21,7 +22,7 @@ namespace Artemis.Plugins.Modules.General
|
||||
public PlayerInfo PlayerInfo { get; set; }
|
||||
}
|
||||
|
||||
public class PlayerInfo
|
||||
public class PlayerInfo : DataModel
|
||||
{
|
||||
[DataModelProperty(Name = "A test string", Description = "This is a test string that's not of any use outside testing!")]
|
||||
public string TestString { get; set; }
|
||||
@ -29,7 +30,8 @@ namespace Artemis.Plugins.Modules.General
|
||||
[DataModelProperty(Name = "A test boolean", Description = "This is a test boolean that's not of any use outside testing!")]
|
||||
public bool TestBoolean { get; set; }
|
||||
|
||||
[DataModelProperty()]
|
||||
public SKRect SkRect { get; set; }
|
||||
public PlayerInfo(Module module) : base(module)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user