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:
parent
a5455c26d6
commit
e2f2f7ca65
@ -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_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_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/=events/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=events_005Cplugins/@EntryIndexedValue">True</s:Boolean>
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -7,8 +7,10 @@ namespace Artemis.Core.DefaultTypes
|
||||
internal class SKColorSumModifierType : DataBindingModifierType
|
||||
{
|
||||
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 Description => "Adds the two colors together";
|
||||
|
||||
public override object Apply(object currentValue, object parameterValue)
|
||||
{
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -5,14 +5,10 @@ namespace Artemis.Core.DefaultTypes
|
||||
{
|
||||
internal class DivideModifierType : DataBindingModifierType
|
||||
{
|
||||
public DivideModifierType()
|
||||
{
|
||||
PreferredParameterType = typeof(float);
|
||||
}
|
||||
|
||||
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 object Apply(object currentValue, object parameterValue)
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -5,14 +5,10 @@ namespace Artemis.Core.DefaultTypes
|
||||
{
|
||||
internal class MultiplicationModifierType : DataBindingModifierType
|
||||
{
|
||||
public MultiplicationModifierType()
|
||||
{
|
||||
PreferredParameterType = typeof(float);
|
||||
}
|
||||
|
||||
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 object Apply(object currentValue, object parameterValue)
|
||||
@ -5,15 +5,12 @@ namespace Artemis.Core.DefaultTypes
|
||||
{
|
||||
internal class PercentageOfModifierType : DataBindingModifierType
|
||||
{
|
||||
public PercentageOfModifierType()
|
||||
{
|
||||
PreferredParameterType = typeof(float);
|
||||
}
|
||||
|
||||
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 Description => "Calculates how much percent the parameter value is of the current value";
|
||||
|
||||
public override object Apply(object currentValue, object parameterValue)
|
||||
{
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -5,15 +5,13 @@ namespace Artemis.Core.DefaultTypes
|
||||
{
|
||||
internal class FloorModifierType : DataBindingModifierType
|
||||
{
|
||||
public FloorModifierType()
|
||||
{
|
||||
SupportsParameter = false;
|
||||
}
|
||||
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
|
||||
public override string Description => "Floor";
|
||||
public override string Icon => "ArrowDownDropCircleOutline";
|
||||
public override bool SupportsParameter => false;
|
||||
|
||||
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)
|
||||
{
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using Artemis.Core.DataModelExpansions;
|
||||
using Artemis.Storage.Entities.Profile.DataBindings;
|
||||
@ -227,16 +226,16 @@ namespace Artemis.Core
|
||||
ParameterDataModel = 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 (staticValue != null && staticValue.GetType() == targetType)
|
||||
if (staticValue != null && staticValue.GetType() == parameterType)
|
||||
ParameterStaticValue = staticValue;
|
||||
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
|
||||
else if (targetType.IsValueType)
|
||||
ParameterStaticValue = Activator.CreateInstance(targetType);
|
||||
else if (parameterType.IsValueType)
|
||||
ParameterStaticValue = Activator.CreateInstance(parameterType);
|
||||
else
|
||||
ParameterStaticValue = null;
|
||||
|
||||
@ -269,18 +268,18 @@ namespace Artemis.Core
|
||||
else if (ParameterType == ProfileRightSideType.Static && Entity.ParameterStaticValue != null && ParameterStaticValue == null)
|
||||
{
|
||||
// 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;
|
||||
|
||||
try
|
||||
{
|
||||
staticValue = JsonConvert.DeserializeObject(Entity.ParameterStaticValue, targetType);
|
||||
staticValue = JsonConvert.DeserializeObject(Entity.ParameterStaticValue, parameterType);
|
||||
}
|
||||
// If deserialization fails, use the type's default
|
||||
catch (JsonSerializationException e)
|
||||
{
|
||||
DeserializationLogger.LogModifierDeserializationFailure(GetType().Name, e);
|
||||
staticValue = Activator.CreateInstance(targetType);
|
||||
staticValue = Activator.CreateInstance(parameterType);
|
||||
}
|
||||
|
||||
UpdateParameter(staticValue);
|
||||
@ -307,7 +306,7 @@ namespace Artemis.Core
|
||||
CompiledParameterAccessor = lambda.Compile();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#region Event handlers
|
||||
|
||||
private void DataBindingModifierTypeStoreOnDataBindingModifierAdded(object sender, DataBindingModifierTypeStoreEvent e)
|
||||
|
||||
@ -21,9 +21,20 @@ namespace Artemis.Core
|
||||
public abstract IReadOnlyCollection<Type> CompatibleTypes { get; }
|
||||
|
||||
/// <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>
|
||||
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>
|
||||
/// Gets or sets the icon of this modifier
|
||||
@ -31,16 +42,15 @@ namespace Artemis.Core
|
||||
public abstract string Icon { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether this modifier supports a parameter, defaults to <c>true</c>
|
||||
/// Gets the description of this modifier
|
||||
/// </summary>
|
||||
public bool SupportsParameter { get; protected set; } = true;
|
||||
public virtual string Description => null;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the preferred parameter type
|
||||
/// <para>If <c>null</c>, the parameter type will match the source property</para>
|
||||
/// Gets the category of this modifier
|
||||
/// </summary>
|
||||
public Type PreferredParameterType { get; protected set; } = null;
|
||||
|
||||
public virtual string Category => null;
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether the given type is supported by the modifier
|
||||
/// </summary>
|
||||
|
||||
@ -42,11 +42,38 @@ namespace Artemis.Core.Services
|
||||
|
||||
private void RegisterBuiltInModifiers()
|
||||
{
|
||||
// Numbers - General
|
||||
RegisterModifierType(Constants.CorePluginInfo, new SumModifierType());
|
||||
RegisterModifierType(Constants.CorePluginInfo, new SubtractModifierType());
|
||||
RegisterModifierType(Constants.CorePluginInfo, new MultiplicationModifierType());
|
||||
RegisterModifierType(Constants.CorePluginInfo, new PercentageOfModifierType());
|
||||
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 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 SKColorBrightenModifierType());
|
||||
RegisterModifierType(Constants.CorePluginInfo, new SKColorDarkenModifierType());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -14,7 +14,7 @@ namespace Artemis.Core
|
||||
lock (Registrations)
|
||||
{
|
||||
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 };
|
||||
Registrations.Add(typeRegistration);
|
||||
@ -29,7 +29,7 @@ namespace Artemis.Core
|
||||
lock (Registrations)
|
||||
{
|
||||
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);
|
||||
typeRegistration.IsInStore = false;
|
||||
@ -56,7 +56,7 @@ namespace Artemis.Core
|
||||
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
|
||||
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();
|
||||
foreach (var displayDataBindingModifier in displayDataBindingModifiers)
|
||||
|
||||
@ -4,8 +4,6 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
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"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800"
|
||||
@ -29,40 +27,35 @@
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
|
||||
<Button Background="{Binding ButtonBrush}"
|
||||
BorderBrush="{Binding ButtonBrush}"
|
||||
Style="{StaticResource DataModelConditionButton}"
|
||||
ToolTip="{Binding SelectedPropertyViewModel.DisplayPropertyPath}"
|
||||
IsEnabled="{Binding IsEnabled}"
|
||||
HorizontalAlignment="Left"
|
||||
Click="PropertyButton_OnClick">
|
||||
<Button.ContextMenu>
|
||||
<ContextMenu ItemsSource="{Binding DataModelViewModel.Children}" IsOpen="{Binding IsDataModelViewModelOpen, Mode=OneWayToSource}">
|
||||
<ContextMenu.ItemContainerStyle>
|
||||
<Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource MaterialDesignMenuItem}">
|
||||
<Setter Property="ItemsSource" Value="{Binding Children}" />
|
||||
<Setter Property="Command" Value="{Binding Data.SelectPropertyCommand, Source={StaticResource DataContextProxy}}" />
|
||||
<Setter Property="CommandParameter" Value="{Binding}" />
|
||||
<Setter Property="CommandTarget" Value="{Binding}" />
|
||||
<Setter Property="IsEnabled" Value="{Binding IsMatchingFilteredTypes}" />
|
||||
<Setter Property="IsSubmenuOpen" Value="{Binding IsVisualizationExpanded, Mode=TwoWay}" />
|
||||
<Setter Property="HeaderTemplate" Value="{StaticResource DataModelDataTemplate}" />
|
||||
</Style>
|
||||
</ContextMenu.ItemContainerStyle>
|
||||
</ContextMenu>
|
||||
</Button.ContextMenu>
|
||||
<Grid>
|
||||
<TextBlock Text="{Binding SelectedPropertyViewModel.PropertyDescription.Name}"
|
||||
Visibility="{Binding SelectedPropertyViewModel, Converter={StaticResource NullToVisibilityConverter}}" />
|
||||
<TextBlock FontStyle="Italic"
|
||||
Visibility="{Binding SelectedPropertyViewModel, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted}">
|
||||
<Run Text="« " /><Run Text="{Binding Placeholder}" /><Run Text=" »" />
|
||||
</TextBlock>
|
||||
</Grid>
|
||||
</Button>
|
||||
|
||||
|
||||
|
||||
|
||||
<Button Background="{Binding ButtonBrush}"
|
||||
BorderBrush="{Binding ButtonBrush}"
|
||||
Style="{StaticResource DataModelConditionButton}"
|
||||
ToolTip="{Binding SelectedPropertyViewModel.DisplayPropertyPath}"
|
||||
IsEnabled="{Binding IsEnabled}"
|
||||
HorizontalAlignment="Left"
|
||||
Click="PropertyButton_OnClick">
|
||||
<Button.ContextMenu>
|
||||
<ContextMenu ItemsSource="{Binding DataModelViewModel.Children}" IsOpen="{Binding IsDataModelViewModelOpen, Mode=OneWayToSource}">
|
||||
<ContextMenu.ItemContainerStyle>
|
||||
<Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource MaterialDesignMenuItem}">
|
||||
<Setter Property="ItemsSource" Value="{Binding Children}" />
|
||||
<Setter Property="Command" Value="{Binding Data.SelectPropertyCommand, Source={StaticResource DataContextProxy}}" />
|
||||
<Setter Property="CommandParameter" Value="{Binding}" />
|
||||
<Setter Property="CommandTarget" Value="{Binding}" />
|
||||
<Setter Property="IsEnabled" Value="{Binding IsMatchingFilteredTypes}" />
|
||||
<Setter Property="IsSubmenuOpen" Value="{Binding IsVisualizationExpanded, Mode=TwoWay}" />
|
||||
<Setter Property="HeaderTemplate" Value="{StaticResource DataModelDataTemplate}" />
|
||||
</Style>
|
||||
</ContextMenu.ItemContainerStyle>
|
||||
</ContextMenu>
|
||||
</Button.ContextMenu>
|
||||
<Grid>
|
||||
<TextBlock Text="{Binding SelectedPropertyViewModel.PropertyDescription.Name}"
|
||||
Visibility="{Binding SelectedPropertyViewModel, Converter={StaticResource NullToVisibilityConverter}}" />
|
||||
<TextBlock FontStyle="Italic"
|
||||
Visibility="{Binding SelectedPropertyViewModel, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted}">
|
||||
<Run Text="« " /><Run Text="{Binding Placeholder}" /><Run Text=" »" />
|
||||
</TextBlock>
|
||||
</Grid>
|
||||
</Button>
|
||||
</UserControl>
|
||||
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Artemis.Core.DataModelExpansions;
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.DataModelExpansions;
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Artemis.Core.DataModelExpansions;
|
||||
using Artemis.UI.Shared.Services;
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Artemis.Core;
|
||||
@ -169,7 +170,7 @@ namespace Artemis.UI.Shared
|
||||
IsMatchingFilteredTypes = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (looseMatch)
|
||||
IsMatchingFilteredTypes = filteredTypes.Any(t => t.IsCastableFrom(PropertyInfo.PropertyType) || t == typeof(Enum) && PropertyInfo.PropertyType.IsEnum);
|
||||
else
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
<UserControl x:Class="Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.ConditionalDataBinding.ConditionalDataBindingModeView"
|
||||
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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
xmlns:dd="urn:gong-wpf-dragdrop" xmlns:Converters="clr-namespace:Artemis.UI.Converters"
|
||||
xmlns:utilities="clr-namespace:Artemis.UI.Utilities"
|
||||
mc:Ignorable="d"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
@ -78,7 +78,7 @@
|
||||
</ListBox.ItemTemplate>
|
||||
<ListBox.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<VirtualizingStackPanel/>
|
||||
<VirtualizingStackPanel />
|
||||
</ItemsPanelTemplate>
|
||||
</ListBox.ItemsPanel>
|
||||
</ListBox>
|
||||
|
||||
@ -11,8 +11,8 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.Conditio
|
||||
{
|
||||
public class ConditionalDataBindingModeViewModel<TLayerProperty, TProperty> : Screen, IDataBindingModeViewModel
|
||||
{
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private readonly IDataBindingsVmFactory _dataBindingsVmFactory;
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private bool _updating;
|
||||
|
||||
public ConditionalDataBindingModeViewModel(ConditionalDataBinding<TLayerProperty, TProperty> conditionalDataBinding,
|
||||
@ -36,12 +36,25 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.Conditio
|
||||
{
|
||||
UpdateConditionViewModels();
|
||||
}
|
||||
|
||||
|
||||
public object GetTestValue()
|
||||
{
|
||||
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)
|
||||
{
|
||||
var condition = ConditionalDataBinding.AddCondition();
|
||||
@ -105,18 +118,5 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.Conditio
|
||||
{
|
||||
UpdateConditionViewModels();
|
||||
}
|
||||
|
||||
#region IDisposable
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
ConditionalDataBinding.ConditionsUpdated -= ConditionalDataBindingOnConditionsUpdated;
|
||||
|
||||
foreach (var conditionViewModel in ConditionViewModels)
|
||||
conditionViewModel.Dispose();
|
||||
ConditionViewModels.Clear();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -32,6 +32,15 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.Conditio
|
||||
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)
|
||||
{
|
||||
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));
|
||||
_profileEditorService.UpdateSelectedProfileElement();
|
||||
}
|
||||
|
||||
public DataBindingCondition<TLayerProperty, TProperty> DataBindingCondition { get; }
|
||||
|
||||
public DataModelStaticViewModel ValueViewModel { get; set; }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
ValueViewModel.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,4 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
{
|
||||
|
||||
@ -12,16 +12,16 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
public class DataBindingViewModel<TLayerProperty, TProperty> : Conductor<IDataBindingModeViewModel>, IDataBindingViewModel
|
||||
{
|
||||
private readonly IDataBindingsVmFactory _dataBindingsVmFactory;
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private readonly IDataModelUIService _dataModelUIService;
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private DataBinding<TLayerProperty, TProperty> _dataBinding;
|
||||
private int _easingTime;
|
||||
private bool _isDataBindingEnabled;
|
||||
private bool _isEasingTimeEnabled;
|
||||
private DataBindingModeType _selectedDataBindingMode;
|
||||
private TimelineEasingViewModel _selectedEasingViewModel;
|
||||
|
||||
private bool _updating;
|
||||
private bool _isDataBindingEnabled;
|
||||
|
||||
public DataBindingViewModel(DataBindingRegistration<TLayerProperty, TProperty> registration,
|
||||
IProfileEditorService profileEditorService,
|
||||
@ -219,9 +219,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
TestResultValue.UpdateValue(Registration.DataBinding != null ? Registration.DataBinding.GetValue(currentValue) : default);
|
||||
}
|
||||
else
|
||||
{
|
||||
TestResultValue.UpdateValue(Registration.DataBinding != null ? Registration.DataBinding.GetValue(default) : default);
|
||||
}
|
||||
}
|
||||
|
||||
private void EnableDataBinding()
|
||||
|
||||
@ -26,6 +26,12 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
set => SetAndNotify(ref _selectedItemIndex, value);
|
||||
}
|
||||
|
||||
protected override void OnClose()
|
||||
{
|
||||
_profileEditorService.SelectedDataBindingChanged -= ProfileEditorServiceOnSelectedDataBindingChanged;
|
||||
base.OnClose();
|
||||
}
|
||||
|
||||
private void CreateDataBindingViewModels()
|
||||
{
|
||||
Items.Clear();
|
||||
@ -44,12 +50,6 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
SelectedItemIndex = 0;
|
||||
}
|
||||
|
||||
protected override void OnClose()
|
||||
{
|
||||
_profileEditorService.SelectedDataBindingChanged -= ProfileEditorServiceOnSelectedDataBindingChanged;
|
||||
base.OnClose();
|
||||
}
|
||||
|
||||
private void ProfileEditorServiceOnSelectedDataBindingChanged(object? sender, EventArgs e)
|
||||
{
|
||||
CreateDataBindingViewModels();
|
||||
|
||||
@ -8,9 +8,9 @@
|
||||
xmlns:converters="clr-namespace:Artemis.UI.Converters"
|
||||
xmlns:utilities="clr-namespace:Artemis.UI.Utilities"
|
||||
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"
|
||||
d:DesignHeight="450" d:DesignWidth="800"
|
||||
d:DataContext="{d:DesignInstance local:DataBindingModifierViewModel}">
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
@ -56,17 +56,33 @@
|
||||
BorderBrush="#7B7B7B"
|
||||
Click="PropertyButton_OnClick">
|
||||
<Button.ContextMenu>
|
||||
<ContextMenu ItemsSource="{Binding ModifierTypes}">
|
||||
<ContextMenu ItemsSource="{Binding ModifierTypeViewModels.Children}">
|
||||
<ContextMenu.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<materialDesign:PackIcon Kind="{Binding Icon}" VerticalAlignment="Center" Margin="0 0 15 0" />
|
||||
<TextBlock Text="{Binding Description}" VerticalAlignment="Center" />
|
||||
<StackPanel>
|
||||
<StackPanel.Resources>
|
||||
<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>
|
||||
</DataTemplate>
|
||||
</ContextMenu.ItemTemplate>
|
||||
<ContextMenu.ItemContainerStyle>
|
||||
<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="CommandParameter" Value="{Binding}" />
|
||||
<Setter Property="CommandTarget" Value="{Binding}" />
|
||||
@ -75,14 +91,14 @@
|
||||
</ContextMenu>
|
||||
</Button.ContextMenu>
|
||||
<Grid>
|
||||
<TextBlock Text="{Binding SelectedModifierType.Description}"
|
||||
<TextBlock Text="{Binding SelectedModifierType.Name}"
|
||||
Visibility="{Binding SelectedModifierType, Converter={StaticResource NullToVisibilityConverter}}" />
|
||||
<TextBlock FontStyle="Italic"
|
||||
Visibility="{Binding SelectedModifierType, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted}">
|
||||
« Select a modifier »
|
||||
</TextBlock>
|
||||
</Grid>
|
||||
|
||||
|
||||
</Button>
|
||||
|
||||
<ContentControl Grid.Column="3" s:View.Model="{Binding DynamicSelectionViewModel}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" IsTabStop="False" />
|
||||
|
||||
@ -4,7 +4,7 @@ using System.Windows.Controls;
|
||||
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDataBinding
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for DataBindingModifierView.xaml
|
||||
/// Interaction logic for DataBindingModifierView.xaml
|
||||
/// </summary>
|
||||
public partial class DataBindingModifierView : UserControl
|
||||
{
|
||||
@ -23,4 +23,4 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Exceptions;
|
||||
using Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDataBinding.ModifierTypes;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Input;
|
||||
using Artemis.UI.Shared.Services;
|
||||
@ -15,6 +17,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa
|
||||
private readonly IDataModelUIService _dataModelUIService;
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private DataModelDynamicViewModel _dynamicSelectionViewModel;
|
||||
private ModifierTypeCategoryViewModel _modifierTypeViewModels;
|
||||
private DataBindingModifierType _selectedModifierType;
|
||||
private DataModelStaticViewModel _staticInputViewModel;
|
||||
|
||||
@ -31,8 +34,6 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa
|
||||
ShowDataModelValues = settingsService.GetSetting<bool>("ProfileEditor.ShowDataModelValues");
|
||||
|
||||
Modifier = modifier;
|
||||
ModifierTypes = new BindableCollection<DataBindingModifierType>();
|
||||
|
||||
SelectModifierTypeCommand = new DelegateCommand(ExecuteSelectModifierTypeCommand);
|
||||
|
||||
Update();
|
||||
@ -41,7 +42,12 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa
|
||||
public DelegateCommand SelectModifierTypeCommand { get; }
|
||||
public PluginSetting<bool> ShowDataModelValues { 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
|
||||
{
|
||||
@ -61,6 +67,21 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa
|
||||
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()
|
||||
{
|
||||
Modifier.DirectDataBinding.RemoveModifier(Modifier);
|
||||
@ -70,7 +91,10 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa
|
||||
public void SwapType()
|
||||
{
|
||||
if (Modifier.ParameterType == ProfileRightSideType.Dynamic)
|
||||
Modifier.UpdateParameter(Modifier.DirectDataBinding.GetSourceType().GetDefault());
|
||||
{
|
||||
var sourceType = Modifier.DirectDataBinding.GetSourceType();
|
||||
Modifier.UpdateParameter((Modifier.ModifierType.ParameterType ?? sourceType).GetDefault());
|
||||
}
|
||||
else
|
||||
Modifier.UpdateParameter(null, null);
|
||||
|
||||
@ -114,24 +138,30 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa
|
||||
if (DynamicSelectionViewModel != null)
|
||||
{
|
||||
DynamicSelectionViewModel.PropertySelected += ParameterSelectionViewModelOnPropertySelected;
|
||||
DynamicSelectionViewModel.FilterTypes = new[] {sourceType};
|
||||
DynamicSelectionViewModel.FilterTypes = new[] {Modifier.ModifierType.ParameterType ?? sourceType};
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DynamicSelectionViewModel = null;
|
||||
if (Modifier.ModifierType.PreferredParameterType != null && sourceType.IsCastableFrom(Modifier.ModifierType.PreferredParameterType))
|
||||
StaticInputViewModel = _dataModelUIService.GetStaticInputViewModel(Modifier.ModifierType.PreferredParameterType);
|
||||
else
|
||||
StaticInputViewModel = _dataModelUIService.GetStaticInputViewModel(sourceType);
|
||||
|
||||
StaticInputViewModel = _dataModelUIService.GetStaticInputViewModel(Modifier.ModifierType.ParameterType ?? sourceType);
|
||||
if (StaticInputViewModel != null)
|
||||
StaticInputViewModel.ValueUpdated += StaticInputViewModelOnValueUpdated;
|
||||
}
|
||||
|
||||
// Modifier type
|
||||
ModifierTypes.Clear();
|
||||
ModifierTypes.AddRange(_dataBindingService.GetCompatibleModifierTypes(sourceType));
|
||||
var root = new ModifierTypeCategoryViewModel(null, null);
|
||||
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;
|
||||
|
||||
// Parameter
|
||||
@ -143,27 +173,13 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa
|
||||
|
||||
private void ExecuteSelectModifierTypeCommand(object context)
|
||||
{
|
||||
if (!(context is DataBindingModifierType dataBindingModifierType))
|
||||
if (!(context is ModifierTypeViewModel modifierTypeViewModel))
|
||||
return;
|
||||
|
||||
Modifier.UpdateModifierType(dataBindingModifierType);
|
||||
Modifier.UpdateModifierType(modifierTypeViewModel.ModifierType);
|
||||
_profileEditorService.UpdateSelectedProfileElement();
|
||||
|
||||
Update();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (DynamicSelectionViewModel != null)
|
||||
{
|
||||
DynamicSelectionViewModel.Dispose();
|
||||
DynamicSelectionViewModel.PropertySelected -= ParameterSelectionViewModelOnPropertySelected;
|
||||
}
|
||||
|
||||
if (StaticInputViewModel != null)
|
||||
{
|
||||
StaticInputViewModel.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -19,8 +19,8 @@
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<ContentControl Grid.Row="0"
|
||||
s:View.Model="{Binding TargetSelectionViewModel}"
|
||||
VerticalContentAlignment="Stretch"
|
||||
s:View.Model="{Binding TargetSelectionViewModel}"
|
||||
VerticalContentAlignment="Stretch"
|
||||
HorizontalContentAlignment="Stretch"
|
||||
IsTabStop="False" />
|
||||
|
||||
|
||||
@ -16,8 +16,8 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa
|
||||
private readonly IDataBindingsVmFactory _dataBindingsVmFactory;
|
||||
private readonly IDataModelUIService _dataModelUIService;
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private DataModelDynamicViewModel _targetSelectionViewModel;
|
||||
private bool _canAddModifier;
|
||||
private DataModelDynamicViewModel _targetSelectionViewModel;
|
||||
private bool _updating;
|
||||
|
||||
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 BindableCollection<DataBindingModifierViewModel<TLayerProperty, TProperty>> ModifierViewModels { get; }
|
||||
public bool SupportsTestValue => true;
|
||||
|
||||
public bool CanAddModifier
|
||||
{
|
||||
@ -52,6 +51,8 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa
|
||||
private set => SetAndNotify(ref _targetSelectionViewModel, value);
|
||||
}
|
||||
|
||||
public bool SupportsTestValue => true;
|
||||
|
||||
public void Update()
|
||||
{
|
||||
TargetSelectionViewModel.PopulateSelectedPropertyViewModel(DirectDataBinding.SourceDataModel, DirectDataBinding.SourcePropertyPath);
|
||||
@ -66,6 +67,21 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa
|
||||
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()
|
||||
{
|
||||
DirectDataBinding.ModifiersUpdated += DirectDataBindingOnModifiersUpdated;
|
||||
@ -110,7 +126,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa
|
||||
DirectDataBinding.AddModifier(ProfileRightSideType.Dynamic);
|
||||
_profileEditorService.UpdateSelectedProfileElement();
|
||||
}
|
||||
|
||||
|
||||
private void UpdateModifierViewModels()
|
||||
{
|
||||
_updating = true;
|
||||
@ -142,20 +158,5 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IDisposable
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
TargetSelectionViewModel.PropertySelected -= TargetSelectionViewModelOnPropertySelected;
|
||||
TargetSelectionViewModel.Dispose();
|
||||
DirectDataBinding.ModifiersUpdated -= DirectDataBindingOnModifiersUpdated;
|
||||
|
||||
foreach (var dataBindingModifierViewModel in ModifierViewModels)
|
||||
dataBindingModifierViewModel.Dispose();
|
||||
ModifierViewModels.Clear();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,6 @@
|
||||
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDataBinding.ModifierTypes
|
||||
{
|
||||
public interface IModifierTypeViewModel
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -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; }
|
||||
}
|
||||
}
|
||||
@ -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; }
|
||||
}
|
||||
}
|
||||
@ -5,8 +5,8 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
{
|
||||
public interface IDataBindingModeViewModel : IScreen, IDisposable
|
||||
{
|
||||
void Update();
|
||||
bool SupportsTestValue { get; }
|
||||
void Update();
|
||||
object GetTestValue();
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user