Skip to content

Commit

Permalink
Configurable pointing keybind
Browse files Browse the repository at this point in the history
  • Loading branch information
SabreML committed Feb 24, 2023
1 parent 0df06c5 commit eaee78a
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 14 deletions.
5 changes: 5 additions & 0 deletions SingleplayerCoopEmotes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="src\SingleplayerCoopEmotes.cs" />
<Compile Include="src\SPCoopEmotesConfig.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -70,6 +71,10 @@
<HintPath>..\..\DLLs\UnityEngine.CoreModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.InputLegacyModule">
<HintPath>..\..\DLLs\Additional\UnityEngine.InputLegacyModule.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion SingleplayerCoopEmotes/modinfo.json
Original file line number Diff line number Diff line change
@@ -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!",
Expand Down
78 changes: 78 additions & 0 deletions src/SPCoopEmotesConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using Menu.Remix.MixedUI;
using UnityEngine;

namespace SingleplayerCoopEmotes
{
public class SPCoopEmotesConfig : OptionInterface
{
public static Configurable<KeyCode> 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
});
}
}
}
63 changes: 50 additions & 13 deletions src/SingleplayerCoopEmotes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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());
}


Expand All @@ -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);
}
}


Expand Down

0 comments on commit eaee78a

Please sign in to comment.