(Feat) Add Remmaping
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Ashwild.Player
|
||||
{
|
||||
/// <summary>
|
||||
/// One rebindable entry: the action it targets, the binding index within that action, and the
|
||||
/// human label shown in the row. Composite parts (Move up/down/left/right) are four separate
|
||||
/// entries, each pointing at its own part-binding index.
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public struct RebindableEntry
|
||||
{
|
||||
[SerializeField] private string actionName;
|
||||
[SerializeField] private int bindingIndex;
|
||||
[SerializeField] private string displayLabel;
|
||||
|
||||
public string ActionName => actionName;
|
||||
public int BindingIndex => bindingIndex;
|
||||
public string DisplayLabel => displayLabel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// One glyph: the layout-aware display name it matches (case-insensitive) and its sprite.
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public struct KeyIcon
|
||||
{
|
||||
[SerializeField] private string displayName;
|
||||
[SerializeField] private Sprite icon;
|
||||
|
||||
public string DisplayName => displayName;
|
||||
public Sprite Icon => icon;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// One authored binding override: which binding of which action to re-path, and to what control
|
||||
/// path. Used only for deliberate letter-mnemonic exceptions per layout.
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public struct LayoutOverride
|
||||
{
|
||||
[SerializeField] private string actionName;
|
||||
[SerializeField] private int bindingIndex;
|
||||
[SerializeField] private string overridePath;
|
||||
|
||||
public string ActionName => actionName;
|
||||
public int BindingIndex => bindingIndex;
|
||||
public string OverridePath => overridePath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Single authored asset for everything the input UI needs: which bindings are rebindable (and
|
||||
/// their labels), the key glyphs to show instead of text, and the optional first-launch layout
|
||||
/// overrides per keyboard layout. One asset keeps all input configuration in one place — the
|
||||
/// settings panel reads the bindings/icons, the SettingsManager reads the layout overrides.
|
||||
/// Look is intentionally absent (mouse-only) and gamepad bindings are absent (keyboard only).
|
||||
/// </summary>
|
||||
[CreateAssetMenu(fileName = "InputConfig", menuName = "Input/Input Config")]
|
||||
public class InputConfig : ScriptableObject
|
||||
{
|
||||
#region Serialized Fields
|
||||
|
||||
[Header("Rebindable bindings (shown in the panel, in order)")]
|
||||
[SerializeField] private List<RebindableEntry> bindings = new List<RebindableEntry>();
|
||||
|
||||
[Header("Key glyphs (display name → sprite; missing falls back to text)")]
|
||||
[SerializeField] private List<KeyIcon> icons = new List<KeyIcon>();
|
||||
|
||||
[Header("First-launch layout overrides (usually empty — physical paths already fit)")]
|
||||
[SerializeField] private List<LayoutOverride> qwertyOverrides = new List<LayoutOverride>();
|
||||
[SerializeField] private List<LayoutOverride> azertyOverrides = new List<LayoutOverride>();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public API
|
||||
|
||||
public IReadOnlyList<RebindableEntry> Bindings => bindings;
|
||||
|
||||
/// <summary>
|
||||
/// Returns the glyph for a display name, or null when none is authored (caller shows text).
|
||||
/// </summary>
|
||||
public Sprite GetIcon(string displayName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(displayName)) return null;
|
||||
|
||||
foreach (KeyIcon entry in icons)
|
||||
if (string.Equals(entry.DisplayName, displayName, System.StringComparison.OrdinalIgnoreCase))
|
||||
return entry.Icon;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The first-launch overrides authored for a detected layout (usually empty).
|
||||
/// </summary>
|
||||
public IReadOnlyList<LayoutOverride> OverridesFor(KeyboardLayout layout) =>
|
||||
layout == KeyboardLayout.Azerty ? azertyOverrides : qwertyOverrides;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user