Improved and organised code in shop menu patch
parent
8523026ed0
commit
80963c4dc6
|
@ -16,12 +16,12 @@ namespace stardew_access
|
|||
#region Dialogue Patches
|
||||
harmony.Patch(
|
||||
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(
|
||||
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(
|
||||
|
|
|
@ -1,17 +1,14 @@
|
|||
using Microsoft.Xna.Framework.Graphics;
|
||||
using StardewModdingAPI;
|
||||
using StardewValley;
|
||||
using StardewValley;
|
||||
using StardewValley.Menus;
|
||||
|
||||
namespace stardew_access.Patches
|
||||
{
|
||||
internal class DialoguePatches
|
||||
internal class DialogueBoxPatch
|
||||
{
|
||||
private static string currentDialogue = "";
|
||||
private static string previousSpeakerName = "";
|
||||
private static bool isDialogueAppearingFirstTime = true;
|
||||
|
||||
internal static void DialoguePatch(DialogueBox __instance, SpriteBatch b)
|
||||
internal static void DrawPatch(DialogueBox __instance)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
|
@ -283,7 +283,7 @@ namespace stardew_access.Patches
|
|||
}
|
||||
else if (menu is DialogueBox)
|
||||
{
|
||||
DialoguePatches.Cleanup();
|
||||
DialogueBoxPatch.Cleanup();
|
||||
}
|
||||
else if (menu is JojaCDMenu)
|
||||
{
|
||||
|
|
|
@ -25,60 +25,64 @@ namespace stardew_access.Patches
|
|||
__instance.setCurrentlySnappedComponentTo(__instance.inventory.inventory[0].myID);
|
||||
}
|
||||
|
||||
#region Narrate buttons in the menu
|
||||
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
|
||||
if (narrateHoveredButton(__instance, x, y)) return;
|
||||
|
||||
#region Narrate hovered item
|
||||
if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, hoverPrice: __instance.hoverPrice))
|
||||
{
|
||||
shopMenuQueryKey = "";
|
||||
return;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Narrate hovered selling item
|
||||
if (__instance.hoveredItem != null)
|
||||
narrateHoveredSellingItem(__instance);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}");
|
||||
}
|
||||
}
|
||||
|
||||
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 Narrate required items for item
|
||||
#region get required items for item
|
||||
int itemIndex = -1, itemAmount = 5;
|
||||
|
||||
if (__instance.itemPriceAndStock[__instance.hoveredItem].Length > 2)
|
||||
|
@ -99,20 +103,12 @@ namespace stardew_access.Patches
|
|||
#endregion
|
||||
|
||||
string toSpeak = $"{name}, {requirements}, {price}, \n\t{description}";
|
||||
if (shopMenuQueryKey != toSpeak)
|
||||
{
|
||||
if (shopMenuQueryKey == toSpeak) return;
|
||||
|
||||
shopMenuQueryKey = toSpeak;
|
||||
hoveredItemQueryKey = "";
|
||||
MainClass.ScreenReader.Say(toSpeak, true);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}");
|
||||
}
|
||||
}
|
||||
|
||||
internal static void Cleanup()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue