mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
Device dialog - Added input remapping for keyboards
Device dialog - Display layout author, if I missed anyone let me know!
This commit is contained in:
1 parent
8066586328
commit
c66c21152f
12 files changed
+302
-38
No files matched your search
@@ -35,10 +35,9 @@ namespace Artemis.Core
|
||||
IsEnabled = true;
|
||||
|
||||
InputIdentifiers = new List<ArtemisDeviceInputIdentifier>();
|
||||
InputMappings = new Dictionary<ArtemisLed, ArtemisLed>();
|
||||
|
||||
Leds = rgbDevice.Select(l => new ArtemisLed(l, this)).ToList().AsReadOnly();
|
||||
LedIds = new ReadOnlyDictionary<LedId, ArtemisLed>(Leds.ToDictionary(l => l.RgbLed.Id, l => l));
|
||||
|
||||
UpdateLeds();
|
||||
ApplyKeyboardLayout();
|
||||
ApplyToEntity();
|
||||
CalculateRenderProperties();
|
||||
@@ -52,12 +51,12 @@ namespace Artemis.Core
|
||||
DeviceProvider = deviceProvider;
|
||||
|
||||
InputIdentifiers = new List<ArtemisDeviceInputIdentifier>();
|
||||
InputMappings = new Dictionary<ArtemisLed, ArtemisLed>();
|
||||
|
||||
foreach (DeviceInputIdentifierEntity identifierEntity in DeviceEntity.InputIdentifiers)
|
||||
InputIdentifiers.Add(new ArtemisDeviceInputIdentifier(identifierEntity.InputProvider, identifierEntity.Identifier));
|
||||
|
||||
Leds = rgbDevice.Select(l => new ArtemisLed(l, this)).ToList().AsReadOnly();
|
||||
LedIds = new ReadOnlyDictionary<LedId, ArtemisLed>(Leds.ToDictionary(l => l.RgbLed.Id, l => l));
|
||||
|
||||
UpdateLeds();
|
||||
ApplyKeyboardLayout();
|
||||
}
|
||||
|
||||
@@ -110,6 +109,8 @@ namespace Artemis.Core
|
||||
/// </summary>
|
||||
public List<ArtemisDeviceInputIdentifier> InputIdentifiers { get; }
|
||||
|
||||
public Dictionary<ArtemisLed, ArtemisLed> InputMappings { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the X-position of the device
|
||||
/// </summary>
|
||||
@@ -287,20 +288,27 @@ namespace Artemis.Core
|
||||
/// Attempts to retrieve the <see cref="ArtemisLed" /> that corresponds the provided RGB.NET <see cref="Led" />
|
||||
/// </summary>
|
||||
/// <param name="led">The RGB.NET <see cref="Led" /> to find the corresponding <see cref="ArtemisLed" /> for </param>
|
||||
/// <param name="applyInputMapping">If <see langword="true"/>, LEDs mapped to different LEDs <see cref="InputMappings"/> are taken into consideration</param>
|
||||
/// <returns>If found, the corresponding <see cref="ArtemisLed" />; otherwise <see langword="null" />.</returns>
|
||||
public ArtemisLed? GetLed(Led led)
|
||||
public ArtemisLed? GetLed(Led led, bool applyInputMapping)
|
||||
{
|
||||
return GetLed(led.Id);
|
||||
return GetLed(led.Id, applyInputMapping);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to retrieve the <see cref="ArtemisLed" /> that corresponds the provided RGB.NET <see cref="LedId" />
|
||||
/// </summary>
|
||||
/// <param name="ledId">The RGB.NET <see cref="LedId" /> to find the corresponding <see cref="ArtemisLed" /> for </param>
|
||||
/// <param name="applyInputMapping">If <see langword="true"/>, LEDs mapped to different LEDs <see cref="InputMappings"/> are taken into consideration</param>
|
||||
/// <returns>If found, the corresponding <see cref="ArtemisLed" />; otherwise <see langword="null" />.</returns>
|
||||
public ArtemisLed? GetLed(LedId ledId)
|
||||
public ArtemisLed? GetLed(LedId ledId, bool applyInputMapping)
|
||||
{
|
||||
LedIds.TryGetValue(ledId, out ArtemisLed? artemisLed);
|
||||
if (artemisLed == null)
|
||||
return null;
|
||||
|
||||
if (applyInputMapping && InputMappings.TryGetValue(artemisLed, out ArtemisLed? mappedLed))
|
||||
return mappedLed;
|
||||
return artemisLed;
|
||||
}
|
||||
|
||||
@@ -339,8 +347,7 @@ namespace Artemis.Core
|
||||
if (layout.IsValid)
|
||||
layout.RgbLayout!.ApplyTo(RgbDevice, createMissingLeds, removeExcessiveLeds);
|
||||
|
||||
Leds = RgbDevice.Select(l => new ArtemisLed(l, this)).ToList().AsReadOnly();
|
||||
LedIds = new ReadOnlyDictionary<LedId, ArtemisLed>(Leds.ToDictionary(l => l.RgbLed.Id, l => l));
|
||||
UpdateLeds();
|
||||
|
||||
Layout = layout;
|
||||
Layout.ApplyDevice(this);
|
||||
@@ -348,6 +355,21 @@ namespace Artemis.Core
|
||||
OnDeviceUpdated();
|
||||
}
|
||||
|
||||
private void UpdateLeds()
|
||||
{
|
||||
Leds = RgbDevice.Select(l => new ArtemisLed(l, this)).ToList().AsReadOnly();
|
||||
LedIds = new ReadOnlyDictionary<LedId, ArtemisLed>(Leds.ToDictionary(l => l.RgbLed.Id, l => l));
|
||||
|
||||
InputMappings.Clear();
|
||||
foreach (InputMappingEntity deviceEntityInputMapping in DeviceEntity.InputMappings)
|
||||
{
|
||||
ArtemisLed? original = Leds.FirstOrDefault(l => l.RgbLed.Id == (LedId) deviceEntityInputMapping.OriginalLedId);
|
||||
ArtemisLed? mapped = Leds.FirstOrDefault(l => l.RgbLed.Id == (LedId) deviceEntityInputMapping.MappedLedId);
|
||||
if (original != null && mapped != null)
|
||||
InputMappings.Add(original, mapped);
|
||||
}
|
||||
}
|
||||
|
||||
internal void ApplyToEntity()
|
||||
{
|
||||
// Other properties are computed
|
||||
@@ -362,6 +384,10 @@ namespace Artemis.Core
|
||||
Identifier = identifier.Identifier
|
||||
});
|
||||
}
|
||||
|
||||
DeviceEntity.InputMappings.Clear();
|
||||
foreach (var (original, mapped) in InputMappings)
|
||||
DeviceEntity.InputMappings.Add(new InputMappingEntity {OriginalLedId = (int) original.RgbLed.Id, MappedLedId = (int) mapped.RgbLed.Id});
|
||||
}
|
||||
|
||||
internal void ApplyToRgbDevice()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Artemis.Core.Services;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
@@ -12,7 +13,7 @@ namespace Artemis.Core
|
||||
/// </summary>
|
||||
/// <param name="inputProvider">The full type and namespace of the <see cref="Services.InputProvider" /> this identifier is used by</param>
|
||||
/// <param name="identifier">A value used to identify the device</param>
|
||||
public ArtemisDeviceInputIdentifier(string inputProvider, object identifier)
|
||||
internal ArtemisDeviceInputIdentifier(string inputProvider, object identifier)
|
||||
{
|
||||
InputProvider = inputProvider;
|
||||
Identifier = identifier;
|
||||
@@ -28,4 +29,16 @@ namespace Artemis.Core
|
||||
/// </summary>
|
||||
public object Identifier { get; set; }
|
||||
}
|
||||
|
||||
public class ArtemisDeviceInputMapping
|
||||
{
|
||||
public ArtemisLed OriginalLed { get; }
|
||||
public ArtemisLed MappedLed { get; }
|
||||
|
||||
internal ArtemisDeviceInputMapping(ArtemisLed originalLed, ArtemisLed mappedLed)
|
||||
{
|
||||
OriginalLed = originalLed;
|
||||
MappedLed = mappedLed;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,15 @@ using RGB.NET.Core;
|
||||
|
||||
namespace Artemis.Core.Services
|
||||
{
|
||||
internal static class InputKeyUtilities
|
||||
/// <summary>
|
||||
/// Utilities for mapping keys and buttons to LEDs
|
||||
/// </summary>
|
||||
public static class InputKeyUtilities
|
||||
{
|
||||
internal static readonly Dictionary<KeyboardKey, LedId> KeyboardKeyLedIdMap = new()
|
||||
/// <summary>
|
||||
/// A dictionary of mappings between <see cref="KeyboardKey" /> and <see cref="LedId" />
|
||||
/// </summary>
|
||||
public static readonly Dictionary<KeyboardKey, LedId> KeyboardKeyLedIdMap = new()
|
||||
{
|
||||
{KeyboardKey.None, LedId.Keyboard_Custom1},
|
||||
{KeyboardKey.Cancel, LedId.Keyboard_Custom2},
|
||||
@@ -182,7 +188,10 @@ namespace Artemis.Core.Services
|
||||
{KeyboardKey.NumPadEnter, LedId.Keyboard_NumEnter}
|
||||
};
|
||||
|
||||
internal static readonly Dictionary<MouseButton, LedId> MouseButtonLedIdMap = new()
|
||||
/// <summary>
|
||||
/// A dictionary of mappings between <see cref="MouseButton" /> and <see cref="LedId" />
|
||||
/// </summary>
|
||||
public static readonly Dictionary<MouseButton, LedId> MouseButtonLedIdMap = new()
|
||||
{
|
||||
{MouseButton.Left, LedId.Mouse1},
|
||||
{MouseButton.Middle, LedId.Mouse2},
|
||||
|
||||
@@ -201,7 +201,7 @@ namespace Artemis.Core.Services
|
||||
bool foundLedId = InputKeyUtilities.KeyboardKeyLedIdMap.TryGetValue(e.Key, out LedId ledId);
|
||||
ArtemisLed? led = null;
|
||||
if (foundLedId && e.Device != null)
|
||||
led = e.Device.GetLed(ledId);
|
||||
led = e.Device.GetLed(ledId, true);
|
||||
|
||||
// Create the UpDown event args because it can be used for every event
|
||||
ArtemisKeyboardKeyUpDownEventArgs eventArgs = new(e.Device, led, e.Key, keyboardModifierKey, e.IsDown);
|
||||
|
||||
Reference in new issue
Block a user