mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-19 15:51:48 +00:00
init vanilla keybinds after input manager init
This commit is contained in:
1 parent
6872ca6866
commit
c41dd27f88
5 files changed
+52
-42
No files matched your search
@@ -16,7 +16,7 @@ public class BaseKeybind
|
||||
/// <summary>
|
||||
/// Gets the unique identifier for this keybind. Used in Rewired.
|
||||
/// </summary>
|
||||
public string Id { get; }
|
||||
public string Id { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the currently assigned keycode.
|
||||
@@ -38,6 +38,11 @@ public class BaseKeybind
|
||||
Handler = () => { };
|
||||
}
|
||||
|
||||
public BaseKeybind()
|
||||
{
|
||||
Handler = () => { };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Triggers the keybind, invoking its handler.
|
||||
/// </summary>
|
||||
|
||||
@@ -16,7 +16,8 @@ public static class KeybindManager
|
||||
/// Gets a list of all registered keybinds.
|
||||
/// </summary>
|
||||
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()
|
||||
{
|
||||
@@ -92,10 +93,4 @@ public static class KeybindManager
|
||||
|
||||
return all.ToArray();
|
||||
}
|
||||
|
||||
internal static void RegisterVanillaKeybind(ActionButton button, int id)
|
||||
{
|
||||
var keybind = new VanillaKeybind(button, KeybindUtils.GetInputActionById(id)!);
|
||||
VanillaKeybinds.Add(button.GetType(), keybind);
|
||||
}
|
||||
}
|
||||
@@ -10,16 +10,15 @@ public class VanillaKeybind : BaseKeybind
|
||||
/// <summary>
|
||||
/// Gets the <see cref="ActionButton"/> this keybind is binded to.
|
||||
/// </summary>
|
||||
public ActionButton? Button { get; }
|
||||
public ActionButton? Button { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="VanillaKeybind"/> class.
|
||||
/// </summary>
|
||||
/// <param name="button">The keybind action button.</param>
|
||||
/// <param name="action">The rewired input action.</param>
|
||||
public VanillaKeybind(ActionButton button, InputAction action) : base(action.name)
|
||||
/// <param name="id">The keybind id.</param>
|
||||
public VanillaKeybind(int id)
|
||||
{
|
||||
Button = button;
|
||||
RewiredInputAction = action;
|
||||
RewiredInputAction = KeybindUtils.GetInputActionById(id);
|
||||
Id = RewiredInputAction?.name;
|
||||
}
|
||||
}
|
||||
@@ -45,33 +45,6 @@ public static class HudManagerPatches
|
||||
[HarmonyPatch(nameof(HudManager.Start))]
|
||||
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)
|
||||
{
|
||||
Buttons = __instance.transform.Find("Buttons");
|
||||
@@ -125,8 +98,35 @@ public static class HudManagerPatches
|
||||
|
||||
gridArrange.Start();
|
||||
gridArrange.ArrangeChilds();
|
||||
|
||||
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>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Keybinds;
|
||||
using MonoMod.Utils;
|
||||
using Rewired;
|
||||
|
||||
namespace MiraAPI.Patches.Keybinds;
|
||||
@@ -20,5 +21,15 @@ public static class KeybindMenuPatch
|
||||
KeybindUtils.RewiredInputManager = __instance;
|
||||
KeybindManager.RewiredInit();
|
||||
_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) },
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user