diff --git a/src/Artemis.Core/Models/Profile/AdaptionHints/KeyboardSectionAdaptionHint.cs b/src/Artemis.Core/Models/Profile/AdaptionHints/KeyboardSectionAdaptionHint.cs index 2415a9082..df6a78d93 100644 --- a/src/Artemis.Core/Models/Profile/AdaptionHints/KeyboardSectionAdaptionHint.cs +++ b/src/Artemis.Core/Models/Profile/AdaptionHints/KeyboardSectionAdaptionHint.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using Artemis.Storage.Entities.Profile.AdaptionHints; using RGB.NET.Core; @@ -15,7 +16,12 @@ public class KeyboardSectionAdaptionHint : CorePropertyChanged, IAdaptionHint { {KeyboardSection.MacroKeys, Enum.GetValues().Where(l => l >= LedId.Keyboard_Programmable1 && l <= LedId.Keyboard_Programmable32).ToList()}, {KeyboardSection.LedStrips, Enum.GetValues().Where(l => l >= LedId.LedStripe1 && l <= LedId.LedStripe128).ToList()}, - {KeyboardSection.Extra, Enum.GetValues().Where(l => l >= LedId.Keyboard_Custom1 && l <= LedId.Keyboard_Custom64).ToList()} + {KeyboardSection.Extra, Enum.GetValues().Where(l => l >= LedId.Keyboard_Custom1 && l <= LedId.Keyboard_Custom64).ToList()}, + {KeyboardSection.FunctionKeys, Enum.GetValues().Where(l => l >= LedId.Keyboard_F1 && l <= LedId.Keyboard_F12).ToList()}, + {KeyboardSection.NumberKeys, Enum.GetValues().Where(l => l >= LedId.Keyboard_1 && l <= LedId.Keyboard_0).ToList()}, + {KeyboardSection.NumPad, Enum.GetValues().Where(l => l >= LedId.Keyboard_NumLock && l <= LedId.Keyboard_NumPeriodAndDelete).ToList()}, + {KeyboardSection.ArrowKeys, Enum.GetValues().Where(l => l >= LedId.Keyboard_PageDown && l <= LedId.Keyboard_ArrowRight).ToList()}, + {KeyboardSection.MediaKeys, Enum.GetValues().Where(l => l >= LedId.Keyboard_MediaMute && l <= LedId.Keyboard_MediaNextTrack).ToList()}, }; private KeyboardSection _section; @@ -46,6 +52,12 @@ public KeyboardSection Section /// public void Apply(Layer layer, List devices) { + if (Section == KeyboardSection.Movement) + { + ApplyMovement(layer, devices); + return; + } + // Only keyboards should have the LEDs we care about foreach (ArtemisDevice keyboard in devices.Where(d => d.DeviceType == RGBDeviceType.Keyboard)) { @@ -54,6 +66,26 @@ public void Apply(Layer layer, List devices) } } + private void ApplyMovement(Layer layer, List devices) + { + // Only keyboards should have the LEDs we care about + foreach (ArtemisDevice keyboard in devices.Where(d => d.DeviceType == RGBDeviceType.Keyboard)) + { + ArtemisLed? qLed = keyboard.Leds.FirstOrDefault(l => l.RgbLed.Id == LedId.Keyboard_Q); + ArtemisLed? aLed = keyboard.Leds.FirstOrDefault(l => l.RgbLed.Id == LedId.Keyboard_A); + if (qLed == null || aLed == null) + continue; + + // AZERTY keyboards will have their A above their Q + bool isAzerty = aLed.Rectangle.MidX < qLed.Rectangle.MidX; + + if (isAzerty) + layer.AddLeds(keyboard.Leds.Where(l => l.RgbLed.Id is LedId.Keyboard_Z or LedId.Keyboard_Q or LedId.Keyboard_S or LedId.Keyboard_D)); + else + layer.AddLeds(keyboard.Leds.Where(l => l.RgbLed.Id is LedId.Keyboard_W or LedId.Keyboard_A or LedId.Keyboard_S or LedId.Keyboard_D)); + } + } + /// public IAdaptionHintEntity GetEntry() { @@ -77,15 +109,45 @@ public enum KeyboardSection /// /// A region containing the macro keys of a keyboard /// - MacroKeys, + [Description("Macro Keys")] MacroKeys, /// /// A region containing the LED strips of a keyboard /// - LedStrips, + [Description("LED Strips")] LedStrips, + + /// + /// A region containing the extra non-standard LEDs of a keyboard + /// + [Description("Extra LEDs")] Extra, + + /// + /// A region containing the movement keys of a keyboard (WASD for QWERTY and ZQSD for AZERTY) + /// + [Description("Movement (WASD/ZQSD)")] Movement, + + /// + /// A region containing the F-keys of a keyboard + /// + [Description("F-keys")] FunctionKeys, + + /// + /// A region containing the numeric keys of a keyboard + /// + [Description("Numeric keys")] NumberKeys, + + /// + /// A region containing the Numpad of a keyboard + /// + [Description("Numpad")] NumPad, + + /// + /// A region containing the arrow keys of a keyboard + /// + [Description("Arrow keys")] ArrowKeys, /// - /// A region containing extra non-standard LEDs of a keyboard + /// A region containing the media keys of a keyboard /// - Extra + [Description("Media keys")] MediaKeys } \ No newline at end of file diff --git a/src/Artemis.Core/Models/Profile/AdaptionHints/SingeLedAdaptionHint.cs b/src/Artemis.Core/Models/Profile/AdaptionHints/SingeLedAdaptionHint.cs new file mode 100644 index 000000000..9f3975432 --- /dev/null +++ b/src/Artemis.Core/Models/Profile/AdaptionHints/SingeLedAdaptionHint.cs @@ -0,0 +1,102 @@ +using System.Collections.Generic; +using System.Linq; +using Artemis.Storage.Entities.Profile.AdaptionHints; +using RGB.NET.Core; + +namespace Artemis.Core; + +/// +/// Represents a hint that adapts layers to a single LED of one or more devices +/// +public class SingleLedAdaptionHint : CorePropertyChanged, IAdaptionHint +{ + private LedId _ledId; + private int _skip; + private bool _limitAmount; + private int _amount; + + /// + /// Creates a new instance of the class + /// + public SingleLedAdaptionHint() + { + } + + internal SingleLedAdaptionHint(SingleLedAdaptionHintEntity entity) + { + LedId = (LedId) entity.LedId; + Skip = entity.Skip; + LimitAmount = entity.LimitAmount; + Amount = entity.Amount; + } + + /// + /// Gets or sets the LED ID to apply to. + /// + public LedId LedId + { + get => _ledId; + set => SetAndNotify(ref _ledId, value); + } + + /// + /// Gets or sets the amount of devices to skip + /// + public int Skip + { + get => _skip; + set => SetAndNotify(ref _skip, value); + } + + /// + /// Gets or sets a boolean indicating whether a limited amount of devices should be used + /// + public bool LimitAmount + { + get => _limitAmount; + set => SetAndNotify(ref _limitAmount, value); + } + + /// + /// Gets or sets the amount of devices to limit to if is + /// + public int Amount + { + get => _amount; + set => SetAndNotify(ref _amount, value); + } + + #region Implementation of IAdaptionHint + + /// + public void Apply(Layer layer, List devices) + { + IEnumerable matches = devices + .Where(d => d.Leds.Any(l => l.RgbLed.Id == LedId)) + .OrderBy(d => d.Rectangle.Top) + .ThenBy(d => d.Rectangle.Left) + .Skip(Skip); + if (LimitAmount) + matches = matches.Take(Amount); + + foreach (ArtemisDevice artemisDevice in matches) + { + ArtemisLed led = artemisDevice.Leds.First(l => l.RgbLed.Id == LedId); + layer.AddLed(led); + } + } + + /// + public IAdaptionHintEntity GetEntry() + { + return new SingleLedAdaptionHintEntity {Amount = Amount, LimitAmount = LimitAmount, Skip = Skip, LedId = (int) LedId}; + } + + /// + public override string ToString() + { + return $"Single LED adaption - {nameof(LedId)}: {LedId}, {nameof(Skip)}: {Skip}, {nameof(LimitAmount)}: {LimitAmount}, {nameof(Amount)}: {Amount}"; + } + + #endregion +} \ No newline at end of file diff --git a/src/Artemis.Core/Models/Profile/LayerAdapter.cs b/src/Artemis.Core/Models/Profile/LayerAdapter.cs index 30c922a1d..72b29719c 100644 --- a/src/Artemis.Core/Models/Profile/LayerAdapter.cs +++ b/src/Artemis.Core/Models/Profile/LayerAdapter.cs @@ -111,6 +111,15 @@ public List DetermineHints(IEnumerable devices) newHints.Add(hint); } } + + // A single LED assignment is turned into a hint for one matching LED ID on the same device type + if (Layer.Leds.Count == 1) + { + ArtemisLed led = Layer.Leds.Single(); + SingleLedAdaptionHint hint = new() {LedId = led.RgbLed.Id, Amount = 1, LimitAmount = true}; + Add(hint); + newHints.Add(hint); + } } return newHints; @@ -184,6 +193,9 @@ public void Load() case KeyboardSectionAdaptionHintEntity entity: Add(new KeyboardSectionAdaptionHint(entity)); break; + case SingleLedAdaptionHintEntity entity: + Add(new SingleLedAdaptionHint(entity)); + break; } } } diff --git a/src/Artemis.Storage/Entities/Profile/AdaptionHints/SingleLedAdaptionHintEntity.cs b/src/Artemis.Storage/Entities/Profile/AdaptionHints/SingleLedAdaptionHintEntity.cs new file mode 100644 index 000000000..925929af7 --- /dev/null +++ b/src/Artemis.Storage/Entities/Profile/AdaptionHints/SingleLedAdaptionHintEntity.cs @@ -0,0 +1,10 @@ +namespace Artemis.Storage.Entities.Profile.AdaptionHints; + +public class SingleLedAdaptionHintEntity : IAdaptionHintEntity +{ + public int LedId { get; set; } + + public bool LimitAmount { get; set; } + public int Skip { get; set; } + public int Amount { get; set; } +} \ No newline at end of file diff --git a/src/Artemis.UI.Shared/Controls/EnumComboBox.axaml b/src/Artemis.UI.Shared/Controls/EnumComboBox.axaml index 19c39fd7d..864692588 100644 --- a/src/Artemis.UI.Shared/Controls/EnumComboBox.axaml +++ b/src/Artemis.UI.Shared/Controls/EnumComboBox.axaml @@ -8,7 +8,7 @@ - + diff --git a/src/Artemis.UI.Shared/Services/ProfileEditor/Commands/ApplyAdaptionHints.cs b/src/Artemis.UI.Shared/Services/ProfileEditor/Commands/ApplyAdaptionHints.cs new file mode 100644 index 000000000..1ce33ca35 --- /dev/null +++ b/src/Artemis.UI.Shared/Services/ProfileEditor/Commands/ApplyAdaptionHints.cs @@ -0,0 +1,45 @@ +using System.Collections.Generic; +using Artemis.Core; + +namespace Artemis.UI.Shared.Services.ProfileEditor.Commands; + +/// +/// Represents a profile editor command that can be used to apply adaption hints to a layer. +/// +public class ApplyAdaptionHints : IProfileEditorCommand +{ + private readonly Layer _layer; + private readonly List _devices; + private readonly List _originalLeds; + + /// + /// Creates a new instance of the class. + /// + public ApplyAdaptionHints(Layer layer, List devices) + { + _layer = layer; + _devices = devices; + _originalLeds = new List(_layer.Leds); + } + + #region Implementation of IProfileEditorCommand + + /// + public string DisplayName => "Apply adaption hints"; + + /// + public void Execute() + { + _layer.ClearLeds(); + _layer.Adapter.Adapt(_devices); + } + + /// + public void Undo() + { + _layer.ClearLeds(); + _layer.AddLeds(_originalLeds); + } + + #endregion +} \ No newline at end of file diff --git a/src/Artemis.UI/Artemis.UI.csproj b/src/Artemis.UI/Artemis.UI.csproj index c1b71c6f2..b468d03f6 100644 --- a/src/Artemis.UI/Artemis.UI.csproj +++ b/src/Artemis.UI/Artemis.UI.csproj @@ -51,23 +51,4 @@ - - - - ProfileListView.axaml - Code - - - LayoutListView.axaml - Code - - - SubmissionsDetailView.axaml - Code - - - - - - \ No newline at end of file diff --git a/src/Artemis.UI/DryIoc/Factories/IVMFactory.cs b/src/Artemis.UI/DryIoc/Factories/IVMFactory.cs index 98fb7ea4e..b66691036 100644 --- a/src/Artemis.UI/DryIoc/Factories/IVMFactory.cs +++ b/src/Artemis.UI/DryIoc/Factories/IVMFactory.cs @@ -430,6 +430,7 @@ public interface ILayerHintVmFactory : IVmFactory CategoryAdaptionHintViewModel CategoryAdaptionHintViewModel(Layer layer, CategoryAdaptionHint adaptionHint); DeviceAdaptionHintViewModel DeviceAdaptionHintViewModel(Layer layer, DeviceAdaptionHint adaptionHint); KeyboardSectionAdaptionHintViewModel KeyboardSectionAdaptionHintViewModel(Layer layer, KeyboardSectionAdaptionHint adaptionHint); + SingleLedAdaptionHintViewModel SingleLedAdaptionHintViewModel(Layer layer, SingleLedAdaptionHint adaptionHint); } public class LayerHintVmFactory : ILayerHintVmFactory { @@ -454,6 +455,11 @@ public KeyboardSectionAdaptionHintViewModel KeyboardSectionAdaptionHintViewModel { return _container.Resolve(new object[] { layer, adaptionHint }); } + + public SingleLedAdaptionHintViewModel SingleLedAdaptionHintViewModel(Layer layer, SingleLedAdaptionHint adaptionHint) + { + return _container.Resolve(new object[] { layer, adaptionHint }); + } } public interface IScriptVmFactory : IVmFactory diff --git a/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/Dialogs/AdaptionHints/CategoryAdaptionHintView.axaml b/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/Dialogs/AdaptionHints/CategoryAdaptionHintView.axaml index 6fc3e55ba..de6da561e 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/Dialogs/AdaptionHints/CategoryAdaptionHintView.axaml +++ b/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/Dialogs/AdaptionHints/CategoryAdaptionHintView.axaml @@ -26,7 +26,7 @@ - + Skip - + Skip - + diff --git a/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/Dialogs/AdaptionHints/SingleLedAdaptionHintView.axaml b/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/Dialogs/AdaptionHints/SingleLedAdaptionHintView.axaml new file mode 100644 index 000000000..1c927177c --- /dev/null +++ b/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/Dialogs/AdaptionHints/SingleLedAdaptionHintView.axaml @@ -0,0 +1,57 @@ + + + + Single LED hint + Applies the layer to a single LED of one or more devices + + + + + + + Skip + + device(s) + + Take + + device(s) + + + + + diff --git a/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/Dialogs/AdaptionHints/SingleLedAdaptionHintView.axaml.cs b/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/Dialogs/AdaptionHints/SingleLedAdaptionHintView.axaml.cs new file mode 100644 index 000000000..1a82d8d6e --- /dev/null +++ b/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/Dialogs/AdaptionHints/SingleLedAdaptionHintView.axaml.cs @@ -0,0 +1,13 @@ +using Avalonia.Controls; +using Avalonia.Markup.Xaml; + +namespace Artemis.UI.Screens.ProfileEditor.ProfileTree.Dialogs.AdaptionHints; + +public partial class SingleLedAdaptionHintView : UserControl +{ + public SingleLedAdaptionHintView() + { + InitializeComponent(); + } + +} \ No newline at end of file diff --git a/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/Dialogs/AdaptionHints/SingleLedAdaptionHintViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/Dialogs/AdaptionHints/SingleLedAdaptionHintViewModel.cs new file mode 100644 index 000000000..4264a2d55 --- /dev/null +++ b/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/Dialogs/AdaptionHints/SingleLedAdaptionHintViewModel.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Artemis.Core; +using ReactiveUI; +using RGB.NET.Core; + +namespace Artemis.UI.Screens.ProfileEditor.ProfileTree.Dialogs.AdaptionHints; + +public class SingleLedAdaptionHintViewModel : AdaptionHintViewModelBase +{ + private List _adaptionLeds; + private AdaptionLed? _selectedLed; + + public SingleLedAdaptionHintViewModel(Layer layer, SingleLedAdaptionHint adaptionHint) : base(layer, adaptionHint) + { + SingleLedAdaptionHint = adaptionHint; + + this.WhenAnyValue(vm => vm.SelectedLed).WhereNotNull().Subscribe(l => SingleLedAdaptionHint.LedId = l.Value); + Task.Run(() => + { + AdaptionLeds = Enum.GetValues().Select(l => new AdaptionLed(l)).ToList(); + SelectedLed = AdaptionLeds.FirstOrDefault(l => l.Value == adaptionHint.LedId); + }); + } + + public List AdaptionLeds + { + get => _adaptionLeds; + set => RaiseAndSetIfChanged(ref _adaptionLeds, value); + } + + public AdaptionLed? SelectedLed + { + get => _selectedLed; + set => RaiseAndSetIfChanged(ref _selectedLed, value); + } + + public SingleLedAdaptionHint SingleLedAdaptionHint { get; } +} + +public class AdaptionLed +{ + public AdaptionLed(LedId led) + { + Value = led; + Description = led.ToString(); + } + + public LedId Value { get; } + public string Description { get; } +} \ No newline at end of file diff --git a/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/Dialogs/LayerHintsDialogView.axaml b/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/Dialogs/LayerHintsDialogView.axaml index 23911689d..dd639d704 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/Dialogs/LayerHintsDialogView.axaml +++ b/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/Dialogs/LayerHintsDialogView.axaml @@ -34,37 +34,34 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - - You haven't set up any adaption hints - - - Artemis will attempt to directly map the LEDs of this layer to different surfaces but results may vary. - - - - - + + + + You haven't set up any adaption hints + + + Artemis will attempt to directly map the LEDs of this layer to different surfaces but results may vary. + + + @@ -87,6 +84,11 @@ + + + + + Add hint diff --git a/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/Dialogs/LayerHintsDialogViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/Dialogs/LayerHintsDialogViewModel.cs index 41514aa0e..5072135a1 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/Dialogs/LayerHintsDialogViewModel.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/Dialogs/LayerHintsDialogViewModel.cs @@ -66,6 +66,12 @@ public void AddKeyboardSectionHint() { Layer.Adapter.Add(new KeyboardSectionAdaptionHint()); } + + public void AddSingleLedHint() + { + Layer.Adapter.Add(new SingleLedAdaptionHint()); + } + public void RemoveAdaptionHint(IAdaptionHint hint) { @@ -79,6 +85,7 @@ private AdaptionHintViewModelBase CreateHintViewModel(IAdaptionHint hint) CategoryAdaptionHint categoryAdaptionHint => _vmFactory.CategoryAdaptionHintViewModel(Layer, categoryAdaptionHint), DeviceAdaptionHint deviceAdaptionHint => _vmFactory.DeviceAdaptionHintViewModel(Layer, deviceAdaptionHint), KeyboardSectionAdaptionHint keyboardSectionAdaptionHint => _vmFactory.KeyboardSectionAdaptionHintViewModel(Layer, keyboardSectionAdaptionHint), + SingleLedAdaptionHint singleLedAdaptionHint => _vmFactory.SingleLedAdaptionHintViewModel(Layer, singleLedAdaptionHint), _ => throw new ArgumentOutOfRangeException(nameof(hint)) }; } diff --git a/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/FolderTreeItemViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/FolderTreeItemViewModel.cs index c8c54bdca..3e767e93f 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/FolderTreeItemViewModel.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/FolderTreeItemViewModel.cs @@ -22,7 +22,7 @@ public FolderTreeItemViewModel(TreeItemViewModel? parent, IProfileEditorService profileEditorService, IRgbService rgbService, IProfileEditorVmFactory profileEditorVmFactory) - : base(parent, folder, windowService, profileEditorService, profileEditorVmFactory) + : base(parent, folder, windowService, rgbService, profileEditorService, profileEditorVmFactory) { _rgbService = rgbService; Folder = folder; diff --git a/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/LayerTreeItemViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/LayerTreeItemViewModel.cs index f3c63fc4e..920674f17 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/LayerTreeItemViewModel.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/LayerTreeItemViewModel.cs @@ -22,7 +22,7 @@ public LayerTreeItemViewModel(TreeItemViewModel? parent, IProfileEditorService profileEditorService, IRgbService rgbService, IProfileEditorVmFactory profileEditorVmFactory) - : base(parent, layer, windowService, profileEditorService, profileEditorVmFactory) + : base(parent, layer, windowService, rgbService, profileEditorService, profileEditorVmFactory) { _rgbService = rgbService; Layer = layer; diff --git a/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/ProfileTreeView.axaml b/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/ProfileTreeView.axaml index bfea0d4e5..e6a788876 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/ProfileTreeView.axaml +++ b/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/ProfileTreeView.axaml @@ -119,6 +119,11 @@ + + + + + diff --git a/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/ProfileTreeViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/ProfileTreeViewModel.cs index 7a331d321..6d46177b7 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/ProfileTreeViewModel.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/ProfileTreeViewModel.cs @@ -7,6 +7,7 @@ using System.Reactive.Linq; using System.Threading.Tasks; using Artemis.Core; +using Artemis.Core.Services; using Artemis.UI.DryIoc.Factories; using Artemis.UI.Shared.Services; using Artemis.UI.Shared.Services.ProfileEditor; @@ -22,8 +23,8 @@ public class ProfileTreeViewModel : TreeItemViewModel private ObservableAsPropertyHelper? _keyBindingsEnabled; private TreeItemViewModel? _selectedChild; - public ProfileTreeViewModel(IWindowService windowService, IProfileEditorService profileEditorService, IProfileEditorVmFactory profileEditorVmFactory) - : base(null, null, windowService, profileEditorService, profileEditorVmFactory) + public ProfileTreeViewModel(IWindowService windowService, IRgbService rgbService, IProfileEditorService profileEditorService, IProfileEditorVmFactory profileEditorVmFactory) + : base(null, null, windowService, rgbService, profileEditorService, profileEditorVmFactory) { this.WhenActivated(d => { diff --git a/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/TreeItemViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/TreeItemViewModel.cs index fffbb21ff..9a35c54eb 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/TreeItemViewModel.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/Panels/ProfileTree/TreeItemViewModel.cs @@ -5,8 +5,10 @@ using System.Reactive; using System.Reactive.Disposables; using System.Reactive.Linq; +using System.Threading; using System.Threading.Tasks; using Artemis.Core; +using Artemis.Core.Services; using Artemis.UI.DryIoc.Factories; using Artemis.UI.Extensions; using Artemis.UI.Screens.ProfileEditor.ProfileTree.ContentDialogs; @@ -26,6 +28,7 @@ public abstract class TreeItemViewModel : ActivatableViewModelBase { private readonly IProfileEditorVmFactory _profileEditorVmFactory; private readonly IWindowService _windowService; + private readonly IRgbService _rgbService; protected readonly IProfileEditorService ProfileEditorService; private bool _canPaste; private RenderProfileElement? _currentProfileElement; @@ -38,11 +41,13 @@ public abstract class TreeItemViewModel : ActivatableViewModelBase protected TreeItemViewModel(TreeItemViewModel? parent, ProfileElement? profileElement, IWindowService windowService, + IRgbService rgbService, IProfileEditorService profileEditorService, IProfileEditorVmFactory profileEditorVmFactory) { ProfileEditorService = profileEditorService; _windowService = windowService; + _rgbService = rgbService; _profileEditorVmFactory = profileEditorVmFactory; Parent = parent; @@ -51,6 +56,7 @@ protected TreeItemViewModel(TreeItemViewModel? parent, AddLayer = ReactiveCommand.Create(ExecuteAddLayer); AddFolder = ReactiveCommand.Create(ExecuteAddFolder); OpenAdaptionHints = ReactiveCommand.CreateFromTask(ExecuteOpenAdaptionHints, this.WhenAnyValue(vm => vm.ProfileElement).Select(p => p is Layer)); + ApplyAdaptionHints = ReactiveCommand.Create(ExecuteApplyAdaptionHints, this.WhenAnyValue(vm => vm.ProfileElement).Select(p => p is Layer)); Rename = ReactiveCommand.CreateFromTask(ExecuteRename); Delete = ReactiveCommand.Create(ExecuteDelete); Duplicate = ReactiveCommand.CreateFromTask(ExecuteDuplicate); @@ -109,6 +115,7 @@ public bool CanPaste public ReactiveCommand AddLayer { get; } public ReactiveCommand AddFolder { get; } public ReactiveCommand OpenAdaptionHints { get; } + public ReactiveCommand ApplyAdaptionHints { get; } public ReactiveCommand Rename { get; } public ReactiveCommand Duplicate { get; } public ReactiveCommand Copy { get; } @@ -254,6 +261,14 @@ private async Task ExecuteOpenAdaptionHints() await _windowService.ShowDialogAsync(layer); await ProfileEditorService.SaveProfileAsync(); } + + private void ExecuteApplyAdaptionHints() + { + if (ProfileElement is not Layer layer) + return; + + ProfileEditorService.ExecuteCommand(new ApplyAdaptionHints(layer, _rgbService.EnabledDevices.ToList())); + } private async void UpdateCanPaste(bool isFlyoutOpen) {