Fixed bug for TextBoxEntryMenu

master^2
Mohammad Shoaib Khan 2023-04-10 15:33:19 +05:30
parent be8b9a9e41
commit ca249644dd
No known key found for this signature in database
GPG Key ID: 4AD59D0913614FE6
7 changed files with 143 additions and 127 deletions

View File

@ -241,11 +241,6 @@ namespace stardew_access
prefix: new HarmonyMethod(typeof(PurchaseAnimalsMenuPatch), nameof(PurchaseAnimalsMenuPatch.DrawPatch)) prefix: new HarmonyMethod(typeof(PurchaseAnimalsMenuPatch), nameof(PurchaseAnimalsMenuPatch.DrawPatch))
); );
harmony.Patch(
original: AccessTools.Method(typeof(PurchaseAnimalsMenu), nameof(PurchaseAnimalsMenu.receiveKeyPress), new Type[] { typeof(Keys) }),
prefix: new HarmonyMethod(typeof(PurchaseAnimalsMenuPatch), nameof(PurchaseAnimalsMenuPatch.RecieveKeyPressPatch))
);
harmony.Patch( harmony.Patch(
original: AccessTools.Method(typeof(AnimalQueryMenu), nameof(AnimalQueryMenu.draw), new Type[] { typeof(SpriteBatch) }), original: AccessTools.Method(typeof(AnimalQueryMenu), nameof(AnimalQueryMenu.draw), new Type[] { typeof(SpriteBatch) }),
postfix: new HarmonyMethod(typeof(AnimalQueryMenuPatch), nameof(AnimalQueryMenuPatch.DrawPatch)) postfix: new HarmonyMethod(typeof(AnimalQueryMenuPatch), nameof(AnimalQueryMenuPatch.DrawPatch))
@ -296,6 +291,21 @@ namespace stardew_access
original: AccessTools.Method(typeof(TextBox), nameof(TextBox.Draw)), original: AccessTools.Method(typeof(TextBox), nameof(TextBox.Draw)),
prefix: new HarmonyMethod(typeof(TextBoxPatch), nameof(TextBoxPatch.DrawPatch)) prefix: new HarmonyMethod(typeof(TextBoxPatch), nameof(TextBoxPatch.DrawPatch))
); );
harmony.Patch(
original: AccessTools.Method(typeof(TextEntryMenu), nameof(TextEntryMenu.draw), new Type[] { typeof(SpriteBatch) }),
prefix: new HarmonyMethod(typeof(TextEntryMenuPatch), nameof(TextEntryMenuPatch.DrawPatch))
);
harmony.Patch(
original: AccessTools.Method(typeof(TextEntryMenu), nameof(TextEntryMenu.Close)),
prefix: new HarmonyMethod(typeof(TextEntryMenuPatch), nameof(TextEntryMenuPatch.ClosePatch))
);
harmony.Patch(
original: AccessTools.Method(typeof(Game1), nameof(Game1.closeTextEntry)),
prefix: new HarmonyMethod(typeof(Game1Patch), nameof(Game1Patch.CloseTextEntryPatch))
);
} }
} }
} }

View File

@ -13,7 +13,7 @@ namespace stardew_access
{ {
#region Global Vars & Properties #region Global Vars & Properties
#pragma warning disable CS8603 #pragma warning disable CS8603
private static int prevDate = -99; private static int prevDate = -99;
private static ModConfig? config; private static ModConfig? config;
private Harmony? harmony; private Harmony? harmony;
@ -129,10 +129,21 @@ namespace stardew_access
helper.Events.Input.ButtonPressed += this.OnButtonPressed; helper.Events.Input.ButtonPressed += this.OnButtonPressed;
helper.Events.GameLoop.UpdateTicked += this.onUpdateTicked; helper.Events.GameLoop.UpdateTicked += this.onUpdateTicked;
helper.Events.GameLoop.DayStarted += this.onDayStarted; helper.Events.GameLoop.DayStarted += this.onDayStarted;
helper.Events.Display.MenuChanged += this.onMenuChanged;
AppDomain.CurrentDomain.DomainUnload += OnExit; AppDomain.CurrentDomain.DomainUnload += OnExit;
AppDomain.CurrentDomain.ProcessExit += OnExit; AppDomain.CurrentDomain.ProcessExit += OnExit;
} }
private void onMenuChanged(object? sender, MenuChangedEventArgs e)
{
TextBoxPatch.activeTextBoxes = "";
if (e.OldMenu != null)
{
MainClass.DebugLog($"Switched from {e.OldMenu.GetType().ToString()} menu, performing cleanup...");
IClickableMenuPatch.Cleanup(e.OldMenu);
}
}
/// <summary>Returns the Screen Reader class for other mods to use.</summary> /// <summary>Returns the Screen Reader class for other mods to use.</summary>
public override object GetApi() public override object GetApi()
{ {

View File

@ -13,6 +13,7 @@ namespace stardew_access.Patches
{ {
try try
{ {
MainClass.DebugLog($"Closing {Game1.activeClickableMenu.GetType().ToString()} menu, performing cleanup...");
IClickableMenuPatch.Cleanup(Game1.activeClickableMenu); IClickableMenuPatch.Cleanup(Game1.activeClickableMenu);
} }
catch (Exception e) catch (Exception e)
@ -21,6 +22,11 @@ namespace stardew_access.Patches
} }
} }
internal static void CloseTextEntryPatch()
{
TextBoxPatch.activeTextBoxes = "";
}
internal static bool PlaySoundPatch(string cueName) internal static bool PlaySoundPatch(string cueName)
{ {
try try

View File

@ -199,6 +199,7 @@ namespace stardew_access.Patches
{ {
try try
{ {
MainClass.DebugLog($"Closed {__instance.GetType().ToString()} menu, performing cleanup...");
Cleanup(__instance); Cleanup(__instance);
} }
catch (Exception e) catch (Exception e)
@ -209,114 +210,88 @@ namespace stardew_access.Patches
internal static void Cleanup(IClickableMenu menu) internal static void Cleanup(IClickableMenu menu)
{ {
if (menu is TitleMenu) switch (menu)
{ {
case TitleMenu:
TitleMenuPatch.Cleanup(); TitleMenuPatch.Cleanup();
} break;
else if (menu is CoopMenu) case CoopMenu:
{
CoopMenuPatch.Cleanup(); CoopMenuPatch.Cleanup();
} break;
else if (menu is LoadGameMenu) case LoadGameMenu:
{
LoadGameMenuPatch.Cleanup(); LoadGameMenuPatch.Cleanup();
} break;
else if (menu is AdvancedGameOptions) case AdvancedGameOptions:
{
AdvancedGameOptionsPatch.Cleanup(); AdvancedGameOptionsPatch.Cleanup();
} break;
else if (menu is LetterViewerMenu) case LetterViewerMenu:
{
LetterViwerMenuPatch.Cleanup(); LetterViwerMenuPatch.Cleanup();
} break;
else if (menu is LevelUpMenu) case LevelUpMenu:
{
LevelUpMenuPatch.Cleanup(); LevelUpMenuPatch.Cleanup();
} break;
else if (menu is Billboard) case Billboard:
{
BillboardPatch.Cleanup(); BillboardPatch.Cleanup();
} break;
else if (menu is GameMenu) case GameMenu:
{
GameMenuPatch.Cleanup(); GameMenuPatch.Cleanup();
ExitPagePatch.Cleanup(); ExitPagePatch.Cleanup();
OptionsPagePatch.Cleanup(); OptionsPagePatch.Cleanup();
SocialPagePatch.Cleanup(); SocialPagePatch.Cleanup();
InventoryPagePatch.Cleanup(); InventoryPagePatch.Cleanup();
CraftingPagePatch.Cleanup(); CraftingPagePatch.Cleanup();
} break;
else if (menu is JunimoNoteMenu) case JunimoNoteMenu:
{
JunimoNoteMenuPatch.Cleanup(); JunimoNoteMenuPatch.Cleanup();
} break;
else if (menu is ShopMenu) case ShopMenu:
{
ShopMenuPatch.Cleanup(); ShopMenuPatch.Cleanup();
} break;
else if (menu is ItemGrabMenu) case ItemGrabMenu:
{
ItemGrabMenuPatch.Cleanup(); ItemGrabMenuPatch.Cleanup();
} break;
else if (menu is GeodeMenu) case GeodeMenu:
{
GeodeMenuPatch.Cleanup(); GeodeMenuPatch.Cleanup();
} break;
else if (menu is CarpenterMenu) case CarpenterMenu:
{
CarpenterMenuPatch.Cleanup(); CarpenterMenuPatch.Cleanup();
} break;
else if (menu is PurchaseAnimalsMenu) case PurchaseAnimalsMenu:
{
PurchaseAnimalsMenuPatch.Cleanup(); PurchaseAnimalsMenuPatch.Cleanup();
} break;
else if (menu is AnimalQueryMenu) case AnimalQueryMenu:
{
AnimalQueryMenuPatch.Cleanup(); AnimalQueryMenuPatch.Cleanup();
} break;
else if (menu is DialogueBox) case DialogueBox:
{
DialogueBoxPatch.Cleanup(); DialogueBoxPatch.Cleanup();
} break;
else if (menu is JojaCDMenu) case JojaCDMenu:
{
JojaCDMenuPatch.Cleanup(); JojaCDMenuPatch.Cleanup();
} break;
else if (menu is QuestLog) case QuestLog:
{
QuestLogPatch.Cleaup(); QuestLogPatch.Cleaup();
} break;
else if (menu is TailoringMenu) case TailoringMenu:
{
TailoringMenuPatch.Cleanup(); TailoringMenuPatch.Cleanup();
} break;
else if (menu is ForgeMenu) case ForgeMenu:
{
ForgeMenuPatch.Cleanup(); ForgeMenuPatch.Cleanup();
} break;
else if (menu is ItemListMenu) case ItemListMenu:
{
ItemListMenuPatch.Cleanup(); ItemListMenuPatch.Cleanup();
} break;
else if (menu is FieldOfficeMenu) case FieldOfficeMenu:
{
FieldOfficeMenuPatch.Cleanup(); FieldOfficeMenuPatch.Cleanup();
} break;
else if (menu is MuseumMenu) case MuseumMenu:
{
MuseumMenuPatch.Cleanup(); MuseumMenuPatch.Cleanup();
} break;
else if (menu is PondQueryMenu) case PondQueryMenu:
{
PondQueryMenuPatch.Cleanup(); PondQueryMenuPatch.Cleanup();
} break;
else if (menu is GeodeMenu) case SpecialOrdersBoard:
{
GeodeMenuPatch.Cleanup();
}
else if (menu is SpecialOrdersBoard)
{
SpecialOrdersBoardPatch.Cleanup(); SpecialOrdersBoardPatch.Cleanup();
break;
} }
InventoryUtils.Cleanup(); InventoryUtils.Cleanup();

View File

@ -2,7 +2,7 @@ namespace stardew_access.Patches
{ {
internal class TextBoxPatch internal class TextBoxPatch
{ {
internal static string textBoxQuery = " "; internal static string textBoxQuery = "";
internal static string activeTextBoxes = ""; internal static string activeTextBoxes = "";
internal static bool isAnyTextBoxActive => activeTextBoxes != ""; internal static bool isAnyTextBoxActive => activeTextBoxes != "";
@ -24,6 +24,7 @@ namespace stardew_access.Patches
if (isEscPressed) if (isEscPressed)
{ {
if (activeTextBoxes.Contains(uniqueIdentifier)) activeTextBoxes = activeTextBoxes.Replace(uniqueIdentifier, "");
__instance.Selected = false; __instance.Selected = false;
} }

View File

@ -0,0 +1,23 @@
namespace stardew_access.Patches
{
internal class TextEntryMenuPatch
{
internal static void DrawPatch(StardewValley.Menus.TextEntryMenu __instance, StardewValley.Menus.TextBox ____target)
{
try
{
TextBoxPatch.DrawPatch(____target);
}
catch (Exception e)
{
MainClass.ErrorLog($"An error occured in DrawPatch() in TextEntryPatch:\n{e.Message}\n{e.StackTrace}");
}
}
internal static void ClosePatch()
{
TextBoxPatch.activeTextBoxes = "";
}
}
}

View File

@ -103,16 +103,6 @@ namespace stardew_access.Patches
MainClass.ScreenReader.Say(toSpeak, true); MainClass.ScreenReader.Say(toSpeak, true);
} }
internal static bool RecieveKeyPressPatch(PurchaseAnimalsMenu __instance, Microsoft.Xna.Framework.Input.Keys key)
{
if (TextBoxPatch.isAnyTextBoxActive && Game1.options.doesInputListContain(Game1.options.menuButton, key) && __instance.readyToClose())
{
return false;
}
return true;
}
internal static void Cleanup() internal static void Cleanup()
{ {
purchaseAnimalMenuQuery = ""; purchaseAnimalMenuQuery = "";