Profile editor - Finished most of the refactor except databindings

This commit is contained in:
SpoinkyNL committed 2020-09-14 01:24:07 +02:00
1 parent 5b321b25c9
commit d49b574bda
56 files changed
+866 -459

No files matched your search

@@ -11,28 +11,11 @@
d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance {x:Type propertyInput:BrushPropertyInputViewModel}}">
<UserControl.Resources>
<DataTemplate x:Key="SimpleTemplate">
<StackPanel d:DataContext="{d:DesignInstance {x:Type layerBrush:LayerBrushDescriptor}}" Orientation="Horizontal">
<materialDesign:PackIcon Kind="{Binding Icon}" Height="13" Width="13" Margin="0 1 3 0" />
<TextBlock Text="{Binding DisplayName}" />
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="ExtendedTemplate">
<Grid d:DataContext="{d:DesignInstance {x:Type layerBrush:LayerBrushDescriptor}}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<materialDesign:PackIcon Grid.Row="0" Grid.RowSpan="2" Kind="{Binding Icon}" Height="20" Width="20" Margin="-5 -2 10 0" VerticalAlignment="Center" />
<TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding DisplayName}" TextWrapping="Wrap" MaxWidth="350" />
<TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding Description}" TextWrapping="Wrap" MaxWidth="350" Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}" />
</Grid>
</DataTemplate>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Artemis.UI;component/ResourceDictionaries/LayerBrushDescriptors.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<StackPanel Orientation="Horizontal">
<TextBlock Width="10" Text="{Binding LayerProperty.PropertyDescription.InputPrefix}" />
@@ -46,8 +29,8 @@
ItemsSource="{Binding Path=Descriptors}"
SelectedValue="{Binding Path=SelectedDescriptor}"
ItemTemplateSelector="{dataTemplateSelectors:ComboBoxTemplateSelector
SelectedItemTemplate={StaticResource SimpleTemplate},
DropdownItemsTemplate={StaticResource ExtendedTemplate}}" />
SelectedItemTemplate={StaticResource SimpleLayerBrushDescriptorTemplate},
DropdownItemsTemplate={StaticResource ExtendedLayerBrushDescriptorTemplate}}" />
<TextBlock Width="10" Text="{Binding LayerProperty.PropertyDescription.InputAffix}" />
</StackPanel>
</UserControl>
@@ -5,16 +5,17 @@ using Artemis.Core.LayerBrushes;
using Artemis.Core.Services;
using Artemis.UI.Shared;
using Artemis.UI.Shared.Services;
using Stylet;
namespace Artemis.UI.PropertyInput
{
public class BrushPropertyInputViewModel : PropertyInputViewModel<LayerBrushReference>
{
private readonly IPluginService _pluginService;
private List<LayerBrushDescriptor> _descriptors;
private BindableCollection<LayerBrushDescriptor> _descriptors;
public BrushPropertyInputViewModel(LayerProperty<LayerBrushReference> layerProperty,
IProfileEditorService profileEditorService,
IProfileEditorService profileEditorService,
IPluginService pluginService) : base(layerProperty, profileEditorService)
{
_pluginService = pluginService;
@@ -24,7 +25,7 @@ namespace Artemis.UI.PropertyInput
UpdateEnumValues();
}
public List<LayerBrushDescriptor> Descriptors
public BindableCollection<LayerBrushDescriptor> Descriptors
{
get => _descriptors;
set => SetAndNotify(ref _descriptors, value);
@@ -32,14 +33,14 @@ namespace Artemis.UI.PropertyInput
public LayerBrushDescriptor SelectedDescriptor
{
get => Descriptors.FirstOrDefault(d => d.LayerBrushProvider.PluginInfo.Guid == InputValue?.BrushPluginGuid && d.LayerBrushType.Name == InputValue?.BrushType);
get => Descriptors.FirstOrDefault(d => d.MatchesLayerBrushReference(InputValue));
set => SetBrushByDescriptor(value);
}
public void UpdateEnumValues()
{
var layerBrushProviders = _pluginService.GetPluginsOfType<LayerBrushProvider>();
Descriptors = layerBrushProviders.SelectMany(l => l.LayerBrushDescriptors).ToList();
Descriptors = new BindableCollection<LayerBrushDescriptor>(layerBrushProviders.SelectMany(l => l.LayerBrushDescriptors));
NotifyOfPropertyChange(nameof(SelectedDescriptor));
}
@@ -53,13 +54,13 @@ namespace Artemis.UI.PropertyInput
protected override void OnInputValueApplied()
{
if (LayerProperty.ProfileElement is Layer layer)
if (LayerProperty.ProfileElement is Layer layer)
layer.ChangeLayerBrush(SelectedDescriptor);
}
private void SetBrushByDescriptor(LayerBrushDescriptor value)
{
InputValue = new LayerBrushReference {BrushPluginGuid = value.LayerBrushProvider.PluginInfo.Guid, BrushType = value.LayerBrushType.Name};
InputValue = new LayerBrushReference(value);
}
private void PluginServiceOnPluginLoaded(object sender, PluginEventArgs e)