add show keybinds setting

This commit is contained in:
xChipseq committed 2025-08-30 21:41:04 +02:00
1 parent 45291b0e98
commit 43d7f80660
4 files changed
+40 -14

No files matched your search

+4 -3
View File
@@ -6,7 +6,7 @@ using MiraAPI.Keybinds;
using MiraAPI.Patches; using MiraAPI.Patches;
using MiraAPI.Utilities; using MiraAPI.Utilities;
using MiraAPI.Utilities.Assets; using MiraAPI.Utilities.Assets;
using Rewired; using Reactor.Utilities;
using TMPro; using TMPro;
using UnityEngine; using UnityEngine;
using UnityEngine.Events; using UnityEngine.Events;
@@ -203,7 +203,7 @@ public abstract class CustomActionButton
} }
})); }));
if (Keybind != null && Keybind.CurrentKey != KeyboardKeyCode.None) if (Keybind != null)
{ {
Keybind.OnActivate(() => Keybind.OnActivate(() =>
{ {
@@ -490,7 +490,8 @@ public abstract class CustomActionButton
if (Keybind != null && KeybindText != null) if (Keybind != null && KeybindText != null)
{ {
KeybindText.text = Keybind.CurrentKey.ToString(); KeybindText.text = Keybind.CurrentKey.ToString();
KeybindIcon?.SetActive(ActiveInputManager.currentControlType == ActiveInputManager.InputType.Keyboard); KeybindIcon?.SetActive(ActiveInputManager.currentControlType == ActiveInputManager.InputType.Keyboard &&
PluginSingleton<MiraApiPlugin>.Instance.MiraConfig!.ShowKeybinds.Value);
} }
if (Timer >= 0) if (Timer >= 0)
+6 -10
View File
@@ -1,13 +1,4 @@
using BepInEx; using BepInEx.Configuration;
using BepInEx.Configuration;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using MiraAPI.PluginLoading;
using Reactor;
using Reactor.Networking;
using Reactor.Networking.Attributes;
using Reactor.Utilities;
using UnityEngine;
namespace MiraAPI; namespace MiraAPI;
@@ -20,4 +11,9 @@ public class MiraApiConfig(ConfigFile config)
/// Gets whether the modifiers hud should be on the left side of the screen (under roles/task tab). Recommended for streamers. /// Gets whether the modifiers hud should be on the left side of the screen (under roles/task tab). Recommended for streamers.
/// </summary> /// </summary>
public ConfigEntry<bool> ModifiersHudLeftSide { get; private set; } = config.Bind("Displays", "Show Modifiers HUD on Left Side", false); public ConfigEntry<bool> ModifiersHudLeftSide { get; private set; } = config.Bind("Displays", "Show Modifiers HUD on Left Side", false);
/// <summary>
/// Gets whether the keybind icons should be visible.
/// </summary>
public ConfigEntry<bool> ShowKeybinds { get; private set; } = config.Bind("Displays", "Show Keybinds on buttons", true);
} }
+2 -1
View File
@@ -163,7 +163,8 @@ public static class HudManagerPatches
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(ActiveInputManager.currentControlType == ActiveInputManager.InputType.Keyboard); btnIcon.Key.transform.parent.gameObject.SetActive(ActiveInputManager.currentControlType == ActiveInputManager.InputType.Keyboard &&
PluginSingleton<MiraApiPlugin>.Instance.MiraConfig!.ShowKeybinds.Value);
} }
foreach (var entry in KeybindManager.Keybinds) foreach (var entry in KeybindManager.Keybinds)
@@ -1,8 +1,12 @@
using System.Linq; using System.Linq;
using HarmonyLib; using HarmonyLib;
using MiraAPI.Keybinds; using MiraAPI.Keybinds;
using Reactor.Utilities;
using Reactor.Utilities.Extensions;
using Rewired.UI.ControlMapper; using Rewired.UI.ControlMapper;
using TMPro;
using UnityEngine; using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI; using UnityEngine.UI;
namespace MiraAPI.Patches.Keybinds; namespace MiraAPI.Patches.Keybinds;
@@ -10,6 +14,30 @@ namespace MiraAPI.Patches.Keybinds;
[HarmonyPatch(typeof(ControlMapper))] [HarmonyPatch(typeof(ControlMapper))]
public static class ControlMapperPatches public static class ControlMapperPatches
{ {
[HarmonyPrefix]
[HarmonyPatch(nameof(ControlMapper.Start))]
private static void StartPrefix(ControlMapper __instance)
{
var doneButton = GameObject.Find("DoneButton")?.GetComponent<CustomButton>();
if (doneButton == null)
{
return;
}
var toggle = Object.Instantiate(doneButton, doneButton.transform.parent);
var text = toggle.GetComponentInChildren<TextMeshProUGUI>();
var entry = PluginSingleton<MiraApiPlugin>.Instance!.MiraConfig!.ShowKeybinds;
toggle.gameObject.name = "KeybindsVisibleToggle";
text.text = $"Show Keybinds: {(entry.Value ? "On" : "Off")}";
toggle.onClick.RemoveAllListeners();
toggle.GetComponent<ButtonInfo>().identifier = "KeybindsVisibleToggle";
toggle.onClick.AddListener((UnityAction)(() =>
{
entry.Value = !entry.Value;
text.text = $"Show Keybinds: {(entry.Value ? "On" : "Off")}";
}));
}
[HarmonyPrefix] [HarmonyPrefix]
[HarmonyPatch(nameof(ControlMapper.Update))] [HarmonyPatch(nameof(ControlMapper.Update))]
private static void UpdatePrefix(ControlMapper __instance) private static void UpdatePrefix(ControlMapper __instance)