1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-31 09:43:46 +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" BorderBrush="#ab47bc"
Style="{StaticResource DisplayConditionButton}" Style="{StaticResource DisplayConditionButton}"
ToolTip="{Binding SelectedLeftSideProperty.DisplayPropertyPath}" ToolTip="{Binding SelectedLeftSideProperty.DisplayPropertyPath}"
IsEnabled="{Binding IsDataBindingEnabled}"
HorizontalAlignment="Left"> HorizontalAlignment="Left">
<Button.ContextMenu> <Button.ContextMenu>
<ContextMenu ItemsSource="{Binding LeftSideDataModel.Children}" IsOpen="{Binding LeftSideDataModelOpen, Mode=OneWayToSource}"> <ContextMenu ItemsSource="{Binding LeftSideDataModel.Children}" IsOpen="{Binding LeftSideDataModelOpen, Mode=OneWayToSource}">
@ -82,7 +83,8 @@
<ComboBox Grid.Row="1" <ComboBox Grid.Row="1"
Style="{StaticResource MaterialDesignFloatingHintComboBox}" Style="{StaticResource MaterialDesignFloatingHintComboBox}"
materialDesign:HintAssist.Hint="Mode" materialDesign:HintAssist.Hint="Mode"
MinWidth="128"> MinWidth="128"
IsEnabled="{Binding IsDataBindingEnabled}">
<ComboBoxItem> <ComboBoxItem>
Replace value Replace value
</ComboBoxItem> </ComboBoxItem>
@ -99,13 +101,15 @@
Text="200" Text="200"
materialDesign:TextFieldAssist.HasClearButton="True" materialDesign:TextFieldAssist.HasClearButton="True"
materialDesign:TextFieldAssist.SuffixText="ms" materialDesign:TextFieldAssist.SuffixText="ms"
materialDesign:HintAssist.Hint="Smoothing time" /> materialDesign:HintAssist.Hint="Smoothing time"
IsEnabled="{Binding IsDataBindingEnabled}" />
</StackPanel> </StackPanel>
<ComboBox Grid.Row="3" <ComboBox Grid.Row="3"
Style="{StaticResource MaterialDesignFloatingHintComboBox}" Style="{StaticResource MaterialDesignFloatingHintComboBox}"
materialDesign:HintAssist.Hint="Smoothing type" materialDesign:HintAssist.Hint="Smoothing type"
MinWidth="128"> MinWidth="128"
IsEnabled="{Binding IsDataBindingEnabled}">
<ComboBoxItem> <ComboBoxItem>
Ease in Ease in
</ComboBoxItem> </ComboBoxItem>
@ -149,6 +153,10 @@
<Grid Grid.Column="1"> <Grid Grid.Column="1">
<Grid Margin="5 26 0 0"> <Grid Margin="5 26 0 0">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="*" /> <RowDefinition Height="*" />
@ -158,7 +166,8 @@
HorizontalAlignment="Left" HorizontalAlignment="Left"
FontSize="12" FontSize="12"
Padding="6 4" Padding="6 4"
Height="22"> Height="22"
IsEnabled="{Binding IsDataBindingEnabled}">
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Margin="0 -1 4 0" Kind="Plus" /> <materialDesign:PackIcon Margin="0 -1 4 0" Kind="Plus" />
<TextBlock> <TextBlock>
@ -167,7 +176,18 @@
</StackPanel> </StackPanel>
</Button> </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" <ListBox Grid.Row="1"
Grid.Column="0"
Grid.ColumnSpan="2"
ItemsSource="{Binding ModifierViewModels}" ItemsSource="{Binding ModifierViewModels}"
materialDesign:RippleAssist.IsDisabled="True" materialDesign:RippleAssist.IsDisabled="True"
dd:DragDrop.IsDragSource="True" dd:DragDrop.IsDragSource="True"
@ -180,7 +200,6 @@
<ContentControl s:View.Model="{Binding}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" IsTabStop="False" /> <ContentControl s:View.Model="{Binding}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" IsTabStop="False" />
</DataTemplate> </DataTemplate>
</ListBox.ItemTemplate> </ListBox.ItemTemplate>
</ListBox> </ListBox>
</Grid> </Grid>
</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.Reflection;
using System.Threading.Tasks;
using System.Timers;
using Artemis.Core; using Artemis.Core;
using Artemis.Core.Services;
using Artemis.UI.Shared;
using Artemis.UI.Shared.Services;
using Stylet; using Stylet;
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
{ {
public class DataBindingViewModel : PropertyChangedBase 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 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; LayerProperty = layerProperty;
TargetProperty = targetProperty; TargetProperty = targetProperty;
DisplayName = TargetProperty.Name.ToUpper(); DisplayName = TargetProperty.Name.ToUpper();
ModifierViewModels = new BindableCollection<DataBindingModifierViewModel>(); ModifierViewModels = new BindableCollection<DataBindingModifierViewModel>();
DataBinding = layerProperty.DataBindings.FirstOrDefault(d => d.TargetProperty == targetProperty); 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 BaseLayerProperty LayerProperty { get; }
public PropertyInfo TargetProperty { get; } public PropertyInfo TargetProperty { get; }
public string DisplayName { get; } public string DisplayName { get; }
public BindableCollection<DataBindingModifierViewModel> ModifierViewModels { 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 public DataBinding DataBinding
{ {
get => _dataBinding; get => _dataBinding;
@ -63,6 +125,30 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
ModifierViewModels.Add(new DataBindingModifierViewModel(modifier)); 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() private void UpdateModifierViewModels()
{ {
ModifierViewModels.Clear(); ModifierViewModels.Clear();