1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Layer properties - Updated property input views and VMs

This commit is contained in:
SpoinkyNL 2020-05-16 22:56:12 +02:00
parent af21d83487
commit e036cbbfe4
22 changed files with 283 additions and 362 deletions

View File

@ -1,12 +1,8 @@
using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Profile.LayerProperties;
using Artemis.Core.Models.Surface;
using Artemis.Core.Plugins.Abstract;
using Artemis.UI.Screens.Module;
using Artemis.UI.Screens.Module.ProfileEditor;
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties;
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree;
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Timeline;
using Artemis.UI.Screens.Module.ProfileEditor.ProfileTree.TreeItem;
using Artemis.UI.Screens.Module.ProfileEditor.Visualization;
using Artemis.UI.Screens.Settings.Tabs.Devices;

View File

@ -2,7 +2,6 @@
using Artemis.UI.Ninject.Factories;
using Artemis.UI.Screens;
using Artemis.UI.Screens.Module.ProfileEditor;
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput;
using Artemis.UI.Services.Interfaces;
using Artemis.UI.Shared.Services.Dialog;
using Artemis.UI.Stylet;
@ -58,15 +57,6 @@ namespace Artemis.UI.Ninject
.BindAllBaseClasses();
});
// Bind property input VMs
Kernel.Bind(x =>
{
x.FromThisAssembly()
.SelectAllClasses()
.InheritedFrom<PropertyInputViewModel>()
.BindAllBaseClasses();
});
// Bind all UI services as singletons
Kernel.Bind(x =>
{

View File

@ -0,0 +1,93 @@
using System;
using Stylet;
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput.Abstract
{
public abstract class PropertyInputViewModel<T> : ValidatingModelBase, IDisposable
{
private T _inputValue;
protected PropertyInputViewModel(LayerPropertyViewModel<T> layerPropertyViewModel)
{
LayerPropertyViewModel = layerPropertyViewModel;
LayerPropertyViewModel.LayerProperty.Updated += LayerPropertyOnUpdated;
}
protected PropertyInputViewModel(LayerPropertyViewModel<T> layerPropertyViewModel, IModelValidator validator) : base(validator)
{
LayerPropertyViewModel = layerPropertyViewModel;
LayerPropertyViewModel.LayerProperty.Updated += LayerPropertyOnUpdated;
}
public LayerPropertyViewModel<T> LayerPropertyViewModel { get; }
public bool InputDragging { get; private set; }
public T InputValue
{
get => _inputValue;
set
{
_inputValue = value;
ApplyInputValue();
}
}
public virtual void Dispose()
{
LayerPropertyViewModel.LayerProperty.Updated -= LayerPropertyOnUpdated;
}
protected virtual void OnInputValueChanged()
{
}
private void LayerPropertyOnUpdated(object sender, EventArgs e)
{
UpdateInputValue();
}
private void UpdateInputValue()
{
// Avoid unnecessary UI updates and validator cycles
if (_inputValue.Equals(LayerPropertyViewModel.LayerProperty.CurrentValue))
return;
// Override the input value
_inputValue = LayerPropertyViewModel.LayerProperty.CurrentValue;
// Notify a change in the input value
OnInputValueChanged();
NotifyOfPropertyChange(nameof(InputValue));
// Force the validator to run with the overridden value
Validate();
}
private void ApplyInputValue()
{
// Force the validator to run
Validate();
// Only apply the input value to the layer property if the validator found no errors
if (!HasErrors)
LayerPropertyViewModel.SetCurrentValue(_inputValue, !InputDragging);
OnInputValueChanged();
}
#region Event handlers
public void InputDragStarted(object sender, EventArgs e)
{
InputDragging = true;
}
public void InputDragEnded(object sender, EventArgs e)
{
InputDragging = false;
LayerPropertyViewModel.ProfileEditorService.UpdateSelectedProfileElement();
}
#endregion
}
}

View File

@ -1,23 +1,25 @@
<UserControl x:Class="Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput.BrushPropertyInputView"
<UserControl x:Class="Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput.BrushPropertyInputView"
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:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:propertyInput="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance {x:Type propertyInput:BrushPropertyInputViewModel}}">
<StackPanel Orientation="Horizontal">
<TextBlock Margin="0 0 5 4" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.LayerProperty.InputPrefix}" />
<TextBlock Margin="0 0 5 4" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.PropertyDescription.InputPrefix}" />
<ComboBox Width="132"
Margin="0 2"
Padding="0 -1"
Height="15"
materialDesign:ValidationAssist.UsePopup="True"
HorizontalAlignment="Left"
ItemsSource="{Binding Path=EnumValues}"
ItemsSource="{Binding Path=ComboboxValues}"
SelectedValuePath="Value"
DisplayMemberPath="Description"
SelectedValue="{Binding Path=BrushInputValue}" />
<TextBlock Margin="5 0 0 4" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.LayerProperty.InputAffix}" />
SelectedValue="{Binding Path=InputValue}" />
<TextBlock Margin="5 0 0 4" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.PropertyDescription.InputAffix}" />
</StackPanel>
</UserControl>

View File

@ -1,16 +1,14 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using Artemis.Core.Events;
using Artemis.Core.Models.Profile;
using Artemis.Core.Plugins.LayerBrush;
using Artemis.Core.Services.Interfaces;
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput;
using Artemis.UI.Services.Interfaces;
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput.Abstract;
using Artemis.UI.Shared.Utilities;
using Stylet;
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput
{
public class BrushPropertyInputViewModel : PropertyInputViewModel<LayerBrushReference>
{
@ -22,22 +20,13 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.P
{
_layerService = layerService;
_pluginService = pluginService;
EnumValues = new BindableCollection<ValueDescription>();
ComboboxValues = new BindableCollection<ValueDescription>();
_pluginService.PluginLoaded += PluginServiceOnPluginLoaded;
UpdateEnumValues();
}
public BindableCollection<ValueDescription> EnumValues { get; }
public LayerBrushReference BrushInputValue
{
get => (LayerBrushReference) InputValue;
set
{
InputValue = value;
_layerService.InstantiateLayerBrush(LayerPropertyViewModel.LayerProperty.Layer);
}
}
public BindableCollection<ValueDescription> ComboboxValues { get; }
public void UpdateEnumValues()
{
@ -49,18 +38,14 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.P
{
var brushName = layerBrushDescriptor.LayerBrushType.Name;
var brushGuid = layerBrushDescriptor.LayerBrushProvider.PluginInfo.Guid;
if (BrushInputValue != null && BrushInputValue.BrushType == brushName && BrushInputValue.BrushPluginGuid == brushGuid)
enumValues.Add(new ValueDescription {Description = layerBrushDescriptor.DisplayName, Value = BrushInputValue});
if (InputValue != null && InputValue.BrushType == brushName && InputValue.BrushPluginGuid == brushGuid)
enumValues.Add(new ValueDescription {Description = layerBrushDescriptor.DisplayName, Value = InputValue});
else
enumValues.Add(new ValueDescription {Description = layerBrushDescriptor.DisplayName, Value = new LayerBrushReference {BrushType = brushName, BrushPluginGuid = brushGuid}});
}
EnumValues.Clear();
EnumValues.AddRange(enumValues);
}
public override void Update()
{
NotifyOfPropertyChange(() => BrushInputValue);
ComboboxValues.Clear();
ComboboxValues.AddRange(enumValues);
}
public override void Dispose()
@ -69,12 +54,6 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.P
base.Dispose();
}
protected override void OnInitialized()
{
UpdateEnumValues();
base.OnInitialized();
}
private void PluginServiceOnPluginLoaded(object sender, PluginEventArgs e)
{
UpdateEnumValues();

View File

@ -1,22 +1,20 @@
<UserControl x:Class="Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput.ColorGradientPropertyInputView"
<UserControl x:Class="Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput.ColorGradientPropertyInputView"
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.PropertyTree.PropertyInput"
xmlns:artemis="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
xmlns:converters="clr-namespace:Artemis.UI.Shared.Converters;assembly=Artemis.UI.Shared"
xmlns:controls="clr-namespace:Artemis.UI.Shared.Controls;assembly=Artemis.UI.Shared"
xmlns:propertyInput="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput"
mc:Ignorable="d"
d:DesignHeight="25" d:DesignWidth="800"
d:DataContext="{d:DesignInstance local:ColorGradientPropertyInputViewModel}">
d:DataContext="{d:DesignInstance propertyInput:ColorGradientPropertyInputViewModel}">
<StackPanel Orientation="Horizontal">
<TextBlock Margin="0 0 5 4" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.LayerProperty.InputPrefix}" />
<TextBlock Margin="0 0 5 4" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.PropertyDescription.InputPrefix}" />
<controls:GradientPicker Width="132"
Margin="0 2"
Padding="0 -1"
ColorGradient="{Binding ColorGradientInputValue}"
ColorGradient="{Binding InputValue}"
DialogHost="PropertyTreeDialogHost"/>
<TextBlock Margin="5 0 0 4" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.LayerProperty.InputAffix}" />
<TextBlock Margin="5 0 0 4" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.PropertyDescription.InputAffix}" />
</StackPanel>
</UserControl>

View File

@ -1,28 +1,12 @@
using System;
using System.Collections.Generic;
using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Profile.Colors;
using Artemis.UI.Services.Interfaces;
using Artemis.Core.Models.Profile.Colors;
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput.Abstract;
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput
{
public class ColorGradientPropertyInputViewModel : PropertyInputViewModel
public class ColorGradientPropertyInputViewModel : PropertyInputViewModel<ColorGradient>
{
public ColorGradientPropertyInputViewModel(IProfileEditorService profileEditorService) : base(profileEditorService)
public ColorGradientPropertyInputViewModel(LayerPropertyViewModel<ColorGradient> layerPropertyViewModel) : base(layerPropertyViewModel)
{
}
public sealed override List<Type> CompatibleTypes { get; } = new List<Type> {typeof(ColorGradient)};
public ColorGradient ColorGradientInputValue
{
get => (ColorGradient) InputValue ?? new ColorGradient();
set => InputValue = value;
}
public override void Update()
{
NotifyOfPropertyChange(() => ColorGradientInputValue);
}
}
}

View File

@ -1,15 +1,13 @@
<UserControl x:Class="Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput.EnumPropertyInputView"
<UserControl x:Class="Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput.EnumPropertyInputView"
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.PropertyTree.PropertyInput"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance local:EnumPropertyInputViewModel}">
d:DesignHeight="450" d:DesignWidth="800">
<StackPanel Orientation="Horizontal">
<TextBlock Margin="0 0 5 4" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.LayerProperty.InputPrefix}" />
<TextBlock Margin="0 0 5 4" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.PropertyDescription.InputPrefix}" />
<ComboBox Width="132"
Margin="0 2"
Padding="0 -1"
@ -19,7 +17,7 @@
ItemsSource="{Binding Path=EnumValues}"
SelectedValuePath="Value"
DisplayMemberPath="Description"
SelectedValue="{Binding Path=EnumInputValue}" />
<TextBlock Margin="5 0 0 4" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.LayerProperty.InputAffix}" />
SelectedValue="{Binding Path=InputValue}" />
<TextBlock Margin="5 0 0 4" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.PropertyDescription.InputAffix}" />
</StackPanel>
</UserControl>

View File

@ -1,41 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Artemis.UI.Services.Interfaces;
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput.Abstract;
using Artemis.UI.Shared.Utilities;
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput
{
public class EnumPropertyInputViewModel : PropertyInputViewModel
public class EnumPropertyInputViewModel<T> : PropertyInputViewModel<T> where T : Enum
{
public EnumPropertyInputViewModel(IProfileEditorService profileEditorService) : base(profileEditorService)
public EnumPropertyInputViewModel(LayerPropertyViewModel<T> layerPropertyViewModel) : base(layerPropertyViewModel)
{
EnumValues = EnumUtilities.GetAllValuesAndDescriptions(typeof(T));
}
public IEnumerable<ValueDescription> EnumValues { get; private set; }
public sealed override List<Type> CompatibleTypes { get; } = new List<Type> {typeof(Enum)};
public object EnumInputValue
{
get => InputValue ?? Enum.GetValues(GetLayerPropertyEnumType()).Cast<object>().First();
set => InputValue = value;
}
public override void Update()
{
NotifyOfPropertyChange(() => EnumInputValue);
}
protected override void OnInitialized()
{
EnumValues = EnumUtilities.GetAllValuesAndDescriptions(GetLayerPropertyEnumType());
}
private Type GetLayerPropertyEnumType()
{
return LayerPropertyViewModel.BaseLayerProperty.GetType().GetGenericTypeDefinition();
}
public IEnumerable<ValueDescription> EnumValues { get; }
}
}

View File

@ -1,21 +1,22 @@
<UserControl x:Class="Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput.FloatPropertyInputView"
<UserControl x:Class="Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput.FloatPropertyInputView"
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.PropertyTree.PropertyInput"
xmlns:local="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput"
xmlns:s="https://github.com/canton7/Stylet"
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
xmlns:controls="clr-namespace:Artemis.UI.Shared.Controls;assembly=Artemis.UI.Shared"
xmlns:propertyInput="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance local:FloatPropertyInputViewModel}">
d:DataContext="{d:DesignInstance propertyInput:FloatPropertyInputViewModel}">
<StackPanel Orientation="Horizontal">
<TextBlock Margin="0 0 5 4" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.LayerProperty.InputPrefix}" />
<controls:DraggableFloat Value="{Binding FloatInputValue}"
StepSize="{Binding LayerPropertyViewModel.LayerProperty.InputStepSize}"
<TextBlock Margin="0 0 5 4" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.PropertyDescription.InputPrefix}" />
<controls:DraggableFloat Value="{Binding InputValue}"
StepSize="{Binding LayerPropertyViewModel.PropertyDescription.InputStepSize}"
DragStarted="{s:Action InputDragStarted}"
DragEnded="{s:Action InputDragEnded}" />
<TextBlock Margin="5 0 0 4" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.LayerProperty.InputAffix}" />
<TextBlock Margin="5 0 0 4" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.PropertyDescription.InputAffix}" />
</StackPanel>
</UserControl>

View File

@ -1,39 +1,28 @@
using System;
using System.Collections.Generic;
using Artemis.UI.Services.Interfaces;
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput.Abstract;
using FluentValidation;
using Stylet;
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput
{
public class FloatPropertyInputViewModel : PropertyInputViewModel
public class FloatPropertyInputViewModel : PropertyInputViewModel<float>
{
public FloatPropertyInputViewModel(IProfileEditorService profileEditorService) : base(profileEditorService)
public FloatPropertyInputViewModel(LayerPropertyViewModel<float> layerPropertyViewModel, IModelValidator<FloatPropertyInputViewModel> validator)
: base(layerPropertyViewModel, validator)
{
}
public sealed override List<Type> CompatibleTypes { get; } = new List<Type> {typeof(float)};
public float FloatInputValue
{
get => (float?) InputValue ?? 0f;
set => InputValue = ApplyInputValue(value);
}
public override void Update()
public class FloatPropertyInputViewModelValidator : AbstractValidator<FloatPropertyInputViewModel>
{
NotifyOfPropertyChange(() => FloatInputValue);
}
private float ApplyInputValue(float value)
public FloatPropertyInputViewModelValidator()
{
if (LayerPropertyViewModel.LayerProperty.MaxInputValue != null &&
LayerPropertyViewModel.LayerProperty.MaxInputValue is float maxFloat)
value = Math.Min(value, maxFloat);
if (LayerPropertyViewModel.LayerProperty.MinInputValue != null &&
LayerPropertyViewModel.LayerProperty.MinInputValue is float minFloat)
value = Math.Max(value, minFloat);
RuleFor(vm => vm.InputValue)
.LessThanOrEqualTo(vm => (float) vm.LayerPropertyViewModel.PropertyDescription.MaxInputValue)
.When(vm => vm.LayerPropertyViewModel.PropertyDescription.MaxInputValue is float);
return value;
RuleFor(vm => vm.InputValue)
.GreaterThanOrEqualTo(vm => (float) vm.LayerPropertyViewModel.PropertyDescription.MinInputValue)
.When(vm => vm.LayerPropertyViewModel.PropertyDescription.MinInputValue is float);
}
}
}

View File

@ -1,21 +1,22 @@
<UserControl x:Class="Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput.IntPropertyInputView"
<UserControl x:Class="Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput.IntPropertyInputView"
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.PropertyTree.PropertyInput"
xmlns:local="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput"
xmlns:s="https://github.com/canton7/Stylet"
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
xmlns:controls="clr-namespace:Artemis.UI.Shared.Controls;assembly=Artemis.UI.Shared"
xmlns:propertyInput="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance local:IntPropertyInputViewModel}">
d:DataContext="{d:DesignInstance propertyInput:IntPropertyInputViewModel}">
<StackPanel Orientation="Horizontal">
<TextBlock Margin="0 0 5 4" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.LayerProperty.InputPrefix}" />
<controls:DraggableFloat Value="{Binding IntInputValue}"
StepSize="{Binding LayerPropertyViewModel.LayerProperty.InputStepSize}"
<TextBlock Margin="0 0 5 4" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.PropertyDescription.InputPrefix}" />
<controls:DraggableFloat Value="{Binding InputValue}"
StepSize="{Binding LayerPropertyViewModel.PropertyDescription.InputStepSize}"
DragStarted="{s:Action InputDragStarted}"
DragEnded="{s:Action InputDragEnded}" />
<TextBlock Margin="5 0 0 4" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.LayerProperty.InputAffix}" />
<TextBlock Margin="5 0 0 4" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.PropertyDescription.InputAffix}" />
</StackPanel>
</UserControl>

View File

@ -1,38 +1,28 @@
using System;
using System.Collections.Generic;
using Artemis.UI.Services.Interfaces;
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput.Abstract;
using FluentValidation;
using Stylet;
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput
{
public class IntPropertyInputViewModel : PropertyInputViewModel
public class IntPropertyInputViewModel : PropertyInputViewModel<int>
{
public IntPropertyInputViewModel(IProfileEditorService profileEditorService) : base(profileEditorService)
public IntPropertyInputViewModel(LayerPropertyViewModel<int> layerPropertyViewModel, IModelValidator<IntPropertyInputViewModel> validator)
: base(layerPropertyViewModel, validator)
{
}
public sealed override List<Type> CompatibleTypes { get; } = new List<Type> {typeof(int)};
public int IntInputValue
{
get => (int?) InputValue ?? 0;
set => InputValue = ApplyInputValue(value);
}
public override void Update()
public class IntPropertyInputViewModelValidator : AbstractValidator<IntPropertyInputViewModel>
{
NotifyOfPropertyChange(() => IntInputValue);
}
private int ApplyInputValue(int value)
public IntPropertyInputViewModelValidator()
{
if (LayerPropertyViewModel.LayerProperty.MaxInputValue != null &&
LayerPropertyViewModel.LayerProperty.MaxInputValue is int maxInt)
value = Math.Min(value, maxInt);
if (LayerPropertyViewModel.LayerProperty.MinInputValue != null &&
LayerPropertyViewModel.LayerProperty.MinInputValue is int minInt)
value = Math.Max(value, minInt);
RuleFor(vm => vm.InputValue)
.LessThanOrEqualTo(vm => (int) vm.LayerPropertyViewModel.PropertyDescription.MaxInputValue)
.When(vm => vm.LayerPropertyViewModel.PropertyDescription.MaxInputValue is int);
return value;
RuleFor(vm => vm.InputValue)
.GreaterThanOrEqualTo(vm => (int) vm.LayerPropertyViewModel.PropertyDescription.MinInputValue)
.When(vm => vm.LayerPropertyViewModel.PropertyDescription.MinInputValue is int);
}
}
}

View File

@ -1,51 +0,0 @@
using System;
using Stylet;
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput
{
public abstract class PropertyInputViewModel<T> : PropertyChangedBase, IDisposable
{
protected PropertyInputViewModel(LayerPropertyViewModel<T> layerPropertyViewModel)
{
LayerPropertyViewModel = layerPropertyViewModel;
LayerPropertyViewModel.LayerProperty.Updated += LayerPropertyOnUpdated;
}
public LayerPropertyViewModel<T> LayerPropertyViewModel { get; }
public bool InputDragging { get; private set; }
protected T InputValue
{
get => LayerPropertyViewModel.LayerProperty.CurrentValue;
set => LayerPropertyViewModel.SetCurrentValue(value, !InputDragging);
}
public abstract void Update();
private void LayerPropertyOnUpdated(object? sender, EventArgs e)
{
Update();
}
#region Event handlers
public void InputDragStarted(object sender, EventArgs e)
{
InputDragging = true;
}
public void InputDragEnded(object sender, EventArgs e)
{
InputDragging = false;
LayerPropertyViewModel.ProfileEditorService.UpdateSelectedProfileElement();
}
#endregion
public void Dispose()
{
LayerPropertyViewModel.LayerProperty.Updated -= LayerPropertyOnUpdated;
}
}
}

View File

@ -1,24 +1,25 @@
<UserControl x:Class="Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput.SKColorPropertyInputView"
<UserControl x:Class="Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput.SKColorPropertyInputView"
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.PropertyTree.PropertyInput"
xmlns:local="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput"
xmlns:artemis="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
xmlns:converters="clr-namespace:Artemis.UI.Shared.Converters;assembly=Artemis.UI.Shared"
xmlns:controls="clr-namespace:Artemis.UI.Shared.Controls;assembly=Artemis.UI.Shared"
xmlns:propertyInput="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput"
mc:Ignorable="d"
d:DesignHeight="25" d:DesignWidth="800"
d:DataContext="{d:DesignInstance local:SKColorPropertyInputViewModel}">
d:DataContext="{d:DesignInstance propertyInput:SKColorPropertyInputViewModel}">
<UserControl.Resources>
<converters:SKColorToColorConverter x:Key="SKColorToColorConverter" />
</UserControl.Resources>
<StackPanel Orientation="Horizontal">
<TextBlock Margin="0 0 5 4" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.LayerProperty.InputPrefix}" />
<TextBlock Margin="0 0 5 4" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.PropertyDescription.InputPrefix}" />
<controls:ColorPicker Width="132"
Margin="0 -2 0 3"
Padding="0 -1"
Color="{Binding SKColorInputValue, Converter={StaticResource SKColorToColorConverter}}" />
<TextBlock Margin="5 0 0 4" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.LayerProperty.InputAffix}" />
Color="{Binding InputValue, Converter={StaticResource SKColorToColorConverter}}" />
<TextBlock Margin="5 0 0 4" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.PropertyDescription.InputAffix}" />
</StackPanel>
</UserControl>

View File

@ -1,27 +1,12 @@
using System;
using System.Collections.Generic;
using Artemis.UI.Services.Interfaces;
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput.Abstract;
using SkiaSharp;
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput
{
public class SKColorPropertyInputViewModel : PropertyInputViewModel
public class SKColorPropertyInputViewModel : PropertyInputViewModel<SKColor>
{
public SKColorPropertyInputViewModel(IProfileEditorService profileEditorService) : base(profileEditorService)
public SKColorPropertyInputViewModel(LayerPropertyViewModel<SKColor> layerPropertyViewModel) : base(layerPropertyViewModel)
{
}
public sealed override List<Type> CompatibleTypes { get; } = new List<Type> {typeof(SKColor)};
public SKColor SKColorInputValue
{
get => (SKColor?) InputValue ?? new SKColor();
set => InputValue = value;
}
public override void Update()
{
NotifyOfPropertyChange(() => SKColorInputValue);
}
}
}

View File

@ -1,28 +1,29 @@
<UserControl x:Class="Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput.SKPointPropertyInputView"
<UserControl x:Class="Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput.SKPointPropertyInputView"
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.PropertyTree.PropertyInput"
xmlns:local="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput"
xmlns:s="https://github.com/canton7/Stylet"
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
xmlns:controls="clr-namespace:Artemis.UI.Shared.Controls;assembly=Artemis.UI.Shared"
xmlns:propertyInput="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput"
mc:Ignorable="d"
d:DesignHeight="25" d:DesignWidth="800"
d:DataContext="{d:DesignInstance local:SKPointPropertyInputViewModel}">
d:DataContext="{d:DesignInstance propertyInput:SKPointPropertyInputViewModel}">
<StackPanel Orientation="Horizontal" KeyboardNavigation.IsTabStop="True">
<TextBlock Margin="0 0 5 4" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.LayerProperty.InputPrefix}" />
<TextBlock Margin="0 0 5 4" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.PropertyDescription.InputPrefix}" />
<controls:DraggableFloat ToolTip="X-coordinate (horizontal)"
Value="{Binding X}"
StepSize="{Binding LayerPropertyViewModel.LayerProperty.InputStepSize}"
StepSize="{Binding LayerPropertyViewModel.PropertyDescription.InputStepSize}"
DragStarted="{s:Action InputDragStarted}"
DragEnded="{s:Action InputDragEnded}" />
<TextBlock Margin="5 0" VerticalAlignment="Bottom">,</TextBlock>
<controls:DraggableFloat ToolTip="Y-coordinate (vertical)"
Value="{Binding Y}"
StepSize="{Binding LayerPropertyViewModel.LayerProperty.InputStepSize}"
StepSize="{Binding LayerPropertyViewModel.PropertyDescription.InputStepSize}"
DragStarted="{s:Action InputDragStarted}"
DragEnded="{s:Action InputDragEnded}" />
<TextBlock Margin="5 0 0 4" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.LayerProperty.InputAffix}" />
<TextBlock Margin="5 0 0 4" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.PropertyDescription.InputAffix}" />
</StackPanel>
</UserControl>

View File

@ -1,50 +1,56 @@
using System;
using System.Collections.Generic;
using Artemis.UI.Services.Interfaces;
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput.Abstract;
using FluentValidation;
using PropertyChanged;
using SkiaSharp;
using Stylet;
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput
{
public class SKPointPropertyInputViewModel : PropertyInputViewModel
public class SKPointPropertyInputViewModel : PropertyInputViewModel<SKPoint>
{
public SKPointPropertyInputViewModel(IProfileEditorService profileEditorService) : base(profileEditorService)
public SKPointPropertyInputViewModel(LayerPropertyViewModel<SKPoint> layerPropertyViewModel, IModelValidator validator) : base(layerPropertyViewModel, validator)
{
}
public sealed override List<Type> CompatibleTypes { get; } = new List<Type> {typeof(SKPoint)};
// Since SKPoint is immutable we need to create properties that replace the SKPoint entirely
[DependsOn(nameof(InputValue))]
public float X
{
get => ((SKPoint?) InputValue)?.X ?? 0;
set => InputValue = new SKPoint(ApplyInputValue(value), Y);
get => InputValue.X;
set => InputValue = new SKPoint(value, Y);
}
[DependsOn(nameof(InputValue))]
public float Y
{
get => ((SKPoint?) InputValue)?.Y ?? 0;
set => InputValue = new SKPoint(X, ApplyInputValue(value));
get => InputValue.Y;
set => InputValue = new SKPoint(X, value);
}
public override void Update()
protected override void OnInputValueChanged()
{
NotifyOfPropertyChange(() => X);
NotifyOfPropertyChange(() => Y);
NotifyOfPropertyChange(nameof(X));
NotifyOfPropertyChange(nameof(Y));
}
}
private float ApplyInputValue(float value)
public class SKPointPropertyInputViewModelValidator : AbstractValidator<SKPointPropertyInputViewModel>
{
if (LayerPropertyViewModel.LayerProperty.MaxInputValue != null &&
LayerPropertyViewModel.LayerProperty.MaxInputValue is float maxFloat)
value = Math.Min(value, maxFloat);
if (LayerPropertyViewModel.LayerProperty.MinInputValue != null &&
LayerPropertyViewModel.LayerProperty.MinInputValue is float minFloat)
value = Math.Max(value, minFloat);
public SKPointPropertyInputViewModelValidator()
{
RuleFor(vm => vm.X)
.LessThanOrEqualTo(vm => ((SKPoint) vm.LayerPropertyViewModel.PropertyDescription.MaxInputValue).X)
.When(vm => vm.LayerPropertyViewModel.PropertyDescription.MaxInputValue is SKPoint);
RuleFor(vm => vm.X)
.GreaterThanOrEqualTo(vm => ((SKPoint) vm.LayerPropertyViewModel.PropertyDescription.MaxInputValue).X)
.When(vm => vm.LayerPropertyViewModel.PropertyDescription.MaxInputValue is SKPoint);
return value;
RuleFor(vm => vm.Y)
.LessThanOrEqualTo(vm => ((SKPoint) vm.LayerPropertyViewModel.PropertyDescription.MaxInputValue).Y)
.When(vm => vm.LayerPropertyViewModel.PropertyDescription.MaxInputValue is SKPoint);
RuleFor(vm => vm.Y)
.GreaterThanOrEqualTo(vm => ((SKPoint) vm.LayerPropertyViewModel.PropertyDescription.MaxInputValue).Y)
.When(vm => vm.LayerPropertyViewModel.PropertyDescription.MaxInputValue is SKPoint);
}
}
}

View File

@ -1,9 +1,9 @@
<UserControl x:Class="Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput.SKSizePropertyInputView"
<UserControl x:Class="Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput.SKSizePropertyInputView"
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.PropertyTree.PropertyInput"
xmlns:local="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput"
xmlns:s="https://github.com/canton7/Stylet"
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
xmlns:controls="clr-namespace:Artemis.UI.Shared.Controls;assembly=Artemis.UI.Shared"
@ -11,18 +11,18 @@
d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance local:SKSizePropertyInputViewModel}">
<StackPanel Orientation="Horizontal">
<TextBlock Margin="0 0 5 4" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.LayerProperty.InputPrefix}" />
<TextBlock Margin="0 0 5 4" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.PropertyDescription.InputPrefix}" />
<controls:DraggableFloat ToolTip="Height"
Value="{Binding Height}"
StepSize="{Binding LayerPropertyViewModel.LayerProperty.InputStepSize}"
StepSize="{Binding LayerPropertyViewModel.PropertyDescription.InputStepSize}"
DragStarted="{s:Action InputDragStarted}"
DragEnded="{s:Action InputDragEnded}" />
<TextBlock Margin="5 0" VerticalAlignment="Bottom">,</TextBlock>
<controls:DraggableFloat ToolTip="Width"
Value="{Binding Width}"
StepSize="{Binding LayerPropertyViewModel.LayerProperty.InputStepSize}"
StepSize="{Binding LayerPropertyViewModel.PropertyDescription.InputStepSize}"
DragStarted="{s:Action InputDragStarted}"
DragEnded="{s:Action InputDragEnded}" />
<TextBlock Margin="5 0 0 4" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.LayerProperty.InputAffix}" />
<TextBlock Margin="5 0 0 4" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.PropertyDescription.InputAffix}" />
</StackPanel>
</UserControl>

View File

@ -1,50 +1,56 @@
using System;
using System.Collections.Generic;
using Artemis.UI.Services.Interfaces;
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput.Abstract;
using FluentValidation;
using PropertyChanged;
using SkiaSharp;
using Stylet;
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput
{
public class SKSizePropertyInputViewModel : PropertyInputViewModel
public class SKSizePropertyInputViewModel : PropertyInputViewModel<SKSize>
{
public SKSizePropertyInputViewModel(IProfileEditorService profileEditorService) : base(profileEditorService)
public SKSizePropertyInputViewModel(LayerPropertyViewModel<SKSize> layerPropertyViewModel, IModelValidator validator) : base(layerPropertyViewModel, validator)
{
}
public sealed override List<Type> CompatibleTypes { get; } = new List<Type> {typeof(SKSize)};
// Since SKSize is immutable we need to create properties that replace the SKPoint entirely
// Since SKSize is immutable we need to create properties that replace the SKSize entirely
[DependsOn(nameof(InputValue))]
public float Width
{
get => ((SKSize?) InputValue)?.Width ?? 0;
set => InputValue = new SKSize(ApplyInputValue(value), Height);
get => InputValue.Width;
set => InputValue = new SKSize(value, Height);
}
[DependsOn(nameof(InputValue))]
public float Height
{
get => ((SKSize?) InputValue)?.Height ?? 0;
set => InputValue = new SKSize(Width, ApplyInputValue(value));
get => InputValue.Height;
set => InputValue = new SKSize(Width, value);
}
public override void Update()
protected override void OnInputValueChanged()
{
NotifyOfPropertyChange(() => Width);
NotifyOfPropertyChange(() => Height);
NotifyOfPropertyChange(nameof(Width));
NotifyOfPropertyChange(nameof(Height));
}
}
private float ApplyInputValue(float value)
public class SKSizePropertyInputViewModelValidator : AbstractValidator<SKSizePropertyInputViewModel>
{
if (LayerPropertyViewModel.LayerProperty.MaxInputValue != null &&
LayerPropertyViewModel.LayerProperty.MaxInputValue is float maxFloat)
value = Math.Min(value, maxFloat);
if (LayerPropertyViewModel.LayerProperty.MinInputValue != null &&
LayerPropertyViewModel.LayerProperty.MinInputValue is float minFloat)
value = Math.Max(value, minFloat);
public SKSizePropertyInputViewModelValidator()
{
RuleFor(vm => vm.Width)
.LessThanOrEqualTo(vm => ((SKSize)vm.LayerPropertyViewModel.PropertyDescription.MaxInputValue).Width)
.When(vm => vm.LayerPropertyViewModel.PropertyDescription.MaxInputValue is SKSize);
RuleFor(vm => vm.Width)
.GreaterThanOrEqualTo(vm => ((SKSize)vm.LayerPropertyViewModel.PropertyDescription.MaxInputValue).Width)
.When(vm => vm.LayerPropertyViewModel.PropertyDescription.MaxInputValue is SKSize);
return value;
RuleFor(vm => vm.Height)
.LessThanOrEqualTo(vm => ((SKSize)vm.LayerPropertyViewModel.PropertyDescription.MaxInputValue).Height)
.When(vm => vm.LayerPropertyViewModel.PropertyDescription.MaxInputValue is SKSize);
RuleFor(vm => vm.Height)
.GreaterThanOrEqualTo(vm => ((SKSize)vm.LayerPropertyViewModel.PropertyDescription.MaxInputValue).Height)
.When(vm => vm.LayerPropertyViewModel.PropertyDescription.MaxInputValue is SKSize);
}
}
}

View File

@ -1,20 +1,15 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Artemis.Core.Models.Profile;
using Artemis.UI.Exceptions;
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Abstract;
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput;
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput;
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput.Abstract;
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree
{
public class TreePropertyViewModel<T> : TreePropertyViewModel
{
public TreePropertyViewModel(LayerPropertyBaseViewModel layerPropertyBaseViewModel) : base(layerPropertyBaseViewModel)
public TreePropertyViewModel(LayerPropertyBaseViewModel layerPropertyBaseViewModel, PropertyInputViewModel<T> propertyInputViewModel) : base(layerPropertyBaseViewModel)
{
LayerPropertyViewModel = (LayerPropertyViewModel<T>) layerPropertyBaseViewModel;
PropertyInputViewModel = CreatePropertyInputViewModel();
PropertyInputViewModel = propertyInputViewModel;
}
public LayerPropertyViewModel<T> LayerPropertyViewModel { get; }
@ -24,36 +19,10 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree
{
PropertyInputViewModel.Dispose();
}
private PropertyInputViewModel<T> CreatePropertyInputViewModel()
{
if (!IsPropertySupported(typeof(T)))
throw new ArtemisUIException($"Failed to create a property input view model, type {typeof(T).Name} is not supported.");
return (PropertyInputViewModel<T>) Activator.CreateInstance(SupportedTypes[typeof(T)], this);
}
}
public abstract class TreePropertyViewModel : IDisposable
{
public static ReadOnlyDictionary<Type, Type> SupportedTypes = new ReadOnlyDictionary<Type, Type>(new Dictionary<Type, Type>
{
{typeof(LayerBrushReference), typeof(BrushPropertyInputViewModel)},
{typeof(LayerBrushReference), typeof(BrushPropertyInputViewModel)},
{typeof(LayerBrushReference), typeof(BrushPropertyInputViewModel)},
{typeof(LayerBrushReference), typeof(BrushPropertyInputViewModel)}
});
public static void RegisterPropertyInputViewModel()
{
}
public static bool IsPropertySupported(Type type)
{
return SupportedTypes.ContainsKey(type);
}
protected TreePropertyViewModel(LayerPropertyBaseViewModel layerPropertyBaseViewModel)
{
LayerPropertyBaseViewModel = layerPropertyBaseViewModel;
@ -61,5 +30,9 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree
public LayerPropertyBaseViewModel LayerPropertyBaseViewModel { get; }
public abstract void Dispose();
public static void RegisterPropertyInputViewModel()
{
}
}
}

View File

@ -5,6 +5,7 @@ using Artemis.Core.Models.Profile.LayerProperties.Attributes;
using Artemis.Core.Plugins.Abstract;
using Artemis.UI.Events;
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Abstract;
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree;
namespace Artemis.UI.Services.Interfaces
{
@ -54,5 +55,7 @@ namespace Artemis.UI.Services.Interfaces
/// Occurs when the profile preview has been updated
/// </summary>
event EventHandler ProfilePreviewUpdated;
TreePropertyViewModel<T> CreateTreePropertyViewModel<T>();
}
}