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

Data model visualization - Moved services and VMs to UI.Shared

Data model visualization - Added support for custom display VMs
Data model visualization - Added framework for custom input VMs
Shared UI - Made internal converters public
This commit is contained in:
Robert 2020-07-02 20:25:20 +02:00
parent 2e87b79407
commit 6ee06b2fc5
30 changed files with 537 additions and 129 deletions

View File

@ -22,12 +22,12 @@ namespace Artemis.Core.Plugins.Abstract
}
/// <summary>
/// A read-only collection of all layer brushes added with <see cref="AddLayerBrushDescriptor{T}" />
/// A read-only collection of all layer brushes added with <see cref="RegisterLayerBrushDescriptor{T}" />
/// </summary>
public ReadOnlyCollection<LayerBrushDescriptor> LayerBrushDescriptors => _layerBrushDescriptors.AsReadOnly();
/// <summary>
/// Adds a layer brush descriptor for a given layer brush, so that it appears in the UI.
/// Registers a layer brush descriptor for a given layer brush, so that it appears in the UI.
/// <para>Note: You do not need to manually remove these on disable</para>
/// </summary>
/// <typeparam name="T">The type of the layer brush you wish to register</typeparam>
@ -37,7 +37,7 @@ namespace Artemis.Core.Plugins.Abstract
/// The Material icon to display in the UI, a full reference can be found
/// <see href="https://materialdesignicons.com">here</see>
/// </param>
protected void AddLayerBrushDescriptor<T>(string displayName, string description, string icon) where T : BaseLayerBrush
protected void RegisterLayerBrushDescriptor<T>(string displayName, string description, string icon) where T : BaseLayerBrush
{
if (!Enabled)
throw new ArtemisPluginException(PluginInfo, "Can only add a layer brush descriptor when the plugin is enabled");

View File

@ -65,8 +65,6 @@
</ResourceDictionary>
</UserControl.Resources>
<Grid HorizontalAlignment="Stretch">
<!-- Style="{StaticResource MaterialDesignFloatingHintTextBox}" -->
<!-- Padding="0 0 10 0" -->
<TextBox x:Name="ColorCodeTextBox"
materialDesign:TextFieldAssist.TextBoxViewMargin="1 0 1 0"
Text="{Binding Color, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Converter={StaticResource ColorToStringConverter}}"

View File

@ -11,7 +11,7 @@ namespace Artemis.UI.Shared.Converters
/// opacity.
/// </summary>
[ValueConversion(typeof(Color), typeof(string))]
internal class ColorToSolidColorConverter : IValueConverter
public class ColorToSolidColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{

View File

@ -10,7 +10,7 @@ namespace Artemis.UI.Shared.Converters
/// Converts <see cref="T:System.Windows.Media.Color" /> into <see cref="T:System.String" />.
/// </summary>
[ValueConversion(typeof(Color), typeof(string))]
internal class ColorToStringConverter : IValueConverter
public class ColorToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{

View File

@ -0,0 +1,29 @@
using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;
using SkiaSharp;
namespace Artemis.UI.Shared.Converters
{
/// <inheritdoc />
/// <summary>
/// Converts <see cref="SKColor"/>into <see cref="T:System.String" />.
/// </summary>
[ValueConversion(typeof(Color), typeof(string))]
public class SKColorToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value?.ToString();
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (string.IsNullOrWhiteSpace((string) value))
return SKColor.Empty;
return SKColor.TryParse((string)value, out var color) ? color : SKColor.Empty;
}
}
}

View File

@ -0,0 +1,39 @@
using Stylet;
namespace Artemis.UI.Shared.DataModelVisualization
{
public abstract class DataModelDisplayViewModel<T> : DataModelDisplayViewModel
{
private T _displayValue;
public T DisplayValue
{
get => _displayValue;
set
{
if (!SetAndNotify(ref _displayValue, value)) return;
OnDisplayValueUpdated();
}
}
protected virtual void OnDisplayValueUpdated()
{
}
internal override void UpdateValue(object model)
{
DisplayValue = model is T value ? value : default;
}
}
/// <summary>
/// For internal use only, implement <see cref="DataModelDisplayViewModel{T}" /> instead.
/// </summary>
public abstract class DataModelDisplayViewModel : PropertyChangedBase
{
/// <summary>
/// Prevents this type being implemented directly, implement <see cref="DataModelDisplayViewModel{T}" /> instead.
/// </summary>
internal abstract void UpdateValue(object model);
}
}

View File

@ -0,0 +1,28 @@
using Artemis.Core.Plugins.Abstract.DataModels.Attributes;
using Stylet;
namespace Artemis.UI.Shared.DataModelVisualization
{
public abstract class DataModelInputViewModel<T> : DataModelInputViewModel
{
protected DataModelInputViewModel(DataModelPropertyAttribute description)
{
Description = description;
}
public DataModelPropertyAttribute Description { get; }
internal override object InternalGuard { get; } = null;
}
/// <summary>
/// For internal use only, implement <see cref="DataModelInputViewModel{T}" /> instead.
/// </summary>
public abstract class DataModelInputViewModel : PropertyChangedBase
{
/// <summary>
/// Prevents this type being implemented directly, implement <see cref="DataModelInputViewModel{T}" /> instead.
/// </summary>
// ReSharper disable once UnusedMember.Global
internal abstract object InternalGuard { get; }
}
}

View File

@ -0,0 +1,53 @@
using System;
using Artemis.Core;
using Artemis.Core.Plugins.Models;
using Artemis.UI.Shared.Services;
namespace Artemis.UI.Shared.DataModelVisualization
{
public class DataModelVisualizationRegistration
{
private readonly IDataModelVisualizationService _dataModelVisualizationService;
public DataModelVisualizationRegistration(IDataModelVisualizationService dataModelVisualizationService,
RegistrationType registrationType,
PluginInfo pluginInfo,
Type supportedType,
Type viewModelType)
{
_dataModelVisualizationService = dataModelVisualizationService;
RegistrationType = registrationType;
PluginInfo = pluginInfo;
SupportedType = supportedType;
ViewModelType = viewModelType;
if (PluginInfo != Constants.CorePluginInfo)
PluginInfo.Instance.PluginDisabled += InstanceOnPluginDisabled;
}
public RegistrationType RegistrationType { get; }
public PluginInfo PluginInfo { get; }
public Type SupportedType { get; }
public Type ViewModelType { get; }
internal void Unsubscribe()
{
if (PluginInfo != Constants.CorePluginInfo)
PluginInfo.Instance.PluginDisabled -= InstanceOnPluginDisabled;
}
private void InstanceOnPluginDisabled(object sender, EventArgs e)
{
if (RegistrationType == RegistrationType.Input)
_dataModelVisualizationService.RemoveDataModelInput(this);
else if (RegistrationType == RegistrationType.Display)
_dataModelVisualizationService.RemoveDataModelDisplay(this);
}
}
public enum RegistrationType
{
Display,
Input
}
}

View File

@ -3,18 +3,22 @@ using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Artemis.Core.Plugins.Abstract.DataModels.Attributes;
using Artemis.UI.Shared.Services;
using Stylet;
namespace Artemis.UI.DataModelVisualization
namespace Artemis.UI.Shared.DataModelVisualization.Shared
{
public class DataModelListViewModel : DataModelVisualizationViewModel
{
private readonly IDataModelVisualizationService _dataModelVisualizationService;
private BindableCollection<DataModelVisualizationViewModel> _children;
private IList _list;
private string _count;
private IList _list;
public DataModelListViewModel(PropertyInfo propertyInfo, DataModelPropertyAttribute propertyDescription, DataModelVisualizationViewModel parent)
internal DataModelListViewModel(PropertyInfo propertyInfo, DataModelPropertyAttribute propertyDescription, DataModelVisualizationViewModel parent,
IDataModelVisualizationService dataModelVisualizationService)
{
_dataModelVisualizationService = dataModelVisualizationService;
PropertyInfo = propertyInfo;
Parent = parent;
PropertyDescription = propertyDescription;
@ -53,7 +57,7 @@ namespace Artemis.UI.DataModelVisualization
DataModelVisualizationViewModel child;
if (Children.Count <= index)
{
child = CreateChild(item);
child = CreateChild(_dataModelVisualizationService, item);
Children.Add(child);
}
else

View File

@ -0,0 +1,59 @@
using System.Reflection;
using Artemis.Core.Plugins.Abstract.DataModels.Attributes;
namespace Artemis.UI.Shared.DataModelVisualization.Shared
{
public class DataModelPropertyViewModel : DataModelVisualizationViewModel
{
private DataModelDisplayViewModel _displayViewModel;
private bool _showNull;
private bool _showToString;
private bool _showViewModel;
internal DataModelPropertyViewModel(PropertyInfo propertyInfo, DataModelPropertyAttribute propertyDescription, DataModelVisualizationViewModel parent)
{
PropertyInfo = propertyInfo;
Parent = parent;
PropertyDescription = propertyDescription;
}
public DataModelDisplayViewModel DisplayViewModel
{
get => _displayViewModel;
set => SetAndNotify(ref _displayViewModel, value);
}
public bool ShowToString
{
get => _showToString;
set => SetAndNotify(ref _showToString, value);
}
public bool ShowNull
{
get => _showNull;
set => SetAndNotify(ref _showNull, value);
}
public bool ShowViewModel
{
get => _showViewModel;
set => SetAndNotify(ref _showViewModel, value);
}
public override void Update()
{
if (PropertyInfo != null && Parent?.Model != null)
{
Model = PropertyInfo.GetValue(Parent.Model);
DisplayViewModel?.UpdateValue(Model);
}
ShowToString = Model != null && DisplayViewModel == null;
ShowNull = Model == null;
ShowViewModel = Model != null && DisplayViewModel != null;
UpdateListStatus();
}
}
}

View File

@ -1,21 +1,25 @@
using System.Reflection;
using Artemis.Core.Extensions;
using Artemis.Core.Plugins.Abstract.DataModels.Attributes;
using Artemis.UI.Shared.Services;
using Stylet;
namespace Artemis.UI.DataModelVisualization
namespace Artemis.UI.Shared.DataModelVisualization.Shared
{
public class DataModelViewModel : DataModelVisualizationViewModel
{
private readonly IDataModelVisualizationService _dataModelVisualizationService;
private BindableCollection<DataModelVisualizationViewModel> _children;
public DataModelViewModel()
internal DataModelViewModel()
{
Children = new BindableCollection<DataModelVisualizationViewModel>();
}
public DataModelViewModel(PropertyInfo propertyInfo, object model, DataModelPropertyAttribute propertyDescription, DataModelVisualizationViewModel parent)
internal DataModelViewModel(PropertyInfo propertyInfo, object model, DataModelPropertyAttribute propertyDescription, DataModelVisualizationViewModel parent,
IDataModelVisualizationService dataModelVisualizationService)
{
_dataModelVisualizationService = dataModelVisualizationService;
PropertyInfo = propertyInfo;
Model = model;
PropertyDescription = propertyDescription;
@ -36,7 +40,7 @@ namespace Artemis.UI.DataModelVisualization
Children.Clear();
foreach (var propertyInfo in Model.GetType().GetProperties())
{
var child = CreateChild(propertyInfo);
var child = CreateChild(_dataModelVisualizationService, propertyInfo);
if (child != null)
Children.Add(child);
}

View File

@ -3,20 +3,25 @@ using System.Collections;
using System.Reflection;
using Artemis.Core.Extensions;
using Artemis.Core.Plugins.Abstract.DataModels.Attributes;
using Artemis.UI.Shared.Services;
using Humanizer;
using Stylet;
namespace Artemis.UI.DataModelVisualization
namespace Artemis.UI.Shared.DataModelVisualization.Shared
{
public abstract class DataModelVisualizationViewModel : PropertyChangedBase
{
private bool _isListProperty;
private string _listDescription;
private object _model;
private DataModelVisualizationViewModel _parent;
private DataModelPropertyAttribute _propertyDescription;
private PropertyInfo _propertyInfo;
private Type _propertyType;
private DataModelVisualizationViewModel _parent;
private object _model;
private bool _isListProperty;
private string _listDescription;
internal DataModelVisualizationViewModel()
{
}
public DataModelPropertyAttribute PropertyDescription
{
@ -62,7 +67,7 @@ namespace Artemis.UI.DataModelVisualization
public abstract void Update();
protected DataModelVisualizationViewModel CreateChild(PropertyInfo propertyInfo)
protected DataModelVisualizationViewModel CreateChild(IDataModelVisualizationService dataModelVisualizationService, PropertyInfo propertyInfo)
{
// Skip properties decorated with DataModelIgnore
if (Attribute.IsDefined(propertyInfo, typeof(DataModelIgnoreAttribute)))
@ -73,11 +78,15 @@ namespace Artemis.UI.DataModelVisualization
if (dataModelPropertyAttribute == null)
dataModelPropertyAttribute = new DataModelPropertyAttribute {Name = propertyInfo.Name.Humanize()};
// If a display VM was found, prefer to use that in any case
var typeViewModel = dataModelVisualizationService.GetDataModelDisplayViewModel(propertyInfo.PropertyType);
if (typeViewModel != null)
return new DataModelPropertyViewModel(propertyInfo, dataModelPropertyAttribute, this) {DisplayViewModel = typeViewModel};
// For primitives, create a property view model, it may be null that is fine
if (propertyInfo.PropertyType.IsPrimitive || propertyInfo.PropertyType == typeof(string))
return new DataModelPropertyViewModel(propertyInfo, dataModelPropertyAttribute, this);
if (typeof(IList).IsAssignableFrom(propertyInfo.PropertyType))
return new DataModelListViewModel(propertyInfo, dataModelPropertyAttribute, this);
return new DataModelListViewModel(propertyInfo, dataModelPropertyAttribute, this, dataModelVisualizationService);
// For other value types create a child view model if the value type is not null
if (propertyInfo.PropertyType.IsClass || propertyInfo.PropertyType.IsStruct())
{
@ -85,22 +94,26 @@ namespace Artemis.UI.DataModelVisualization
if (value == null)
return null;
return new DataModelViewModel(propertyInfo, value, dataModelPropertyAttribute, this);
return new DataModelViewModel(propertyInfo, value, dataModelPropertyAttribute, this, dataModelVisualizationService);
}
return null;
}
protected DataModelVisualizationViewModel CreateChild(object value)
protected DataModelVisualizationViewModel CreateChild(IDataModelVisualizationService dataModelVisualizationService, object value)
{
var dataModelPropertyAttribute = new DataModelPropertyAttribute {Name = "Unknown property"};
// If a display VM was found, prefer to use that in any case
var typeViewModel = dataModelVisualizationService.GetDataModelDisplayViewModel(value.GetType());
if (typeViewModel != null)
return new DataModelPropertyViewModel(null, dataModelPropertyAttribute, this) {Model = value, DisplayViewModel = typeViewModel};
// For primitives, create a property view model, it may be null that is fine
if (value.GetType().IsPrimitive || value is string)
return new DataModelPropertyViewModel(null, dataModelPropertyAttribute, this) {Model = value};
// For other value types create a child view model if the value type is not null
if (value.GetType().IsClass || value.GetType().IsStruct())
return new DataModelViewModel(null, value, dataModelPropertyAttribute, this);
return new DataModelViewModel(null, value, dataModelPropertyAttribute, this, dataModelVisualizationService);
return null;
}

View File

@ -30,15 +30,10 @@ namespace Artemis.UI.Shared.PropertyInput
PluginInfo.Instance.PluginDisabled -= InstanceOnPluginDisabled;
}
internal void Remove()
{
// It'll call Unsubscribe for us
_profileEditorService.RemovePropertyInput(this);
}
private void InstanceOnPluginDisabled(object sender, EventArgs e)
{
Remove();
// Profile editor service will call Unsubscribe
_profileEditorService.RemovePropertyInput(this);
}
}
}

View File

@ -5,10 +5,10 @@ using Stylet;
namespace Artemis.UI.Shared.PropertyInput
{
public abstract class PropertyInputViewModel<T> : ValidatingModelBase, IDisposable
public abstract class PropertyInputViewModel<T> : PropertyInputViewModel
{
private T _inputValue;
private bool _inputDragging;
private T _inputValue;
protected PropertyInputViewModel(LayerProperty<T> layerProperty, IProfileEditorService profileEditorService)
{
@ -30,6 +30,7 @@ namespace Artemis.UI.Shared.PropertyInput
public LayerProperty<T> LayerProperty { get; }
public IProfileEditorService ProfileEditorService { get; }
internal override object InternalGuard { get; } = null;
public bool InputDragging
{
@ -47,12 +48,15 @@ namespace Artemis.UI.Shared.PropertyInput
}
}
public virtual void Dispose()
public override void Dispose()
{
LayerProperty.Updated -= LayerPropertyOnUpdated;
LayerProperty.BaseValueChanged -= LayerPropertyOnUpdated;
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void OnInputValueApplied()
{
}
@ -97,7 +101,6 @@ namespace Artemis.UI.Shared.PropertyInput
Validate();
}
#region Event handlers
public void InputDragStarted(object sender, EventArgs e)
@ -122,4 +125,33 @@ namespace Artemis.UI.Shared.PropertyInput
#endregion
}
/// <summary>
/// For internal use only, implement <see cref="PropertyInputViewModel{T}"/> instead.
/// </summary>
public abstract class PropertyInputViewModel : ValidatingModelBase, IDisposable
{
protected PropertyInputViewModel()
{
}
protected PropertyInputViewModel(IModelValidator validator) : base(validator)
{
}
/// <summary>
/// Prevents this type being implemented directly, implement <see cref="PropertyInputViewModel{T}"/> instead.
/// </summary>
// ReSharper disable once UnusedMember.Global
internal abstract object InternalGuard { get; }
public abstract void Dispose();
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
}
}
}
}

View File

@ -0,0 +1,144 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.Exceptions;
using Artemis.Core.Plugins.Models;
using Artemis.Core.Services.Interfaces;
using Artemis.UI.Shared.DataModelVisualization;
using Artemis.UI.Shared.DataModelVisualization.Shared;
using Artemis.UI.Shared.Services.Interfaces;
using Ninject;
namespace Artemis.UI.Shared.Services
{
public class DataModelVisualizationService : IDataModelVisualizationService
{
private readonly IDataModelService _dataModelService;
private readonly IKernel _kernel;
private readonly List<DataModelVisualizationRegistration> _registeredDataModelDisplays;
private readonly List<DataModelVisualizationRegistration> _registeredDataModelEditors;
public DataModelVisualizationService(IDataModelService dataModelService, IKernel kernel)
{
_dataModelService = dataModelService;
_kernel = kernel;
_registeredDataModelEditors = new List<DataModelVisualizationRegistration>();
_registeredDataModelDisplays = new List<DataModelVisualizationRegistration>();
}
public DataModelViewModel GetMainDataModelVisualization()
{
var viewModel = new DataModelViewModel();
foreach (var dataModelExpansion in _dataModelService.DataModelExpansions)
viewModel.Children.Add(new DataModelViewModel(null, dataModelExpansion, dataModelExpansion.DataModelDescription, viewModel, this));
return viewModel;
}
public DataModelViewModel GetPluginDataModelVisualization(Plugin plugin)
{
var dataModel = _dataModelService.GetPluginDataModel(plugin);
if (dataModel == null)
return null;
var viewModel = new DataModelViewModel();
viewModel.Children.Add(new DataModelViewModel(null, dataModel, dataModel.DataModelDescription, viewModel, this));
return viewModel;
}
public DataModelVisualizationRegistration RegisterDataModelInput<T>(PluginInfo pluginInfo) where T : DataModelInputViewModel
{
var viewModelType = typeof(T);
lock (_registeredDataModelEditors)
{
var supportedType = viewModelType.BaseType.GetGenericArguments()[0];
var existing = _registeredDataModelEditors.FirstOrDefault(r => r.SupportedType == supportedType);
if (existing != null)
{
if (existing.PluginInfo != pluginInfo)
throw new ArtemisPluginException($"Cannot register property editor for type {supportedType.Name} because an editor was already registered by {pluginInfo.Name}");
return existing;
}
_kernel.Bind(viewModelType).ToSelf();
var registration = new DataModelVisualizationRegistration(this, RegistrationType.Input, pluginInfo, supportedType, viewModelType);
_registeredDataModelEditors.Add(registration);
return registration;
}
}
public DataModelVisualizationRegistration RegisterDataModelDisplay<T>(PluginInfo pluginInfo) where T : DataModelDisplayViewModel
{
var viewModelType = typeof(T);
lock (_registeredDataModelDisplays)
{
var supportedType = viewModelType.BaseType.GetGenericArguments()[0];
var existing = _registeredDataModelDisplays.FirstOrDefault(r => r.SupportedType == supportedType);
if (existing != null)
{
if (existing.PluginInfo != pluginInfo)
throw new ArtemisPluginException($"Cannot register property editor for type {supportedType.Name} because an editor was already registered by {pluginInfo.Name}");
return existing;
}
_kernel.Bind(viewModelType).ToSelf();
var registration = new DataModelVisualizationRegistration(this, RegistrationType.Display, pluginInfo, supportedType, viewModelType);
_registeredDataModelDisplays.Add(registration);
return registration;
}
}
public void RemoveDataModelInput(DataModelVisualizationRegistration registration)
{
lock (_registeredDataModelEditors)
{
if (_registeredDataModelEditors.Contains(registration))
{
registration.Unsubscribe();
_registeredDataModelEditors.Remove(registration);
_kernel.Unbind(registration.ViewModelType);
}
}
}
public void RemoveDataModelDisplay(DataModelVisualizationRegistration registration)
{
lock (_registeredDataModelDisplays)
{
if (_registeredDataModelDisplays.Contains(registration))
{
registration.Unsubscribe();
_registeredDataModelDisplays.Remove(registration);
_kernel.Unbind(registration.ViewModelType);
}
}
}
public DataModelDisplayViewModel GetDataModelDisplayViewModel(Type propertyType)
{
lock (_registeredDataModelDisplays)
{
var match = _registeredDataModelDisplays.FirstOrDefault(d => d.SupportedType == propertyType);
if (match != null)
return (DataModelDisplayViewModel) _kernel.Get(match.ViewModelType);
return null;
}
}
}
public interface IDataModelVisualizationService : IArtemisSharedUIService
{
DataModelViewModel GetMainDataModelVisualization();
DataModelViewModel GetPluginDataModelVisualization(Plugin plugin);
DataModelVisualizationRegistration RegisterDataModelInput<T>(PluginInfo pluginInfo) where T : DataModelInputViewModel;
DataModelVisualizationRegistration RegisterDataModelDisplay<T>(PluginInfo pluginInfo) where T : DataModelDisplayViewModel;
void RemoveDataModelInput(DataModelVisualizationRegistration registration);
void RemoveDataModelDisplay(DataModelVisualizationRegistration registration);
DataModelDisplayViewModel GetDataModelDisplayViewModel(Type propertyType);
}
}

View File

@ -63,7 +63,15 @@ namespace Artemis.UI.Shared.Services.Interfaces
/// </summary>
event EventHandler ProfilePreviewUpdated;
PropertyInputRegistration RegisterPropertyInput(PluginInfo pluginInfo, Type viewModelType);
/// <summary>
/// Registers a new property input view model used in the profile editor for the generic type defined in
/// <see cref="PropertyInputViewModel{T}" />
/// <para>Note: Registration will remove itself on plugin disable so you don't have to</para>
/// </summary>
/// <param name="pluginInfo"></param>
/// <returns></returns>
PropertyInputRegistration RegisterPropertyInput<T>(PluginInfo pluginInfo) where T : PropertyInputViewModel;
void RemovePropertyInput(PropertyInputRegistration registration);
}
}

View File

@ -103,6 +103,7 @@ namespace Artemis.UI.Shared.Services
foreach (var baseLayerEffect in folder.LayerEffects)
baseLayerEffect.Update(delta.TotalSeconds);
}
foreach (var layer in SelectedProfile.GetAllLayers())
{
layer.OverrideProgress(CurrentTime);
@ -153,12 +154,9 @@ namespace Artemis.UI.Shared.Services
UpdateProfilePreview();
}
public PropertyInputRegistration RegisterPropertyInput(PluginInfo pluginInfo, Type viewModelType)
public PropertyInputRegistration RegisterPropertyInput<T>(PluginInfo pluginInfo) where T : PropertyInputViewModel
{
// Bit ugly to do a name comparison but I don't know a nicer way right now
if (viewModelType.BaseType == null || viewModelType.BaseType.Name != typeof(PropertyInputViewModel<>).Name)
throw new ArtemisPluginException($"{nameof(viewModelType)} base type must be of type PropertyInputViewModel<T>");
var viewModelType = typeof(T);
lock (_registeredPropertyEditors)
{
var supportedType = viewModelType.BaseType.GetGenericArguments()[0];

View File

@ -1,23 +0,0 @@
using System.Reflection;
using Artemis.Core.Plugins.Abstract.DataModels.Attributes;
namespace Artemis.UI.DataModelVisualization
{
public class DataModelPropertyViewModel : DataModelVisualizationViewModel
{
public DataModelPropertyViewModel(PropertyInfo propertyInfo, DataModelPropertyAttribute propertyDescription, DataModelVisualizationViewModel parent)
{
PropertyInfo = propertyInfo;
Parent = parent;
PropertyDescription = propertyDescription;
}
public override void Update()
{
if (PropertyInfo != null && Parent?.Model != null)
Model = PropertyInfo.GetValue(Parent.Model);
UpdateListStatus();
}
}
}

View File

@ -0,0 +1,40 @@
<UserControl x:Class="Artemis.UI.DataModelVisualization.SKColorDataModelDisplayView"
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.DataModelVisualization"
xmlns:converters="clr-namespace:Artemis.UI.Shared.Converters;assembly=Artemis.UI.Shared"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance {x:Type local:SKColorDataModelDisplayViewModel}}">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Artemis.UI.Shared;component/Resources/ArtemisShared.xaml" />
</ResourceDictionary.MergedDictionaries>
<converters:ColorToStringConverter x:Key="SKColorToStringConverter" />
<converters:SKColorToColorConverter x:Key="SKColorToColorConverter" />
</ResourceDictionary>
</UserControl.Resources>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<TextBlock x:Name="HexDisplay"
Text="{Binding DisplayValue, Converter={StaticResource SKColorToStringConverter}}"
VerticalAlignment="Center"
HorizontalAlignment="Stretch"/>
<Border Width="{Binding ActualHeight, ElementName=HexDisplay}"
Height="{Binding ActualHeight, ElementName=HexDisplay}"
CornerRadius="{Binding ActualHeight, ElementName=HexDisplay}"
Margin="5 0 0 0"
VerticalAlignment="Center"
HorizontalAlignment="Right"
Background="{StaticResource Checkerboard}">
<Ellipse Stroke="{DynamicResource NormalBorderBrush}">
<Ellipse.Fill>
<SolidColorBrush Color="{Binding DisplayValue, Converter={StaticResource SKColorToColorConverter}}" />
</Ellipse.Fill>
</Ellipse>
</Border>
</StackPanel>
</UserControl>

View File

@ -0,0 +1,9 @@
using Artemis.UI.Shared.DataModelVisualization;
using SkiaSharp;
namespace Artemis.UI.DataModelVisualization
{
public class SKColorDataModelDisplayViewModel : DataModelDisplayViewModel<SKColor>
{
}
}

View File

@ -4,7 +4,6 @@ using Artemis.Core.Models.Profile.LayerProperties;
using Artemis.UI.Shared.PropertyInput;
using Artemis.UI.Shared.Services.Interfaces;
using FluentValidation;
// using PropertyChanged;
using SkiaSharp;
using Stylet;
@ -17,15 +16,12 @@ namespace Artemis.UI.PropertyInput
{
}
// Since SKPoint is immutable we need to create properties that replace the SKPoint entirely
// [DependsOn(nameof(InputValue))]
public float X
{
get => InputValue.X;
set => InputValue = new SKPoint(value, Y);
}
// [DependsOn(nameof(InputValue))]
public float Y
{
get => InputValue.Y;

View File

@ -4,11 +4,11 @@
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.Settings.Debug.Tabs"
xmlns:dataModel="clr-namespace:Artemis.UI.DataModelVisualization"
xmlns:s="https://github.com/canton7/Stylet"
xmlns:converters="clr-namespace:Artemis.UI.Converters"
xmlns:wpf="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:plugins="clr-namespace:Artemis.Core.Plugins.Abstract;assembly=Artemis.Core"
xmlns:dataModel="clr-namespace:Artemis.UI.Shared.DataModelVisualization.Shared;assembly=Artemis.UI.Shared"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" d:DataContext="{d:DesignInstance local:DataModelDebugViewModel}">
<UserControl.Resources>
@ -101,6 +101,8 @@
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<!-- Value description -->
<TextBlock Grid.Column="0" Margin="0 0 5 0" FontWeight="Bold">
<Run>[</Run><Run Text="{Binding PropertyType.Name, Mode=OneWay}" /><Run>]</Run>
</TextBlock>
@ -112,17 +114,24 @@
Text="{Binding ListDescription}"
ToolTip="{Binding PropertyDescription.Description}"
Visibility="{Binding IsListProperty, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}" />
<!-- Value display -->
<TextBlock Grid.Column="2"
Text="{Binding Model, Mode=OneWay}"
FontFamily="Consolas"
HorizontalAlignment="Right"
Visibility="{Binding Model, Converter={StaticResource NullToVisibilityConverter}}" />
Visibility="{Binding ShowToString, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}" />
<TextBlock Grid.Column="2"
Text="null"
FontFamily="Consolas"
HorizontalAlignment="Right"
Foreground="{DynamicResource MaterialDesignCheckBoxDisabled}"
Visibility="{Binding Model, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted}" />
Visibility="{Binding ShowNull, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}" />
<ContentControl Grid.Column="2"
s:View.Model="{Binding DisplayViewModel}"
FontFamily="Consolas"
Visibility="{Binding ShowViewModel, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}"/>
</Grid>
</HierarchicalDataTemplate>
</TreeView.Resources>

View File

@ -3,8 +3,9 @@ using System.Linq;
using System.Timers;
using Artemis.Core.Events;
using Artemis.Core.Services.Interfaces;
using Artemis.UI.DataModelVisualization;
using Artemis.UI.Services;
using Artemis.UI.Shared.DataModelVisualization.Shared;
using Artemis.UI.Shared.Services;
using Stylet;
namespace Artemis.UI.Screens.Settings.Debug.Tabs

View File

@ -1,43 +0,0 @@
using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Services.Interfaces;
using Artemis.UI.DataModelVisualization;
using Artemis.UI.Services.Interfaces;
namespace Artemis.UI.Services
{
public class DataModelVisualizationService : IDataModelVisualizationService
{
private readonly IDataModelService _dataModelService;
public DataModelVisualizationService(IDataModelService dataModelService)
{
_dataModelService = dataModelService;
}
public DataModelViewModel GetMainDataModelVisualization()
{
var viewModel = new DataModelViewModel();
foreach (var dataModelExpansion in _dataModelService.DataModelExpansions)
viewModel.Children.Add(new DataModelViewModel(null, dataModelExpansion, dataModelExpansion.DataModelDescription, viewModel));
return viewModel;
}
public DataModelViewModel GetPluginDataModelVisualization(Plugin plugin)
{
var dataModel = _dataModelService.GetPluginDataModel(plugin);
if (dataModel == null)
return null;
var viewModel = new DataModelViewModel();
viewModel.Children.Add(new DataModelViewModel(null, dataModel, dataModel.DataModelDescription, viewModel));
return viewModel;
}
}
public interface IDataModelVisualizationService : IArtemisUIService
{
DataModelViewModel GetMainDataModelVisualization();
DataModelViewModel GetPluginDataModelVisualization(Plugin plugin);
}
}

View File

@ -1,6 +1,10 @@
using System.Windows;
using System;
using System.Windows;
using Artemis.Core;
using Artemis.UI.DataModelVisualization;
using Artemis.UI.Screens.Settings.Debug;
using Artemis.UI.Services.Interfaces;
using Artemis.UI.Shared.Services;
using MaterialDesignExtensions.Controls;
using Ninject;
using Stylet;
@ -11,12 +15,21 @@ namespace Artemis.UI.Services
{
private readonly IKernel _kernel;
private readonly IWindowManager _windowManager;
private readonly IDataModelVisualizationService _dataModelVisualizationService;
private DebugViewModel _debugViewModel;
public DebugService(IKernel kernel, IWindowManager windowManager)
public DebugService(IKernel kernel, IWindowManager windowManager, IDataModelVisualizationService dataModelVisualizationService)
{
_kernel = kernel;
_windowManager = windowManager;
_dataModelVisualizationService = dataModelVisualizationService;
RegisterBuiltInDataModelDisplays();
}
private void RegisterBuiltInDataModelDisplays()
{
_dataModelVisualizationService.RegisterDataModelDisplay<SKColorDataModelDisplayViewModel>(Constants.CorePluginInfo);
}
public void ShowDebugger()

View File

@ -141,13 +141,13 @@ namespace Artemis.UI.Services
private void RegisterBuiltInPropertyEditors()
{
_profileEditorService.RegisterPropertyInput(Constants.CorePluginInfo, typeof(BrushPropertyInputViewModel));
_profileEditorService.RegisterPropertyInput(Constants.CorePluginInfo, typeof(ColorGradientPropertyInputViewModel));
_profileEditorService.RegisterPropertyInput(Constants.CorePluginInfo, typeof(FloatPropertyInputViewModel));
_profileEditorService.RegisterPropertyInput(Constants.CorePluginInfo, typeof(IntPropertyInputViewModel));
_profileEditorService.RegisterPropertyInput(Constants.CorePluginInfo, typeof(SKColorPropertyInputViewModel));
_profileEditorService.RegisterPropertyInput(Constants.CorePluginInfo, typeof(SKPointPropertyInputViewModel));
_profileEditorService.RegisterPropertyInput(Constants.CorePluginInfo, typeof(SKSizePropertyInputViewModel));
_profileEditorService.RegisterPropertyInput<BrushPropertyInputViewModel>(Constants.CorePluginInfo);
_profileEditorService.RegisterPropertyInput<ColorGradientPropertyInputViewModel>(Constants.CorePluginInfo);
_profileEditorService.RegisterPropertyInput<FloatPropertyInputViewModel>(Constants.CorePluginInfo);
_profileEditorService.RegisterPropertyInput<IntPropertyInputViewModel>(Constants.CorePluginInfo);
_profileEditorService.RegisterPropertyInput<SKColorPropertyInputViewModel>(Constants.CorePluginInfo);
_profileEditorService.RegisterPropertyInput<SKPointPropertyInputViewModel>(Constants.CorePluginInfo);
_profileEditorService.RegisterPropertyInput<SKSizePropertyInputViewModel>(Constants.CorePluginInfo);
}
}
}

View File

@ -6,7 +6,7 @@ namespace Artemis.Plugins.LayerBrushes.Color
{
public override void EnablePlugin()
{
AddLayerBrushDescriptor<ColorBrush>("Color", "A brush supporting solid colors and multiple types of gradients", "Brush");
RegisterLayerBrushDescriptor<ColorBrush>("Color", "A brush supporting solid colors and multiple types of gradients", "Brush");
}
public override void DisablePlugin()

View File

@ -15,8 +15,8 @@ namespace Artemis.Plugins.LayerBrushes.ColorRgbNet
public override void EnablePlugin()
{
_profileEditorService.RegisterPropertyInput(PluginInfo, typeof(StringPropertyInputViewModel));
AddLayerBrushDescriptor<RgbNetColorBrush>("RGB.NET Color", "A RGB.NET based color", "Brush");
_profileEditorService.RegisterPropertyInput<StringPropertyInputViewModel>(PluginInfo);
RegisterLayerBrushDescriptor<RgbNetColorBrush>("RGB.NET Color", "A RGB.NET based color", "Brush");
}
public override void DisablePlugin()

View File

@ -6,7 +6,7 @@ namespace Artemis.Plugins.LayerBrushes.Noise
{
public override void EnablePlugin()
{
AddLayerBrushDescriptor<NoiseBrush>("Noise", "A brush of that shows an animated random noise", "ScatterPlot");
RegisterLayerBrushDescriptor<NoiseBrush>("Noise", "A brush of that shows an animated random noise", "ScatterPlot");
}
public override void DisablePlugin()

View File

@ -20,6 +20,8 @@ namespace Artemis.Plugins.Modules.General
[DataModelProperty(Name = "A test boolean", Description = "This is a test boolean that's not of any use outside testing!")]
public bool TestBoolean { get; set; }
public SKColor TestColor { get; set; } = new SKColor(221, 21, 152);
[DataModelProperty(Name = "Player info", Description = "[TEST] Contains information about the player")]
public PlayerInfo PlayerInfo { get; set; }