Organised code for geode menu patch

master
Mohammad Shoaib Khan 2023-03-09 13:21:46 +05:30
parent 8970a2c441
commit 1346e90bf5
No known key found for this signature in database
GPG Key ID: D8040D966320B620
2 changed files with 61 additions and 69 deletions

View File

@ -5,7 +5,7 @@ namespace stardew_access.Patches
{
internal class GeodeMenuPatch
{
internal static string geodeMenuQueryKey = "";
private static string geodeMenuQueryKey = "";
internal static void DrawPatch(GeodeMenu __instance)
{
@ -13,9 +13,23 @@ namespace stardew_access.Patches
{
int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position
#region Narrate the treasure recieved on breaking the geode
if (__instance.geodeTreasure != null)
if (narrateRecievedTreasure(__instance)) return;
if (narrateHoveredButton(__instance, x, y)) return;
if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y))
geodeMenuQueryKey = "";
}
catch (Exception e)
{
MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}");
}
}
private static bool narrateRecievedTreasure(GeodeMenu __instance)
{
// Narrates the treasure recieved on breaking the geode
if (__instance.geodeTreasure == null) return false;
string name = __instance.geodeTreasure.DisplayName;
int stack = __instance.geodeTreasure.Stack;
@ -26,69 +40,43 @@ namespace stardew_access.Patches
geodeMenuQueryKey = toSpeak;
MainClass.ScreenReader.Say(toSpeak, true);
}
return;
return true;
}
#endregion
#region Narrate hovered buttons in the menu
private static bool narrateHoveredButton(GeodeMenu __instance, int x, int y)
{
string toSpeak = "";
bool isDropItemButton = false;
if (__instance.geodeSpot != null && __instance.geodeSpot.containsPoint(x, y))
{
string toSpeak = "Place geode here";
if (geodeMenuQueryKey != toSpeak)
toSpeak = "Place geode here";
}
else if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y))
{
toSpeak = "Drop item here";
isDropItemButton = true;
}
else if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y))
{
toSpeak = "Trash can";
}
else if (__instance.okButton != null && __instance.okButton.containsPoint(x, y))
{
toSpeak = "Ok button";
}
else
{
return false;
}
if (geodeMenuQueryKey == toSpeak) return true;
geodeMenuQueryKey = toSpeak;
MainClass.ScreenReader.Say(toSpeak, true);
}
return;
}
if (isDropItemButton) Game1.playSound("drop_item");
if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y))
{
string toSpeak = "Drop item here";
if (geodeMenuQueryKey != toSpeak)
{
geodeMenuQueryKey = toSpeak;
MainClass.ScreenReader.Say(toSpeak, true);
Game1.playSound("drop_item");
}
return;
}
if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y))
{
string toSpeak = "Trash can";
if (geodeMenuQueryKey != toSpeak)
{
geodeMenuQueryKey = toSpeak;
MainClass.ScreenReader.Say(toSpeak, true);
}
return;
}
if (__instance.okButton != null && __instance.okButton.containsPoint(x, y))
{
string toSpeak = "Ok button";
if (geodeMenuQueryKey != toSpeak)
{
geodeMenuQueryKey = toSpeak;
MainClass.ScreenReader.Say(toSpeak, true);
}
return;
}
#endregion
#region Narrate hovered item
if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y))
geodeMenuQueryKey = "";
#endregion
}
catch (Exception e)
{
MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}");
}
return true;
}
internal static void Cleanup()

View File

@ -309,6 +309,10 @@ namespace stardew_access.Patches
{
MenuPatches.pondQueryMenuQuery = " ";
}
else if (menu is GeodeMenu)
{
GeodeMenuPatch.Cleanup();
}
InventoryUtils.Cleanup();
TextBoxPatch.activeTextBoxes = "";