Implemented layer elements

Added a brush layer element
Corsair - Added ST100 RGB layout
This commit is contained in:
SpoinkyNL committed 2019-12-01 18:55:49 +01:00
1 parent c70c162ef0
commit f8037feb81
81 files changed
+1610 -365

No files matched your search

@@ -16,7 +16,7 @@
Margin="0 8 0 16"
Style="{StaticResource MaterialDesignFloatingHintTextBox}"
Text="{Binding ElementName, UpdateSourceTrigger=PropertyChanged}"
Loaded="FrameworkElement_OnLoaded"/>
Loaded="FrameworkElement_OnLoaded" />
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<Button Style="{StaticResource MaterialDesignFlatButton}" IsCancel="True" Margin="0 8 8 0" Command="{s:Action Cancel}">
@@ -3,15 +3,23 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.ElementProperties"
xmlns:elementProperties="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.ElementProperties"
xmlns:s="https://github.com/canton7/Stylet"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance {x:Type elementProperties:ElementPropertiesViewModel}}">
<Grid>
<StackPanel>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0">
<TextBlock Style="{StaticResource MaterialDesignSubheadingTextBlock}" Margin="10 5 0 -4">
Layer element properties
</TextBlock>
<Separator Style="{StaticResource MaterialDesignDarkSeparator}" Margin="8 0" />
</StackPanel>
<ContentControl Grid.Row="1" s:View.Model="{Binding LayerElementViewModel}" />
</Grid>
</UserControl>
@@ -1,6 +1,25 @@
namespace Artemis.UI.Screens.Module.ProfileEditor.ElementProperties
using System;
using Artemis.Core.Plugins.LayerElement;
using Artemis.UI.Services.Interfaces;
namespace Artemis.UI.Screens.Module.ProfileEditor.ElementProperties
{
public class ElementPropertiesViewModel : ProfileEditorPanelViewModel
{
private readonly IProfileEditorService _profileEditorService;
public ElementPropertiesViewModel(IProfileEditorService profileEditorService)
{
_profileEditorService = profileEditorService;
_profileEditorService.SelectedLayerElementChanged += OnSelectedLayerElementChanged;
}
public LayerElementViewModel LayerElementViewModel { get; set; }
private void OnSelectedLayerElementChanged(object sender, EventArgs e)
{
LayerElementViewModel = _profileEditorService.SelectedLayerElement?.GetViewModel();
}
}
}
@@ -1,10 +0,0 @@
<UserControl x:Class="Artemis.UI.Screens.Module.ProfileEditor.ElementProperties.ElementPropertyView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.ElementProperties"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid />
</UserControl>
@@ -1,6 +0,0 @@
namespace Artemis.UI.Screens.Module.ProfileEditor.ElementProperties
{
public class ElementPropertyViewModel
{
}
}
@@ -0,0 +1,45 @@
<UserControl x:Class="Artemis.UI.Screens.Module.ProfileEditor.LayerElements.Dialogs.AddLayerElementView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:layerElement="clr-namespace:Artemis.Core.Plugins.LayerElement;assembly=Artemis.Core"
xmlns:layerElements="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.LayerElements.Dialogs"
xmlns:s="https://github.com/canton7/Stylet"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance {x:Type layerElements:AddLayerElementViewModel}}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Margin="15">Select a new layer element below</TextBlock>
<ListBox Grid.Row="1" ItemsSource="{Binding LayerElementDescriptors}" SelectedItem="{Binding SelectedLayerElementDescriptor}" HorizontalContentAlignment="Stretch">
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type layerElement:LayerElementDescriptor}">
<Border Padding="8" BorderThickness="0 0 0 1" BorderBrush="{DynamicResource MaterialDesignDivider}" VerticalAlignment="Stretch" MouseDown="{s:Action ListBoxItemMouseClick}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<materialDesign:PackIcon Kind="{Binding Icon}" Width="20" Height="20" VerticalAlignment="Center" />
<StackPanel Margin="8 0 0 0" Grid.Column="1" VerticalAlignment="Stretch">
<TextBlock FontWeight="Bold" Text="{Binding DisplayName}" />
<TextBlock Text="{Binding Description}" />
</StackPanel>
</Grid>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right" Margin="10 15">
<Button Style="{StaticResource MaterialDesignFlatButton}" IsCancel="True" Margin="0 8 8 0" Command="{s:Action Cancel}">CANCEL</Button>
<Button Style="{StaticResource MaterialDesignFlatButton}" IsDefault="True" Margin="0 8 8 0" Command="{s:Action Accept}">ACCEPT</Button>
</StackPanel>
</Grid>
</UserControl>
@@ -0,0 +1,53 @@
using System.Windows.Input;
using Artemis.Core.Models.Profile;
using Artemis.Core.Plugins.LayerElement;
using Artemis.Core.Services.Interfaces;
using Artemis.UI.ViewModels.Dialogs;
using Stylet;
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerElements.Dialogs
{
public class AddLayerElementViewModel : DialogViewModelBase
{
private readonly ILayerService _layerService;
public AddLayerElementViewModel(IPluginService pluginService, ILayerService layerService, Layer layer)
{
_layerService = layerService;
Layer = layer;
LayerElementDescriptors = new BindableCollection<LayerElementDescriptor>();
var layerElementProviders = pluginService.GetPluginsOfType<LayerElementProvider>();
foreach (var layerElementProvider in layerElementProviders)
LayerElementDescriptors.AddRange(layerElementProvider.LayerElementDescriptors);
}
public Layer Layer { get; }
public LayerElementDescriptor SelectedLayerElementDescriptor { get; set; }
public BindableCollection<LayerElementDescriptor> LayerElementDescriptors { get; set; }
public bool CanAccept => SelectedLayerElementDescriptor != null;
public void Accept()
{
var layerElement = _layerService.InstantiateLayerElement(Layer, SelectedLayerElementDescriptor);
Session.Close(layerElement);
}
public void Cancel()
{
Session.Close();
}
#region View event handlers
public void ListBoxItemMouseClick(object sender, MouseButtonEventArgs args)
{
if (args.ClickCount > 1 && SelectedLayerElementDescriptor != null)
Accept();
}
#endregion
}
}
@@ -1,10 +0,0 @@
<UserControl x:Class="Artemis.UI.Screens.Module.ProfileEditor.LayerElements.LayerElementView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.LayerElements"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid />
</UserControl>
@@ -1,6 +1,19 @@
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerElements
using Artemis.Core.Models.Profile;
using Artemis.Core.Plugins.LayerElement;
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerElements
{
public class LayerElementViewModel
{
public LayerElementViewModel(LayerElement layerElement)
{
Layer = layerElement.Layer;
LayerElement = layerElement;
LayerElementDescriptor = layerElement.Descriptor;
}
public Layer Layer { get; set; }
public LayerElement LayerElement { get; set; }
public LayerElementDescriptor LayerElementDescriptor { get; set; }
}
}
@@ -3,15 +3,69 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.LayerElements"
xmlns:layerElements="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.LayerElements"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:s="https://github.com/canton7/Stylet"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<StackPanel>
<TextBlock Style="{StaticResource MaterialDesignSubheadingTextBlock}" Margin="10 5 0 -4">
Layer elements
</TextBlock>
<Separator Style="{StaticResource MaterialDesignDarkSeparator}" Margin="8 0" />
</StackPanel>
</Grid>
d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance {x:Type layerElements:LayerElementsViewModel}}">
<materialDesign:DialogHost Identifier="LayerElementsDialogHost" CloseOnClickAway="True">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0">
<TextBlock Style="{StaticResource MaterialDesignSubheadingTextBlock}" Margin="10 5 0 -4">
Layer elements
</TextBlock>
<Separator Style="{StaticResource MaterialDesignDarkSeparator}" Margin="8 0" />
</StackPanel>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ListBox ItemsSource="{Binding LayerElements}" SelectedItem="{Binding SelectedLayerElement}" HorizontalContentAlignment="Stretch">
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type layerElements:LayerElementViewModel}">
<Border Padding="8" BorderThickness="0 0 0 1" BorderBrush="{DynamicResource MaterialDesignDivider}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<materialDesign:PackIcon Kind="{Binding LayerElementDescriptor.Icon}" Width="20" Height="20" VerticalAlignment="Center" />
<StackPanel Margin="8 0 0 0" Grid.Column="1">
<TextBlock FontWeight="Bold" Text="{Binding LayerElementDescriptor.DisplayName}" />
<TextBlock Text="{Binding LayerElementDescriptor.Description}" />
</StackPanel>
</Grid>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<StackPanel VerticalAlignment="Bottom" Grid.Column="1" Orientation="Vertical" Margin="8">
<Button Style="{StaticResource MaterialDesignToolButton}"
Width="30"
Padding="2 0 2 0"
materialDesign:RippleAssist.IsCentered="True"
ToolTip="Add a new layer element"
Command="{s:Action AddLayerElement}">
<materialDesign:PackIcon Kind="LibraryAdd" />
</Button>
<Button Style="{StaticResource MaterialDesignToolButton}"
Width="30"
Padding="2 0 2 0"
materialDesign:RippleAssist.IsCentered="True"
ToolTip="Delete selected layer element"
Command="{s:Action DeleteSelectedLayerElement}">
<materialDesign:PackIcon Kind="Delete" />
</Button>
</StackPanel>
</Grid>
</Grid>
</materialDesign:DialogHost>
</UserControl>
@@ -1,6 +1,95 @@
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerElements
using System;
using System.Collections.Generic;
using System.Linq;
using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Profile.Abstract;
using Artemis.Core.Plugins.LayerElement;
using Artemis.UI.Screens.Module.ProfileEditor.LayerElements.Dialogs;
using Artemis.UI.Services.Interfaces;
using Stylet;
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerElements
{
public class LayerElementsViewModel : ProfileEditorPanelViewModel
{
private readonly IDialogService _dialogService;
private readonly IProfileEditorService _profileEditorService;
private LayerElementViewModel _selectedLayerElement;
public LayerElementsViewModel(IProfileEditorService profileEditorService, IDialogService dialogService)
{
_profileEditorService = profileEditorService;
_dialogService = dialogService;
LayerElements = new BindableCollection<LayerElementViewModel>();
SelectedProfileElement = _profileEditorService.SelectedProfileElement;
PopulateLayerElements();
_profileEditorService.SelectedProfileElementChanged += OnSelectedProfileElementChanged;
_profileEditorService.SelectedLayerElementChanged += OnSelectedLayerElementChanged;
}
public ProfileElement SelectedProfileElement { get; private set; }
public BindableCollection<LayerElementViewModel> LayerElements { get; set; }
public LayerElementViewModel SelectedLayerElement
{
get => _selectedLayerElement;
set
{
_selectedLayerElement = value;
_profileEditorService.ChangeSelectedLayerElement(value?.LayerElement);
}
}
public bool CanAddLayerElement => SelectedProfileElement is Layer;
public bool CanDeleteSelectedLayerElement => SelectedLayerElement != null;
private void OnSelectedLayerElementChanged(object sender, EventArgs e)
{
_selectedLayerElement = LayerElements.FirstOrDefault(l => l.LayerElement == _profileEditorService.SelectedLayerElement);
NotifyOfPropertyChange(() => SelectedLayerElement);
}
private void OnSelectedProfileElementChanged(object sender, EventArgs e)
{
SelectedProfileElement = _profileEditorService.SelectedProfileElement;
PopulateLayerElements();
}
private void PopulateLayerElements()
{
LayerElements.Clear();
if (SelectedProfileElement is Layer layer)
{
foreach (var layerElement in layer.LayerElements)
LayerElements.Add(new LayerElementViewModel(layerElement));
}
}
public async void AddLayerElement()
{
var result = await _dialogService.ShowDialogAt<AddLayerElementViewModel>(
"LayerElementsDialogHost",
new Dictionary<string, object> {{"layer", (Layer) SelectedProfileElement}}
);
if (result is LayerElement layerElement)
LayerElements.Add(new LayerElementViewModel(layerElement));
}
public async void DeleteSelectedLayerElement()
{
if (SelectedLayerElement == null)
return;
var result = await _dialogService.ShowConfirmDialogAt(
"LayerElementsDialogHost",
"Delete layer element",
"Are you sure you want to delete the selected layer element?"
);
if (!result)
return;
}
}
}
@@ -8,7 +8,6 @@ using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.Models;
using Artemis.Core.Services;
using Artemis.Core.Services.Storage.Interfaces;
using Artemis.UI.Events;
using Artemis.UI.Screens.Module.ProfileEditor.Dialogs;
using Artemis.UI.Screens.Module.ProfileEditor.DisplayConditions;
using Artemis.UI.Screens.Module.ProfileEditor.ElementProperties;
@@ -29,8 +28,8 @@ namespace Artemis.UI.Screens.Module.ProfileEditor
public ProfileEditorViewModel(ProfileModule module,
ICollection<ProfileEditorPanelViewModel> viewModels,
IProfileEditorService profileEditorService,
IProfileService profileService,
IDialogService dialogService,
IProfileService profileService,
IDialogService dialogService,
ISettingsService settingsService)
{
_profileEditorService = profileEditorService;
@@ -81,8 +80,8 @@ namespace Artemis.UI.Screens.Module.ProfileEditor
return;
var oldProfile = Module.ActiveProfile;
Module.ChangeActiveProfile(profile);
_profileService.ActivateProfile(Module, profile);
if (oldProfile != null)
_profileService.UpdateProfile(oldProfile, false);
if (profile != null)
@@ -186,7 +185,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor
_profileEditorService.ChangeSelectedProfile(SelectedProfile);
if (!activeProfile.IsActivated)
Module.ChangeActiveProfile(activeProfile);
_profileService.ActivateProfile(Module, activeProfile);
}
}
}
@@ -25,7 +25,7 @@
</TextBlock>
<Separator Style="{StaticResource MaterialDesignDarkSeparator}" Margin="8 0" />
</StackPanel>
<TreeView Grid.Row="1"
ItemsSource="{Binding RootFolder.Children}"
HorizontalContentAlignment="Stretch"
@@ -132,10 +132,10 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileTree
private void OnSelectedElementChanged(object sender, EventArgs e)
{
var vms = RootFolder.GetAllChildren();
var vms = RootFolder?.GetAllChildren();
// Don't set it using the setter or that will trigger the event again
_selectedTreeItem = vms.FirstOrDefault(vm => vm.ProfileElement == _profileEditorService.SelectedProfileElement);
_selectedTreeItem = vms?.FirstOrDefault(vm => vm.ProfileElement == _profileEditorService.SelectedProfileElement);
NotifyOfPropertyChange(() => SelectedTreeItem);
}
@@ -37,9 +37,11 @@
</ContextMenu>
</StackPanel.ContextMenu>
<StackPanel Orientation="Horizontal" Margin="10">
<materialDesign:PackIcon Kind="Folder" Visibility="{Binding IsExpanded, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TreeViewItem}}}"/>
<materialDesign:PackIcon Kind="FolderOpen" Visibility="{Binding IsExpanded, Converter={x:Static s:BoolToVisibilityConverter.Instance}, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TreeViewItem}}}"/>
<materialDesign:PackIcon Kind="Folder"
Visibility="{Binding IsExpanded, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TreeViewItem}}}" />
<materialDesign:PackIcon Kind="FolderOpen"
Visibility="{Binding IsExpanded, Converter={x:Static s:BoolToVisibilityConverter.Instance}, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TreeViewItem}}}" />
<TextBlock Text="{Binding ProfileElement.Name}" Margin="10 0 0 0" />
</StackPanel>
</StackPanel>
@@ -38,7 +38,6 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
public Geometry StrokeGeometry { get; private set; }
public Color DisplayColor { get; private set; }
private void CreateLedGeometry()
{
switch (Led.RgbLed.Shape)