Organised code for item grab menu patch

master
Mohammad Shoaib Khan 2023-03-08 12:44:07 +05:30
parent 6822bd4840
commit 5195313a5b
No known key found for this signature in database
GPG Key ID: D8040D966320B620
2 changed files with 100 additions and 136 deletions

View File

@ -25,103 +25,76 @@ namespace stardew_access.Patches
__instance.inventory.inventory[0].snapMouseCursorToCenter(); __instance.inventory.inventory[0].snapMouseCursorToCenter();
} }
#region Narrate buttons in the menu if (narrateHoveredButton(__instance, x, y))
{
InventoryUtils.Cleanup();
return;
}
if (narrateLastShippedItem(__instance, x, y))
{
InventoryUtils.Cleanup();
return;
}
if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, true))
{
itemGrabMenuQueryKey = "";
return;
}
if (InventoryUtils.narrateHoveredSlot(__instance.ItemsToGrabMenu, __instance.ItemsToGrabMenu.inventory, __instance.ItemsToGrabMenu.actualInventory, x, y, true))
{
itemGrabMenuQueryKey = "";
return;
}
}
catch (Exception e)
{
MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}");
}
}
private static bool narrateHoveredButton(ItemGrabMenu __instance, int x, int y)
{
string toSpeak = "";
bool isDropItemButton = false;
if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) if (__instance.okButton != null && __instance.okButton.containsPoint(x, y))
{ {
string toSpeak = "Ok Button"; toSpeak = "Ok Button";
if (itemGrabMenuQueryKey != toSpeak)
{
itemGrabMenuQueryKey = toSpeak;
hoveredItemQueryKey = "";
MainClass.ScreenReader.Say(toSpeak, true);
} }
return; else if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y))
}
if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y))
{ {
string toSpeak = "Trash Can"; toSpeak = "Trash Can";
if (itemGrabMenuQueryKey != toSpeak)
{
itemGrabMenuQueryKey = toSpeak;
hoveredItemQueryKey = "";
MainClass.ScreenReader.Say(toSpeak, true);
} }
return; else if (__instance.organizeButton != null && __instance.organizeButton.containsPoint(x, y))
}
if (__instance.organizeButton != null && __instance.organizeButton.containsPoint(x, y))
{ {
string toSpeak = "Organize Button"; toSpeak = "Organize Button";
if (itemGrabMenuQueryKey != toSpeak)
{
itemGrabMenuQueryKey = toSpeak;
hoveredItemQueryKey = "";
MainClass.ScreenReader.Say(toSpeak, true);
} }
return; else if (__instance.fillStacksButton != null && __instance.fillStacksButton.containsPoint(x, y))
}
if (__instance.fillStacksButton != null && __instance.fillStacksButton.containsPoint(x, y))
{ {
string toSpeak = "Add to existing stacks button"; toSpeak = "Add to existing stacks button";
if (itemGrabMenuQueryKey != toSpeak)
{
itemGrabMenuQueryKey = toSpeak;
hoveredItemQueryKey = "";
MainClass.ScreenReader.Say(toSpeak, true);
} }
return; else if (__instance.specialButton != null && __instance.specialButton.containsPoint(x, y))
}
if (__instance.specialButton != null && __instance.specialButton.containsPoint(x, y))
{ {
string toSpeak = "Special Button"; toSpeak = "Special Button";
if (itemGrabMenuQueryKey != toSpeak)
{
itemGrabMenuQueryKey = toSpeak;
hoveredItemQueryKey = "";
MainClass.ScreenReader.Say(toSpeak, true);
} }
return; else if (__instance.colorPickerToggleButton != null && __instance.colorPickerToggleButton.containsPoint(x, y))
}
if (__instance.colorPickerToggleButton != null && __instance.colorPickerToggleButton.containsPoint(x, y))
{ {
toSpeak = "Color Picker: " + (__instance.chestColorPicker.visible ? "Enabled" : "Disabled");
string toSpeak = "Color Picker: " + (__instance.chestColorPicker.visible ? "Enabled" : "Disabled");
if (itemGrabMenuQueryKey != toSpeak)
{
itemGrabMenuQueryKey = toSpeak;
hoveredItemQueryKey = "";
MainClass.ScreenReader.Say(toSpeak, true);
} }
return; else if (__instance.junimoNoteIcon != null && __instance.junimoNoteIcon.containsPoint(x, y))
}
if (__instance.junimoNoteIcon != null && __instance.junimoNoteIcon.containsPoint(x, y))
{ {
toSpeak = "Community Center Button";
string toSpeak = "Community Center Button";
if (itemGrabMenuQueryKey != toSpeak)
{
itemGrabMenuQueryKey = toSpeak;
hoveredItemQueryKey = "";
MainClass.ScreenReader.Say(toSpeak, true);
} }
return; else if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y))
}
if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y))
{ {
string toSpeak = "Drop Item"; toSpeak = "Drop Item";
if (itemGrabMenuQueryKey != toSpeak) isDropItemButton = true;
{
itemGrabMenuQueryKey = toSpeak;
hoveredItemQueryKey = "";
MainClass.ScreenReader.Say(toSpeak, true);
Game1.playSound("drop_item");
} }
return; else
{
return false;
} }
// FIXME // FIXME
@ -143,11 +116,22 @@ namespace stardew_access.Patches
} }
} }
}*/ }*/
#endregion
#region Narrate the last shipped item if in the shipping bin if (itemGrabMenuQueryKey == toSpeak) return true;
if (__instance.shippingBin && Game1.getFarm().lastItemShipped != null && __instance.lastShippedHolder.containsPoint(x, y))
itemGrabMenuQueryKey = toSpeak;
hoveredItemQueryKey = "";
MainClass.ScreenReader.Say(toSpeak, true);
if (isDropItemButton) Game1.playSound("drop_item");
return true;
}
private static bool narrateLastShippedItem(ItemGrabMenu __instance, int x, int y)
{ {
if (!__instance.shippingBin || Game1.getFarm().lastItemShipped == null || !__instance.lastShippedHolder.containsPoint(x, y))
return false;
Item lastShippedItem = Game1.getFarm().lastItemShipped; Item lastShippedItem = Game1.getFarm().lastItemShipped;
string name = lastShippedItem.DisplayName; string name = lastShippedItem.DisplayName;
int count = lastShippedItem.Stack; int count = lastShippedItem.Stack;
@ -160,29 +144,7 @@ namespace stardew_access.Patches
hoveredItemQueryKey = ""; hoveredItemQueryKey = "";
MainClass.ScreenReader.Say(toSpeak, true); MainClass.ScreenReader.Say(toSpeak, true);
} }
return; return true;
}
#endregion
#region Narrate hovered item
if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, true))
{
itemGrabMenuQueryKey = "";
return;
}
if (InventoryUtils.narrateHoveredSlot(__instance.ItemsToGrabMenu, __instance.ItemsToGrabMenu.inventory, __instance.ItemsToGrabMenu.actualInventory, x, y, true))
{
itemGrabMenuQueryKey = "";
return;
}
#endregion
}
catch (Exception e)
{
MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}");
}
} }
// TODO Add color names // TODO Add color names
@ -258,7 +220,8 @@ namespace stardew_access.Patches
return toReturn; return toReturn;
} }
internal static void Cleanup() { internal static void Cleanup()
{
hoveredItemQueryKey = ""; hoveredItemQueryKey = "";
itemGrabMenuQueryKey = ""; itemGrabMenuQueryKey = "";
} }

View File

@ -45,6 +45,7 @@ namespace stardew_access.Patches
{ {
string toSpeak = ""; string toSpeak = "";
bool isDropItemButton = false; bool isDropItemButton = false;
if (__instance.inventory.dropItemInvisibleButton != null && __instance.inventory.dropItemInvisibleButton.containsPoint(x, y)) if (__instance.inventory.dropItemInvisibleButton != null && __instance.inventory.dropItemInvisibleButton.containsPoint(x, y))
{ {
toSpeak = "Drop Item"; toSpeak = "Drop Item";