Layer adapter hints - Ported UI

This commit is contained in:
Robert committed 2022-05-24 23:24:49 +02:00
1 parent 850346ccd2
commit 720bebaf35
23 files changed
+606 -22

No files matched your search

@@ -7,8 +7,13 @@ namespace Artemis.Core
/// <summary>
/// Represents a hint that adapts layers to a certain category of devices
/// </summary>
public class CategoryAdaptionHint : IAdaptionHint
public class CategoryAdaptionHint : CorePropertyChanged, IAdaptionHint
{
private DeviceCategory _category;
private int _skip;
private bool _limitAmount;
private int _amount;
/// <summary>
/// Creates a new instance of the <see cref="CategoryAdaptionHint" /> class
/// </summary>
@@ -27,22 +32,38 @@ namespace Artemis.Core
/// <summary>
/// Gets or sets the category of devices LEDs will be applied to
/// </summary>
public DeviceCategory Category { get; set; }
public DeviceCategory Category
{
get => _category;
set => SetAndNotify(ref _category, value);
}
/// <summary>
/// Gets or sets the amount of devices to skip
/// </summary>
public int Skip { get; set; }
public int Skip
{
get => _skip;
set => SetAndNotify(ref _skip, value);
}
/// <summary>
/// Gets or sets a boolean indicating whether a limited amount of devices should be used
/// </summary>
public bool LimitAmount { get; set; }
public bool LimitAmount
{
get => _limitAmount;
set => SetAndNotify(ref _limitAmount, value);
}
/// <summary>
/// Gets or sets the amount of devices to limit to if <see cref="LimitAmount" /> is <see langword="true" />
/// </summary>
public int Amount { get; set; }
public int Amount
{
get => _amount;
set => SetAndNotify(ref _amount, value);
}
/// <inheritdoc />
public override string ToString()
@@ -8,8 +8,13 @@ namespace Artemis.Core
/// <summary>
/// Represents a hint that adapts layers to a certain type of devices
/// </summary>
public class DeviceAdaptionHint : IAdaptionHint
public class DeviceAdaptionHint : CorePropertyChanged, IAdaptionHint
{
private RGBDeviceType _deviceType;
private int _skip;
private bool _limitAmount;
private int _amount;
/// <summary>
/// Creates a new instance of the <see cref="DeviceAdaptionHint" /> class
/// </summary>
@@ -28,22 +33,38 @@ namespace Artemis.Core
/// <summary>
/// Gets or sets the type of devices LEDs will be applied to
/// </summary>
public RGBDeviceType DeviceType { get; set; }
public RGBDeviceType DeviceType
{
get => _deviceType;
set => SetAndNotify(ref _deviceType, value);
}
/// <summary>
/// Gets or sets the amount of devices to skip
/// </summary>
public int Skip { get; set; }
public int Skip
{
get => _skip;
set => SetAndNotify(ref _skip, value);
}
/// <summary>
/// Gets or sets a boolean indicating whether a limited amount of devices should be used
/// </summary>
public bool LimitAmount { get; set; }
public bool LimitAmount
{
get => _limitAmount;
set => SetAndNotify(ref _limitAmount, value);
}
/// <summary>
/// Gets or sets the amount of devices to limit to if <see cref="LimitAmount" /> is <see langword="true" />
/// </summary>
public int Amount { get; set; }
public int Amount
{
get => _amount;
set => SetAndNotify(ref _amount, value);
}
#region Implementation of IAdaptionHint
@@ -9,7 +9,7 @@ namespace Artemis.Core
/// <summary>
/// Represents a hint that adapts layers to a certain region of keyboards
/// </summary>
public class KeyboardSectionAdaptionHint : IAdaptionHint
public class KeyboardSectionAdaptionHint : CorePropertyChanged, IAdaptionHint
{
private static readonly Dictionary<KeyboardSection, List<LedId>> RegionLedIds = new()
{
@@ -18,6 +18,8 @@ namespace Artemis.Core
{KeyboardSection.Extra, Enum.GetValues<LedId>().Where(l => l >= LedId.Keyboard_Custom1 && l <= LedId.Keyboard_Custom64).ToList()}
};
private KeyboardSection _section;
/// <summary>
/// Creates a new instance of the <see cref="KeyboardSectionAdaptionHint" /> class
/// </summary>
@@ -33,7 +35,11 @@ namespace Artemis.Core
/// <summary>
/// Gets or sets the section this hint will apply LEDs to
/// </summary>
public KeyboardSection Section { get; set; }
public KeyboardSection Section
{
get => _section;
set => SetAndNotify(ref _section, value);
}
#region Implementation of IAdaptionHint
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Artemis.Storage.Entities.Profile;
using Artemis.Storage.Entities.Profile.AdaptionHints;
@@ -12,10 +13,13 @@ namespace Artemis.Core
/// </summary>
public class LayerAdapter : IStorageModel
{
private readonly List<IAdaptionHint> _adaptionHints;
internal LayerAdapter(Layer layer)
{
_adaptionHints = new List<IAdaptionHint>();
Layer = layer;
AdaptionHints = new List<IAdaptionHint>();
AdaptionHints = new ReadOnlyCollection<IAdaptionHint>(_adaptionHints);
}
/// <summary>
@@ -26,7 +30,7 @@ namespace Artemis.Core
/// <summary>
/// Gets or sets a list containing the adaption hints used by this adapter
/// </summary>
public List<IAdaptionHint> AdaptionHints { get; set; }
public ReadOnlyCollection<IAdaptionHint> AdaptionHints { get; set; }
/// <summary>
/// Modifies the layer, adapting it to the provided <paramref name="devices" />
@@ -73,7 +77,7 @@ namespace Artemis.Core
if (devices.All(DoesLayerCoverDevice))
{
DeviceAdaptionHint hint = new() {DeviceType = RGBDeviceType.All};
AdaptionHints.Add(hint);
Add(hint);
newHints.Add(hint);
}
else
@@ -88,7 +92,7 @@ namespace Artemis.Core
if (DoesLayerCoverDevice(device))
{
DeviceAdaptionHint hint = new() {DeviceType = device.DeviceType};
AdaptionHints.Add(hint);
Add(hint);
newHints.Add(hint);
}
}
@@ -103,7 +107,7 @@ namespace Artemis.Core
if (categoryDevices.Any() && categoryDevices.All(DoesLayerCoverDevice))
{
CategoryAdaptionHint hint = new() {Category = deviceCategory};
AdaptionHints.Add(hint);
Add(hint);
newHints.Add(hint);
}
}
@@ -117,25 +121,57 @@ namespace Artemis.Core
return device.Leds.All(l => Layer.Leds.Contains(l));
}
/// <summary>
/// Adds an adaption hint to the adapter.
/// </summary>
/// <param name="adaptionHint">The adaption hint to add.</param>
public void Add(IAdaptionHint adaptionHint)
{
if (_adaptionHints.Contains(adaptionHint))
return;
_adaptionHints.Add(adaptionHint);
AdapterHintAdded?.Invoke(this, new LayerAdapterHintEventArgs(adaptionHint));
}
/// <summary>
/// Removes the first occurrence of a specific adaption hint from the adapter.
/// </summary>
/// <param name="adaptionHint">The adaption hint to remove.</param>
public void Remove(IAdaptionHint adaptionHint)
{
if (_adaptionHints.Remove(adaptionHint))
AdapterHintRemoved?.Invoke(this, new LayerAdapterHintEventArgs(adaptionHint));
}
/// <summary>
/// Removes all adaption hints from the adapter.
/// </summary>
public void Clear()
{
while (_adaptionHints.Any())
Remove(_adaptionHints.First());
}
#region Implementation of IStorageModel
/// <inheritdoc />
public void Load()
{
AdaptionHints.Clear();
_adaptionHints.Clear();
// Kind of meh.
// This leaves the adapter responsible for finding the right hint for the right entity, but it's gotta be done somewhere..
foreach (IAdaptionHintEntity hintEntity in Layer.LayerEntity.AdaptionHints)
switch (hintEntity)
{
case DeviceAdaptionHintEntity entity:
AdaptionHints.Add(new DeviceAdaptionHint(entity));
Add(new DeviceAdaptionHint(entity));
break;
case CategoryAdaptionHintEntity entity:
AdaptionHints.Add(new CategoryAdaptionHint(entity));
Add(new CategoryAdaptionHint(entity));
break;
case KeyboardSectionAdaptionHintEntity entity:
AdaptionHints.Add(new KeyboardSectionAdaptionHint(entity));
Add(new KeyboardSectionAdaptionHint(entity));
break;
}
}
@@ -149,5 +185,15 @@ namespace Artemis.Core
}
#endregion
/// <summary>
/// Occurs whenever a new adapter hint is added to the adapter.
/// </summary>
public event EventHandler<LayerAdapterHintEventArgs>? AdapterHintAdded;
/// <summary>
/// Occurs whenever an adapter hint is removed from the adapter.
/// </summary>
public event EventHandler<LayerAdapterHintEventArgs>? AdapterHintRemoved;
}
}