mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Data bindings - WIP commit
This commit is contained in:
1 parent
0f1f8cd79c
commit
e4fbc9ac55
42 files changed
+902
-356
No files matched your search
+65
-11
@@ -1,7 +1,10 @@
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Exceptions;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Input;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using Stylet;
|
||||
|
||||
@@ -13,6 +16,8 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
private readonly IDataModelUIService _dataModelUIService;
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private DataBindingModifierType _selectedModifierType;
|
||||
private DataModelDynamicViewModel _dynamicSelectionViewModel;
|
||||
private DataModelStaticViewModel _staticInputViewModel;
|
||||
|
||||
public DataBindingModifierViewModel(DataBindingModifier modifier,
|
||||
IDataBindingService dataBindingService,
|
||||
@@ -32,11 +37,10 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
SelectModifierTypeCommand = new DelegateCommand(ExecuteSelectModifierTypeCommand);
|
||||
|
||||
// Initialize async, no need to wait for it
|
||||
Task.Run(Initialize);
|
||||
Execute.PostToUIThread(Initialize);
|
||||
}
|
||||
|
||||
public DelegateCommand SelectModifierTypeCommand { get; set; }
|
||||
|
||||
public DelegateCommand SelectModifierTypeCommand { get; }
|
||||
public PluginSetting<bool> ShowDataModelValues { get; }
|
||||
public DataBindingModifier Modifier { get; }
|
||||
public BindableCollection<DataBindingModifierType> ModifierTypes { get; }
|
||||
@@ -47,30 +51,65 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
set => SetAndNotify(ref _selectedModifierType, value);
|
||||
}
|
||||
|
||||
public DataModelSelectionViewModel ParameterSelectionViewModel { get; private set; }
|
||||
public DataModelDynamicViewModel DynamicSelectionViewModel
|
||||
{
|
||||
get => _dynamicSelectionViewModel;
|
||||
private set => SetAndNotify(ref _dynamicSelectionViewModel, value);
|
||||
}
|
||||
|
||||
public DataModelStaticViewModel StaticInputViewModel
|
||||
{
|
||||
get => _staticInputViewModel;
|
||||
private set => SetAndNotify(ref _staticInputViewModel, value);
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
ParameterSelectionViewModel = _dataModelUIService.GetDataModelSelectionViewModel(_profileEditorService.GetCurrentModule());
|
||||
ParameterSelectionViewModel.PropertySelected += ParameterSelectionViewModelOnPropertySelected;
|
||||
ParameterSelectionViewModel.FilterTypes = new[] {Modifier.DataBinding.TargetProperty.PropertyType};
|
||||
var sourceType = Modifier.DataBinding.GetSourceType();
|
||||
if (sourceType == null)
|
||||
throw new ArtemisUIException("Cannot initialize a data binding modifier VM for a data binding without a source");
|
||||
|
||||
if (Modifier.ParameterType == ProfileRightSideType.Dynamic)
|
||||
{
|
||||
StaticInputViewModel = null;
|
||||
DynamicSelectionViewModel = _dataModelUIService.GetDynamicSelectionViewModel(_profileEditorService.GetCurrentModule());
|
||||
DynamicSelectionViewModel.PropertySelected += ParameterSelectionViewModelOnPropertySelected;
|
||||
DynamicSelectionViewModel.FilterTypes = new[] {sourceType};
|
||||
}
|
||||
else
|
||||
{
|
||||
DynamicSelectionViewModel = null;
|
||||
StaticInputViewModel = _dataModelUIService.GetStaticInputViewModel(sourceType);
|
||||
StaticInputViewModel.ValueUpdated += StaticInputViewModelOnValueUpdated;
|
||||
}
|
||||
|
||||
Update();
|
||||
}
|
||||
|
||||
private void ParameterSelectionViewModelOnPropertySelected(object sender, DataModelPropertySelectedEventArgs e)
|
||||
private void ParameterSelectionViewModelOnPropertySelected(object sender, DataModelInputDynamicEventArgs e)
|
||||
{
|
||||
Modifier.UpdateParameter(e.DataModelVisualizationViewModel.DataModel, e.DataModelVisualizationViewModel.PropertyPath);
|
||||
}
|
||||
|
||||
private void StaticInputViewModelOnValueUpdated(object sender, DataModelInputStaticEventArgs e)
|
||||
{
|
||||
Modifier.UpdateParameter(e.Value);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
var sourceType = Modifier.DataBinding.GetSourceType();
|
||||
|
||||
// Modifier type
|
||||
ModifierTypes.Clear();
|
||||
ModifierTypes.AddRange(_dataBindingService.GetCompatibleModifierTypes(Modifier.DataBinding.TargetProperty.PropertyType));
|
||||
ModifierTypes.AddRange(_dataBindingService.GetCompatibleModifierTypes(sourceType));
|
||||
SelectedModifierType = Modifier.ModifierType;
|
||||
|
||||
ParameterSelectionViewModel.PopulateSelectedPropertyViewModel(Modifier.ParameterDataModel, Modifier.ParameterPropertyPath);
|
||||
// Parameter
|
||||
if (DynamicSelectionViewModel != null)
|
||||
DynamicSelectionViewModel?.PopulateSelectedPropertyViewModel(Modifier.ParameterDataModel, Modifier.ParameterPropertyPath);
|
||||
else if (StaticInputViewModel != null)
|
||||
StaticInputViewModel.Value = Modifier.ParameterStaticValue;
|
||||
}
|
||||
|
||||
private void ExecuteSelectModifierTypeCommand(object context)
|
||||
@@ -83,5 +122,20 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
|
||||
Update();
|
||||
}
|
||||
|
||||
public void Delete()
|
||||
{
|
||||
Modifier.DataBinding.RemoveModifier(Modifier);
|
||||
}
|
||||
|
||||
public void SwapType()
|
||||
{
|
||||
if (Modifier.ParameterType == ProfileRightSideType.Dynamic)
|
||||
Modifier.UpdateParameter(Modifier.DataBinding.GetSourceType().GetDefault());
|
||||
else
|
||||
Modifier.UpdateParameter(null, null);
|
||||
|
||||
Initialize();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user