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

Invalid plugin settings will fall back to their type's default

Main window remembers it's position now
Surface editor's surface list size is saved
This commit is contained in:
Robert 2019-11-14 21:16:50 +01:00
parent 1a98ef62d3
commit 5a8a2b2684
6 changed files with 75 additions and 31 deletions

View File

@ -21,7 +21,14 @@ namespace Artemis.Core.Plugins.Models
_pluginSettingEntity = pluginSettingEntity;
Name = pluginSettingEntity.Name;
Value = JsonConvert.DeserializeObject<T>(pluginSettingEntity.Value);
try
{
Value = JsonConvert.DeserializeObject<T>(pluginSettingEntity.Value);
}
catch (JsonReaderException)
{
Value = default(T);
}
}
/// <summary>
@ -86,5 +93,10 @@ namespace Artemis.Core.Plugins.Models
{
SettingChanged?.Invoke(this, EventArgs.Empty);
}
public override string ToString()
{
return $"{nameof(Name)}: {Name}, {nameof(Value)}: {Value}, {nameof(HasChanged)}: {HasChanged}";
}
}
}

View File

@ -37,7 +37,10 @@ namespace Artemis.UI.ViewModels.Controls.ProfileEditor
switch (Led.Shape)
{
case Shape.Custom:
CreateCustomGeometry();
if (Led.Device.DeviceInfo.DeviceType == RGBDeviceType.Keyboard || Led.Device.DeviceInfo.DeviceType == RGBDeviceType.Keypad)
CreateCustomGeometry(2.0);
else
CreateCustomGeometry(1.0);
break;
case Shape.Rectangle:
if (Led.Device.DeviceInfo.DeviceType == RGBDeviceType.Keyboard || Led.Device.DeviceInfo.DeviceType == RGBDeviceType.Keypad)
@ -73,7 +76,7 @@ namespace Artemis.UI.ViewModels.Controls.ProfileEditor
DisplayGeometry = new RectangleGeometry(new Rect(1, 1, Led.LedRectangle.Width - 2, Led.LedRectangle.Height - 2), 1.6, 1.6);
}
private void CreateCustomGeometry()
private void CreateCustomGeometry(double deflateAmount)
{
try
{
@ -85,8 +88,8 @@ namespace Artemis.UI.ViewModels.Controls.ProfileEditor
{
Children = new TransformCollection
{
new ScaleTransform(Led.LedRectangle.Width - 1, Led.LedRectangle.Height - 1),
new TranslateTransform(0.5, 0.5)
new ScaleTransform(Led.LedRectangle.Width - deflateAmount, Led.LedRectangle.Height - deflateAmount),
new TranslateTransform(deflateAmount/2, deflateAmount/2)
}
}
);

View File

@ -6,6 +6,8 @@ using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using Artemis.Core.Models.Surface;
using Artemis.Core.Plugins.Models;
using Artemis.Core.Services;
using Artemis.Core.Services.Storage;
using Artemis.UI.Services.Interfaces;
using Artemis.UI.ViewModels.Controls.SurfaceEditor;
@ -19,9 +21,10 @@ namespace Artemis.UI.ViewModels.Screens
public class SurfaceEditorViewModel : Screen, IScreenViewModel
{
private readonly IDialogService _dialogService;
private readonly ISettingsService _settingsService;
private readonly ISurfaceService _surfaceService;
public SurfaceEditorViewModel(ISurfaceService surfaceService, IDialogService dialogService)
public SurfaceEditorViewModel(ISurfaceService surfaceService, IDialogService dialogService, ISettingsService settingsService)
{
Devices = new ObservableCollection<SurfaceDeviceViewModel>();
SurfaceConfigurations = new ObservableCollection<Surface>();
@ -30,12 +33,14 @@ namespace Artemis.UI.ViewModels.Screens
_surfaceService = surfaceService;
_dialogService = dialogService;
_settingsService = settingsService;
}
public ObservableCollection<SurfaceDeviceViewModel> Devices { get; set; }
public ObservableCollection<Surface> SurfaceConfigurations { get; set; }
public RectangleGeometry SelectionRectangle { get; set; }
public PanZoomViewModel PanZoomViewModel { get; set; }
public PluginSetting<GridLength> SurfaceListWidth { get; set; }
public Surface SelectedSurface
{
@ -56,6 +61,16 @@ namespace Artemis.UI.ViewModels.Screens
return config;
}
private void LoadWorkspaceSettings()
{
SurfaceListWidth = _settingsService.GetSetting("SurfaceEditor.SurfaceListWidth", new GridLength(300.0));
}
private void SaveWorkspaceSettings()
{
SurfaceListWidth.Save();
}
private void LoadSurfaceConfigurations()
{
// Get surface configs
@ -116,9 +131,16 @@ namespace Artemis.UI.ViewModels.Screens
protected override void OnActivate()
{
LoadSurfaceConfigurations();
LoadWorkspaceSettings();
base.OnActivate();
}
protected override void OnDeactivate()
{
SaveWorkspaceSettings();
base.OnDeactivate();
}
#endregion
#region Configuration management

View File

@ -32,12 +32,13 @@
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Style="{StaticResource MaterialDesignDisplay1TextBlock}">Profile editor</TextBlock>
<TextBlock Grid.Row="1" Grid.Column="0" Style="{StaticResource MaterialDesignCaptionTextBlock}"
Margin="0,0,0,5">
The profile defines what colors the LEDs will have. Multiple groups of LEDs are defined into layers. On these layers you can apply effects.
</TextBlock>
<StackPanel Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2">
<TextBlock >
<materialDesign:PackIcon Kind="AboutOutline" Margin="0 0 0 -3"/> The profile defines what colors the LEDs will have. Multiple groups of LEDs are defined into layers. On these layers you can apply effects.
</TextBlock>
<Border BorderBrush="{DynamicResource MaterialDesignDivider}" BorderThickness="0 0 0 1" Margin="0 10" />
</StackPanel>
<materialDesign:Card materialDesign:ShadowAssist.ShadowDepth="Depth1" Grid.Row="2" Grid.Column="0"
VerticalAlignment="Stretch" Margin="0,0,5,0">
@ -161,8 +162,8 @@
</materialDesign:DialogHost>
</materialDesign:Card>
<TextBlock Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2"
Style="{StaticResource MaterialDesignCaptionTextBlock}" Margin="0,5,0,0">
<TextBlock Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" Style="{StaticResource MaterialDesignCaptionTextBlock}" Margin="0,5,0,0">
<materialDesign:PackIcon Kind="Keyboard" Margin="0 0 0 -3"/>
<Run Text="Hold" />
<Run FontWeight="Bold" Text="shift" />
<Run Text="or click and drag to select multiple LEDs at once. To move around the surface hold down" />

View File

@ -12,9 +12,10 @@
GlowBrush="{DynamicResource AccentColorBrush}"
FontFamily="{StaticResource DefaultFont}"
Title="Artemis"
d:DesignHeight="639.411"
d:DesignWidth="1113.251"
d:DesignHeight="640"
d:DesignWidth="1200"
d:DataContext="{d:DesignInstance screens:RootViewModel}"
SaveWindowPosition="True"
Icon="/Artemis.UI;component/Resources/logo-512.png">
<metro:MetroWindow.LeftWindowCommands>
<metro:WindowCommands>

View File

@ -24,22 +24,22 @@
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" MinWidth="100" />
<ColumnDefinition Width="5" />
<ColumnDefinition Width="300" MinWidth="100" />
<ColumnDefinition Width="{Binding SurfaceListWidth.Value, Mode=TwoWay}" MinWidth="100" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Style="{StaticResource MaterialDesignDisplay1TextBlock}">Surface layout</TextBlock>
<TextBlock Grid.Row="1" Grid.Column="0" Style="{StaticResource MaterialDesignCaptionTextBlock}"
Margin="0,0,0,5">
The surface is a digital representation of your LED setup. Set this up accurately and effects will seamlessly move from one device to the other.
</TextBlock>
<StackPanel Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3">
<TextBlock >
<materialDesign:PackIcon Kind="AboutOutline" Margin="0 0 0 -3"/> The surface is a digital representation of your LED setup. Set this up accurately and effects will seamlessly move from one device to the other.
</TextBlock>
<Border BorderBrush="{DynamicResource MaterialDesignDivider}" BorderThickness="0 0 0 1" Margin="0 10" />
</StackPanel>
<materialDesign:Card materialDesign:ShadowAssist.ShadowDepth="Depth1" Grid.Row="2" Grid.Column="0"
<materialDesign:Card materialDesign:ShadowAssist.ShadowDepth="Depth1" Grid.Row="1" Grid.Column="0"
VerticalAlignment="Stretch" Margin="0,0,5,0">
<Grid ClipToBounds="True"
KeyUp="{s:Action EditorGridKeyUp}"
@ -176,16 +176,20 @@
</StackPanel>
</Grid>
</materialDesign:Card>
<GridSplitter Grid.Column="1" Grid.Row="2" Width="5" HorizontalAlignment="Stretch" />
<materialDesign:Card materialDesign:ShadowAssist.ShadowDepth="Depth1" Grid.Row="2" Grid.Column="2"
<GridSplitter Grid.Column="1" Grid.Row="1" Width="5" HorizontalAlignment="Stretch" ShowsPreview="True" />
<materialDesign:Card materialDesign:ShadowAssist.ShadowDepth="Depth1" Grid.Row="1" Grid.Column="2"
VerticalAlignment="Stretch" Margin="5,0,0,0">
<materialDesign:DialogHost Identifier="SurfaceListDialogHost" CloseOnClickAway="True" UseLayoutRounding="True">
<materialDesign:DialogHost Identifier="SurfaceListDialogHost" CloseOnClickAway="True"
UseLayoutRounding="True">
<Grid HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ListBox Grid.Row="0" HorizontalContentAlignment="Stretch" ItemsSource="{Binding SurfaceConfigurations}" SelectedItem="{Binding SelectedSurface}">
<ListBox Grid.Row="0" HorizontalContentAlignment="Stretch"
ItemsSource="{Binding SurfaceConfigurations}" SelectedItem="{Binding SelectedSurface}">
<ListBox.Resources>
<DataTemplate DataType="{x:Type models:Surface}">
<Grid>
@ -193,7 +197,8 @@
<ColumnDefinition Width="*" />
<ColumnDefinition Width="40" />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Name}" ToolTip="{Binding Name}" HorizontalAlignment="Left" VerticalAlignment="Center" />
<TextBlock Text="{Binding Name}" ToolTip="{Binding Name}"
HorizontalAlignment="Left" VerticalAlignment="Center" />
<Button Grid.Column="1"
Command="{s:Action DeleteSurfaceConfiguration}"
CommandParameter="{Binding}"
@ -220,8 +225,8 @@
</materialDesign:DialogHost>
</materialDesign:Card>
<TextBlock Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2"
Style="{StaticResource MaterialDesignCaptionTextBlock}" Margin="0,5,0,0">
<TextBlock Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2" Style="{StaticResource MaterialDesignCaptionTextBlock}" Margin="0,5,0,0">
<materialDesign:PackIcon Kind="Keyboard" Margin="0 0 0 -3"/>
<Run Text="Hold" />
<Run FontWeight="Bold" Text="shift" />
<Run Text="or click and drag to select multiple devices at once. To move around the surface hold down" />