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

Fixed profile editor deselecting layer when closing the edit window

This commit is contained in:
SpoinkyNL 2016-08-24 22:12:38 +02:00
parent 3739ffad03
commit 278afc9110
5 changed files with 44 additions and 26 deletions

View File

@ -1,4 +1,5 @@
using Artemis.Profiles.Layers.Models; using System.ComponentModel;
using Artemis.Profiles.Layers.Models;
namespace Artemis.Profiles.Layers.Types.Audio namespace Artemis.Profiles.Layers.Types.Audio
{ {
@ -10,5 +11,14 @@ namespace Artemis.Profiles.Layers.Types.Audio
public int Sensitivity { get; set; } public int Sensitivity { get; set; }
public double FadeSpeed { get; set; } public double FadeSpeed { get; set; }
public Direction Direction { get; set; }
}
public enum Direction
{
[Description("Top to bottom")] TopToBottom,
[Description("Bottom to top")] BottomToTop,
[Description("Left to right")] LeftToRight,
[Description("Right to left")] RightToLeft
} }
} }

View File

@ -4,9 +4,21 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ncore="http://schemas.ncore.com/wpf/xaml/colorbox" xmlns:ncore="http://schemas.ncore.com/wpf/xaml/colorbox"
xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls" xmlns:properties="clr-namespace:Artemis.Profiles.Layers.Types.Audio"
xmlns:system="clr-namespace:System;assembly=mscorlib"
xmlns:converters="clr-namespace:Artemis.Utilities.Converters"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="600" d:DesignWidth="500"> d:DesignHeight="600" d:DesignWidth="500">
<UserControl.Resources>
<converters:EnumDescriptionConverter x:Key="HEnumDescriptionConverter" />
<ObjectDataProvider MethodName="GetValues"
ObjectType="{x:Type system:Enum}"
x:Key="DirectionEnumValues">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="properties:Direction" />
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</UserControl.Resources>
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition /> <ColumnDefinition />
@ -49,12 +61,18 @@
</Border> </Border>
</StackPanel> </StackPanel>
<!-- Random color --> <!-- Bar direction -->
<TextBlock Grid.Row="1" Grid.Column="2" Margin="10,13,10,10" FontSize="13.333" Text="Bar direction:" <TextBlock Grid.Row="1" Grid.Column="2" Margin="10,13,10,10" FontSize="13.333" Text="Bar direction:"
VerticalAlignment="Top" Height="18" /> VerticalAlignment="Top" Height="18" />
<controls:ToggleSwitch Grid.Row="1" Grid.Column="3" OnLabel="Yes" OffLabel="No" <ComboBox Grid.Row="1" Grid.Column="3" ItemsSource="{Binding Source={StaticResource DirectionEnumValues}}"
IsChecked="{Binding Path=LayerModel.Properties.RandomColor, Mode=TwoWay}" Margin="10,10,10,0" SelectedItem="{Binding Path=LayerModel.Properties.Direction}"
VerticalAlignment="Top" Margin="10,5,10,2" /> VerticalAlignment="Top" Height="22">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Converter={StaticResource HEnumDescriptionConverter}}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</Grid> </Grid>
</UserControl> </UserControl>

View File

@ -41,6 +41,7 @@ namespace Artemis.Profiles.Layers.Types.Audio
_waveIn.StartRecording(); _waveIn.StartRecording();
} }
[JsonIgnore]
public List<byte> SpectrumData { get; set; } = new List<byte>(); public List<byte> SpectrumData { get; set; } = new List<byte>();
public string Name { get; } = "Keyboard - Audio visualization"; public string Name { get; } = "Keyboard - Audio visualization";

View File

@ -35,7 +35,7 @@
VerticalAlignment="Top" Height="18" /> VerticalAlignment="Top" Height="18" />
<Slider x:Name="RotationSpeed" Grid.Row="0" Grid.Column="3" VerticalAlignment="Top" <Slider x:Name="RotationSpeed" Grid.Row="0" Grid.Column="3" VerticalAlignment="Top"
TickPlacement="None" TickFrequency="0.05" TickPlacement="None" TickFrequency="0.05"
Value="{Binding Path=LayerModel.Properties.AnimationSpeed, Mode=TwoWay}" Minimum="0.05" Maximum="3" Value="{Binding Path=LayerModel.Properties.AnimationSpeed, Mode=TwoWay}" Minimum="0.5" Maximum="5"
SmallChange="0" IsSnapToTickEnabled="True" Margin="10,12,10,2" Height="24" /> SmallChange="0" IsSnapToTickEnabled="True" Margin="10,12,10,2" Height="24" />
<!-- Colors --> <!-- Colors -->

View File

@ -15,6 +15,7 @@ using Artemis.ViewModels.Profiles.Events;
using Caliburn.Micro; using Caliburn.Micro;
using Newtonsoft.Json; using Newtonsoft.Json;
using Ninject; using Ninject;
using NuGet;
namespace Artemis.ViewModels.Profiles namespace Artemis.ViewModels.Profiles
{ {
@ -40,6 +41,7 @@ namespace Artemis.ViewModels.Profiles
Layer = layer; Layer = layer;
ProposedLayer = GeneralHelpers.Clone(layer); ProposedLayer = GeneralHelpers.Clone(layer);
ProposedLayer.Children.Clear();
if (Layer.Properties == null) if (Layer.Properties == null)
Layer.SetupProperties(); Layer.SetupProperties();
@ -165,24 +167,7 @@ namespace Artemis.ViewModels.Profiles
public void Apply() public void Apply()
{ {
LayerPropertiesViewModel?.ApplyProperties(); LayerPropertiesViewModel?.ApplyProperties();
var appliedLayer = GeneralHelpers.Clone(ProposedLayer); JsonConvert.PopulateObject(JsonConvert.SerializeObject(ProposedLayer), Layer);
// Fix relations
if (Layer.Parent != null)
{
Layer.Parent.Children.Add(appliedLayer);
Layer.Parent.Children.Remove(Layer);
}
else
{
Layer.Profile.Layers.Add(appliedLayer);
Layer.Profile.Layers.Remove(Layer);
}
appliedLayer.Children.Clear();
foreach (var layerModel in Layer.Children)
appliedLayer.Children.Add(layerModel);
Layer = appliedLayer;
// TODO: EventPropVM must have layer too // TODO: EventPropVM must have layer too
if (EventPropertiesViewModel != null) if (EventPropertiesViewModel != null)
@ -227,7 +212,11 @@ namespace Artemis.ViewModels.Profiles
ProposedLayer.Properties.Contain = Layer.Properties.Contain; ProposedLayer.Properties.Contain = Layer.Properties.Contain;
} }
var current = JsonConvert.SerializeObject(Layer, Formatting.Indented); // Ignore the children, can't just temporarily add them to the proposed layer because
// that would upset the child layers' relations (sounds like an episode of Dr. Phil amirite?)
var currentObj = GeneralHelpers.Clone(Layer);
currentObj.Children.Clear();
var current = JsonConvert.SerializeObject(currentObj, Formatting.Indented);
var proposed = JsonConvert.SerializeObject(ProposedLayer, Formatting.Indented); var proposed = JsonConvert.SerializeObject(ProposedLayer, Formatting.Indented);
if (current.Equals(proposed)) if (current.Equals(proposed))