From 1d789bf23c2a07599099221e2a487bbf1ab808be Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Mon, 14 Sep 2020 19:54:09 +0200 Subject: [PATCH] Profile editor - Performance improvements --- .../Modifiers/PercentageOfModifierType.cs | 28 +++++++++++++ .../Registration/DataBindingService.cs | 1 + .../Screens/Modules/ModuleRootView.xaml | 5 ++- .../LayerProperties/Tree/TreeView.xaml | 2 +- .../ProfileEditor/ProfileEditorView.xaml | 8 ++-- .../Visualization/ProfileView.xaml | 40 ------------------- src/Artemis.UI/Screens/RootView.xaml | 2 +- src/Artemis.UI/Screens/RootViewModel.cs | 7 +++- .../Screens/Settings/SettingsView.xaml | 2 +- .../Tabs/Devices/DeviceSettingsTabView.xaml | 4 +- .../Devices/DeviceSettingsTabViewModel.cs | 16 ++------ .../Tabs/Plugins/PluginSettingsTabView.xaml | 5 ++- .../Plugins/PluginSettingsTabViewModel.cs | 21 +++------- 13 files changed, 58 insertions(+), 83 deletions(-) create mode 100644 src/Artemis.Core/Models/Profile/DataBindings/Modifiers/PercentageOfModifierType.cs diff --git a/src/Artemis.Core/Models/Profile/DataBindings/Modifiers/PercentageOfModifierType.cs b/src/Artemis.Core/Models/Profile/DataBindings/Modifiers/PercentageOfModifierType.cs new file mode 100644 index 000000000..ffc1b4662 --- /dev/null +++ b/src/Artemis.Core/Models/Profile/DataBindings/Modifiers/PercentageOfModifierType.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; + +namespace Artemis.Core +{ + internal class PercentageOfModifierType : DataBindingModifierType + { + public PercentageOfModifierType() + { + PreferredParameterType = typeof(float); + } + + public override IReadOnlyCollection CompatibleTypes => Constants.NumberTypes; + + public override string Description => "Percentage of"; + public override string Icon => "Percent"; + + public override object Apply(object currentValue, object parameterValue) + { + var parameter = Convert.ToSingle(parameterValue); + // Ye ye none of that + if (parameter == 0f) + return 100f; + + return 100f / Convert.ToSingle(parameterValue) * Convert.ToSingle(currentValue); + } + } +} \ No newline at end of file diff --git a/src/Artemis.Core/Services/Registration/DataBindingService.cs b/src/Artemis.Core/Services/Registration/DataBindingService.cs index 8deed0c63..4acec1b62 100644 --- a/src/Artemis.Core/Services/Registration/DataBindingService.cs +++ b/src/Artemis.Core/Services/Registration/DataBindingService.cs @@ -42,6 +42,7 @@ namespace Artemis.Core.Services private void RegisterBuiltInModifiers() { RegisterModifierType(Constants.CorePluginInfo, new MultiplicationModifierType()); + RegisterModifierType(Constants.CorePluginInfo, new PercentageOfModifierType()); RegisterModifierType(Constants.CorePluginInfo, new DivideModifierType()); RegisterModifierType(Constants.CorePluginInfo, new FloorModifierType()); } diff --git a/src/Artemis.UI/Screens/Modules/ModuleRootView.xaml b/src/Artemis.UI/Screens/Modules/ModuleRootView.xaml index ae7908c5b..0278e9576 100644 --- a/src/Artemis.UI/Screens/Modules/ModuleRootView.xaml +++ b/src/Artemis.UI/Screens/Modules/ModuleRootView.xaml @@ -5,9 +5,10 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:s="https://github.com/canton7/Stylet" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" + xmlns:modules="clr-namespace:Artemis.UI.Screens.Modules" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800" - d:DataContext="{d:DesignInstance module:ModuleRootViewModel}"> + d:DataContext="{d:DesignInstance modules:ModuleRootViewModel}"> - + diff --git a/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/Tree/TreeView.xaml b/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/Tree/TreeView.xaml index 0cf321bbf..6e1f553b6 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/Tree/TreeView.xaml +++ b/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/Tree/TreeView.xaml @@ -102,7 +102,7 @@ - + diff --git a/src/Artemis.UI/Screens/ProfileEditor/ProfileEditorView.xaml b/src/Artemis.UI/Screens/ProfileEditor/ProfileEditorView.xaml index afbcfe439..5d3ad756b 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/ProfileEditorView.xaml +++ b/src/Artemis.UI/Screens/ProfileEditor/ProfileEditorView.xaml @@ -86,7 +86,7 @@ - + @@ -96,7 +96,7 @@ - + @@ -179,7 +179,7 @@ - + @@ -187,7 +187,7 @@ - + diff --git a/src/Artemis.UI/Screens/ProfileEditor/Visualization/ProfileView.xaml b/src/Artemis.UI/Screens/ProfileEditor/Visualization/ProfileView.xaml index 2db249ab1..ef0da0a9f 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Visualization/ProfileView.xaml +++ b/src/Artemis.UI/Screens/ProfileEditor/Visualization/ProfileView.xaml @@ -10,36 +10,6 @@ mc:Ignorable="d" d:DesignHeight="510.9" d:DesignWidth="800" d:DataContext="{d:DesignInstance {x:Type visualization:ProfileViewModel}}"> - - - - @@ -186,16 +156,6 @@ - - - - - - Initializing LED visualization... - - - - diff --git a/src/Artemis.UI/Screens/RootView.xaml b/src/Artemis.UI/Screens/RootView.xaml index c3c016cdd..8dd3e3221 100644 --- a/src/Artemis.UI/Screens/RootView.xaml +++ b/src/Artemis.UI/Screens/RootView.xaml @@ -41,7 +41,7 @@ - + diff --git a/src/Artemis.UI/Screens/RootViewModel.cs b/src/Artemis.UI/Screens/RootViewModel.cs index 0f551b77c..5a0991f58 100644 --- a/src/Artemis.UI/Screens/RootViewModel.cs +++ b/src/Artemis.UI/Screens/RootViewModel.cs @@ -8,6 +8,7 @@ using System.Windows.Input; using Artemis.Core; using Artemis.Core.Services; using Artemis.UI.Events; +using Artemis.UI.Screens.Modules; using Artemis.UI.Screens.Settings.Tabs.General; using Artemis.UI.Screens.Sidebar; using Artemis.UI.Services; @@ -139,8 +140,10 @@ namespace Artemis.UI.Screens if (e.PropertyName == nameof(SidebarViewModel.SelectedItem) && ActiveItem != SidebarViewModel.SelectedItem) { SidebarViewModel.IsSidebarOpen = false; - ActiveItemReady = false; - + // Don't do a fade when selecting a module because the editor is so bulky the animation slows things down + if (!(SidebarViewModel.SelectedItem is ModuleRootViewModel)) + ActiveItemReady = false; + // Allow the menu to close, it's slower but feels more responsive, funny how that works right Execute.PostToUIThreadAsync(async () => { diff --git a/src/Artemis.UI/Screens/Settings/SettingsView.xaml b/src/Artemis.UI/Screens/Settings/SettingsView.xaml index 3042626be..9038fac90 100644 --- a/src/Artemis.UI/Screens/Settings/SettingsView.xaml +++ b/src/Artemis.UI/Screens/Settings/SettingsView.xaml @@ -22,7 +22,7 @@ DisplayMemberPath="DisplayName"> - Below you view and manage the devices that were detected by Artemis - + @@ -19,7 +19,7 @@ - + diff --git a/src/Artemis.UI/Screens/Settings/Tabs/Devices/DeviceSettingsTabViewModel.cs b/src/Artemis.UI/Screens/Settings/Tabs/Devices/DeviceSettingsTabViewModel.cs index aa1d88c12..3ff720cd0 100644 --- a/src/Artemis.UI/Screens/Settings/Tabs/Devices/DeviceSettingsTabViewModel.cs +++ b/src/Artemis.UI/Screens/Settings/Tabs/Devices/DeviceSettingsTabViewModel.cs @@ -6,7 +6,7 @@ using Stylet; namespace Artemis.UI.Screens.Settings.Tabs.Devices { - public class DeviceSettingsTabViewModel : Screen + public class DeviceSettingsTabViewModel : Conductor.Collection.AllActive { private readonly ISettingsVmFactory _settingsVmFactory; private readonly ISurfaceService _surfaceService; @@ -18,25 +18,17 @@ namespace Artemis.UI.Screens.Settings.Tabs.Devices _surfaceService = surfaceService; _settingsVmFactory = settingsVmFactory; - - DeviceSettingsViewModels = new BindableCollection(); } - - public BindableCollection DeviceSettingsViewModels - { - get => _deviceSettingsViewModels; - set => SetAndNotify(ref _deviceSettingsViewModels, value); - } - + protected override void OnActivate() { // Take it off the UI thread to avoid freezing on tab change Task.Run(() => { - DeviceSettingsViewModels.Clear(); + Items.Clear(); var instances = _surfaceService.ActiveSurface.Devices.Select(d => _settingsVmFactory.CreateDeviceSettingsViewModel(d)).ToList(); foreach (var deviceSettingsViewModel in instances) - DeviceSettingsViewModels.Add(deviceSettingsViewModel); + Items.Add(deviceSettingsViewModel); }); } } diff --git a/src/Artemis.UI/Screens/Settings/Tabs/Plugins/PluginSettingsTabView.xaml b/src/Artemis.UI/Screens/Settings/Tabs/Plugins/PluginSettingsTabView.xaml index 94e03992b..efc2bd56d 100644 --- a/src/Artemis.UI/Screens/Settings/Tabs/Plugins/PluginSettingsTabView.xaml +++ b/src/Artemis.UI/Screens/Settings/Tabs/Plugins/PluginSettingsTabView.xaml @@ -5,13 +5,14 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:Artemis.UI.Screens.Settings.Tabs.Plugins" xmlns:s="https://github.com/canton7/Stylet" + xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800" d:DataContext="{d:DesignInstance local:PluginSettingsTabViewModel}"> The list below shows all loaded plugins. If you're missing something, view your logs folder. - + @@ -19,7 +20,7 @@ - + diff --git a/src/Artemis.UI/Screens/Settings/Tabs/Plugins/PluginSettingsTabViewModel.cs b/src/Artemis.UI/Screens/Settings/Tabs/Plugins/PluginSettingsTabViewModel.cs index 7b77046f6..6cb8de565 100644 --- a/src/Artemis.UI/Screens/Settings/Tabs/Plugins/PluginSettingsTabViewModel.cs +++ b/src/Artemis.UI/Screens/Settings/Tabs/Plugins/PluginSettingsTabViewModel.cs @@ -6,7 +6,7 @@ using Stylet; namespace Artemis.UI.Screens.Settings.Tabs.Plugins { - public class PluginSettingsTabViewModel : Screen + public class PluginSettingsTabViewModel : Conductor.Collection.AllActive { private readonly IPluginService _pluginService; private readonly ISettingsVmFactory _settingsVmFactory; @@ -18,26 +18,15 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins _pluginService = pluginService; _settingsVmFactory = settingsVmFactory; - - Plugins = new BindableCollection(); - } - - public BindableCollection Plugins - { - get => _plugins; - set => SetAndNotify(ref _plugins, value); } protected override void OnActivate() { // Take it off the UI thread to avoid freezing on tab change - Task.Run(() => - { - Plugins.Clear(); - var instances = _pluginService.GetAllPluginInfo().Select(p => _settingsVmFactory.CreatePluginSettingsViewModel(p.Instance)).ToList(); - foreach (var pluginSettingsViewModel in instances) - Plugins.Add(pluginSettingsViewModel); - }); + Items.Clear(); + var instances = _pluginService.GetAllPluginInfo().Select(p => _settingsVmFactory.CreatePluginSettingsViewModel(p.Instance)).ToList(); + foreach (var pluginSettingsViewModel in instances) + Items.Add(pluginSettingsViewModel); } } } \ No newline at end of file