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

Direct databindings - Added a large amount of modifiers

Direct databindings - Allow modifiers to have a different input parameter
Direct databindings - Categorised modifiers
Direct databindings - Added descriptions to modifiers
This commit is contained in:
Robert 2020-09-29 19:09:34 +02:00
parent a5455c26d6
commit e2f2f7ca65
48 changed files with 658 additions and 186 deletions

View File

@ -6,6 +6,11 @@
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=defaulttypes_005Cdatabindings_005Cconditions_005Coperators/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=defaulttypes_005Cdatabindings_005Cconditions_005Coperators/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=defaulttypes_005Cdatabindings_005Cconverters/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=defaulttypes_005Cdatabindings_005Cconverters/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=defaulttypes_005Cdatabindings_005Cmodifiers/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=defaulttypes_005Cdatabindings_005Cmodifiers/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=defaulttypes_005Cdatabindings_005Cmodifiers_005Ccolors/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=defaulttypes_005Cdatabindings_005Cmodifiers_005Cnumbers/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=defaulttypes_005Cdatabindings_005Cmodifiers_005Cnumbers_005Crounding/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=defaulttypes_005Cdatabindings_005Cmodifiers_005Cnumbers_005Ctrigonometric/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=defaulttypes_005Cdatabindings_005Cmodifiers_005Cnumbers_005Ctrigonometry/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=defaulttypes_005Cproperties/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=defaulttypes_005Cproperties/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=events/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=events/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=events_005Cplugins/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=events_005Cplugins/@EntryIndexedValue">True</s:Boolean>

View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using SkiaSharp;
namespace Artemis.Core.DefaultTypes
{
internal class SKColorBrightenModifierType : DataBindingModifierType
{
public override IReadOnlyCollection<Type> CompatibleTypes => new List<Type> {typeof(SKColor)};
public override Type ParameterType => typeof(float);
public override string Name => "Brighten by";
public override string Icon => "CarLightHigh";
public override string Description => "Brightens the color by the amount in percent";
public override object Apply(object currentValue, object parameterValue)
{
((SKColor) currentValue).ToHsl(out var h, out var s, out var l);
l *= (Convert.ToSingle(parameterValue) + 100f) / 100f;
return SKColor.FromHsl(h, s, l);
}
}
}

View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using SkiaSharp;
namespace Artemis.Core.DefaultTypes
{
internal class SKColorDarkenModifierType : DataBindingModifierType
{
public override IReadOnlyCollection<Type> CompatibleTypes => new List<Type> {typeof(SKColor)};
public override Type ParameterType => typeof(float);
public override string Name => "Darken by";
public override string Icon => "CarLightDimmed";
public override string Description => "Darkens the color by the amount in percent";
public override object Apply(object currentValue, object parameterValue)
{
((SKColor) currentValue).ToHsl(out var h, out var s, out var l);
l *= (Convert.ToSingle(parameterValue) * -1 + 100f) / 100f;
return SKColor.FromHsl(h, s, l);
}
}
}

View File

@ -7,8 +7,10 @@ namespace Artemis.Core.DefaultTypes
internal class SKColorSumModifierType : DataBindingModifierType internal class SKColorSumModifierType : DataBindingModifierType
{ {
public override IReadOnlyCollection<Type> CompatibleTypes => new List<Type> {typeof(SKColor)}; public override IReadOnlyCollection<Type> CompatibleTypes => new List<Type> {typeof(SKColor)};
public override string Description => "Combine with";
public override string Name => "Combine with";
public override string Icon => "FormatColorFill"; public override string Icon => "FormatColorFill";
public override string Description => "Adds the two colors together";
public override object Apply(object currentValue, object parameterValue) public override object Apply(object currentValue, object parameterValue)
{ {

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
namespace Artemis.Core.DefaultTypes
{
internal class AbsoluteModifierType : DataBindingModifierType
{
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
public override bool SupportsParameter => false;
public override string Name => "Absolute";
public override string Icon => "NumericPositive1";
public override string Category => "Advanced";
public override string Description => "Converts the input value to an absolute value";
public override object Apply(object currentValue, object parameterValue)
{
return Math.Abs(Convert.ToSingle(currentValue));
}
}
}

View File

@ -5,14 +5,10 @@ namespace Artemis.Core.DefaultTypes
{ {
internal class DivideModifierType : DataBindingModifierType internal class DivideModifierType : DataBindingModifierType
{ {
public DivideModifierType()
{
PreferredParameterType = typeof(float);
}
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes; public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
public override Type ParameterType => typeof(float);
public override string Description => "Divide by"; public override string Name => "Divide by";
public override string Icon => "Divide"; public override string Icon => "Divide";
public override object Apply(object currentValue, object parameterValue) public override object Apply(object currentValue, object parameterValue)

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
namespace Artemis.Core.DefaultTypes
{
internal class MaxModifierType : DataBindingModifierType
{
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
public override string Name => "Max";
public override string Icon => "ChevronUpBoxOutline";
public override string Category => "Advanced";
public override string Description => "Keeps only the largest of input value and parameter";
public override object Apply(object currentValue, object parameterValue)
{
return Math.Max(Convert.ToSingle(currentValue), Convert.ToSingle(parameterValue));
}
}
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
namespace Artemis.Core.DefaultTypes
{
internal class MinModifierType : DataBindingModifierType
{
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
public override string Name => "Min";
public override string Icon => "ChevronDownBoxOutline";
public override string Category => "Advanced";
public override string Description => "Keeps only the smallest of input value and parameter";
public override object Apply(object currentValue, object parameterValue)
{
return Math.Min(Convert.ToSingle(currentValue), Convert.ToSingle(parameterValue));
}
}
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
namespace Artemis.Core.DefaultTypes
{
internal class ModuloModifierType : DataBindingModifierType
{
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
public override string Name => "Modulo";
public override string Icon => "Stairs";
public override string Category => "Advanced";
public override string Description => "Calculates the remained of the division between the input value and the parameter";
public override object Apply(object currentValue, object parameterValue)
{
return Convert.ToSingle(currentValue) % Convert.ToSingle(parameterValue);
}
}
}

View File

@ -5,14 +5,10 @@ namespace Artemis.Core.DefaultTypes
{ {
internal class MultiplicationModifierType : DataBindingModifierType internal class MultiplicationModifierType : DataBindingModifierType
{ {
public MultiplicationModifierType()
{
PreferredParameterType = typeof(float);
}
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes; public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
public override Type ParameterType => typeof(float);
public override string Description => "Multiply by"; public override string Name => "Multiply by";
public override string Icon => "Close"; public override string Icon => "Close";
public override object Apply(object currentValue, object parameterValue) public override object Apply(object currentValue, object parameterValue)

View File

@ -5,15 +5,12 @@ namespace Artemis.Core.DefaultTypes
{ {
internal class PercentageOfModifierType : DataBindingModifierType internal class PercentageOfModifierType : DataBindingModifierType
{ {
public PercentageOfModifierType()
{
PreferredParameterType = typeof(float);
}
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes; public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
public override Type ParameterType => typeof(float);
public override string Description => "Percentage of"; public override string Name => "Percentage of";
public override string Icon => "Percent"; public override string Icon => "Percent";
public override string Description => "Calculates how much percent the parameter value is of the current value";
public override object Apply(object currentValue, object parameterValue) public override object Apply(object currentValue, object parameterValue)
{ {

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
namespace Artemis.Core.DefaultTypes
{
internal class PowerModifierType : DataBindingModifierType
{
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
public override string Name => "Power";
public override string Icon => "Exponent";
public override string Category => "Advanced";
public override string Description => "Raises the input value to the power of the parameter value";
public override object Apply(object currentValue, object parameterValue)
{
return Math.Pow(Convert.ToSingle(currentValue), Convert.ToSingle(parameterValue));
}
}
}

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
namespace Artemis.Core.DefaultTypes
{
internal class CeilingModifierType : DataBindingModifierType
{
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
public override bool SupportsParameter => false;
public override string Name => "Round up";
public override string Icon => "ArrowUp";
public override string Category => "Rounding";
public override string Description => "Ceils the input, rounding it up to the nearest whole number";
public override object Apply(object currentValue, object parameterValue)
{
var floatValue = Convert.ToSingle(currentValue);
return Math.Ceiling(floatValue);
}
}
}

View File

@ -5,15 +5,13 @@ namespace Artemis.Core.DefaultTypes
{ {
internal class FloorModifierType : DataBindingModifierType internal class FloorModifierType : DataBindingModifierType
{ {
public FloorModifierType()
{
SupportsParameter = false;
}
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes; public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
public override string Description => "Floor"; public override bool SupportsParameter => false;
public override string Icon => "ArrowDownDropCircleOutline";
public override string Name => "Round down";
public override string Icon => "ArrowDown";
public override string Category => "Rounding";
public override string Description => "Floors the input, rounding it down to the nearest whole number";
public override object Apply(object currentValue, object parameterValue) public override object Apply(object currentValue, object parameterValue)
{ {

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
namespace Artemis.Core.DefaultTypes
{
internal class RoundModifierType : DataBindingModifierType
{
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
public override bool SupportsParameter => false;
public override string Name => "Round";
public override string Icon => "ArrowCollapse";
public override string Category => "Rounding";
public override string Description => "Rounds the input to the nearest whole number";
public override object Apply(object currentValue, object parameterValue)
{
var floatValue = Convert.ToSingle(currentValue);
return Math.Round(floatValue, MidpointRounding.AwayFromZero);
}
}
}

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
namespace Artemis.Core.DefaultTypes
{
internal class SquareRootModifierType : DataBindingModifierType
{
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
public override bool SupportsParameter => false;
public override string Name => "Square root";
public override string Icon => "SquareRoot";
public override string Category => "Advanced";
public override string Description => "Calculates square root of the input value";
public override object Apply(object currentValue, object parameterValue)
{
return Math.Sqrt(Convert.ToSingle(currentValue));
}
}
}

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
namespace Artemis.Core.DefaultTypes
{
internal class SubtractModifierType : DataBindingModifierType
{
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
public override string Name => "Subtract";
public override string Icon => "Minus";
public override object Apply(object currentValue, object parameterValue)
{
return Convert.ToSingle(currentValue) - Convert.ToSingle(parameterValue);
}
}
}

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
namespace Artemis.Core.DefaultTypes
{
internal class SumModifierType : DataBindingModifierType
{
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
public override string Name => "Sum";
public override string Icon => "Plus";
public override object Apply(object currentValue, object parameterValue)
{
return Convert.ToSingle(currentValue) + Convert.ToSingle(parameterValue);
}
}
}

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
namespace Artemis.Core.DefaultTypes
{
internal class CosecantModifierType : DataBindingModifierType
{
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
public override bool SupportsParameter => false;
public override string Name => "Cosecant";
public override string Icon => null;
public override string Category => "Trigonometry";
public override string Description => "Treats the input as an angle and calculates the cosecant";
public override object Apply(object currentValue, object parameterValue)
{
return 1f / Math.Sin(Convert.ToSingle(currentValue));
}
}
}

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
namespace Artemis.Core.DefaultTypes
{
internal class CosineModifierType : DataBindingModifierType
{
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
public override bool SupportsParameter => false;
public override string Name => "Cosine";
public override string Icon => "MathCos";
public override string Category => "Trigonometry";
public override string Description => "Treats the input as an angle and calculates the cosine";
public override object Apply(object currentValue, object parameterValue)
{
return Math.Cos(Convert.ToSingle(currentValue));
}
}
}

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
namespace Artemis.Core.DefaultTypes
{
internal class CotangentModifierType : DataBindingModifierType
{
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
public override bool SupportsParameter => false;
public override string Name => "Cotangent";
public override string Icon => null;
public override string Category => "Trigonometry";
public override string Description => "Treats the input as an angle and calculates the cotangent";
public override object Apply(object currentValue, object parameterValue)
{
return 1f / Math.Tan(Convert.ToSingle(currentValue));
}
}
}

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
namespace Artemis.Core.DefaultTypes
{
internal class SecantModifierType : DataBindingModifierType
{
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
public override bool SupportsParameter => false;
public override string Name => "Secant";
public override string Icon => null;
public override string Category => "Trigonometry";
public override string Description => "Treats the input as an angle and calculates the secant";
public override object Apply(object currentValue, object parameterValue)
{
return 1f / Math.Cos(Convert.ToSingle(currentValue));
}
}
}

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
namespace Artemis.Core.DefaultTypes
{
internal class SineModifierType : DataBindingModifierType
{
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
public override bool SupportsParameter => false;
public override string Name => "Sine";
public override string Icon => "MathSin";
public override string Category => "Trigonometry";
public override string Description => "Treats the input as an angle and calculates the sine";
public override object Apply(object currentValue, object parameterValue)
{
return Math.Sin(Convert.ToSingle(currentValue));
}
}
}

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
namespace Artemis.Core.DefaultTypes
{
internal class TangentModifierType : DataBindingModifierType
{
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
public override bool SupportsParameter => false;
public override string Name => "Tangent";
public override string Icon => "MathTan";
public override string Category => "Trigonometry";
public override string Description => "Treats the input as an angle and calculates the tangent";
public override object Apply(object currentValue, object parameterValue)
{
return Math.Tan(Convert.ToSingle(currentValue));
}
}
}

View File

@ -1,5 +1,4 @@
using System; using System;
using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
using Artemis.Core.DataModelExpansions; using Artemis.Core.DataModelExpansions;
using Artemis.Storage.Entities.Profile.DataBindings; using Artemis.Storage.Entities.Profile.DataBindings;
@ -227,16 +226,16 @@ namespace Artemis.Core
ParameterDataModel = null; ParameterDataModel = null;
ParameterPropertyPath = null; ParameterPropertyPath = null;
var targetType = DirectDataBinding.DataBinding.GetTargetType(); var parameterType = ModifierType?.ParameterType ?? DirectDataBinding.DataBinding.GetTargetType();
// If not null ensure the types match and if not, convert it // If not null ensure the types match and if not, convert it
if (staticValue != null && staticValue.GetType() == targetType) if (staticValue != null && staticValue.GetType() == parameterType)
ParameterStaticValue = staticValue; ParameterStaticValue = staticValue;
else if (staticValue != null) else if (staticValue != null)
ParameterStaticValue = Convert.ChangeType(staticValue, targetType); ParameterStaticValue = Convert.ChangeType(staticValue, parameterType);
// If null create a default instance for value types or simply make it null for reference types // If null create a default instance for value types or simply make it null for reference types
else if (targetType.IsValueType) else if (parameterType.IsValueType)
ParameterStaticValue = Activator.CreateInstance(targetType); ParameterStaticValue = Activator.CreateInstance(parameterType);
else else
ParameterStaticValue = null; ParameterStaticValue = null;
@ -269,18 +268,18 @@ namespace Artemis.Core
else if (ParameterType == ProfileRightSideType.Static && Entity.ParameterStaticValue != null && ParameterStaticValue == null) else if (ParameterType == ProfileRightSideType.Static && Entity.ParameterStaticValue != null && ParameterStaticValue == null)
{ {
// Use the target type so JSON.NET has a better idea what to do // Use the target type so JSON.NET has a better idea what to do
var targetType = DirectDataBinding.DataBinding.GetTargetType(); var parameterType = ModifierType?.ParameterType ?? DirectDataBinding.DataBinding.GetTargetType();
object staticValue; object staticValue;
try try
{ {
staticValue = JsonConvert.DeserializeObject(Entity.ParameterStaticValue, targetType); staticValue = JsonConvert.DeserializeObject(Entity.ParameterStaticValue, parameterType);
} }
// If deserialization fails, use the type's default // If deserialization fails, use the type's default
catch (JsonSerializationException e) catch (JsonSerializationException e)
{ {
DeserializationLogger.LogModifierDeserializationFailure(GetType().Name, e); DeserializationLogger.LogModifierDeserializationFailure(GetType().Name, e);
staticValue = Activator.CreateInstance(targetType); staticValue = Activator.CreateInstance(parameterType);
} }
UpdateParameter(staticValue); UpdateParameter(staticValue);

View File

@ -21,9 +21,20 @@ namespace Artemis.Core
public abstract IReadOnlyCollection<Type> CompatibleTypes { get; } public abstract IReadOnlyCollection<Type> CompatibleTypes { get; }
/// <summary> /// <summary>
/// Gets or sets the description of this modifier /// Gets the supported parameter type
/// <para>If <c>null</c>, the parameter type will match the source property</para>
/// </summary> /// </summary>
public abstract string Description { get; } public virtual Type ParameterType => null;
/// <summary>
/// Gets or sets whether this modifier supports a parameter, defaults to <c>true</c>
/// </summary>
public virtual bool SupportsParameter => true;
/// <summary>
/// Gets the name of this modifier
/// </summary>
public abstract string Name { get; }
/// <summary> /// <summary>
/// Gets or sets the icon of this modifier /// Gets or sets the icon of this modifier
@ -31,15 +42,14 @@ namespace Artemis.Core
public abstract string Icon { get; } public abstract string Icon { get; }
/// <summary> /// <summary>
/// Gets or sets whether this modifier supports a parameter, defaults to <c>true</c> /// Gets the description of this modifier
/// </summary> /// </summary>
public bool SupportsParameter { get; protected set; } = true; public virtual string Description => null;
/// <summary> /// <summary>
/// Gets or sets the preferred parameter type /// Gets the category of this modifier
/// <para>If <c>null</c>, the parameter type will match the source property</para>
/// </summary> /// </summary>
public Type PreferredParameterType { get; protected set; } = null; public virtual string Category => null;
/// <summary> /// <summary>
/// Returns whether the given type is supported by the modifier /// Returns whether the given type is supported by the modifier

View File

@ -42,11 +42,38 @@ namespace Artemis.Core.Services
private void RegisterBuiltInModifiers() private void RegisterBuiltInModifiers()
{ {
// Numbers - General
RegisterModifierType(Constants.CorePluginInfo, new SumModifierType());
RegisterModifierType(Constants.CorePluginInfo, new SubtractModifierType());
RegisterModifierType(Constants.CorePluginInfo, new MultiplicationModifierType()); RegisterModifierType(Constants.CorePluginInfo, new MultiplicationModifierType());
RegisterModifierType(Constants.CorePluginInfo, new PercentageOfModifierType());
RegisterModifierType(Constants.CorePluginInfo, new DivideModifierType()); RegisterModifierType(Constants.CorePluginInfo, new DivideModifierType());
RegisterModifierType(Constants.CorePluginInfo, new PercentageOfModifierType());
// Numbers - Advanced
RegisterModifierType(Constants.CorePluginInfo, new MaxModifierType());
RegisterModifierType(Constants.CorePluginInfo, new MinModifierType());
RegisterModifierType(Constants.CorePluginInfo, new ModuloModifierType());
RegisterModifierType(Constants.CorePluginInfo, new AbsoluteModifierType());
RegisterModifierType(Constants.CorePluginInfo, new PowerModifierType());
RegisterModifierType(Constants.CorePluginInfo, new SquareRootModifierType());
// Numbers - Rounding
RegisterModifierType(Constants.CorePluginInfo, new FloorModifierType()); RegisterModifierType(Constants.CorePluginInfo, new FloorModifierType());
RegisterModifierType(Constants.CorePluginInfo, new RoundModifierType());
RegisterModifierType(Constants.CorePluginInfo, new CeilingModifierType());
// Numbers - Trigonometric
RegisterModifierType(Constants.CorePluginInfo, new SineModifierType());
RegisterModifierType(Constants.CorePluginInfo, new CosineModifierType());
RegisterModifierType(Constants.CorePluginInfo, new TangentModifierType());
RegisterModifierType(Constants.CorePluginInfo, new CotangentModifierType());
RegisterModifierType(Constants.CorePluginInfo, new SecantModifierType());
RegisterModifierType(Constants.CorePluginInfo, new CosecantModifierType());
// Colors
RegisterModifierType(Constants.CorePluginInfo, new SKColorSumModifierType()); RegisterModifierType(Constants.CorePluginInfo, new SKColorSumModifierType());
RegisterModifierType(Constants.CorePluginInfo, new SKColorBrightenModifierType());
RegisterModifierType(Constants.CorePluginInfo, new SKColorDarkenModifierType());
} }
} }
} }

View File

@ -14,7 +14,7 @@ namespace Artemis.Core
lock (Registrations) lock (Registrations)
{ {
if (Registrations.Any(r => r.DataBindingModifierType == modifierType)) if (Registrations.Any(r => r.DataBindingModifierType == modifierType))
throw new ArtemisCoreException($"Data binding modifier type store already contains modifier '{modifierType.Description}'"); throw new ArtemisCoreException($"Data binding modifier type store already contains modifier '{modifierType.Name}'");
typeRegistration = new DataBindingModifierTypeRegistration(modifierType, modifierType.PluginInfo.Instance) { IsInStore = true }; typeRegistration = new DataBindingModifierTypeRegistration(modifierType, modifierType.PluginInfo.Instance) { IsInStore = true };
Registrations.Add(typeRegistration); Registrations.Add(typeRegistration);
@ -29,7 +29,7 @@ namespace Artemis.Core
lock (Registrations) lock (Registrations)
{ {
if (!Registrations.Contains(typeRegistration)) if (!Registrations.Contains(typeRegistration))
throw new ArtemisCoreException($"Data binding modifier type store does not contain modifier type '{typeRegistration.DataBindingModifierType.Description}'"); throw new ArtemisCoreException($"Data binding modifier type store does not contain modifier type '{typeRegistration.DataBindingModifierType.Name}'");
Registrations.Remove(typeRegistration); Registrations.Remove(typeRegistration);
typeRegistration.IsInStore = false; typeRegistration.IsInStore = false;
@ -56,7 +56,7 @@ namespace Artemis.Core
var candidates = Registrations.Where(r => r.DataBindingModifierType.CompatibleTypes.Any(t => t == type)).ToList(); var candidates = Registrations.Where(r => r.DataBindingModifierType.CompatibleTypes.Any(t => t == type)).ToList();
// If there are multiple operators with the same description, use the closest match // If there are multiple operators with the same description, use the closest match
foreach (var displayDataBindingModifiers in candidates.GroupBy(r => r.DataBindingModifierType.Description).Where(g => g.Count() > 1).ToList()) foreach (var displayDataBindingModifiers in candidates.GroupBy(r => r.DataBindingModifierType.Name).Where(g => g.Count() > 1).ToList())
{ {
var closest = displayDataBindingModifiers.OrderByDescending(r => r.DataBindingModifierType.CompatibleTypes.Contains(type)).FirstOrDefault(); var closest = displayDataBindingModifiers.OrderByDescending(r => r.DataBindingModifierType.CompatibleTypes.Contains(type)).FirstOrDefault();
foreach (var displayDataBindingModifier in displayDataBindingModifiers) foreach (var displayDataBindingModifier in displayDataBindingModifiers)

View File

@ -4,8 +4,6 @@
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:shared="clr-namespace:Artemis.UI.Shared" xmlns:shared="clr-namespace:Artemis.UI.Shared"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:s="https://github.com/canton7/Stylet"
xmlns:input="clr-namespace:Artemis.UI.Shared.Input" xmlns:input="clr-namespace:Artemis.UI.Shared.Input"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" d:DesignHeight="450" d:DesignWidth="800"
@ -29,40 +27,35 @@
</ResourceDictionary.MergedDictionaries> </ResourceDictionary.MergedDictionaries>
</ResourceDictionary> </ResourceDictionary>
</UserControl.Resources> </UserControl.Resources>
<Button Background="{Binding ButtonBrush}"
<Button Background="{Binding ButtonBrush}" BorderBrush="{Binding ButtonBrush}"
BorderBrush="{Binding ButtonBrush}" Style="{StaticResource DataModelConditionButton}"
Style="{StaticResource DataModelConditionButton}" ToolTip="{Binding SelectedPropertyViewModel.DisplayPropertyPath}"
ToolTip="{Binding SelectedPropertyViewModel.DisplayPropertyPath}" IsEnabled="{Binding IsEnabled}"
IsEnabled="{Binding IsEnabled}" HorizontalAlignment="Left"
HorizontalAlignment="Left" Click="PropertyButton_OnClick">
Click="PropertyButton_OnClick"> <Button.ContextMenu>
<Button.ContextMenu> <ContextMenu ItemsSource="{Binding DataModelViewModel.Children}" IsOpen="{Binding IsDataModelViewModelOpen, Mode=OneWayToSource}">
<ContextMenu ItemsSource="{Binding DataModelViewModel.Children}" IsOpen="{Binding IsDataModelViewModelOpen, Mode=OneWayToSource}"> <ContextMenu.ItemContainerStyle>
<ContextMenu.ItemContainerStyle> <Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource MaterialDesignMenuItem}">
<Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource MaterialDesignMenuItem}"> <Setter Property="ItemsSource" Value="{Binding Children}" />
<Setter Property="ItemsSource" Value="{Binding Children}" /> <Setter Property="Command" Value="{Binding Data.SelectPropertyCommand, Source={StaticResource DataContextProxy}}" />
<Setter Property="Command" Value="{Binding Data.SelectPropertyCommand, Source={StaticResource DataContextProxy}}" /> <Setter Property="CommandParameter" Value="{Binding}" />
<Setter Property="CommandParameter" Value="{Binding}" /> <Setter Property="CommandTarget" Value="{Binding}" />
<Setter Property="CommandTarget" Value="{Binding}" /> <Setter Property="IsEnabled" Value="{Binding IsMatchingFilteredTypes}" />
<Setter Property="IsEnabled" Value="{Binding IsMatchingFilteredTypes}" /> <Setter Property="IsSubmenuOpen" Value="{Binding IsVisualizationExpanded, Mode=TwoWay}" />
<Setter Property="IsSubmenuOpen" Value="{Binding IsVisualizationExpanded, Mode=TwoWay}" /> <Setter Property="HeaderTemplate" Value="{StaticResource DataModelDataTemplate}" />
<Setter Property="HeaderTemplate" Value="{StaticResource DataModelDataTemplate}" /> </Style>
</Style> </ContextMenu.ItemContainerStyle>
</ContextMenu.ItemContainerStyle> </ContextMenu>
</ContextMenu> </Button.ContextMenu>
</Button.ContextMenu> <Grid>
<Grid> <TextBlock Text="{Binding SelectedPropertyViewModel.PropertyDescription.Name}"
<TextBlock Text="{Binding SelectedPropertyViewModel.PropertyDescription.Name}" Visibility="{Binding SelectedPropertyViewModel, Converter={StaticResource NullToVisibilityConverter}}" />
Visibility="{Binding SelectedPropertyViewModel, Converter={StaticResource NullToVisibilityConverter}}" /> <TextBlock FontStyle="Italic"
<TextBlock FontStyle="Italic" Visibility="{Binding SelectedPropertyViewModel, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted}">
Visibility="{Binding SelectedPropertyViewModel, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted}"> <Run Text="« " /><Run Text="{Binding Placeholder}" /><Run Text=" »" />
<Run Text="« " /><Run Text="{Binding Placeholder}" /><Run Text=" »" /> </TextBlock>
</TextBlock> </Grid>
</Grid> </Button>
</Button>
</UserControl> </UserControl>

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using Artemis.Core.DataModelExpansions; using Artemis.Core.DataModelExpansions;

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using Artemis.Core; using Artemis.Core;
using Artemis.Core.DataModelExpansions; using Artemis.Core.DataModelExpansions;

View File

@ -1,4 +1,6 @@
using System.Linq; using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection; using System.Reflection;
using Artemis.Core.DataModelExpansions; using Artemis.Core.DataModelExpansions;
using Artemis.UI.Shared.Services; using Artemis.UI.Shared.Services;

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using Artemis.Core; using Artemis.Core;

View File

@ -78,7 +78,7 @@
</ListBox.ItemTemplate> </ListBox.ItemTemplate>
<ListBox.ItemsPanel> <ListBox.ItemsPanel>
<ItemsPanelTemplate> <ItemsPanelTemplate>
<VirtualizingStackPanel/> <VirtualizingStackPanel />
</ItemsPanelTemplate> </ItemsPanelTemplate>
</ListBox.ItemsPanel> </ListBox.ItemsPanel>
</ListBox> </ListBox>

View File

@ -11,8 +11,8 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.Conditio
{ {
public class ConditionalDataBindingModeViewModel<TLayerProperty, TProperty> : Screen, IDataBindingModeViewModel public class ConditionalDataBindingModeViewModel<TLayerProperty, TProperty> : Screen, IDataBindingModeViewModel
{ {
private readonly IProfileEditorService _profileEditorService;
private readonly IDataBindingsVmFactory _dataBindingsVmFactory; private readonly IDataBindingsVmFactory _dataBindingsVmFactory;
private readonly IProfileEditorService _profileEditorService;
private bool _updating; private bool _updating;
public ConditionalDataBindingModeViewModel(ConditionalDataBinding<TLayerProperty, TProperty> conditionalDataBinding, public ConditionalDataBindingModeViewModel(ConditionalDataBinding<TLayerProperty, TProperty> conditionalDataBinding,
@ -42,6 +42,19 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.Conditio
throw new NotSupportedException(); throw new NotSupportedException();
} }
#region IDisposable
public void Dispose()
{
ConditionalDataBinding.ConditionsUpdated -= ConditionalDataBindingOnConditionsUpdated;
foreach (var conditionViewModel in ConditionViewModels)
conditionViewModel.Dispose();
ConditionViewModels.Clear();
}
#endregion
public void AddCondition(string type) public void AddCondition(string type)
{ {
var condition = ConditionalDataBinding.AddCondition(); var condition = ConditionalDataBinding.AddCondition();
@ -105,18 +118,5 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.Conditio
{ {
UpdateConditionViewModels(); UpdateConditionViewModels();
} }
#region IDisposable
public void Dispose()
{
ConditionalDataBinding.ConditionsUpdated -= ConditionalDataBindingOnConditionsUpdated;
foreach (var conditionViewModel in ConditionViewModels)
conditionViewModel.Dispose();
ConditionViewModels.Clear();
}
#endregion
} }
} }

View File

@ -32,6 +32,15 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.Conditio
ValueViewModel.Value = DataBindingCondition.Value; ValueViewModel.Value = DataBindingCondition.Value;
} }
public DataBindingCondition<TLayerProperty, TProperty> DataBindingCondition { get; }
public DataModelStaticViewModel ValueViewModel { get; set; }
public void Dispose()
{
ValueViewModel.Dispose();
}
private void ActiveItemOnUpdated(object sender, EventArgs e) private void ActiveItemOnUpdated(object sender, EventArgs e)
{ {
if (!ActiveItem.GetChildren().Any()) if (!ActiveItem.GetChildren().Any())
@ -43,14 +52,5 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.Conditio
DataBindingCondition.Value = (TProperty) Convert.ChangeType(e.Value, typeof(TProperty)); DataBindingCondition.Value = (TProperty) Convert.ChangeType(e.Value, typeof(TProperty));
_profileEditorService.UpdateSelectedProfileElement(); _profileEditorService.UpdateSelectedProfileElement();
} }
public DataBindingCondition<TLayerProperty, TProperty> DataBindingCondition { get; }
public DataModelStaticViewModel ValueViewModel { get; set; }
public void Dispose()
{
ValueViewModel.Dispose();
}
} }
} }

View File

@ -1,5 +1,4 @@
using System.Windows; using System.Windows.Controls;
using System.Windows.Controls;
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
{ {

View File

@ -12,16 +12,16 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
public class DataBindingViewModel<TLayerProperty, TProperty> : Conductor<IDataBindingModeViewModel>, IDataBindingViewModel public class DataBindingViewModel<TLayerProperty, TProperty> : Conductor<IDataBindingModeViewModel>, IDataBindingViewModel
{ {
private readonly IDataBindingsVmFactory _dataBindingsVmFactory; private readonly IDataBindingsVmFactory _dataBindingsVmFactory;
private readonly IProfileEditorService _profileEditorService;
private readonly IDataModelUIService _dataModelUIService; private readonly IDataModelUIService _dataModelUIService;
private readonly IProfileEditorService _profileEditorService;
private DataBinding<TLayerProperty, TProperty> _dataBinding; private DataBinding<TLayerProperty, TProperty> _dataBinding;
private int _easingTime; private int _easingTime;
private bool _isDataBindingEnabled;
private bool _isEasingTimeEnabled; private bool _isEasingTimeEnabled;
private DataBindingModeType _selectedDataBindingMode; private DataBindingModeType _selectedDataBindingMode;
private TimelineEasingViewModel _selectedEasingViewModel; private TimelineEasingViewModel _selectedEasingViewModel;
private bool _updating; private bool _updating;
private bool _isDataBindingEnabled;
public DataBindingViewModel(DataBindingRegistration<TLayerProperty, TProperty> registration, public DataBindingViewModel(DataBindingRegistration<TLayerProperty, TProperty> registration,
IProfileEditorService profileEditorService, IProfileEditorService profileEditorService,
@ -219,9 +219,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
TestResultValue.UpdateValue(Registration.DataBinding != null ? Registration.DataBinding.GetValue(currentValue) : default); TestResultValue.UpdateValue(Registration.DataBinding != null ? Registration.DataBinding.GetValue(currentValue) : default);
} }
else else
{
TestResultValue.UpdateValue(Registration.DataBinding != null ? Registration.DataBinding.GetValue(default) : default); TestResultValue.UpdateValue(Registration.DataBinding != null ? Registration.DataBinding.GetValue(default) : default);
}
} }
private void EnableDataBinding() private void EnableDataBinding()

View File

@ -26,6 +26,12 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
set => SetAndNotify(ref _selectedItemIndex, value); set => SetAndNotify(ref _selectedItemIndex, value);
} }
protected override void OnClose()
{
_profileEditorService.SelectedDataBindingChanged -= ProfileEditorServiceOnSelectedDataBindingChanged;
base.OnClose();
}
private void CreateDataBindingViewModels() private void CreateDataBindingViewModels()
{ {
Items.Clear(); Items.Clear();
@ -44,12 +50,6 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
SelectedItemIndex = 0; SelectedItemIndex = 0;
} }
protected override void OnClose()
{
_profileEditorService.SelectedDataBindingChanged -= ProfileEditorServiceOnSelectedDataBindingChanged;
base.OnClose();
}
private void ProfileEditorServiceOnSelectedDataBindingChanged(object? sender, EventArgs e) private void ProfileEditorServiceOnSelectedDataBindingChanged(object? sender, EventArgs e)
{ {
CreateDataBindingViewModels(); CreateDataBindingViewModels();

View File

@ -8,9 +8,9 @@
xmlns:converters="clr-namespace:Artemis.UI.Converters" xmlns:converters="clr-namespace:Artemis.UI.Converters"
xmlns:utilities="clr-namespace:Artemis.UI.Utilities" xmlns:utilities="clr-namespace:Artemis.UI.Utilities"
xmlns:local="clr-namespace:Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDataBinding" xmlns:local="clr-namespace:Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDataBinding"
xmlns:modifierTypes="clr-namespace:Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDataBinding.ModifierTypes"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" d:DesignHeight="450" d:DesignWidth="800">
d:DataContext="{d:DesignInstance local:DataBindingModifierViewModel}">
<UserControl.Resources> <UserControl.Resources>
<ResourceDictionary> <ResourceDictionary>
<ResourceDictionary.MergedDictionaries> <ResourceDictionary.MergedDictionaries>
@ -56,17 +56,33 @@
BorderBrush="#7B7B7B" BorderBrush="#7B7B7B"
Click="PropertyButton_OnClick"> Click="PropertyButton_OnClick">
<Button.ContextMenu> <Button.ContextMenu>
<ContextMenu ItemsSource="{Binding ModifierTypes}"> <ContextMenu ItemsSource="{Binding ModifierTypeViewModels.Children}">
<ContextMenu.ItemTemplate> <ContextMenu.ItemTemplate>
<DataTemplate> <DataTemplate>
<StackPanel Orientation="Horizontal"> <StackPanel>
<materialDesign:PackIcon Kind="{Binding Icon}" VerticalAlignment="Center" Margin="0 0 15 0" /> <StackPanel.Resources>
<TextBlock Text="{Binding Description}" VerticalAlignment="Center" /> <DataTemplate DataType="{x:Type modifierTypes:ModifierTypeCategoryViewModel}">
<TextBlock Text="{Binding Category}" />
</DataTemplate>
<DataTemplate DataType="{x:Type modifierTypes:ModifierTypeViewModel}">
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="{Binding ModifierType.Icon}"
VerticalAlignment="Center"
Margin="0 0 15 0"
Visibility="{Binding ModifierType.Icon, Converter={StaticResource NullToVisibilityConverter}}"/>
<TextBlock Text="{Binding ModifierType.Name}"
VerticalAlignment="Center"
ToolTip="{Binding ModifierType.Description}"/>
</StackPanel>
</DataTemplate>
</StackPanel.Resources>
<ContentPresenter Content="{Binding}" />
</StackPanel> </StackPanel>
</DataTemplate> </DataTemplate>
</ContextMenu.ItemTemplate> </ContextMenu.ItemTemplate>
<ContextMenu.ItemContainerStyle> <ContextMenu.ItemContainerStyle>
<Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource MaterialDesignMenuItem}"> <Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource MaterialDesignMenuItem}">
<Setter Property="ItemsSource" Value="{Binding Children}" />
<Setter Property="Command" Value="{Binding Data.SelectModifierTypeCommand, Source={StaticResource DataContextProxy}}" /> <Setter Property="Command" Value="{Binding Data.SelectModifierTypeCommand, Source={StaticResource DataContextProxy}}" />
<Setter Property="CommandParameter" Value="{Binding}" /> <Setter Property="CommandParameter" Value="{Binding}" />
<Setter Property="CommandTarget" Value="{Binding}" /> <Setter Property="CommandTarget" Value="{Binding}" />
@ -75,7 +91,7 @@
</ContextMenu> </ContextMenu>
</Button.ContextMenu> </Button.ContextMenu>
<Grid> <Grid>
<TextBlock Text="{Binding SelectedModifierType.Description}" <TextBlock Text="{Binding SelectedModifierType.Name}"
Visibility="{Binding SelectedModifierType, Converter={StaticResource NullToVisibilityConverter}}" /> Visibility="{Binding SelectedModifierType, Converter={StaticResource NullToVisibilityConverter}}" />
<TextBlock FontStyle="Italic" <TextBlock FontStyle="Italic"
Visibility="{Binding SelectedModifierType, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted}"> Visibility="{Binding SelectedModifierType, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted}">

View File

@ -4,7 +4,7 @@ using System.Windows.Controls;
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDataBinding namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDataBinding
{ {
/// <summary> /// <summary>
/// Interaction logic for DataBindingModifierView.xaml /// Interaction logic for DataBindingModifierView.xaml
/// </summary> /// </summary>
public partial class DataBindingModifierView : UserControl public partial class DataBindingModifierView : UserControl
{ {

View File

@ -1,7 +1,9 @@
using System; using System;
using System.Linq;
using Artemis.Core; using Artemis.Core;
using Artemis.Core.Services; using Artemis.Core.Services;
using Artemis.UI.Exceptions; using Artemis.UI.Exceptions;
using Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDataBinding.ModifierTypes;
using Artemis.UI.Shared; using Artemis.UI.Shared;
using Artemis.UI.Shared.Input; using Artemis.UI.Shared.Input;
using Artemis.UI.Shared.Services; using Artemis.UI.Shared.Services;
@ -15,6 +17,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa
private readonly IDataModelUIService _dataModelUIService; private readonly IDataModelUIService _dataModelUIService;
private readonly IProfileEditorService _profileEditorService; private readonly IProfileEditorService _profileEditorService;
private DataModelDynamicViewModel _dynamicSelectionViewModel; private DataModelDynamicViewModel _dynamicSelectionViewModel;
private ModifierTypeCategoryViewModel _modifierTypeViewModels;
private DataBindingModifierType _selectedModifierType; private DataBindingModifierType _selectedModifierType;
private DataModelStaticViewModel _staticInputViewModel; private DataModelStaticViewModel _staticInputViewModel;
@ -31,8 +34,6 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa
ShowDataModelValues = settingsService.GetSetting<bool>("ProfileEditor.ShowDataModelValues"); ShowDataModelValues = settingsService.GetSetting<bool>("ProfileEditor.ShowDataModelValues");
Modifier = modifier; Modifier = modifier;
ModifierTypes = new BindableCollection<DataBindingModifierType>();
SelectModifierTypeCommand = new DelegateCommand(ExecuteSelectModifierTypeCommand); SelectModifierTypeCommand = new DelegateCommand(ExecuteSelectModifierTypeCommand);
Update(); Update();
@ -41,7 +42,12 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa
public DelegateCommand SelectModifierTypeCommand { get; } public DelegateCommand SelectModifierTypeCommand { get; }
public PluginSetting<bool> ShowDataModelValues { get; } public PluginSetting<bool> ShowDataModelValues { get; }
public DataBindingModifier<TLayerProperty, TProperty> Modifier { get; } public DataBindingModifier<TLayerProperty, TProperty> Modifier { get; }
public BindableCollection<DataBindingModifierType> ModifierTypes { get; }
public ModifierTypeCategoryViewModel ModifierTypeViewModels
{
get => _modifierTypeViewModels;
set => SetAndNotify(ref _modifierTypeViewModels, value);
}
public DataBindingModifierType SelectedModifierType public DataBindingModifierType SelectedModifierType
{ {
@ -61,6 +67,21 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa
private set => SetAndNotify(ref _staticInputViewModel, value); private set => SetAndNotify(ref _staticInputViewModel, value);
} }
public void Dispose()
{
if (DynamicSelectionViewModel != null)
{
DynamicSelectionViewModel.Dispose();
DynamicSelectionViewModel.PropertySelected -= ParameterSelectionViewModelOnPropertySelected;
}
if (StaticInputViewModel != null)
{
StaticInputViewModel.Dispose();
StaticInputViewModel.ValueUpdated -= StaticInputViewModelOnValueUpdated;
}
}
public void Delete() public void Delete()
{ {
Modifier.DirectDataBinding.RemoveModifier(Modifier); Modifier.DirectDataBinding.RemoveModifier(Modifier);
@ -70,7 +91,10 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa
public void SwapType() public void SwapType()
{ {
if (Modifier.ParameterType == ProfileRightSideType.Dynamic) if (Modifier.ParameterType == ProfileRightSideType.Dynamic)
Modifier.UpdateParameter(Modifier.DirectDataBinding.GetSourceType().GetDefault()); {
var sourceType = Modifier.DirectDataBinding.GetSourceType();
Modifier.UpdateParameter((Modifier.ModifierType.ParameterType ?? sourceType).GetDefault());
}
else else
Modifier.UpdateParameter(null, null); Modifier.UpdateParameter(null, null);
@ -114,24 +138,30 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa
if (DynamicSelectionViewModel != null) if (DynamicSelectionViewModel != null)
{ {
DynamicSelectionViewModel.PropertySelected += ParameterSelectionViewModelOnPropertySelected; DynamicSelectionViewModel.PropertySelected += ParameterSelectionViewModelOnPropertySelected;
DynamicSelectionViewModel.FilterTypes = new[] {sourceType}; DynamicSelectionViewModel.FilterTypes = new[] {Modifier.ModifierType.ParameterType ?? sourceType};
} }
} }
else else
{ {
DynamicSelectionViewModel = null; DynamicSelectionViewModel = null;
if (Modifier.ModifierType.PreferredParameterType != null && sourceType.IsCastableFrom(Modifier.ModifierType.PreferredParameterType)) StaticInputViewModel = _dataModelUIService.GetStaticInputViewModel(Modifier.ModifierType.ParameterType ?? sourceType);
StaticInputViewModel = _dataModelUIService.GetStaticInputViewModel(Modifier.ModifierType.PreferredParameterType);
else
StaticInputViewModel = _dataModelUIService.GetStaticInputViewModel(sourceType);
if (StaticInputViewModel != null) if (StaticInputViewModel != null)
StaticInputViewModel.ValueUpdated += StaticInputViewModelOnValueUpdated; StaticInputViewModel.ValueUpdated += StaticInputViewModelOnValueUpdated;
} }
// Modifier type // Modifier type
ModifierTypes.Clear(); var root = new ModifierTypeCategoryViewModel(null, null);
ModifierTypes.AddRange(_dataBindingService.GetCompatibleModifierTypes(sourceType)); var modifierTypes = _dataBindingService.GetCompatibleModifierTypes(sourceType).GroupBy(t => t.Category);
foreach (var dataBindingModifierTypes in modifierTypes)
{
var viewModels = dataBindingModifierTypes.Select(t => new ModifierTypeViewModel(t));
if (dataBindingModifierTypes.Key == null)
root.Children.AddRange(viewModels);
else
root.Children.Add(new ModifierTypeCategoryViewModel(dataBindingModifierTypes.Key, viewModels));
}
ModifierTypeViewModels = root;
SelectedModifierType = Modifier.ModifierType; SelectedModifierType = Modifier.ModifierType;
// Parameter // Parameter
@ -143,27 +173,13 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa
private void ExecuteSelectModifierTypeCommand(object context) private void ExecuteSelectModifierTypeCommand(object context)
{ {
if (!(context is DataBindingModifierType dataBindingModifierType)) if (!(context is ModifierTypeViewModel modifierTypeViewModel))
return; return;
Modifier.UpdateModifierType(dataBindingModifierType); Modifier.UpdateModifierType(modifierTypeViewModel.ModifierType);
_profileEditorService.UpdateSelectedProfileElement(); _profileEditorService.UpdateSelectedProfileElement();
Update(); Update();
} }
public void Dispose()
{
if (DynamicSelectionViewModel != null)
{
DynamicSelectionViewModel.Dispose();
DynamicSelectionViewModel.PropertySelected -= ParameterSelectionViewModelOnPropertySelected;
}
if (StaticInputViewModel != null)
{
StaticInputViewModel.Dispose();
}
}
} }
} }

View File

@ -16,8 +16,8 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa
private readonly IDataBindingsVmFactory _dataBindingsVmFactory; private readonly IDataBindingsVmFactory _dataBindingsVmFactory;
private readonly IDataModelUIService _dataModelUIService; private readonly IDataModelUIService _dataModelUIService;
private readonly IProfileEditorService _profileEditorService; private readonly IProfileEditorService _profileEditorService;
private DataModelDynamicViewModel _targetSelectionViewModel;
private bool _canAddModifier; private bool _canAddModifier;
private DataModelDynamicViewModel _targetSelectionViewModel;
private bool _updating; private bool _updating;
public DirectDataBindingModeViewModel(DirectDataBinding<TLayerProperty, TProperty> directDataBinding, public DirectDataBindingModeViewModel(DirectDataBinding<TLayerProperty, TProperty> directDataBinding,
@ -38,7 +38,6 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa
public DirectDataBinding<TLayerProperty, TProperty> DirectDataBinding { get; } public DirectDataBinding<TLayerProperty, TProperty> DirectDataBinding { get; }
public BindableCollection<DataBindingModifierViewModel<TLayerProperty, TProperty>> ModifierViewModels { get; } public BindableCollection<DataBindingModifierViewModel<TLayerProperty, TProperty>> ModifierViewModels { get; }
public bool SupportsTestValue => true;
public bool CanAddModifier public bool CanAddModifier
{ {
@ -52,6 +51,8 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa
private set => SetAndNotify(ref _targetSelectionViewModel, value); private set => SetAndNotify(ref _targetSelectionViewModel, value);
} }
public bool SupportsTestValue => true;
public void Update() public void Update()
{ {
TargetSelectionViewModel.PopulateSelectedPropertyViewModel(DirectDataBinding.SourceDataModel, DirectDataBinding.SourcePropertyPath); TargetSelectionViewModel.PopulateSelectedPropertyViewModel(DirectDataBinding.SourceDataModel, DirectDataBinding.SourcePropertyPath);
@ -66,6 +67,21 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa
return TargetSelectionViewModel.SelectedPropertyViewModel?.GetCurrentValue(); return TargetSelectionViewModel.SelectedPropertyViewModel?.GetCurrentValue();
} }
#region IDisposable
public void Dispose()
{
TargetSelectionViewModel.PropertySelected -= TargetSelectionViewModelOnPropertySelected;
TargetSelectionViewModel.Dispose();
DirectDataBinding.ModifiersUpdated -= DirectDataBindingOnModifiersUpdated;
foreach (var dataBindingModifierViewModel in ModifierViewModels)
dataBindingModifierViewModel.Dispose();
ModifierViewModels.Clear();
}
#endregion
private void Initialize() private void Initialize()
{ {
DirectDataBinding.ModifiersUpdated += DirectDataBindingOnModifiersUpdated; DirectDataBinding.ModifiersUpdated += DirectDataBindingOnModifiersUpdated;
@ -142,20 +158,5 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa
} }
#endregion #endregion
#region IDisposable
public void Dispose()
{
TargetSelectionViewModel.PropertySelected -= TargetSelectionViewModelOnPropertySelected;
TargetSelectionViewModel.Dispose();
DirectDataBinding.ModifiersUpdated -= DirectDataBindingOnModifiersUpdated;
foreach (var dataBindingModifierViewModel in ModifierViewModels)
dataBindingModifierViewModel.Dispose();
ModifierViewModels.Clear();
}
#endregion
} }
} }

View File

@ -0,0 +1,6 @@
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDataBinding.ModifierTypes
{
public interface IModifierTypeViewModel
{
}
}

View File

@ -0,0 +1,19 @@
using System.Collections.Generic;
using Stylet;
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDataBinding.ModifierTypes
{
public class ModifierTypeCategoryViewModel : IModifierTypeViewModel
{
public ModifierTypeCategoryViewModel(string category, IEnumerable<IModifierTypeViewModel> children)
{
Category = category;
Children = children == null
? new BindableCollection<IModifierTypeViewModel>()
: new BindableCollection<IModifierTypeViewModel>(children);
}
public string Category { get; set; }
public BindableCollection<IModifierTypeViewModel> Children { get; set; }
}
}

View File

@ -0,0 +1,14 @@
using Artemis.Core;
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDataBinding.ModifierTypes
{
public class ModifierTypeViewModel : IModifierTypeViewModel
{
public ModifierTypeViewModel(DataBindingModifierType modifierType)
{
ModifierType = modifierType;
}
public DataBindingModifierType ModifierType { get; set; }
}
}

View File

@ -5,8 +5,8 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
{ {
public interface IDataBindingModeViewModel : IScreen, IDisposable public interface IDataBindingModeViewModel : IScreen, IDisposable
{ {
void Update();
bool SupportsTestValue { get; } bool SupportsTestValue { get; }
void Update();
object GetTestValue(); object GetTestValue();
} }
} }