Skip to content

Commit

Permalink
Text input detection
Browse files Browse the repository at this point in the history
Added a check for text input boxes such as the dev console, signs, lockers etc.

The medkit hotkey will not be available when using said text input. Added by user request.
  • Loading branch information
DingoDjango committed Feb 15, 2019
1 parent e5596d8 commit 56e314a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
Binary file modified QMods/MedkitHotkey/MedkitHotkey.dll
Binary file not shown.
31 changes: 28 additions & 3 deletions Source/Entry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public static class Entry
{
public static KeyCode SelectedHotkey;

public static bool TextInputOpen;

public static void Initialize()
{
if (ConfigHandler.TryLoadConfig())
Expand Down Expand Up @@ -39,16 +41,39 @@ public static void InitializeHarmony()
HarmonyInstance.DEBUG = true;
#endif

/* uGUI_QuickSlots.Update checks game state and does all of the necessary null checks.
* This hotkey is only relevant when QuickSlots are relevant, so we check for input in the same method. */
// Update player text input mode (for signs, lockers, console, etc.)
MethodInfo inputGroupOnSelect = AccessTools.Method(typeof(uGUI_InputGroup), nameof(uGUI_InputGroup.OnSelect));
MethodInfo inputGroupOnDeselect = AccessTools.Method(typeof(uGUI_InputGroup), nameof(uGUI_InputGroup.OnDeselect));
MethodInfo inputGroupDeselect = AccessTools.Method(typeof(uGUI_InputGroup), nameof(uGUI_InputGroup.Deselect));

harmony.Patch(inputGroupOnSelect, null, new HarmonyMethod(typeof(Entry), nameof(Patch_uGUI_InputGroup_OnSelect)), null);
harmony.Patch(inputGroupOnDeselect, null, new HarmonyMethod(typeof(Entry), nameof(Patch_uGUI_InputGroup_OnDeselect)), null);
harmony.Patch(inputGroupDeselect, null, new HarmonyMethod(typeof(Entry), nameof(Patch_uGUI_InputGroup_Deselect)), null);

// Listen for First Aid Kit hotkey. Injected where QuickSlots are handled for convenience.
MethodInfo handleQuickSlotsInput = AccessTools.Method(typeof(uGUI_QuickSlots), "HandleInput");

harmony.Patch(handleQuickSlotsInput, null, new HarmonyMethod(typeof(Entry), nameof(Patch_uGUI_QuickSlots_ListenForMedkit)), null);
}

public static void Patch_uGUI_InputGroup_OnSelect()
{
TextInputOpen = true;
}

public static void Patch_uGUI_InputGroup_OnDeselect()
{
TextInputOpen = false;
}

public static void Patch_uGUI_InputGroup_Deselect()
{
TextInputOpen = false;
}

public static void Patch_uGUI_QuickSlots_ListenForMedkit()
{
if (!IntroVignette.isIntroActive && Player.main.GetCanItemBeUsed() && Input.GetKeyDown(SelectedHotkey))
if (!TextInputOpen && Input.GetKeyDown(SelectedHotkey) && !IntroVignette.isIntroActive && Player.main.GetCanItemBeUsed())
{
#if DEBUG
Debug.Log($"[MedkitHotkey] :: Pressed '{SelectedHotkey.ToString()}', looking for medkit.");
Expand Down
4 changes: 2 additions & 2 deletions Source/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyVersion("1.1.2.0")]
[assembly: AssemblyFileVersion("1.1.2.0")]

0 comments on commit 56e314a

Please sign in to comment.