1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Data bindings - WIP commit 🤐🤐🤐

This commit is contained in:
SpoinkyNL 2020-09-03 23:09:05 +02:00
parent 21beffc0a9
commit 59e1f37aec
2 changed files with 113 additions and 8 deletions

View File

@ -53,6 +53,7 @@
BorderBrush="#ab47bc"
Style="{StaticResource DisplayConditionButton}"
ToolTip="{Binding SelectedLeftSideProperty.DisplayPropertyPath}"
IsEnabled="{Binding IsDataBindingEnabled}"
HorizontalAlignment="Left">
<Button.ContextMenu>
<ContextMenu ItemsSource="{Binding LeftSideDataModel.Children}" IsOpen="{Binding LeftSideDataModelOpen, Mode=OneWayToSource}">
@ -82,7 +83,8 @@
<ComboBox Grid.Row="1"
Style="{StaticResource MaterialDesignFloatingHintComboBox}"
materialDesign:HintAssist.Hint="Mode"
MinWidth="128">
MinWidth="128"
IsEnabled="{Binding IsDataBindingEnabled}">
<ComboBoxItem>
Replace value
</ComboBoxItem>
@ -99,13 +101,15 @@
Text="200"
materialDesign:TextFieldAssist.HasClearButton="True"
materialDesign:TextFieldAssist.SuffixText="ms"
materialDesign:HintAssist.Hint="Smoothing time" />
materialDesign:HintAssist.Hint="Smoothing time"
IsEnabled="{Binding IsDataBindingEnabled}" />
</StackPanel>
<ComboBox Grid.Row="3"
Style="{StaticResource MaterialDesignFloatingHintComboBox}"
materialDesign:HintAssist.Hint="Smoothing type"
MinWidth="128">
MinWidth="128"
IsEnabled="{Binding IsDataBindingEnabled}">
<ComboBoxItem>
Ease in
</ComboBoxItem>
@ -149,6 +153,10 @@
<Grid Grid.Column="1">
<Grid Margin="5 26 0 0">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
@ -158,7 +166,8 @@
HorizontalAlignment="Left"
FontSize="12"
Padding="6 4"
Height="22">
Height="22"
IsEnabled="{Binding IsDataBindingEnabled}">
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Margin="0 -1 4 0" Kind="Plus" />
<TextBlock>
@ -167,7 +176,18 @@
</StackPanel>
</Button>
<CheckBox Grid.Row="0"
Grid.Column="1"
Style="{StaticResource MaterialDesignCheckBox}"
HorizontalAlignment="Right"
VerticalAlignment="Top"
IsChecked="{Binding IsDataBindingEnabled}">
Enable data binding
</CheckBox>
<ListBox Grid.Row="1"
Grid.Column="0"
Grid.ColumnSpan="2"
ItemsSource="{Binding ModifierViewModels}"
materialDesign:RippleAssist.IsDisabled="True"
dd:DragDrop.IsDragSource="True"
@ -180,7 +200,6 @@
<ContentControl s:View.Model="{Binding}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" IsTabStop="False" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Grid>

View File

@ -1,29 +1,91 @@
using System.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Timers;
using Artemis.Core;
using Artemis.Core.Services;
using Artemis.UI.Shared;
using Artemis.UI.Shared.Services;
using Stylet;
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
{
public class DataBindingViewModel : PropertyChangedBase
{
private readonly IDataModelService _dataModelService;
private readonly IDataModelUIService _dataModelUIService;
private readonly IProfileEditorService _profileEditorService;
private readonly ISettingsService _settingsService;
private readonly Timer _updateTimer;
private DataBinding _dataBinding;
private bool _isDataBindingEnabled;
private DataModelPropertiesViewModel _sourceDataModel;
private DataModelVisualizationViewModel _selectedSourceProperty;
public DataBindingViewModel(BaseLayerProperty layerProperty, PropertyInfo targetProperty)
public DataBindingViewModel(
BaseLayerProperty layerProperty,
PropertyInfo targetProperty,
IProfileEditorService profileEditorService,
IDataModelUIService dataModelUIService,
IDataModelService dataModelService,
ISettingsService settingsService)
{
_profileEditorService = profileEditorService;
_dataModelUIService = dataModelUIService;
_dataModelService = dataModelService;
_settingsService = settingsService;
_updateTimer = new Timer(500);
LayerProperty = layerProperty;
TargetProperty = targetProperty;
DisplayName = TargetProperty.Name.ToUpper();
ModifierViewModels = new BindableCollection<DataBindingModifierViewModel>();
DataBinding = layerProperty.DataBindings.FirstOrDefault(d => d.TargetProperty == targetProperty);
ShowDataModelValues = settingsService.GetSetting<bool>("ProfileEditor.ShowDataModelValues");
_isDataBindingEnabled = DataBinding != null;
// Initialize async, no need to wait for it
Task.Run(Initialize);
}
public bool SourceDataModelOpen { get; set; }
public DataModelPropertiesViewModel SourceDataModel
{
get => _sourceDataModel;
set => SetAndNotify(ref _sourceDataModel, value);
}
public DataModelVisualizationViewModel SelectedSourceProperty
{
get => _selectedSourceProperty;
set => SetAndNotify(ref _selectedSourceProperty, value);
}
public PluginSetting<bool> ShowDataModelValues { get; }
public BaseLayerProperty LayerProperty { get; }
public PropertyInfo TargetProperty { get; }
public string DisplayName { get; }
public BindableCollection<DataBindingModifierViewModel> ModifierViewModels { get; }
public bool IsDataBindingEnabled
{
get => _isDataBindingEnabled;
set
{
if (!SetAndNotify(ref _isDataBindingEnabled, value)) return;
if (value)
EnableDataBinding();
else
RemoveDataBinding();
}
}
public DataBinding DataBinding
{
get => _dataBinding;
@ -63,6 +125,30 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
ModifierViewModels.Add(new DataBindingModifierViewModel(modifier));
}
private void Initialize()
{
// Get the data models
SourceDataModel = _dataModelUIService.GetMainDataModelVisualization();
if (!_dataModelUIService.GetPluginExtendsDataModel(_profileEditorService.GetCurrentModule()))
SourceDataModel.Children.Add(_dataModelUIService.GetPluginDataModelVisualization(_profileEditorService.GetCurrentModule()));
SourceDataModel.UpdateRequested += SourceDataModelOnUpdateRequested;
_updateTimer.Start();
_updateTimer.Elapsed += OnUpdateTimerOnElapsed;
}
private void SourceDataModelOnUpdateRequested(object sender, EventArgs e)
{
SourceDataModel.ApplyTypeFilter(true, DataBinding.TargetProperty.PropertyType);
}
private void OnUpdateTimerOnElapsed(object sender, ElapsedEventArgs e)
{
if (SourceDataModelOpen)
SourceDataModel.Update(_dataModelUIService);
}
private void UpdateModifierViewModels()
{
ModifierViewModels.Clear();