mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-20 01:46:15 +00:00
Reduce memory allocations in HudManagerPatches.cs
This commit is contained in:
1 parent
64ef78e3a2
commit
b3ed6d67f9
1 file changed
+30
-8
@@ -1,6 +1,5 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using MiraAPI.Hud;
|
using MiraAPI.Hud;
|
||||||
using MiraAPI.Keybinds;
|
using MiraAPI.Keybinds;
|
||||||
@@ -26,9 +25,9 @@ public static class HudManagerPatches
|
|||||||
public static Transform? BottomRight { get; private set; }
|
public static Transform? BottomRight { get; private set; }
|
||||||
public static Transform? Buttons { get; private set; }
|
public static Transform? Buttons { get; private set; }
|
||||||
|
|
||||||
private static Dictionary<TextMeshPro, int> vanillaKeybindIcons = new();
|
private static Dictionary<TextMeshPro, int> vanillaKeybindIcons = [];
|
||||||
|
|
||||||
internal static List<TextMeshPro> ModdedKeybindIcons = new();
|
internal static List<TextMeshPro> ModdedKeybindIcons = [];
|
||||||
|
|
||||||
public static IEnumerator CoResizeUI()
|
public static IEnumerator CoResizeUI()
|
||||||
{
|
{
|
||||||
@@ -272,31 +271,54 @@ public static class HudManagerPatches
|
|||||||
{
|
{
|
||||||
var canSeeBinds = ActiveInputManager.currentControlType == ActiveInputManager.InputType.Keyboard &&
|
var canSeeBinds = ActiveInputManager.currentControlType == ActiveInputManager.InputType.Keyboard &&
|
||||||
LocalSettingsTabSingleton<MiraApiSettings>.Instance.ShowKeybinds.Value;
|
LocalSettingsTabSingleton<MiraApiSettings>.Instance.ShowKeybinds.Value;
|
||||||
|
|
||||||
foreach (var btnIcon in vanillaKeybindIcons)
|
foreach (var btnIcon in vanillaKeybindIcons)
|
||||||
{
|
{
|
||||||
btnIcon.Key.text = KeybindUtils.GetKeycodeByActionId(btnIcon.Value).ToString();
|
btnIcon.Key.text = KeybindUtils.GetKeycodeByActionId(btnIcon.Value).ToString();
|
||||||
btnIcon.Key.transform.parent.gameObject.SetActive(canSeeBinds);
|
btnIcon.Key.transform.parent.gameObject.SetActive(canSeeBinds);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var btnIcon in ModdedKeybindIcons)
|
foreach (var btnIcon in ModdedKeybindIcons)
|
||||||
{
|
{
|
||||||
btnIcon.transform.parent.gameObject.SetActive(canSeeBinds);
|
btnIcon.transform.parent.gameObject.SetActive(canSeeBinds);
|
||||||
}
|
}
|
||||||
|
|
||||||
var player = ReInput.players.GetPlayer(0);
|
var player = ReInput.players.GetPlayer(0);
|
||||||
|
var keyboard = player.controllers.Keyboard;
|
||||||
foreach (var entry in KeybindManager.Keybinds)
|
foreach (var entry in KeybindManager.Keybinds)
|
||||||
{
|
{
|
||||||
var keyboard = player.controllers.Keyboard;
|
var modKeys = entry.ModifierKeys;
|
||||||
bool modifierKeysPressed = entry.ModifierKeys.All(k => keyboard.GetModifierKey(k)) ||
|
bool modifierKeysPressed;
|
||||||
entry.ModifierKeys.Length <= 0;
|
if (modKeys.Length == 0)
|
||||||
|
{
|
||||||
|
modifierKeysPressed = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
modifierKeysPressed = true;
|
||||||
|
foreach (var key in modKeys)
|
||||||
|
{
|
||||||
|
if (keyboard.GetModifierKey(key)) continue;
|
||||||
|
modifierKeysPressed = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (player.GetButtonDown(entry.Id) && modifierKeysPressed)
|
if (player.GetButtonDown(entry.Id) && modifierKeysPressed)
|
||||||
{
|
{
|
||||||
entry.Invoke();
|
entry.Invoke();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var entry in KeybindManager.VanillaKeybinds.Values.Where(x => player.GetButtonDown(x.Id)))
|
// suppressed warning because we want minimum allocations here
|
||||||
|
#pragma warning disable S3267
|
||||||
|
foreach (var entry in KeybindManager.VanillaKeybinds.Values)
|
||||||
|
#pragma warning restore S3267
|
||||||
{
|
{
|
||||||
entry.Invoke();
|
if (player.GetButtonDown(entry.Id))
|
||||||
|
{
|
||||||
|
entry.Invoke();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user