mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Data bindings - Further implemented default converters
This commit is contained in:
1 parent
5972e148ee
commit
237f8b8eea
21 files changed
+447
-257
No files matched your search
+29
-26
@@ -42,43 +42,46 @@
|
||||
|
||||
<ComboBox Grid.Row="1"
|
||||
Style="{StaticResource MaterialDesignFloatingHintComboBox}"
|
||||
materialDesign:HintAssist.Hint="Mode"
|
||||
materialDesign:HintAssist.Hint="Data binding mode"
|
||||
MinWidth="128"
|
||||
IsEnabled="{Binding IsDataBindingEnabled}">
|
||||
<ComboBoxItem>
|
||||
Replace value
|
||||
</ComboBoxItem>
|
||||
<ComboBoxItem>
|
||||
Add to value
|
||||
</ComboBoxItem>
|
||||
<ComboBoxItem>
|
||||
Subtract from value
|
||||
</ComboBoxItem>
|
||||
SelectedValue="{Binding SelectedDataBindingMode}" ItemsSource="{Binding DataBindingModes}" SelectedValuePath="Value" DisplayMemberPath="Description" >
|
||||
</ComboBox>
|
||||
|
||||
<StackPanel Grid.Row="2">
|
||||
<TextBox Style="{StaticResource MaterialDesignFloatingHintTextBox}"
|
||||
Text="200"
|
||||
Text="{Binding EasingTime}"
|
||||
materialDesign:TextFieldAssist.HasClearButton="True"
|
||||
materialDesign:TextFieldAssist.SuffixText="ms"
|
||||
materialDesign:HintAssist.Hint="Smoothing time"
|
||||
materialDesign:HintAssist.Hint="Easing time"
|
||||
IsEnabled="{Binding IsDataBindingEnabled}" />
|
||||
</StackPanel>
|
||||
|
||||
<ComboBox Grid.Row="3"
|
||||
Style="{StaticResource MaterialDesignFloatingHintComboBox}"
|
||||
materialDesign:HintAssist.Hint="Smoothing type"
|
||||
materialDesign:HintAssist.Hint="Easing type"
|
||||
MinWidth="128"
|
||||
IsEnabled="{Binding IsDataBindingEnabled}">
|
||||
<ComboBoxItem>
|
||||
Ease in
|
||||
</ComboBoxItem>
|
||||
<ComboBoxItem>
|
||||
Ease out
|
||||
</ComboBoxItem>
|
||||
<ComboBoxItem>
|
||||
Ease in and out
|
||||
</ComboBoxItem>
|
||||
IsEnabled="{Binding IsEasingTimeEnabled}"
|
||||
SelectedItem="{Binding SelectedEasingViewModel}"
|
||||
ItemsSource="{Binding EasingViewModels}">
|
||||
<ComboBox.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<VirtualizingStackPanel />
|
||||
</ItemsPanelTemplate>
|
||||
</ComboBox.ItemsPanel>
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Polyline Stroke="{DynamicResource MaterialDesignBody}"
|
||||
StrokeThickness="1"
|
||||
Points="{Binding EasingPoints}"
|
||||
Stretch="Uniform"
|
||||
Width="14"
|
||||
Height="14"
|
||||
Margin="0 0 10 0" />
|
||||
<TextBlock Text="{Binding Description}" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
|
||||
<materialDesign:Card Grid.Row="4" Grid.ColumnSpan="2" Margin="0 5 0 0">
|
||||
@@ -102,10 +105,10 @@
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Margin="0 2">Input</TextBlock>
|
||||
<TextBlock Grid.Row="0" Grid.Column="1" Margin="0 2" FontFamily="Consolas" Text="{Binding TestInputValue}"/>
|
||||
<TextBlock Grid.Row="0" Grid.Column="1" Margin="0 2" FontFamily="Consolas" Text="{Binding TestInputValue}" />
|
||||
|
||||
<TextBlock Grid.Row="1" Grid.Column="0" Margin="0 2">Output</TextBlock>
|
||||
<TextBlock Grid.Row="1" Grid.Column="1" Margin="0 2" FontFamily="Consolas" Text="{Binding TestResultValue}"/>
|
||||
<TextBlock Grid.Row="1" Grid.Column="1" Margin="0 2" FontFamily="Consolas" Text="{Binding TestResultValue}" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</materialDesign:Card>
|
||||
|
||||
+87
-18
@@ -1,9 +1,9 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Timers;
|
||||
using Artemis.Core;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
using Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Input;
|
||||
using Artemis.UI.Shared.Services;
|
||||
@@ -22,25 +22,30 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
private DataModelDynamicViewModel _targetSelectionViewModel;
|
||||
private object _testInputValue;
|
||||
private object _testResultValue;
|
||||
private TimelineEasingViewModel _selectedEasingViewModel;
|
||||
private DataBindingMode _selectedDataBindingMode;
|
||||
private int _easingTime;
|
||||
private bool _isEasingTimeEnabled;
|
||||
private bool _updating;
|
||||
|
||||
public DataBindingViewModel(BaseLayerProperty layerProperty,
|
||||
PropertyInfo targetProperty,
|
||||
public DataBindingViewModel(DataBindingRegistration registration,
|
||||
IProfileEditorService profileEditorService,
|
||||
IDataModelUIService dataModelUIService,
|
||||
IDataBindingsVmFactory dataBindingsVmFactory)
|
||||
{
|
||||
Registration = registration;
|
||||
_profileEditorService = profileEditorService;
|
||||
_dataModelUIService = dataModelUIService;
|
||||
_dataBindingsVmFactory = dataBindingsVmFactory;
|
||||
_updateTimer = new Timer(500);
|
||||
|
||||
DisplayName = targetProperty.Name.ToUpper();
|
||||
DisplayName = Registration.Property.Name.ToUpper();
|
||||
|
||||
DataBindingModes = new BindableCollection<ValueDescription>(EnumUtilities.GetAllValuesAndDescriptions(typeof(DataBindingMode)));
|
||||
EasingViewModels = new BindableCollection<TimelineEasingViewModel>();
|
||||
ModifierViewModels = new BindableCollection<DataBindingModifierViewModel>();
|
||||
|
||||
LayerProperty = layerProperty;
|
||||
TargetProperty = targetProperty;
|
||||
DataBinding = layerProperty.DataBindings.FirstOrDefault(d => d.TargetProperty == targetProperty);
|
||||
|
||||
DataBinding = Registration.DataBinding;
|
||||
if (DataBinding != null)
|
||||
DataBinding.ModifiersUpdated += DataBindingOnModifiersUpdated;
|
||||
|
||||
@@ -50,11 +55,49 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
Execute.PostToUIThread(Initialize);
|
||||
}
|
||||
|
||||
public BaseLayerProperty LayerProperty { get; }
|
||||
public PropertyInfo TargetProperty { get; }
|
||||
public DataBindingRegistration Registration { get; }
|
||||
public string DisplayName { get; }
|
||||
|
||||
public BindableCollection<ValueDescription> DataBindingModes { get; }
|
||||
public BindableCollection<TimelineEasingViewModel> EasingViewModels { get; }
|
||||
public BindableCollection<DataBindingModifierViewModel> ModifierViewModels { get; }
|
||||
|
||||
public DataBindingMode SelectedDataBindingMode
|
||||
{
|
||||
get => _selectedDataBindingMode;
|
||||
set => SetAndNotify(ref _selectedDataBindingMode, value);
|
||||
}
|
||||
|
||||
public TimelineEasingViewModel SelectedEasingViewModel
|
||||
{
|
||||
get => _selectedEasingViewModel;
|
||||
set
|
||||
{
|
||||
if (!SetAndNotify(ref _selectedEasingViewModel, value)) return;
|
||||
ApplyChanges();
|
||||
}
|
||||
}
|
||||
|
||||
public int EasingTime
|
||||
{
|
||||
get => _easingTime;
|
||||
set
|
||||
{
|
||||
if (!SetAndNotify(ref _easingTime, value)) return;
|
||||
ApplyChanges();
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsEasingTimeEnabled
|
||||
{
|
||||
get => _isEasingTimeEnabled;
|
||||
set
|
||||
{
|
||||
if (!SetAndNotify(ref _isEasingTimeEnabled, value)) return;
|
||||
ApplyChanges();
|
||||
}
|
||||
}
|
||||
|
||||
public DataModelDynamicViewModel TargetSelectionViewModel
|
||||
{
|
||||
get => _targetSelectionViewModel;
|
||||
@@ -101,23 +144,22 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
if (DataBinding != null)
|
||||
return;
|
||||
|
||||
DataBinding = LayerProperty.AddDataBinding(TargetProperty);
|
||||
DataBinding = Registration.LayerProperty.EnableDataBinding(Registration);
|
||||
DataBinding.ModifiersUpdated += DataBindingOnModifiersUpdated;
|
||||
Update();
|
||||
|
||||
_profileEditorService.UpdateSelectedProfileElement();
|
||||
}
|
||||
|
||||
|
||||
public void RemoveDataBinding()
|
||||
{
|
||||
if (DataBinding == null)
|
||||
return;
|
||||
|
||||
var toRemove = DataBinding;
|
||||
var toDisable = DataBinding;
|
||||
DataBinding = null;
|
||||
LayerProperty.RemoveDataBinding(toRemove);
|
||||
toRemove.ModifiersUpdated -= DataBindingOnModifiersUpdated;
|
||||
Registration.LayerProperty.DisableDataBinding(toDisable);
|
||||
toDisable.ModifiersUpdated -= DataBindingOnModifiersUpdated;
|
||||
Update();
|
||||
|
||||
_profileEditorService.UpdateSelectedProfileElement();
|
||||
@@ -136,6 +178,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
EasingViewModels.AddRange(Enum.GetValues(typeof(Easings.Functions)).Cast<Easings.Functions>().Select(v => new TimelineEasingViewModel(null, v)));
|
||||
TargetSelectionViewModel = _dataModelUIService.GetDynamicSelectionViewModel(_profileEditorService.GetCurrentModule());
|
||||
TargetSelectionViewModel.PropertySelected += TargetSelectionViewModelOnPropertySelected;
|
||||
|
||||
@@ -147,17 +190,43 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (_updating)
|
||||
return;
|
||||
|
||||
if (DataBinding == null)
|
||||
{
|
||||
TargetSelectionViewModel.IsEnabled = false;
|
||||
IsEasingTimeEnabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
_updating = true;
|
||||
|
||||
SelectedDataBindingMode = DataBinding.Mode;
|
||||
EasingTime = (int) DataBinding.EasingTime.TotalMilliseconds;
|
||||
SelectedEasingViewModel = EasingViewModels.First(vm => vm.EasingFunction == DataBinding.EasingFunction);
|
||||
IsEasingTimeEnabled = EasingTime > 0;
|
||||
|
||||
TargetSelectionViewModel.IsEnabled = true;
|
||||
TargetSelectionViewModel.PopulateSelectedPropertyViewModel(DataBinding.SourceDataModel, DataBinding.SourcePropertyPath);
|
||||
TargetSelectionViewModel.FilterTypes = new[] {DataBinding.TargetProperty.PropertyType};
|
||||
|
||||
UpdateModifierViewModels();
|
||||
|
||||
_updating = false;
|
||||
}
|
||||
|
||||
private void ApplyChanges()
|
||||
{
|
||||
if (_updating)
|
||||
return;
|
||||
|
||||
DataBinding.Mode = SelectedDataBindingMode;
|
||||
DataBinding.EasingTime = TimeSpan.FromMilliseconds(EasingTime);
|
||||
DataBinding.EasingFunction = SelectedEasingViewModel?.EasingFunction ?? Easings.Functions.Linear;
|
||||
|
||||
_profileEditorService.UpdateSelectedProfileElement();
|
||||
Update();
|
||||
}
|
||||
|
||||
private void DataBindingOnModifiersUpdated(object sender, EventArgs e)
|
||||
@@ -179,10 +248,10 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
private void UpdateTestResult()
|
||||
{
|
||||
var currentValue = TargetSelectionViewModel.SelectedPropertyViewModel?.GetCurrentValue();
|
||||
if (currentValue == null && TargetProperty.PropertyType.IsValueType)
|
||||
currentValue = Activator.CreateInstance(TargetProperty.PropertyType);
|
||||
if (currentValue == null && Registration.Property.PropertyType.IsValueType)
|
||||
currentValue = Activator.CreateInstance(Registration.Property.PropertyType);
|
||||
|
||||
TestInputValue = Convert.ChangeType(currentValue, TargetProperty.PropertyType);
|
||||
TestInputValue = Convert.ChangeType(currentValue, Registration.Property.PropertyType);
|
||||
TestResultValue = DataBinding?.GetValue(TestInputValue);
|
||||
}
|
||||
|
||||
|
||||
+6
-6
@@ -37,19 +37,19 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
DataBindingViewModel = null;
|
||||
DataBindingsTabsViewModel = null;
|
||||
|
||||
var properties = LayerProperty.GetDataBindingProperties();
|
||||
if (properties == null || properties.Count == 0)
|
||||
var registrations = LayerProperty.DataBindingRegistrations;
|
||||
if (registrations == null || registrations.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 = _dataBindingsVmFactory.DataBindingViewModel(LayerProperty, properties.First());
|
||||
if (registrations.Count == 1)
|
||||
DataBindingViewModel = _dataBindingsVmFactory.DataBindingViewModel(registrations.First());
|
||||
else
|
||||
{
|
||||
DataBindingsTabsViewModel = new DataBindingsTabsViewModel();
|
||||
foreach (var dataBindingProperty in properties)
|
||||
DataBindingsTabsViewModel.Tabs.Add(_dataBindingsVmFactory.DataBindingViewModel(LayerProperty, dataBindingProperty));
|
||||
foreach (var registration in registrations)
|
||||
DataBindingsTabsViewModel.Tabs.Add(_dataBindingsVmFactory.DataBindingViewModel(registration));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user