init vanilla keybinds after input manager init

This commit is contained in:
xChipseq committed 2025-09-08 19:38:07 +02:00
1 parent 6872ca6866
commit c41dd27f88
5 files changed
+52 -42

No files matched your search

+6 -1
View File
@@ -16,7 +16,7 @@ public class BaseKeybind
/// <summary> /// <summary>
/// Gets the unique identifier for this keybind. Used in Rewired. /// Gets the unique identifier for this keybind. Used in Rewired.
/// </summary> /// </summary>
public string Id { get; } public string Id { get; protected set; }
/// <summary> /// <summary>
/// Gets the currently assigned keycode. /// Gets the currently assigned keycode.
@@ -38,6 +38,11 @@ public class BaseKeybind
Handler = () => { }; Handler = () => { };
} }
public BaseKeybind()
{
Handler = () => { };
}
/// <summary> /// <summary>
/// Triggers the keybind, invoking its handler. /// Triggers the keybind, invoking its handler.
/// </summary> /// </summary>
+2 -7
View File
@@ -16,7 +16,8 @@ public static class KeybindManager
/// Gets a list of all registered keybinds. /// Gets a list of all registered keybinds.
/// </summary> /// </summary>
public static List<MiraKeybind> Keybinds { get; } = new(); public static List<MiraKeybind> Keybinds { get; } = new();
internal static Dictionary<Type, VanillaKeybind> VanillaKeybinds { get; } = new();
internal static Dictionary<Type, VanillaKeybind> VanillaKeybinds { get; set; }
internal static void RewiredInit() internal static void RewiredInit()
{ {
@@ -92,10 +93,4 @@ public static class KeybindManager
return all.ToArray(); return all.ToArray();
} }
internal static void RegisterVanillaKeybind(ActionButton button, int id)
{
var keybind = new VanillaKeybind(button, KeybindUtils.GetInputActionById(id)!);
VanillaKeybinds.Add(button.GetType(), keybind);
}
} }
+5 -6
View File
@@ -10,16 +10,15 @@ public class VanillaKeybind : BaseKeybind
/// <summary> /// <summary>
/// Gets the <see cref="ActionButton"/> this keybind is binded to. /// Gets the <see cref="ActionButton"/> this keybind is binded to.
/// </summary> /// </summary>
public ActionButton? Button { get; } public ActionButton? Button { get; internal set; }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="VanillaKeybind"/> class. /// Initializes a new instance of the <see cref="VanillaKeybind"/> class.
/// </summary> /// </summary>
/// <param name="button">The keybind action button.</param> /// <param name="id">The keybind id.</param>
/// <param name="action">The rewired input action.</param> public VanillaKeybind(int id)
public VanillaKeybind(ActionButton button, InputAction action) : base(action.name)
{ {
Button = button; RewiredInputAction = KeybindUtils.GetInputActionById(id);
RewiredInputAction = action; Id = RewiredInputAction?.name;
} }
} }
+28 -28
View File
@@ -45,33 +45,6 @@ public static class HudManagerPatches
[HarmonyPatch(nameof(HudManager.Start))] [HarmonyPatch(nameof(HudManager.Start))]
public static void StartPostfix(HudManager __instance) public static void StartPostfix(HudManager __instance)
{ {
vanillaKeybindIcons = [];
var keybindIconPos = new Vector3(-0.4f, 0.4f, -9f);
var vanillaButtons = new Dictionary<GameObject, int>
{
{ __instance.KillButton.gameObject, 8 },
{ __instance.UseButton.gameObject, 6 },
{ __instance.ReportButton.gameObject, 7 },
{ __instance.ImpostorVentButton.gameObject, 50 },
{ __instance.SabotageButton.gameObject, 4 },
};
KeybindManager.VanillaKeybinds.Clear();
foreach (var kvp in vanillaButtons)
{
var buttonObj = kvp.Key;
var actionId = kvp.Value;
var key = KeybindUtils.GetKeycodeByActionId(actionId);
if (key == KeyboardKeyCode.None)
{
continue;
}
var icon = Helpers.CreateKeybindIcon(buttonObj, key, keybindIconPos);
vanillaKeybindIcons.Add(icon.transform.GetChild(0).GetComponent<TextMeshPro>(), actionId);
KeybindManager.RegisterVanillaKeybind(buttonObj.GetComponent<ActionButton>(), actionId);
}
if (Buttons == null) if (Buttons == null)
{ {
Buttons = __instance.transform.Find("Buttons"); Buttons = __instance.transform.Find("Buttons");
@@ -125,8 +98,35 @@ public static class HudManagerPatches
gridArrange.Start(); gridArrange.Start();
gridArrange.ArrangeChilds(); gridArrange.ArrangeChilds();
aspectPosition.AdjustPosition(); aspectPosition.AdjustPosition();
vanillaKeybindIcons = [];
var keybindIconPos = new Vector3(-0.4f, 0.4f, -9f);
var vanillaButtons = new Dictionary<GameObject, int>
{
{ __instance.KillButton.gameObject, 8 },
{ __instance.UseButton.gameObject, 6 },
{ __instance.ReportButton.gameObject, 7 },
{ __instance.ImpostorVentButton.gameObject, 50 },
{ __instance.SabotageButton.gameObject, 4 },
};
KeybindManager.VanillaKeybinds.Clear();
foreach (var kvp in vanillaButtons)
{
var buttonObj = kvp.Key;
var actionId = kvp.Value;
var key = KeybindUtils.GetKeycodeByActionId(actionId);
if (key == KeyboardKeyCode.None)
{
continue;
}
var icon = Helpers.CreateKeybindIcon(buttonObj, key, keybindIconPos);
vanillaKeybindIcons.Add(icon.transform.GetChild(0).GetComponent<TextMeshPro>(), actionId);
var comp = buttonObj.GetComponent<ActionButton>();
KeybindManager.VanillaKeybinds[comp.GetType()].Button = comp;
}
} }
/// <summary> /// <summary>
+11
View File
@@ -1,5 +1,6 @@
using HarmonyLib; using HarmonyLib;
using MiraAPI.Keybinds; using MiraAPI.Keybinds;
using MonoMod.Utils;
using Rewired; using Rewired;
namespace MiraAPI.Patches.Keybinds; namespace MiraAPI.Patches.Keybinds;
@@ -20,5 +21,15 @@ public static class KeybindMenuPatch
KeybindUtils.RewiredInputManager = __instance; KeybindUtils.RewiredInputManager = __instance;
KeybindManager.RewiredInit(); KeybindManager.RewiredInit();
_registered = true; _registered = true;
// Set these here right after input manager initializes
KeybindManager.VanillaKeybinds = new()
{
{ typeof(KillButton), new VanillaKeybind(8) },
{ typeof(UseButton), new VanillaKeybind(6) },
{ typeof(ReportButton), new VanillaKeybind(7) },
{ typeof(VentButton), new VanillaKeybind(50) },
{ typeof(SabotageButton), new VanillaKeybind(4) },
};
} }
} }