mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Data bindings - WIP commit
Layer/effect config dialogs - Don't require specific ctor parameter names
This commit is contained in:
parent
c98fc51623
commit
21beffc0a9
@ -15,18 +15,23 @@ namespace Artemis.Core
|
||||
public class DataBinding
|
||||
{
|
||||
private readonly List<DataBindingModifier> _modifiers = new List<DataBindingModifier>();
|
||||
private bool _isInitialized;
|
||||
|
||||
public DataBinding(BaseLayerProperty layerProperty, PropertyInfo targetProperty)
|
||||
internal DataBinding(BaseLayerProperty layerProperty, PropertyInfo targetProperty)
|
||||
{
|
||||
LayerProperty = layerProperty;
|
||||
TargetProperty = targetProperty;
|
||||
Entity = new DataBindingEntity();
|
||||
|
||||
ApplyToEntity();
|
||||
}
|
||||
|
||||
public DataBinding(BaseLayerProperty layerProperty, PropertyInfo targetProperty, DataBindingEntity entity)
|
||||
internal DataBinding(BaseLayerProperty layerProperty, DataBindingEntity entity)
|
||||
{
|
||||
LayerProperty = layerProperty;
|
||||
TargetProperty = targetProperty;
|
||||
Entity = entity;
|
||||
|
||||
ApplyToDataBinding();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -37,7 +42,7 @@ namespace Artemis.Core
|
||||
/// <summary>
|
||||
/// Gets the inner property this data binding targets
|
||||
/// </summary>
|
||||
public PropertyInfo TargetProperty { get; }
|
||||
public PropertyInfo TargetProperty { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the currently used instance of the data model that contains the source of the data binding
|
||||
@ -49,13 +54,25 @@ namespace Artemis.Core
|
||||
/// </summary>
|
||||
public string SourcePropertyPath { get; private set; }
|
||||
|
||||
public DataBindingMode Mode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the easing time of the data binding
|
||||
/// </summary>
|
||||
public TimeSpan EasingTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets ors ets the easing function of the data binding
|
||||
/// </summary>
|
||||
public Easings.Functions EasingFunction { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of modifiers applied to this data binding
|
||||
/// </summary>
|
||||
public IReadOnlyList<DataBindingModifier> Modifiers => _modifiers.AsReadOnly();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the compiled function that gets the current value of the data binding target
|
||||
/// Gets the compiled function that gets the current value of the data binding target
|
||||
/// </summary>
|
||||
public Func<DataModel, object> CompiledTargetAccessor { get; private set; }
|
||||
|
||||
@ -131,15 +148,60 @@ namespace Artemis.Core
|
||||
return dataBindingValue;
|
||||
}
|
||||
|
||||
internal void Initialize(IDataModelService dataModelService, IDataBindingService dataBindingService)
|
||||
internal void ApplyToEntity()
|
||||
{
|
||||
// Source
|
||||
// General
|
||||
Entity.TargetProperty = TargetProperty?.Name;
|
||||
Entity.DataBindingMode = (int) Mode;
|
||||
Entity.EasingTime = EasingTime;
|
||||
Entity.EasingFunction = (int) EasingFunction;
|
||||
|
||||
// Data model
|
||||
Entity.SourceDataModelGuid = SourceDataModel?.PluginInfo?.Guid;
|
||||
Entity.SourcePropertyPath = SourcePropertyPath;
|
||||
|
||||
// Modifiers
|
||||
Entity.Modifiers.Clear();
|
||||
foreach (var dataBindingModifier in Modifiers)
|
||||
{
|
||||
dataBindingModifier.ApplyToEntity();
|
||||
Entity.Modifiers.Add(dataBindingModifier.Entity);
|
||||
}
|
||||
}
|
||||
|
||||
internal void ApplyToDataBinding()
|
||||
{
|
||||
// General
|
||||
TargetProperty = LayerProperty.GetDataBindingProperties()?.FirstOrDefault(p => p.Name == Entity.TargetProperty);
|
||||
Mode = (DataBindingMode) Entity.DataBindingMode;
|
||||
EasingTime = Entity.EasingTime;
|
||||
EasingFunction = (Easings.Functions) Entity.EasingFunction;
|
||||
|
||||
foreach (var dataBindingModifier in Modifiers)
|
||||
// Data model is done during Initialize
|
||||
|
||||
// Modifiers
|
||||
foreach (var dataBindingModifierEntity in Entity.Modifiers)
|
||||
_modifiers.Add(new DataBindingModifier(this, dataBindingModifierEntity));
|
||||
}
|
||||
|
||||
internal void Initialize(IDataModelService dataModelService, IDataBindingService dataBindingService)
|
||||
{
|
||||
if (_isInitialized)
|
||||
throw new ArtemisCoreException("Data binding is already initialized");
|
||||
|
||||
// Source
|
||||
if (Entity.SourceDataModelGuid != null)
|
||||
{
|
||||
var dataModel = dataModelService.GetPluginDataModelByGuid(Entity.SourceDataModelGuid.Value);
|
||||
if (dataModel != null && dataModel.ContainsPath(Entity.SourcePropertyPath))
|
||||
UpdateSource(dataModel, Entity.SourcePropertyPath);
|
||||
}
|
||||
|
||||
// Modifiers
|
||||
foreach (var dataBindingModifier in Modifiers)
|
||||
dataBindingModifier.Initialize(dataModelService, dataBindingService);
|
||||
|
||||
_isInitialized = true;
|
||||
}
|
||||
|
||||
private void CreateExpression()
|
||||
@ -158,4 +220,10 @@ namespace Artemis.Core
|
||||
CompiledTargetAccessor = lambda.Compile();
|
||||
}
|
||||
}
|
||||
|
||||
public enum DataBindingMode
|
||||
{
|
||||
Override,
|
||||
Add
|
||||
}
|
||||
}
|
||||
@ -4,6 +4,7 @@ using System.Linq.Expressions;
|
||||
using Artemis.Core.DataModelExpansions;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.Storage.Entities.Profile.DataBindings;
|
||||
using Microsoft.VisualBasic;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Artemis.Core
|
||||
@ -14,26 +15,26 @@ namespace Artemis.Core
|
||||
public class DataBindingModifier
|
||||
{
|
||||
private DataBinding _dataBinding;
|
||||
private bool _isInitialized;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="DataBindingModifier" /> class
|
||||
/// Creates a new instance of the <see cref="DataBindingModifier"/> class
|
||||
/// </summary>
|
||||
public DataBindingModifier(DataBinding dataBinding, ProfileRightSideType parameterType)
|
||||
/// <param name="parameterType">The type of the parameter, can either be dynamic (based on a data model value) or static</param>
|
||||
public DataBindingModifier(ProfileRightSideType parameterType)
|
||||
{
|
||||
DataBinding = dataBinding;
|
||||
ParameterType = parameterType;
|
||||
Entity = new DataBindingModifierEntity();
|
||||
|
||||
ApplyToEntity();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="DataBindingModifier" /> class
|
||||
/// </summary>
|
||||
public DataBindingModifier(DataBinding dataBinding, DataBindingModifierEntity entity)
|
||||
internal DataBindingModifier(DataBinding dataBinding, DataBindingModifierEntity entity)
|
||||
{
|
||||
DataBinding = dataBinding;
|
||||
ParameterType = (ProfileRightSideType) entity.ParameterType;
|
||||
Order = entity.Order;
|
||||
Entity = entity;
|
||||
|
||||
ApplyToDataBindingModifier();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -192,6 +193,9 @@ namespace Artemis.Core
|
||||
|
||||
internal void Initialize(IDataModelService dataModelService, IDataBindingService dataBindingService)
|
||||
{
|
||||
if (_isInitialized)
|
||||
throw new ArtemisCoreException("Data binding modifier is already initialized");
|
||||
|
||||
// Modifier type
|
||||
if (Entity.ModifierTypePluginGuid != null)
|
||||
{
|
||||
@ -207,6 +211,7 @@ namespace Artemis.Core
|
||||
if (dataModel != null && dataModel.ContainsPath(Entity.ParameterPropertyPath))
|
||||
UpdateParameter(dataModel, Entity.ParameterPropertyPath);
|
||||
}
|
||||
// Static parameter
|
||||
else if (ParameterType == ProfileRightSideType.Static && Entity.ParameterStaticValue != null)
|
||||
{
|
||||
// Use the target type so JSON.NET has a better idea what to do
|
||||
@ -227,7 +232,7 @@ namespace Artemis.Core
|
||||
UpdateParameter(staticValue);
|
||||
}
|
||||
|
||||
// Static parameter
|
||||
_isInitialized = true;
|
||||
}
|
||||
|
||||
|
||||
@ -291,5 +296,32 @@ namespace Artemis.Core
|
||||
Expression.Property
|
||||
);
|
||||
}
|
||||
|
||||
internal void ApplyToEntity()
|
||||
{
|
||||
// Modifier
|
||||
Entity.ModifierType = ModifierType?.GetType().Name;
|
||||
Entity.ModifierTypePluginGuid = ModifierType?.PluginInfo.Guid;
|
||||
|
||||
// General
|
||||
Entity.Order = Order;
|
||||
Entity.ParameterType = (int) ParameterType;
|
||||
|
||||
// Parameter
|
||||
Entity.ParameterDataModelGuid = ParameterDataModel?.PluginInfo.Guid;
|
||||
Entity.ParameterPropertyPath = ParameterPropertyPath;
|
||||
Entity.ParameterStaticValue = JsonConvert.SerializeObject(ParameterStaticValue);
|
||||
}
|
||||
|
||||
internal void ApplyToDataBindingModifier()
|
||||
{
|
||||
// Modifier type is done during Initialize
|
||||
|
||||
// General
|
||||
Order = Entity.Order;
|
||||
ParameterType = (ProfileRightSideType) Entity.ParameterType;
|
||||
|
||||
// Parameter is done during initialize
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -112,6 +112,7 @@ namespace Artemis.Core
|
||||
internal set => SetAndNotify(ref _layerBrush, value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
return $"[Layer] {nameof(Name)}: {Name}, {nameof(Order)}: {Order}";
|
||||
@ -138,6 +139,7 @@ namespace Artemis.Core
|
||||
return keyframes;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposing)
|
||||
|
||||
@ -10,7 +10,7 @@ namespace Artemis.Core
|
||||
/// </summary>
|
||||
public abstract class BaseLayerProperty
|
||||
{
|
||||
private readonly List<DataBinding> _dataBindings = new List<DataBinding>();
|
||||
protected readonly List<DataBinding> _dataBindings = new List<DataBinding>();
|
||||
private bool _isHidden;
|
||||
private bool _keyframesEnabled;
|
||||
|
||||
@ -31,15 +31,15 @@ namespace Artemis.Core
|
||||
/// <summary>
|
||||
/// Gets whether keyframes are supported on this type of property
|
||||
/// </summary>
|
||||
public bool KeyframesSupported { get; protected internal set; } = true;
|
||||
|
||||
public bool KeyframesSupported { get; protected internal set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether data bindings are supported on this type of property
|
||||
/// </summary>
|
||||
public bool DataBindingsSupported { get; protected internal set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a read-only collection of the currently applied data bindings
|
||||
/// Gets a read-only collection of the currently applied data bindings
|
||||
/// </summary>
|
||||
public IReadOnlyCollection<DataBinding> DataBindings => _dataBindings.AsReadOnly();
|
||||
|
||||
@ -141,6 +141,30 @@ namespace Artemis.Core
|
||||
ApplyDataBinding(dataBinding);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new data binding targeting the given property to the <see cref="DataBindings" /> collection
|
||||
/// </summary>
|
||||
/// <param name="targetProperty">The property the new data binding should target</param>
|
||||
/// <returns>The newly created data binding</returns>
|
||||
public DataBinding AddDataBinding(PropertyInfo targetProperty)
|
||||
{
|
||||
var dataBinding = new DataBinding(this, targetProperty);
|
||||
_dataBindings.Add(dataBinding);
|
||||
|
||||
return dataBinding;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the provided data binding from the <see cref="DataBindings" /> collection
|
||||
/// </summary>
|
||||
/// <param name="dataBinding">The data binding to remove</param>
|
||||
public void RemoveDataBinding(DataBinding dataBinding)
|
||||
{
|
||||
_dataBindings.Remove(dataBinding);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
|
||||
@ -255,6 +255,13 @@ namespace Artemis.Core
|
||||
(Easings.Functions) k.EasingFunction,
|
||||
this
|
||||
)));
|
||||
|
||||
_dataBindings.Clear();
|
||||
foreach (var entityDataBindingEntity in entity.DataBindingEntities)
|
||||
{
|
||||
var dataBinding = new DataBinding(this, entityDataBindingEntity);
|
||||
_dataBindings.Add(dataBinding);
|
||||
}
|
||||
}
|
||||
catch (JsonException e)
|
||||
{
|
||||
|
||||
@ -10,6 +10,7 @@ namespace Artemis.Storage.Entities.Profile.DataBindings
|
||||
Modifiers = new List<DataBindingModifierEntity>();
|
||||
}
|
||||
|
||||
public string TargetProperty { get; set; }
|
||||
public Guid? SourceDataModelGuid { get; set; }
|
||||
public string SourcePropertyPath { get; set; }
|
||||
public int DataBindingMode { get; set; }
|
||||
@ -17,5 +18,6 @@ namespace Artemis.Storage.Entities.Profile.DataBindings
|
||||
public int EasingFunction { get; set; }
|
||||
|
||||
public List<DataBindingModifierEntity> Modifiers { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@ -9,6 +9,7 @@ namespace Artemis.Storage.Entities.Profile
|
||||
public PropertyEntity()
|
||||
{
|
||||
KeyframeEntities = new List<KeyframeEntity>();
|
||||
DataBindingEntities = new List<DataBindingEntity>();
|
||||
}
|
||||
|
||||
public Guid PluginGuid { get; set; }
|
||||
@ -18,6 +19,6 @@ namespace Artemis.Storage.Entities.Profile
|
||||
public bool KeyframesEnabled { get; set; }
|
||||
|
||||
public List<KeyframeEntity> KeyframeEntities { get; set; }
|
||||
public DataBindingEntity DataBindingEntity { get; set; }
|
||||
public List<DataBindingEntity> DataBindingEntities { get; set; }
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,96 @@
|
||||
<UserControl x:Class="Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DataBindingModifierView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800"
|
||||
d:DataContext="{d:DesignInstance local:DataBindingModifierViewModel}">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Button Grid.Column="0"
|
||||
ToolTip="Delete the modifier"
|
||||
Style="{StaticResource MaterialDesignIconForegroundButton}"
|
||||
HorizontalAlignment="Left"
|
||||
Foreground="#E74C4C"
|
||||
Width="25"
|
||||
Height="25"
|
||||
Command="{s:Action Delete}">
|
||||
<materialDesign:PackIcon Kind="Close" Width="18" Height="18" />
|
||||
</Button>
|
||||
<Button Grid.Column="1"
|
||||
ToolTip="Swap modifier type to static/dynamic"
|
||||
Style="{StaticResource MaterialDesignIconForegroundButton}"
|
||||
HorizontalAlignment="Left"
|
||||
Foreground="{StaticResource SecondaryAccentBrush}"
|
||||
Width="25"
|
||||
Height="25"
|
||||
Command="{s:Action SwapType}">
|
||||
<materialDesign:PackIcon Kind="SwapHorizontalVariant" Width="18" Height="18" />
|
||||
</Button>
|
||||
|
||||
<Button Grid.Column="2"
|
||||
Style="{StaticResource DisplayConditionButtonLeftClickMenu}"
|
||||
Background="#7B7B7B"
|
||||
BorderBrush="#7B7B7B"
|
||||
Content="{Binding SelectedOperator.Description}">
|
||||
<!-- Click="PropertyButton_OnClick" -->
|
||||
<Button.ContextMenu>
|
||||
<ContextMenu ItemsSource="{Binding Operators}">
|
||||
<ContextMenu.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<materialDesign:PackIcon Kind="{Binding Icon}" VerticalAlignment="Center" Margin="0 0 15 0" />
|
||||
<TextBlock Text="{Binding Description}" VerticalAlignment="Center" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ContextMenu.ItemTemplate>
|
||||
<ContextMenu.ItemContainerStyle>
|
||||
<Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource MaterialDesignMenuItem}">
|
||||
<Setter Property="Command" Value="{Binding Data.SelectOperatorCommand, Source={StaticResource DataContextProxy}}" />
|
||||
<Setter Property="CommandParameter" Value="{Binding}" />
|
||||
<Setter Property="CommandTarget" Value="{Binding}" />
|
||||
</Style>
|
||||
</ContextMenu.ItemContainerStyle>
|
||||
</ContextMenu>
|
||||
</Button.ContextMenu>
|
||||
</Button>
|
||||
<Button Grid.Column="3"
|
||||
Background="#ab47bc"
|
||||
BorderBrush="#ab47bc"
|
||||
Style="{StaticResource DisplayConditionButton}"
|
||||
ToolTip="{Binding SelectedLeftSideProperty.DisplayPropertyPath}"
|
||||
HorizontalAlignment="Left">
|
||||
<Button.ContextMenu>
|
||||
<ContextMenu ItemsSource="{Binding LeftSideDataModel.Children}" IsOpen="{Binding LeftSideDataModelOpen, 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="CommandParameter" Value="{Binding}" />
|
||||
<Setter Property="CommandTarget" Value="{Binding}" />
|
||||
<Setter Property="IsEnabled" Value="{Binding IsMatchingFilteredTypes}" />
|
||||
<Setter Property="IsSubmenuOpen" Value="{Binding IsVisualizationExpanded, Mode=TwoWay}" />
|
||||
<Setter Property="HeaderTemplate" Value="{StaticResource DataModelDataTemplate}" />
|
||||
</Style>
|
||||
</ContextMenu.ItemContainerStyle>
|
||||
</ContextMenu>
|
||||
</Button.ContextMenu>
|
||||
<Grid>
|
||||
<TextBlock Text="{Binding SelectedLeftSideProperty.PropertyDescription.Name}"
|
||||
Visibility="{Binding SelectedLeftSideProperty, Converter={StaticResource NullToVisibilityConverter}}" />
|
||||
<TextBlock Text="« Select a property »"
|
||||
FontStyle="Italic"
|
||||
Visibility="{Binding SelectedLeftSideProperty, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted}" />
|
||||
</Grid>
|
||||
</Button>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for DataBindingModifierView.xaml
|
||||
/// </summary>
|
||||
public partial class DataBindingModifierView : UserControl
|
||||
{
|
||||
public DataBindingModifierView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
using Artemis.Core;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
{
|
||||
public class DataBindingModifierViewModel : PropertyChangedBase
|
||||
{
|
||||
public DataBindingModifierViewModel(DataBindingModifier modifier)
|
||||
{
|
||||
Modifier = modifier;
|
||||
}
|
||||
|
||||
public DataBindingModifier Modifier { get; }
|
||||
}
|
||||
}
|
||||
@ -8,8 +8,10 @@
|
||||
xmlns:utilities="clr-namespace:Artemis.UI.Utilities"
|
||||
xmlns:dd="urn:gong-wpf-dragdrop"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
xmlns:local="clr-namespace:Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
d:DesignHeight="450" d:DesignWidth="800"
|
||||
d:DataContext="{d:DesignInstance local:DataBindingViewModel}">
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
@ -165,103 +167,20 @@
|
||||
</StackPanel>
|
||||
</Button>
|
||||
|
||||
<!-- ItemsSource="{Binding ModifierViewModels}" -->
|
||||
<ListBox Grid.Row="1"
|
||||
ItemsSource="{Binding ModifierViewModels}"
|
||||
materialDesign:RippleAssist.IsDisabled="True"
|
||||
dd:DragDrop.IsDragSource="True"
|
||||
dd:DragDrop.IsDropTarget="True"
|
||||
dd:DragDrop.UseDefaultDragAdorner="True"
|
||||
dd:DragDrop.DropHandler="{Binding}"
|
||||
HorizontalContentAlignment="Stretch">
|
||||
<!-- <ListBox.ItemTemplate> -->
|
||||
<!-- <DataTemplate> -->
|
||||
<!-- <ContentControl s:View.Model="{Binding}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" IsTabStop="False" /> -->
|
||||
<!-- </DataTemplate> -->
|
||||
<!-- </ListBox.ItemTemplate> -->
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Button Grid.Column="0"
|
||||
ToolTip="Delete the modifier"
|
||||
Style="{StaticResource MaterialDesignIconForegroundButton}"
|
||||
HorizontalAlignment="Left"
|
||||
Foreground="#E74C4C"
|
||||
Width="25"
|
||||
Height="25"
|
||||
Command="{s:Action Delete}">
|
||||
<materialDesign:PackIcon Kind="Close" Width="18" Height="18" />
|
||||
</Button>
|
||||
<Button Grid.Column="1"
|
||||
ToolTip="Swap modifier type to static/dynamic"
|
||||
Style="{StaticResource MaterialDesignIconForegroundButton}"
|
||||
HorizontalAlignment="Left"
|
||||
Foreground="{StaticResource SecondaryAccentBrush}"
|
||||
Width="25"
|
||||
Height="25"
|
||||
Command="{s:Action SwapType}">
|
||||
<materialDesign:PackIcon Kind="SwapHorizontalVariant" Width="18" Height="18" />
|
||||
</Button>
|
||||
|
||||
<Button Grid.Column="2"
|
||||
Style="{StaticResource DisplayConditionButtonLeftClickMenu}"
|
||||
Background="#7B7B7B"
|
||||
BorderBrush="#7B7B7B"
|
||||
Content="{Binding SelectedOperator.Description}">
|
||||
<!-- Click="PropertyButton_OnClick" -->
|
||||
<Button.ContextMenu>
|
||||
<ContextMenu ItemsSource="{Binding Operators}">
|
||||
<ContextMenu.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<materialDesign:PackIcon Kind="{Binding Icon}" VerticalAlignment="Center" Margin="0 0 15 0" />
|
||||
<TextBlock Text="{Binding Description}" VerticalAlignment="Center" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ContextMenu.ItemTemplate>
|
||||
<ContextMenu.ItemContainerStyle>
|
||||
<Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource MaterialDesignMenuItem}">
|
||||
<Setter Property="Command" Value="{Binding Data.SelectOperatorCommand, Source={StaticResource DataContextProxy}}" />
|
||||
<Setter Property="CommandParameter" Value="{Binding}" />
|
||||
<Setter Property="CommandTarget" Value="{Binding}" />
|
||||
</Style>
|
||||
</ContextMenu.ItemContainerStyle>
|
||||
</ContextMenu>
|
||||
</Button.ContextMenu>
|
||||
</Button>
|
||||
<Button Grid.Column="3"
|
||||
Background="#ab47bc"
|
||||
BorderBrush="#ab47bc"
|
||||
Style="{StaticResource DisplayConditionButton}"
|
||||
ToolTip="{Binding SelectedLeftSideProperty.DisplayPropertyPath}"
|
||||
HorizontalAlignment="Left">
|
||||
<Button.ContextMenu>
|
||||
<ContextMenu ItemsSource="{Binding LeftSideDataModel.Children}" IsOpen="{Binding LeftSideDataModelOpen, 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="CommandParameter" Value="{Binding}" />
|
||||
<Setter Property="CommandTarget" Value="{Binding}" />
|
||||
<Setter Property="IsEnabled" Value="{Binding IsMatchingFilteredTypes}" />
|
||||
<Setter Property="IsSubmenuOpen" Value="{Binding IsVisualizationExpanded, Mode=TwoWay}" />
|
||||
<Setter Property="HeaderTemplate" Value="{StaticResource DataModelDataTemplate}" />
|
||||
</Style>
|
||||
</ContextMenu.ItemContainerStyle>
|
||||
</ContextMenu>
|
||||
</Button.ContextMenu>
|
||||
<Grid>
|
||||
<TextBlock Text="{Binding SelectedLeftSideProperty.PropertyDescription.Name}"
|
||||
Visibility="{Binding SelectedLeftSideProperty, Converter={StaticResource NullToVisibilityConverter}}" />
|
||||
<TextBlock Text="« Select a property »"
|
||||
FontStyle="Italic"
|
||||
Visibility="{Binding SelectedLeftSideProperty, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted}" />
|
||||
</Grid>
|
||||
</Button>
|
||||
</Grid>
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<ContentControl s:View.Model="{Binding}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" IsTabStop="False" />
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
|
||||
</ListBox>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System.Reflection;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Artemis.Core;
|
||||
using Stylet;
|
||||
|
||||
@ -6,15 +7,70 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
{
|
||||
public class DataBindingViewModel : PropertyChangedBase
|
||||
{
|
||||
public DataBindingViewModel(BaseLayerProperty layerProperty, PropertyInfo dataBindingProperty)
|
||||
private DataBinding _dataBinding;
|
||||
|
||||
public DataBindingViewModel(BaseLayerProperty layerProperty, PropertyInfo targetProperty)
|
||||
{
|
||||
DisplayName = dataBindingProperty.Name.ToUpper();
|
||||
LayerProperty = layerProperty;
|
||||
DataBindingProperty = dataBindingProperty;
|
||||
TargetProperty = targetProperty;
|
||||
|
||||
DisplayName = TargetProperty.Name.ToUpper();
|
||||
ModifierViewModels = new BindableCollection<DataBindingModifierViewModel>();
|
||||
DataBinding = layerProperty.DataBindings.FirstOrDefault(d => d.TargetProperty == targetProperty);
|
||||
}
|
||||
|
||||
public string DisplayName { get; }
|
||||
public BaseLayerProperty LayerProperty { get; }
|
||||
public PropertyInfo DataBindingProperty { get; }
|
||||
public PropertyInfo TargetProperty { get; }
|
||||
public string DisplayName { get; }
|
||||
public BindableCollection<DataBindingModifierViewModel> ModifierViewModels { get; }
|
||||
|
||||
public DataBinding DataBinding
|
||||
{
|
||||
get => _dataBinding;
|
||||
set
|
||||
{
|
||||
if (!SetAndNotify(ref _dataBinding, value)) return;
|
||||
UpdateModifierViewModels();
|
||||
}
|
||||
}
|
||||
|
||||
public void EnableDataBinding()
|
||||
{
|
||||
if (DataBinding != null)
|
||||
return;
|
||||
|
||||
DataBinding = LayerProperty.AddDataBinding(TargetProperty);
|
||||
}
|
||||
|
||||
public void RemoveDataBinding()
|
||||
{
|
||||
if (DataBinding == null)
|
||||
return;
|
||||
|
||||
var toRemove = DataBinding;
|
||||
DataBinding = null;
|
||||
LayerProperty.RemoveDataBinding(toRemove);
|
||||
}
|
||||
|
||||
public void AddModifier()
|
||||
{
|
||||
if (DataBinding == null)
|
||||
return;
|
||||
|
||||
var modifier = new DataBindingModifier(ProfileRightSideType.Dynamic);
|
||||
DataBinding.AddModifier(modifier);
|
||||
|
||||
ModifierViewModels.Add(new DataBindingModifierViewModel(modifier));
|
||||
}
|
||||
|
||||
private void UpdateModifierViewModels()
|
||||
{
|
||||
ModifierViewModels.Clear();
|
||||
if (DataBinding == null)
|
||||
return;
|
||||
|
||||
foreach (var dataBindingModifier in DataBinding.Modifiers)
|
||||
ModifierViewModels.Add(new DataBindingModifierViewModel(dataBindingModifier));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -31,16 +31,21 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
|
||||
private void Initialise()
|
||||
{
|
||||
DataBindingViewModel = null;
|
||||
DataBindingsTabsViewModel = null;
|
||||
|
||||
var properties = LayerProperty.GetDataBindingProperties();
|
||||
if (properties.Count == 0)
|
||||
if (properties == null || properties.Count == 0)
|
||||
return;
|
||||
|
||||
// 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());
|
||||
else
|
||||
{
|
||||
DataBindingsTabsViewModel = new DataBindingsTabsViewModel();
|
||||
foreach (var dataBindingProperty in LayerProperty.GetDataBindingProperties())
|
||||
foreach (var dataBindingProperty in properties)
|
||||
DataBindingsTabsViewModel.Tabs.Add(new DataBindingViewModel(LayerProperty, dataBindingProperty));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,8 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Artemis.Core.LayerBrushes;
|
||||
using Artemis.Core.LayerEffects;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Exceptions;
|
||||
using Artemis.UI.Screens.ProfileEditor.Dialogs;
|
||||
using Artemis.UI.Screens.ProfileEditor.LayerProperties.Abstract;
|
||||
using Artemis.UI.Shared.Services;
|
||||
@ -39,33 +42,48 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree
|
||||
|
||||
public void OpenBrushSettings()
|
||||
{
|
||||
var configurationViewModel = LayerPropertyGroupViewModel.LayerPropertyGroup.LayerBrush.ConfigurationDialog;
|
||||
var layerBrush = LayerPropertyGroupViewModel.LayerPropertyGroup.LayerBrush;
|
||||
var configurationViewModel = layerBrush.ConfigurationDialog;
|
||||
if (configurationViewModel == null)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
var layerBrush = new ConstructorArgument("layerBrush", LayerPropertyGroupViewModel.LayerPropertyGroup.LayerBrush);
|
||||
var viewModel = (BrushConfigurationViewModel) _kernel.Get(configurationViewModel.Type, layerBrush);
|
||||
// Limit to one constructor, there's no need to have more and it complicates things anyway
|
||||
var constructors = configurationViewModel.Type.GetConstructors();
|
||||
if (constructors.Length != 1)
|
||||
throw new ArtemisUIException("Brush configuration dialogs must have exactly one constructor");
|
||||
|
||||
// Find the BaseLayerBrush parameter, it is required by the base constructor so its there for sure
|
||||
var brushParameter = constructors.First().GetParameters().First(p => typeof(BaseLayerBrush).IsAssignableFrom(p.ParameterType));
|
||||
var argument = new ConstructorArgument(brushParameter.Name, layerBrush);
|
||||
var viewModel = (BrushConfigurationViewModel) _kernel.Get(configurationViewModel.Type, argument);
|
||||
|
||||
_windowManager.ShowDialog(new LayerBrushSettingsWindowViewModel(viewModel));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_dialogService.ShowExceptionDialog("An exception occured while trying to show the brush's settings window", e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void OpenEffectSettings()
|
||||
{
|
||||
var configurationViewModel = LayerPropertyGroupViewModel.LayerPropertyGroup.LayerEffect.ConfigurationDialog;
|
||||
var layerEffect = LayerPropertyGroupViewModel.LayerPropertyGroup.LayerEffect;
|
||||
var configurationViewModel = layerEffect.ConfigurationDialog;
|
||||
if (configurationViewModel == null)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
var layerEffect = new ConstructorArgument("layerEffect", LayerPropertyGroupViewModel.LayerPropertyGroup.LayerEffect);
|
||||
var viewModel = (EffectConfigurationViewModel) _kernel.Get(configurationViewModel.Type, layerEffect);
|
||||
// Limit to one constructor, there's no need to have more and it complicates things anyway
|
||||
var constructors = configurationViewModel.Type.GetConstructors();
|
||||
if (constructors.Length != 1)
|
||||
throw new ArtemisUIException("Effect configuration dialogs must have exactly one constructor");
|
||||
|
||||
var effectParameter = constructors.First().GetParameters().First(p => typeof(BaseLayerEffect).IsAssignableFrom(p.ParameterType));
|
||||
var argument = new ConstructorArgument(effectParameter.Name, layerEffect);
|
||||
var viewModel = (EffectConfigurationViewModel) _kernel.Get(configurationViewModel.Type, argument);
|
||||
_windowManager.ShowDialog(new LayerEffectSettingsWindowViewModel(viewModel));
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
@ -10,6 +10,7 @@ using Artemis.Core.LayerBrushes;
|
||||
using Artemis.Core.LayerEffects;
|
||||
using Artemis.Core.Modules;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Exceptions;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using Ninject;
|
||||
@ -88,7 +89,13 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
||||
|
||||
try
|
||||
{
|
||||
var plugin = new ConstructorArgument("plugin", Plugin);
|
||||
// Limit to one constructor, there's no need to have more and it complicates things anyway
|
||||
var constructors = configurationViewModel.Type.GetConstructors();
|
||||
if (constructors.Length != 1)
|
||||
throw new ArtemisUIException("Plugin configuration dialogs must have exactly one constructor");
|
||||
|
||||
var pluginParameter = constructors.First().GetParameters().First(p => typeof(Plugin).IsAssignableFrom(p.ParameterType));
|
||||
var plugin = new ConstructorArgument(pluginParameter.Name, Plugin);
|
||||
var viewModel = (PluginConfigurationViewModel) _kernel.Get(configurationViewModel.Type, plugin);
|
||||
_windowManager.ShowDialog(new PluginSettingsWindowViewModel(viewModel, Icon));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user