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)
{ {
TitleMenuPatch.Cleanup(); case TitleMenu:
} TitleMenuPatch.Cleanup();
else if (menu is CoopMenu) break;
{ case CoopMenu:
CoopMenuPatch.Cleanup(); CoopMenuPatch.Cleanup();
} break;
else if (menu is LoadGameMenu) case LoadGameMenu:
{ LoadGameMenuPatch.Cleanup();
LoadGameMenuPatch.Cleanup(); break;
} case AdvancedGameOptions:
else if (menu is AdvancedGameOptions) AdvancedGameOptionsPatch.Cleanup();
{ break;
AdvancedGameOptionsPatch.Cleanup(); case LetterViewerMenu:
} LetterViwerMenuPatch.Cleanup();
else if (menu is LetterViewerMenu) break;
{ case LevelUpMenu:
LetterViwerMenuPatch.Cleanup(); LevelUpMenuPatch.Cleanup();
} break;
else if (menu is LevelUpMenu) case Billboard:
{ BillboardPatch.Cleanup();
LevelUpMenuPatch.Cleanup(); break;
} case GameMenu:
else if (menu is Billboard) GameMenuPatch.Cleanup();
{ ExitPagePatch.Cleanup();
BillboardPatch.Cleanup(); OptionsPagePatch.Cleanup();
} SocialPagePatch.Cleanup();
else if (menu is GameMenu) InventoryPagePatch.Cleanup();
{ CraftingPagePatch.Cleanup();
GameMenuPatch.Cleanup(); break;
ExitPagePatch.Cleanup(); case JunimoNoteMenu:
OptionsPagePatch.Cleanup(); JunimoNoteMenuPatch.Cleanup();
SocialPagePatch.Cleanup(); break;
InventoryPagePatch.Cleanup(); case ShopMenu:
CraftingPagePatch.Cleanup(); ShopMenuPatch.Cleanup();
} break;
else if (menu is JunimoNoteMenu) case ItemGrabMenu:
{ ItemGrabMenuPatch.Cleanup();
JunimoNoteMenuPatch.Cleanup(); break;
} case GeodeMenu:
else if (menu is ShopMenu) GeodeMenuPatch.Cleanup();
{ break;
ShopMenuPatch.Cleanup(); case CarpenterMenu:
} CarpenterMenuPatch.Cleanup();
else if (menu is ItemGrabMenu) break;
{ case PurchaseAnimalsMenu:
ItemGrabMenuPatch.Cleanup(); PurchaseAnimalsMenuPatch.Cleanup();
} break;
else if (menu is GeodeMenu) case AnimalQueryMenu:
{ AnimalQueryMenuPatch.Cleanup();
GeodeMenuPatch.Cleanup(); break;
} case DialogueBox:
else if (menu is CarpenterMenu) DialogueBoxPatch.Cleanup();
{ break;
CarpenterMenuPatch.Cleanup(); case JojaCDMenu:
} JojaCDMenuPatch.Cleanup();
else if (menu is PurchaseAnimalsMenu) break;
{ case QuestLog:
PurchaseAnimalsMenuPatch.Cleanup(); QuestLogPatch.Cleaup();
} break;
else if (menu is AnimalQueryMenu) case TailoringMenu:
{ TailoringMenuPatch.Cleanup();
AnimalQueryMenuPatch.Cleanup(); break;
} case ForgeMenu:
else if (menu is DialogueBox) ForgeMenuPatch.Cleanup();
{ break;
DialogueBoxPatch.Cleanup(); case ItemListMenu:
} ItemListMenuPatch.Cleanup();
else if (menu is JojaCDMenu) break;
{ case FieldOfficeMenu:
JojaCDMenuPatch.Cleanup(); FieldOfficeMenuPatch.Cleanup();
} break;
else if (menu is QuestLog) case MuseumMenu:
{ MuseumMenuPatch.Cleanup();
QuestLogPatch.Cleaup(); break;
} case PondQueryMenu:
else if (menu is TailoringMenu) PondQueryMenuPatch.Cleanup();
{ break;
TailoringMenuPatch.Cleanup(); case SpecialOrdersBoard:
} SpecialOrdersBoardPatch.Cleanup();
else if (menu is ForgeMenu) break;
{
ForgeMenuPatch.Cleanup();
}
else if (menu is ItemListMenu)
{
ItemListMenuPatch.Cleanup();
}
else if (menu is FieldOfficeMenu)
{
FieldOfficeMenuPatch.Cleanup();
}
else if (menu is MuseumMenu)
{
MuseumMenuPatch.Cleanup();
}
else if (menu is PondQueryMenu)
{
PondQueryMenuPatch.Cleanup();
}
else if (menu is GeodeMenu)
{
GeodeMenuPatch.Cleanup();
}
else if (menu is SpecialOrdersBoard)
{
SpecialOrdersBoardPatch.Cleanup();
} }
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 != "";
@ -13,7 +13,7 @@ namespace stardew_access.Patches
string uniqueIdentifier = $"{__instance.X}:{__instance.Y}:{__instance.Height}:{__instance.Width}"; string uniqueIdentifier = $"{__instance.X}:{__instance.Y}:{__instance.Height}:{__instance.Width}";
if (!__instance.Selected) if (!__instance.Selected)
{ {
if (activeTextBoxes.Contains(uniqueIdentifier)) activeTextBoxes = activeTextBoxes.Replace(uniqueIdentifier, ""); if (activeTextBoxes.Contains(uniqueIdentifier)) activeTextBoxes = activeTextBoxes.Replace(uniqueIdentifier, "");
return; return;
} }
@ -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

@ -66,7 +66,7 @@ namespace stardew_access.Patches
} }
if (purchaseAnimalMenuQuery == toSpeak) return; if (purchaseAnimalMenuQuery == toSpeak) return;
purchaseAnimalMenuQuery = toSpeak; purchaseAnimalMenuQuery = toSpeak;
if (firstTimeInNamingMenu) if (firstTimeInNamingMenu)
@ -98,21 +98,11 @@ namespace stardew_access.Patches
} }
if (purchaseAnimalMenuQuery == toSpeak) return; if (purchaseAnimalMenuQuery == toSpeak) return;
purchaseAnimalMenuQuery = toSpeak; purchaseAnimalMenuQuery = toSpeak;
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 = "";