From d2c34451b3335af60ccf46cda9d86d639c194aa3 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Mon, 20 Feb 2023 11:48:24 +0530 Subject: [PATCH 1/6] Added sound cue when the slot item is not usable --- invalid-selection-license.txt | 32 ++++++++++++++++++ stardew-access/CustomSoundEffects.cs | 1 + stardew-access/Patches/GameMenuPatches.cs | 8 ++++- stardew-access/Patches/MenuPatches.cs | 15 ++++++++ .../assets/sounds/invalid-selection.wav | Bin 0 -> 30836 bytes 5 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 invalid-selection-license.txt create mode 100644 stardew-access/assets/sounds/invalid-selection.wav diff --git a/invalid-selection-license.txt b/invalid-selection-license.txt new file mode 100644 index 0000000..f1b27d8 --- /dev/null +++ b/invalid-selection-license.txt @@ -0,0 +1,32 @@ +PIXABAY LICENSE CERTIFICATE +============================================== + +This document confirms the download of an audio file pursuant to the Pixabay License as defined in the Pixabay Terms of Service available at https://https://pixabay.com/service/terms/ + +Licensor's Username: +https://pixabay.com/users/pixabay-1/ + +Licensee: +TheOneWhoKnocks + +Audio File Title: +Invalid Selection + +Audio File URL: +https://pixabay.com/sound-effects/invalid-selection-39351/ + +Audio File ID: +39351 + +Date of download: +2023-02-20 05:52:26 UTC + +Pixabay GmbH c/o Lacore Rechtsanwälte LLP +Berliner Freiheit 2, 10785 Berlin, Germany + +Pixabay is a user-contributed stock content website. The above-named Licensor is responsible for this audio file. Pixabay monitors uploaded audio files only to a reasonable extent. Pixabay cannot be held responsible for the acts or omissions of its users and does not represent or warrant that any required third-party consents or licenses have been obtained. + +For any queries related to this document please contact Pixabay via info@pixabay.com. + + +==== THIS IS NOT A TAX RECEIPT OR INVOICE ==== \ No newline at end of file diff --git a/stardew-access/CustomSoundEffects.cs b/stardew-access/CustomSoundEffects.cs index b5610e4..f4c6d43 100644 --- a/stardew-access/CustomSoundEffects.cs +++ b/stardew-access/CustomSoundEffects.cs @@ -22,6 +22,7 @@ namespace stardew_access soundEffects.Add("drop_item", TYPE.Sound); soundEffects.Add("colliding", TYPE.Sound); + soundEffects.Add("invalid-selection", TYPE.Sound); soundEffects.Add("npc_top", TYPE.Footstep); soundEffects.Add("npc_right", TYPE.Footstep); diff --git a/stardew-access/Patches/GameMenuPatches.cs b/stardew-access/Patches/GameMenuPatches.cs index e1c2d46..ead5f39 100644 --- a/stardew-access/Patches/GameMenuPatches.cs +++ b/stardew-access/Patches/GameMenuPatches.cs @@ -1,5 +1,4 @@ using StardewValley; -using StardewValley.Locations; using StardewValley.Menus; using StardewValley.Objects; @@ -21,6 +20,7 @@ namespace stardew_access.Patches internal static string profilePageQuery = ""; internal static int currentSelectedCraftingRecipe = -1; internal static bool isSelectingRecipe = false; + internal static int prevSlotIndex = -999; internal static void CollectionsPagePatch(CollectionsPage __instance) { @@ -1295,6 +1295,12 @@ namespace stardew_access.Patches if (!inventoryMenu.highlightMethod(actualInventory[i])) { name = $"{name} not usable here"; + + if (prevSlotIndex != i) + { + prevSlotIndex = i; + Game1.playSound("invalid-selection"); + } } if (giveExtraDetails) diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs index 993d580..ca05742 100644 --- a/stardew-access/Patches/MenuPatches.cs +++ b/stardew-access/Patches/MenuPatches.cs @@ -16,6 +16,7 @@ namespace stardew_access.Patches internal static string pondQueryMenuQuery = " "; internal static string forgeMenuQuery = " "; internal static string itemListMenuQuery = " "; + internal static int prevSlotIndex = -999; public static Vector2? prevTile = null; internal static void ItemListMenuPatch(ItemListMenu __instance, string ___title, int ___currentTab, int ___totalValueOfItems, List ___itemsToList) @@ -143,6 +144,13 @@ namespace stardew_access.Patches { toSpeak = $"{toSpeak} not usable here"; } + + if (prevSlotIndex != i) + { + prevSlotIndex = i; + MainClass.DebugLog("here"); + Game1.playSound("invalid-selection"); + } } if (forgeMenuQuery != $"{toSpeak}:{i}") @@ -310,6 +318,13 @@ namespace stardew_access.Patches { toSpeak = $"{toSpeak} not usable here"; } + + if (prevSlotIndex != i) + { + prevSlotIndex = i; + MainClass.DebugLog("here"); + Game1.playSound("invalid-selection"); + } } if (tailoringMenuQuery != $"{toSpeak}:{i}") diff --git a/stardew-access/assets/sounds/invalid-selection.wav b/stardew-access/assets/sounds/invalid-selection.wav new file mode 100644 index 0000000000000000000000000000000000000000..83e63bada354ac5edf4711b63e399d63de3a49e5 GIT binary patch literal 30836 zcmZ9V2mFoY8~>kihE4X~GbL4-q4j}+E}fvDpqx?sny7;WL37>GrC(>S`)1|t?wCQ?9q0SWT|As zbj|eVshO!BsmoFiCm&1BNz6_3N?eiH?(TM9c3*J2#G{+L*V*pe>D=d7PR@SIe$Sp{ zziB^UkFl%TS#@5 zS$^b2wv~xaM#ZgjtTK%Ap^QGOYE`g~MW;D)OZ0O%FPxkEG539Dc4lPuj;x;zvd`w8 z%~kX&dhd8|dt1D%-XMRFf5<=RcMGlvCIsVyFM`j5Ob`Yw!=~Xa;T_@3XnOPzbeZSO zb<%DDH*!Pwp5(pB*2$L1Nr}mcYKba|C)~%~aqa}S2;V>Fyy&!G{A+Kr*V+HrTkXyE zYJ08yApEIr*RYG&MeQZlZ`OC#Pu33WKWn}<&-&c@(t6ms&+2VmZM9{zWHn`2M@=|> zq1BF8<*g1@N4R~3RnMvqJ&IU0z{1s5f9p2*beDBMXlM-{dcn8btx?tptDki}R7+ZC zpwzVJ^C*a-==Y2PUIW6^7s!6Irs!ytaYC&>dGLcLshbD$4JU8pU2vSPA zCES;tSDm|^yPRRp&EO=oU$w{CH`zDZmoZjYe_1Q6Kdqj2AG?HI$i9#n-pOp9v7WbH zwO(Ld3$4M{Kx>$F3x5Y$!>yaGS&YZ5M|gJwt7^skN?1FiZP9QtK+_U)U;c zoom&Jk7>&>4Xq}u=ytArE1%YeGA&tsL8PPrD{hW7H04#AD;2j&S>>$N(TZpa>-{@g z7wzS`eZbq#V5JJy_hj$MexCg_`*Chs z?pAMzchd72r@bnE4gW{~d%s7}D|j883=4(_s~OjXSBFEw8^aI7_rrDJ#x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nj}{=WJyk2P~to=Uo_p@;dzpv6$wtlnHx=WFF> z=WOnG7R%<<*%=!u>b>Wi(VZ!)o$`dOZkZ+U6xAE5U9Lt}nzq+z$AYVn% zx2_>y#8@A5SIygKLgC8Tg0u3Jryp{L0My%{)X+%|(8eBFVhW84QWe`Pf9<(XnQJ1{LOhI@`#Pp?)6I`kVjU zoSR3A=y4W*c`a|KVYp-HWVBdb7wVh*3N>F@ZDHkqd6?I>`M;uDUPkrmEU%1oN-EEC z!(30)5(hO$;~5yeAPQ?m%A}eY#H?KN&;K*)6x|Ge%pJ9|{E9UL&DlgU#y%L1=JBC- znn6Au$a^MQhvu8t=cfNTFXe`|qF7!Uj0DKDF|*Me&1wz(jkYmVH+0c@bwu837#%EJ zNS-A{d8s$36A$yaGxyaD^RM)c-kbU8KDw`&y=;akWIhw(&svGR*3_rEpOIdpjZJi9 zycDy3;{_RH{IA|o{@ft(tTYNe;#MA)Mp}(sHX2&|Iy>vLYssG_-Yc$E=1sayH5=(E yLnEW-4c-hA^7j%AL<@01>(&fRd}HLm=m4!)D=}9vv^5CQ`Q{j5!&s_>^?v|noNJi? literal 0 HcmV?d00001 From 042afa4d901106dede37920ae31975e32a684df2 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Mon, 20 Feb 2023 12:43:25 +0530 Subject: [PATCH 2/6] Organized code --- stardew-access/Patches/GameMenuPatches.cs | 285 +++++++++++----------- 1 file changed, 148 insertions(+), 137 deletions(-) diff --git a/stardew-access/Patches/GameMenuPatches.cs b/stardew-access/Patches/GameMenuPatches.cs index ead5f39..655d51b 100644 --- a/stardew-access/Patches/GameMenuPatches.cs +++ b/stardew-access/Patches/GameMenuPatches.cs @@ -1196,150 +1196,161 @@ namespace stardew_access.Patches internal static bool narrateHoveredItemInInventory(InventoryMenu inventoryMenu, List inventory, IList actualInventory, int x, int y, bool giveExtraDetails = false, int hoverPrice = -1, int extraItemToShowIndex = -1, int extraItemToShowAmount = -1) { - #region Narrate hovered item for (int i = 0; i < inventory.Count; i++) { - if (inventory[i].containsPoint(x, y)) + if (!inventory[i].containsPoint(x, y)) continue; + + if ((i + 1) > actualInventory.Count || actualInventory[i] == null) { - string toSpeak = ""; - if ((i + 1) <= actualInventory.Count) - { - if (actualInventory[i] != null) - { - string name = actualInventory[i].DisplayName; - int stack = actualInventory[i].Stack; - string quality = ""; - string healthNStamine = ""; - string buffs = ""; - string description = ""; - string price = ""; - string requirements = ""; - - #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 (giveExtraDetails) - { - description = actualInventory[i].getDescription(); - #region Add health & stamina provided by the item - if (actualInventory[i] is StardewValley.Object && ((StardewValley.Object)actualInventory[i]).Edibility != -300) - { - int stamina_recovery = ((StardewValley.Object)actualInventory[i]).staminaRecoveredOnConsumption(); - healthNStamine += $"{stamina_recovery} Energy"; - if (stamina_recovery >= 0) - { - int health_recovery = ((StardewValley.Object)actualInventory[i]).healthRecoveredOnConsumption(); - healthNStamine += $"\n\t{health_recovery} Health"; - } - } - #endregion - - #region Add buff items (effects like +1 walking speed) - // These variables are taken from the game's code itself (IClickableMenu.cs -> 1016 line) - bool edibleItem = actualInventory[i] != null && actualInventory[i] is StardewValley.Object && (int)((StardewValley.Object)actualInventory[i]).Edibility != -300; - string[]? buffIconsToDisplay = (edibleItem && Game1.objectInformation[((StardewValley.Object)actualInventory[i]).ParentSheetIndex].Split('/').Length > 7) ? actualInventory[i].ModifyItemBuffs(Game1.objectInformation[((StardewValley.Object)actualInventory[i]).ParentSheetIndex].Split('/')[7].Split(' ')) : null; - if (buffIconsToDisplay != null) - { - for (int j = 0; j < buffIconsToDisplay.Length; j++) - { - string buffName = ((Convert.ToInt32(buffIconsToDisplay[j]) > 0) ? "+" : "") + buffIconsToDisplay[j] + " "; - if (j <= 11) - { - buffName = Game1.content.LoadString("Strings\\UI:ItemHover_Buff" + j, buffName); - } - try - { - int count = int.Parse(buffName.Substring(0, buffName.IndexOf(' '))); - if (count != 0) - buffs += $"{buffName}\n"; - } - catch (Exception) { } - } - } - #endregion - } - - #region Narrate hovered required ingredients - if (extraItemToShowIndex != -1) - { - string itemName = Game1.objectInformation[extraItemToShowIndex].Split('/')[0]; - - if (extraItemToShowAmount != -1) - requirements = $"Required: {extraItemToShowAmount} {itemName}"; - else - requirements = $"Required: {itemName}"; - } - #endregion - - if (hoverPrice != -1) - { - price = $"Sell Price: {hoverPrice} g"; - } - - if (!inventoryMenu.highlightMethod(actualInventory[i])) - { - name = $"{name} not usable here"; - - if (prevSlotIndex != i) - { - prevSlotIndex = i; - Game1.playSound("invalid-selection"); - } - } - - if (giveExtraDetails) - { - if (stack > 1) - toSpeak = $"{stack} {name} {quality}, \n{requirements}, \n{price}, \n{description}, \n{healthNStamine}, \n{buffs}"; - else - toSpeak = $"{name} {quality}, \n{requirements}, \n{price}, \n{description}, \n{healthNStamine}, \n{buffs}"; - } - else - { - if (stack > 1) - toSpeak = $"{stack} {name} {quality}, \n{requirements}, \n{price}"; - else - toSpeak = $"{name} {quality}, \n{requirements}, \n{price}"; - } - } - else - { - // For empty slot - toSpeak = "Empty Slot"; - } - } - else - { - // For empty slot - toSpeak = "Empty Slot"; - } - - if (hoveredItemQueryKey != $"{toSpeak}:{i}") - { - hoveredItemQueryKey = $"{toSpeak}:{i}"; - MainClass.ScreenReader.Say(toSpeak, true); - } + // For empty slot + checkAndSpeak("Empty Slot", i); + prevSlotIndex = i; return true; } + + string toSpeak = ""; + string name = $"{actualInventory[i].DisplayName}{handleUnHighlightedItem(inventoryMenu.highlightMethod(actualInventory[i]), i)}"; + int stack = actualInventory[i].Stack; + string quality = getQualityFromItem(actualInventory[i]); + string healthNStamine = getHealthNStaminaFromItem(actualInventory[i]); + string buffs = getBuffsFromItem(actualInventory[i]); + string description = actualInventory[i].getDescription(); + string price = getPrice(hoverPrice); + string requirements = getExtraItemInfo(extraItemToShowIndex, extraItemToShowAmount); + + if (giveExtraDetails) + { + if (stack > 1) + toSpeak = $"{stack} {name} {quality}, \n{requirements}, \n{price}, \n{description}, \n{healthNStamine}, \n{buffs}"; + else + toSpeak = $"{name} {quality}, \n{requirements}, \n{price}, \n{description}, \n{healthNStamine}, \n{buffs}"; + } + else + { + if (stack > 1) + toSpeak = $"{stack} {name} {quality}, \n{requirements}, \n{price}"; + else + toSpeak = $"{name} {quality}, \n{requirements}, \n{price}"; + } + + + checkAndSpeak(toSpeak, i); + prevSlotIndex = i; + return true; } - #endregion + + // If no slot is hovered return false; } + + private static void checkAndSpeak(String toSpeak, int hoveredInventoryIndex) + { + if (hoveredItemQueryKey == $"{toSpeak}:{hoveredInventoryIndex}") return; + + hoveredItemQueryKey = $"{toSpeak}:{hoveredInventoryIndex}"; + MainClass.ScreenReader.Say(toSpeak, true); + } + + private static String getQualityFromItem(Item item) + { + if (item is not StardewValley.Object || ((StardewValley.Object)item).Quality <= 0) + return ""; + + int qualityIndex = ((StardewValley.Object)item).Quality; + if (qualityIndex == 1) + { + return "Silver quality"; + } + else if (qualityIndex == 2 || qualityIndex == 3) + { + return "Gold quality"; + } + else if (qualityIndex >= 4) + { + return "Iridium quality"; + } + + return ""; + } + + private static String getHealthNStaminaFromItem(Item item) + { + if (item is not StardewValley.Object || ((StardewValley.Object)item).Edibility == -300) + return ""; + + String toReturn = ""; + int stamina_recovery = ((StardewValley.Object)item).staminaRecoveredOnConsumption(); + toReturn += $"{stamina_recovery} Energy"; + + if (stamina_recovery < 0) return toReturn; + + int health_recovery = ((StardewValley.Object)item).healthRecoveredOnConsumption(); + toReturn += $"\n\t{health_recovery} Health"; + + return toReturn; + } + + private static String getBuffsFromItem(Item item) + { + if (item == null) return ""; + if (item is not StardewValley.Object) return ""; + if (((StardewValley.Object)item) == null) return ""; + + // These variables are taken from the game's code itself (IClickableMenu.cs -> 1016 line) + bool edibleItem = (int)((StardewValley.Object)item).Edibility != -300; + string[]? buffIconsToDisplay = (edibleItem && Game1.objectInformation[((StardewValley.Object)item).ParentSheetIndex].Split('/').Length > 7) + ? item.ModifyItemBuffs(Game1.objectInformation[((StardewValley.Object)item).ParentSheetIndex].Split('/')[7].Split(' ')) + : null; + + if (buffIconsToDisplay == null) + return ""; + + String toReturn = ""; + for (int j = 0; j < buffIconsToDisplay.Length; j++) + { + string buffName = ((Convert.ToInt32(buffIconsToDisplay[j]) > 0) ? "+" : "") + buffIconsToDisplay[j] + " "; + if (j <= 11) + { + buffName = Game1.content.LoadString("Strings\\UI:ItemHover_Buff" + j, buffName); + } + try + { + int count = int.Parse(buffName.Substring(0, buffName.IndexOf(' '))); + if (count != 0) + toReturn += $"{buffName}\n"; + } + catch (Exception) { } + } + return toReturn; + } + + private static String getExtraItemInfo(int itemIndex, int itemAmount) + { + if (itemIndex == -1) return ""; + + string itemName = Game1.objectInformation[itemIndex].Split('/')[0]; + + if (itemAmount != -1) + return $"Required: {itemAmount} {itemName}"; + else + return $"Required: {itemName}"; + } + + private static String getPrice(int price) + { + if (price == -1) return ""; + + return $"Sell Price: {price} g"; + } + + private static String handleUnHighlightedItem(bool isHighlighted, int hoveredInventoryIndex) + { + if (isHighlighted) return ""; + + if (prevSlotIndex != hoveredInventoryIndex) + Game1.playSound("invalid-selection"); + + return " not usable here"; + } } } From 80637af4711f6e13604062b538ec9746b63e8138 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Mon, 20 Feb 2023 12:59:55 +0530 Subject: [PATCH 3/6] Moved narrateHoveredItemInInventory to separate class --- stardew-access/Patches/DonationMenuPatches.cs | 52 +++--- stardew-access/Patches/GameMenuPatches.cs | 172 +----------------- stardew-access/Patches/InventoryUtils.cs | 171 +++++++++++++++++ stardew-access/Patches/MenuPatches.cs | 5 +- 4 files changed, 206 insertions(+), 194 deletions(-) create mode 100644 stardew-access/Patches/InventoryUtils.cs diff --git a/stardew-access/Patches/DonationMenuPatches.cs b/stardew-access/Patches/DonationMenuPatches.cs index f4969ca..a49be83 100644 --- a/stardew-access/Patches/DonationMenuPatches.cs +++ b/stardew-access/Patches/DonationMenuPatches.cs @@ -303,31 +303,33 @@ 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 (fieldOfficeMenuQuery != $"{toSpeak}:{i}") - { - fieldOfficeMenuQuery = $"{toSpeak}:{i}"; - MainClass.ScreenReader.Say(toSpeak, true); - } - + if (InventoryUtils.narrateHoveredItemInInventory(__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++) { @@ -414,4 +416,4 @@ namespace stardew_access.Patches #endregion } -} \ No newline at end of file +} diff --git a/stardew-access/Patches/GameMenuPatches.cs b/stardew-access/Patches/GameMenuPatches.cs index 655d51b..a3018a8 100644 --- a/stardew-access/Patches/GameMenuPatches.cs +++ b/stardew-access/Patches/GameMenuPatches.cs @@ -20,7 +20,6 @@ namespace stardew_access.Patches internal static string profilePageQuery = ""; internal static int currentSelectedCraftingRecipe = -1; internal static bool isSelectingRecipe = false; - internal static int prevSlotIndex = -999; internal static void CollectionsPagePatch(CollectionsPage __instance) { @@ -241,7 +240,7 @@ namespace stardew_access.Patches #endregion #region Narrate hovered item - if (narrateHoveredItemInInventory(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, hoverPrice: __instance.hoverPrice)) + if (InventoryUtils.narrateHoveredItemInInventory(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, hoverPrice: __instance.hoverPrice)) { shopMenuQueryKey = ""; return; @@ -396,7 +395,7 @@ namespace stardew_access.Patches #endregion #region Narrate hovered item - if (narrateHoveredItemInInventory(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) + if (InventoryUtils.narrateHoveredItemInInventory(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) geodeMenuQueryKey = ""; #endregion } @@ -573,14 +572,14 @@ namespace stardew_access.Patches #endregion #region Narrate hovered item - if (narrateHoveredItemInInventory(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, true)) + if (InventoryUtils.narrateHoveredItemInInventory(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, true)) { gameMenuQueryKey = ""; itemGrabMenuQueryKey = ""; return; } - if (narrateHoveredItemInInventory(__instance.ItemsToGrabMenu, __instance.ItemsToGrabMenu.inventory, __instance.ItemsToGrabMenu.actualInventory, x, y, true)) + if (InventoryUtils.narrateHoveredItemInInventory(__instance.ItemsToGrabMenu, __instance.ItemsToGrabMenu.inventory, __instance.ItemsToGrabMenu.actualInventory, x, y, true)) { gameMenuQueryKey = ""; itemGrabMenuQueryKey = ""; @@ -855,7 +854,7 @@ namespace stardew_access.Patches #endregion #region Narrate hovered item - if (narrateHoveredItemInInventory(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) + if (InventoryUtils.narrateHoveredItemInInventory(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) { gameMenuQueryKey = ""; craftingPageQueryKey = ""; @@ -1066,7 +1065,7 @@ namespace stardew_access.Patches #endregion #region Narrate hovered item - if (narrateHoveredItemInInventory(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, true)) + if (InventoryUtils.narrateHoveredItemInInventory(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, true)) { gameMenuQueryKey = ""; inventoryPageQueryKey = ""; @@ -1193,164 +1192,5 @@ namespace stardew_access.Patches MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); } } - - internal static bool narrateHoveredItemInInventory(InventoryMenu inventoryMenu, List inventory, IList actualInventory, int x, int y, bool giveExtraDetails = false, int hoverPrice = -1, int extraItemToShowIndex = -1, int extraItemToShowAmount = -1) - { - for (int i = 0; i < inventory.Count; i++) - { - if (!inventory[i].containsPoint(x, y)) continue; - - if ((i + 1) > actualInventory.Count || actualInventory[i] == null) - { - // For empty slot - checkAndSpeak("Empty Slot", i); - prevSlotIndex = i; - return true; - } - - string toSpeak = ""; - string name = $"{actualInventory[i].DisplayName}{handleUnHighlightedItem(inventoryMenu.highlightMethod(actualInventory[i]), i)}"; - int stack = actualInventory[i].Stack; - string quality = getQualityFromItem(actualInventory[i]); - string healthNStamine = getHealthNStaminaFromItem(actualInventory[i]); - string buffs = getBuffsFromItem(actualInventory[i]); - string description = actualInventory[i].getDescription(); - string price = getPrice(hoverPrice); - string requirements = getExtraItemInfo(extraItemToShowIndex, extraItemToShowAmount); - - if (giveExtraDetails) - { - if (stack > 1) - toSpeak = $"{stack} {name} {quality}, \n{requirements}, \n{price}, \n{description}, \n{healthNStamine}, \n{buffs}"; - else - toSpeak = $"{name} {quality}, \n{requirements}, \n{price}, \n{description}, \n{healthNStamine}, \n{buffs}"; - } - else - { - if (stack > 1) - toSpeak = $"{stack} {name} {quality}, \n{requirements}, \n{price}"; - else - toSpeak = $"{name} {quality}, \n{requirements}, \n{price}"; - } - - - checkAndSpeak(toSpeak, i); - prevSlotIndex = i; - return true; - } - - // If no slot is hovered - return false; - } - - private static void checkAndSpeak(String toSpeak, int hoveredInventoryIndex) - { - if (hoveredItemQueryKey == $"{toSpeak}:{hoveredInventoryIndex}") return; - - hoveredItemQueryKey = $"{toSpeak}:{hoveredInventoryIndex}"; - MainClass.ScreenReader.Say(toSpeak, true); - } - - private static String getQualityFromItem(Item item) - { - if (item is not StardewValley.Object || ((StardewValley.Object)item).Quality <= 0) - return ""; - - int qualityIndex = ((StardewValley.Object)item).Quality; - if (qualityIndex == 1) - { - return "Silver quality"; - } - else if (qualityIndex == 2 || qualityIndex == 3) - { - return "Gold quality"; - } - else if (qualityIndex >= 4) - { - return "Iridium quality"; - } - - return ""; - } - - private static String getHealthNStaminaFromItem(Item item) - { - if (item is not StardewValley.Object || ((StardewValley.Object)item).Edibility == -300) - return ""; - - String toReturn = ""; - int stamina_recovery = ((StardewValley.Object)item).staminaRecoveredOnConsumption(); - toReturn += $"{stamina_recovery} Energy"; - - if (stamina_recovery < 0) return toReturn; - - int health_recovery = ((StardewValley.Object)item).healthRecoveredOnConsumption(); - toReturn += $"\n\t{health_recovery} Health"; - - return toReturn; - } - - private static String getBuffsFromItem(Item item) - { - if (item == null) return ""; - if (item is not StardewValley.Object) return ""; - if (((StardewValley.Object)item) == null) return ""; - - // These variables are taken from the game's code itself (IClickableMenu.cs -> 1016 line) - bool edibleItem = (int)((StardewValley.Object)item).Edibility != -300; - string[]? buffIconsToDisplay = (edibleItem && Game1.objectInformation[((StardewValley.Object)item).ParentSheetIndex].Split('/').Length > 7) - ? item.ModifyItemBuffs(Game1.objectInformation[((StardewValley.Object)item).ParentSheetIndex].Split('/')[7].Split(' ')) - : null; - - if (buffIconsToDisplay == null) - return ""; - - String toReturn = ""; - for (int j = 0; j < buffIconsToDisplay.Length; j++) - { - string buffName = ((Convert.ToInt32(buffIconsToDisplay[j]) > 0) ? "+" : "") + buffIconsToDisplay[j] + " "; - if (j <= 11) - { - buffName = Game1.content.LoadString("Strings\\UI:ItemHover_Buff" + j, buffName); - } - try - { - int count = int.Parse(buffName.Substring(0, buffName.IndexOf(' '))); - if (count != 0) - toReturn += $"{buffName}\n"; - } - catch (Exception) { } - } - return toReturn; - } - - private static String getExtraItemInfo(int itemIndex, int itemAmount) - { - if (itemIndex == -1) return ""; - - string itemName = Game1.objectInformation[itemIndex].Split('/')[0]; - - if (itemAmount != -1) - return $"Required: {itemAmount} {itemName}"; - else - return $"Required: {itemName}"; - } - - private static String getPrice(int price) - { - if (price == -1) return ""; - - return $"Sell Price: {price} g"; - } - - private static String handleUnHighlightedItem(bool isHighlighted, int hoveredInventoryIndex) - { - if (isHighlighted) return ""; - - if (prevSlotIndex != hoveredInventoryIndex) - Game1.playSound("invalid-selection"); - - return " not usable here"; - } } } diff --git a/stardew-access/Patches/InventoryUtils.cs b/stardew-access/Patches/InventoryUtils.cs new file mode 100644 index 0000000..3362e4c --- /dev/null +++ b/stardew-access/Patches/InventoryUtils.cs @@ -0,0 +1,171 @@ + +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class InventoryUtils + { + internal static string hoveredItemQueryKey = ""; + internal static int prevSlotIndex = -999; + + internal static bool narrateHoveredItemInInventory(InventoryMenu inventoryMenu, List inventory, IList actualInventory, int x, int y, bool giveExtraDetails = false, int hoverPrice = -1, int extraItemToShowIndex = -1, int extraItemToShowAmount = -1) + { + for (int i = 0; i < inventory.Count; i++) + { + if (!inventory[i].containsPoint(x, y)) continue; + + if ((i + 1) > actualInventory.Count || actualInventory[i] == null) + { + // For empty slot + checkAndSpeak("Empty Slot", i); + prevSlotIndex = i; + return true; + } + + string toSpeak = ""; + string name = $"{actualInventory[i].DisplayName}{handleUnHighlightedItem(inventoryMenu.highlightMethod(actualInventory[i]), i)}"; + int stack = actualInventory[i].Stack; + string quality = getQualityFromItem(actualInventory[i]); + string healthNStamine = getHealthNStaminaFromItem(actualInventory[i]); + string buffs = getBuffsFromItem(actualInventory[i]); + string description = actualInventory[i].getDescription(); + string price = getPrice(hoverPrice); + string requirements = getExtraItemInfo(extraItemToShowIndex, extraItemToShowAmount); + + if (giveExtraDetails) + { + if (stack > 1) + toSpeak = $"{stack} {name} {quality}, \n{requirements}, \n{price}, \n{description}, \n{healthNStamine}, \n{buffs}"; + else + toSpeak = $"{name} {quality}, \n{requirements}, \n{price}, \n{description}, \n{healthNStamine}, \n{buffs}"; + } + else + { + if (stack > 1) + toSpeak = $"{stack} {name} {quality}, \n{requirements}, \n{price}"; + else + toSpeak = $"{name} {quality}, \n{requirements}, \n{price}"; + } + + + checkAndSpeak(toSpeak, i); + prevSlotIndex = i; + return true; + } + + // If no slot is hovered + return false; + } + + private static void checkAndSpeak(String toSpeak, int hoveredInventoryIndex) + { + if (hoveredItemQueryKey == $"{toSpeak}:{hoveredInventoryIndex}") return; + + hoveredItemQueryKey = $"{toSpeak}:{hoveredInventoryIndex}"; + MainClass.ScreenReader.Say(toSpeak, true); + } + + private static String getQualityFromItem(Item item) + { + if (item is not StardewValley.Object || ((StardewValley.Object)item).Quality <= 0) + return ""; + + int qualityIndex = ((StardewValley.Object)item).Quality; + if (qualityIndex == 1) + { + return "Silver quality"; + } + else if (qualityIndex == 2 || qualityIndex == 3) + { + return "Gold quality"; + } + else if (qualityIndex >= 4) + { + return "Iridium quality"; + } + + return ""; + } + + private static String getHealthNStaminaFromItem(Item item) + { + if (item is not StardewValley.Object || ((StardewValley.Object)item).Edibility == -300) + return ""; + + String toReturn = ""; + int stamina_recovery = ((StardewValley.Object)item).staminaRecoveredOnConsumption(); + toReturn += $"{stamina_recovery} Energy"; + + if (stamina_recovery < 0) return toReturn; + + int health_recovery = ((StardewValley.Object)item).healthRecoveredOnConsumption(); + toReturn += $"\n\t{health_recovery} Health"; + + return toReturn; + } + + private static String getBuffsFromItem(Item item) + { + if (item == null) return ""; + if (item is not StardewValley.Object) return ""; + if (((StardewValley.Object)item) == null) return ""; + + // These variables are taken from the game's code itself (IClickableMenu.cs -> 1016 line) + bool edibleItem = (int)((StardewValley.Object)item).Edibility != -300; + string[]? buffIconsToDisplay = (edibleItem && Game1.objectInformation[((StardewValley.Object)item).ParentSheetIndex].Split('/').Length > 7) + ? item.ModifyItemBuffs(Game1.objectInformation[((StardewValley.Object)item).ParentSheetIndex].Split('/')[7].Split(' ')) + : null; + + if (buffIconsToDisplay == null) + return ""; + + String toReturn = ""; + for (int j = 0; j < buffIconsToDisplay.Length; j++) + { + string buffName = ((Convert.ToInt32(buffIconsToDisplay[j]) > 0) ? "+" : "") + buffIconsToDisplay[j] + " "; + if (j <= 11) + { + buffName = Game1.content.LoadString("Strings\\UI:ItemHover_Buff" + j, buffName); + } + try + { + int count = int.Parse(buffName.Substring(0, buffName.IndexOf(' '))); + if (count != 0) + toReturn += $"{buffName}\n"; + } + catch (Exception) { } + } + return toReturn; + } + + private static String getExtraItemInfo(int itemIndex, int itemAmount) + { + if (itemIndex == -1) return ""; + + string itemName = Game1.objectInformation[itemIndex].Split('/')[0]; + + if (itemAmount != -1) + return $"Required: {itemAmount} {itemName}"; + else + return $"Required: {itemName}"; + } + + private static String getPrice(int price) + { + if (price == -1) return ""; + + return $"Sell Price: {price} g"; + } + + private static String handleUnHighlightedItem(bool isHighlighted, int hoveredInventoryIndex) + { + if (isHighlighted) return ""; + + if (prevSlotIndex != hoveredInventoryIndex) + Game1.playSound("invalid-selection"); + + return " not usable here"; + } + } +} diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs index ca05742..739f83e 100644 --- a/stardew-access/Patches/MenuPatches.cs +++ b/stardew-access/Patches/MenuPatches.cs @@ -148,7 +148,6 @@ namespace stardew_access.Patches if (prevSlotIndex != i) { prevSlotIndex = i; - MainClass.DebugLog("here"); Game1.playSound("invalid-selection"); } } @@ -322,7 +321,6 @@ namespace stardew_access.Patches if (prevSlotIndex != i) { prevSlotIndex = i; - MainClass.DebugLog("here"); Game1.playSound("invalid-selection"); } } @@ -803,7 +801,8 @@ namespace stardew_access.Patches pondQueryMenuQuery = " "; } - GameMenuPatches.hoveredItemQueryKey = ""; + InventoryUtils.hoveredItemQueryKey = ""; + InventoryUtils.prevSlotIndex = -999; } #endregion From 2d061e220b0f52ea85803efadef13bd729661358 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Mon, 20 Feb 2023 13:34:03 +0530 Subject: [PATCH 4/6] Organized code --- stardew-access/Patches/DonationMenuPatches.cs | 99 +------------------ stardew-access/Patches/GameMenuPatches.cs | 12 +-- stardew-access/Patches/InventoryUtils.cs | 41 +++++++- stardew-access/Patches/MenuPatches.cs | 98 +++++++----------- 4 files changed, 81 insertions(+), 169 deletions(-) diff --git a/stardew-access/Patches/DonationMenuPatches.cs b/stardew-access/Patches/DonationMenuPatches.cs index a49be83..fd83808 100644 --- a/stardew-access/Patches/DonationMenuPatches.cs +++ b/stardew-access/Patches/DonationMenuPatches.cs @@ -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,74 +149,7 @@ namespace stardew_access.Patches } } - // Returns the index of the hovered item or -9999 - internal static int narrateHoveredItemInInventory(InventoryMenu inventoryMenu, List inventory, IList 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++) { diff --git a/stardew-access/Patches/GameMenuPatches.cs b/stardew-access/Patches/GameMenuPatches.cs index a3018a8..f5d0ea2 100644 --- a/stardew-access/Patches/GameMenuPatches.cs +++ b/stardew-access/Patches/GameMenuPatches.cs @@ -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 = ""; diff --git a/stardew-access/Patches/InventoryUtils.cs b/stardew-access/Patches/InventoryUtils.cs index 3362e4c..e4d0089 100644 --- a/stardew-access/Patches/InventoryUtils.cs +++ b/stardew-access/Patches/InventoryUtils.cs @@ -9,7 +9,20 @@ namespace stardew_access.Patches internal static string hoveredItemQueryKey = ""; internal static int prevSlotIndex = -999; - internal static bool narrateHoveredItemInInventory(InventoryMenu inventoryMenu, List inventory, IList actualInventory, int x, int y, bool giveExtraDetails = false, int hoverPrice = -1, int extraItemToShowIndex = -1, int extraItemToShowAmount = -1) + internal static bool narrateHoveredSlot(InventoryMenu inventoryMenu, List inventory, IList 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 inventory, IList 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 ""; diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs index 739f83e..ff1535d 100644 --- a/stardew-access/Patches/MenuPatches.cs +++ b/stardew-access/Patches/MenuPatches.cs @@ -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); - } - - return; - } - } + if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) + return; if (tailoringMenuQuery != toSpeak) From b8f77384b22671811eba990e19541feecd46bfe3 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Mon, 20 Feb 2023 13:46:06 +0530 Subject: [PATCH 5/6] Added config to disable inventory verbosity If set to true, disables speaking of 'not usable here' and 'donatable' in inventories --- stardew-access/ModConfig.cs | 3 ++- stardew-access/Patches/DonationMenuPatches.cs | 2 +- stardew-access/Patches/InventoryUtils.cs | 4 ++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/stardew-access/ModConfig.cs b/stardew-access/ModConfig.cs index d8530fd..3516999 100644 --- a/stardew-access/ModConfig.cs +++ b/stardew-access/ModConfig.cs @@ -85,9 +85,10 @@ namespace stardew_access public Boolean Warning { get; set; } = true; // Toggles the warnings feature public Boolean TTS { get; set; } = true; // Toggles the screen reader/tts. public Boolean TrackDroppedItems {get; set;} = true; // Toggles detecting the dropped items. + public Boolean DisableInventoryVerbosity {get; set;} = false; // If enabled, does not speaks 'not usable here' and 'donatable' in inventories #endregion // TODO Add the exclusion and focus list too // public String ExclusionList { get; set; } = "test"; } -} \ No newline at end of file +} diff --git a/stardew-access/Patches/DonationMenuPatches.cs b/stardew-access/Patches/DonationMenuPatches.cs index fd83808..ffffa2f 100644 --- a/stardew-access/Patches/DonationMenuPatches.cs +++ b/stardew-access/Patches/DonationMenuPatches.cs @@ -264,7 +264,7 @@ namespace stardew_access.Patches else toSpeak = $"Slot {i + 1} finished: {__instance.pieceHolders[i].item.DisplayName}"; - if (__instance.heldItem != null && __instance.pieceHolders[i].item == null) + if (!MainClass.Config.DisableInventoryVerbosity && __instance.heldItem != null && __instance.pieceHolders[i].item == null) { int highlight = getPieceIndexForDonationItem(__instance.heldItem.ParentSheetIndex); if (highlight != -1 && highlight == i) diff --git a/stardew-access/Patches/InventoryUtils.cs b/stardew-access/Patches/InventoryUtils.cs index e4d0089..5903f92 100644 --- a/stardew-access/Patches/InventoryUtils.cs +++ b/stardew-access/Patches/InventoryUtils.cs @@ -20,6 +20,7 @@ namespace stardew_access.Patches return true; } + internal static int narrateHoveredSlotAndReturnIndex(InventoryMenu inventoryMenu, List inventory, IList actualInventory, int x, int y, bool giveExtraDetails = false, int hoverPrice = -1, int extraItemToShowIndex = -1, int extraItemToShowAmount = -1, bool handleHighlightedItem = false, String highlightedItemPrefix = "", String highlightedItemSuffix = "") @@ -177,6 +178,7 @@ namespace stardew_access.Patches private static String handleHighlightedItemPrefix(bool isHighlighted, String prefix) { + if (MainClass.Config.DisableInventoryVerbosity) return ""; if (!isHighlighted) return ""; return prefix; @@ -184,6 +186,7 @@ namespace stardew_access.Patches private static String handleHighlightedItemSuffix(bool isHighlighted, String suffix) { + if (MainClass.Config.DisableInventoryVerbosity) return ""; if (!isHighlighted) return ""; return suffix; @@ -196,6 +199,7 @@ namespace stardew_access.Patches if (prevSlotIndex != hoveredInventoryIndex) Game1.playSound("invalid-selection"); + if (MainClass.Config.DisableInventoryVerbosity) return ""; return " not usable here"; } } From 0a244649ee640d58840e2ccc8a8d5c343de26068 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Mon, 20 Feb 2023 13:54:39 +0530 Subject: [PATCH 6/6] Removed unnecessary comment --- stardew-access/Patches/MenuPatches.cs | 39 ++------------------------- 1 file changed, 2 insertions(+), 37 deletions(-) diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs index ff1535d..e33a237 100644 --- a/stardew-access/Patches/MenuPatches.cs +++ b/stardew-access/Patches/MenuPatches.cs @@ -127,44 +127,9 @@ namespace stardew_access.Patches if (Game1.player.rightRing.Value != null) toSpeak = $"{toSpeak}: {Game1.player.rightRing.Value.DisplayName}"; } - else - { - 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; - // } - } + if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) + return; if (forgeMenuQuery != toSpeak) {