From 92c6aede930687038f84b30209da3d8ca3151477 Mon Sep 17 00:00:00 2001 From: SabreML <57483089+SabreML@users.noreply.github.com> Date: Tue, 14 Mar 2023 15:18:22 +0000 Subject: [PATCH] Better map key handling --- SingleplayerCoopEmotes/modinfo.json | 2 +- src/SPCoopEmotesConfig.cs | 22 ++++++++++++-------- src/SingleplayerCoopEmotes.cs | 31 +++++++++++++++++------------ 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/SingleplayerCoopEmotes/modinfo.json b/SingleplayerCoopEmotes/modinfo.json index 39a452f..d69f07f 100644 --- a/SingleplayerCoopEmotes/modinfo.json +++ b/SingleplayerCoopEmotes/modinfo.json @@ -1,7 +1,7 @@ { "id": "sabreml.singleplayercoopemotes", "name": "Singleplayer Co-op Emotes", - "version": "1.2.0", + "version": "1.2.1", "target_game_version": "v1.9.06", "authors": "SabreML", "description": "Makes the Jolly Co-op emotes work in singleplayer!", diff --git a/src/SPCoopEmotesConfig.cs b/src/SPCoopEmotesConfig.cs index 393b515..39fddb6 100644 --- a/src/SPCoopEmotesConfig.cs +++ b/src/SPCoopEmotesConfig.cs @@ -41,23 +41,29 @@ public override void Initialize() // If the player is using the default map key then a double tap is required to start pointing, so this changes to reflect that. public override void Update() { - string newText; + string newLabelText; - // Default keybind. - if (keyBinder.value == PointInput.defaultValue) + if (!System.Enum.TryParse(keyBinder.value, out KeyCode currentKeybind)) { - newText = "Double tap and hold the Point button with a movement input to start pointing in a direction."; + // This shouldn't ever happen since it can only store `KeyCode`s. + return; } - // Custom keybind. + + // Using the map button. (Default behaviour) + if (SingleplayerCoopEmotes.KeybindIsMapKey(currentKeybind)) + { + newLabelText = "Double tap and hold the Point button with a movement input to start pointing in a direction."; + } + // Using a custom keybind. else { - newText = "Press and hold the Point button with a movement input to start pointing in a direction."; + newLabelText = "Press and hold the Point button with a movement input to start pointing in a direction."; } // Only go through the effort of updating it if the text has actually changed. - if (pointingLabel.text != newText) + if (pointingLabel.text != newLabelText) { - pointingLabel.text = newText; + pointingLabel.text = newLabelText; } } diff --git a/src/SingleplayerCoopEmotes.cs b/src/SingleplayerCoopEmotes.cs index 6deec56..a0d99b0 100644 --- a/src/SingleplayerCoopEmotes.cs +++ b/src/SingleplayerCoopEmotes.cs @@ -12,7 +12,7 @@ namespace SingleplayerCoopEmotes { - [BepInPlugin("sabreml.singleplayercoopemotes", "SingleplayerCoopEmotes", "1.2.0")] + [BepInPlugin("sabreml.singleplayercoopemotes", "SingleplayerCoopEmotes", "1.2.1")] public class SingleplayerCoopEmotes : BaseUnityPlugin { // The current mod version. @@ -87,20 +87,13 @@ private void JollyUpdateHK(On.Player.orig_JollyUpdate orig, Player self, bool eu // Updates `self.jollyButtonDown` based on the player's pointing keybind. // If the player is using the default keybind (the map button), this copies the standard Jolly Co-op behaviour of a double-tap and hold. // If not, then this just checks if the key is currently being held. - // - // (Taken mostly from the 'Jolly Rebind' mod.) - // (It's a lot simpler and easier to just copy some of the functionality over to this than to try and make them compatible.) private void UpdateJollyButton(Player self) { - Options.ControlSetup playerControls = RWCustom.Custom.rainWorld.options.controls[self.playerState.playerNumber]; - - // The map key. - KeyCode defaultKeybind = self.input[0].gamePad ? playerControls.GamePadMap : playerControls.KeyboardMap; - // The key which is set in the remix menu. (By default, the map key.) - KeyCode playerKeybind = SPCoopEmotesConfig.PointInput.Value; + // The key which is set in the remix menu. + KeyCode customKeybind = SPCoopEmotesConfig.PointInput.Value; - // If the player is using the default keybind, use the standard Jolly Co-op double-tap behaviour. - if (playerKeybind == defaultKeybind) + // If the player's keybind is the same as the map key, continue on to the standard double tap behaviour. + if (KeybindIsMapKey(customKeybind)) { if (!self.input[0].mp) // If the button isn't being held down at all. { @@ -118,13 +111,25 @@ private void UpdateJollyButton(Player self) } } } + // Otherwise check for their custom keybind. else { - self.jollyButtonDown = Input.GetKey(playerKeybind); + self.jollyButtonDown = Input.GetKey(customKeybind); } } + // Checks if `keybindToCheck` is the same as the player's map keybind. + public static bool KeybindIsMapKey(KeyCode keybindToCheck) + { + // The player's Rain World keybinds. (Always player 0 since it's a singleplayer mod) + Options.ControlSetup playerControls = RWCustom.Custom.rainWorld.options.controls[0]; + + // If the keybind is the same as the keyboard or controller map key. + return keybindToCheck == playerControls.KeyboardMap || keybindToCheck == playerControls.GamePadMap; + } + + // Restores the (most likely unintentional) functionality from the 1.5 version of // pointing with no movement input making your slugcat face towards the screen. // (Technically, making them face towards the hand rendered behind their body.)