Improved and organised code in shop menu patch
parent
8523026ed0
commit
80963c4dc6
|
@ -16,12 +16,12 @@ namespace stardew_access
|
||||||
#region Dialogue Patches
|
#region Dialogue Patches
|
||||||
harmony.Patch(
|
harmony.Patch(
|
||||||
original: AccessTools.Method(typeof(DialogueBox), nameof(DialogueBox.draw), new Type[] { typeof(SpriteBatch) }),
|
original: AccessTools.Method(typeof(DialogueBox), nameof(DialogueBox.draw), new Type[] { typeof(SpriteBatch) }),
|
||||||
postfix: new HarmonyMethod(typeof(DialoguePatches), nameof(DialoguePatches.DialoguePatch))
|
postfix: new HarmonyMethod(typeof(DialogueBoxPatch), nameof(DialogueBoxPatch.DrawPatch))
|
||||||
);
|
);
|
||||||
|
|
||||||
harmony.Patch(
|
harmony.Patch(
|
||||||
original: AccessTools.Method(typeof(DialogueBox), nameof(DialogueBox.receiveLeftClick)),
|
original: AccessTools.Method(typeof(DialogueBox), nameof(DialogueBox.receiveLeftClick)),
|
||||||
postfix: new HarmonyMethod(typeof(DialoguePatches), nameof(DialoguePatches.RecieveLeftClickPatch))
|
postfix: new HarmonyMethod(typeof(DialogueBoxPatch), nameof(DialogueBoxPatch.RecieveLeftClickPatch))
|
||||||
);
|
);
|
||||||
|
|
||||||
harmony.Patch(
|
harmony.Patch(
|
||||||
|
|
|
@ -1,17 +1,14 @@
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using StardewValley;
|
||||||
using StardewModdingAPI;
|
|
||||||
using StardewValley;
|
|
||||||
using StardewValley.Menus;
|
using StardewValley.Menus;
|
||||||
|
|
||||||
namespace stardew_access.Patches
|
namespace stardew_access.Patches
|
||||||
{
|
{
|
||||||
internal class DialoguePatches
|
internal class DialogueBoxPatch
|
||||||
{
|
{
|
||||||
private static string currentDialogue = "";
|
private static string currentDialogue = "";
|
||||||
private static string previousSpeakerName = "";
|
|
||||||
private static bool isDialogueAppearingFirstTime = true;
|
private static bool isDialogueAppearingFirstTime = true;
|
||||||
|
|
||||||
internal static void DialoguePatch(DialogueBox __instance, SpriteBatch b)
|
internal static void DrawPatch(DialogueBox __instance)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
@ -283,7 +283,7 @@ namespace stardew_access.Patches
|
||||||
}
|
}
|
||||||
else if (menu is DialogueBox)
|
else if (menu is DialogueBox)
|
||||||
{
|
{
|
||||||
DialoguePatches.Cleanup();
|
DialogueBoxPatch.Cleanup();
|
||||||
}
|
}
|
||||||
else if (menu is JojaCDMenu)
|
else if (menu is JojaCDMenu)
|
||||||
{
|
{
|
||||||
|
|
|
@ -25,88 +25,15 @@ namespace stardew_access.Patches
|
||||||
__instance.setCurrentlySnappedComponentTo(__instance.inventory.inventory[0].myID);
|
__instance.setCurrentlySnappedComponentTo(__instance.inventory.inventory[0].myID);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Narrate buttons in the menu
|
if (narrateHoveredButton(__instance, x, y)) return;
|
||||||
if (__instance.inventory.dropItemInvisibleButton != null && __instance.inventory.dropItemInvisibleButton.containsPoint(x, y))
|
|
||||||
{
|
|
||||||
string toSpeak = "Drop Item";
|
|
||||||
if (shopMenuQueryKey != toSpeak)
|
|
||||||
{
|
|
||||||
shopMenuQueryKey = toSpeak;
|
|
||||||
hoveredItemQueryKey = "";
|
|
||||||
MainClass.ScreenReader.Say(toSpeak, true);
|
|
||||||
Game1.playSound("drop_item");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (__instance.upArrow != null && __instance.upArrow.containsPoint(x, y))
|
|
||||||
{
|
|
||||||
string toSpeak = "Up Arrow Button";
|
|
||||||
if (shopMenuQueryKey != toSpeak)
|
|
||||||
{
|
|
||||||
shopMenuQueryKey = toSpeak;
|
|
||||||
hoveredItemQueryKey = "";
|
|
||||||
MainClass.ScreenReader.Say(toSpeak, true);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (__instance.downArrow != null && __instance.downArrow.containsPoint(x, y))
|
|
||||||
{
|
|
||||||
string toSpeak = "Down Arrow Button";
|
|
||||||
if (shopMenuQueryKey != toSpeak)
|
|
||||||
{
|
|
||||||
shopMenuQueryKey = toSpeak;
|
|
||||||
hoveredItemQueryKey = "";
|
|
||||||
MainClass.ScreenReader.Say(toSpeak, true);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Narrate hovered item
|
|
||||||
if (InventoryUtils.narrateHoveredSlot(__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 = "";
|
shopMenuQueryKey = "";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Narrate hovered selling item
|
narrateHoveredSellingItem(__instance);
|
||||||
if (__instance.hoveredItem != null)
|
|
||||||
{
|
|
||||||
string name = __instance.hoveredItem.DisplayName;
|
|
||||||
string price = $"Buy Price: {__instance.hoverPrice} g";
|
|
||||||
string description = __instance.hoveredItem.getDescription();
|
|
||||||
string requirements = "";
|
|
||||||
|
|
||||||
#region Narrate required items for item
|
|
||||||
int itemIndex = -1, itemAmount = 5;
|
|
||||||
|
|
||||||
if (__instance.itemPriceAndStock[__instance.hoveredItem].Length > 2)
|
|
||||||
itemIndex = __instance.itemPriceAndStock[__instance.hoveredItem][2];
|
|
||||||
|
|
||||||
if (__instance.itemPriceAndStock[__instance.hoveredItem].Length > 3)
|
|
||||||
itemAmount = __instance.itemPriceAndStock[__instance.hoveredItem][3];
|
|
||||||
|
|
||||||
if (itemIndex != -1)
|
|
||||||
{
|
|
||||||
string itemName = Game1.objectInformation[itemIndex].Split('/')[0];
|
|
||||||
|
|
||||||
if (itemAmount != -1)
|
|
||||||
requirements = $"Required: {itemAmount} {itemName}";
|
|
||||||
else
|
|
||||||
requirements = $"Required: {itemName}";
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
string toSpeak = $"{name}, {requirements}, {price}, \n\t{description}";
|
|
||||||
if (shopMenuQueryKey != toSpeak)
|
|
||||||
{
|
|
||||||
shopMenuQueryKey = toSpeak;
|
|
||||||
hoveredItemQueryKey = "";
|
|
||||||
MainClass.ScreenReader.Say(toSpeak, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -114,6 +41,75 @@ namespace stardew_access.Patches
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool narrateHoveredButton(ShopMenu __instance, int x, int y)
|
||||||
|
{
|
||||||
|
string toSpeak = "";
|
||||||
|
bool isDropItemButton = false;
|
||||||
|
if (__instance.inventory.dropItemInvisibleButton != null && __instance.inventory.dropItemInvisibleButton.containsPoint(x, y))
|
||||||
|
{
|
||||||
|
toSpeak = "Drop Item";
|
||||||
|
isDropItemButton = true;
|
||||||
|
}
|
||||||
|
else if (__instance.upArrow != null && __instance.upArrow.containsPoint(x, y))
|
||||||
|
{
|
||||||
|
toSpeak = "Up Arrow Button";
|
||||||
|
}
|
||||||
|
else if (__instance.downArrow != null && __instance.downArrow.containsPoint(x, y))
|
||||||
|
{
|
||||||
|
toSpeak = "Down Arrow Button";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shopMenuQueryKey == toSpeak) return true;
|
||||||
|
|
||||||
|
shopMenuQueryKey = toSpeak;
|
||||||
|
hoveredItemQueryKey = "";
|
||||||
|
MainClass.ScreenReader.Say(toSpeak, true);
|
||||||
|
if (isDropItemButton) Game1.playSound("drop_item");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void narrateHoveredSellingItem(ShopMenu __instance)
|
||||||
|
{
|
||||||
|
if (__instance.hoveredItem == null) return;
|
||||||
|
|
||||||
|
string name = __instance.hoveredItem.DisplayName;
|
||||||
|
string price = $"Buy Price: {__instance.hoverPrice} g";
|
||||||
|
string description = __instance.hoveredItem.getDescription();
|
||||||
|
string requirements = "";
|
||||||
|
|
||||||
|
#region get required items for item
|
||||||
|
int itemIndex = -1, itemAmount = 5;
|
||||||
|
|
||||||
|
if (__instance.itemPriceAndStock[__instance.hoveredItem].Length > 2)
|
||||||
|
itemIndex = __instance.itemPriceAndStock[__instance.hoveredItem][2];
|
||||||
|
|
||||||
|
if (__instance.itemPriceAndStock[__instance.hoveredItem].Length > 3)
|
||||||
|
itemAmount = __instance.itemPriceAndStock[__instance.hoveredItem][3];
|
||||||
|
|
||||||
|
if (itemIndex != -1)
|
||||||
|
{
|
||||||
|
string itemName = Game1.objectInformation[itemIndex].Split('/')[0];
|
||||||
|
|
||||||
|
if (itemAmount != -1)
|
||||||
|
requirements = $"Required: {itemAmount} {itemName}";
|
||||||
|
else
|
||||||
|
requirements = $"Required: {itemName}";
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
string toSpeak = $"{name}, {requirements}, {price}, \n\t{description}";
|
||||||
|
if (shopMenuQueryKey == toSpeak) return;
|
||||||
|
|
||||||
|
shopMenuQueryKey = toSpeak;
|
||||||
|
hoveredItemQueryKey = "";
|
||||||
|
MainClass.ScreenReader.Say(toSpeak, true);
|
||||||
|
}
|
||||||
|
|
||||||
internal static void Cleanup()
|
internal static void Cleanup()
|
||||||
{
|
{
|
||||||
shopMenuQueryKey = "";
|
shopMenuQueryKey = "";
|
||||||
|
|
Loading…
Reference in New Issue