mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Data bindings - Fixed some conversion issues
Data bindings - Started hooking up the UI
This commit is contained in:
parent
59e1f37aec
commit
18225ca6fa
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
public class LayerPropertyGroupUpdatingEventArgs : EventArgs
|
||||
{
|
||||
public LayerPropertyGroupUpdatingEventArgs(double deltaTime)
|
||||
{
|
||||
DeltaTime = deltaTime;
|
||||
}
|
||||
|
||||
public double DeltaTime { get; }
|
||||
}
|
||||
}
|
||||
@ -132,11 +132,13 @@ namespace Artemis.Core
|
||||
/// <returns></returns>
|
||||
public object GetValue(object baseValue)
|
||||
{
|
||||
if (baseValue.GetType() != TargetProperty.PropertyType)
|
||||
{
|
||||
throw new ArtemisCoreException($"The provided current value type ({baseValue.GetType().Name}) not match the " +
|
||||
$"target property type ({TargetProperty.PropertyType.Name})");
|
||||
}
|
||||
// Validating this is kinda expensive, it'll fail on ChangeType later anyway ^^
|
||||
// var targetType = TargetProperty.PropertyType;
|
||||
// if (!targetType.IsCastableFrom(baseValue.GetType()))
|
||||
// {
|
||||
// throw new ArtemisCoreException($"The provided current value type ({baseValue.GetType().Name}) not match the " +
|
||||
// $"target property type ({targetType.Name})");
|
||||
// }
|
||||
|
||||
if (CompiledTargetAccessor == null)
|
||||
return baseValue;
|
||||
@ -145,7 +147,11 @@ namespace Artemis.Core
|
||||
foreach (var dataBindingModifier in Modifiers)
|
||||
dataBindingValue = dataBindingModifier.Apply(dataBindingValue);
|
||||
|
||||
return dataBindingValue;
|
||||
return Convert.ChangeType(dataBindingValue, TargetProperty.PropertyType);
|
||||
}
|
||||
|
||||
internal void Update(double deltaTime)
|
||||
{
|
||||
}
|
||||
|
||||
internal void ApplyToEntity()
|
||||
@ -210,20 +216,32 @@ namespace Artemis.Core
|
||||
if (listType != null)
|
||||
throw new ArtemisCoreException($"Cannot create a regular accessor at path {SourcePropertyPath} because the path contains a list");
|
||||
|
||||
var parameter = Expression.Parameter(typeof(object), "targetDataModel");
|
||||
var parameter = Expression.Parameter(typeof(DataModel), "targetDataModel");
|
||||
var accessor = SourcePropertyPath.Split('.').Aggregate<string, Expression>(
|
||||
Expression.Convert(parameter, SourceDataModel.GetType()), // Cast to the appropriate type
|
||||
Expression.Property
|
||||
);
|
||||
|
||||
var lambda = Expression.Lambda<Func<DataModel, object>>(accessor);
|
||||
var returnValue = Expression.Convert(accessor, typeof(object));
|
||||
|
||||
var lambda = Expression.Lambda<Func<DataModel, object>>(returnValue, parameter);
|
||||
CompiledTargetAccessor = lambda.Compile();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A mode that determines how the data binding is applied to the layer property
|
||||
/// </summary>
|
||||
public enum DataBindingMode
|
||||
{
|
||||
Override,
|
||||
/// <summary>
|
||||
/// Replaces the layer property value with the data binding value
|
||||
/// </summary>
|
||||
Replace,
|
||||
|
||||
/// <summary>
|
||||
/// Adds the data binding value to the layer property value
|
||||
/// </summary>
|
||||
Add
|
||||
}
|
||||
}
|
||||
@ -100,13 +100,6 @@ namespace Artemis.Core
|
||||
/// <returns>The modified value</returns>
|
||||
public object Apply(object currentValue)
|
||||
{
|
||||
var targetType = DataBinding.TargetProperty.GetType();
|
||||
if (currentValue.GetType() != targetType)
|
||||
{
|
||||
throw new ArtemisCoreException("The current value of the data binding does not match the type of the target property." +
|
||||
$" {targetType.Name} expected, received {currentValue.GetType().Name}.");
|
||||
}
|
||||
|
||||
if (CompiledDynamicPredicate != null)
|
||||
return CompiledDynamicPredicate(currentValue, ParameterDataModel);
|
||||
if (CompiledStaticPredicate != null)
|
||||
|
||||
@ -20,11 +20,6 @@ namespace Artemis.Core
|
||||
/// </summary>
|
||||
public PluginInfo PluginInfo { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the data binding modifier this modifier type is applied to
|
||||
/// </summary>
|
||||
public DataBindingModifier Modifier { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the types this modifier supports
|
||||
/// </summary>
|
||||
|
||||
@ -79,7 +79,7 @@ namespace Artemis.Core
|
||||
|
||||
foreach (var baseLayerEffect in LayerEffects.Where(e => e.Enabled))
|
||||
{
|
||||
baseLayerEffect.BaseProperties?.Update();
|
||||
baseLayerEffect.BaseProperties?.Update(deltaTime);
|
||||
baseLayerEffect.Update(deltaTime);
|
||||
}
|
||||
|
||||
@ -125,7 +125,7 @@ namespace Artemis.Core
|
||||
|
||||
foreach (var baseLayerEffect in LayerEffects.Where(e => e.Enabled))
|
||||
{
|
||||
baseLayerEffect.BaseProperties?.Update();
|
||||
baseLayerEffect.BaseProperties?.Update(delta);
|
||||
baseLayerEffect.Update(delta);
|
||||
}
|
||||
}
|
||||
|
||||
@ -261,14 +261,14 @@ namespace Artemis.Core
|
||||
if (TimelinePosition > TimelineLength)
|
||||
return;
|
||||
|
||||
General.Update();
|
||||
Transform.Update();
|
||||
LayerBrush.BaseProperties?.Update();
|
||||
General.Update(deltaTime);
|
||||
Transform.Update(deltaTime);
|
||||
LayerBrush.BaseProperties?.Update(deltaTime);
|
||||
LayerBrush.Update(deltaTime);
|
||||
|
||||
foreach (var baseLayerEffect in LayerEffects.Where(e => e.Enabled))
|
||||
{
|
||||
baseLayerEffect.BaseProperties?.Update();
|
||||
baseLayerEffect.BaseProperties?.Update(deltaTime);
|
||||
baseLayerEffect.Update(deltaTime);
|
||||
}
|
||||
}
|
||||
@ -301,14 +301,14 @@ namespace Artemis.Core
|
||||
|
||||
var delta = (TimelinePosition - beginTime).TotalSeconds;
|
||||
|
||||
General.Update();
|
||||
Transform.Update();
|
||||
LayerBrush.BaseProperties?.Update();
|
||||
General.Update(delta);
|
||||
Transform.Update(delta);
|
||||
LayerBrush.BaseProperties?.Update(delta);
|
||||
LayerBrush.Update(delta);
|
||||
|
||||
foreach (var baseLayerEffect in LayerEffects.Where(e => e.Enabled))
|
||||
{
|
||||
baseLayerEffect.BaseProperties?.Update();
|
||||
baseLayerEffect.BaseProperties?.Update(delta);
|
||||
baseLayerEffect.Update(delta);
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,7 +19,6 @@ namespace Artemis.Core
|
||||
public class LayerProperty<T> : BaseLayerProperty
|
||||
{
|
||||
private T _baseValue;
|
||||
private T _currentValue;
|
||||
private bool _isInitialized;
|
||||
private List<LayerPropertyKeyframe<T>> _keyframes;
|
||||
|
||||
@ -47,11 +46,7 @@ namespace Artemis.Core
|
||||
/// <summary>
|
||||
/// Gets the current value of this property as it is affected by it's keyframes, updated once every frame
|
||||
/// </summary>
|
||||
public T CurrentValue
|
||||
{
|
||||
get => !KeyframesEnabled || !KeyframesSupported ? BaseValue : _currentValue;
|
||||
internal set => _currentValue = value;
|
||||
}
|
||||
public T CurrentValue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the default value of this layer property. If set, this value is automatically applied if the property
|
||||
@ -100,7 +95,7 @@ namespace Artemis.Core
|
||||
currentKeyframe.Value = value;
|
||||
|
||||
// Update the property so that the new keyframe is reflected on the current value
|
||||
Update();
|
||||
Update(0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -190,9 +185,19 @@ namespace Artemis.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the property, applying keyframes to the current value
|
||||
/// Updates the property, applying keyframes and data bindings to the current value
|
||||
/// </summary>
|
||||
internal void Update()
|
||||
internal void Update(double deltaTime)
|
||||
{
|
||||
CurrentValue = BaseValue;
|
||||
|
||||
UpdateKeyframes();
|
||||
UpdateDataBindings(deltaTime);
|
||||
|
||||
OnUpdated();
|
||||
}
|
||||
|
||||
private void UpdateKeyframes()
|
||||
{
|
||||
if (!KeyframesSupported || !KeyframesEnabled)
|
||||
return;
|
||||
@ -216,8 +221,15 @@ namespace Artemis.Core
|
||||
var keyframeProgressEased = (float) Easings.Interpolate(keyframeProgress, CurrentKeyframe.EasingFunction);
|
||||
UpdateCurrentValue(keyframeProgress, keyframeProgressEased);
|
||||
}
|
||||
}
|
||||
|
||||
OnUpdated();
|
||||
private void UpdateDataBindings(double deltaTime)
|
||||
{
|
||||
foreach (var dataBinding in DataBindings)
|
||||
{
|
||||
dataBinding.Update(deltaTime);
|
||||
ApplyDataBinding(dataBinding);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -237,7 +249,7 @@ namespace Artemis.Core
|
||||
|
||||
PropertyEntity = entity;
|
||||
LayerPropertyGroup = layerPropertyGroup;
|
||||
LayerPropertyGroup.PropertyGroupUpdating += (sender, args) => Update();
|
||||
LayerPropertyGroup.PropertyGroupUpdating += (sender, args) => Update(args.DeltaTime);
|
||||
|
||||
try
|
||||
{
|
||||
@ -303,9 +315,7 @@ namespace Artemis.Core
|
||||
/// <inheritdoc />
|
||||
protected override void ApplyDataBinding(DataBinding dataBinding)
|
||||
{
|
||||
// The default implementation only supports simple types
|
||||
if (dataBinding.TargetProperty.DeclaringType == GetType())
|
||||
CurrentValue = (T) dataBinding.GetValue(CurrentValue);
|
||||
CurrentValue = (T) dataBinding.GetValue(CurrentValue);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -227,11 +227,11 @@ namespace Artemis.Core
|
||||
}
|
||||
}
|
||||
|
||||
internal void Update()
|
||||
internal void Update(double deltaTime)
|
||||
{
|
||||
// Since at this point we don't know what properties the group has without using reflection,
|
||||
// let properties subscribe to the update event and update themselves
|
||||
OnPropertyGroupUpdating();
|
||||
OnPropertyGroupUpdating(new LayerPropertyGroupUpdatingEventArgs(deltaTime));
|
||||
}
|
||||
|
||||
private void InitializeProperty(RenderProfileElement profileElement, string path, BaseLayerProperty instance)
|
||||
@ -264,7 +264,7 @@ namespace Artemis.Core
|
||||
|
||||
#region Events
|
||||
|
||||
internal event EventHandler PropertyGroupUpdating;
|
||||
internal event EventHandler<LayerPropertyGroupUpdatingEventArgs> PropertyGroupUpdating;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the property group has initialized all its children
|
||||
@ -282,9 +282,9 @@ namespace Artemis.Core
|
||||
/// </summary>
|
||||
public event EventHandler VisibilityChanged;
|
||||
|
||||
protected virtual void OnPropertyGroupUpdating()
|
||||
protected virtual void OnPropertyGroupUpdating(LayerPropertyGroupUpdatingEventArgs e)
|
||||
{
|
||||
PropertyGroupUpdating?.Invoke(this, EventArgs.Empty);
|
||||
PropertyGroupUpdating?.Invoke(this, e);
|
||||
}
|
||||
|
||||
protected virtual void OnVisibilityChanged()
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using Artemis.Core;
|
||||
using System.Reflection;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Modules;
|
||||
using Artemis.UI.Screens.Modules;
|
||||
using Artemis.UI.Screens.Modules.Tabs;
|
||||
@ -7,6 +8,7 @@ using Artemis.UI.Screens.ProfileEditor.DisplayConditions;
|
||||
using Artemis.UI.Screens.ProfileEditor.DisplayConditions.Abstract;
|
||||
using Artemis.UI.Screens.ProfileEditor.LayerProperties;
|
||||
using Artemis.UI.Screens.ProfileEditor.LayerProperties.Abstract;
|
||||
using Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings;
|
||||
using Artemis.UI.Screens.ProfileEditor.LayerProperties.LayerEffects;
|
||||
using Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline;
|
||||
using Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree;
|
||||
@ -17,6 +19,7 @@ using Artemis.UI.Screens.Settings.Debug;
|
||||
using Artemis.UI.Screens.Settings.Tabs.Devices;
|
||||
using Artemis.UI.Screens.Settings.Tabs.Plugins;
|
||||
using Stylet;
|
||||
using Module = Artemis.Core.Modules.Module;
|
||||
|
||||
namespace Artemis.UI.Ninject.Factories
|
||||
{
|
||||
@ -75,6 +78,13 @@ namespace Artemis.UI.Ninject.Factories
|
||||
DisplayConditionListPredicateViewModel DisplayConditionListPredicateViewModel(DisplayConditionListPredicate displayConditionListPredicate, DisplayConditionViewModel parent);
|
||||
}
|
||||
|
||||
public interface IDataBindingsVmFactory : IVmFactory
|
||||
{
|
||||
DataBindingsViewModel DataBindingsViewModel(BaseLayerProperty layerProperty);
|
||||
DataBindingViewModel DataBindingViewModel(BaseLayerProperty layerProperty, PropertyInfo targetProperty);
|
||||
DataBindingModifierViewModel DataBindingModifierViewModel(DataBindingModifier modifier);
|
||||
}
|
||||
|
||||
public interface ILayerPropertyVmFactory : IVmFactory
|
||||
{
|
||||
LayerPropertyGroupViewModel LayerPropertyGroupViewModel(LayerPropertyGroup layerPropertyGroup, PropertyGroupDescriptionAttribute propertyGroupDescription);
|
||||
|
||||
@ -6,9 +6,30 @@
|
||||
xmlns:local="clr-namespace:Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:converters="clr-namespace:Artemis.UI.Converters"
|
||||
xmlns:utilities="clr-namespace:Artemis.UI.Utilities"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800"
|
||||
d:DataContext="{d:DesignInstance local:DataBindingModifierViewModel}">
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="pack://application:,,,/Artemis.UI;component/ResourceDictionaries/DisplayConditions.xaml" />
|
||||
<ResourceDictionary>
|
||||
<converters:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
|
||||
<utilities:BindingProxy x:Key="DataContextProxy" Data="{Binding}" />
|
||||
<DataTemplate x:Key="DataModelDataTemplate">
|
||||
<Control x:Name="TemplateControl" Focusable="False" Template="{StaticResource DataModelSelectionTemplate}" />
|
||||
<DataTemplate.Triggers>
|
||||
<DataTrigger Binding="{Binding Data.ShowDataModelValues.Value, Source={StaticResource DataContextProxy}}" Value="True">
|
||||
<Setter TargetName="TemplateControl" Property="Template" Value="{StaticResource DataModelSelectionTemplateWithValues}" />
|
||||
</DataTrigger>
|
||||
</DataTemplate.Triggers>
|
||||
</DataTemplate>
|
||||
</ResourceDictionary>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
@ -41,10 +62,10 @@
|
||||
Style="{StaticResource DisplayConditionButtonLeftClickMenu}"
|
||||
Background="#7B7B7B"
|
||||
BorderBrush="#7B7B7B"
|
||||
Content="{Binding SelectedOperator.Description}">
|
||||
Content="{Binding SelectedModifierType.Description}">
|
||||
<!-- Click="PropertyButton_OnClick" -->
|
||||
<Button.ContextMenu>
|
||||
<ContextMenu ItemsSource="{Binding Operators}">
|
||||
<ContextMenu ItemsSource="{Binding ModifierTypes}">
|
||||
<ContextMenu.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
@ -55,7 +76,7 @@
|
||||
</ContextMenu.ItemTemplate>
|
||||
<ContextMenu.ItemContainerStyle>
|
||||
<Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource MaterialDesignMenuItem}">
|
||||
<Setter Property="Command" Value="{Binding Data.SelectOperatorCommand, Source={StaticResource DataContextProxy}}" />
|
||||
<Setter Property="Command" Value="{Binding Data.SelectModifierTypeCommand, Source={StaticResource DataContextProxy}}" />
|
||||
<Setter Property="CommandParameter" Value="{Binding}" />
|
||||
<Setter Property="CommandTarget" Value="{Binding}" />
|
||||
</Style>
|
||||
@ -63,18 +84,19 @@
|
||||
</ContextMenu>
|
||||
</Button.ContextMenu>
|
||||
</Button>
|
||||
|
||||
<Button Grid.Column="3"
|
||||
Background="#ab47bc"
|
||||
BorderBrush="#ab47bc"
|
||||
Style="{StaticResource DisplayConditionButton}"
|
||||
ToolTip="{Binding SelectedLeftSideProperty.DisplayPropertyPath}"
|
||||
ToolTip="{Binding SelectedParameterProperty.DisplayPropertyPath}"
|
||||
HorizontalAlignment="Left">
|
||||
<Button.ContextMenu>
|
||||
<ContextMenu ItemsSource="{Binding LeftSideDataModel.Children}" IsOpen="{Binding LeftSideDataModelOpen, Mode=OneWayToSource}">
|
||||
<ContextMenu ItemsSource="{Binding ParameterDataModel.Children}" IsOpen="{Binding ParameterDataModelOpen, Mode=OneWayToSource}">
|
||||
<ContextMenu.ItemContainerStyle>
|
||||
<Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource MaterialDesignMenuItem}">
|
||||
<Setter Property="ItemsSource" Value="{Binding Children}" />
|
||||
<Setter Property="Command" Value="{Binding Data.SelectLeftPropertyCommand, Source={StaticResource DataContextProxy}}" />
|
||||
<Setter Property="Command" Value="{Binding Data.SelectModifierTypeCommand, Source={StaticResource DataContextProxy}}" />
|
||||
<Setter Property="CommandParameter" Value="{Binding}" />
|
||||
<Setter Property="CommandTarget" Value="{Binding}" />
|
||||
<Setter Property="IsEnabled" Value="{Binding IsMatchingFilteredTypes}" />
|
||||
@ -85,11 +107,11 @@
|
||||
</ContextMenu>
|
||||
</Button.ContextMenu>
|
||||
<Grid>
|
||||
<TextBlock Text="{Binding SelectedLeftSideProperty.PropertyDescription.Name}"
|
||||
Visibility="{Binding SelectedLeftSideProperty, Converter={StaticResource NullToVisibilityConverter}}" />
|
||||
<TextBlock Text="{Binding SelectedParameterProperty.PropertyDescription.Name}"
|
||||
Visibility="{Binding SelectedParameterProperty, Converter={StaticResource NullToVisibilityConverter}}" />
|
||||
<TextBlock Text="« Select a property »"
|
||||
FontStyle="Italic"
|
||||
Visibility="{Binding SelectedLeftSideProperty, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted}" />
|
||||
Visibility="{Binding SelectedParameterProperty, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted}" />
|
||||
</Grid>
|
||||
</Button>
|
||||
</Grid>
|
||||
|
||||
@ -1,15 +1,127 @@
|
||||
using Artemis.Core;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Timers;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using Artemis.UI.Utilities;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
{
|
||||
public class DataBindingModifierViewModel : PropertyChangedBase
|
||||
{
|
||||
public DataBindingModifierViewModel(DataBindingModifier modifier)
|
||||
private readonly IDataBindingService _dataBindingService;
|
||||
private readonly IDataModelUIService _dataModelUIService;
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private readonly Timer _updateTimer;
|
||||
private DataModelPropertiesViewModel _parameterDataModel;
|
||||
private bool _parameterDataModelOpen;
|
||||
private DataBindingModifierType _selectedModifierType;
|
||||
private DataModelVisualizationViewModel _selectedParameterProperty;
|
||||
|
||||
public DataBindingModifierViewModel(DataBindingModifier modifier,
|
||||
IDataBindingService dataBindingService,
|
||||
ISettingsService settingsService,
|
||||
IDataModelUIService dataModelUIService,
|
||||
IProfileEditorService profileEditorService)
|
||||
{
|
||||
_dataBindingService = dataBindingService;
|
||||
_dataModelUIService = dataModelUIService;
|
||||
_profileEditorService = profileEditorService;
|
||||
_updateTimer = new Timer(500);
|
||||
|
||||
ShowDataModelValues = settingsService.GetSetting<bool>("ProfileEditor.ShowDataModelValues");
|
||||
|
||||
Modifier = modifier;
|
||||
ModifierTypes = new BindableCollection<DataBindingModifierType>();
|
||||
|
||||
SelectModifierTypeCommand = new DelegateCommand(ExecuteSelectModifierTypeCommand);
|
||||
|
||||
// Initialize async, no need to wait for it
|
||||
Task.Run(Initialize);
|
||||
}
|
||||
|
||||
public DelegateCommand SelectModifierTypeCommand { get; set; }
|
||||
|
||||
public PluginSetting<bool> ShowDataModelValues { get; }
|
||||
public DataBindingModifier Modifier { get; }
|
||||
public BindableCollection<DataBindingModifierType> ModifierTypes { get; }
|
||||
|
||||
public DataBindingModifierType SelectedModifierType
|
||||
{
|
||||
get => _selectedModifierType;
|
||||
set => SetAndNotify(ref _selectedModifierType, value);
|
||||
}
|
||||
|
||||
public DataModelPropertiesViewModel ParameterDataModel
|
||||
{
|
||||
get => _parameterDataModel;
|
||||
set => SetAndNotify(ref _parameterDataModel, value);
|
||||
}
|
||||
|
||||
public bool ParameterDataModelOpen
|
||||
{
|
||||
get => _parameterDataModelOpen;
|
||||
set => SetAndNotify(ref _parameterDataModelOpen, value);
|
||||
}
|
||||
|
||||
public DataModelVisualizationViewModel SelectedParameterProperty
|
||||
{
|
||||
get => _selectedParameterProperty;
|
||||
set => SetAndNotify(ref _selectedParameterProperty, value);
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
// Get the data models
|
||||
ParameterDataModel = _dataModelUIService.GetMainDataModelVisualization();
|
||||
if (!_dataModelUIService.GetPluginExtendsDataModel(_profileEditorService.GetCurrentModule()))
|
||||
ParameterDataModel.Children.Add(_dataModelUIService.GetPluginDataModelVisualization(_profileEditorService.GetCurrentModule()));
|
||||
|
||||
ParameterDataModel.UpdateRequested += ParameterDataModelOnUpdateRequested;
|
||||
|
||||
Update();
|
||||
|
||||
_updateTimer.Start();
|
||||
_updateTimer.Elapsed += OnUpdateTimerOnElapsed;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// Modifier type
|
||||
ModifierTypes.Clear();
|
||||
ModifierTypes.AddRange(_dataBindingService.GetCompatibleModifierTypes(Modifier.DataBinding.TargetProperty.PropertyType));
|
||||
SelectedModifierType = Modifier.ModifierType;
|
||||
|
||||
// Determine the parameter property
|
||||
if (Modifier.ParameterDataModel == null)
|
||||
SelectedParameterProperty = null;
|
||||
else
|
||||
SelectedParameterProperty = ParameterDataModel.GetChildByPath(Modifier.ParameterDataModel.PluginInfo.Guid, Modifier.ParameterPropertyPath);
|
||||
}
|
||||
|
||||
private void ExecuteSelectModifierTypeCommand(object context)
|
||||
{
|
||||
if (!(context is DataBindingModifierType dataBindingModifierType))
|
||||
return;
|
||||
|
||||
Modifier.UpdateModifierType(dataBindingModifierType);
|
||||
_profileEditorService.UpdateSelectedProfileElement();
|
||||
|
||||
Update();
|
||||
}
|
||||
|
||||
private void ParameterDataModelOnUpdateRequested(object sender, EventArgs e)
|
||||
{
|
||||
ParameterDataModel.ApplyTypeFilter(true, Modifier.DataBinding.TargetProperty.PropertyType);
|
||||
}
|
||||
|
||||
private void OnUpdateTimerOnElapsed(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
if (ParameterDataModelOpen)
|
||||
ParameterDataModel.Update(_dataModelUIService);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -52,15 +52,16 @@
|
||||
<Button Background="#ab47bc"
|
||||
BorderBrush="#ab47bc"
|
||||
Style="{StaticResource DisplayConditionButton}"
|
||||
ToolTip="{Binding SelectedLeftSideProperty.DisplayPropertyPath}"
|
||||
ToolTip="{Binding SelectedSourceProperty.DisplayPropertyPath}"
|
||||
IsEnabled="{Binding IsDataBindingEnabled}"
|
||||
HorizontalAlignment="Left">
|
||||
HorizontalAlignment="Left"
|
||||
Click="PropertyButton_OnClick">
|
||||
<Button.ContextMenu>
|
||||
<ContextMenu ItemsSource="{Binding LeftSideDataModel.Children}" IsOpen="{Binding LeftSideDataModelOpen, Mode=OneWayToSource}">
|
||||
<ContextMenu ItemsSource="{Binding SourceDataModel.Children}" IsOpen="{Binding SourceDataModelOpen, Mode=OneWayToSource}">
|
||||
<ContextMenu.ItemContainerStyle>
|
||||
<Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource MaterialDesignMenuItem}">
|
||||
<Setter Property="ItemsSource" Value="{Binding Children}" />
|
||||
<Setter Property="Command" Value="{Binding Data.SelectLeftPropertyCommand, Source={StaticResource DataContextProxy}}" />
|
||||
<Setter Property="Command" Value="{Binding Data.SelectSourcePropertyCommand, Source={StaticResource DataContextProxy}}" />
|
||||
<Setter Property="CommandParameter" Value="{Binding}" />
|
||||
<Setter Property="CommandTarget" Value="{Binding}" />
|
||||
<Setter Property="IsEnabled" Value="{Binding IsMatchingFilteredTypes}" />
|
||||
@ -71,11 +72,11 @@
|
||||
</ContextMenu>
|
||||
</Button.ContextMenu>
|
||||
<Grid>
|
||||
<TextBlock Text="{Binding SelectedLeftSideProperty.PropertyDescription.Name}"
|
||||
Visibility="{Binding SelectedLeftSideProperty, Converter={StaticResource NullToVisibilityConverter}}" />
|
||||
<TextBlock Text="{Binding SelectedSourceProperty.PropertyDescription.Name}"
|
||||
Visibility="{Binding SelectedSourceProperty, Converter={StaticResource NullToVisibilityConverter}}" />
|
||||
<TextBlock Text="« Select a property »"
|
||||
FontStyle="Italic"
|
||||
Visibility="{Binding SelectedLeftSideProperty, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted}" />
|
||||
Visibility="{Binding SelectedSourceProperty, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted}" />
|
||||
</Grid>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
@ -142,10 +143,10 @@
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Margin="0 2">Input</TextBlock>
|
||||
<TextBlock Grid.Row="0" Grid.Column="1" Margin="0 2" FontFamily="Consolas">1250</TextBlock>
|
||||
<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="1" Margin="0 2" FontFamily="Consolas">909</TextBlock>
|
||||
<TextBlock Grid.Row="1" Grid.Column="1" Margin="0 2" FontFamily="Consolas" Text="{Binding TestResultValue}"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</materialDesign:Card>
|
||||
@ -167,7 +168,8 @@
|
||||
FontSize="12"
|
||||
Padding="6 4"
|
||||
Height="22"
|
||||
IsEnabled="{Binding IsDataBindingEnabled}">
|
||||
IsEnabled="{Binding IsDataBindingEnabled}"
|
||||
Command="{s:Action AddModifier}">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<materialDesign:PackIcon Margin="0 -1 4 0" Kind="Plus" />
|
||||
<TextBlock>
|
||||
|
||||
@ -0,0 +1,26 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for DataBindingView.xaml
|
||||
/// </summary>
|
||||
public partial class DataBindingView : UserControl
|
||||
{
|
||||
public DataBindingView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void PropertyButton_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// DataContext is not set when using left button, I don't know why but there it is
|
||||
if (sender is Button button && button.ContextMenu != null)
|
||||
{
|
||||
button.ContextMenu.DataContext = button.DataContext;
|
||||
button.ContextMenu.IsOpen = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6,42 +6,45 @@ using System.Threading.Tasks;
|
||||
using System.Timers;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using Artemis.UI.Utilities;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
{
|
||||
public class DataBindingViewModel : PropertyChangedBase
|
||||
{
|
||||
private readonly IDataModelService _dataModelService;
|
||||
private readonly IDataModelUIService _dataModelUIService;
|
||||
private readonly IDataBindingsVmFactory _dataBindingsVmFactory;
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private readonly ISettingsService _settingsService;
|
||||
private readonly Timer _updateTimer;
|
||||
private DataBinding _dataBinding;
|
||||
private bool _isDataBindingEnabled;
|
||||
private DataModelPropertiesViewModel _sourceDataModel;
|
||||
private DataModelVisualizationViewModel _selectedSourceProperty;
|
||||
private bool _sourceDataModelOpen;
|
||||
private object _testInputValue;
|
||||
private object _testResultValue;
|
||||
|
||||
public DataBindingViewModel(
|
||||
BaseLayerProperty layerProperty,
|
||||
public DataBindingViewModel(BaseLayerProperty layerProperty,
|
||||
PropertyInfo targetProperty,
|
||||
IProfileEditorService profileEditorService,
|
||||
IDataModelUIService dataModelUIService,
|
||||
IDataModelService dataModelService,
|
||||
ISettingsService settingsService)
|
||||
ISettingsService settingsService,
|
||||
IDataBindingsVmFactory dataBindingsVmFactory)
|
||||
{
|
||||
_profileEditorService = profileEditorService;
|
||||
_dataModelUIService = dataModelUIService;
|
||||
_dataModelService = dataModelService;
|
||||
_settingsService = settingsService;
|
||||
_dataBindingsVmFactory = dataBindingsVmFactory;
|
||||
_updateTimer = new Timer(500);
|
||||
|
||||
LayerProperty = layerProperty;
|
||||
TargetProperty = targetProperty;
|
||||
|
||||
DisplayName = TargetProperty.Name.ToUpper();
|
||||
SelectSourcePropertyCommand = new DelegateCommand(ExecuteSelectSourceProperty);
|
||||
ModifierViewModels = new BindableCollection<DataBindingModifierViewModel>();
|
||||
DataBinding = layerProperty.DataBindings.FirstOrDefault(d => d.TargetProperty == targetProperty);
|
||||
|
||||
@ -53,14 +56,18 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
Task.Run(Initialize);
|
||||
}
|
||||
|
||||
public bool SourceDataModelOpen { get; set; }
|
||||
|
||||
public DataModelPropertiesViewModel SourceDataModel
|
||||
{
|
||||
get => _sourceDataModel;
|
||||
set => SetAndNotify(ref _sourceDataModel, value);
|
||||
}
|
||||
|
||||
public bool SourceDataModelOpen
|
||||
{
|
||||
get => _sourceDataModelOpen;
|
||||
set => SetAndNotify(ref _sourceDataModelOpen, value);
|
||||
}
|
||||
|
||||
public DataModelVisualizationViewModel SelectedSourceProperty
|
||||
{
|
||||
get => _selectedSourceProperty;
|
||||
@ -73,6 +80,8 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
public string DisplayName { get; }
|
||||
public BindableCollection<DataBindingModifierViewModel> ModifierViewModels { get; }
|
||||
|
||||
public DelegateCommand SelectSourcePropertyCommand { get; }
|
||||
|
||||
public bool IsDataBindingEnabled
|
||||
{
|
||||
get => _isDataBindingEnabled;
|
||||
@ -122,7 +131,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
var modifier = new DataBindingModifier(ProfileRightSideType.Dynamic);
|
||||
DataBinding.AddModifier(modifier);
|
||||
|
||||
ModifierViewModels.Add(new DataBindingModifierViewModel(modifier));
|
||||
ModifierViewModels.Add(_dataBindingsVmFactory.DataBindingModifierViewModel(modifier));
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
@ -134,10 +143,24 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
|
||||
SourceDataModel.UpdateRequested += SourceDataModelOnUpdateRequested;
|
||||
|
||||
Update();
|
||||
|
||||
_updateTimer.Start();
|
||||
_updateTimer.Elapsed += OnUpdateTimerOnElapsed;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (DataBinding == null || SourceDataModel == null)
|
||||
return;
|
||||
|
||||
// Determine the source property
|
||||
if (DataBinding.SourceDataModel == null)
|
||||
SelectedSourceProperty = null;
|
||||
else
|
||||
SelectedSourceProperty = SourceDataModel.GetChildByPath(DataBinding.SourceDataModel.PluginInfo.Guid, DataBinding.SourcePropertyPath);
|
||||
}
|
||||
|
||||
private void SourceDataModelOnUpdateRequested(object sender, EventArgs e)
|
||||
{
|
||||
SourceDataModel.ApplyTypeFilter(true, DataBinding.TargetProperty.PropertyType);
|
||||
@ -145,10 +168,33 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
|
||||
private void OnUpdateTimerOnElapsed(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
UpdateTestResult();
|
||||
if (SourceDataModelOpen)
|
||||
SourceDataModel.Update(_dataModelUIService);
|
||||
}
|
||||
|
||||
private void UpdateTestResult()
|
||||
{
|
||||
var currentValue = SelectedSourceProperty?.GetCurrentValue();
|
||||
if (currentValue == null && TargetProperty.PropertyType.IsValueType)
|
||||
currentValue = Activator.CreateInstance(TargetProperty.PropertyType);
|
||||
|
||||
TestInputValue = Convert.ChangeType(currentValue, TargetProperty.PropertyType);
|
||||
TestResultValue = DataBinding?.GetValue(TestInputValue);
|
||||
}
|
||||
|
||||
public object TestInputValue
|
||||
{
|
||||
get => _testInputValue;
|
||||
set => SetAndNotify(ref _testInputValue, value);
|
||||
}
|
||||
|
||||
public object TestResultValue
|
||||
{
|
||||
get => _testResultValue;
|
||||
set => SetAndNotify(ref _testResultValue, value);
|
||||
}
|
||||
|
||||
private void UpdateModifierViewModels()
|
||||
{
|
||||
ModifierViewModels.Clear();
|
||||
@ -156,7 +202,18 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
return;
|
||||
|
||||
foreach (var dataBindingModifier in DataBinding.Modifiers)
|
||||
ModifierViewModels.Add(new DataBindingModifierViewModel(dataBindingModifier));
|
||||
ModifierViewModels.Add(_dataBindingsVmFactory.DataBindingModifierViewModel(dataBindingModifier));
|
||||
}
|
||||
|
||||
private void ExecuteSelectSourceProperty(object context)
|
||||
{
|
||||
if (!(context is DataModelVisualizationViewModel selected))
|
||||
return;
|
||||
|
||||
DataBinding.UpdateSource(selected.DataModel, selected.PropertyPath);
|
||||
_profileEditorService.UpdateSelectedProfileElement();
|
||||
|
||||
Update();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,16 +1,19 @@
|
||||
using System.Linq;
|
||||
using Artemis.Core;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
{
|
||||
public class DataBindingsViewModel : PropertyChangedBase
|
||||
{
|
||||
private readonly IDataBindingsVmFactory _dataBindingsVmFactory;
|
||||
private DataBindingsTabsViewModel _dataBindingsTabsViewModel;
|
||||
private DataBindingViewModel _dataBindingViewModel;
|
||||
|
||||
public DataBindingsViewModel(BaseLayerProperty layerProperty)
|
||||
public DataBindingsViewModel(BaseLayerProperty layerProperty, IDataBindingsVmFactory dataBindingsVmFactory)
|
||||
{
|
||||
_dataBindingsVmFactory = dataBindingsVmFactory;
|
||||
LayerProperty = layerProperty;
|
||||
Initialise();
|
||||
}
|
||||
@ -41,12 +44,12 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
// Create a data binding VM for each data bindable property. These VMs will be responsible for retrieving
|
||||
// and creating the actual data bindings
|
||||
if (properties.Count == 1)
|
||||
DataBindingViewModel = new DataBindingViewModel(LayerProperty, properties.First());
|
||||
DataBindingViewModel = _dataBindingsVmFactory.DataBindingViewModel(LayerProperty, properties.First());
|
||||
else
|
||||
{
|
||||
DataBindingsTabsViewModel = new DataBindingsTabsViewModel();
|
||||
foreach (var dataBindingProperty in properties)
|
||||
DataBindingsTabsViewModel.Tabs.Add(new DataBindingViewModel(LayerProperty, dataBindingProperty));
|
||||
DataBindingsTabsViewModel.Tabs.Add(_dataBindingsVmFactory.DataBindingViewModel(LayerProperty, dataBindingProperty));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,6 +23,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
|
||||
public class LayerPropertiesViewModel : ProfileEditorPanelViewModel, IDropTarget
|
||||
{
|
||||
private readonly ILayerPropertyVmFactory _layerPropertyVmFactory;
|
||||
private readonly IDataBindingsVmFactory _dataBindingsVmFactory;
|
||||
private LayerPropertyGroupViewModel _brushPropertyGroup;
|
||||
private DataBindingsViewModel _dataBindingsViewModel;
|
||||
private EffectsViewModel _effectsViewModel;
|
||||
@ -38,10 +39,14 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
|
||||
private TimelineViewModel _timelineViewModel;
|
||||
private TreeViewModel _treeViewModel;
|
||||
|
||||
public LayerPropertiesViewModel(IProfileEditorService profileEditorService, ICoreService coreService, ISettingsService settingsService,
|
||||
ILayerPropertyVmFactory layerPropertyVmFactory)
|
||||
public LayerPropertiesViewModel(IProfileEditorService profileEditorService,
|
||||
ICoreService coreService,
|
||||
ISettingsService settingsService,
|
||||
ILayerPropertyVmFactory layerPropertyVmFactory,
|
||||
IDataBindingsVmFactory dataBindingsVmFactory)
|
||||
{
|
||||
_layerPropertyVmFactory = layerPropertyVmFactory;
|
||||
_dataBindingsVmFactory = dataBindingsVmFactory;
|
||||
|
||||
ProfileEditorService = profileEditorService;
|
||||
CoreService = coreService;
|
||||
@ -236,7 +241,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
|
||||
if (ProfileEditorService.SelectedDataBinding != null)
|
||||
{
|
||||
RightSideIndex = 1;
|
||||
DataBindingsViewModel = new DataBindingsViewModel(ProfileEditorService.SelectedDataBinding);
|
||||
DataBindingsViewModel = _dataBindingsVmFactory.DataBindingsViewModel(ProfileEditorService.SelectedDataBinding);
|
||||
}
|
||||
else
|
||||
RightSideIndex = 0;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user