diff --git a/MiraAPI/Hud/CustomActionButton.cs b/MiraAPI/Hud/CustomActionButton.cs index 8651fd1..dd84316 100644 --- a/MiraAPI/Hud/CustomActionButton.cs +++ b/MiraAPI/Hud/CustomActionButton.cs @@ -6,7 +6,7 @@ using MiraAPI.Keybinds; using MiraAPI.Patches; using MiraAPI.Utilities; using MiraAPI.Utilities.Assets; -using Rewired; +using Reactor.Utilities; using TMPro; using UnityEngine; using UnityEngine.Events; @@ -203,7 +203,7 @@ public abstract class CustomActionButton } })); - if (Keybind != null && Keybind.CurrentKey != KeyboardKeyCode.None) + if (Keybind != null) { Keybind.OnActivate(() => { @@ -490,7 +490,8 @@ public abstract class CustomActionButton if (Keybind != null && KeybindText != null) { KeybindText.text = Keybind.CurrentKey.ToString(); - KeybindIcon?.SetActive(ActiveInputManager.currentControlType == ActiveInputManager.InputType.Keyboard); + KeybindIcon?.SetActive(ActiveInputManager.currentControlType == ActiveInputManager.InputType.Keyboard && + PluginSingleton.Instance.MiraConfig!.ShowKeybinds.Value); } if (Timer >= 0) diff --git a/MiraAPI/MiraApiConfig.cs b/MiraAPI/MiraApiConfig.cs index 10c9776..3db12a9 100644 --- a/MiraAPI/MiraApiConfig.cs +++ b/MiraAPI/MiraApiConfig.cs @@ -1,13 +1,4 @@ -using BepInEx; -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; +using BepInEx.Configuration; 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. /// public ConfigEntry ModifiersHudLeftSide { get; private set; } = config.Bind("Displays", "Show Modifiers HUD on Left Side", false); + + /// + /// Gets whether the keybind icons should be visible. + /// + public ConfigEntry ShowKeybinds { get; private set; } = config.Bind("Displays", "Show Keybinds on buttons", true); } diff --git a/MiraAPI/Patches/HudManagerPatches.cs b/MiraAPI/Patches/HudManagerPatches.cs index 829556b..bfdcce5 100644 --- a/MiraAPI/Patches/HudManagerPatches.cs +++ b/MiraAPI/Patches/HudManagerPatches.cs @@ -163,7 +163,8 @@ public static class HudManagerPatches foreach (var btnIcon in vanillaKeybindIcons) { 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.Instance.MiraConfig!.ShowKeybinds.Value); } foreach (var entry in KeybindManager.Keybinds) diff --git a/MiraAPI/Patches/Keybinds/ControlMapperPatches.cs b/MiraAPI/Patches/Keybinds/ControlMapperPatches.cs index c08175b..4a5fe90 100644 --- a/MiraAPI/Patches/Keybinds/ControlMapperPatches.cs +++ b/MiraAPI/Patches/Keybinds/ControlMapperPatches.cs @@ -1,8 +1,12 @@ using System.Linq; using HarmonyLib; using MiraAPI.Keybinds; +using Reactor.Utilities; +using Reactor.Utilities.Extensions; using Rewired.UI.ControlMapper; +using TMPro; using UnityEngine; +using UnityEngine.Events; using UnityEngine.UI; namespace MiraAPI.Patches.Keybinds; @@ -10,6 +14,30 @@ namespace MiraAPI.Patches.Keybinds; [HarmonyPatch(typeof(ControlMapper))] public static class ControlMapperPatches { + [HarmonyPrefix] + [HarmonyPatch(nameof(ControlMapper.Start))] + private static void StartPrefix(ControlMapper __instance) + { + var doneButton = GameObject.Find("DoneButton")?.GetComponent(); + if (doneButton == null) + { + return; + } + + var toggle = Object.Instantiate(doneButton, doneButton.transform.parent); + var text = toggle.GetComponentInChildren(); + var entry = PluginSingleton.Instance!.MiraConfig!.ShowKeybinds; + toggle.gameObject.name = "KeybindsVisibleToggle"; + text.text = $"Show Keybinds: {(entry.Value ? "On" : "Off")}"; + toggle.onClick.RemoveAllListeners(); + toggle.GetComponent().identifier = "KeybindsVisibleToggle"; + toggle.onClick.AddListener((UnityAction)(() => + { + entry.Value = !entry.Value; + text.text = $"Show Keybinds: {(entry.Value ? "On" : "Off")}"; + })); + } + [HarmonyPrefix] [HarmonyPatch(nameof(ControlMapper.Update))] private static void UpdatePrefix(ControlMapper __instance)