1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Profile editor - Fixed new layers not saving in some situations

Profile tree - Improved buttons visibility
Layer brushes - Support transformation by default, unless a RGB.NET brush
This commit is contained in:
SpoinkyNL 2020-06-11 21:16:13 +02:00
parent c60ae48e66
commit f917728ac8
13 changed files with 88 additions and 40 deletions

View File

@ -1,5 +1,6 @@
using System;
using Artemis.Core.Models.Profile;
using Artemis.Core.Plugins.Exceptions;
using Artemis.Core.Plugins.Models;
using Artemis.Core.Services.Interfaces;
using SkiaSharp;
@ -11,6 +12,8 @@ namespace Artemis.Core.Plugins.LayerBrush.Abstract
/// </summary>
public abstract class BaseLayerBrush : IDisposable
{
private bool _supportsTransformation = true;
/// <summary>
/// Gets the layer this brush is applied to
/// </summary>
@ -37,9 +40,19 @@ namespace Artemis.Core.Plugins.LayerBrush.Abstract
public virtual LayerPropertyGroup BaseProperties => null;
/// <summary>
/// Gets whether the brush supports transformations, RGB.NET brushes never support transformation
/// Gets or sets whether the brush supports transformations
/// <para>Note: RGB.NET brushes can never be transformed and setting this to true will throw an exception</para>
/// </summary>
public bool SupportsTransformation { get; protected set; }
public bool SupportsTransformation
{
get => _supportsTransformation;
protected set
{
if (BrushType == LayerBrushType.RgbNet)
throw new ArtemisPluginException(PluginInfo, "An RGB.NET brush cannot support transformation");
_supportsTransformation = value;
}
}
public void Dispose()
{

View File

@ -13,6 +13,7 @@ namespace Artemis.Core.Plugins.LayerBrush.Abstract
protected RgbNetLayerBrush()
{
BrushType = LayerBrushType.RgbNet;
SupportsTransformation = false;
}
/// <summary>

View File

@ -19,7 +19,7 @@ namespace Artemis.UI.Shared.Services.Interfaces
IKernel Kernel { get; }
void ChangeSelectedProfile(Profile profile);
void UpdateSelectedProfile();
void UpdateSelectedProfile(bool includeChildren);
void ChangeSelectedProfileElement(ProfileElement profileElement);
void UpdateSelectedProfileElement();
void UpdateProfilePreview();

View File

@ -71,9 +71,9 @@ namespace Artemis.UI.Shared.Services
OnSelectedProfileChanged(profileElementEvent);
}
public void UpdateSelectedProfile()
public void UpdateSelectedProfile(bool includeChildren)
{
_profileService.UpdateProfile(SelectedProfile, false);
_profileService.UpdateProfile(SelectedProfile, includeChildren);
UpdateProfilePreview();
OnSelectedProfileElementUpdated(new ProfileElementEventArgs(SelectedProfile));
}

View File

@ -9,17 +9,22 @@ namespace Artemis.UI.Converters
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var direction = (Parameters) Enum.Parse(typeof(Parameters), (string) parameter ?? throw new InvalidOperationException());
Parameters direction;
if (parameter == null)
direction = Parameters.Normal;
else
direction = (Parameters) Enum.Parse(typeof(Parameters), (string) parameter);
if (direction == Parameters.Normal)
{
if (value == null)
return Visibility.Hidden;
return Visibility.Collapsed;
return Visibility.Visible;
}
if (value == null)
return Visibility.Visible;
return Visibility.Hidden;
return Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)

View File

@ -1,4 +1,4 @@
<UserControl x:Class="Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.LayerPropertiesView"
<UserControl
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"
@ -8,16 +8,14 @@
xmlns:timeline="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Timeline"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:behaviors="clr-namespace:Artemis.UI.Behaviors"
xmlns:Converters="clr-namespace:Artemis.UI.Converters" x:Class="Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.LayerPropertiesView"
mc:Ignorable="d"
d:DesignHeight="450"
d:DesignWidth="800"
d:DataContext="{d:DesignInstance local:LayerPropertiesViewModel}"
d:DataContext="{d:DesignInstance {x:Type local:LayerPropertiesViewModel}}"
behaviors:InputBindingBehavior.PropagateInputBindingsToWindow="True">
<UserControl.InputBindings>
<KeyBinding Command="{s:Action Play}" Key="Space" />
<KeyBinding Command="{s:Action PlayFromStart}" Modifiers="Shift" Key="Space" />
</UserControl.InputBindings>
<UserControl.Resources>
<Converters:NullToVisibilityConverter x:Key="NullToVisibilityConverter"/>
<Style x:Key="SvStyle" TargetType="{x:Type ScrollViewer}">
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Template">
@ -33,7 +31,7 @@
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ScrollContentPresenter Grid.ColumnSpan="2" Grid.RowSpan="2" />
<ScrollBar Name="PART_VerticalScrollBar"
<ScrollBar x:Name="PART_VerticalScrollBar"
HorizontalAlignment="Right"
Opacity="0.5"
Grid.Row="0"
@ -42,7 +40,7 @@
Maximum="{TemplateBinding ScrollableHeight}"
ViewportSize="{TemplateBinding ViewportHeight}"
Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}" />
<ScrollBar Name="PART_HorizontalScrollBar"
<ScrollBar x:Name="PART_HorizontalScrollBar"
VerticalAlignment="Bottom"
Orientation="Horizontal"
Opacity="0.5"
@ -58,6 +56,10 @@
</Setter>
</Style>
</UserControl.Resources>
<UserControl.InputBindings>
<KeyBinding Command="{s:Action Play}" Key="Space" />
<KeyBinding Command="{s:Action PlayFromStart}" Modifiers="Shift" Key="Space" />
</UserControl.InputBindings>
<Grid x:Name="ContainerGrid">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
@ -147,13 +149,13 @@
VerticalScrollBarVisibility="Hidden" ScrollChanged="TimelineScrollChanged">
<Grid Background="{DynamicResource MaterialDesignCardBackground}">
<!-- Caret -->
<Canvas ZIndex="1"
<Canvas Panel.ZIndex="1"
Margin="{Binding TimeCaretPosition}"
Cursor="SizeWE"
MouseDown="{s:Action TimelineMouseDown}"
MouseUp="{s:Action TimelineMouseUp}"
MouseMove="{s:Action TimelineMouseMove}">
<Polygon Points="-10,0 0,20, 10,00" Fill="{StaticResource SecondaryAccentBrush}" />
<Polygon Points="-10,0 0,20 10,0" Fill="{StaticResource SecondaryAccentBrush}" />
<Line X1="0" X2="0" Y1="0" Y2="{Binding ActualHeight, ElementName=ContainerGrid}"
StrokeThickness="2" Stroke="{StaticResource SecondaryAccentBrush}" />
</Canvas>
@ -175,7 +177,7 @@
VerticalScrollBarVisibility="Auto"
ScrollChanged="TimelineScrollChanged">
<Grid>
<Canvas ZIndex="1"
<Canvas Panel.ZIndex="1"
Margin="{Binding TimeCaretPosition}"
Cursor="SizeWE"
MouseDown="{s:Action TimelineMouseDown}"
@ -194,7 +196,7 @@
Grid.ColumnSpan="2"
Grid.Column="0"
HorizontalAlignment="Stretch"
ZIndex="2"
Panel.ZIndex="2"
Background="{DynamicResource MaterialDesignCardBackground}">
<!-- Selected layer controls -->
<Grid.ColumnDefinitions>
@ -206,15 +208,26 @@
<ColumnDefinition />
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Orientation="Horizontal" Margin="6">
<StackPanel Grid.Column="0"
Orientation="Horizontal"
Margin="6"
Visibility="{Binding SelectedLayer, Converter={StaticResource NullToVisibilityConverter}}">
<materialDesign:PackIcon Kind="Layers" Width="16" />
<materialDesign:PackIcon Kind="{Binding SelectedLayer.LayerBrush.Descriptor.Icon}"
Width="16"
Margin="5 0 0 0"
ToolTip="{Binding SelectedLayer.LayerBrush.Descriptor.DisplayName, Mode=OneWay}"
Background="Transparent" />
Background="Transparent"
Visibility="{Binding SelectedLayer.LayerBrush, Converter={StaticResource NullToVisibilityConverter}}"/>
<TextBlock Text="{Binding SelectedLayer.Name}" Margin="5 0 0 0" />
</StackPanel>
<StackPanel Grid.Column="0"
Orientation="Horizontal"
Margin="6"
Visibility="{Binding SelectedFolder, Converter={StaticResource NullToVisibilityConverter}}">
<materialDesign:PackIcon Kind="Folder" Width="16" />
<TextBlock Text="{Binding SelectedFolder.Name}" Margin="5 0 0 0" />
</StackPanel>
<Button Grid.Column="1"
Style="{StaticResource MaterialDesignFlatMidBgButton}"
Margin="0 -2"
@ -224,7 +237,7 @@
ToolTip="Change the property's data binding"
VerticalAlignment="Center">
<TextBlock FontSize="10">ADD EFFECT</TextBlock>
<TextBlock FontSize="10"><Run Text="ADD EFFECT"/></TextBlock>
</Button>
</Grid>

View File

@ -47,6 +47,8 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
}
public Layer SelectedLayer { get; set; }
public Folder SelectedFolder { get; set; }
public BindableCollection<LayerPropertyGroupViewModel> LayerPropertyGroups { get; set; }
public TreeViewModel TreeViewModel { get; set; }
public TimelineViewModel TimelineViewModel { get; set; }
@ -104,6 +106,10 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
private void PopulateProperties(ProfileElement profileElement)
{
if (SelectedFolder != null)
{
SelectedFolder = null;
}
if (SelectedLayer != null)
{
SelectedLayer.LayerBrushUpdated -= SelectedLayerOnLayerBrushUpdated;
@ -115,7 +121,11 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
LayerPropertyGroups.Clear();
_brushPropertyGroup = null;
if (profileElement is Layer layer)
if (profileElement is Folder folder)
{
SelectedFolder = folder;
}
else if (profileElement is Layer layer)
{
SelectedLayer = layer;
SelectedLayer.LayerBrushUpdated += SelectedLayerOnLayerBrushUpdated;
@ -151,7 +161,8 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
if (SelectedLayer == null)
return;
var hideRenderRelatedProperties = SelectedLayer?.LayerBrush?.BrushType == LayerBrushType.Regular && SelectedLayer.LayerBrush.SupportsTransformation;
var hideRenderRelatedProperties = SelectedLayer?.LayerBrush != null && !SelectedLayer.LayerBrush.SupportsTransformation;
SelectedLayer.General.ShapeType.IsHidden = hideRenderRelatedProperties;
SelectedLayer.General.FillType.IsHidden = hideRenderRelatedProperties;
SelectedLayer.General.BlendMode.IsHidden = hideRenderRelatedProperties;

View File

@ -47,21 +47,23 @@
</TreeView>
<StackPanel HorizontalAlignment="Right" Grid.Row="2" Orientation="Horizontal" Margin="8">
<Button Style="{StaticResource MaterialDesignToolButton}"
Width="30"
<Button Style="{StaticResource MaterialDesignIconForegroundButton}"
Padding="2 0 2 0"
Width="30"
Height="30"
materialDesign:RippleAssist.IsCentered="True"
ToolTip="Add new folder to root"
Command="{s:Action AddFolder}">
<materialDesign:PackIcon Kind="CreateNewFolder" />
<materialDesign:PackIcon Kind="CreateNewFolder" Width="15"/>
</Button>
<Button Style="{StaticResource MaterialDesignToolButton}"
<Button Style="{StaticResource MaterialDesignIconForegroundButton}"
Width="30"
Height="30"
Padding="2 0 2 0"
materialDesign:RippleAssist.IsCentered="True"
ToolTip="Add new layer to root"
Command="{s:Action AddLayer}">
<materialDesign:PackIcon Kind="LayersPlus" />
<materialDesign:PackIcon Kind="LayersPlus" Width="15"/>
</Button>
</StackPanel>
</Grid>

View File

@ -78,7 +78,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileTree
break;
}
_profileEditorService.UpdateSelectedProfile();
_profileEditorService.UpdateSelectedProfile(true);
}
// ReSharper disable once UnusedMember.Global - Called from view

View File

@ -114,7 +114,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileTree.TreeItem
ProfileElement.AddChild(new Folder(ProfileElement.Profile, ProfileElement, "New folder"));
UpdateProfileElements();
_profileEditorService.UpdateSelectedProfile();
_profileEditorService.UpdateSelectedProfile(true);
}
public void AddLayer()
@ -124,7 +124,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileTree.TreeItem
_layerService.CreateLayer(ProfileElement.Profile, ProfileElement, "New layer");
UpdateProfileElements();
_profileEditorService.UpdateSelectedProfile();
_profileEditorService.UpdateSelectedProfile(true);
}
// ReSharper disable once UnusedMember.Global - Called from view
@ -136,7 +136,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileTree.TreeItem
if (result is string newName)
{
ProfileElement.Name = newName;
_profileEditorService.UpdateSelectedProfile();
_profileEditorService.UpdateSelectedProfile(true);
}
}
@ -153,11 +153,11 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileTree.TreeItem
// Farewell, cruel world
var parent = Parent;
ProfileElement.Parent.RemoveChild(ProfileElement);
ProfileElement.Parent?.RemoveChild(ProfileElement);
parent.RemoveExistingElement(this);
parent.UpdateProfileElements();
_profileEditorService.UpdateSelectedProfile();
_profileEditorService.UpdateSelectedProfile(true);
}
public void UpdateProfileElements()

View File

@ -7,6 +7,7 @@ using System.Windows.Media.Imaging;
using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Profile.LayerShapes;
using Artemis.Core.Models.Surface;
using Artemis.Core.Plugins.LayerBrush.Abstract;
using Artemis.UI.Extensions;
using Artemis.UI.Services.Interfaces;
using Artemis.UI.Shared.Services.Interfaces;
@ -147,7 +148,9 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
break;
}
shapeGeometry.Transform = _layerEditorService.GetLayerTransformGroup(Layer);
if (Layer.LayerBrush == null || Layer.LayerBrush.SupportsTransformation)
shapeGeometry.Transform = _layerEditorService.GetLayerTransformGroup(Layer);
ShapeGeometry = shapeGeometry;
});
}

View File

@ -207,7 +207,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
if (_profileEditorService.SelectedProfileElement is Layer layer)
{
CanApplyToLayer = true;
CanSelectEditTool = (layer.LayerBrush == null || layer.LayerBrush.BrushType == LayerBrushType.Regular) && layer.Leds.Any();
CanSelectEditTool = (layer.LayerBrush == null || layer.LayerBrush.SupportsTransformation) && layer.Leds.Any();
}
else
{

View File

@ -58,7 +58,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
newLayer.AddLeds(selectedLeds);
ProfileEditorService.ChangeSelectedProfileElement(newLayer);
ProfileEditorService.UpdateSelectedProfileElement();
ProfileEditorService.UpdateSelectedProfile();
ProfileEditorService.UpdateSelectedProfile(false);
}
// If no folder selected, apply it to a new layer in the root folder
else
@ -68,7 +68,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
newLayer.AddLeds(selectedLeds);
ProfileEditorService.ChangeSelectedProfileElement(newLayer);
ProfileEditorService.UpdateSelectedProfileElement();
ProfileEditorService.UpdateSelectedProfile();
ProfileEditorService.UpdateSelectedProfile(false);
}
}