From eaee78ae7d1b653737e47dd4be6dee8bd164e50b Mon Sep 17 00:00:00 2001 From: SabreML <57483089+SabreML@users.noreply.github.com> Date: Fri, 24 Feb 2023 14:28:26 +0000 Subject: [PATCH] Configurable pointing keybind Entirely stolen from https://github.com/SabreML/JollyRebind --- SingleplayerCoopEmotes.csproj | 5 ++ SingleplayerCoopEmotes/modinfo.json | 2 +- src/SPCoopEmotesConfig.cs | 78 +++++++++++++++++++++++++++++ src/SingleplayerCoopEmotes.cs | 63 ++++++++++++++++++----- 4 files changed, 134 insertions(+), 14 deletions(-) create mode 100644 src/SPCoopEmotesConfig.cs diff --git a/SingleplayerCoopEmotes.csproj b/SingleplayerCoopEmotes.csproj index 4e01e31..f3ef5a7 100644 --- a/SingleplayerCoopEmotes.csproj +++ b/SingleplayerCoopEmotes.csproj @@ -35,6 +35,7 @@ + @@ -70,6 +71,10 @@ ..\..\DLLs\UnityEngine.CoreModule.dll False + + ..\..\DLLs\Additional\UnityEngine.InputLegacyModule.dll + False + diff --git a/SingleplayerCoopEmotes/modinfo.json b/SingleplayerCoopEmotes/modinfo.json index a0b2c73..39a452f 100644 --- a/SingleplayerCoopEmotes/modinfo.json +++ b/SingleplayerCoopEmotes/modinfo.json @@ -1,7 +1,7 @@ { "id": "sabreml.singleplayercoopemotes", "name": "Singleplayer Co-op Emotes", - "version": "1.1.6", + "version": "1.2.0", "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 new file mode 100644 index 0000000..38721dc --- /dev/null +++ b/src/SPCoopEmotesConfig.cs @@ -0,0 +1,78 @@ +using Menu.Remix.MixedUI; +using UnityEngine; + +namespace SingleplayerCoopEmotes +{ + public class SPCoopEmotesConfig : OptionInterface + { + public static Configurable PointInput; + + public SPCoopEmotesConfig() + { + PointInput = config.Bind("PointInput", KeyCode.Space, new ConfigurableInfo("Input a button to change the pointing keybind. (Note: The map key requires a double-tap and hold)", tags: new object[] + { + "Point button keybind" + })); + } + + // Pretty much entirely taken from the music announcements config menu. + public override void Initialize() + { + base.Initialize(); + Tabs = new OpTab[] + { + new OpTab(this, "Options") + }; + + AddDivider(593f); + AddTitle(); + AddDivider(540f); + AddKeyBinder(); + } + + private void AddDivider(float y) + { + OpImage dividerLeft = new OpImage(new Vector2(300f, y), "LinearGradient200"); + dividerLeft.sprite.SetAnchor(0.5f, 0f); + dividerLeft.sprite.rotation = 270f; + + OpImage dividerRight = new OpImage(new Vector2(300f, y), "LinearGradient200"); + dividerRight.sprite.SetAnchor(0.5f, 0f); + dividerRight.sprite.rotation = 90f; + + Tabs[0].AddItems(new UIelement[] + { + dividerLeft, + dividerRight + }); + } + + private void AddTitle() + { + OpLabel title = new OpLabel(new Vector2(150f, 560f), new Vector2(300f, 30f), "Singleplayer Co-op Emotes", bigText: true); + OpLabel version = new OpLabel(new Vector2(150f, 540f), new Vector2(300f, 30f), $"Version {SingleplayerCoopEmotes.Version}"); + + Tabs[0].AddItems(new UIelement[] + { + title, + version + }); + } + + private void AddKeyBinder() + { + OpKeyBinder keyBinder = new OpKeyBinder(PointInput, new Vector2(240, 475f), new Vector2(120f, 50f), false) + { + description = PointInput.info.description + }; + + OpLabel keyBinderLabel = new OpLabel(new Vector2(150f, 450f), new Vector2(300f, 30f), PointInput.info.Tags[0] as string); + + Tabs[0].AddItems(new UIelement[] + { + keyBinder, + keyBinderLabel + }); + } + } +} diff --git a/src/SingleplayerCoopEmotes.cs b/src/SingleplayerCoopEmotes.cs index 55ad441..6deec56 100644 --- a/src/SingleplayerCoopEmotes.cs +++ b/src/SingleplayerCoopEmotes.cs @@ -12,11 +12,17 @@ namespace SingleplayerCoopEmotes { - [BepInPlugin("sabreml.singleplayercoopemotes", "SingleplayerCoopEmotes", "1.1.6")] + [BepInPlugin("sabreml.singleplayercoopemotes", "SingleplayerCoopEmotes", "1.2.0")] public class SingleplayerCoopEmotes : BaseUnityPlugin { + // The current mod version. + public static string Version; + public void OnEnable() { + // Take the version number that was given to `BepInPlugin()` above. + Version = Info.Metadata.Version.ToString(); + On.RainWorld.OnModsInit += Init; } @@ -52,6 +58,9 @@ private void Init(On.RainWorld.orig_OnModsInit orig, RainWorld self) typeof(Player).GetProperty("RevealMap", BindingFlags.Public | BindingFlags.Instance).GetGetMethod(), new ILContext.Manipulator(RemoveCoopAvailableChecks) ); + + // Set up the remix menu. + MachineConnector.SetRegisteredOI(Info.Metadata.GUID, new SPCoopEmotesConfig()); } @@ -67,24 +76,52 @@ private void JollyUpdateHK(On.Player.orig_JollyUpdate orig, Player self, bool eu // Sleeping emote things. self.JollyEmoteUpdate(); - // Update the jolly button. (Taken from `JollyInputUpdate()`) - if (!self.input[0].mp) // If the button isn't being held down at all. - { - self.jollyButtonDown = false; - } - else if (!self.input[1].mp) // If the button was down this frame, but not last frame. + // Update the jolly button. + UpdateJollyButton(self); + + // Pointing emote things. + self.JollyPointUpdate(); + } + + + // 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; + + // If the player is using the default keybind, use the standard Jolly Co-op double-tap behaviour. + if (playerKeybind == defaultKeybind) { - self.jollyButtonDown = false; - for (int i = 2; i < self.input.Length - 1; i++) + if (!self.input[0].mp) // If the button isn't being held down at all. + { + self.jollyButtonDown = false; + } + else if (!self.input[1].mp) // If the button was down this frame, but not last frame. { - if (self.input[i].mp && !self.input[i + 1].mp) // Look for a double tap. + self.jollyButtonDown = false; + for (int i = 2; i < self.input.Length - 1; i++) { - self.jollyButtonDown = true; + if (self.input[i].mp && !self.input[i + 1].mp) // Look for a double tap. + { + self.jollyButtonDown = true; + } } } } - // Pointing emote things. - self.JollyPointUpdate(); + else + { + self.jollyButtonDown = Input.GetKey(playerKeybind); + } }