From 8970a2c4414109b561f0111ff099280b28b50843 Mon Sep 17 00:00:00 2001
From: Mohammad Shoaib Khan <shoaib.khan20@outlook.com>
Date: Thu, 9 Mar 2023 13:12:07 +0530
Subject: [PATCH] Fixed bug for Museum menu patch

---
 .../DonationMenuPatches/MuseumMenuPatch.cs    | 51 ++++++++++---------
 1 file changed, 28 insertions(+), 23 deletions(-)

diff --git a/stardew-access/Patches/DonationMenuPatches/MuseumMenuPatch.cs b/stardew-access/Patches/DonationMenuPatches/MuseumMenuPatch.cs
index a79c2b2..284f40a 100644
--- a/stardew-access/Patches/DonationMenuPatches/MuseumMenuPatch.cs
+++ b/stardew-access/Patches/DonationMenuPatches/MuseumMenuPatch.cs
@@ -88,6 +88,8 @@ namespace stardew_access.Patches
         {
             if (__instance.heldItem != null) return;
 
+            if (narrateHoveredButtons(__instance, x, y)) return;
+
             int hoveredItemIndex = InventoryUtils.narrateHoveredSlotAndReturnIndex(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y,
                     handleHighlightedItem: true, highlightedItemPrefix: "Donatable ");
             if (hoveredItemIndex != -9999)
@@ -99,32 +101,35 @@ namespace stardew_access.Patches
                     manuallyDonateItem(__instance, hoveredItemIndex);
                 }
             }
+        }
+
+        private static bool narrateHoveredButtons(MuseumMenu __instance, int x, int y)
+        {
+            string toSpeak = "";
+            bool isDropItemButton = false;
+
+            if (__instance.okButton != null && __instance.okButton.containsPoint(x, y))
+            {
+                toSpeak = "Ok button";
+            }
+            else if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y))
+            {
+                toSpeak = "Drop Item";
+                isDropItemButton = true;
+            }
             else
             {
-                string toSpeak = "";
-                bool isDropItemButton = false;
-
-                if (__instance.okButton != null && __instance.okButton.containsPoint(x, y))
-                {
-                    toSpeak = "Ok button";
-                }
-                else if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y))
-                {
-                    toSpeak = "Drop Item";
-                    isDropItemButton = true;
-                }
-                else
-                {
-                    return;
-                }
-
-                if (museumQueryKey != toSpeak)
-                {
-                    museumQueryKey = toSpeak;
-                    MainClass.ScreenReader.Say(toSpeak, true);
-                    if (isDropItemButton) Game1.playSound("drop_item");
-                }
+                return false;
             }
+
+            if (museumQueryKey != toSpeak)
+            {
+                museumQueryKey = toSpeak;
+                MainClass.ScreenReader.Say(toSpeak, true);
+                if (isDropItemButton) Game1.playSound("drop_item");
+            }
+
+            return true;
         }
 
         private static void manuallyDonateItem(MuseumMenu __instance, int i)