From 5a8a2b268413907deb153324181df9a1c07ccb4d Mon Sep 17 00:00:00 2001 From: Robert Date: Thu, 14 Nov 2019 21:16:50 +0100 Subject: [PATCH] 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 --- .../Plugins/Models/PluginSetting.cs | 14 +++++++- .../ProfileEditor/ProfileLedViewModel.cs | 11 +++--- .../Screens/SurfaceEditorViewModel.cs | 24 ++++++++++++- .../ProfileEditor/ProfileEditorView.xaml | 17 ++++----- src/Artemis.UI/Views/Screens/RootView.xaml | 5 +-- .../Views/Screens/SurfaceEditorView.xaml | 35 +++++++++++-------- 6 files changed, 75 insertions(+), 31 deletions(-) diff --git a/src/Artemis.Core/Plugins/Models/PluginSetting.cs b/src/Artemis.Core/Plugins/Models/PluginSetting.cs index b925c140f..a532559b2 100644 --- a/src/Artemis.Core/Plugins/Models/PluginSetting.cs +++ b/src/Artemis.Core/Plugins/Models/PluginSetting.cs @@ -21,7 +21,14 @@ namespace Artemis.Core.Plugins.Models _pluginSettingEntity = pluginSettingEntity; Name = pluginSettingEntity.Name; - Value = JsonConvert.DeserializeObject(pluginSettingEntity.Value); + try + { + Value = JsonConvert.DeserializeObject(pluginSettingEntity.Value); + } + catch (JsonReaderException) + { + Value = default(T); + } } /// @@ -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}"; + } } } \ No newline at end of file diff --git a/src/Artemis.UI/ViewModels/Controls/ProfileEditor/ProfileLedViewModel.cs b/src/Artemis.UI/ViewModels/Controls/ProfileEditor/ProfileLedViewModel.cs index 108b746d0..9c0905c8a 100644 --- a/src/Artemis.UI/ViewModels/Controls/ProfileEditor/ProfileLedViewModel.cs +++ b/src/Artemis.UI/ViewModels/Controls/ProfileEditor/ProfileLedViewModel.cs @@ -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) } } ); diff --git a/src/Artemis.UI/ViewModels/Screens/SurfaceEditorViewModel.cs b/src/Artemis.UI/ViewModels/Screens/SurfaceEditorViewModel.cs index 74a02b95b..d92c4c98d 100644 --- a/src/Artemis.UI/ViewModels/Screens/SurfaceEditorViewModel.cs +++ b/src/Artemis.UI/ViewModels/Screens/SurfaceEditorViewModel.cs @@ -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(); SurfaceConfigurations = new ObservableCollection(); @@ -30,12 +33,14 @@ namespace Artemis.UI.ViewModels.Screens _surfaceService = surfaceService; _dialogService = dialogService; + _settingsService = settingsService; } public ObservableCollection Devices { get; set; } public ObservableCollection SurfaceConfigurations { get; set; } public RectangleGeometry SelectionRectangle { get; set; } public PanZoomViewModel PanZoomViewModel { get; set; } + public PluginSetting 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 diff --git a/src/Artemis.UI/Views/Controls/ProfileEditor/ProfileEditorView.xaml b/src/Artemis.UI/Views/Controls/ProfileEditor/ProfileEditorView.xaml index 582ead8a5..9916eee04 100644 --- a/src/Artemis.UI/Views/Controls/ProfileEditor/ProfileEditorView.xaml +++ b/src/Artemis.UI/Views/Controls/ProfileEditor/ProfileEditorView.xaml @@ -32,12 +32,13 @@ - - Profile editor - - The profile defines what colors the LEDs will have. Multiple groups of LEDs are defined into layers. On these layers you can apply effects. - + + + + The profile defines what colors the LEDs will have. Multiple groups of LEDs are defined into layers. On these layers you can apply effects. + + + @@ -161,8 +162,8 @@ - + + diff --git a/src/Artemis.UI/Views/Screens/RootView.xaml b/src/Artemis.UI/Views/Screens/RootView.xaml index bc46a4b86..d1f1c31e8 100644 --- a/src/Artemis.UI/Views/Screens/RootView.xaml +++ b/src/Artemis.UI/Views/Screens/RootView.xaml @@ -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"> diff --git a/src/Artemis.UI/Views/Screens/SurfaceEditorView.xaml b/src/Artemis.UI/Views/Screens/SurfaceEditorView.xaml index 0a592bc60..8a3097815 100644 --- a/src/Artemis.UI/Views/Screens/SurfaceEditorView.xaml +++ b/src/Artemis.UI/Views/Screens/SurfaceEditorView.xaml @@ -24,22 +24,22 @@ - + - - Surface layout - - 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. - + + + 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. + + + - - - + + - + - + @@ -193,7 +197,8 @@ - +