mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Conditions - Removed old systems
Data bindings - Removed old systems Data bindings - Implemented node system
This commit is contained in:
1 parent
32d4ec2812
commit
5675d1895b
157 files changed
+784
-8802
No files matched your search
-55
@@ -1,55 +0,0 @@
|
||||
<UserControl x:Class="Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.ConditionalDataBinding.ConditionalDataBindingModeView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
xmlns:dd="urn:gong-wpf-dragdrop"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="pack://application:,,,/Artemis.UI;component/ResourceDictionaries/DataModelConditions.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Button Grid.Row="0"
|
||||
Style="{StaticResource DataModelConditionButton}"
|
||||
Background="{StaticResource PrimaryHueMidBrush}"
|
||||
BorderBrush="{StaticResource PrimaryHueMidBrush}"
|
||||
HorizontalAlignment="Right"
|
||||
Command="{s:Action AddCondition}"
|
||||
Margin="0 5">
|
||||
ADD CONDITION
|
||||
</Button>
|
||||
|
||||
<ListBox Grid.Row="1"
|
||||
ItemsSource="{Binding Items}"
|
||||
materialDesign:RippleAssist.IsDisabled="True"
|
||||
dd:DragDrop.IsDragSource="True"
|
||||
dd:DragDrop.IsDropTarget="True"
|
||||
dd:DragDrop.UseDefaultDragAdorner="True"
|
||||
HorizontalContentAlignment="Stretch"
|
||||
VirtualizingPanel.ScrollUnit="Pixel"
|
||||
Margin="-10 0 -10 -5">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<ContentControl s:View.Model="{Binding}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" IsTabStop="False"/>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
<ListBox.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<VirtualizingStackPanel/>
|
||||
</ItemsPanelTemplate>
|
||||
</ListBox.ItemsPanel>
|
||||
</ListBox>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
-131
@@ -1,131 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using Artemis.Core;
|
||||
using Artemis.UI.Extensions;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.ConditionalDataBinding
|
||||
{
|
||||
public sealed class ConditionalDataBindingModeViewModel<TLayerProperty, TProperty> : Conductor<DataBindingConditionViewModel<TLayerProperty, TProperty>>.Collection.AllActive,
|
||||
IDataBindingModeViewModel
|
||||
{
|
||||
private readonly IDataBindingsVmFactory _dataBindingsVmFactory;
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private bool _updating;
|
||||
|
||||
public ConditionalDataBindingModeViewModel(ConditionalDataBinding<TLayerProperty, TProperty> conditionalDataBinding,
|
||||
IProfileEditorService profileEditorService,
|
||||
IDataBindingsVmFactory dataBindingsVmFactory)
|
||||
{
|
||||
_profileEditorService = profileEditorService;
|
||||
_dataBindingsVmFactory = dataBindingsVmFactory;
|
||||
|
||||
ConditionalDataBinding = conditionalDataBinding;
|
||||
}
|
||||
|
||||
public ConditionalDataBinding<TLayerProperty, TProperty> ConditionalDataBinding { get; }
|
||||
|
||||
public void AddCondition()
|
||||
{
|
||||
DataBindingCondition<TLayerProperty, TProperty> condition = ConditionalDataBinding.AddCondition();
|
||||
|
||||
// Find the VM of the new condition
|
||||
DataBindingConditionViewModel<TLayerProperty, TProperty> viewModel = Items.First(c => c.DataBindingCondition == condition);
|
||||
viewModel.ActiveItem.AddCondition();
|
||||
|
||||
_profileEditorService.SaveSelectedProfileElement();
|
||||
}
|
||||
|
||||
public void RemoveCondition(DataBindingCondition<TLayerProperty, TProperty> dataBindingCondition)
|
||||
{
|
||||
ConditionalDataBinding.RemoveCondition(dataBindingCondition);
|
||||
}
|
||||
|
||||
protected override void OnInitialActivate()
|
||||
{
|
||||
Initialize();
|
||||
base.OnInitialActivate();
|
||||
}
|
||||
|
||||
private void UpdateItems()
|
||||
{
|
||||
_updating = true;
|
||||
|
||||
// Remove old VMs
|
||||
List<DataBindingConditionViewModel<TLayerProperty, TProperty>> toRemove = Items.Where(c => !ConditionalDataBinding.Conditions.Contains(c.DataBindingCondition)).ToList();
|
||||
foreach (DataBindingConditionViewModel<TLayerProperty, TProperty> dataBindingConditionViewModel in toRemove)
|
||||
{
|
||||
Items.Remove(dataBindingConditionViewModel);
|
||||
dataBindingConditionViewModel.Dispose();
|
||||
}
|
||||
|
||||
// Add missing VMs
|
||||
foreach (DataBindingCondition<TLayerProperty, TProperty> condition in ConditionalDataBinding.Conditions)
|
||||
if (Items.All(c => c.DataBindingCondition != condition))
|
||||
Items.Add(_dataBindingsVmFactory.DataBindingConditionViewModel(condition));
|
||||
|
||||
// Fix order
|
||||
((BindableCollection<DataBindingConditionViewModel<TLayerProperty, TProperty>>) Items).Sort(c => c.DataBindingCondition.Order);
|
||||
|
||||
_updating = false;
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
ConditionalDataBinding.ConditionsUpdated += ConditionalDataBindingOnConditionsUpdated;
|
||||
Items.CollectionChanged += ItemsOnCollectionChanged;
|
||||
UpdateItems();
|
||||
}
|
||||
|
||||
private void ItemsOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
if (_updating || e.Action != NotifyCollectionChangedAction.Add)
|
||||
return;
|
||||
|
||||
for (int index = 0; index < Items.Count; index++)
|
||||
{
|
||||
DataBindingConditionViewModel<TLayerProperty, TProperty> conditionViewModel = Items[index];
|
||||
conditionViewModel.DataBindingCondition.Order = index + 1;
|
||||
}
|
||||
|
||||
ConditionalDataBinding.ApplyOrder();
|
||||
|
||||
_profileEditorService.SaveSelectedProfileElement();
|
||||
}
|
||||
|
||||
private void ConditionalDataBindingOnConditionsUpdated(object sender, EventArgs e)
|
||||
{
|
||||
UpdateItems();
|
||||
}
|
||||
|
||||
public bool SupportsTestValue => false;
|
||||
|
||||
public void Update()
|
||||
{
|
||||
UpdateItems();
|
||||
}
|
||||
|
||||
public object GetTestValue()
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
#region IDisposable
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
ConditionalDataBinding.ConditionsUpdated -= ConditionalDataBindingOnConditionsUpdated;
|
||||
|
||||
foreach (DataBindingConditionViewModel<TLayerProperty, TProperty> conditionViewModel in Items)
|
||||
conditionViewModel.Dispose();
|
||||
Items.Clear();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
-66
@@ -1,66 +0,0 @@
|
||||
<UserControl x:Class="Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.ConditionalDataBinding.DataBindingConditionView"
|
||||
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:s="https://github.com/canton7/Stylet"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<Border BorderThickness="0 0 0 1"
|
||||
BorderBrush="{DynamicResource MaterialDesignDivider}"
|
||||
Margin="0 0 0 -4"
|
||||
Padding="0 4"
|
||||
Background="Transparent">
|
||||
<Border.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="Add new condition" Command="{s:Action AddCondition}">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="CodeNotEqual" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<Separator />
|
||||
<MenuItem Header="Duplicate" Command="{s:Action DuplicateCondition}" InputGestureText="Ctrl+D" IsEnabled="False">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="ContentDuplicate" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Copy" Command="{s:Action CopyCondition}" InputGestureText="Ctrl+C" IsEnabled="False">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="ContentCopy" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Paste" Command="{s:Action PasteCondition}" InputGestureText="Ctrl+V" IsEnabled="False">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="ContentPaste" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<Separator />
|
||||
<MenuItem Header="Delete" Command="{s:Action RemoveCondition}" InputGestureText="Del">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="TrashCan" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
</ContextMenu>
|
||||
</Border.ContextMenu>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<ContentControl Grid.Row="0"
|
||||
s:View.Model="{Binding ActiveItem}"
|
||||
VerticalContentAlignment="Stretch"
|
||||
HorizontalContentAlignment="Stretch"
|
||||
IsTabStop="False"
|
||||
Margin="0 -10 0 0"/>
|
||||
|
||||
<ContentControl Grid.Row="1"
|
||||
Margin="26 0 0 0"
|
||||
s:View.Model="{Binding ValueViewModel}"
|
||||
VerticalContentAlignment="Stretch"
|
||||
HorizontalContentAlignment="Stretch"
|
||||
IsTabStop="False" />
|
||||
</Grid>
|
||||
</Border>
|
||||
</UserControl>
|
||||
-86
@@ -1,86 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Modules;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
using Artemis.UI.Screens.ProfileEditor.Conditions;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Input;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.ConditionalDataBinding
|
||||
{
|
||||
public sealed class DataBindingConditionViewModel<TLayerProperty, TProperty> : Conductor<DataModelConditionGroupViewModel>, IDisposable
|
||||
{
|
||||
private readonly IDataModelConditionsVmFactory _dataModelConditionsVmFactory;
|
||||
private readonly IDataModelUIService _dataModelUIService;
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
|
||||
public DataBindingConditionViewModel(DataBindingCondition<TLayerProperty, TProperty> dataBindingCondition,
|
||||
IProfileEditorService profileEditorService,
|
||||
IDataModelConditionsVmFactory dataModelConditionsVmFactory,
|
||||
IDataModelUIService dataModelUIService)
|
||||
{
|
||||
_profileEditorService = profileEditorService;
|
||||
_dataModelConditionsVmFactory = dataModelConditionsVmFactory;
|
||||
_dataModelUIService = dataModelUIService;
|
||||
DataBindingCondition = dataBindingCondition;
|
||||
}
|
||||
|
||||
public DataBindingCondition<TLayerProperty, TProperty> DataBindingCondition { get; }
|
||||
|
||||
public DataModelStaticViewModel ValueViewModel { get; set; }
|
||||
|
||||
protected override void OnInitialActivate()
|
||||
{
|
||||
base.OnInitialActivate();
|
||||
List<Module> modules = new();
|
||||
if (_profileEditorService.SelectedProfileConfiguration?.Module != null)
|
||||
modules.Add(_profileEditorService.SelectedProfileConfiguration.Module);
|
||||
ActiveItem = _dataModelConditionsVmFactory.DataModelConditionGroupViewModel(DataBindingCondition.Condition, ConditionGroupType.General, modules);
|
||||
ActiveItem.IsRootGroup = true;
|
||||
|
||||
ActiveItem.Update();
|
||||
ActiveItem.Updated += ActiveItemOnUpdated;
|
||||
|
||||
ValueViewModel = _dataModelUIService.GetStaticInputViewModel(typeof(TProperty), null);
|
||||
ValueViewModel.ValueUpdated += ValueViewModelOnValueUpdated;
|
||||
ValueViewModel.Value = DataBindingCondition.Value;
|
||||
}
|
||||
|
||||
private void ActiveItemOnUpdated(object sender, EventArgs e)
|
||||
{
|
||||
if (!ActiveItem.GetChildren().Any())
|
||||
DataBindingCondition.ConditionalDataBinding.RemoveCondition(DataBindingCondition);
|
||||
}
|
||||
|
||||
private void ValueViewModelOnValueUpdated(object sender, DataModelInputStaticEventArgs e)
|
||||
{
|
||||
DataBindingCondition.Value = (TProperty) Convert.ChangeType(e.Value, typeof(TProperty));
|
||||
_profileEditorService.SaveSelectedProfileElement();
|
||||
}
|
||||
|
||||
public void AddCondition()
|
||||
{
|
||||
((ConditionalDataBindingModeViewModel<TLayerProperty, TProperty>) Parent).AddCondition();
|
||||
}
|
||||
|
||||
public void RemoveCondition()
|
||||
{
|
||||
((ConditionalDataBindingModeViewModel<TLayerProperty, TProperty>)Parent).RemoveCondition(DataBindingCondition);
|
||||
|
||||
}
|
||||
|
||||
#region IDisposable
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
ValueViewModel?.Dispose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+4
-16
@@ -5,6 +5,7 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
xmlns:controls="clr-namespace:Artemis.VisualScripting.Editor.Controls;assembly=Artemis.VisualScripting"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<UserControl.Resources>
|
||||
@@ -36,16 +37,8 @@
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<ComboBox Grid.Row="0"
|
||||
Style="{StaticResource MaterialDesignFilledComboBox}"
|
||||
Margin="0 5"
|
||||
materialDesign:HintAssist.Hint="Data binding mode"
|
||||
MinWidth="128"
|
||||
SelectedValue="{Binding SelectedDataBindingMode}"
|
||||
ItemsSource="{Binding DataBindingModes}"
|
||||
SelectedValuePath="Value"
|
||||
DisplayMemberPath="Description" />
|
||||
|
||||
<CheckBox Grid.Row="0" Margin="0 10" IsChecked="{Binding IsDataBindingEnabled}">Enable data binding</CheckBox>
|
||||
|
||||
<TextBox Grid.Row="1"
|
||||
Style="{StaticResource MaterialDesignFilledTextBox}"
|
||||
Margin="0 5"
|
||||
@@ -168,12 +161,7 @@
|
||||
</materialDesign:Card>
|
||||
|
||||
<materialDesign:Card Grid.Column="1" UniformCornerRadius="0" Background="{DynamicResource MaterialDesignToolBarBackground}" Panel.ZIndex="1">
|
||||
<Grid Margin="10 5">
|
||||
<ContentControl s:View.Model="{Binding ActiveItem}"
|
||||
VerticalContentAlignment="Stretch"
|
||||
HorizontalContentAlignment="Stretch"
|
||||
IsTabStop="False" />
|
||||
</Grid>
|
||||
<controls:VisualScriptEditor Script="{Binding Script}" AvailableNodes="{Binding AvailableNodes}"></controls:VisualScriptEditor>
|
||||
</materialDesign:Card>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
+127
-189
@@ -1,11 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Timers;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.Storage.Entities.Profile.DataBindings;
|
||||
using Artemis.UI.Exceptions;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
using Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Services;
|
||||
@@ -13,63 +12,62 @@ using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
{
|
||||
public sealed class DataBindingViewModel<TLayerProperty, TProperty> : Conductor<IDataBindingModeViewModel>, IDataBindingViewModel
|
||||
public sealed class DataBindingViewModel<TLayerProperty, TProperty> : Screen, IDataBindingViewModel
|
||||
{
|
||||
private readonly IDataBindingsVmFactory _dataBindingsVmFactory;
|
||||
private readonly ICoreService _coreService;
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private int _easingTime;
|
||||
private bool _isDataBindingEnabled;
|
||||
private bool _isEasingTimeEnabled;
|
||||
private DataBindingModeType _selectedDataBindingMode;
|
||||
private DateTime _lastUpdate;
|
||||
private TimelineEasingViewModel _selectedEasingViewModel;
|
||||
|
||||
private bool _updating;
|
||||
private bool _updatingTestResult;
|
||||
private DateTime _lastUpdate;
|
||||
|
||||
public DataBindingViewModel(DataBindingRegistration<TLayerProperty, TProperty> registration,
|
||||
ICoreService coreService,
|
||||
ISettingsService settingsService,
|
||||
IProfileEditorService profileEditorService,
|
||||
IDataModelUIService dataModelUIService,
|
||||
IDataBindingsVmFactory dataBindingsVmFactory)
|
||||
INodeService nodeService)
|
||||
{
|
||||
Registration = registration;
|
||||
_coreService = coreService;
|
||||
_profileEditorService = profileEditorService;
|
||||
_dataBindingsVmFactory = dataBindingsVmFactory;
|
||||
|
||||
DisplayName = Registration.DisplayName.ToUpper();
|
||||
AlwaysApplyDataBindings = settingsService.GetSetting("ProfileEditor.AlwaysApplyDataBindings", true);
|
||||
DataBindingModes = new BindableCollection<ValueDescription>(EnumUtilities.GetAllValuesAndDescriptions(typeof(DataBindingModeType)));
|
||||
EasingViewModels = new BindableCollection<TimelineEasingViewModel>();
|
||||
AvailableNodes = nodeService.AvailableNodes;
|
||||
TestInputValue = dataModelUIService.GetDataModelDisplayViewModel(typeof(TProperty), null, true);
|
||||
TestResultValue = dataModelUIService.GetDataModelDisplayViewModel(typeof(TProperty), null, true);
|
||||
}
|
||||
|
||||
public DataBindingRegistration<TLayerProperty, TProperty> Registration { get; }
|
||||
public NodeScript<TProperty> Script => Registration.DataBinding?.Script;
|
||||
|
||||
public PluginSetting<bool> AlwaysApplyDataBindings { get; }
|
||||
public BindableCollection<ValueDescription> DataBindingModes { get; }
|
||||
public BindableCollection<TimelineEasingViewModel> EasingViewModels { get; }
|
||||
public IEnumerable<NodeData> AvailableNodes { get; }
|
||||
public DataModelDisplayViewModel TestInputValue { get; }
|
||||
public DataModelDisplayViewModel TestResultValue { get; }
|
||||
|
||||
public DataBindingModeType SelectedDataBindingMode
|
||||
{
|
||||
get => _selectedDataBindingMode;
|
||||
set
|
||||
{
|
||||
if (!SetAndNotify(ref _selectedDataBindingMode, value)) return;
|
||||
ApplyDataBindingMode();
|
||||
Update();
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsDataBindingEnabled
|
||||
{
|
||||
get => _isDataBindingEnabled;
|
||||
set => SetAndNotify(ref _isDataBindingEnabled, value);
|
||||
set
|
||||
{
|
||||
SetAndNotify(ref _isDataBindingEnabled, value);
|
||||
if (_updating)
|
||||
return;
|
||||
|
||||
if (value)
|
||||
EnableDataBinding();
|
||||
else
|
||||
DisableDataBinding();
|
||||
}
|
||||
}
|
||||
|
||||
public TimelineEasingViewModel SelectedEasingViewModel
|
||||
@@ -102,162 +100,6 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnInitialActivate()
|
||||
{
|
||||
Initialize();
|
||||
base.OnInitialActivate();
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
EasingViewModels.AddRange(Enum.GetValues(typeof(Easings.Functions)).Cast<Easings.Functions>().Select(v => new TimelineEasingViewModel(v, false)));
|
||||
|
||||
_lastUpdate = DateTime.Now;
|
||||
_coreService.FrameRendered += OnFrameRendered;
|
||||
CreateDataBindingModeModeViewModel();
|
||||
Update();
|
||||
}
|
||||
|
||||
private void CreateDataBindingModeModeViewModel()
|
||||
{
|
||||
if (Registration.DataBinding?.DataBindingMode == null)
|
||||
{
|
||||
ActiveItem = null;
|
||||
return;
|
||||
}
|
||||
|
||||
switch (Registration.DataBinding.DataBindingMode)
|
||||
{
|
||||
case DirectDataBinding<TLayerProperty, TProperty> directDataBinding:
|
||||
ActiveItem = _dataBindingsVmFactory.DirectDataBindingModeViewModel(directDataBinding);
|
||||
break;
|
||||
case ConditionalDataBinding<TLayerProperty, TProperty> conditionalDataBinding:
|
||||
ActiveItem = _dataBindingsVmFactory.ConditionalDataBindingModeViewModel(conditionalDataBinding);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (_updating)
|
||||
return;
|
||||
|
||||
if (Registration.DataBinding == null)
|
||||
{
|
||||
IsDataBindingEnabled = false;
|
||||
IsEasingTimeEnabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
_updating = true;
|
||||
|
||||
IsDataBindingEnabled = ActiveItem != null;
|
||||
EasingTime = (int) Registration.DataBinding.EasingTime.TotalMilliseconds;
|
||||
SelectedEasingViewModel = EasingViewModels.First(vm => vm.EasingFunction == Registration.DataBinding.EasingFunction);
|
||||
IsEasingTimeEnabled = EasingTime > 0;
|
||||
SelectedDataBindingMode = Registration.DataBinding.DataBindingMode switch
|
||||
{
|
||||
DirectDataBinding<TLayerProperty, TProperty> _ => DataBindingModeType.Direct,
|
||||
ConditionalDataBinding<TLayerProperty, TProperty> _ => DataBindingModeType.Conditional,
|
||||
_ => DataBindingModeType.None
|
||||
};
|
||||
|
||||
ActiveItem?.Update();
|
||||
|
||||
_updating = false;
|
||||
}
|
||||
|
||||
private void ApplyChanges()
|
||||
{
|
||||
if (_updating)
|
||||
return;
|
||||
|
||||
if (Registration.DataBinding != null)
|
||||
{
|
||||
Registration.DataBinding.EasingTime = TimeSpan.FromMilliseconds(EasingTime);
|
||||
Registration.DataBinding.EasingFunction = SelectedEasingViewModel?.EasingFunction ?? Easings.Functions.Linear;
|
||||
}
|
||||
|
||||
_profileEditorService.SaveSelectedProfileElement();
|
||||
Update();
|
||||
}
|
||||
|
||||
private void ApplyDataBindingMode()
|
||||
{
|
||||
if (_updating)
|
||||
return;
|
||||
|
||||
if (Registration.DataBinding != null && SelectedDataBindingMode == DataBindingModeType.None)
|
||||
RemoveDataBinding();
|
||||
else
|
||||
{
|
||||
if (Registration.DataBinding == null && SelectedDataBindingMode != DataBindingModeType.None)
|
||||
EnableDataBinding();
|
||||
|
||||
Registration.DataBinding!.ChangeDataBindingMode(SelectedDataBindingMode);
|
||||
}
|
||||
|
||||
CreateDataBindingModeModeViewModel();
|
||||
_profileEditorService.SaveSelectedProfileElement();
|
||||
}
|
||||
|
||||
private void UpdateTestResult()
|
||||
{
|
||||
if (_updating || _updatingTestResult)
|
||||
return;
|
||||
|
||||
_updatingTestResult = true;
|
||||
if (Registration.DataBinding == null || ActiveItem == null)
|
||||
{
|
||||
TestInputValue.UpdateValue(default);
|
||||
TestResultValue.UpdateValue(default);
|
||||
_updatingTestResult = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// If always update is disabled, do constantly update the data binding as long as the view model is open
|
||||
// If always update is enabled, this is done for all data bindings in ProfileViewModel
|
||||
if (!AlwaysApplyDataBindings.Value)
|
||||
{
|
||||
Registration.DataBinding.UpdateWithDelta(DateTime.Now - _lastUpdate);
|
||||
_profileEditorService.UpdateProfilePreview();
|
||||
}
|
||||
|
||||
if (ActiveItem.SupportsTestValue)
|
||||
{
|
||||
TProperty currentValue = Registration.Converter.ConvertFromObject(ActiveItem?.GetTestValue() ?? default(TProperty));
|
||||
TestInputValue.UpdateValue(currentValue);
|
||||
TestResultValue.UpdateValue(Registration.DataBinding != null ? Registration.DataBinding.GetValue(currentValue) : default);
|
||||
}
|
||||
else
|
||||
{
|
||||
TestResultValue.UpdateValue(Registration.DataBinding != null ? Registration.DataBinding.GetValue(default) : default);
|
||||
}
|
||||
|
||||
_updatingTestResult = false;
|
||||
}
|
||||
|
||||
private void EnableDataBinding()
|
||||
{
|
||||
if (Registration.DataBinding != null)
|
||||
return;
|
||||
|
||||
Registration.LayerProperty.EnableDataBinding(Registration);
|
||||
_profileEditorService.SaveSelectedProfileElement();
|
||||
}
|
||||
|
||||
private void RemoveDataBinding()
|
||||
{
|
||||
if (Registration.DataBinding == null)
|
||||
return;
|
||||
|
||||
ActiveItem = null;
|
||||
Registration.LayerProperty.DisableDataBinding(Registration.DataBinding);
|
||||
Update();
|
||||
|
||||
_profileEditorService.SaveSelectedProfileElement();
|
||||
}
|
||||
|
||||
public void CopyDataBinding()
|
||||
{
|
||||
if (Registration.DataBinding != null)
|
||||
@@ -277,10 +119,115 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
|
||||
Registration.DataBinding.EasingTime = dataBindingEntity.EasingTime;
|
||||
Registration.DataBinding.EasingFunction = (Easings.Functions) dataBindingEntity.EasingFunction;
|
||||
Registration.DataBinding.ApplyDataBindingEntity(dataBindingEntity.DataBindingMode);
|
||||
CreateDataBindingModeModeViewModel();
|
||||
|
||||
// TODO - Paste visual script
|
||||
|
||||
Update();
|
||||
|
||||
_profileEditorService.SaveSelectedProfileElement();
|
||||
}
|
||||
|
||||
protected override void OnInitialActivate()
|
||||
{
|
||||
Initialize();
|
||||
base.OnInitialActivate();
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
EasingViewModels.AddRange(Enum.GetValues(typeof(Easings.Functions)).Cast<Easings.Functions>().Select(v => new TimelineEasingViewModel(v, false)));
|
||||
|
||||
_lastUpdate = DateTime.Now;
|
||||
_coreService.FrameRendered += OnFrameRendered;
|
||||
Update();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (_updating)
|
||||
return;
|
||||
|
||||
if (Registration.DataBinding == null)
|
||||
{
|
||||
IsDataBindingEnabled = false;
|
||||
IsEasingTimeEnabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
_updating = true;
|
||||
|
||||
EasingTime = (int) Registration.DataBinding.EasingTime.TotalMilliseconds;
|
||||
SelectedEasingViewModel = EasingViewModels.First(vm => vm.EasingFunction == Registration.DataBinding.EasingFunction);
|
||||
IsDataBindingEnabled = true;
|
||||
IsEasingTimeEnabled = EasingTime > 0;
|
||||
|
||||
_updating = false;
|
||||
}
|
||||
|
||||
private void ApplyChanges()
|
||||
{
|
||||
if (_updating)
|
||||
return;
|
||||
|
||||
if (Registration.DataBinding != null)
|
||||
{
|
||||
Registration.DataBinding.EasingTime = TimeSpan.FromMilliseconds(EasingTime);
|
||||
Registration.DataBinding.EasingFunction = SelectedEasingViewModel?.EasingFunction ?? Easings.Functions.Linear;
|
||||
}
|
||||
|
||||
_profileEditorService.SaveSelectedProfileElement();
|
||||
Update();
|
||||
}
|
||||
|
||||
private void UpdateTestResult()
|
||||
{
|
||||
if (_updating || _updatingTestResult)
|
||||
return;
|
||||
|
||||
_updatingTestResult = true;
|
||||
|
||||
if (Registration.DataBinding == null)
|
||||
{
|
||||
TestInputValue.UpdateValue(default);
|
||||
TestResultValue.UpdateValue(default);
|
||||
_updatingTestResult = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// If always update is disabled, do constantly update the data binding as long as the view model is open
|
||||
// If always update is enabled, this is done for all data bindings in ProfileViewModel
|
||||
if (!AlwaysApplyDataBindings.Value)
|
||||
{
|
||||
Registration.DataBinding.UpdateWithDelta(DateTime.Now - _lastUpdate);
|
||||
_profileEditorService.UpdateProfilePreview();
|
||||
}
|
||||
|
||||
TProperty currentValue = Registration.Converter.ConvertFromObject(Registration.DataBinding.Script.Result ?? default(TProperty));
|
||||
TestInputValue.UpdateValue(currentValue);
|
||||
TestResultValue.UpdateValue(Registration.DataBinding != null ? Registration.DataBinding.GetValue(currentValue) : default);
|
||||
|
||||
_updatingTestResult = false;
|
||||
}
|
||||
|
||||
private void EnableDataBinding()
|
||||
{
|
||||
if (Registration.DataBinding != null)
|
||||
return;
|
||||
|
||||
Registration.LayerProperty.EnableDataBinding(Registration);
|
||||
NotifyOfPropertyChange(nameof(Script));
|
||||
|
||||
_profileEditorService.SaveSelectedProfileElement();
|
||||
}
|
||||
|
||||
private void DisableDataBinding()
|
||||
{
|
||||
if (Registration.DataBinding == null)
|
||||
return;
|
||||
|
||||
Registration.LayerProperty.DisableDataBinding(Registration.DataBinding);
|
||||
NotifyOfPropertyChange(nameof(Script));
|
||||
Update();
|
||||
|
||||
|
||||
_profileEditorService.SaveSelectedProfileElement();
|
||||
}
|
||||
@@ -291,20 +238,11 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
_lastUpdate = DateTime.Now;
|
||||
}
|
||||
|
||||
private void OnUpdateTimerOnElapsed(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
UpdateTestResult();
|
||||
}
|
||||
|
||||
#region IDisposable
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
_coreService.FrameRendered -= OnFrameRendered;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public interface IDataBindingViewModel : IScreen, IDisposable
|
||||
|
||||
-97
@@ -1,97 +0,0 @@
|
||||
<UserControl x:Class="Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDataBinding.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: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"
|
||||
xmlns:local="clr-namespace:Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDataBinding"
|
||||
xmlns:modifierTypes="clr-namespace:Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDataBinding.ModifierTypes"
|
||||
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="pack://application:,,,/Artemis.UI;component/ResourceDictionaries/DataModelConditions.xaml" />
|
||||
<ResourceDictionary>
|
||||
<shared:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
|
||||
<utilities:BindingProxy x:Key="DataContextProxy" Data="{Binding}" />
|
||||
</ResourceDictionary>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<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"
|
||||
Style="{StaticResource DataModelConditionButtonLeftClickMenu}"
|
||||
Background="#7B7B7B"
|
||||
BorderBrush="#7B7B7B"
|
||||
Click="PropertyButton_OnClick">
|
||||
<Button.ContextMenu>
|
||||
<ContextMenu ItemsSource="{Binding ModifierTypeViewModels.Children}">
|
||||
<ContextMenu.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel>
|
||||
<StackPanel.Resources>
|
||||
<DataTemplate DataType="{x:Type modifierTypes:ModifierTypeCategoryViewModel}">
|
||||
<TextBlock Text="{Binding Category}" />
|
||||
</DataTemplate>
|
||||
<DataTemplate DataType="{x:Type modifierTypes:ModifierTypeViewModel}">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<materialDesign:PackIcon Kind="{Binding ModifierType.Icon}"
|
||||
VerticalAlignment="Center"
|
||||
Margin="0 0 15 0"
|
||||
Visibility="{Binding ModifierType.Icon, Converter={StaticResource NullToVisibilityConverter}}"/>
|
||||
<TextBlock Text="{Binding ModifierType.Name}"
|
||||
VerticalAlignment="Center"
|
||||
ToolTip="{Binding ModifierType.Description}"/>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</StackPanel.Resources>
|
||||
<ContentPresenter Content="{Binding}" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ContextMenu.ItemTemplate>
|
||||
<ContextMenu.ItemContainerStyle>
|
||||
<Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource MaterialDesignMenuItem}">
|
||||
<Setter Property="ItemsSource" Value="{Binding Children}" />
|
||||
<Setter Property="Command" Value="{Binding Data.SelectModifierTypeCommand, Source={StaticResource DataContextProxy}}" />
|
||||
<Setter Property="CommandParameter" Value="{Binding}" />
|
||||
<Setter Property="CommandTarget" Value="{Binding}" />
|
||||
</Style>
|
||||
</ContextMenu.ItemContainerStyle>
|
||||
</ContextMenu>
|
||||
</Button.ContextMenu>
|
||||
<Grid>
|
||||
<TextBlock Text="{Binding SelectedModifierType.Name}"
|
||||
Visibility="{Binding SelectedModifierType, Converter={StaticResource NullToVisibilityConverter}}" />
|
||||
<TextBlock FontStyle="Italic"
|
||||
Visibility="{Binding SelectedModifierType, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted}">
|
||||
« Select a modifier »
|
||||
</TextBlock>
|
||||
</Grid>
|
||||
|
||||
</Button>
|
||||
|
||||
<ContentControl Grid.Column="2" s:View.Model="{Binding DynamicSelectionViewModel}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" IsTabStop="False" />
|
||||
<ContentControl Grid.Column="2" s:View.Model="{Binding StaticInputViewModel}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" IsTabStop="False" />
|
||||
</Grid>
|
||||
</UserControl>
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDataBinding
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for DataBindingModifierView.xaml
|
||||
/// </summary>
|
||||
public partial class DataBindingModifierView : UserControl
|
||||
{
|
||||
public DataBindingModifierView()
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
-212
@@ -1,212 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Exceptions;
|
||||
using Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDataBinding.ModifierTypes;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Input;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDataBinding
|
||||
{
|
||||
public sealed class DataBindingModifierViewModel<TLayerProperty, TProperty> : PropertyChangedBase, IDisposable
|
||||
{
|
||||
private readonly IDataBindingService _dataBindingService;
|
||||
private readonly IDataModelUIService _dataModelUIService;
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private DataModelDynamicViewModel _dynamicSelectionViewModel;
|
||||
private ModifierTypeCategoryViewModel _modifierTypeViewModels;
|
||||
private BaseDataBindingModifierType _selectedModifierType;
|
||||
private DataModelStaticViewModel _staticInputViewModel;
|
||||
|
||||
public DataBindingModifierViewModel(DataBindingModifier<TLayerProperty, TProperty> modifier,
|
||||
IDataBindingService dataBindingService,
|
||||
ISettingsService settingsService,
|
||||
IDataModelUIService dataModelUIService,
|
||||
IProfileEditorService profileEditorService)
|
||||
{
|
||||
_dataBindingService = dataBindingService;
|
||||
_dataModelUIService = dataModelUIService;
|
||||
_profileEditorService = profileEditorService;
|
||||
|
||||
ShowDataModelValues = settingsService.GetSetting<bool>("ProfileEditor.ShowDataModelValues");
|
||||
|
||||
Modifier = modifier;
|
||||
SelectModifierTypeCommand = new DelegateCommand(ExecuteSelectModifierTypeCommand);
|
||||
|
||||
Update();
|
||||
}
|
||||
|
||||
public DelegateCommand SelectModifierTypeCommand { get; }
|
||||
public PluginSetting<bool> ShowDataModelValues { get; }
|
||||
public DataBindingModifier<TLayerProperty, TProperty> Modifier { get; }
|
||||
|
||||
public ModifierTypeCategoryViewModel ModifierTypeViewModels
|
||||
{
|
||||
get => _modifierTypeViewModels;
|
||||
set => SetAndNotify(ref _modifierTypeViewModels, value);
|
||||
}
|
||||
|
||||
public BaseDataBindingModifierType SelectedModifierType
|
||||
{
|
||||
get => _selectedModifierType;
|
||||
set => SetAndNotify(ref _selectedModifierType, value);
|
||||
}
|
||||
|
||||
public DataModelDynamicViewModel DynamicSelectionViewModel
|
||||
{
|
||||
get => _dynamicSelectionViewModel;
|
||||
private set => SetAndNotify(ref _dynamicSelectionViewModel, value);
|
||||
}
|
||||
|
||||
public DataModelStaticViewModel StaticInputViewModel
|
||||
{
|
||||
get => _staticInputViewModel;
|
||||
private set => SetAndNotify(ref _staticInputViewModel, value);
|
||||
}
|
||||
|
||||
public void Delete()
|
||||
{
|
||||
Modifier.DirectDataBinding.RemoveModifier(Modifier);
|
||||
_profileEditorService.SaveSelectedProfileElement();
|
||||
}
|
||||
|
||||
private void ParameterSelectionViewModelOnPropertySelected(object sender, DataModelInputDynamicEventArgs e)
|
||||
{
|
||||
Modifier.UpdateParameterDynamic(e.DataModelPath);
|
||||
_profileEditorService.SaveSelectedProfileElement();
|
||||
}
|
||||
|
||||
private void StaticInputViewModelOnValueUpdated(object sender, DataModelInputStaticEventArgs e)
|
||||
{
|
||||
Modifier.UpdateParameterStatic(e.Value);
|
||||
_profileEditorService.SaveSelectedProfileElement();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
Type sourceType = Modifier.DirectDataBinding.GetSourceType();
|
||||
if (sourceType == null)
|
||||
throw new ArtemisUIException("Cannot use a data binding modifier VM for a data binding without a source");
|
||||
|
||||
if (Modifier.ModifierType == null || Modifier.ModifierType.ParameterType == null)
|
||||
{
|
||||
DisposeDynamicSelectionViewModel();
|
||||
DisposeStaticInputViewModel();
|
||||
}
|
||||
else if (Modifier.ParameterType == ProfileRightSideType.Dynamic)
|
||||
{
|
||||
DisposeStaticInputViewModel();
|
||||
DynamicSelectionViewModel = _dataModelUIService.GetDynamicSelectionViewModel(_profileEditorService.SelectedProfileConfiguration.Module);
|
||||
if (DynamicSelectionViewModel != null)
|
||||
{
|
||||
DynamicSelectionViewModel.DisplaySwitchButton = true;
|
||||
DynamicSelectionViewModel.PropertySelected += ParameterSelectionViewModelOnPropertySelected;
|
||||
DynamicSelectionViewModel.SwitchToStaticRequested += DynamicSelectionViewModelOnSwitchToStaticRequested;
|
||||
DynamicSelectionViewModel.FilterTypes = new[] {Modifier.ModifierType.ParameterType ?? sourceType};
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DisposeDynamicSelectionViewModel();
|
||||
StaticInputViewModel = _dataModelUIService.GetStaticInputViewModel(Modifier.ModifierType.ParameterType ?? sourceType, null);
|
||||
if (StaticInputViewModel != null)
|
||||
{
|
||||
StaticInputViewModel.DisplaySwitchButton = true;
|
||||
StaticInputViewModel.ValueUpdated += StaticInputViewModelOnValueUpdated;
|
||||
StaticInputViewModel.SwitchToDynamicRequested += StaticInputViewModelOnSwitchToDynamicRequested;
|
||||
}
|
||||
}
|
||||
|
||||
// Modifier type
|
||||
ModifierTypeCategoryViewModel root = new(null, null);
|
||||
IEnumerable<IGrouping<string, BaseDataBindingModifierType>> modifierTypes = _dataBindingService.GetCompatibleModifierTypes(sourceType, ModifierTypePart.Value).GroupBy(t => t.Category);
|
||||
foreach (IGrouping<string, BaseDataBindingModifierType> dataBindingModifierTypes in modifierTypes)
|
||||
{
|
||||
IEnumerable<ModifierTypeViewModel> viewModels = dataBindingModifierTypes.Select(t => new ModifierTypeViewModel(t));
|
||||
if (dataBindingModifierTypes.Key == null)
|
||||
root.Children.AddRange(viewModels);
|
||||
else
|
||||
root.Children.Add(new ModifierTypeCategoryViewModel(dataBindingModifierTypes.Key, viewModels));
|
||||
}
|
||||
|
||||
ModifierTypeViewModels = root;
|
||||
SelectedModifierType = Modifier.ModifierType;
|
||||
|
||||
// Parameter
|
||||
if (DynamicSelectionViewModel != null)
|
||||
DynamicSelectionViewModel.ChangeDataModelPath(Modifier.ParameterPath);
|
||||
else if (StaticInputViewModel != null)
|
||||
StaticInputViewModel.Value = Modifier.ParameterStaticValue;
|
||||
}
|
||||
|
||||
private void ExecuteSelectModifierTypeCommand(object context)
|
||||
{
|
||||
if (!(context is ModifierTypeViewModel modifierTypeViewModel))
|
||||
return;
|
||||
|
||||
Modifier.UpdateModifierType(modifierTypeViewModel.ModifierType);
|
||||
_profileEditorService.SaveSelectedProfileElement();
|
||||
|
||||
Update();
|
||||
}
|
||||
|
||||
#region IDisposable
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
DisposeDynamicSelectionViewModel();
|
||||
DisposeStaticInputViewModel();
|
||||
}
|
||||
|
||||
private void DisposeStaticInputViewModel()
|
||||
{
|
||||
if (StaticInputViewModel != null)
|
||||
{
|
||||
StaticInputViewModel.Dispose();
|
||||
StaticInputViewModel.ValueUpdated -= StaticInputViewModelOnValueUpdated;
|
||||
StaticInputViewModel.SwitchToDynamicRequested -= StaticInputViewModelOnSwitchToDynamicRequested;
|
||||
StaticInputViewModel = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void DisposeDynamicSelectionViewModel()
|
||||
{
|
||||
if (DynamicSelectionViewModel != null)
|
||||
{
|
||||
DynamicSelectionViewModel.Dispose();
|
||||
DynamicSelectionViewModel.PropertySelected -= ParameterSelectionViewModelOnPropertySelected;
|
||||
DynamicSelectionViewModel.SwitchToStaticRequested -= DynamicSelectionViewModelOnSwitchToStaticRequested;
|
||||
DynamicSelectionViewModel = null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Event handlers
|
||||
|
||||
private void DynamicSelectionViewModelOnSwitchToStaticRequested(object sender, EventArgs e)
|
||||
{
|
||||
Modifier.ParameterType = ProfileRightSideType.Static;
|
||||
|
||||
// Ensure the right static value is never null when the preferred type is a value type
|
||||
if (SelectedModifierType.ParameterType != null &&
|
||||
SelectedModifierType.ParameterType.IsValueType && Modifier.ParameterStaticValue == null)
|
||||
Modifier.UpdateParameterStatic(SelectedModifierType.ParameterType.GetDefault());
|
||||
|
||||
Update();
|
||||
}
|
||||
|
||||
private void StaticInputViewModelOnSwitchToDynamicRequested(object sender, EventArgs e)
|
||||
{
|
||||
Modifier.ParameterType = ProfileRightSideType.Dynamic;
|
||||
Update();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
-55
@@ -1,55 +0,0 @@
|
||||
<UserControl x:Class="Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDataBinding.DirectDataBindingModeView"
|
||||
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:s="https://github.com/canton7/Stylet"
|
||||
xmlns:dd="urn:gong-wpf-dragdrop"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<Grid Margin="0 5 0 0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<ContentControl Grid.Row="0"
|
||||
s:View.Model="{Binding TargetSelectionViewModel}"
|
||||
VerticalContentAlignment="Stretch"
|
||||
HorizontalContentAlignment="Stretch"
|
||||
IsTabStop="False" />
|
||||
|
||||
<Button Grid.Row="0"
|
||||
Grid.Column="1"
|
||||
Style="{StaticResource MaterialDesignFlatMidBgButton}"
|
||||
HorizontalAlignment="Right"
|
||||
FontSize="12"
|
||||
Padding="6 4"
|
||||
Height="22"
|
||||
Command="{s:Action AddModifier}">
|
||||
ADD MODIFIER
|
||||
</Button>
|
||||
|
||||
<ListBox Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Grid.ColumnSpan="2"
|
||||
ItemsSource="{Binding ModifierViewModels}"
|
||||
materialDesign:RippleAssist.IsDisabled="True"
|
||||
dd:DragDrop.IsDragSource="True"
|
||||
dd:DragDrop.IsDropTarget="True"
|
||||
dd:DragDrop.UseDefaultDragAdorner="True"
|
||||
HorizontalContentAlignment="Stretch"
|
||||
Margin="0 5 0 0">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<ContentControl s:View.Model="{Binding}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" IsTabStop="False" />
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
-169
@@ -1,169 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Modules;
|
||||
using Artemis.UI.Extensions;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Input;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDataBinding
|
||||
{
|
||||
public sealed class DirectDataBindingModeViewModel<TLayerProperty, TProperty> : Screen, IDataBindingModeViewModel
|
||||
{
|
||||
private readonly IDataBindingsVmFactory _dataBindingsVmFactory;
|
||||
private readonly IDataModelUIService _dataModelUIService;
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private bool _canAddModifier;
|
||||
private DataModelDynamicViewModel _targetSelectionViewModel;
|
||||
private bool _updating;
|
||||
|
||||
public DirectDataBindingModeViewModel(DirectDataBinding<TLayerProperty, TProperty> directDataBinding,
|
||||
IProfileEditorService profileEditorService,
|
||||
IDataModelUIService dataModelUIService,
|
||||
IDataBindingsVmFactory dataBindingsVmFactory)
|
||||
{
|
||||
_profileEditorService = profileEditorService;
|
||||
_dataModelUIService = dataModelUIService;
|
||||
_dataBindingsVmFactory = dataBindingsVmFactory;
|
||||
|
||||
DirectDataBinding = directDataBinding;
|
||||
ModifierViewModels = new BindableCollection<DataBindingModifierViewModel<TLayerProperty, TProperty>>();
|
||||
|
||||
Initialize();
|
||||
}
|
||||
|
||||
|
||||
public DirectDataBinding<TLayerProperty, TProperty> DirectDataBinding { get; }
|
||||
public BindableCollection<DataBindingModifierViewModel<TLayerProperty, TProperty>> ModifierViewModels { get; }
|
||||
|
||||
public bool CanAddModifier
|
||||
{
|
||||
get => _canAddModifier;
|
||||
set => SetAndNotify(ref _canAddModifier, value);
|
||||
}
|
||||
|
||||
public DataModelDynamicViewModel TargetSelectionViewModel
|
||||
{
|
||||
get => _targetSelectionViewModel;
|
||||
private set => SetAndNotify(ref _targetSelectionViewModel, value);
|
||||
}
|
||||
|
||||
public bool SupportsTestValue => true;
|
||||
|
||||
public void Update()
|
||||
{
|
||||
TargetSelectionViewModel.ChangeDataModelPath(DirectDataBinding.SourcePath);
|
||||
TargetSelectionViewModel.FilterTypes = new[] {DirectDataBinding.DataBinding.GetTargetType()};
|
||||
|
||||
CanAddModifier = DirectDataBinding.SourcePath != null && DirectDataBinding.SourcePath.IsValid;
|
||||
UpdateModifierViewModels();
|
||||
}
|
||||
|
||||
public object GetTestValue()
|
||||
{
|
||||
return DirectDataBinding.SourcePath?.GetValue();
|
||||
}
|
||||
|
||||
#region IDisposable
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
TargetSelectionViewModel.PropertySelected -= TargetSelectionViewModelOnPropertySelected;
|
||||
TargetSelectionViewModel.Dispose();
|
||||
DirectDataBinding.ModifiersUpdated -= DirectDataBindingOnModifiersUpdated;
|
||||
|
||||
foreach (DataBindingModifierViewModel<TLayerProperty, TProperty> dataBindingModifierViewModel in ModifierViewModels)
|
||||
dataBindingModifierViewModel.Dispose();
|
||||
ModifierViewModels.Clear();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
DirectDataBinding.ModifiersUpdated += DirectDataBindingOnModifiersUpdated;
|
||||
TargetSelectionViewModel = _dataModelUIService.GetDynamicSelectionViewModel(_profileEditorService.SelectedProfileConfiguration.Module);
|
||||
TargetSelectionViewModel.PropertySelected += TargetSelectionViewModelOnPropertySelected;
|
||||
ModifierViewModels.CollectionChanged += ModifierViewModelsOnCollectionChanged;
|
||||
Update();
|
||||
}
|
||||
|
||||
private void ModifierViewModelsOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
if (_updating || e.Action != NotifyCollectionChangedAction.Add)
|
||||
return;
|
||||
|
||||
for (int index = 0; index < ModifierViewModels.Count; index++)
|
||||
{
|
||||
DataBindingModifierViewModel<TLayerProperty, TProperty> dataBindingModifierViewModel = ModifierViewModels[index];
|
||||
dataBindingModifierViewModel.Modifier.Order = index + 1;
|
||||
}
|
||||
|
||||
DirectDataBinding.ApplyOrder();
|
||||
|
||||
_profileEditorService.SaveSelectedProfileElement();
|
||||
}
|
||||
|
||||
#region Target
|
||||
|
||||
private void TargetSelectionViewModelOnPropertySelected(object sender, DataModelInputDynamicEventArgs e)
|
||||
{
|
||||
DirectDataBinding.UpdateSource(e.DataModelPath);
|
||||
Update();
|
||||
|
||||
_profileEditorService.SaveSelectedProfileElement();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Modifiers
|
||||
|
||||
public void AddModifier()
|
||||
{
|
||||
DirectDataBinding.AddModifier(ProfileRightSideType.Dynamic);
|
||||
_profileEditorService.SaveSelectedProfileElement();
|
||||
}
|
||||
|
||||
private void UpdateModifierViewModels()
|
||||
{
|
||||
_updating = true;
|
||||
|
||||
// Remove old VMs
|
||||
List<DataBindingModifierViewModel<TLayerProperty, TProperty>> toRemove = ModifierViewModels.Where(m => !DirectDataBinding.Modifiers.Contains(m.Modifier)).ToList();
|
||||
foreach (DataBindingModifierViewModel<TLayerProperty, TProperty> modifierViewModel in toRemove)
|
||||
{
|
||||
ModifierViewModels.Remove(modifierViewModel);
|
||||
modifierViewModel.Dispose();
|
||||
}
|
||||
|
||||
// Don't create children without a source or with an invalid source
|
||||
if (DirectDataBinding.SourcePath == null || !DirectDataBinding.SourcePath.IsValid)
|
||||
return;
|
||||
|
||||
// Add missing VMs
|
||||
foreach (DataBindingModifier<TLayerProperty, TProperty> modifier in DirectDataBinding.Modifiers)
|
||||
{
|
||||
if (ModifierViewModels.All(m => m.Modifier != modifier))
|
||||
ModifierViewModels.Add(_dataBindingsVmFactory.DataBindingModifierViewModel(modifier));
|
||||
}
|
||||
|
||||
// Fix order
|
||||
ModifierViewModels.Sort(m => m.Modifier.Order);
|
||||
|
||||
_updating = false;
|
||||
}
|
||||
|
||||
private void DirectDataBindingOnModifiersUpdated(object sender, EventArgs e)
|
||||
{
|
||||
UpdateModifierViewModels();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
-6
@@ -1,6 +0,0 @@
|
||||
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDataBinding.ModifierTypes
|
||||
{
|
||||
public interface IModifierTypeViewModel
|
||||
{
|
||||
}
|
||||
}
|
||||
-19
@@ -1,19 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDataBinding.ModifierTypes
|
||||
{
|
||||
public class ModifierTypeCategoryViewModel : IModifierTypeViewModel
|
||||
{
|
||||
public ModifierTypeCategoryViewModel(string category, IEnumerable<IModifierTypeViewModel> children)
|
||||
{
|
||||
Category = category;
|
||||
Children = children == null
|
||||
? new BindableCollection<IModifierTypeViewModel>()
|
||||
: new BindableCollection<IModifierTypeViewModel>(children);
|
||||
}
|
||||
|
||||
public string Category { get; set; }
|
||||
public BindableCollection<IModifierTypeViewModel> Children { get; set; }
|
||||
}
|
||||
}
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
using Artemis.Core;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDataBinding.ModifierTypes
|
||||
{
|
||||
public class ModifierTypeViewModel : IModifierTypeViewModel
|
||||
{
|
||||
public ModifierTypeViewModel(BaseDataBindingModifierType modifierType)
|
||||
{
|
||||
ModifierType = modifierType;
|
||||
}
|
||||
|
||||
public BaseDataBindingModifierType ModifierType { get; set; }
|
||||
}
|
||||
}
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
using System;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
{
|
||||
public interface IDataBindingModeViewModel : IScreen, IDisposable
|
||||
{
|
||||
bool SupportsTestValue { get; }
|
||||
void Update();
|
||||
object GetTestValue();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user