Skip to content

Commit

Permalink
Merge pull request #23 from KlutzyBubbles/keybind-fixes
Browse files Browse the repository at this point in the history
Keybind and other fixes
  • Loading branch information
KlutzyBubbles committed Jan 29, 2024
2 parents 1b087a9 + 26583b6 commit f4bd9f2
Show file tree
Hide file tree
Showing 13 changed files with 216 additions and 89 deletions.
26 changes: 23 additions & 3 deletions BetterEmote/AssetScripts/CustomAnimationObjects.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using BetterEmote.Patches;
using BetterEmote.Utils;
using GameNetcodeStuff;
using System;
using UnityEngine;

namespace BetterEmote.AssetScripts
Expand Down Expand Up @@ -88,14 +89,33 @@ private void DisableEverything()
private void FindSign()
{
Plugin.Debug("FindSign()");
_sign = _player.transform.Find("ScavengerModel").Find("metarig").Find("Sign").GetComponent<MeshRenderer>();
_signText = _sign.transform.Find("Text").gameObject;
if (_sign == null && _player != null)
{
Plugin.Debug("Sign is null and player exists");
_sign = _player.transform.Find("ScavengerModel").Find("metarig").Find("Sign").GetComponent<MeshRenderer>();
}
if (_signText == null && _sign != null)
{
Plugin.Debug("Sign text is null and sign exists");
_signText = _sign.transform.Find("Text").gameObject;
}
}

private void FindLegs()
{
Plugin.Debug("FindLegs()");
_legs = _player.transform.Find("ScavengerModel").Find("LEGS").GetComponent<SkinnedMeshRenderer>();
if (_legs == null && _player != null)
{
Plugin.Debug("Legs are null and player exists");
try
{
_legs = _player.transform.Find("ScavengerModel").Find("LEGS").GetComponent<SkinnedMeshRenderer>();
}
catch (Exception e)
{
Plugin.StaticLogger.LogWarning("Unable to find custom legs, this should be corrected soon.");
}
}
}
}
}
10 changes: 5 additions & 5 deletions BetterEmote/AssetScripts/EmoteWheel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal class EmoteWheel : MonoBehaviour
public Vector2 controllerValue = Vector2.zero;

public static string[] emoteNames;
public static string[] emoteKeybinds;
public static InputBind[] emoteKeybinds;

private Vector2 centerScreen;

Expand All @@ -60,10 +60,10 @@ private void Awake()
private void OnEnable()
{
Plugin.Debug("EmoteWheel.OnEnable()");
emoteKeybinds = new string[EmoteDefs.getEmoteCount() + 1];
emoteKeybinds = new InputBind[EmoteDefs.getEmoteCount() + 1];
foreach (string name in Enum.GetNames(typeof(Emote)))
{
emoteKeybinds[EmoteDefs.getEmoteNumber(name) - 1] = Settings.keybinds.getByEmote(EmoteDefs.getEmote(name)).GetBindingDisplayString(0, 0);
emoteKeybinds[EmoteDefs.getEmoteNumber(name) - 1] = Keybinds.getDisplayStrings(Settings.keybinds.getByEmote(EmoteDefs.getEmote(name)));
}
centerScreen = new Vector2(Screen.width / 2, Screen.height / 2);
Cursor.visible = true;
Expand Down Expand Up @@ -254,7 +254,7 @@ private void updatePageInfo()
private void displayEmoteInfo()
{
Plugin.Trace($"EmoteWheel.displayEmoteInfo({selectedEmoteID})");
string text = selectedEmoteID > emoteKeybinds.Length ? "" : emoteKeybinds[selectedEmoteID - 1];
InputBind bind = selectedEmoteID > emoteKeybinds.Length ? new InputBind("", "") : emoteKeybinds[selectedEmoteID - 1];
string text2;
if (selectedEmoteID <= Enum.GetValues(typeof(Emote)).Length)
{
Expand All @@ -267,7 +267,7 @@ private void displayEmoteInfo()
Plugin.Trace("selectedEmoteID out of range of emotes");
text2 = "EMPTY";
}
emoteInformation.text = $"{text2 ?? ""}\n[{(text ?? "").ToUpper()}]";
emoteInformation.text = $"{text2 ?? ""}\n{Keybinds.formatInputBind(bind)}";
}
private void updateSelectionArrow()
{
Expand Down
39 changes: 17 additions & 22 deletions BetterEmote/AssetScripts/SignUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class SignUI : MonoBehaviour
private TMP_InputField _inputField;

private Text _charactersLeftText;
private Text _submitText;
private Text _cancelText;

private TMP_Text _previewText;

Expand Down Expand Up @@ -49,9 +51,19 @@ private void OnEnable()
_inputField.Select();
_inputField.text = string.Empty;
_previewText.text = "PREVIEW";
updateKeybindText();
Player.disableLookInput = true;
}

public void updateKeybindText()
{
Plugin.Debug("SignUI.updateKeybindText()");
InputBind submit = Keybinds.getDisplayStrings(Settings.keybinds.SignSubmit);
InputBind cancel = Keybinds.getDisplayStrings(Settings.keybinds.SignCancel);
_submitText.text = $"<color=orange>{Keybinds.formatInputBind(submit)}</color> Submit";
_cancelText.text = $"<color=orange>{Keybinds.formatInputBind(cancel)}</color> Cancel";
}

private void Update()
{
Plugin.Trace("SignUI.Update()");
Expand All @@ -62,30 +74,11 @@ private void Update()
Plugin.Debug("SignUI Player isnt performing emote");
Close(true);
}
if (Keyboard.current[Key.Enter].wasPressedThisFrame && !Keyboard.current[Key.LeftShift].isPressed)
{
Plugin.Debug("Enter was pressed without shift");
SubmitText();
}
if (Player.quickMenuManager.isMenuOpen || EmoteKeybindPatch.emoteWheelIsOpened || Mouse.current["rightButton"].IsPressed(0f))
if (Player.quickMenuManager.isMenuOpen || EmoteKeybindPatch.emoteWheelIsOpened)
{
Plugin.Debug("Menu is open or right mouse button is clicked");
Close(true);
}
if (Gamepad.all.Count != 0)
{
Plugin.Trace("Has gamepad");
if (Gamepad.current.buttonWest.isPressed || Gamepad.current.startButton.isPressed)
{
Plugin.Debug("Button west or start button pressed");
SubmitText();
}
if (Gamepad.current.buttonEast.isPressed || Gamepad.current.selectButton.isPressed)
{
Plugin.Debug("Button east or select button pressed");
Close(true);
}
}
}

private void FindComponents()
Expand All @@ -96,6 +89,8 @@ private void FindComponents()
_submitButton = transform.Find("Submit").GetComponent<Button>();
_cancelButton = transform.Find("Cancel").GetComponent<Button>();
_previewText = transform.Find("Sign").transform.Find("Text").GetComponent<TMP_Text>();
_submitText = transform.Find("Submit").transform.Find("Text").GetComponent<Text>();
_cancelText = transform.Find("Cancel").transform.Find("Text").GetComponent<Text>();
}

private void UpdateCharactersLeftText()
Expand All @@ -110,7 +105,7 @@ private void UpdatePreviewText(string text)
_previewText.text = text;
}

private void SubmitText()
public void SubmitText()
{
Plugin.Debug("SignUI.SubmitText()");
if (_inputField.text.Equals(string.Empty))
Expand All @@ -131,7 +126,7 @@ private void SubmitText()
}
}

private void Close(bool cancelAction)
public void Close(bool cancelAction)
{
Plugin.Debug($"SignUI.Close({cancelAction})");
Player.isTypingChat = false;
Expand Down
6 changes: 3 additions & 3 deletions BetterEmote/AssetScripts/SyncAnimatorToOthers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ private void Start()

public void UpdateEmoteIDForOthers(int newID)
{
Plugin.Debug($"UpdateEmoteIDForOthers({newID})");
Plugin.Debug($"UpdateEmoteIDForOthers({newID}, {_player.IsOwner}, {_player.isPlayerControlled})");
if (_player.IsOwner && _player.isPlayerControlled)
{
UpdateCurrentEmoteIDServerRpc(newID);
Expand All @@ -31,8 +31,8 @@ private void UpdateCurrentEmoteIDServerRpc(int newID)
[ClientRpc]
private void UpdateCurrentEmoteIDClientRpc(int newID)
{
Plugin.Debug($"UpdateCurrentEmoteIDClientRpc({newID})");
if (!_player.IsOwner)
Plugin.Debug($"UpdateCurrentEmoteIDClientRpc({newID}, {_player.IsOwner}, {_player.isPlayerControlled})");
if (!_player.IsOwner || !_player.isPlayerControlled)
{
_player.playerBodyAnimator.SetInteger("emoteNumber", newID);
}
Expand Down
2 changes: 1 addition & 1 deletion BetterEmote/BetterEmote.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.1</TargetFramework>
<AssemblyName>BetterEmotes</AssemblyName>
<Description>Alters the integration method of more emotes</Description>
<Version>1.4.1</Version>
<Version>1.4.2</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
</PropertyGroup>
Expand Down
30 changes: 30 additions & 0 deletions BetterEmote/Patches/EmoteKeybindPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ private static void StartPostfix(PlayerControllerB __instance)
Settings.keybinds.Prisyadka.performed += onEmoteKeyPrisyadka;
Settings.keybinds.Sign.performed += onEmoteKeySign;
Settings.keybinds.Twerk.performed += onEmoteKeyTwerk;
Settings.keybinds.SignSubmit.performed += onSignKeySubmit;
Settings.keybinds.SignCancel.performed += onSignKeyCancel;
Settings.keybinds.EmoteWheel.started += onEmoteKeyWheelStarted;
Settings.keybinds.EmoteWheel.canceled += onEmoteKeyWheelCanceled;
Settings.keybinds.EmoteWheelNextPage.performed += onEmoteKeyWheelNext;
Expand All @@ -51,6 +53,8 @@ private static void StartPostfix(PlayerControllerB __instance)
Settings.keybinds.Prisyadka.Enable();
Settings.keybinds.Sign.Enable();
Settings.keybinds.Twerk.Enable();
Settings.keybinds.SignSubmit.Enable();
Settings.keybinds.SignCancel.Enable();
Settings.keybinds.EmoteWheel.Enable();
Settings.keybinds.EmoteWheelNextPage.Enable();
Settings.keybinds.EmoteWheelPreviousPage.Enable();
Expand All @@ -72,6 +76,8 @@ public static void OnDisablePostfix(PlayerControllerB __instance)
Settings.keybinds.Prisyadka.performed -= onEmoteKeyPrisyadka;
Settings.keybinds.Sign.performed -= onEmoteKeySign;
Settings.keybinds.Twerk.performed -= onEmoteKeyTwerk;
Settings.keybinds.SignSubmit.performed -= onSignKeySubmit;
Settings.keybinds.SignCancel.performed -= onSignKeyCancel;
Settings.keybinds.EmoteWheel.started -= onEmoteKeyWheelStarted;
Settings.keybinds.EmoteWheel.canceled -= onEmoteKeyWheelCanceled;
Settings.keybinds.EmoteWheelNextPage.performed -= onEmoteKeyWheelNext;
Expand All @@ -84,12 +90,36 @@ public static void OnDisablePostfix(PlayerControllerB __instance)
Settings.keybinds.Prisyadka.Disable();
Settings.keybinds.Sign.Disable();
Settings.keybinds.Twerk.Disable();
Settings.keybinds.SignSubmit.Disable();
Settings.keybinds.SignCancel.Disable();
Settings.keybinds.EmoteWheel.Disable();
Settings.keybinds.EmoteWheelNextPage.Disable();
Settings.keybinds.EmoteWheelPreviousPage.Disable();
}
}

public static void onSignKeySubmit(InputAction.CallbackContext context)
{
Plugin.Debug("onSignKeySubmit()");
if (Keyboard.current[Key.RightShift].isPressed || Keyboard.current[Key.LeftShift].isPressed)
{
Plugin.Debug("They have one of the shifts pressed");
return;
}
if (!Settings.disableSelfEmote && EmotePatch.customSignInputField != null && EmotePatch.customSignInputField.IsSignUIOpen)
{
EmotePatch.customSignInputField.SubmitText();
}
}

public static void onSignKeyCancel(InputAction.CallbackContext context)
{
Plugin.Debug("onSignKeyCancel()");
if (!Settings.disableSelfEmote && EmotePatch.customSignInputField != null && EmotePatch.customSignInputField.IsSignUIOpen)
{
EmotePatch.customSignInputField.Close(true);
}
}

public static void onEmoteKeyWheelStarted(InputAction.CallbackContext context)
{
Expand Down
6 changes: 3 additions & 3 deletions BetterEmote/Patches/EmotePatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -447,14 +447,14 @@ private static void postfixCheckConditions(ref bool __result, PlayerControllerB
[HarmonyPostfix]
private static void StopPerformingEmoteServerPrefix(PlayerControllerB __instance)
{
Plugin.Debug("prefixCheckConditions()");
Plugin.Debug("StopPerformingEmoteServerPrefix()");
if (__instance.IsOwner && __instance.isPlayerControlled)
{
__instance.playerBodyAnimator.SetInteger("emoteNumber", 0);
syncAnimator.UpdateEmoteIDForOthers(0);
currentEmoteID = 0;
}
TogglePlayerBadges(true);
syncAnimator.UpdateEmoteIDForOthers(0);
currentEmoteID = 0;
}
}
}

0 comments on commit f4bd9f2

Please sign in to comment.