From 957bfde0af6450037cb18783e5d4fbec312c47cd Mon Sep 17 00:00:00 2001 From: RobertBeekman Date: Thu, 2 May 2024 20:02:12 +0200 Subject: [PATCH] Workshop - Added layout finder --- .../Models/Surface/Layout/ArtemisLedLayout.cs | 16 +- .../Plugins/Profiling/Profiler.cs | 3 +- src/Artemis.UI/Artemis.UI.csproj | 1 + .../StartupWizard/StartupWizardView.axaml.cs | 6 +- .../StartupWizard/StartupWizardViewModel.cs | 18 +- .../StartupWizard/Steps/LayoutsStep.axaml | 31 ++++ .../StartupWizard/Steps/LayoutsStep.axaml.cs | 13 ++ .../{LayoutStep.axaml => SurfaceStep.axaml} | 2 +- ...youtStep.axaml.cs => SurfaceStep.axaml.cs} | 4 +- .../CurrentUser/CurrentUserView.axaml | 20 +-- .../Workshop/Entries/List/EntryListView.axaml | 4 +- .../Entries/List/EntryListViewModel.cs | 2 + .../Dialogs/DeviceSelectionDialogView.axaml | 24 --- .../DeviceSelectionDialogView.axaml.cs | 11 -- .../Dialogs/DeviceSelectionDialogViewModel.cs | 44 ----- .../Workshop/Layout/LayoutInfoViewModel.cs | 11 +- .../Layout/LayoutListDefaultView.axaml | 25 +++ .../Layout/LayoutListDefaultView.axaml.cs | 14 ++ .../Layout/LayoutListDefaultViewModel.cs | 20 +++ .../Workshop/Layout/LayoutListViewModel.cs | 7 +- .../LayoutFinder/LayoutFinderDeviceView.axaml | 73 ++++++++ .../LayoutFinderDeviceView.axaml.cs | 13 ++ .../LayoutFinderDeviceViewModel.cs | 159 ++++++++++++++++++ .../LayoutFinder/LayoutFinderView.axaml | 27 +++ .../LayoutFinder/LayoutFinderView.axaml.cs | 14 ++ .../LayoutFinder/LayoutFinderViewModel.cs | 53 ++++++ .../Steps/Layout/LayoutInfoStepView.axaml | 5 + src/Artemis.UI/Styles/Artemis.axaml | 2 + .../IEntryInstallationHandler.cs | 1 - .../LayoutEntryInstallationHandler.cs | 2 +- .../LayoutEntryUploadHandler.cs | 56 +++++- .../Mutations/SetLayoutInfo.graphql | 5 + .../Queries/SearchLayout.graphql | 23 +++ src/Artemis.WebClient.Workshop/schema.graphql | 15 ++ src/Directory.Packages.props | 1 + 35 files changed, 598 insertions(+), 127 deletions(-) create mode 100644 src/Artemis.UI/Screens/StartupWizard/Steps/LayoutsStep.axaml create mode 100644 src/Artemis.UI/Screens/StartupWizard/Steps/LayoutsStep.axaml.cs rename src/Artemis.UI/Screens/StartupWizard/Steps/{LayoutStep.axaml => SurfaceStep.axaml} (97%) rename src/Artemis.UI/Screens/StartupWizard/Steps/{LayoutStep.axaml.cs => SurfaceStep.axaml.cs} (67%) delete mode 100644 src/Artemis.UI/Screens/Workshop/Layout/Dialogs/DeviceSelectionDialogView.axaml delete mode 100644 src/Artemis.UI/Screens/Workshop/Layout/Dialogs/DeviceSelectionDialogView.axaml.cs delete mode 100644 src/Artemis.UI/Screens/Workshop/Layout/Dialogs/DeviceSelectionDialogViewModel.cs create mode 100644 src/Artemis.UI/Screens/Workshop/Layout/LayoutListDefaultView.axaml create mode 100644 src/Artemis.UI/Screens/Workshop/Layout/LayoutListDefaultView.axaml.cs create mode 100644 src/Artemis.UI/Screens/Workshop/Layout/LayoutListDefaultViewModel.cs create mode 100644 src/Artemis.UI/Screens/Workshop/LayoutFinder/LayoutFinderDeviceView.axaml create mode 100644 src/Artemis.UI/Screens/Workshop/LayoutFinder/LayoutFinderDeviceView.axaml.cs create mode 100644 src/Artemis.UI/Screens/Workshop/LayoutFinder/LayoutFinderDeviceViewModel.cs create mode 100644 src/Artemis.UI/Screens/Workshop/LayoutFinder/LayoutFinderView.axaml create mode 100644 src/Artemis.UI/Screens/Workshop/LayoutFinder/LayoutFinderView.axaml.cs create mode 100644 src/Artemis.UI/Screens/Workshop/LayoutFinder/LayoutFinderViewModel.cs create mode 100644 src/Artemis.WebClient.Workshop/Mutations/SetLayoutInfo.graphql create mode 100644 src/Artemis.WebClient.Workshop/Queries/SearchLayout.graphql diff --git a/src/Artemis.Core/Models/Surface/Layout/ArtemisLedLayout.cs b/src/Artemis.Core/Models/Surface/Layout/ArtemisLedLayout.cs index 55e237b5d..ac8e3827b 100644 --- a/src/Artemis.Core/Models/Surface/Layout/ArtemisLedLayout.cs +++ b/src/Artemis.Core/Models/Surface/Layout/ArtemisLedLayout.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.IO; using System.Linq; using RGB.NET.Layout; @@ -15,7 +16,7 @@ public class ArtemisLedLayout DeviceLayout = deviceLayout; RgbLayout = led; LayoutCustomLedData = (LayoutCustomLedData?) led.CustomData ?? new LayoutCustomLedData(); - + // Default to the first logical layout for images LayoutCustomLedDataLogicalLayout? defaultLogicalLayout = LayoutCustomLedData.LogicalLayouts?.FirstOrDefault(); if (defaultLogicalLayout != null) @@ -46,7 +47,14 @@ public class ArtemisLedLayout /// Gets the custom layout data embedded in the RGB.NET layout /// public LayoutCustomLedData LayoutCustomLedData { get; } - + + /// + /// Gets the logical layout names available for this LED + /// + public IEnumerable GetLogicalLayoutNames() + { + return LayoutCustomLedData.LogicalLayouts?.Where(l => l.Name != null).Select(l => l.Name!) ?? []; + } internal void ApplyCustomLedData(ArtemisDevice artemisDevice) { @@ -61,11 +69,11 @@ public class ArtemisLedLayout ApplyLogicalLayout(logicalLayout); } - + private void ApplyLogicalLayout(LayoutCustomLedDataLogicalLayout logicalLayout) { string? layoutDirectory = Path.GetDirectoryName(DeviceLayout.FilePath); - + LogicalName = logicalLayout.Name; if (layoutDirectory != null && logicalLayout.Image != null) Image = new Uri(Path.Combine(layoutDirectory, logicalLayout.Image!), UriKind.Absolute); diff --git a/src/Artemis.Core/Plugins/Profiling/Profiler.cs b/src/Artemis.Core/Plugins/Profiling/Profiler.cs index e920ed3da..d8d184ef1 100644 --- a/src/Artemis.Core/Plugins/Profiling/Profiler.cs +++ b/src/Artemis.Core/Plugins/Profiling/Profiler.cs @@ -23,8 +23,7 @@ public class Profiler /// Gets the name of this profiler /// public string Name { get; } - - + /// /// Gets a dictionary containing measurements by their identifiers /// diff --git a/src/Artemis.UI/Artemis.UI.csproj b/src/Artemis.UI/Artemis.UI.csproj index 1714435f1..9702f8043 100644 --- a/src/Artemis.UI/Artemis.UI.csproj +++ b/src/Artemis.UI/Artemis.UI.csproj @@ -21,6 +21,7 @@ + diff --git a/src/Artemis.UI/Screens/StartupWizard/StartupWizardView.axaml.cs b/src/Artemis.UI/Screens/StartupWizard/StartupWizardView.axaml.cs index 094e16d39..71c72bb2e 100644 --- a/src/Artemis.UI/Screens/StartupWizard/StartupWizardView.axaml.cs +++ b/src/Artemis.UI/Screens/StartupWizard/StartupWizardView.axaml.cs @@ -29,10 +29,12 @@ public partial class StartupWizardView : ReactiveAppWindow IPluginManagementService pluginManagementService, IWindowService windowService, IDeviceService deviceService, - ISettingsVmFactory settingsVmFactory) + ISettingsVmFactory settingsVmFactory, + LayoutFinderViewModel layoutFinderViewModel) { _settingsService = settingsService; _windowService = windowService; @@ -54,6 +56,7 @@ public partial class StartupWizardViewModel : DialogViewModelBase .Where(p => p.Info.IsCompatible && p.Features.Any(f => f.AlwaysEnabled && f.FeatureType.IsAssignableTo(typeof(DeviceProvider)))) .OrderBy(p => p.Info.Name) .Select(p => settingsVmFactory.PluginViewModel(p, ReactiveCommand.Create(() => new Unit())))); + LayoutFinderViewModel = layoutFinderViewModel; CurrentStep = 1; SetupButtons(); @@ -82,7 +85,8 @@ public partial class StartupWizardViewModel : DialogViewModelBase public string Version { get; } public ObservableCollection DeviceProviders { get; } - + public LayoutFinderViewModel LayoutFinderViewModel { get; } + public bool IsAutoRunSupported => _autoRunProvider != null; public PluginSetting UIAutoRun => _settingsService.GetSetting("UI.AutoRun", false); @@ -98,7 +102,7 @@ public partial class StartupWizardViewModel : DialogViewModelBase CurrentStep--; // Skip the settings step if none of it's contents are supported - if (CurrentStep == 4 && !IsAutoRunSupported) + if (CurrentStep == 5 && !IsAutoRunSupported) CurrentStep--; SetupButtons(); @@ -106,11 +110,11 @@ public partial class StartupWizardViewModel : DialogViewModelBase private void ExecuteContinue() { - if (CurrentStep < 5) + if (CurrentStep < 6) CurrentStep++; // Skip the settings step if none of it's contents are supported - if (CurrentStep == 4 && !IsAutoRunSupported) + if (CurrentStep == 5 && !IsAutoRunSupported) CurrentStep++; SetupButtons(); @@ -118,9 +122,9 @@ public partial class StartupWizardViewModel : DialogViewModelBase private void SetupButtons() { - ShowContinue = CurrentStep != 3 && CurrentStep < 5; + ShowContinue = CurrentStep != 4 && CurrentStep < 6; ShowGoBack = CurrentStep > 1; - ShowFinish = CurrentStep == 5; + ShowFinish = CurrentStep == 6; } private void ExecuteSkipOrFinishWizard() diff --git a/src/Artemis.UI/Screens/StartupWizard/Steps/LayoutsStep.axaml b/src/Artemis.UI/Screens/StartupWizard/Steps/LayoutsStep.axaml new file mode 100644 index 000000000..40810d841 --- /dev/null +++ b/src/Artemis.UI/Screens/StartupWizard/Steps/LayoutsStep.axaml @@ -0,0 +1,31 @@ + + + + + + Device layouts provide Artemis with an image of your devices and exact LED positions. + While not strictly necessary, this helps to create effects that are perfectly aligned with your hardware. + + + Below you can automatically search the Artemis Workshop for device layouts of your devices. + + + +