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;
using Artemis.Core.Models.Profile.LayerProperties;
using Artemis.Core.Models.Surface; using Artemis.Core.Models.Surface;
using Artemis.Core.Plugins.Abstract; using Artemis.Core.Plugins.Abstract;
using Artemis.UI.Screens.Module; using Artemis.UI.Screens.Module;
using Artemis.UI.Screens.Module.ProfileEditor; 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.ProfileTree.TreeItem;
using Artemis.UI.Screens.Module.ProfileEditor.Visualization; using Artemis.UI.Screens.Module.ProfileEditor.Visualization;
using Artemis.UI.Screens.Settings.Tabs.Devices; using Artemis.UI.Screens.Settings.Tabs.Devices;

View File

@ -2,7 +2,6 @@
using Artemis.UI.Ninject.Factories; using Artemis.UI.Ninject.Factories;
using Artemis.UI.Screens; using Artemis.UI.Screens;
using Artemis.UI.Screens.Module.ProfileEditor; using Artemis.UI.Screens.Module.ProfileEditor;
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput;
using Artemis.UI.Services.Interfaces; using Artemis.UI.Services.Interfaces;
using Artemis.UI.Shared.Services.Dialog; using Artemis.UI.Shared.Services.Dialog;
using Artemis.UI.Stylet; using Artemis.UI.Stylet;
@ -57,16 +56,7 @@ namespace Artemis.UI.Ninject
.InheritedFrom<ProfileEditorPanelViewModel>() .InheritedFrom<ProfileEditorPanelViewModel>()
.BindAllBaseClasses(); .BindAllBaseClasses();
}); });
// Bind property input VMs
Kernel.Bind(x =>
{
x.FromThisAssembly()
.SelectAllClasses()
.InheritedFrom<PropertyInputViewModel>()
.BindAllBaseClasses();
});
// Bind all UI services as singletons // Bind all UI services as singletons
Kernel.Bind(x => 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="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:propertyInput="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput"
mc:Ignorable="d" 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"> <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" <ComboBox Width="132"
Margin="0 2" Margin="0 2"
Padding="0 -1" Padding="0 -1"
Height="15" Height="15"
materialDesign:ValidationAssist.UsePopup="True" materialDesign:ValidationAssist.UsePopup="True"
HorizontalAlignment="Left" HorizontalAlignment="Left"
ItemsSource="{Binding Path=EnumValues}" ItemsSource="{Binding Path=ComboboxValues}"
SelectedValuePath="Value" SelectedValuePath="Value"
DisplayMemberPath="Description" DisplayMemberPath="Description"
SelectedValue="{Binding Path=BrushInputValue}" /> SelectedValue="{Binding Path=InputValue}" />
<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> </StackPanel>
</UserControl> </UserControl>

View File

@ -1,16 +1,14 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using Artemis.Core.Events; using Artemis.Core.Events;
using Artemis.Core.Models.Profile; using Artemis.Core.Models.Profile;
using Artemis.Core.Plugins.LayerBrush; using Artemis.Core.Plugins.LayerBrush;
using Artemis.Core.Services.Interfaces; using Artemis.Core.Services.Interfaces;
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 Artemis.UI.Shared.Utilities; using Artemis.UI.Shared.Utilities;
using Stylet; 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> public class BrushPropertyInputViewModel : PropertyInputViewModel<LayerBrushReference>
{ {
@ -22,59 +20,40 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.P
{ {
_layerService = layerService; _layerService = layerService;
_pluginService = pluginService; _pluginService = pluginService;
EnumValues = new BindableCollection<ValueDescription>(); ComboboxValues = new BindableCollection<ValueDescription>();
_pluginService.PluginLoaded += PluginServiceOnPluginLoaded; _pluginService.PluginLoaded += PluginServiceOnPluginLoaded;
UpdateEnumValues();
} }
public BindableCollection<ValueDescription> EnumValues { get; } public BindableCollection<ValueDescription> ComboboxValues { get; }
public LayerBrushReference BrushInputValue
{
get => (LayerBrushReference) InputValue;
set
{
InputValue = value;
_layerService.InstantiateLayerBrush(LayerPropertyViewModel.LayerProperty.Layer);
}
}
public void UpdateEnumValues() public void UpdateEnumValues()
{ {
var layerBrushProviders = _pluginService.GetPluginsOfType<LayerBrushProvider>(); var layerBrushProviders = _pluginService.GetPluginsOfType<LayerBrushProvider>();
var descriptors = layerBrushProviders.SelectMany(l => l.LayerBrushDescriptors).ToList(); var descriptors = layerBrushProviders.SelectMany(l => l.LayerBrushDescriptors).ToList();
var enumValues = new List<ValueDescription>(); var enumValues = new List<ValueDescription>();
foreach (var layerBrushDescriptor in descriptors) foreach (var layerBrushDescriptor in descriptors)
{ {
var brushName = layerBrushDescriptor.LayerBrushType.Name; var brushName = layerBrushDescriptor.LayerBrushType.Name;
var brushGuid = layerBrushDescriptor.LayerBrushProvider.PluginInfo.Guid; var brushGuid = layerBrushDescriptor.LayerBrushProvider.PluginInfo.Guid;
if (BrushInputValue != null && BrushInputValue.BrushType == brushName && BrushInputValue.BrushPluginGuid == brushGuid) if (InputValue != null && InputValue.BrushType == brushName && InputValue.BrushPluginGuid == brushGuid)
enumValues.Add(new ValueDescription {Description = layerBrushDescriptor.DisplayName, Value = BrushInputValue}); enumValues.Add(new ValueDescription {Description = layerBrushDescriptor.DisplayName, Value = InputValue});
else else
enumValues.Add(new ValueDescription {Description = layerBrushDescriptor.DisplayName, Value = new LayerBrushReference {BrushType = brushName, BrushPluginGuid = brushGuid}}); enumValues.Add(new ValueDescription {Description = layerBrushDescriptor.DisplayName, Value = new LayerBrushReference {BrushType = brushName, BrushPluginGuid = brushGuid}});
} }
EnumValues.Clear();
EnumValues.AddRange(enumValues);
}
public override void Update() ComboboxValues.Clear();
{ ComboboxValues.AddRange(enumValues);
NotifyOfPropertyChange(() => BrushInputValue);
} }
public override void Dispose() public override void Dispose()
{ {
_pluginService.PluginLoaded -= PluginServiceOnPluginLoaded; _pluginService.PluginLoaded -= PluginServiceOnPluginLoaded;
base.Dispose(); base.Dispose();
} }
protected override void OnInitialized()
{
UpdateEnumValues();
base.OnInitialized();
}
private void PluginServiceOnPluginLoaded(object sender, PluginEventArgs e) private void PluginServiceOnPluginLoaded(object sender, PluginEventArgs e)
{ {
UpdateEnumValues(); 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="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 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: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" mc:Ignorable="d"
d:DesignHeight="25" d:DesignWidth="800" d:DesignHeight="25" d:DesignWidth="800"
d:DataContext="{d:DesignInstance local:ColorGradientPropertyInputViewModel}"> d:DataContext="{d:DesignInstance propertyInput:ColorGradientPropertyInputViewModel}">
<StackPanel Orientation="Horizontal"> <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" <controls:GradientPicker Width="132"
Margin="0 2" Margin="0 2"
Padding="0 -1" Padding="0 -1"
ColorGradient="{Binding ColorGradientInputValue}" ColorGradient="{Binding InputValue}"
DialogHost="PropertyTreeDialogHost"/> 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> </StackPanel>
</UserControl> </UserControl>

View File

@ -1,28 +1,12 @@
using System; using Artemis.Core.Models.Profile.Colors;
using System.Collections.Generic; using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput.Abstract;
using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Profile.Colors;
using Artemis.UI.Services.Interfaces;
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="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 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" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" d:DesignHeight="450" d:DesignWidth="800">
d:DataContext="{d:DesignInstance local:EnumPropertyInputViewModel}">
<StackPanel Orientation="Horizontal"> <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" <ComboBox Width="132"
Margin="0 2" Margin="0 2"
Padding="0 -1" Padding="0 -1"
@ -19,7 +17,7 @@
ItemsSource="{Binding Path=EnumValues}" ItemsSource="{Binding Path=EnumValues}"
SelectedValuePath="Value" SelectedValuePath="Value"
DisplayMemberPath="Description" DisplayMemberPath="Description"
SelectedValue="{Binding Path=EnumInputValue}" /> SelectedValue="{Binding Path=InputValue}" />
<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> </StackPanel>
</UserControl> </UserControl>

View File

@ -1,41 +1,17 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput.Abstract;
using Artemis.UI.Services.Interfaces;
using Artemis.UI.Shared.Utilities; 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 IEnumerable<ValueDescription> EnumValues { get; }
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();
}
} }
} }

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="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 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:s="https://github.com/canton7/Stylet"
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared" xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
xmlns:controls="clr-namespace:Artemis.UI.Shared.Controls;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" mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance local:FloatPropertyInputViewModel}"> d:DataContext="{d:DesignInstance propertyInput:FloatPropertyInputViewModel}">
<StackPanel Orientation="Horizontal"> <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 Value="{Binding FloatInputValue}" <controls:DraggableFloat Value="{Binding InputValue}"
StepSize="{Binding LayerPropertyViewModel.LayerProperty.InputStepSize}" StepSize="{Binding LayerPropertyViewModel.PropertyDescription.InputStepSize}"
DragStarted="{s:Action InputDragStarted}" DragStarted="{s:Action InputDragStarted}"
DragEnded="{s:Action InputDragEnded}" /> 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> </StackPanel>
</UserControl> </UserControl>

View File

@ -1,39 +1,28 @@
using System; using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput.Abstract;
using System.Collections.Generic; using FluentValidation;
using Artemis.UI.Services.Interfaces; 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 class FloatPropertyInputViewModelValidator : AbstractValidator<FloatPropertyInputViewModel>
{
public FloatPropertyInputViewModelValidator()
public float FloatInputValue
{ {
get => (float?) InputValue ?? 0f; RuleFor(vm => vm.InputValue)
set => InputValue = ApplyInputValue(value); .LessThanOrEqualTo(vm => (float) vm.LayerPropertyViewModel.PropertyDescription.MaxInputValue)
} .When(vm => vm.LayerPropertyViewModel.PropertyDescription.MaxInputValue is float);
public override void Update() RuleFor(vm => vm.InputValue)
{ .GreaterThanOrEqualTo(vm => (float) vm.LayerPropertyViewModel.PropertyDescription.MinInputValue)
NotifyOfPropertyChange(() => FloatInputValue); .When(vm => vm.LayerPropertyViewModel.PropertyDescription.MinInputValue is float);
}
private float ApplyInputValue(float value)
{
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);
return value;
} }
} }
} }

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="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 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:s="https://github.com/canton7/Stylet"
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared" xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
xmlns:controls="clr-namespace:Artemis.UI.Shared.Controls;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" mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance local:IntPropertyInputViewModel}"> d:DataContext="{d:DesignInstance propertyInput:IntPropertyInputViewModel}">
<StackPanel Orientation="Horizontal"> <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 Value="{Binding IntInputValue}" <controls:DraggableFloat Value="{Binding InputValue}"
StepSize="{Binding LayerPropertyViewModel.LayerProperty.InputStepSize}" StepSize="{Binding LayerPropertyViewModel.PropertyDescription.InputStepSize}"
DragStarted="{s:Action InputDragStarted}" DragStarted="{s:Action InputDragStarted}"
DragEnded="{s:Action InputDragEnded}" /> 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> </StackPanel>
</UserControl> </UserControl>

View File

@ -1,38 +1,28 @@
using System; using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput.Abstract;
using System.Collections.Generic; using FluentValidation;
using Artemis.UI.Services.Interfaces; 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 class IntPropertyInputViewModelValidator : AbstractValidator<IntPropertyInputViewModel>
{
public int IntInputValue public IntPropertyInputViewModelValidator()
{ {
get => (int?) InputValue ?? 0; RuleFor(vm => vm.InputValue)
set => InputValue = ApplyInputValue(value); .LessThanOrEqualTo(vm => (int) vm.LayerPropertyViewModel.PropertyDescription.MaxInputValue)
} .When(vm => vm.LayerPropertyViewModel.PropertyDescription.MaxInputValue is int);
public override void Update() RuleFor(vm => vm.InputValue)
{ .GreaterThanOrEqualTo(vm => (int) vm.LayerPropertyViewModel.PropertyDescription.MinInputValue)
NotifyOfPropertyChange(() => IntInputValue); .When(vm => vm.LayerPropertyViewModel.PropertyDescription.MinInputValue is int);
}
private int ApplyInputValue(int value)
{
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);
return value;
} }
} }
} }

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="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 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:artemis="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
xmlns:converters="clr-namespace:Artemis.UI.Shared.Converters;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: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" mc:Ignorable="d"
d:DesignHeight="25" d:DesignWidth="800" d:DesignHeight="25" d:DesignWidth="800"
d:DataContext="{d:DesignInstance local:SKColorPropertyInputViewModel}"> d:DataContext="{d:DesignInstance propertyInput:SKColorPropertyInputViewModel}">
<UserControl.Resources> <UserControl.Resources>
<converters:SKColorToColorConverter x:Key="SKColorToColorConverter" /> <converters:SKColorToColorConverter x:Key="SKColorToColorConverter" />
</UserControl.Resources> </UserControl.Resources>
<StackPanel Orientation="Horizontal"> <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" <controls:ColorPicker Width="132"
Margin="0 -2 0 3" Margin="0 -2 0 3"
Padding="0 -1" Padding="0 -1"
Color="{Binding SKColorInputValue, Converter={StaticResource SKColorToColorConverter}}" /> Color="{Binding InputValue, Converter={StaticResource SKColorToColorConverter}}" />
<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> </StackPanel>
</UserControl> </UserControl>

View File

@ -1,27 +1,12 @@
using System; using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput.Abstract;
using System.Collections.Generic;
using Artemis.UI.Services.Interfaces;
using SkiaSharp; 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="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 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:s="https://github.com/canton7/Stylet"
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared" xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
xmlns:controls="clr-namespace:Artemis.UI.Shared.Controls;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" mc:Ignorable="d"
d:DesignHeight="25" d:DesignWidth="800" d:DesignHeight="25" d:DesignWidth="800"
d:DataContext="{d:DesignInstance local:SKPointPropertyInputViewModel}"> d:DataContext="{d:DesignInstance propertyInput:SKPointPropertyInputViewModel}">
<StackPanel Orientation="Horizontal" KeyboardNavigation.IsTabStop="True"> <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)" <controls:DraggableFloat ToolTip="X-coordinate (horizontal)"
Value="{Binding X}" Value="{Binding X}"
StepSize="{Binding LayerPropertyViewModel.LayerProperty.InputStepSize}" StepSize="{Binding LayerPropertyViewModel.PropertyDescription.InputStepSize}"
DragStarted="{s:Action InputDragStarted}" DragStarted="{s:Action InputDragStarted}"
DragEnded="{s:Action InputDragEnded}" /> DragEnded="{s:Action InputDragEnded}" />
<TextBlock Margin="5 0" VerticalAlignment="Bottom">,</TextBlock> <TextBlock Margin="5 0" VerticalAlignment="Bottom">,</TextBlock>
<controls:DraggableFloat ToolTip="Y-coordinate (vertical)" <controls:DraggableFloat ToolTip="Y-coordinate (vertical)"
Value="{Binding Y}" Value="{Binding Y}"
StepSize="{Binding LayerPropertyViewModel.LayerProperty.InputStepSize}" StepSize="{Binding LayerPropertyViewModel.PropertyDescription.InputStepSize}"
DragStarted="{s:Action InputDragStarted}" DragStarted="{s:Action InputDragStarted}"
DragEnded="{s:Action InputDragEnded}" /> 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> </StackPanel>
</UserControl> </UserControl>

View File

@ -1,50 +1,56 @@
using System; using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput.Abstract;
using System.Collections.Generic; using FluentValidation;
using Artemis.UI.Services.Interfaces;
using PropertyChanged; using PropertyChanged;
using SkiaSharp; 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 // Since SKPoint is immutable we need to create properties that replace the SKPoint entirely
[DependsOn(nameof(InputValue))] [DependsOn(nameof(InputValue))]
public float X public float X
{ {
get => ((SKPoint?) InputValue)?.X ?? 0; get => InputValue.X;
set => InputValue = new SKPoint(ApplyInputValue(value), Y); set => InputValue = new SKPoint(value, Y);
} }
[DependsOn(nameof(InputValue))] [DependsOn(nameof(InputValue))]
public float Y public float Y
{ {
get => ((SKPoint?) InputValue)?.Y ?? 0; get => InputValue.Y;
set => InputValue = new SKPoint(X, ApplyInputValue(value)); set => InputValue = new SKPoint(X, value);
} }
public override void Update() protected override void OnInputValueChanged()
{ {
NotifyOfPropertyChange(() => X); NotifyOfPropertyChange(nameof(X));
NotifyOfPropertyChange(() => Y); NotifyOfPropertyChange(nameof(Y));
} }
}
private float ApplyInputValue(float value) public class SKPointPropertyInputViewModelValidator : AbstractValidator<SKPointPropertyInputViewModel>
{
public SKPointPropertyInputViewModelValidator()
{ {
if (LayerPropertyViewModel.LayerProperty.MaxInputValue != null && RuleFor(vm => vm.X)
LayerPropertyViewModel.LayerProperty.MaxInputValue is float maxFloat) .LessThanOrEqualTo(vm => ((SKPoint) vm.LayerPropertyViewModel.PropertyDescription.MaxInputValue).X)
value = Math.Min(value, maxFloat); .When(vm => vm.LayerPropertyViewModel.PropertyDescription.MaxInputValue is SKPoint);
if (LayerPropertyViewModel.LayerProperty.MinInputValue != null && RuleFor(vm => vm.X)
LayerPropertyViewModel.LayerProperty.MinInputValue is float minFloat) .GreaterThanOrEqualTo(vm => ((SKPoint) vm.LayerPropertyViewModel.PropertyDescription.MaxInputValue).X)
value = Math.Max(value, minFloat); .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="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 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:s="https://github.com/canton7/Stylet"
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared" xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
xmlns:controls="clr-namespace:Artemis.UI.Shared.Controls;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:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance local:SKSizePropertyInputViewModel}"> d:DataContext="{d:DesignInstance local:SKSizePropertyInputViewModel}">
<StackPanel Orientation="Horizontal"> <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" <controls:DraggableFloat ToolTip="Height"
Value="{Binding Height}" Value="{Binding Height}"
StepSize="{Binding LayerPropertyViewModel.LayerProperty.InputStepSize}" StepSize="{Binding LayerPropertyViewModel.PropertyDescription.InputStepSize}"
DragStarted="{s:Action InputDragStarted}" DragStarted="{s:Action InputDragStarted}"
DragEnded="{s:Action InputDragEnded}" /> DragEnded="{s:Action InputDragEnded}" />
<TextBlock Margin="5 0" VerticalAlignment="Bottom">,</TextBlock> <TextBlock Margin="5 0" VerticalAlignment="Bottom">,</TextBlock>
<controls:DraggableFloat ToolTip="Width" <controls:DraggableFloat ToolTip="Width"
Value="{Binding Width}" Value="{Binding Width}"
StepSize="{Binding LayerPropertyViewModel.LayerProperty.InputStepSize}" StepSize="{Binding LayerPropertyViewModel.PropertyDescription.InputStepSize}"
DragStarted="{s:Action InputDragStarted}" DragStarted="{s:Action InputDragStarted}"
DragEnded="{s:Action InputDragEnded}" /> 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> </StackPanel>
</UserControl> </UserControl>

View File

@ -1,50 +1,56 @@
using System; using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput.Abstract;
using System.Collections.Generic; using FluentValidation;
using Artemis.UI.Services.Interfaces;
using PropertyChanged; using PropertyChanged;
using SkiaSharp; 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 SKSize entirely
// Since SKSize is immutable we need to create properties that replace the SKPoint entirely
[DependsOn(nameof(InputValue))] [DependsOn(nameof(InputValue))]
public float Width public float Width
{ {
get => ((SKSize?) InputValue)?.Width ?? 0; get => InputValue.Width;
set => InputValue = new SKSize(ApplyInputValue(value), Height); set => InputValue = new SKSize(value, Height);
} }
[DependsOn(nameof(InputValue))] [DependsOn(nameof(InputValue))]
public float Height public float Height
{ {
get => ((SKSize?) InputValue)?.Height ?? 0; get => InputValue.Height;
set => InputValue = new SKSize(Width, ApplyInputValue(value)); set => InputValue = new SKSize(Width, value);
} }
public override void Update() protected override void OnInputValueChanged()
{ {
NotifyOfPropertyChange(() => Width); NotifyOfPropertyChange(nameof(Width));
NotifyOfPropertyChange(() => Height); NotifyOfPropertyChange(nameof(Height));
} }
}
private float ApplyInputValue(float value) public class SKSizePropertyInputViewModelValidator : AbstractValidator<SKSizePropertyInputViewModel>
{
public SKSizePropertyInputViewModelValidator()
{ {
if (LayerPropertyViewModel.LayerProperty.MaxInputValue != null && RuleFor(vm => vm.Width)
LayerPropertyViewModel.LayerProperty.MaxInputValue is float maxFloat) .LessThanOrEqualTo(vm => ((SKSize)vm.LayerPropertyViewModel.PropertyDescription.MaxInputValue).Width)
value = Math.Min(value, maxFloat); .When(vm => vm.LayerPropertyViewModel.PropertyDescription.MaxInputValue is SKSize);
if (LayerPropertyViewModel.LayerProperty.MinInputValue != null && RuleFor(vm => vm.Width)
LayerPropertyViewModel.LayerProperty.MinInputValue is float minFloat) .GreaterThanOrEqualTo(vm => ((SKSize)vm.LayerPropertyViewModel.PropertyDescription.MaxInputValue).Width)
value = Math.Max(value, minFloat); .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;
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.Abstract;
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput; using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput.Abstract;
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree.PropertyInput;
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree
{ {
public class TreePropertyViewModel<T> : TreePropertyViewModel public class TreePropertyViewModel<T> : TreePropertyViewModel
{ {
public TreePropertyViewModel(LayerPropertyBaseViewModel layerPropertyBaseViewModel) : base(layerPropertyBaseViewModel) public TreePropertyViewModel(LayerPropertyBaseViewModel layerPropertyBaseViewModel, PropertyInputViewModel<T> propertyInputViewModel) : base(layerPropertyBaseViewModel)
{ {
LayerPropertyViewModel = (LayerPropertyViewModel<T>) layerPropertyBaseViewModel; LayerPropertyViewModel = (LayerPropertyViewModel<T>) layerPropertyBaseViewModel;
PropertyInputViewModel = CreatePropertyInputViewModel(); PropertyInputViewModel = propertyInputViewModel;
} }
public LayerPropertyViewModel<T> LayerPropertyViewModel { get; } public LayerPropertyViewModel<T> LayerPropertyViewModel { get; }
@ -24,36 +19,10 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree
{ {
PropertyInputViewModel.Dispose(); 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 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) protected TreePropertyViewModel(LayerPropertyBaseViewModel layerPropertyBaseViewModel)
{ {
LayerPropertyBaseViewModel = layerPropertyBaseViewModel; LayerPropertyBaseViewModel = layerPropertyBaseViewModel;
@ -61,5 +30,9 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree
public LayerPropertyBaseViewModel LayerPropertyBaseViewModel { get; } public LayerPropertyBaseViewModel LayerPropertyBaseViewModel { get; }
public abstract void Dispose(); 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.Core.Plugins.Abstract;
using Artemis.UI.Events; using Artemis.UI.Events;
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Abstract; using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Abstract;
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree;
namespace Artemis.UI.Services.Interfaces namespace Artemis.UI.Services.Interfaces
{ {
@ -54,5 +55,7 @@ namespace Artemis.UI.Services.Interfaces
/// Occurs when the profile preview has been updated /// Occurs when the profile preview has been updated
/// </summary> /// </summary>
event EventHandler ProfilePreviewUpdated; event EventHandler ProfilePreviewUpdated;
TreePropertyViewModel<T> CreateTreePropertyViewModel<T>();
} }
} }