mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-31 09:43:46 +00:00
Data bindings - Further implemented default converters
This commit is contained in:
parent
aebe3005e7
commit
6b309cb1f3
@ -3,40 +3,46 @@
|
|||||||
namespace Artemis.Core
|
namespace Artemis.Core
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public class FloatDataBindingConverter : IDataBindingConverter
|
public class FloatDataBindingConverter : DataBindingConverter
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
public FloatDataBindingConverter()
|
||||||
public Type SupportedType => typeof(float);
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public bool SupportsSum => true;
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public bool SupportsInterpolate => true;
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public object Sum(BaseLayerProperty layerProperty, object a, object b)
|
|
||||||
{
|
{
|
||||||
return (float) a + (float) b;
|
SupportedType = typeof(float);
|
||||||
|
SupportsSum = true;
|
||||||
|
SupportsInterpolate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public object Interpolate(BaseLayerProperty layerProperty, object a, object b, float progress)
|
public override object Sum(object a, object b)
|
||||||
{
|
{
|
||||||
var diff = (float) b - (float) a;
|
return Convert.ToSingle(a) + Convert.ToSingle(b);
|
||||||
return diff * progress;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void ApplyValue(BaseLayerProperty layerProperty, object value)
|
public override object Interpolate(object a, object b, double progress)
|
||||||
{
|
{
|
||||||
layerProperty.CurrentValue = value;
|
var floatA = Convert.ToSingle(a);
|
||||||
|
var floatB = Convert.ToSingle(b);
|
||||||
|
var diff = floatB - floatA;
|
||||||
|
return floatA + diff * progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public object GetValue(BaseLayerProperty layerProperty)
|
public override void ApplyValue(object value)
|
||||||
{
|
{
|
||||||
return layerProperty.CurrentValue;
|
var floatValue = Convert.ToSingle(value);
|
||||||
|
if (DataBinding.LayerProperty.PropertyDescription.MaxInputValue is float max)
|
||||||
|
floatValue = Math.Min(floatValue, max);
|
||||||
|
if (DataBinding.LayerProperty.PropertyDescription.MinInputValue is float min)
|
||||||
|
floatValue = Math.Max(floatValue, min);
|
||||||
|
|
||||||
|
ValueSetter?.Invoke(floatValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override object GetValue()
|
||||||
|
{
|
||||||
|
return ValueGetter?.Invoke();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3,39 +3,37 @@
|
|||||||
namespace Artemis.Core
|
namespace Artemis.Core
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public class GeneralDataBindingConverter : IDataBindingConverter
|
public class GeneralDataBindingConverter : DataBindingConverter
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
public GeneralDataBindingConverter()
|
||||||
public Type SupportedType => typeof(object);
|
{
|
||||||
|
SupportedType = typeof(object);
|
||||||
|
SupportsSum = false;
|
||||||
|
SupportsInterpolate = false;
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool SupportsSum => false;
|
public override object Sum(object a, object b)
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public bool SupportsInterpolate => false;
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public object Sum(BaseLayerProperty layerProperty, object a, object b)
|
|
||||||
{
|
{
|
||||||
throw new NotSupportedException();
|
throw new NotSupportedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public object Interpolate(BaseLayerProperty layerProperty, object a, object b, float progress)
|
public override object Interpolate(object a, object b, double progress)
|
||||||
{
|
{
|
||||||
throw new NotSupportedException();
|
throw new NotSupportedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void ApplyValue(BaseLayerProperty layerProperty, object value)
|
public override void ApplyValue(object value)
|
||||||
{
|
{
|
||||||
layerProperty.CurrentValue = value;
|
ValueSetter?.Invoke(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public object GetValue(BaseLayerProperty layerProperty)
|
public override object GetValue()
|
||||||
{
|
{
|
||||||
return layerProperty.CurrentValue;
|
return ValueGetter?.Invoke();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3,40 +3,46 @@
|
|||||||
namespace Artemis.Core
|
namespace Artemis.Core
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public class IntDataBindingConverter : IDataBindingConverter
|
public class IntDataBindingConverter : DataBindingConverter
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
public IntDataBindingConverter()
|
||||||
public Type SupportedType => typeof(int);
|
{
|
||||||
|
SupportedType = typeof(int);
|
||||||
|
SupportsSum = true;
|
||||||
|
SupportsInterpolate = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the <see cref="MidpointRounding" /> mode used for rounding during interpolation. Defaults to
|
||||||
|
/// <see cref="MidpointRounding.AwayFromZero" />
|
||||||
|
/// </summary>
|
||||||
|
public MidpointRounding InterpolationRoundingMode { get; set; } = MidpointRounding.AwayFromZero;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool SupportsSum => true;
|
public override object Sum(object a, object b)
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public bool SupportsInterpolate => true;
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public object Sum(BaseLayerProperty layerProperty, object a, object b)
|
|
||||||
{
|
{
|
||||||
return (int) a + (int) b;
|
return (int) a + (int) b;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public object Interpolate(BaseLayerProperty layerProperty, object a, object b, float progress)
|
public override object Interpolate(object a, object b, double progress)
|
||||||
{
|
{
|
||||||
var diff = (int) b - (int) a;
|
var intA = (int) a;
|
||||||
return diff * progress;
|
var intB = (int) b;
|
||||||
|
var diff = intB - intA;
|
||||||
|
return (int) Math.Round(intA + diff * progress, InterpolationRoundingMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void ApplyValue(BaseLayerProperty layerProperty, object value)
|
public override void ApplyValue(object value)
|
||||||
{
|
{
|
||||||
layerProperty.CurrentValue = value;
|
ValueSetter?.Invoke(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public object GetValue(BaseLayerProperty layerProperty)
|
public override object GetValue()
|
||||||
{
|
{
|
||||||
return layerProperty.CurrentValue;
|
return ValueGetter?.Invoke();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4,52 +4,41 @@ using SkiaSharp;
|
|||||||
namespace Artemis.Core
|
namespace Artemis.Core
|
||||||
{
|
{
|
||||||
// This is internal because it's mainly a proof-of-concept
|
// This is internal because it's mainly a proof-of-concept
|
||||||
internal class SKColorPartDataBindingConverter : IDataBindingConverter
|
internal class SKColorPartDataBindingConverter : DataBindingConverter
|
||||||
{
|
{
|
||||||
private readonly Channel _channel;
|
private readonly Channel _channel;
|
||||||
|
|
||||||
public SKColorPartDataBindingConverter(Channel channel)
|
public SKColorPartDataBindingConverter(Channel channel)
|
||||||
{
|
{
|
||||||
_channel = channel;
|
_channel = channel;
|
||||||
}
|
|
||||||
|
|
||||||
// This depends on what channel was passed
|
SupportsSum = true;
|
||||||
public Type SupportedType
|
SupportsInterpolate = true;
|
||||||
{
|
SupportedType = _channel switch
|
||||||
get
|
|
||||||
{
|
{
|
||||||
switch (_channel)
|
Channel.Alpha => typeof(byte),
|
||||||
{
|
Channel.Red => typeof(byte),
|
||||||
case Channel.Alpha:
|
Channel.Green => typeof(byte),
|
||||||
case Channel.Red:
|
Channel.Blue => typeof(byte),
|
||||||
case Channel.Green:
|
Channel.Hue => typeof(float),
|
||||||
case Channel.Blue:
|
_ => throw new ArgumentOutOfRangeException()
|
||||||
return typeof(byte);
|
};
|
||||||
case Channel.Hue:
|
|
||||||
return typeof(float);
|
|
||||||
default:
|
|
||||||
throw new ArgumentOutOfRangeException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool SupportsSum => true;
|
public override object Sum(object a, object b)
|
||||||
public bool SupportsInterpolate => true;
|
|
||||||
|
|
||||||
public object Sum(BaseLayerProperty layerProperty, object a, object b)
|
|
||||||
{
|
{
|
||||||
return (float) a + (float) b;
|
return (float) a + (float) b;
|
||||||
}
|
}
|
||||||
|
|
||||||
public object Interpolate(BaseLayerProperty layerProperty, object a, object b, float progress)
|
public override object Interpolate(object a, object b, double progress)
|
||||||
{
|
{
|
||||||
var diff = (float) b - (float) a;
|
var diff = (float) b - (float) a;
|
||||||
return diff * progress;
|
return diff * progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ApplyValue(BaseLayerProperty layerProperty, object value)
|
public override void ApplyValue(object value)
|
||||||
{
|
{
|
||||||
var property = (SKColorLayerProperty) layerProperty;
|
var property = (SKColorLayerProperty) DataBinding.LayerProperty;
|
||||||
switch (_channel)
|
switch (_channel)
|
||||||
{
|
{
|
||||||
case Channel.Alpha:
|
case Channel.Alpha:
|
||||||
@ -73,9 +62,9 @@ namespace Artemis.Core
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public object GetValue(BaseLayerProperty layerProperty)
|
public override object GetValue()
|
||||||
{
|
{
|
||||||
var property = (SKColorLayerProperty) layerProperty;
|
var property = (SKColorLayerProperty) DataBinding.LayerProperty;
|
||||||
switch (_channel)
|
switch (_channel)
|
||||||
{
|
{
|
||||||
case Channel.Alpha:
|
case Channel.Alpha:
|
||||||
|
|||||||
@ -15,11 +15,11 @@ namespace Artemis.Core
|
|||||||
public class DataBinding
|
public class DataBinding
|
||||||
{
|
{
|
||||||
private readonly List<DataBindingModifier> _modifiers = new List<DataBindingModifier>();
|
private readonly List<DataBindingModifier> _modifiers = new List<DataBindingModifier>();
|
||||||
private bool _isInitialized;
|
|
||||||
|
|
||||||
private object _currentValue;
|
private object _currentValue;
|
||||||
|
private bool _isInitialized;
|
||||||
private object _previousValue;
|
private object _previousValue;
|
||||||
private float _easingProgress;
|
private TimeSpan _easingProgress;
|
||||||
|
|
||||||
internal DataBinding(DataBindingRegistration dataBindingRegistration)
|
internal DataBinding(DataBindingRegistration dataBindingRegistration)
|
||||||
{
|
{
|
||||||
@ -38,30 +38,23 @@ namespace Artemis.Core
|
|||||||
ApplyToDataBinding();
|
ApplyToDataBinding();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ApplyRegistration(DataBindingRegistration dataBindingRegistration)
|
|
||||||
{
|
|
||||||
Converter = dataBindingRegistration.Converter;
|
|
||||||
Registration = dataBindingRegistration;
|
|
||||||
TargetProperty = dataBindingRegistration.Property;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the layer property this data binding targets
|
/// Gets the layer property this data binding targets
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public BaseLayerProperty LayerProperty { get; }
|
public BaseLayerProperty LayerProperty { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the data binding registration this data binding is based upon
|
/// Gets the data binding registration this data binding is based upon
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DataBindingRegistration Registration { get; private set; }
|
public DataBindingRegistration Registration { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the converter used to apply this data binding to the <see cref="LayerProperty"/>
|
/// Gets the converter used to apply this data binding to the <see cref="LayerProperty" />
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IDataBindingConverter Converter { get; private set; }
|
public DataBindingConverter Converter { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the property on the <see cref="LayerProperty"/> this data binding targets
|
/// Gets the property on the <see cref="LayerProperty" /> this data binding targets
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public PropertyInfo TargetProperty { get; private set; }
|
public PropertyInfo TargetProperty { get; private set; }
|
||||||
|
|
||||||
@ -167,21 +160,32 @@ namespace Artemis.Core
|
|||||||
var value = Convert.ChangeType(dataBindingValue, TargetProperty.PropertyType);
|
var value = Convert.ChangeType(dataBindingValue, TargetProperty.PropertyType);
|
||||||
|
|
||||||
// If no easing is to be applied simple return whatever the current value is
|
// If no easing is to be applied simple return whatever the current value is
|
||||||
if (EasingTime == TimeSpan.Zero || Converter.SupportsInterpolate)
|
if (EasingTime == TimeSpan.Zero || !Converter.SupportsInterpolate)
|
||||||
return value;
|
return value;
|
||||||
|
|
||||||
// If the value changed, update the current and previous values used for easing
|
// If the value changed, update the current and previous values used for easing
|
||||||
if (!Equals(value, _currentValue))
|
if (!Equals(value, _currentValue))
|
||||||
{
|
ResetEasing(value);
|
||||||
_previousValue = GetInterpolatedValue();
|
|
||||||
_currentValue = value;
|
|
||||||
_easingProgress = 0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply interpolation between the previous and current value
|
// Apply interpolation between the previous and current value
|
||||||
return GetInterpolatedValue();
|
return GetInterpolatedValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ResetEasing(object value)
|
||||||
|
{
|
||||||
|
_previousValue = GetInterpolatedValue();
|
||||||
|
_currentValue = value;
|
||||||
|
_easingProgress = TimeSpan.Zero;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the type of the target property of this data binding
|
||||||
|
/// </summary>
|
||||||
|
public Type GetTargetType()
|
||||||
|
{
|
||||||
|
return TargetProperty.PropertyType;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the type of the source property of this data binding
|
/// Returns the type of the source property of this data binding
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -191,21 +195,26 @@ namespace Artemis.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates the smoothing progress of the data binding
|
/// Updates the smoothing progress of the data binding
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="deltaTime"></param>
|
/// <param name="deltaTime">The time in seconds that passed since the last update</param>
|
||||||
public void Update(double deltaTime)
|
public void Update(double deltaTime)
|
||||||
{
|
{
|
||||||
|
_easingProgress = _easingProgress.Add(TimeSpan.FromSeconds(deltaTime));
|
||||||
|
if (_easingProgress > EasingTime)
|
||||||
|
_easingProgress = EasingTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates the value on the <see cref="LayerProperty"/> according to the data binding
|
/// Updates the value on the <see cref="LayerProperty" /> according to the data binding
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void ApplyToProperty()
|
public void ApplyToProperty()
|
||||||
{
|
{
|
||||||
var value = GetValue(Converter.GetValue(LayerProperty));
|
if (Converter == null)
|
||||||
Converter.ApplyValue(LayerProperty, GetValue(value));
|
return;
|
||||||
|
|
||||||
|
var value = GetValue(Converter.GetValue());
|
||||||
|
Converter.ApplyValue(GetValue(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void ApplyToEntity()
|
internal void ApplyToEntity()
|
||||||
@ -232,8 +241,7 @@ namespace Artemis.Core
|
|||||||
internal void ApplyToDataBinding()
|
internal void ApplyToDataBinding()
|
||||||
{
|
{
|
||||||
// General
|
// General
|
||||||
Registration = LayerProperty.DataBindingRegistrations.FirstOrDefault(p => p.Property.Name == Entity.TargetProperty);
|
ApplyRegistration(LayerProperty.DataBindingRegistrations.FirstOrDefault(p => p.Property.Name == Entity.TargetProperty));
|
||||||
TargetProperty = Registration?.Property;
|
|
||||||
|
|
||||||
Mode = (DataBindingMode) Entity.DataBindingMode;
|
Mode = (DataBindingMode) Entity.DataBindingMode;
|
||||||
EasingTime = Entity.EasingTime;
|
EasingTime = Entity.EasingTime;
|
||||||
@ -266,14 +274,33 @@ namespace Artemis.Core
|
|||||||
_isInitialized = true;
|
_isInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ApplyRegistration(DataBindingRegistration dataBindingRegistration)
|
||||||
|
{
|
||||||
|
if (dataBindingRegistration != null)
|
||||||
|
dataBindingRegistration.DataBinding = this;
|
||||||
|
|
||||||
|
Converter = dataBindingRegistration?.Converter;
|
||||||
|
Registration = dataBindingRegistration;
|
||||||
|
TargetProperty = dataBindingRegistration?.Property;
|
||||||
|
|
||||||
|
if (GetTargetType().IsValueType)
|
||||||
|
{
|
||||||
|
if (_currentValue == null)
|
||||||
|
_currentValue = GetTargetType().GetDefault();
|
||||||
|
if (_previousValue == null)
|
||||||
|
_previousValue = _currentValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Converter?.Initialize(this);
|
||||||
|
}
|
||||||
|
|
||||||
private object GetInterpolatedValue()
|
private object GetInterpolatedValue()
|
||||||
{
|
{
|
||||||
if (_easingProgress == 0f)
|
if (_easingProgress == EasingTime || !Converter.SupportsInterpolate)
|
||||||
return _previousValue;
|
|
||||||
if (_easingProgress == 1f || !Converter.SupportsInterpolate)
|
|
||||||
return _currentValue;
|
return _currentValue;
|
||||||
|
|
||||||
return Converter.Interpolate(LayerProperty, _previousValue, _currentValue, _easingProgress);
|
var easingAmount = _easingProgress.TotalSeconds / EasingTime.TotalSeconds;
|
||||||
|
return Converter.Interpolate(_previousValue, _currentValue, Easings.Interpolate(easingAmount, EasingFunction));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreateExpression()
|
private void CreateExpression()
|
||||||
|
|||||||
@ -0,0 +1,121 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace Artemis.Core
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A data binding converter that acts as the bridge between a <see cref="DataBinding" /> and a
|
||||||
|
/// <see cref="LayerProperty{T}" />
|
||||||
|
/// </summary>
|
||||||
|
public abstract class DataBindingConverter
|
||||||
|
{
|
||||||
|
internal Func<object> ValueGetter { get; set; }
|
||||||
|
internal Action<object> ValueSetter { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the data binding this converter is applied to
|
||||||
|
/// </summary>
|
||||||
|
public DataBinding DataBinding { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the type this converter supports
|
||||||
|
/// </summary>
|
||||||
|
public Type SupportedType { get; protected set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets whether or not this data binding converter supports the <see cref="Sum" /> method
|
||||||
|
/// </summary>
|
||||||
|
public bool SupportsSum { get; protected set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets whether or not this data binding converter supports the <see cref="Interpolate" /> method
|
||||||
|
/// </summary>
|
||||||
|
public bool SupportsInterpolate { get; protected set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called when the data binding converter has been initialized and the <see cref="DataBinding" /> is available
|
||||||
|
/// </summary>
|
||||||
|
protected virtual void OnInitialized()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the sum of <paramref name="a" /> and <paramref name="b" />
|
||||||
|
/// </summary>
|
||||||
|
public abstract object Sum(object a, object b);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the the interpolated value between <paramref name="a" /> and <paramref name="b" /> on a scale (generally)
|
||||||
|
/// between <c>0.0</c> and <c>1.0</c> defined by the <paramref name="progress" />
|
||||||
|
/// <para>Note: The progress may go be negative or go beyond <c>1.0</c> depending on the easing method used</para>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="a">The value to interpolate away from</param>
|
||||||
|
/// <param name="b">The value to interpolate towards</param>
|
||||||
|
/// <param name="progress">The progress of the interpolation between 0.0 and 1.0</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public abstract object Interpolate(object a, object b, double progress);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Applies the <paramref name="value" /> to the layer property
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
public abstract void ApplyValue(object value);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the current base value of the data binding
|
||||||
|
/// </summary>
|
||||||
|
public abstract object GetValue();
|
||||||
|
|
||||||
|
internal void Initialize(DataBinding dataBinding)
|
||||||
|
{
|
||||||
|
DataBinding = dataBinding;
|
||||||
|
ValueGetter = CreateValueGetter();
|
||||||
|
ValueSetter = CreateValueSetter();
|
||||||
|
|
||||||
|
OnInitialized();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Func<object> CreateValueGetter()
|
||||||
|
{
|
||||||
|
if (DataBinding.TargetProperty?.DeclaringType == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var getterMethod = DataBinding.TargetProperty.GetGetMethod();
|
||||||
|
if (getterMethod == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var constant = Expression.Constant(DataBinding.LayerProperty);
|
||||||
|
// The path is null if the registration is applied to the root (LayerProperty.CurrentValue)
|
||||||
|
var property = DataBinding.Registration.Path == null
|
||||||
|
? Expression.Property(constant, DataBinding.TargetProperty)
|
||||||
|
: (MemberExpression) DataBinding.Registration.Path.Split('.').Aggregate<string, Expression>(constant, Expression.Property);
|
||||||
|
|
||||||
|
// The get method should cast to the object since it receives whatever type the property is
|
||||||
|
var body = Expression.Convert(property, typeof(object));
|
||||||
|
var lambda = Expression.Lambda<Func<object>>(body);
|
||||||
|
|
||||||
|
return lambda.Compile();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Action<object> CreateValueSetter()
|
||||||
|
{
|
||||||
|
if (DataBinding.TargetProperty?.DeclaringType == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var setterMethod = DataBinding.TargetProperty.GetSetMethod();
|
||||||
|
if (setterMethod == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var constant = Expression.Constant(DataBinding.LayerProperty);
|
||||||
|
var propertyValue = Expression.Parameter(typeof(object), "propertyValue");
|
||||||
|
|
||||||
|
// The assign method should cast to the proper type since it receives an object
|
||||||
|
var body = Expression.Call(constant, setterMethod, Expression.Convert(propertyValue, DataBinding.TargetProperty.PropertyType));
|
||||||
|
var lambda = Expression.Lambda<Action<object>>(body, propertyValue);
|
||||||
|
return lambda.Compile();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -102,7 +102,7 @@ namespace Artemis.Core
|
|||||||
return ModifierType.Apply(currentValue, value);
|
return ModifierType.Apply(currentValue, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ParameterType == ProfileRightSideType.Static)
|
if (ParameterType == ProfileRightSideType.Static && ModifierType != null)
|
||||||
return ModifierType.Apply(currentValue, ParameterStaticValue);
|
return ModifierType.Apply(currentValue, ParameterStaticValue);
|
||||||
|
|
||||||
return currentValue;
|
return currentValue;
|
||||||
|
|||||||
@ -5,15 +5,18 @@ namespace Artemis.Core
|
|||||||
{
|
{
|
||||||
public class DataBindingRegistration
|
public class DataBindingRegistration
|
||||||
{
|
{
|
||||||
internal DataBindingRegistration(BaseLayerProperty layerProperty, PropertyInfo property, IDataBindingConverter converter)
|
internal DataBindingRegistration(BaseLayerProperty layerProperty, PropertyInfo property, DataBindingConverter converter, string path)
|
||||||
{
|
{
|
||||||
LayerProperty = layerProperty ?? throw new ArgumentNullException(nameof(layerProperty));
|
LayerProperty = layerProperty ?? throw new ArgumentNullException(nameof(layerProperty));
|
||||||
Property = property ?? throw new ArgumentNullException(nameof(property));
|
Property = property ?? throw new ArgumentNullException(nameof(property));
|
||||||
Converter = converter ?? throw new ArgumentNullException(nameof(converter));
|
Converter = converter ?? throw new ArgumentNullException(nameof(converter));
|
||||||
|
Path = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BaseLayerProperty LayerProperty { get; set; }
|
public DataBinding DataBinding { get; internal set; }
|
||||||
public PropertyInfo Property { get; set; }
|
public BaseLayerProperty LayerProperty { get; }
|
||||||
public IDataBindingConverter Converter { get; set; }
|
public PropertyInfo Property { get; }
|
||||||
|
public DataBindingConverter Converter { get; }
|
||||||
|
public string Path { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,57 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace Artemis.Core
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// A data binding converter that acts as the bridge between a <see cref="DataBinding" /> and a
|
|
||||||
/// <see cref="LayerProperty{T}" />
|
|
||||||
/// </summary>
|
|
||||||
public interface IDataBindingConverter
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the type this converter supports
|
|
||||||
/// </summary>
|
|
||||||
Type SupportedType { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets whether or not this data binding converter supports the <see cref="Sum" /> method
|
|
||||||
/// </summary>
|
|
||||||
bool SupportsSum { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets whether or not this data binding converter supports the <see cref="Interpolate" /> method
|
|
||||||
/// </summary>
|
|
||||||
bool SupportsInterpolate { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns the sum of <paramref name="a" /> and <paramref name="b" />
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="layerProperty">The layer property this sum is done for</param>
|
|
||||||
object Sum(BaseLayerProperty layerProperty, object a, object b);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns the the interpolated value between <paramref name="a" /> and <paramref name="b" /> on a scale (generally)
|
|
||||||
/// between <c>0.0</c> and <c>1.0</c> defined by the <paramref name="progress" />
|
|
||||||
/// <para>Note: The progress may go be negative or go beyond <c>1.0</c> depending on the easing method used</para>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="layerProperty">The layer property this interpolation is done for</param>
|
|
||||||
/// <param name="a">The value to interpolate away from</param>
|
|
||||||
/// <param name="b">The value to interpolate towards</param>
|
|
||||||
/// <param name="progress">The progress of the interpolation between 0.0 and 1.0</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
object Interpolate(BaseLayerProperty layerProperty, object a, object b, float progress);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Applies the <paramref name="value" /> to the layer property
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="layerProperty">The layer property this value is to be applied to</param>
|
|
||||||
/// <param name="value"></param>
|
|
||||||
void ApplyValue(BaseLayerProperty layerProperty, object value);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns the current base value of the data binding
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="layerProperty">The layer property this value must be retrieved from</param>
|
|
||||||
object GetValue(BaseLayerProperty layerProperty);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -32,7 +32,7 @@ namespace Artemis.Core
|
|||||||
get => _baseValue;
|
get => _baseValue;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value.GetType() != GetPropertyType())
|
if (value != null && value.GetType() != GetPropertyType())
|
||||||
throw new ArtemisCoreException("Cannot update base value because of a type mismatch");
|
throw new ArtemisCoreException("Cannot update base value because of a type mismatch");
|
||||||
_baseValue = value;
|
_baseValue = value;
|
||||||
}
|
}
|
||||||
@ -46,7 +46,7 @@ namespace Artemis.Core
|
|||||||
get => _currentValue;
|
get => _currentValue;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value.GetType() != GetPropertyType())
|
if (value != null && value.GetType() != GetPropertyType())
|
||||||
throw new ArtemisCoreException("Cannot update current value because of a type mismatch");
|
throw new ArtemisCoreException("Cannot update current value because of a type mismatch");
|
||||||
_currentValue = value;
|
_currentValue = value;
|
||||||
}
|
}
|
||||||
@ -61,7 +61,7 @@ namespace Artemis.Core
|
|||||||
get => _defaultValue;
|
get => _defaultValue;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value.GetType() != GetPropertyType())
|
if (value != null && value.GetType() != GetPropertyType())
|
||||||
throw new ArtemisCoreException("Cannot update default value because of a type mismatch");
|
throw new ArtemisCoreException("Cannot update default value because of a type mismatch");
|
||||||
_defaultValue = value;
|
_defaultValue = value;
|
||||||
}
|
}
|
||||||
@ -186,6 +186,9 @@ namespace Artemis.Core
|
|||||||
/// <returns>The newly created data binding</returns>
|
/// <returns>The newly created data binding</returns>
|
||||||
public DataBinding EnableDataBinding(DataBindingRegistration dataBindingRegistration)
|
public DataBinding EnableDataBinding(DataBindingRegistration dataBindingRegistration)
|
||||||
{
|
{
|
||||||
|
if (dataBindingRegistration.LayerProperty != this)
|
||||||
|
throw new ArtemisCoreException("Cannot enable a data binding using a data binding registration of a different layer property");
|
||||||
|
|
||||||
var dataBinding = new DataBinding(dataBindingRegistration);
|
var dataBinding = new DataBinding(dataBindingRegistration);
|
||||||
_dataBindings.Add(dataBinding);
|
_dataBindings.Add(dataBinding);
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
|
using System.Reflection;
|
||||||
using Artemis.Storage.Entities.Profile;
|
using Artemis.Storage.Entities.Profile;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
@ -31,7 +32,7 @@ namespace Artemis.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public new T BaseValue
|
public new T BaseValue
|
||||||
{
|
{
|
||||||
get => (T) base.BaseValue;
|
get => base.BaseValue != null ? (T) base.BaseValue : default;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (Equals(base.BaseValue, value))
|
if (Equals(base.BaseValue, value))
|
||||||
@ -47,7 +48,7 @@ namespace Artemis.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public new T CurrentValue
|
public new T CurrentValue
|
||||||
{
|
{
|
||||||
get => (T) base.CurrentValue;
|
get => base.CurrentValue != null ? (T) base.CurrentValue : default;
|
||||||
set => base.CurrentValue = value;
|
set => base.CurrentValue = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +58,7 @@ namespace Artemis.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public new T DefaultValue
|
public new T DefaultValue
|
||||||
{
|
{
|
||||||
get => (T) base.DefaultValue;
|
get => base.DefaultValue != null ? (T) base.DefaultValue : default;
|
||||||
set => base.DefaultValue = value;
|
set => base.DefaultValue = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -311,14 +312,35 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
#region Data bindings
|
#region Data bindings
|
||||||
|
|
||||||
public void RegisterDataBindingProperty<TProperty>(Expression<Func<T, TProperty>> propertyLambda, IDataBindingConverter converter)
|
public void RegisterDataBindingProperty<TProperty>(Expression<Func<T, TProperty>> propertyLambda, DataBindingConverter converter)
|
||||||
{
|
{
|
||||||
var propertyInfo = ReflectionUtilities.GetPropertyInfo(CurrentValue, propertyLambda);
|
// If the lambda references to itself, use the property info of public new T CurrentValue
|
||||||
|
PropertyInfo propertyInfo;
|
||||||
|
string path = null;
|
||||||
|
if (propertyLambda.Parameters[0] == propertyLambda.Body)
|
||||||
|
{
|
||||||
|
propertyInfo = GetType().GetProperties().FirstOrDefault(p => p.Name == nameof(CurrentValue) && p.PropertyType == typeof(T));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
propertyInfo = ReflectionUtilities.GetPropertyInfo(CurrentValue, propertyLambda);
|
||||||
|
// Deconstruct the lambda
|
||||||
|
var current = (MemberExpression) propertyLambda.Body;
|
||||||
|
path = current.Member.Name;
|
||||||
|
while (current.Expression is MemberExpression memberExpression)
|
||||||
|
{
|
||||||
|
path = current.Member.Name + "." + path;
|
||||||
|
current = memberExpression;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (converter.SupportedType != propertyInfo.PropertyType)
|
if (converter.SupportedType != propertyInfo.PropertyType)
|
||||||
|
{
|
||||||
throw new ArtemisCoreException($"Cannot register data binding property for property {propertyInfo.Name} " +
|
throw new ArtemisCoreException($"Cannot register data binding property for property {propertyInfo.Name} " +
|
||||||
"because the provided converter does not support the property's type");
|
"because the provided converter does not support the property's type");
|
||||||
|
}
|
||||||
|
|
||||||
_dataBindingRegistrations.Add(new DataBindingRegistration(this, propertyInfo, converter));
|
_dataBindingRegistrations.Add(new DataBindingRegistration(this, propertyInfo, converter, path));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateDataBindings(double deltaTime)
|
private void UpdateDataBindings(double deltaTime)
|
||||||
|
|||||||
@ -81,7 +81,7 @@ namespace Artemis.UI.Ninject.Factories
|
|||||||
public interface IDataBindingsVmFactory : IVmFactory
|
public interface IDataBindingsVmFactory : IVmFactory
|
||||||
{
|
{
|
||||||
DataBindingsViewModel DataBindingsViewModel(BaseLayerProperty layerProperty);
|
DataBindingsViewModel DataBindingsViewModel(BaseLayerProperty layerProperty);
|
||||||
DataBindingViewModel DataBindingViewModel(BaseLayerProperty layerProperty, PropertyInfo targetProperty);
|
DataBindingViewModel DataBindingViewModel(DataBindingRegistration registration);
|
||||||
DataBindingModifierViewModel DataBindingModifierViewModel(DataBindingModifier modifier);
|
DataBindingModifierViewModel DataBindingModifierViewModel(DataBindingModifier modifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -42,43 +42,46 @@
|
|||||||
|
|
||||||
<ComboBox Grid.Row="1"
|
<ComboBox Grid.Row="1"
|
||||||
Style="{StaticResource MaterialDesignFloatingHintComboBox}"
|
Style="{StaticResource MaterialDesignFloatingHintComboBox}"
|
||||||
materialDesign:HintAssist.Hint="Mode"
|
materialDesign:HintAssist.Hint="Data binding mode"
|
||||||
MinWidth="128"
|
MinWidth="128"
|
||||||
IsEnabled="{Binding IsDataBindingEnabled}">
|
SelectedValue="{Binding SelectedDataBindingMode}" ItemsSource="{Binding DataBindingModes}" SelectedValuePath="Value" DisplayMemberPath="Description" >
|
||||||
<ComboBoxItem>
|
|
||||||
Replace value
|
|
||||||
</ComboBoxItem>
|
|
||||||
<ComboBoxItem>
|
|
||||||
Add to value
|
|
||||||
</ComboBoxItem>
|
|
||||||
<ComboBoxItem>
|
|
||||||
Subtract from value
|
|
||||||
</ComboBoxItem>
|
|
||||||
</ComboBox>
|
</ComboBox>
|
||||||
|
|
||||||
<StackPanel Grid.Row="2">
|
<StackPanel Grid.Row="2">
|
||||||
<TextBox Style="{StaticResource MaterialDesignFloatingHintTextBox}"
|
<TextBox Style="{StaticResource MaterialDesignFloatingHintTextBox}"
|
||||||
Text="200"
|
Text="{Binding EasingTime}"
|
||||||
materialDesign:TextFieldAssist.HasClearButton="True"
|
materialDesign:TextFieldAssist.HasClearButton="True"
|
||||||
materialDesign:TextFieldAssist.SuffixText="ms"
|
materialDesign:TextFieldAssist.SuffixText="ms"
|
||||||
materialDesign:HintAssist.Hint="Smoothing time"
|
materialDesign:HintAssist.Hint="Easing time"
|
||||||
IsEnabled="{Binding IsDataBindingEnabled}" />
|
IsEnabled="{Binding IsDataBindingEnabled}" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
<ComboBox Grid.Row="3"
|
<ComboBox Grid.Row="3"
|
||||||
Style="{StaticResource MaterialDesignFloatingHintComboBox}"
|
Style="{StaticResource MaterialDesignFloatingHintComboBox}"
|
||||||
materialDesign:HintAssist.Hint="Smoothing type"
|
materialDesign:HintAssist.Hint="Easing type"
|
||||||
MinWidth="128"
|
MinWidth="128"
|
||||||
IsEnabled="{Binding IsDataBindingEnabled}">
|
IsEnabled="{Binding IsEasingTimeEnabled}"
|
||||||
<ComboBoxItem>
|
SelectedItem="{Binding SelectedEasingViewModel}"
|
||||||
Ease in
|
ItemsSource="{Binding EasingViewModels}">
|
||||||
</ComboBoxItem>
|
<ComboBox.ItemsPanel>
|
||||||
<ComboBoxItem>
|
<ItemsPanelTemplate>
|
||||||
Ease out
|
<VirtualizingStackPanel />
|
||||||
</ComboBoxItem>
|
</ItemsPanelTemplate>
|
||||||
<ComboBoxItem>
|
</ComboBox.ItemsPanel>
|
||||||
Ease in and out
|
<ComboBox.ItemTemplate>
|
||||||
</ComboBoxItem>
|
<DataTemplate>
|
||||||
|
<StackPanel Orientation="Horizontal">
|
||||||
|
<Polyline Stroke="{DynamicResource MaterialDesignBody}"
|
||||||
|
StrokeThickness="1"
|
||||||
|
Points="{Binding EasingPoints}"
|
||||||
|
Stretch="Uniform"
|
||||||
|
Width="14"
|
||||||
|
Height="14"
|
||||||
|
Margin="0 0 10 0" />
|
||||||
|
<TextBlock Text="{Binding Description}" />
|
||||||
|
</StackPanel>
|
||||||
|
</DataTemplate>
|
||||||
|
</ComboBox.ItemTemplate>
|
||||||
</ComboBox>
|
</ComboBox>
|
||||||
|
|
||||||
<materialDesign:Card Grid.Row="4" Grid.ColumnSpan="2" Margin="0 5 0 0">
|
<materialDesign:Card Grid.Row="4" Grid.ColumnSpan="2" Margin="0 5 0 0">
|
||||||
@ -102,10 +105,10 @@
|
|||||||
<RowDefinition />
|
<RowDefinition />
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<TextBlock Margin="0 2">Input</TextBlock>
|
<TextBlock Margin="0 2">Input</TextBlock>
|
||||||
<TextBlock Grid.Row="0" Grid.Column="1" Margin="0 2" FontFamily="Consolas" Text="{Binding TestInputValue}"/>
|
<TextBlock Grid.Row="0" Grid.Column="1" Margin="0 2" FontFamily="Consolas" Text="{Binding TestInputValue}" />
|
||||||
|
|
||||||
<TextBlock Grid.Row="1" Grid.Column="0" Margin="0 2">Output</TextBlock>
|
<TextBlock Grid.Row="1" Grid.Column="0" Margin="0 2">Output</TextBlock>
|
||||||
<TextBlock Grid.Row="1" Grid.Column="1" Margin="0 2" FontFamily="Consolas" Text="{Binding TestResultValue}"/>
|
<TextBlock Grid.Row="1" Grid.Column="1" Margin="0 2" FontFamily="Consolas" Text="{Binding TestResultValue}" />
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</materialDesign:Card>
|
</materialDesign:Card>
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
|
||||||
using System.Timers;
|
using System.Timers;
|
||||||
using Artemis.Core;
|
using Artemis.Core;
|
||||||
using Artemis.UI.Ninject.Factories;
|
using Artemis.UI.Ninject.Factories;
|
||||||
|
using Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline;
|
||||||
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;
|
||||||
@ -22,25 +22,30 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
|||||||
private DataModelDynamicViewModel _targetSelectionViewModel;
|
private DataModelDynamicViewModel _targetSelectionViewModel;
|
||||||
private object _testInputValue;
|
private object _testInputValue;
|
||||||
private object _testResultValue;
|
private object _testResultValue;
|
||||||
|
private TimelineEasingViewModel _selectedEasingViewModel;
|
||||||
|
private DataBindingMode _selectedDataBindingMode;
|
||||||
|
private int _easingTime;
|
||||||
|
private bool _isEasingTimeEnabled;
|
||||||
|
private bool _updating;
|
||||||
|
|
||||||
public DataBindingViewModel(BaseLayerProperty layerProperty,
|
public DataBindingViewModel(DataBindingRegistration registration,
|
||||||
PropertyInfo targetProperty,
|
|
||||||
IProfileEditorService profileEditorService,
|
IProfileEditorService profileEditorService,
|
||||||
IDataModelUIService dataModelUIService,
|
IDataModelUIService dataModelUIService,
|
||||||
IDataBindingsVmFactory dataBindingsVmFactory)
|
IDataBindingsVmFactory dataBindingsVmFactory)
|
||||||
{
|
{
|
||||||
|
Registration = registration;
|
||||||
_profileEditorService = profileEditorService;
|
_profileEditorService = profileEditorService;
|
||||||
_dataModelUIService = dataModelUIService;
|
_dataModelUIService = dataModelUIService;
|
||||||
_dataBindingsVmFactory = dataBindingsVmFactory;
|
_dataBindingsVmFactory = dataBindingsVmFactory;
|
||||||
_updateTimer = new Timer(500);
|
_updateTimer = new Timer(500);
|
||||||
|
|
||||||
DisplayName = targetProperty.Name.ToUpper();
|
DisplayName = Registration.Property.Name.ToUpper();
|
||||||
|
|
||||||
|
DataBindingModes = new BindableCollection<ValueDescription>(EnumUtilities.GetAllValuesAndDescriptions(typeof(DataBindingMode)));
|
||||||
|
EasingViewModels = new BindableCollection<TimelineEasingViewModel>();
|
||||||
ModifierViewModels = new BindableCollection<DataBindingModifierViewModel>();
|
ModifierViewModels = new BindableCollection<DataBindingModifierViewModel>();
|
||||||
|
|
||||||
LayerProperty = layerProperty;
|
DataBinding = Registration.DataBinding;
|
||||||
TargetProperty = targetProperty;
|
|
||||||
DataBinding = layerProperty.DataBindings.FirstOrDefault(d => d.TargetProperty == targetProperty);
|
|
||||||
|
|
||||||
if (DataBinding != null)
|
if (DataBinding != null)
|
||||||
DataBinding.ModifiersUpdated += DataBindingOnModifiersUpdated;
|
DataBinding.ModifiersUpdated += DataBindingOnModifiersUpdated;
|
||||||
|
|
||||||
@ -50,11 +55,49 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
|||||||
Execute.PostToUIThread(Initialize);
|
Execute.PostToUIThread(Initialize);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BaseLayerProperty LayerProperty { get; }
|
public DataBindingRegistration Registration { get; }
|
||||||
public PropertyInfo TargetProperty { get; }
|
|
||||||
public string DisplayName { get; }
|
public string DisplayName { get; }
|
||||||
|
|
||||||
|
public BindableCollection<ValueDescription> DataBindingModes { get; }
|
||||||
|
public BindableCollection<TimelineEasingViewModel> EasingViewModels { get; }
|
||||||
public BindableCollection<DataBindingModifierViewModel> ModifierViewModels { get; }
|
public BindableCollection<DataBindingModifierViewModel> ModifierViewModels { get; }
|
||||||
|
|
||||||
|
public DataBindingMode SelectedDataBindingMode
|
||||||
|
{
|
||||||
|
get => _selectedDataBindingMode;
|
||||||
|
set => SetAndNotify(ref _selectedDataBindingMode, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TimelineEasingViewModel SelectedEasingViewModel
|
||||||
|
{
|
||||||
|
get => _selectedEasingViewModel;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (!SetAndNotify(ref _selectedEasingViewModel, value)) return;
|
||||||
|
ApplyChanges();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int EasingTime
|
||||||
|
{
|
||||||
|
get => _easingTime;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (!SetAndNotify(ref _easingTime, value)) return;
|
||||||
|
ApplyChanges();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsEasingTimeEnabled
|
||||||
|
{
|
||||||
|
get => _isEasingTimeEnabled;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (!SetAndNotify(ref _isEasingTimeEnabled, value)) return;
|
||||||
|
ApplyChanges();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public DataModelDynamicViewModel TargetSelectionViewModel
|
public DataModelDynamicViewModel TargetSelectionViewModel
|
||||||
{
|
{
|
||||||
get => _targetSelectionViewModel;
|
get => _targetSelectionViewModel;
|
||||||
@ -101,23 +144,22 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
|||||||
if (DataBinding != null)
|
if (DataBinding != null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
DataBinding = LayerProperty.AddDataBinding(TargetProperty);
|
DataBinding = Registration.LayerProperty.EnableDataBinding(Registration);
|
||||||
DataBinding.ModifiersUpdated += DataBindingOnModifiersUpdated;
|
DataBinding.ModifiersUpdated += DataBindingOnModifiersUpdated;
|
||||||
Update();
|
Update();
|
||||||
|
|
||||||
_profileEditorService.UpdateSelectedProfileElement();
|
_profileEditorService.UpdateSelectedProfileElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void RemoveDataBinding()
|
public void RemoveDataBinding()
|
||||||
{
|
{
|
||||||
if (DataBinding == null)
|
if (DataBinding == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var toRemove = DataBinding;
|
var toDisable = DataBinding;
|
||||||
DataBinding = null;
|
DataBinding = null;
|
||||||
LayerProperty.RemoveDataBinding(toRemove);
|
Registration.LayerProperty.DisableDataBinding(toDisable);
|
||||||
toRemove.ModifiersUpdated -= DataBindingOnModifiersUpdated;
|
toDisable.ModifiersUpdated -= DataBindingOnModifiersUpdated;
|
||||||
Update();
|
Update();
|
||||||
|
|
||||||
_profileEditorService.UpdateSelectedProfileElement();
|
_profileEditorService.UpdateSelectedProfileElement();
|
||||||
@ -136,6 +178,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
|||||||
|
|
||||||
private void Initialize()
|
private void Initialize()
|
||||||
{
|
{
|
||||||
|
EasingViewModels.AddRange(Enum.GetValues(typeof(Easings.Functions)).Cast<Easings.Functions>().Select(v => new TimelineEasingViewModel(null, v)));
|
||||||
TargetSelectionViewModel = _dataModelUIService.GetDynamicSelectionViewModel(_profileEditorService.GetCurrentModule());
|
TargetSelectionViewModel = _dataModelUIService.GetDynamicSelectionViewModel(_profileEditorService.GetCurrentModule());
|
||||||
TargetSelectionViewModel.PropertySelected += TargetSelectionViewModelOnPropertySelected;
|
TargetSelectionViewModel.PropertySelected += TargetSelectionViewModelOnPropertySelected;
|
||||||
|
|
||||||
@ -147,17 +190,43 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
|||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
|
if (_updating)
|
||||||
|
return;
|
||||||
|
|
||||||
if (DataBinding == null)
|
if (DataBinding == null)
|
||||||
{
|
{
|
||||||
TargetSelectionViewModel.IsEnabled = false;
|
TargetSelectionViewModel.IsEnabled = false;
|
||||||
|
IsEasingTimeEnabled = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_updating = true;
|
||||||
|
|
||||||
|
SelectedDataBindingMode = DataBinding.Mode;
|
||||||
|
EasingTime = (int) DataBinding.EasingTime.TotalMilliseconds;
|
||||||
|
SelectedEasingViewModel = EasingViewModels.First(vm => vm.EasingFunction == DataBinding.EasingFunction);
|
||||||
|
IsEasingTimeEnabled = EasingTime > 0;
|
||||||
|
|
||||||
TargetSelectionViewModel.IsEnabled = true;
|
TargetSelectionViewModel.IsEnabled = true;
|
||||||
TargetSelectionViewModel.PopulateSelectedPropertyViewModel(DataBinding.SourceDataModel, DataBinding.SourcePropertyPath);
|
TargetSelectionViewModel.PopulateSelectedPropertyViewModel(DataBinding.SourceDataModel, DataBinding.SourcePropertyPath);
|
||||||
TargetSelectionViewModel.FilterTypes = new[] {DataBinding.TargetProperty.PropertyType};
|
TargetSelectionViewModel.FilterTypes = new[] {DataBinding.TargetProperty.PropertyType};
|
||||||
|
|
||||||
UpdateModifierViewModels();
|
UpdateModifierViewModels();
|
||||||
|
|
||||||
|
_updating = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ApplyChanges()
|
||||||
|
{
|
||||||
|
if (_updating)
|
||||||
|
return;
|
||||||
|
|
||||||
|
DataBinding.Mode = SelectedDataBindingMode;
|
||||||
|
DataBinding.EasingTime = TimeSpan.FromMilliseconds(EasingTime);
|
||||||
|
DataBinding.EasingFunction = SelectedEasingViewModel?.EasingFunction ?? Easings.Functions.Linear;
|
||||||
|
|
||||||
|
_profileEditorService.UpdateSelectedProfileElement();
|
||||||
|
Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DataBindingOnModifiersUpdated(object sender, EventArgs e)
|
private void DataBindingOnModifiersUpdated(object sender, EventArgs e)
|
||||||
@ -179,10 +248,10 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
|||||||
private void UpdateTestResult()
|
private void UpdateTestResult()
|
||||||
{
|
{
|
||||||
var currentValue = TargetSelectionViewModel.SelectedPropertyViewModel?.GetCurrentValue();
|
var currentValue = TargetSelectionViewModel.SelectedPropertyViewModel?.GetCurrentValue();
|
||||||
if (currentValue == null && TargetProperty.PropertyType.IsValueType)
|
if (currentValue == null && Registration.Property.PropertyType.IsValueType)
|
||||||
currentValue = Activator.CreateInstance(TargetProperty.PropertyType);
|
currentValue = Activator.CreateInstance(Registration.Property.PropertyType);
|
||||||
|
|
||||||
TestInputValue = Convert.ChangeType(currentValue, TargetProperty.PropertyType);
|
TestInputValue = Convert.ChangeType(currentValue, Registration.Property.PropertyType);
|
||||||
TestResultValue = DataBinding?.GetValue(TestInputValue);
|
TestResultValue = DataBinding?.GetValue(TestInputValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -37,19 +37,19 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
|||||||
DataBindingViewModel = null;
|
DataBindingViewModel = null;
|
||||||
DataBindingsTabsViewModel = null;
|
DataBindingsTabsViewModel = null;
|
||||||
|
|
||||||
var properties = LayerProperty.GetDataBindingProperties();
|
var registrations = LayerProperty.DataBindingRegistrations;
|
||||||
if (properties == null || properties.Count == 0)
|
if (registrations == null || registrations.Count == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Create a data binding VM for each data bindable property. These VMs will be responsible for retrieving
|
// Create a data binding VM for each data bindable property. These VMs will be responsible for retrieving
|
||||||
// and creating the actual data bindings
|
// and creating the actual data bindings
|
||||||
if (properties.Count == 1)
|
if (registrations.Count == 1)
|
||||||
DataBindingViewModel = _dataBindingsVmFactory.DataBindingViewModel(LayerProperty, properties.First());
|
DataBindingViewModel = _dataBindingsVmFactory.DataBindingViewModel(registrations.First());
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DataBindingsTabsViewModel = new DataBindingsTabsViewModel();
|
DataBindingsTabsViewModel = new DataBindingsTabsViewModel();
|
||||||
foreach (var dataBindingProperty in properties)
|
foreach (var registration in registrations)
|
||||||
DataBindingsTabsViewModel.Tabs.Add(_dataBindingsVmFactory.DataBindingViewModel(LayerProperty, dataBindingProperty));
|
DataBindingsTabsViewModel.Tabs.Add(_dataBindingsVmFactory.DataBindingViewModel(registration));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,8 +12,12 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
|
|||||||
|
|
||||||
public TimelineEasingViewModel(TimelineKeyframeViewModel keyframeViewModel, Easings.Functions easingFunction)
|
public TimelineEasingViewModel(TimelineKeyframeViewModel keyframeViewModel, Easings.Functions easingFunction)
|
||||||
{
|
{
|
||||||
_keyframeViewModel = keyframeViewModel;
|
// Can be null if used by DataBindingViewModel because I'm lazy
|
||||||
_isEasingModeSelected = keyframeViewModel.BaseLayerPropertyKeyframe.EasingFunction == easingFunction;
|
if (keyframeViewModel != null)
|
||||||
|
{
|
||||||
|
_keyframeViewModel = keyframeViewModel;
|
||||||
|
_isEasingModeSelected = keyframeViewModel.BaseLayerPropertyKeyframe.EasingFunction == easingFunction;
|
||||||
|
}
|
||||||
|
|
||||||
EasingFunction = easingFunction;
|
EasingFunction = easingFunction;
|
||||||
Description = easingFunction.Humanize();
|
Description = easingFunction.Humanize();
|
||||||
|
|||||||
@ -102,11 +102,6 @@
|
|||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</MenuItem.ItemTemplate>
|
</MenuItem.ItemTemplate>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<!-- <MenuItem Header="Easing mode" IsEnabled="{Binding CanSelectEasingMode}"> -->
|
|
||||||
<!-- <MenuItem Header="Ease in" Command="{s:Action SetEasingMode}" CommandParameter="EaseIn" /> -->
|
|
||||||
<!-- <MenuItem Header="Ease out" Command="{s:Action SetEasingMode}" CommandParameter="EaseOut" /> -->
|
|
||||||
<!-- <MenuItem Header="Ease in and out" Command="{s:Action SetEasingMode}" CommandParameter="EaseInOut" /> -->
|
|
||||||
<!-- </MenuItem> -->
|
|
||||||
</ContextMenu>
|
</ContextMenu>
|
||||||
</Ellipse.ContextMenu>
|
</Ellipse.ContextMenu>
|
||||||
</Ellipse>
|
</Ellipse>
|
||||||
|
|||||||
@ -28,7 +28,8 @@ namespace Artemis.Plugins.Modules.General.DataModels
|
|||||||
|
|
||||||
public class TimeDataModel : DataModel
|
public class TimeDataModel : DataModel
|
||||||
{
|
{
|
||||||
public DateTime CurrentTime { get; set; }
|
public DateTimeOffset CurrentTime { get; set; }
|
||||||
public DateTime CurrentTimeUTC { get; set; }
|
public long SecondsSinceUnixEpoch { get; set; }
|
||||||
|
public TimeSpan TimeSinceMidnight { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -20,10 +20,10 @@ namespace Artemis.Plugins.Modules.General
|
|||||||
ExpandsDataModel = true;
|
ExpandsDataModel = true;
|
||||||
ModuleTabs = new List<ModuleTab> {new ModuleTab<GeneralViewModel>("General")};
|
ModuleTabs = new List<ModuleTab> {new ModuleTab<GeneralViewModel>("General")};
|
||||||
|
|
||||||
DataModel.TestTimeList.Add(new TimeDataModel {CurrentTime = DateTime.Now.AddDays(1), CurrentTimeUTC = DateTime.UtcNow.AddDays(1)});
|
DataModel.TestTimeList.Add(new TimeDataModel {CurrentTime = DateTimeOffset.Now.AddDays(1)});
|
||||||
DataModel.TestTimeList.Add(new TimeDataModel {CurrentTime = DateTime.Now.AddDays(2), CurrentTimeUTC = DateTime.UtcNow.AddDays(2)});
|
DataModel.TestTimeList.Add(new TimeDataModel {CurrentTime = DateTimeOffset.Now.AddDays(2)});
|
||||||
DataModel.TestTimeList.Add(new TimeDataModel {CurrentTime = DateTime.Now.AddDays(3), CurrentTimeUTC = DateTime.UtcNow.AddDays(3)});
|
DataModel.TestTimeList.Add(new TimeDataModel {CurrentTime = DateTimeOffset.Now.AddDays(3)});
|
||||||
DataModel.TestTimeList.Add(new TimeDataModel {CurrentTime = DateTime.Now.AddDays(4), CurrentTimeUTC = DateTime.UtcNow.AddDays(4)});
|
DataModel.TestTimeList.Add(new TimeDataModel {CurrentTime = DateTimeOffset.Now.AddDays(4)});
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void DisablePlugin()
|
public override void DisablePlugin()
|
||||||
@ -40,9 +40,9 @@ namespace Artemis.Plugins.Modules.General
|
|||||||
|
|
||||||
public override void Update(double deltaTime)
|
public override void Update(double deltaTime)
|
||||||
{
|
{
|
||||||
DataModel.TimeDataModel.CurrentTime = DateTime.Now;
|
DataModel.TimeDataModel.CurrentTime = DateTimeOffset.Now;
|
||||||
DataModel.TimeDataModel.CurrentTimeUTC = DateTime.UtcNow;
|
DataModel.TimeDataModel.SecondsSinceUnixEpoch = DateTimeOffset.Now.ToUnixTimeSeconds();
|
||||||
|
DataModel.TimeDataModel.TimeSinceMidnight = DateTimeOffset.Now - DateTimeOffset.Now.Date;
|
||||||
UpdateCurrentWindow();
|
UpdateCurrentWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -11,14 +11,14 @@ namespace Artemis.Plugins.Modules.General.ViewModels
|
|||||||
|
|
||||||
public GeneralModule GeneralModule { get; }
|
public GeneralModule GeneralModule { get; }
|
||||||
|
|
||||||
public void ShowUTCTimeInDataModel()
|
public void ShowTimeInDataModel()
|
||||||
{
|
{
|
||||||
GeneralModule.ShowProperty(model => model.TimeDataModel.CurrentTimeUTC);
|
GeneralModule.ShowProperty(model => model.TimeDataModel.CurrentTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void HideUTCTimeInDataModel()
|
public void HideTimeInDataModel()
|
||||||
{
|
{
|
||||||
GeneralModule.HideProperty(model => model.TimeDataModel.CurrentTimeUTC);
|
GeneralModule.HideProperty(model => model.TimeDataModel.CurrentTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -11,12 +11,12 @@
|
|||||||
<ColumnDefinition />
|
<ColumnDefinition />
|
||||||
<ColumnDefinition />
|
<ColumnDefinition />
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<Button Grid.Column="0" Style="{StaticResource MaterialDesignRaisedLightButton}" Command="{s:Action ShowUTCTimeInDataModel}" Margin="0 0 25 0">
|
<Button Grid.Column="0" Style="{StaticResource MaterialDesignRaisedLightButton}" Command="{s:Action ShowTimeInDataModel}" Margin="0 0 25 0">
|
||||||
ShowUTCTimeInDataModel
|
ShowTimeInDataModel
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button Grid.Column="1" Style="{StaticResource MaterialDesignRaisedButton}" Command="{s:Action HideUTCTimeInDataModel}" Margin="25 0 0 0">
|
<Button Grid.Column="1" Style="{StaticResource MaterialDesignRaisedButton}" Command="{s:Action HideTimeInDataModel}" Margin="25 0 0 0">
|
||||||
HideUTCTimeInDataModel
|
HideTimeInDataModel
|
||||||
</Button>
|
</Button>
|
||||||
</Grid>
|
</Grid>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
Loading…
x
Reference in New Issue
Block a user