mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
Databinding modifiers - Redesigned API to leverage generics
Databinding modifiers - Updated default modifiers to use new API
This commit is contained in:
1 parent
2bb663db15
commit
fd9f3afef5
50 files changed
+487
-407
No files matched your search
+3
-2
@@ -275,7 +275,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Conditions
|
||||
private void CreateRightSideSelectionViewModel()
|
||||
{
|
||||
RightSideSelectionViewModel = _dataModelUIService.GetDynamicSelectionViewModel(_profileEditorService.GetCurrentModule());
|
||||
RightSideSelectionViewModel.ButtonBrush = (Brush) Application.Current.FindResource("PrimaryHueMidBrush");
|
||||
RightSideSelectionViewModel.ButtonBrush = (SolidColorBrush) Application.Current.FindResource("PrimaryHueMidBrush");
|
||||
RightSideSelectionViewModel.DisplaySwitchButton = true;
|
||||
RightSideSelectionViewModel.PropertySelected += RightSideOnPropertySelected;
|
||||
RightSideSelectionViewModel.SwitchToStaticRequested += RightSideSelectionViewModelOnSwitchToStaticRequested;
|
||||
@@ -289,7 +289,8 @@ namespace Artemis.UI.Screens.ProfileEditor.Conditions
|
||||
private void CreateRightSideInputViewModel(Type leftSideType)
|
||||
{
|
||||
RightSideInputViewModel = _dataModelUIService.GetStaticInputViewModel(leftSideType, LeftSideSelectionViewModel.DataModelPath?.GetPropertyDescription());
|
||||
RightSideInputViewModel.ButtonBrush = (Brush) Application.Current.FindResource("PrimaryHueMidBrush");
|
||||
RightSideInputViewModel.ButtonBrush = (SolidColorBrush) Application.Current.FindResource("PrimaryHueMidBrush");
|
||||
RightSideInputViewModel.DisplaySwitchButton = true;
|
||||
RightSideInputViewModel.ValueUpdated += RightSideOnValueEntered;
|
||||
RightSideInputViewModel.SwitchToDynamicRequested += RightSideInputViewModelOnSwitchToDynamicRequested;
|
||||
}
|
||||
|
||||
+3
-2
@@ -218,7 +218,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Conditions
|
||||
private void CreateRightSideSelectionViewModel()
|
||||
{
|
||||
RightSideSelectionViewModel = _dataModelUIService.GetDynamicSelectionViewModel(_profileEditorService.GetCurrentModule());
|
||||
RightSideSelectionViewModel.ButtonBrush = (Brush) Application.Current.FindResource("PrimaryHueMidBrush");
|
||||
RightSideSelectionViewModel.ButtonBrush = (SolidColorBrush) Application.Current.FindResource("PrimaryHueMidBrush");
|
||||
RightSideSelectionViewModel.DisplaySwitchButton = true;
|
||||
RightSideSelectionViewModel.PropertySelected += RightSideOnPropertySelected;
|
||||
RightSideSelectionViewModel.SwitchToStaticRequested += RightSideSelectionViewModelOnSwitchToStaticRequested;
|
||||
@@ -227,7 +227,8 @@ namespace Artemis.UI.Screens.ProfileEditor.Conditions
|
||||
private void CreateRightSideInputViewModel(Type leftSideType)
|
||||
{
|
||||
RightSideInputViewModel = _dataModelUIService.GetStaticInputViewModel(leftSideType, LeftSideSelectionViewModel.DataModelPath?.GetPropertyDescription());
|
||||
RightSideInputViewModel.ButtonBrush = (Brush) Application.Current.FindResource("PrimaryHueMidBrush");
|
||||
RightSideInputViewModel.ButtonBrush = (SolidColorBrush) Application.Current.FindResource("PrimaryHueMidBrush");
|
||||
RightSideInputViewModel.DisplaySwitchButton = true;
|
||||
RightSideInputViewModel.ValueUpdated += RightSideOnValueEntered;
|
||||
RightSideInputViewModel.SwitchToDynamicRequested += RightSideInputViewModelOnSwitchToDynamicRequested;
|
||||
}
|
||||
|
||||
+3
-14
@@ -24,7 +24,6 @@
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
@@ -39,18 +38,8 @@
|
||||
Command="{s:Action Delete}">
|
||||
<materialDesign:PackIcon Kind="Close" Width="18" Height="18" />
|
||||
</Button>
|
||||
|
||||
<Button Grid.Column="1"
|
||||
ToolTip="Swap modifier type to static/dynamic"
|
||||
Style="{StaticResource MaterialDesignIconForegroundButton}"
|
||||
HorizontalAlignment="Left"
|
||||
Foreground="{StaticResource SecondaryAccentBrush}"
|
||||
Width="25"
|
||||
Height="25"
|
||||
Command="{s:Action SwapType}">
|
||||
<materialDesign:PackIcon Kind="SwapHorizontalVariant" Width="18" Height="18" />
|
||||
</Button>
|
||||
|
||||
<Button Grid.Column="2"
|
||||
Style="{StaticResource DataModelConditionButtonLeftClickMenu}"
|
||||
Background="#7B7B7B"
|
||||
BorderBrush="#7B7B7B"
|
||||
@@ -101,7 +90,7 @@
|
||||
|
||||
</Button>
|
||||
|
||||
<ContentControl Grid.Column="3" s:View.Model="{Binding DynamicSelectionViewModel}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" IsTabStop="False" />
|
||||
<ContentControl Grid.Column="3" s:View.Model="{Binding StaticInputViewModel}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" IsTabStop="False" />
|
||||
<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>
|
||||
+64
-45
@@ -19,7 +19,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private DataModelDynamicViewModel _dynamicSelectionViewModel;
|
||||
private ModifierTypeCategoryViewModel _modifierTypeViewModels;
|
||||
private DataBindingModifierType _selectedModifierType;
|
||||
private BaseDataBindingModifierType _selectedModifierType;
|
||||
private DataModelStaticViewModel _staticInputViewModel;
|
||||
|
||||
public DataBindingModifierViewModel(DataBindingModifier<TLayerProperty, TProperty> modifier,
|
||||
@@ -50,7 +50,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa
|
||||
set => SetAndNotify(ref _modifierTypeViewModels, value);
|
||||
}
|
||||
|
||||
public DataBindingModifierType SelectedModifierType
|
||||
public BaseDataBindingModifierType SelectedModifierType
|
||||
{
|
||||
get => _selectedModifierType;
|
||||
set => SetAndNotify(ref _selectedModifierType, value);
|
||||
@@ -68,41 +68,12 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa
|
||||
private set => SetAndNotify(ref _staticInputViewModel, value);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (DynamicSelectionViewModel != null)
|
||||
{
|
||||
DynamicSelectionViewModel.Dispose();
|
||||
DynamicSelectionViewModel.PropertySelected -= ParameterSelectionViewModelOnPropertySelected;
|
||||
}
|
||||
|
||||
if (StaticInputViewModel != null)
|
||||
{
|
||||
StaticInputViewModel.Dispose();
|
||||
StaticInputViewModel.ValueUpdated -= StaticInputViewModelOnValueUpdated;
|
||||
}
|
||||
}
|
||||
|
||||
public void Delete()
|
||||
{
|
||||
Modifier.DirectDataBinding.RemoveModifier(Modifier);
|
||||
_profileEditorService.UpdateSelectedProfileElement();
|
||||
}
|
||||
|
||||
public void SwapType()
|
||||
{
|
||||
if (Modifier.ParameterType == ProfileRightSideType.Dynamic)
|
||||
{
|
||||
Type sourceType = Modifier.DirectDataBinding.GetSourceType();
|
||||
Modifier.UpdateParameterStatic((Modifier.ModifierType.ParameterType ?? sourceType).GetDefault());
|
||||
}
|
||||
else
|
||||
Modifier.UpdateParameterDynamic(null);
|
||||
|
||||
Update();
|
||||
_profileEditorService.UpdateSelectedProfileElement();
|
||||
}
|
||||
|
||||
|
||||
private void ParameterSelectionViewModelOnPropertySelected(object sender, DataModelInputDynamicEventArgs e)
|
||||
{
|
||||
Modifier.UpdateParameterDynamic(e.DataModelPath);
|
||||
@@ -121,39 +92,39 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa
|
||||
if (sourceType == null)
|
||||
throw new ArtemisUIException("Cannot use a data binding modifier VM for a data binding without a source");
|
||||
|
||||
if (DynamicSelectionViewModel != null)
|
||||
if (Modifier.ModifierType == null || Modifier.ModifierType.ParameterType == null)
|
||||
{
|
||||
DynamicSelectionViewModel.Dispose();
|
||||
DynamicSelectionViewModel.PropertySelected -= ParameterSelectionViewModelOnPropertySelected;
|
||||
}
|
||||
|
||||
if (Modifier.ModifierType == null || !Modifier.ModifierType.SupportsParameter)
|
||||
{
|
||||
StaticInputViewModel = null;
|
||||
DynamicSelectionViewModel = null;
|
||||
DisposeDynamicSelectionViewModel();
|
||||
DisposeStaticInputViewModel();
|
||||
}
|
||||
else if (Modifier.ParameterType == ProfileRightSideType.Dynamic)
|
||||
{
|
||||
StaticInputViewModel = null;
|
||||
DisposeStaticInputViewModel();
|
||||
DynamicSelectionViewModel = _dataModelUIService.GetDynamicSelectionViewModel(_profileEditorService.GetCurrentModule());
|
||||
if (DynamicSelectionViewModel != null)
|
||||
{
|
||||
DynamicSelectionViewModel.DisplaySwitchButton = true;
|
||||
DynamicSelectionViewModel.PropertySelected += ParameterSelectionViewModelOnPropertySelected;
|
||||
DynamicSelectionViewModel.SwitchToStaticRequested += DynamicSelectionViewModelOnSwitchToStaticRequested;
|
||||
DynamicSelectionViewModel.FilterTypes = new[] {Modifier.ModifierType.ParameterType ?? sourceType};
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DynamicSelectionViewModel = null;
|
||||
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 ModifierTypeCategoryViewModel(null, null);
|
||||
IEnumerable<IGrouping<string, DataBindingModifierType>> modifierTypes = _dataBindingService.GetCompatibleModifierTypes(sourceType).GroupBy(t => t.Category);
|
||||
foreach (IGrouping<string, DataBindingModifierType> dataBindingModifierTypes in modifierTypes)
|
||||
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)
|
||||
@@ -182,5 +153,53 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa
|
||||
|
||||
Update();
|
||||
}
|
||||
|
||||
#region IDisposable
|
||||
|
||||
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;
|
||||
Update();
|
||||
}
|
||||
|
||||
private void StaticInputViewModelOnSwitchToDynamicRequested(object? sender, EventArgs e)
|
||||
{
|
||||
Modifier.ParameterType = ProfileRightSideType.Dynamic;
|
||||
Update();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -4,11 +4,11 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa
|
||||
{
|
||||
public class ModifierTypeViewModel : IModifierTypeViewModel
|
||||
{
|
||||
public ModifierTypeViewModel(DataBindingModifierType modifierType)
|
||||
public ModifierTypeViewModel(BaseDataBindingModifierType modifierType)
|
||||
{
|
||||
ModifierType = modifierType;
|
||||
}
|
||||
|
||||
public DataBindingModifierType ModifierType { get; set; }
|
||||
public BaseDataBindingModifierType ModifierType { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user