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))
);
harmony.Patch(
original: AccessTools.Method(typeof(PurchaseAnimalsMenu), nameof(PurchaseAnimalsMenu.receiveKeyPress), new Type[] { typeof(Keys) }),
prefix: new HarmonyMethod(typeof(PurchaseAnimalsMenuPatch), nameof(PurchaseAnimalsMenuPatch.RecieveKeyPressPatch))
);
harmony.Patch(
original: AccessTools.Method(typeof(AnimalQueryMenu), nameof(AnimalQueryMenu.draw), new Type[] { typeof(SpriteBatch) }),
postfix: new HarmonyMethod(typeof(AnimalQueryMenuPatch), nameof(AnimalQueryMenuPatch.DrawPatch))
@ -296,6 +291,21 @@ namespace stardew_access
original: AccessTools.Method(typeof(TextBox), nameof(TextBox.Draw)),
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
#pragma warning disable CS8603
#pragma warning disable CS8603
private static int prevDate = -99;
private static ModConfig? config;
private Harmony? harmony;
@ -129,10 +129,21 @@ namespace stardew_access
helper.Events.Input.ButtonPressed += this.OnButtonPressed;
helper.Events.GameLoop.UpdateTicked += this.onUpdateTicked;
helper.Events.GameLoop.DayStarted += this.onDayStarted;
helper.Events.Display.MenuChanged += this.onMenuChanged;
AppDomain.CurrentDomain.DomainUnload += 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>
public override object GetApi()
{

View File

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

View File

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

View File

@ -2,7 +2,7 @@ namespace stardew_access.Patches
{
internal class TextBoxPatch
{
internal static string textBoxQuery = " ";
internal static string textBoxQuery = "";
internal static string activeTextBoxes = "";
internal static bool isAnyTextBoxActive => activeTextBoxes != "";
@ -13,7 +13,7 @@ namespace stardew_access.Patches
string uniqueIdentifier = $"{__instance.X}:{__instance.Y}:{__instance.Height}:{__instance.Width}";
if (!__instance.Selected)
{
if (activeTextBoxes.Contains(uniqueIdentifier)) activeTextBoxes = activeTextBoxes.Replace(uniqueIdentifier, "");
if (activeTextBoxes.Contains(uniqueIdentifier)) activeTextBoxes = activeTextBoxes.Replace(uniqueIdentifier, "");
return;
}
@ -24,6 +24,7 @@ namespace stardew_access.Patches
if (isEscPressed)
{
if (activeTextBoxes.Contains(uniqueIdentifier)) activeTextBoxes = activeTextBoxes.Replace(uniqueIdentifier, "");
__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;
purchaseAnimalMenuQuery = toSpeak;
if (firstTimeInNamingMenu)
@ -98,21 +98,11 @@ namespace stardew_access.Patches
}
if (purchaseAnimalMenuQuery == toSpeak) return;
purchaseAnimalMenuQuery = toSpeak;
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()
{
purchaseAnimalMenuQuery = "";