diff --git a/src/Artemis.UI/DryIoc/Factories/IVMFactory.cs b/src/Artemis.UI/DryIoc/Factories/IVMFactory.cs index 8d94699dd..81dca6eff 100644 --- a/src/Artemis.UI/DryIoc/Factories/IVMFactory.cs +++ b/src/Artemis.UI/DryIoc/Factories/IVMFactory.cs @@ -40,9 +40,7 @@ public interface IDeviceVmFactory : IVmFactory DevicePropertiesViewModel DevicePropertiesViewModel(ArtemisDevice device); DeviceSettingsViewModel DeviceSettingsViewModel(ArtemisDevice device, DevicesTabViewModel devicesTabViewModel); DeviceDetectInputViewModel DeviceDetectInputViewModel(ArtemisDevice device); - DevicePropertiesTabViewModel DevicePropertiesTabViewModel(ArtemisDevice device); DeviceLayoutTabViewModel DeviceLayoutTabViewModel(ArtemisDevice device); - DeviceInfoTabViewModel DeviceInfoTabViewModel(ArtemisDevice device); DeviceLedsTabViewModel DeviceLedsTabViewModel(ArtemisDevice device, ObservableCollection selectedLeds); InputMappingsTabViewModel InputMappingsTabViewModel(ArtemisDevice device, ObservableCollection selectedLeds); DeviceGeneralTabViewModel DeviceGeneralTabViewModel(ArtemisDevice device); @@ -71,21 +69,11 @@ public class DeviceFactory : IDeviceVmFactory return _container.Resolve(new object[] { device }); } - public DevicePropertiesTabViewModel DevicePropertiesTabViewModel(ArtemisDevice device) - { - return _container.Resolve(new object[] { device }); - } - public DeviceLayoutTabViewModel DeviceLayoutTabViewModel(ArtemisDevice device) { return _container.Resolve(new object[] { device }); } - public DeviceInfoTabViewModel DeviceInfoTabViewModel(ArtemisDevice device) - { - return _container.Resolve(new object[] { device }); - } - public DeviceLedsTabViewModel DeviceLedsTabViewModel(ArtemisDevice device, ObservableCollection selectedLeds) { return _container.Resolve(new object[] { device, selectedLeds }); diff --git a/src/Artemis.UI/Screens/Device/DevicePropertiesViewModel.cs b/src/Artemis.UI/Screens/Device/DevicePropertiesViewModel.cs index 395a718f8..2c9cf056a 100644 --- a/src/Artemis.UI/Screens/Device/DevicePropertiesViewModel.cs +++ b/src/Artemis.UI/Screens/Device/DevicePropertiesViewModel.cs @@ -66,8 +66,6 @@ public class DevicePropertiesViewModel : DialogViewModelBase { Tabs.Add(_deviceVmFactory.DeviceGeneralTabViewModel(Device)); Tabs.Add(_deviceVmFactory.DeviceLayoutTabViewModel(Device)); - //Tabs.Add(_deviceVmFactory.DevicePropertiesTabViewModel(Device)); - //Tabs.Add(_deviceVmFactory.DeviceInfoTabViewModel(Device)); if (Device.DeviceType == RGBDeviceType.Keyboard) Tabs.Add(_deviceVmFactory.InputMappingsTabViewModel(Device, SelectedLeds)); Tabs.Add(_deviceVmFactory.DeviceLedsTabViewModel(Device, SelectedLeds)); diff --git a/src/Artemis.UI/Screens/Device/Tabs/DeviceInfoTabView.axaml b/src/Artemis.UI/Screens/Device/Tabs/DeviceInfoTabView.axaml deleted file mode 100644 index 1cb69cd13..000000000 --- a/src/Artemis.UI/Screens/Device/Tabs/DeviceInfoTabView.axaml +++ /dev/null @@ -1,88 +0,0 @@ - - - - - - - Device name - - - - Manufacturer - - - - - Device type - - - - - Physical layout - - - - - - - - Size (1px = 1mm) - - - - Location (1px = 1mm) - - - - Rotation (degrees) - - - - - Logical layout - - - - - - - - - - Default layout file path - - - - - - - Image file path - - - - - - - - - \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Device/Tabs/DeviceInfoTabView.axaml.cs b/src/Artemis.UI/Screens/Device/Tabs/DeviceInfoTabView.axaml.cs deleted file mode 100644 index 2a84f5581..000000000 --- a/src/Artemis.UI/Screens/Device/Tabs/DeviceInfoTabView.axaml.cs +++ /dev/null @@ -1,24 +0,0 @@ -using Avalonia.Controls; -using Avalonia.Interactivity; -using Avalonia.Markup.Xaml; -using Avalonia.ReactiveUI; - -namespace Artemis.UI.Screens.Device; - -public partial class DeviceInfoTabView : ReactiveUserControl -{ - public DeviceInfoTabView() - { - InitializeComponent(); - } - - private void LayoutPathButton_OnClick(object? sender, RoutedEventArgs e) - { - TopLevel.GetTopLevel(this).Clipboard.SetTextAsync(ViewModel.DefaultLayoutPath); - } - - private void ImagePathButton_OnClick(object? sender, RoutedEventArgs e) - { - TopLevel.GetTopLevel(this).Clipboard.SetTextAsync(ViewModel.Device.Layout.Image.LocalPath); - } -} \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Device/Tabs/DeviceInfoTabViewModel.cs b/src/Artemis.UI/Screens/Device/Tabs/DeviceInfoTabViewModel.cs deleted file mode 100644 index 8ca43ad00..000000000 --- a/src/Artemis.UI/Screens/Device/Tabs/DeviceInfoTabViewModel.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.Threading.Tasks; -using Artemis.Core; -using Artemis.UI.Shared; -using Artemis.UI.Shared.Services; -using Avalonia; -using Avalonia.Controls; -using RGB.NET.Core; - -namespace Artemis.UI.Screens.Device; - -public class DeviceInfoTabViewModel : ActivatableViewModelBase -{ - private readonly INotificationService _notificationService; - - public DeviceInfoTabViewModel(ArtemisDevice device, INotificationService notificationService) - { - _notificationService = notificationService; - - Device = device; - DisplayName = "Info"; - - DefaultLayoutPath = Device.DeviceProvider.LoadLayout(Device).FilePath; - } - - public bool IsKeyboard => Device.DeviceType == RGBDeviceType.Keyboard; - public ArtemisDevice Device { get; } - - public string DefaultLayoutPath { get; } -} \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Device/Tabs/DevicePropertiesTabView.axaml b/src/Artemis.UI/Screens/Device/Tabs/DevicePropertiesTabView.axaml deleted file mode 100644 index b4e0012af..000000000 --- a/src/Artemis.UI/Screens/Device/Tabs/DevicePropertiesTabView.axaml +++ /dev/null @@ -1,204 +0,0 @@ - - - - - - - - - - - - Categories - - - Artemis uses categories to determine where the layers of imported profiles are applied to. - - - You can hover over a category for a more detailed description. - - - - - - - - - - - - - Surface properties - - - X-coordinate - - mm - - Y-coordinate - - mm - - Scale - - times - - Rotation - - deg - - - - - - - - Color calibration - - - - Use the sliders below to adjust the colors of your device so that it matches your other devices. - - - - - - - - - - Layout - - - The device layout is used to determine the position of LEDs and to create the visual representation of the device you see on the left side of this window. - - - - - - Don't load default layout - - - - - - - - - - - - Learn more about layouts on the wiki - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Device/Tabs/DevicePropertiesTabView.axaml.cs b/src/Artemis.UI/Screens/Device/Tabs/DevicePropertiesTabView.axaml.cs deleted file mode 100644 index f71b14155..000000000 --- a/src/Artemis.UI/Screens/Device/Tabs/DevicePropertiesTabView.axaml.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Avalonia.Input; -using Avalonia.Markup.Xaml; -using Avalonia.ReactiveUI; - -namespace Artemis.UI.Screens.Device; - -public partial class DevicePropertiesTabView : ReactiveUserControl -{ - public DevicePropertiesTabView() - { - InitializeComponent(); - } - - - private void InputElement_OnPointerReleased(object? sender, PointerReleasedEventArgs e) - { - ViewModel?.BrowseCustomLayout(); - } -} \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Device/Tabs/DevicePropertiesTabViewModel.cs b/src/Artemis.UI/Screens/Device/Tabs/DevicePropertiesTabViewModel.cs deleted file mode 100644 index da3ac2fb3..000000000 --- a/src/Artemis.UI/Screens/Device/Tabs/DevicePropertiesTabViewModel.cs +++ /dev/null @@ -1,279 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Reactive.Disposables; -using System.Threading.Tasks; -using Artemis.Core; -using Artemis.Core.Services; -using Artemis.UI.Shared; -using Artemis.UI.Shared.Services; -using Artemis.UI.Shared.Services.Builders; -using ReactiveUI; -using SkiaSharp; - -namespace Artemis.UI.Screens.Device; - -public class DevicePropertiesTabViewModel : ActivatableViewModelBase -{ - private readonly List _categories; - private readonly ICoreService _coreService; - private readonly float _initialBlueScale; - private readonly float _initialGreenScale; - private readonly float _initialRedScale; - private readonly INotificationService _notificationService; - private readonly IRgbService _rgbService; - private readonly IWindowService _windowService; - private float _blueScale; - private SKColor _currentColor; - private bool _displayOnDevices; - private float _greenScale; - private float _redScale; - private int _rotation; - private float _scale; - private int _x; - private int _y; - - public DevicePropertiesTabViewModel(ArtemisDevice device, ICoreService coreService, IRgbService rgbService, IWindowService windowService, INotificationService notificationService) - { - _coreService = coreService; - _rgbService = rgbService; - _windowService = windowService; - _notificationService = notificationService; - _categories = new List(device.Categories); - - Device = device; - DisplayName = "Properties"; - - X = (int) Device.X; - Y = (int) Device.Y; - Scale = Device.Scale; - Rotation = (int) Device.Rotation; - RedScale = Device.RedScale * 100f; - GreenScale = Device.GreenScale * 100f; - BlueScale = Device.BlueScale * 100f; - CurrentColor = SKColors.White; - - // We need to store the initial values to be able to restore them when the user clicks "Cancel" - _initialRedScale = Device.RedScale; - _initialGreenScale = Device.GreenScale; - _initialBlueScale = Device.BlueScale; - - this.WhenAnyValue(x => x.RedScale, x => x.GreenScale, x => x.BlueScale).Subscribe(_ => ApplyScaling()); - - this.WhenActivated(d => - { - Device.PropertyChanged += DeviceOnPropertyChanged; - _coreService.FrameRendering += OnFrameRendering; - - Disposable.Create(() => - { - _coreService.FrameRendering -= OnFrameRendering; - Device.PropertyChanged -= DeviceOnPropertyChanged; - }).DisposeWith(d); - }); - } - - public ArtemisDevice Device { get; } - - public int X - { - get => _x; - set => RaiseAndSetIfChanged(ref _x, value); - } - - public int Y - { - get => _y; - set => RaiseAndSetIfChanged(ref _y, value); - } - - public float Scale - { - get => _scale; - set => RaiseAndSetIfChanged(ref _scale, value); - } - - public int Rotation - { - get => _rotation; - set => RaiseAndSetIfChanged(ref _rotation, value); - } - - public float RedScale - { - get => _redScale; - set => RaiseAndSetIfChanged(ref _redScale, value); - } - - public float GreenScale - { - get => _greenScale; - set => RaiseAndSetIfChanged(ref _greenScale, value); - } - - public float BlueScale - { - get => _blueScale; - set => RaiseAndSetIfChanged(ref _blueScale, value); - } - - public SKColor CurrentColor - { - get => _currentColor; - set => RaiseAndSetIfChanged(ref _currentColor, value); - } - - public bool DisplayOnDevices - { - get => _displayOnDevices; - set => RaiseAndSetIfChanged(ref _displayOnDevices, value); - } - - // This solution won't scale well but I don't expect there to be many more categories. - // If for some reason there will be, dynamically creating a view model per category may be more appropriate - public bool HasDeskCategory - { - get => GetCategory(DeviceCategory.Desk); - set => SetCategory(DeviceCategory.Desk, value); - } - - public bool HasMonitorCategory - { - get => GetCategory(DeviceCategory.Monitor); - set => SetCategory(DeviceCategory.Monitor, value); - } - - public bool HasCaseCategory - { - get => GetCategory(DeviceCategory.Case); - set => SetCategory(DeviceCategory.Case, value); - } - - public bool HasRoomCategory - { - get => GetCategory(DeviceCategory.Room); - set => SetCategory(DeviceCategory.Room, value); - } - - public bool HasPeripheralsCategory - { - get => GetCategory(DeviceCategory.Peripherals); - set => SetCategory(DeviceCategory.Peripherals, value); - } - - public bool RequiresManualSetup => !Device.DeviceProvider.CanDetectPhysicalLayout || !Device.DeviceProvider.CanDetectLogicalLayout; - - public void ApplyScaling() - { - Device.RedScale = RedScale / 100f; - Device.GreenScale = GreenScale / 100f; - Device.BlueScale = BlueScale / 100f; - - _rgbService.FlushLeds = true; - } - - public void ClearCustomLayout() - { - Device.CustomLayoutPath = null; - _notificationService.CreateNotification() - .WithMessage("Cleared imported layout.") - .WithSeverity(NotificationSeverity.Informational); - } - - public async Task BrowseCustomLayout() - { - string[]? files = await _windowService.CreateOpenFileDialog() - .WithTitle("Select device layout file") - .HavingFilter(f => f.WithName("Layout files").WithExtension("xml")) - .ShowAsync(); - - if (files?.Length > 0) - { - Device.CustomLayoutPath = files[0]; - _notificationService.CreateNotification() - .WithTitle("Imported layout") - .WithMessage($"File loaded from {files[0]}") - .WithSeverity(NotificationSeverity.Informational); - } - } - - public async Task RestartSetup() - { - if (!RequiresManualSetup) - return; - if (!Device.DeviceProvider.CanDetectPhysicalLayout && !await DevicePhysicalLayoutDialogViewModel.SelectPhysicalLayout(_windowService, Device)) - return; - if (!Device.DeviceProvider.CanDetectLogicalLayout && !await DeviceLogicalLayoutDialogViewModel.SelectLogicalLayout(_windowService, Device)) - return; - - await Task.Delay(400); - _rgbService.SaveDevice(Device); - _rgbService.ApplyBestDeviceLayout(Device); - } - - public async Task Apply() - { - // TODO: Validation - - _coreService.ProfileRenderingDisabled = true; - await Task.Delay(100); - - Device.X = X; - Device.Y = Y; - Device.Scale = Scale; - Device.Rotation = Rotation; - Device.RedScale = RedScale / 100f; - Device.GreenScale = GreenScale / 100f; - Device.BlueScale = BlueScale / 100f; - Device.Categories.Clear(); - foreach (DeviceCategory deviceCategory in _categories) - Device.Categories.Add(deviceCategory); - - _rgbService.SaveDevice(Device); - - _coreService.ProfileRenderingDisabled = false; - } - - public void Reset() - { - HasDeskCategory = Device.Categories.Contains(DeviceCategory.Desk); - HasMonitorCategory = Device.Categories.Contains(DeviceCategory.Monitor); - HasCaseCategory = Device.Categories.Contains(DeviceCategory.Case); - HasRoomCategory = Device.Categories.Contains(DeviceCategory.Room); - HasPeripheralsCategory = Device.Categories.Contains(DeviceCategory.Peripherals); - - RedScale = _initialRedScale * 100; - GreenScale = _initialGreenScale * 100; - BlueScale = _initialBlueScale * 100; - } - - private bool GetCategory(DeviceCategory category) - { - return _categories.Contains(category); - } - - private void SetCategory(DeviceCategory category, bool value) - { - if (value && !_categories.Contains(category)) - _categories.Add(category); - else if (!value) - _categories.Remove(category); - - this.RaisePropertyChanged($"Has{category}Category"); - } - - private void OnFrameRendering(object? sender, FrameRenderingEventArgs e) - { - if (!_displayOnDevices) - return; - - using SKPaint overlayPaint = new() {Color = CurrentColor}; - e.Canvas.DrawRect(0, 0, e.Canvas.LocalClipBounds.Width, e.Canvas.LocalClipBounds.Height, overlayPaint); - } - - private void DeviceOnPropertyChanged(object? sender, PropertyChangedEventArgs e) - { - if (e.PropertyName == nameof(Device.CustomLayoutPath) || e.PropertyName == nameof(Device.DisableDefaultLayout)) - Task.Run(() => _rgbService.ApplyBestDeviceLayout(Device)); - } -} \ No newline at end of file