Organized code
parent
80637af471
commit
2d061e220b
|
@ -79,7 +79,8 @@ namespace stardew_access.Patches
|
|||
else
|
||||
{
|
||||
// Player Inventory
|
||||
int i = narrateHoveredItemInInventory(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y);
|
||||
int i = InventoryUtils.narrateHoveredSlotAndReturnIndex(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y,
|
||||
handleHighlightedItem: true, highlightedItemPrefix: "Donatable ");
|
||||
if (i != -9999)
|
||||
{
|
||||
bool isPrimaryInfoKeyPressed = MainClass.Config.PrimaryInfoKey.JustPressed(); // For donating hovered item
|
||||
|
@ -148,73 +149,6 @@ namespace stardew_access.Patches
|
|||
}
|
||||
}
|
||||
|
||||
// Returns the index of the hovered item or -9999
|
||||
internal static int narrateHoveredItemInInventory(InventoryMenu inventoryMenu, List<ClickableComponent> inventory, IList<Item> actualInventory, int x, int y)
|
||||
{
|
||||
#region Narrate hovered item
|
||||
for (int i = 0; i < inventory.Count; i++)
|
||||
{
|
||||
if (inventory[i].containsPoint(x, y))
|
||||
{
|
||||
string toSpeak = "";
|
||||
if ((i + 1) <= actualInventory.Count)
|
||||
{
|
||||
if (actualInventory[i] != null)
|
||||
{
|
||||
string name = actualInventory[i].DisplayName;
|
||||
int stack = actualInventory[i].Stack;
|
||||
string quality = "";
|
||||
|
||||
#region Add quality of item
|
||||
if (actualInventory[i] is StardewValley.Object && ((StardewValley.Object)actualInventory[i]).Quality > 0)
|
||||
{
|
||||
int qualityIndex = ((StardewValley.Object)actualInventory[i]).Quality;
|
||||
if (qualityIndex == 1)
|
||||
{
|
||||
quality = "Silver quality";
|
||||
}
|
||||
else if (qualityIndex == 2 || qualityIndex == 3)
|
||||
{
|
||||
quality = "Gold quality";
|
||||
}
|
||||
else if (qualityIndex >= 4)
|
||||
{
|
||||
quality = "Iridium quality";
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
if (inventoryMenu.highlightMethod(inventoryMenu.actualInventory[i]))
|
||||
name = $"Donatable {name}";
|
||||
|
||||
if (stack > 1)
|
||||
toSpeak = $"{stack} {name} {quality}";
|
||||
else
|
||||
toSpeak = $"{name} {quality}";
|
||||
}
|
||||
else
|
||||
{
|
||||
// For empty slot
|
||||
toSpeak = "Empty Slot";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// For empty slot
|
||||
toSpeak = "Empty Slot";
|
||||
}
|
||||
|
||||
if (museumQueryKey != $"{toSpeak}:{i}")
|
||||
{
|
||||
museumQueryKey = $"{toSpeak}:{i}";
|
||||
MainClass.ScreenReader.Say(toSpeak, true);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
return -9999;
|
||||
}
|
||||
|
||||
#region These methods are taken from the game's source code, https://github.com/veywrn/StardewValley/blob/3ff171b6e9e6839555d7881a391b624ccd820a83/StardewValley/Multiplayer.cs#L1331-L1395
|
||||
internal static void globalChatInfoMessage(string messageKey, params string[] args)
|
||||
|
@ -303,33 +237,8 @@ namespace stardew_access.Patches
|
|||
}
|
||||
else
|
||||
{
|
||||
if (InventoryUtils.narrateHoveredItemInInventory(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y))
|
||||
if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y))
|
||||
return;
|
||||
// for (int i = 0; i < __instance.inventory.inventory.Count; i++)
|
||||
// {
|
||||
// if (!__instance.inventory.inventory[i].containsPoint(x, y))
|
||||
// continue;
|
||||
//
|
||||
// if (__instance.inventory.actualInventory[i] == null)
|
||||
// toSpeak = "Empty slot";
|
||||
// else
|
||||
// {
|
||||
// toSpeak = $"{__instance.inventory.actualInventory[i].Stack} {__instance.inventory.actualInventory[i].DisplayName}";
|
||||
//
|
||||
// if (!__instance.inventory.highlightMethod(__instance.inventory.actualInventory[i]))
|
||||
// {
|
||||
// toSpeak = $"{toSpeak} not usable here";
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (fieldOfficeMenuQuery != $"{toSpeak}:{i}")
|
||||
// {
|
||||
// fieldOfficeMenuQuery = $"{toSpeak}:{i}";
|
||||
// MainClass.ScreenReader.Say(toSpeak, true);
|
||||
// }
|
||||
//
|
||||
// return;
|
||||
// }
|
||||
|
||||
for (int i = 0; i < __instance.pieceHolders.Count; i++)
|
||||
{
|
||||
|
|
|
@ -240,7 +240,7 @@ namespace stardew_access.Patches
|
|||
#endregion
|
||||
|
||||
#region Narrate hovered item
|
||||
if (InventoryUtils.narrateHoveredItemInInventory(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, hoverPrice: __instance.hoverPrice))
|
||||
if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, hoverPrice: __instance.hoverPrice))
|
||||
{
|
||||
shopMenuQueryKey = "";
|
||||
return;
|
||||
|
@ -395,7 +395,7 @@ namespace stardew_access.Patches
|
|||
#endregion
|
||||
|
||||
#region Narrate hovered item
|
||||
if (InventoryUtils.narrateHoveredItemInInventory(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y))
|
||||
if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y))
|
||||
geodeMenuQueryKey = "";
|
||||
#endregion
|
||||
}
|
||||
|
@ -572,14 +572,14 @@ namespace stardew_access.Patches
|
|||
#endregion
|
||||
|
||||
#region Narrate hovered item
|
||||
if (InventoryUtils.narrateHoveredItemInInventory(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, true))
|
||||
if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, true))
|
||||
{
|
||||
gameMenuQueryKey = "";
|
||||
itemGrabMenuQueryKey = "";
|
||||
return;
|
||||
}
|
||||
|
||||
if (InventoryUtils.narrateHoveredItemInInventory(__instance.ItemsToGrabMenu, __instance.ItemsToGrabMenu.inventory, __instance.ItemsToGrabMenu.actualInventory, x, y, true))
|
||||
if (InventoryUtils.narrateHoveredSlot(__instance.ItemsToGrabMenu, __instance.ItemsToGrabMenu.inventory, __instance.ItemsToGrabMenu.actualInventory, x, y, true))
|
||||
{
|
||||
gameMenuQueryKey = "";
|
||||
itemGrabMenuQueryKey = "";
|
||||
|
@ -854,7 +854,7 @@ namespace stardew_access.Patches
|
|||
#endregion
|
||||
|
||||
#region Narrate hovered item
|
||||
if (InventoryUtils.narrateHoveredItemInInventory(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y))
|
||||
if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y))
|
||||
{
|
||||
gameMenuQueryKey = "";
|
||||
craftingPageQueryKey = "";
|
||||
|
@ -1065,7 +1065,7 @@ namespace stardew_access.Patches
|
|||
#endregion
|
||||
|
||||
#region Narrate hovered item
|
||||
if (InventoryUtils.narrateHoveredItemInInventory(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, true))
|
||||
if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, true))
|
||||
{
|
||||
gameMenuQueryKey = "";
|
||||
inventoryPageQueryKey = "";
|
||||
|
|
|
@ -9,7 +9,20 @@ namespace stardew_access.Patches
|
|||
internal static string hoveredItemQueryKey = "";
|
||||
internal static int prevSlotIndex = -999;
|
||||
|
||||
internal static bool narrateHoveredItemInInventory(InventoryMenu inventoryMenu, List<ClickableComponent> inventory, IList<Item> actualInventory, int x, int y, bool giveExtraDetails = false, int hoverPrice = -1, int extraItemToShowIndex = -1, int extraItemToShowAmount = -1)
|
||||
internal static bool narrateHoveredSlot(InventoryMenu inventoryMenu, List<ClickableComponent> inventory, IList<Item> actualInventory, int x, int y,
|
||||
bool giveExtraDetails = false, int hoverPrice = -1, int extraItemToShowIndex = -1, int extraItemToShowAmount = -1,
|
||||
bool handleHighlightedItem = false, String highlightedItemPrefix = "", String highlightedItemSuffix = "")
|
||||
{
|
||||
if (narrateHoveredSlotAndReturnIndex(inventoryMenu, inventory, actualInventory, x, y,
|
||||
giveExtraDetails = false, hoverPrice = -1, extraItemToShowIndex = -1, extraItemToShowAmount = -1,
|
||||
handleHighlightedItem = false, highlightedItemPrefix = "", highlightedItemSuffix = "") == -999)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
internal static int narrateHoveredSlotAndReturnIndex(InventoryMenu inventoryMenu, List<ClickableComponent> inventory, IList<Item> actualInventory, int x, int y,
|
||||
bool giveExtraDetails = false, int hoverPrice = -1, int extraItemToShowIndex = -1, int extraItemToShowAmount = -1,
|
||||
bool handleHighlightedItem = false, String highlightedItemPrefix = "", String highlightedItemSuffix = "")
|
||||
{
|
||||
for (int i = 0; i < inventory.Count; i++)
|
||||
{
|
||||
|
@ -20,11 +33,15 @@ namespace stardew_access.Patches
|
|||
// For empty slot
|
||||
checkAndSpeak("Empty Slot", i);
|
||||
prevSlotIndex = i;
|
||||
return true;
|
||||
return i;
|
||||
}
|
||||
|
||||
string toSpeak = "";
|
||||
string name = $"{actualInventory[i].DisplayName}{handleUnHighlightedItem(inventoryMenu.highlightMethod(actualInventory[i]), i)}";
|
||||
bool isHighlighted = inventoryMenu.highlightMethod(actualInventory[i]);
|
||||
|
||||
string namePrefix = handleHighlightedItemPrefix(isHighlighted, highlightedItemPrefix);
|
||||
string nameSuffix = $"{handleHighlightedItemSuffix(isHighlighted, highlightedItemSuffix)}{handleUnHighlightedItem(isHighlighted, i)}";
|
||||
string name = $"{namePrefix}{actualInventory[i].DisplayName}{nameSuffix}";
|
||||
int stack = actualInventory[i].Stack;
|
||||
string quality = getQualityFromItem(actualInventory[i]);
|
||||
string healthNStamine = getHealthNStaminaFromItem(actualInventory[i]);
|
||||
|
@ -51,11 +68,11 @@ namespace stardew_access.Patches
|
|||
|
||||
checkAndSpeak(toSpeak, i);
|
||||
prevSlotIndex = i;
|
||||
return true;
|
||||
return i;
|
||||
}
|
||||
|
||||
// If no slot is hovered
|
||||
return false;
|
||||
return -999;
|
||||
}
|
||||
|
||||
private static void checkAndSpeak(String toSpeak, int hoveredInventoryIndex)
|
||||
|
@ -158,6 +175,20 @@ namespace stardew_access.Patches
|
|||
return $"Sell Price: {price} g";
|
||||
}
|
||||
|
||||
private static String handleHighlightedItemPrefix(bool isHighlighted, String prefix)
|
||||
{
|
||||
if (!isHighlighted) return "";
|
||||
|
||||
return prefix;
|
||||
}
|
||||
|
||||
private static String handleHighlightedItemSuffix(bool isHighlighted, String suffix)
|
||||
{
|
||||
if (!isHighlighted) return "";
|
||||
|
||||
return suffix;
|
||||
}
|
||||
|
||||
private static String handleUnHighlightedItem(bool isHighlighted, int hoveredInventoryIndex)
|
||||
{
|
||||
if (isHighlighted) return "";
|
||||
|
|
|
@ -129,37 +129,40 @@ namespace stardew_access.Patches
|
|||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < __instance.inventory.inventory.Count; i++)
|
||||
{
|
||||
if (!__instance.inventory.inventory[i].containsPoint(x, y))
|
||||
continue;
|
||||
|
||||
if (__instance.inventory.actualInventory[i] == null)
|
||||
toSpeak = "Empty slot";
|
||||
else
|
||||
{
|
||||
toSpeak = $"{__instance.inventory.actualInventory[i].Stack} {__instance.inventory.actualInventory[i].DisplayName}";
|
||||
|
||||
if (!__instance.inventory.highlightMethod(__instance.inventory.actualInventory[i]))
|
||||
{
|
||||
toSpeak = $"{toSpeak} not usable here";
|
||||
}
|
||||
|
||||
if (prevSlotIndex != i)
|
||||
{
|
||||
prevSlotIndex = i;
|
||||
Game1.playSound("invalid-selection");
|
||||
}
|
||||
}
|
||||
|
||||
if (forgeMenuQuery != $"{toSpeak}:{i}")
|
||||
{
|
||||
forgeMenuQuery = $"{toSpeak}:{i}";
|
||||
MainClass.ScreenReader.Say(toSpeak, true);
|
||||
}
|
||||
|
||||
if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y))
|
||||
return;
|
||||
}
|
||||
|
||||
// for (int i = 0; i < __instance.inventory.inventory.Count; i++)
|
||||
// {
|
||||
// if (!__instance.inventory.inventory[i].containsPoint(x, y))
|
||||
// continue;
|
||||
//
|
||||
// if (__instance.inventory.actualInventory[i] == null)
|
||||
// toSpeak = "Empty slot";
|
||||
// else
|
||||
// {
|
||||
// toSpeak = $"{__instance.inventory.actualInventory[i].Stack} {__instance.inventory.actualInventory[i].DisplayName}";
|
||||
//
|
||||
// if (!__instance.inventory.highlightMethod(__instance.inventory.actualInventory[i]))
|
||||
// {
|
||||
// toSpeak = $"{toSpeak} not usable here";
|
||||
// }
|
||||
//
|
||||
// if (prevSlotIndex != i)
|
||||
// {
|
||||
// prevSlotIndex = i;
|
||||
// Game1.playSound("invalid-selection");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (forgeMenuQuery != $"{toSpeak}:{i}")
|
||||
// {
|
||||
// forgeMenuQuery = $"{toSpeak}:{i}";
|
||||
// MainClass.ScreenReader.Say(toSpeak, true);
|
||||
// }
|
||||
//
|
||||
// return;
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
@ -300,40 +303,9 @@ namespace stardew_access.Patches
|
|||
if (Game1.player.pantsItem.Value != null)
|
||||
toSpeak = $"{toSpeak}: {Game1.player.pantsItem.Value.DisplayName}";
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < __instance.inventory.inventory.Count; i++)
|
||||
{
|
||||
if (!__instance.inventory.inventory[i].containsPoint(x, y))
|
||||
continue;
|
||||
|
||||
if (__instance.inventory.actualInventory[i] == null)
|
||||
toSpeak = "Empty slot";
|
||||
else
|
||||
{
|
||||
toSpeak = $"{__instance.inventory.actualInventory[i].Stack} {__instance.inventory.actualInventory[i].DisplayName}";
|
||||
|
||||
if (!__instance.inventory.highlightMethod(__instance.inventory.actualInventory[i]))
|
||||
{
|
||||
toSpeak = $"{toSpeak} not usable here";
|
||||
}
|
||||
|
||||
if (prevSlotIndex != i)
|
||||
{
|
||||
prevSlotIndex = i;
|
||||
Game1.playSound("invalid-selection");
|
||||
}
|
||||
}
|
||||
|
||||
if (tailoringMenuQuery != $"{toSpeak}:{i}")
|
||||
{
|
||||
tailoringMenuQuery = $"{toSpeak}:{i}";
|
||||
MainClass.ScreenReader.Say(toSpeak, true);
|
||||
}
|
||||
|
||||
if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (tailoringMenuQuery != toSpeak)
|
||||
|
|
Loading…
Reference in New Issue