Used a different method to detect if any text box is active or not

This fixes the issue when more than one text boxes are present in a menu
master
Mohammad Shoaib Khan 2023-02-22 17:45:59 +05:30
parent cf0e46ecdd
commit 8059e09089
No known key found for this signature in database
GPG Key ID: D8040D966320B620
5 changed files with 12 additions and 10 deletions

View File

@ -30,8 +30,6 @@ namespace stardew_access
internal static ModConfig Config { get => config; set => config = value; } internal static ModConfig Config { get => config; set => config = value; }
public static IModHelper? ModHelper { get => modHelper; } public static IModHelper? ModHelper { get => modHelper; }
public static bool isAnyTextBoxActive = false;
public static StaticTiles STiles public static StaticTiles STiles
{ {
get get
@ -212,7 +210,7 @@ namespace stardew_access
return; return;
#region Simulate left and right clicks #region Simulate left and right clicks
if (Game1.activeClickableMenu != null && !isAnyTextBoxActive) if (Game1.activeClickableMenu != null && !TextBoxPatch.isAnyTextBoxActive)
{ {
bool isCustomizingCharacter = Game1.activeClickableMenu is CharacterCustomization || (TitleMenu.subMenu != null && TitleMenu.subMenu is CharacterCustomization); bool isCustomizingCharacter = Game1.activeClickableMenu is CharacterCustomization || (TitleMenu.subMenu != null && TitleMenu.subMenu is CharacterCustomization);
@ -229,7 +227,7 @@ namespace stardew_access
#endregion #endregion
} }
if (Game1.currentMinigame != null && !isAnyTextBoxActive) if (Game1.currentMinigame != null && !TextBoxPatch.isAnyTextBoxActive)
{ {
#region Mouse Click Simulation #region Mouse Click Simulation
if (Config.LeftClickMainKey.JustPressed() || Config.LeftClickAlternateKey.JustPressed()) if (Config.LeftClickMainKey.JustPressed() || Config.LeftClickAlternateKey.JustPressed())

View File

@ -27,7 +27,7 @@ namespace stardew_access.Patches
{ {
try try
{ {
if (MainClass.isAnyTextBoxActive) return; if (TextBoxPatch.isAnyTextBoxActive) return;
int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position
bool isPrimaryInfoKeyPressed = MainClass.Config.PrimaryInfoKey.JustPressed(); // For narrating animal details bool isPrimaryInfoKeyPressed = MainClass.Config.PrimaryInfoKey.JustPressed(); // For narrating animal details
@ -91,7 +91,7 @@ namespace stardew_access.Patches
{ {
try try
{ {
if (MainClass.isAnyTextBoxActive) return; if (TextBoxPatch.isAnyTextBoxActive) return;
int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position
purchaseAnimalsMenu = __instance; purchaseAnimalsMenu = __instance;

View File

@ -36,7 +36,7 @@ namespace stardew_access.Patches
{ {
try try
{ {
if (MainClass.isAnyTextBoxActive) return; if (TextBoxPatch.isAnyTextBoxActive) return;
bool isEscPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape); // For escaping/unselecting from the animal name text box bool isEscPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape); // For escaping/unselecting from the animal name text box
string toSpeak = ""; string toSpeak = "";

View File

@ -426,7 +426,7 @@ namespace stardew_access.Patches
___textBox.Selected = false; ___textBox.Selected = false;
} }
if (MainClass.isAnyTextBoxActive) return; if (TextBoxPatch.isAnyTextBoxActive) return;
string toSpeak = ""; string toSpeak = "";
int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position
@ -729,6 +729,7 @@ namespace stardew_access.Patches
InventoryUtils.hoveredItemQueryKey = ""; InventoryUtils.hoveredItemQueryKey = "";
InventoryUtils.prevSlotIndex = -999; InventoryUtils.prevSlotIndex = -999;
TextBoxPatch.activeTextBoxes = "";
} }
#endregion #endregion

View File

@ -3,18 +3,21 @@ namespace stardew_access.Patches
internal class TextBoxPatch internal class TextBoxPatch
{ {
internal static string textBoxQuery = " "; internal static string textBoxQuery = " ";
internal static string activeTextBoxes = "";
internal static bool isAnyTextBoxActive => activeTextBoxes != "";
internal static void DrawPatch(StardewValley.Menus.TextBox __instance) internal static void DrawPatch(StardewValley.Menus.TextBox __instance)
{ {
try try
{ {
string uniqueIdentifier = $"{__instance.X}:{__instance.Y}:{__instance.Height}:{__instance.Width}";
if (!__instance.Selected) if (!__instance.Selected)
{ {
MainClass.isAnyTextBoxActive = false; if (activeTextBoxes.Contains(uniqueIdentifier)) activeTextBoxes = activeTextBoxes.Replace(uniqueIdentifier, "");
return; return;
} }
MainClass.isAnyTextBoxActive = true; if (!activeTextBoxes.Contains(uniqueIdentifier)) activeTextBoxes += uniqueIdentifier;
bool isEscPressed = StardewValley.Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape); bool isEscPressed = StardewValley.Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape);
string toSpeak = __instance.Text; string toSpeak = __instance.Text;