diff --git a/src/Artemis.UI/DryIoc/Factories/IVMFactory.cs b/src/Artemis.UI/DryIoc/Factories/IVMFactory.cs index e95a8639c..a5fab0248 100644 --- a/src/Artemis.UI/DryIoc/Factories/IVMFactory.cs +++ b/src/Artemis.UI/DryIoc/Factories/IVMFactory.cs @@ -155,7 +155,7 @@ public class SidebarVmFactory : ISidebarVmFactory public interface ISurfaceVmFactory : IVmFactory { SurfaceDeviceViewModel SurfaceDeviceViewModel(ArtemisDevice device, SurfaceEditorViewModel surfaceEditorViewModel); - ListDeviceViewModel ListDeviceViewModel(ArtemisDevice device, SurfaceEditorViewModel surfaceEditorViewModel); + ListDeviceViewModel ListDeviceViewModel(ArtemisDevice device); } public class SurfaceVmFactory : ISurfaceVmFactory @@ -172,9 +172,9 @@ public class SurfaceVmFactory : ISurfaceVmFactory return _container.Resolve(new object[] {device, surfaceEditorViewModel}); } - public ListDeviceViewModel ListDeviceViewModel(ArtemisDevice device, SurfaceEditorViewModel surfaceEditorViewModel) + public ListDeviceViewModel ListDeviceViewModel(ArtemisDevice device) { - return _container.Resolve(new object[] {device, surfaceEditorViewModel}); + return _container.Resolve(new object[] {device}); } } diff --git a/src/Artemis.UI/Screens/SurfaceEditor/ListDeviceViewModel.cs b/src/Artemis.UI/Screens/SurfaceEditor/ListDeviceViewModel.cs index 075420953..43b6cae49 100644 --- a/src/Artemis.UI/Screens/SurfaceEditor/ListDeviceViewModel.cs +++ b/src/Artemis.UI/Screens/SurfaceEditor/ListDeviceViewModel.cs @@ -21,13 +21,12 @@ public partial class ListDeviceViewModel : ViewModelBase [Notify] private SKColor _color; [Notify] private bool _isSelected; - public ListDeviceViewModel(ArtemisDevice device, SurfaceEditorViewModel surfaceEditorViewModel, IWindowService windowService, IDeviceService deviceService) + public ListDeviceViewModel(ArtemisDevice device, IWindowService windowService, IDeviceService deviceService) { _windowService = windowService; _deviceService = deviceService; Device = device; - SurfaceEditorViewModel = surfaceEditorViewModel; Color = SKColor.FromHsv(Random.NextSingle() * 360, 95, 100); DetectInput = ReactiveCommand.CreateFromTask(ExecuteDetectInput, this.WhenAnyValue(vm => vm.CanDetectInput)); } @@ -35,7 +34,6 @@ public partial class ListDeviceViewModel : ViewModelBase public ReactiveCommand DetectInput { get; } public ArtemisDevice Device { get; } - public SurfaceEditorViewModel SurfaceEditorViewModel { get; } public bool CanDetectInput => Device.DeviceType == RGBDeviceType.Keyboard || Device.DeviceType == RGBDeviceType.Mouse; private async Task ExecuteDetectInput() diff --git a/src/Artemis.UI/Screens/SurfaceEditor/SurfaceEditorViewModel.cs b/src/Artemis.UI/Screens/SurfaceEditor/SurfaceEditorViewModel.cs index 33b54b2c0..932313e96 100644 --- a/src/Artemis.UI/Screens/SurfaceEditor/SurfaceEditorViewModel.cs +++ b/src/Artemis.UI/Screens/SurfaceEditor/SurfaceEditorViewModel.cs @@ -50,7 +50,7 @@ public partial class SurfaceEditorViewModel : RoutableScreen, IMainScreenViewMod DisplayName = "Surface Editor"; SurfaceDeviceViewModels = new ObservableCollection(deviceService.EnabledDevices.OrderBy(d => d.ZIndex).Select(d => surfaceVmFactory.SurfaceDeviceViewModel(d, this))); - ListDeviceViewModels = new ObservableCollection(deviceService.EnabledDevices.OrderBy(d => d.ZIndex).Select(d => surfaceVmFactory.ListDeviceViewModel(d, this))); + ListDeviceViewModels = new ObservableCollection(deviceService.EnabledDevices.OrderBy(d => d.ZIndex).Select(d => surfaceVmFactory.ListDeviceViewModel(d))); AutoArrange = ReactiveCommand.CreateFromTask(ExecuteAutoArrange); IdentifyDevice = ReactiveCommand.Create(ExecuteIdentifyDevice); @@ -163,7 +163,7 @@ public partial class SurfaceEditorViewModel : RoutableScreen, IMainScreenViewMod return; SurfaceDeviceViewModels.Add(_surfaceVmFactory.SurfaceDeviceViewModel(e.Device, this)); - ListDeviceViewModels.Add(_surfaceVmFactory.ListDeviceViewModel(e.Device, this)); + ListDeviceViewModels.Add(_surfaceVmFactory.ListDeviceViewModel(e.Device)); SurfaceDeviceViewModels.Sort(l => l.Device.ZIndex * -1); ListDeviceViewModels.Sort(l => l.Device.ZIndex * -1); } diff --git a/src/Artemis.UI/Screens/Workshop/Layout/Dialogs/DeviceSelectionDialogView.axaml b/src/Artemis.UI/Screens/Workshop/Layout/Dialogs/DeviceSelectionDialogView.axaml new file mode 100644 index 000000000..2f2962b95 --- /dev/null +++ b/src/Artemis.UI/Screens/Workshop/Layout/Dialogs/DeviceSelectionDialogView.axaml @@ -0,0 +1,24 @@ + + + + Select the devices on which you would like to apply the downloaded layout. + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Workshop/Layout/Dialogs/DeviceSelectionDialogView.axaml.cs b/src/Artemis.UI/Screens/Workshop/Layout/Dialogs/DeviceSelectionDialogView.axaml.cs new file mode 100644 index 000000000..76b6cb2ec --- /dev/null +++ b/src/Artemis.UI/Screens/Workshop/Layout/Dialogs/DeviceSelectionDialogView.axaml.cs @@ -0,0 +1,11 @@ +using Avalonia.ReactiveUI; + +namespace Artemis.UI.Screens.Workshop.Layout.Dialogs; + +public partial class DeviceSelectionDialogView : ReactiveUserControl +{ + public DeviceSelectionDialogView() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Workshop/Layout/Dialogs/DeviceSelectionDialogViewModel.cs b/src/Artemis.UI/Screens/Workshop/Layout/Dialogs/DeviceSelectionDialogViewModel.cs new file mode 100644 index 000000000..2028d514e --- /dev/null +++ b/src/Artemis.UI/Screens/Workshop/Layout/Dialogs/DeviceSelectionDialogViewModel.cs @@ -0,0 +1,43 @@ +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Reactive; +using Artemis.Core; +using Artemis.Core.Services; +using Artemis.UI.DryIoc.Factories; +using Artemis.UI.Screens.SurfaceEditor; +using Artemis.UI.Shared; +using Artemis.WebClient.Workshop.Providers; +using Artemis.WebClient.Workshop.Services; +using ReactiveUI; + +namespace Artemis.UI.Screens.Workshop.Layout.Dialogs; + +public class DeviceSelectionDialogViewModel : ContentDialogViewModelBase +{ + private readonly IDeviceService _deviceService; + private readonly WorkshopLayoutProvider _layoutProvider; + + public DeviceSelectionDialogViewModel(List devices, InstalledEntry entry, ISurfaceVmFactory surfaceVmFactory, IDeviceService deviceService, WorkshopLayoutProvider layoutProvider) + { + _deviceService = deviceService; + _layoutProvider = layoutProvider; + Entry = entry; + Devices = new ObservableCollection(devices.Select(surfaceVmFactory.ListDeviceViewModel)); + Apply = ReactiveCommand.Create(ExecuteApply); + } + + public InstalledEntry Entry { get; } + public ObservableCollection Devices { get; } + public ReactiveCommand Apply { get; } + + private void ExecuteApply() + { + foreach (ListDeviceViewModel listDeviceViewModel in Devices.Where(d => d.IsSelected)) + { + _layoutProvider.ConfigureDevice(listDeviceViewModel.Device, Entry); + _deviceService.SaveDevice(listDeviceViewModel.Device); + _deviceService.LoadDeviceLayout(listDeviceViewModel.Device); + } + } +} \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Workshop/Layout/LayoutDetailsViewModel.cs b/src/Artemis.UI/Screens/Workshop/Layout/LayoutDetailsViewModel.cs index b7bce7ac1..1edb014e3 100644 --- a/src/Artemis.UI/Screens/Workshop/Layout/LayoutDetailsViewModel.cs +++ b/src/Artemis.UI/Screens/Workshop/Layout/LayoutDetailsViewModel.cs @@ -1,10 +1,16 @@ using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; using System.Threading; using System.Threading.Tasks; +using Artemis.Core; using Artemis.Core.Services; using Artemis.UI.Screens.Workshop.Entries.Details; +using Artemis.UI.Screens.Workshop.Layout.Dialogs; using Artemis.UI.Screens.Workshop.Parameters; using Artemis.UI.Shared.Routing; +using Artemis.UI.Shared.Services; using Artemis.WebClient.Workshop; using Artemis.WebClient.Workshop.Services; using PropertyChanged.SourceGenerator; @@ -16,6 +22,7 @@ public partial class LayoutDetailsViewModel : RoutableScreen _getEntryInfoViewModel; private readonly Func _getEntryReleasesViewModel; private readonly Func _getEntryImagesViewModel; @@ -26,12 +33,14 @@ public partial class LayoutDetailsViewModel : RoutableScreen getEntryInfoViewModel, Func getEntryReleasesViewModel, Func getEntryImagesViewModel) { _client = client; _deviceService = deviceService; + _windowService = windowService; _getEntryInfoViewModel = getEntryInfoViewModel; _getEntryReleasesViewModel = getEntryReleasesViewModel; _getEntryImagesViewModel = getEntryImagesViewModel; @@ -59,17 +68,26 @@ public partial class LayoutDetailsViewModel : RoutableScreen devices = _deviceService.Devices.Where(d => d.RgbDevice.DeviceInfo.DeviceType == layout.RgbLayout.Type).ToList(); - return Task.CompletedTask; + // If any are found, offer to apply + if (devices.Any()) + { + await _windowService.CreateContentDialog() + .WithTitle("Apply layout to devices") + .WithViewModel(out DeviceSelectionDialogViewModel vm, devices, installedEntry) + .WithCloseButtonText(null) + .HavingPrimaryButton(b => b.WithText("Continue").WithCommand(vm.Apply)) + .ShowAsync(); + } } - } \ No newline at end of file