diff --git a/MiraAPI.Example/Buttons/Freezer/FreezeButton.cs b/MiraAPI.Example/Buttons/Freezer/FreezeButton.cs index 630bc96..4edd4f8 100644 --- a/MiraAPI.Example/Buttons/Freezer/FreezeButton.cs +++ b/MiraAPI.Example/Buttons/Freezer/FreezeButton.cs @@ -21,6 +21,7 @@ public class FreezeButton : CustomActionButton public override LoadableAsset Sprite => ExampleAssets.ExampleButton; public override KeyboardKeyCode Defaultkeybind => KeyboardKeyCode.T; + public override ModifierKey Modifier1 => ModifierKey.Control; protected override void OnClick() { diff --git a/MiraAPI.Example/Buttons/MeetingButton.cs b/MiraAPI.Example/Buttons/MeetingButton.cs index d97793f..c0acc20 100644 --- a/MiraAPI.Example/Buttons/MeetingButton.cs +++ b/MiraAPI.Example/Buttons/MeetingButton.cs @@ -17,6 +17,8 @@ public class MeetingButton : CustomActionButton public override LoadableAsset Sprite => ExampleAssets.ExampleButton; public override KeyboardKeyCode Defaultkeybind => KeyboardKeyCode.P; + public override ModifierKey Modifier1 => ModifierKey.Control; + public override ModifierKey Modifier2 => ModifierKey.Shift; public override bool Enabled(RoleBehaviour? role) { diff --git a/MiraAPI/Hud/CustomActionButton.cs b/MiraAPI/Hud/CustomActionButton.cs index 0eebb1b..ac48c4a 100644 --- a/MiraAPI/Hud/CustomActionButton.cs +++ b/MiraAPI/Hud/CustomActionButton.cs @@ -58,6 +58,23 @@ public abstract class CustomActionButton /// public abstract KeyboardKeyCode Defaultkeybind { get; } + /// + /// The first optional modifier key (e.g., Control, Shift, Alt) that must be held with the main key to activate the button. + /// + public virtual ModifierKey Modifier1 => ModifierKey.None; + + /// + /// The second optional modifier key. + /// Set to if unused. + /// + public virtual ModifierKey Modifier2 => ModifierKey.None; + + /// + /// The third optional modifier key. + /// Set to if unused. + /// + public virtual ModifierKey Modifier3 => ModifierKey.None; + /// /// Gets the button's text outline color. /// diff --git a/MiraAPI/Keybinds/KeybindManager.cs b/MiraAPI/Keybinds/KeybindManager.cs index 1d61890..3f95f4f 100644 --- a/MiraAPI/Keybinds/KeybindManager.cs +++ b/MiraAPI/Keybinds/KeybindManager.cs @@ -34,6 +34,21 @@ namespace MiraAPI.Keybinds /// If true, this keybind will be checked for conflicts with other exclusive keybinds using the same key. /// public bool Exclusive; + + /// + /// The first optional modifier key (e.g., Control, Shift, Alt) that must be held with the main key. + /// + public ModifierKey Modifier1 = ModifierKey.None; + + /// + /// The second optional modifier key, if needed. Set to ModifierKey.None if unused. + /// + public ModifierKey Modifier2 = ModifierKey.None; + + /// + /// The third optional modifier key, if needed. Set to ModifierKey.None if unused. + /// + public ModifierKey Modifier3 = ModifierKey.None; } private static readonly List Registered = new(); @@ -46,8 +61,11 @@ namespace MiraAPI.Keybinds /// Default key to use if no rebind exists. /// Method to invoke when the keybind is pressed. /// If true, conflicts with other exclusive keybinds on the same key. + /// Optional first modifier key (e.g., Control, Shift, Alt) that must be held with the main key. + /// Optional second modifier key. Use ModifierKey.None if unused. + /// Optional third modifier key. Use ModifierKey.None if unused. /// Returns the key that was registered for this keybind. - public static KeyboardKeyCode Register(string id, string description, KeyboardKeyCode key, Action handler, bool exclusive = true) + public static KeyboardKeyCode Register(string id, string description, KeyboardKeyCode key, Action handler, bool exclusive = true, ModifierKey modifier1 = ModifierKey.None, ModifierKey modifier2 = ModifierKey.None, ModifierKey modifier3 = ModifierKey.None) { Registered.Add(new KeybindEntry { @@ -56,6 +74,9 @@ namespace MiraAPI.Keybinds Key = key, Handler = handler, Exclusive = exclusive, + Modifier1 = modifier1, + Modifier2 = modifier2, + Modifier3 = modifier3, }); return key; diff --git a/MiraAPI/Patches/HudManagerPatches.cs b/MiraAPI/Patches/HudManagerPatches.cs index 57d4d32..acb4482 100644 --- a/MiraAPI/Patches/HudManagerPatches.cs +++ b/MiraAPI/Patches/HudManagerPatches.cs @@ -138,8 +138,12 @@ public static class HudManagerPatches foreach (var entry in KeybindManager.GetEntries()) { var player = ReInput.players.GetPlayer(0); + var keyboard = player.controllers.Keyboard; - if (player.GetButtonDown(entry.Id)) + if (player.GetButtonDown(entry.Id) && + (entry.Modifier1 == ModifierKey.None || keyboard.GetModifierKey(entry.Modifier1)) && + (entry.Modifier2 == ModifierKey.None || keyboard.GetModifierKey(entry.Modifier2)) && + (entry.Modifier3 == ModifierKey.None || keyboard.GetModifierKey(entry.Modifier3))) { entry.Handler?.Invoke(); } diff --git a/MiraAPI/Patches/Keybinds/KeybindsPatch.cs b/MiraAPI/Patches/Keybinds/KeybindsPatch.cs index c79f9a3..e609086 100644 --- a/MiraAPI/Patches/Keybinds/KeybindsPatch.cs +++ b/MiraAPI/Patches/Keybinds/KeybindsPatch.cs @@ -13,7 +13,7 @@ namespace MiraAPI.Patches.Keybinds { foreach (var entry in KeybindManager.GetEntries()) { - __instance.userData.RegisterModBind(entry.Id, entry.Description, entry.Key); + __instance.userData.RegisterModBind(entry.Id, entry.Description, entry.Key, modifier1: entry.Modifier1, modifier2: entry.Modifier2, modifier3: entry.Modifier3); } } } diff --git a/MiraAPI/PluginLoading/MiraPluginManager.cs b/MiraAPI/PluginLoading/MiraPluginManager.cs index 4896efe..b845dfb 100644 --- a/MiraAPI/PluginLoading/MiraPluginManager.cs +++ b/MiraAPI/PluginLoading/MiraPluginManager.cs @@ -137,8 +137,7 @@ public sealed class MiraPluginManager foreach (var button in CustomButtonManager.Buttons) { - - KeybindManager.Register($"{button.Name}_Keybind", $"Keybind for {button.Name}", button.Defaultkeybind, button.ClickHandler); + KeybindManager.Register($"{button.Name}_Keybind", $"Keybind for {button.Name}", button.Defaultkeybind, button.ClickHandler, modifier1: button.Modifier1, modifier2: button.Modifier2, modifier3: button.Modifier3); Logger.Info($"Registered keybind for button '{button.GetType().Name}' with default key {button.Defaultkeybind}."); } diff --git a/MiraAPI/Utilities/Extensions.cs b/MiraAPI/Utilities/Extensions.cs index 8a8ee8c..005057a 100644 --- a/MiraAPI/Utilities/Extensions.cs +++ b/MiraAPI/Utilities/Extensions.cs @@ -559,8 +559,11 @@ public static class Extensions /// Category ID to group actions in Rewired (default is 0). /// The element identifier ID (default is -1, meaning none specified). /// The for this action (default is Button). + /// The first optional modifier key (e.g., Control, Shift, Alt) that must be held together with the main key. + /// The second optional modifier key. Set to if not used. + /// The third optional modifier key. Set to if not used. /// The action ID of the newly registered action. - public static int RegisterModBind(this UserData userData, string actionName, string description, KeyboardKeyCode key, int category = 0, int elementIdentifierId = -1, InputActionType type = InputActionType.Button) + public static int RegisterModBind(this UserData userData, string actionName, string description, KeyboardKeyCode key, int category = 0, int elementIdentifierId = -1, InputActionType type = InputActionType.Button, ModifierKey modifier1 = ModifierKey.None, ModifierKey modifier2 = ModifierKey.None, ModifierKey modifier3 = ModifierKey.None) { userData.AddAction(category); @@ -579,9 +582,9 @@ public static class Extensions _elementType = ControllerElementType.Button, _axisContribution = Pole.Positive, _keyboardKeyCode = key, - _modifierKey1 = ModifierKey.None, - _modifierKey2 = ModifierKey.None, - _modifierKey3 = ModifierKey.None, + _modifierKey1 = modifier1, + _modifierKey2 = modifier2, + _modifierKey3 = modifier3, }; userData.keyboardMaps[0].actionElementMaps.Add(map); userData.joystickMaps[0].actionElementMaps.Add(map);