1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-31 17:53:32 +00:00

Merge pull request #506 from diogotr7/feature/reset-layerprop

Added reset layer property button
This commit is contained in:
Robert Beekman 2020-11-21 09:24:27 +01:00 committed by GitHub
commit bc8ac61388
3 changed files with 31 additions and 14 deletions

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
@ -203,13 +203,14 @@ namespace Artemis.Core
/// <summary> /// <summary>
/// Overrides the property value with the default value /// Overrides the property value with the default value
/// </summary> /// </summary>
public void ApplyDefaultValue() public void ApplyDefaultValue(TimeSpan? time)
{ {
if (_disposed) if (_disposed)
throw new ObjectDisposedException("LayerProperty"); throw new ObjectDisposedException("LayerProperty");
BaseValue = DefaultValue; string json = JsonConvert.SerializeObject(DefaultValue, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All });
CurrentValue = DefaultValue;
SetCurrentValue(JsonConvert.DeserializeObject<T>(json), time);
} }
private void ReapplyUpdate() private void ReapplyUpdate()
@ -506,7 +507,7 @@ namespace Artemis.Core
throw new ArtemisCoreException("Layer property is not yet initialized"); throw new ArtemisCoreException("Layer property is not yet initialized");
if (!IsLoadedFromStorage) if (!IsLoadedFromStorage)
ApplyDefaultValue(); ApplyDefaultValue(null);
else else
try try
{ {

View File

@ -1,4 +1,4 @@
<UserControl x:Class="Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree.TreePropertyView" <UserControl x:Class="Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree.TreePropertyView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
@ -48,16 +48,17 @@
<ColumnDefinition Width="*" /> <ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<ToggleButton Grid.Column="0" <ToggleButton Grid.Column="0"
Style="{StaticResource MaterialDesignFlatToggleButton}" Style="{StaticResource MaterialDesignFlatToggleButton}"
ToolTip="Toggle key-framing" ToolTip="Toggle key-framing"
Width="18" Width="24"
Height="18" Height="24"
IsChecked="{Binding KeyframesEnabled}" IsChecked="{Binding KeyframesEnabled}"
IsEnabled="{Binding LayerProperty.KeyframesSupported}" IsEnabled="{Binding LayerProperty.KeyframesSupported}"
VerticalAlignment="Center" Padding="-25"> VerticalAlignment="Center" Padding="-25">
<materialDesign:PackIcon Kind="Stopwatch" Height="13" Width="13" /> <materialDesign:PackIcon Kind="Stopwatch" Height="16" Width="16" />
</ToggleButton> </ToggleButton>
<TextBlock Grid.Column="1" <TextBlock Grid.Column="1"
@ -68,7 +69,7 @@
Text="{Binding LayerProperty.PropertyDescription.Name}" Text="{Binding LayerProperty.PropertyDescription.Name}"
ToolTip="{Binding LayerProperty.PropertyDescription.Description}" ToolTip="{Binding LayerProperty.PropertyDescription.Description}"
HorizontalAlignment="Left" /> HorizontalAlignment="Left" />
<ContentControl Grid.Column="2" Margin="20 0" s:View.Model="{Binding PropertyInputViewModel, IsAsync=True}"> <ContentControl Grid.Column="2" Margin="20 0" s:View.Model="{Binding PropertyInputViewModel, IsAsync=True}">
<ContentControl.Resources> <ContentControl.Resources>
<Style TargetType="TextBlock"> <Style TargetType="TextBlock">
@ -78,17 +79,26 @@
</ContentControl.Resources> </ContentControl.Resources>
</ContentControl> </ContentControl>
<shared:LockableToggleButton Grid.Column="3" <Button Grid.Column="3"
Command="{s:Action ResetToDefault}"
Style="{StaticResource MaterialDesignIconButton}"
ToolTip="Reset the property to its default value."
Width="24"
Height="24">
<materialDesign:PackIcon Kind="BackupRestore" Height="16" Width="16" />
</Button>
<shared:LockableToggleButton Grid.Column="4"
Style="{StaticResource DataBindingsButton}" Style="{StaticResource DataBindingsButton}"
ToolTip="Change the property's data binding" ToolTip="Change the property's data binding"
Width="20" Width="24"
Height="20" Height="24"
VerticalAlignment="Center" VerticalAlignment="Center"
IsLocked="True" IsLocked="True"
IsEnabled="{Binding LayerProperty.DataBindingsSupported}" IsEnabled="{Binding LayerProperty.DataBindingsSupported}"
IsChecked="{Binding HasDataBinding, Mode=OneWay}" IsChecked="{Binding HasDataBinding, Mode=OneWay}"
Click="{s:Action ActivateDataBindingViewModel}"> Click="{s:Action ActivateDataBindingViewModel}">
<materialDesign:PackIcon Kind="VectorLink" Height="13" Width="13" /> <materialDesign:PackIcon Kind="VectorLink" Height="16" Width="16" />
</shared:LockableToggleButton> </shared:LockableToggleButton>
</Grid> </Grid>

View File

@ -49,6 +49,12 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree
_profileEditorService.ChangeSelectedDataBinding(LayerProperty); _profileEditorService.ChangeSelectedDataBinding(LayerProperty);
} }
public void ResetToDefault()
{
LayerProperty.ApplyDefaultValue(_profileEditorService.CurrentTime);
_profileEditorService.UpdateSelectedProfileElement();
}
private void ApplyKeyframesEnabled(bool enable) private void ApplyKeyframesEnabled(bool enable)
{ {
// If enabling keyframes for the first time, add a keyframe with the current value at the current position // If enabling keyframes for the first time, add a keyframe with the current value at the current position