From 3591c2cec63b179ceb0d76f5c982dc2b0be551e3 Mon Sep 17 00:00:00 2001 From: shoaib11120 Date: Fri, 10 Dec 2021 23:35:04 +0530 Subject: [PATCH] Added more(all) dialogue options --- stardew-access/Game/CurrentPlayer.cs | 8 +-- stardew-access/ModEntry.cs | 10 ++- .../{DialoguePatch.cs => DialoguePatcher.cs} | 67 ++++++++++++++++--- stardew-access/Patches/MenuPatch.cs | 24 ++++--- 4 files changed, 85 insertions(+), 24 deletions(-) rename stardew-access/Patches/{DialoguePatch.cs => DialoguePatcher.cs} (58%) diff --git a/stardew-access/Game/CurrentPlayer.cs b/stardew-access/Game/CurrentPlayer.cs index 27b5848..5492c9f 100644 --- a/stardew-access/Game/CurrentPlayer.cs +++ b/stardew-access/Game/CurrentPlayer.cs @@ -16,7 +16,7 @@ namespace stardew_access.Game player = Game1.player; } - public static int getHealth() + internal static int getHealth() { if(player == null) initPlayer(); @@ -28,7 +28,7 @@ namespace stardew_access.Game return healthPercentage; } - public static int getStamina() + internal static int getStamina() { if (player == null) initPlayer(); @@ -41,7 +41,7 @@ namespace stardew_access.Game return staminaPercentage; } - public static int getPositionX() + internal static int getPositionX() { if (player == null) initPlayer(); @@ -50,7 +50,7 @@ namespace stardew_access.Game return x; } - public static int getPositionY() + internal static int getPositionY() { if (player == null) initPlayer(); diff --git a/stardew-access/ModEntry.cs b/stardew-access/ModEntry.cs index c66db14..b66f4d0 100644 --- a/stardew-access/ModEntry.cs +++ b/stardew-access/ModEntry.cs @@ -35,12 +35,17 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(DialogueBox), nameof(DialogueBox.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(DialoguePatch), nameof(DialoguePatch.CharachterDialoguePatch)) + postfix: new HarmonyMethod(typeof(DialoguePatcher), nameof(DialoguePatcher.DialoguePatch)) + ); + + harmony.Patch( + original: AccessTools.Method(typeof(DialogueBox), nameof(DialogueBox.receiveLeftClick)), + postfix: new HarmonyMethod(typeof(DialoguePatcher), nameof(DialoguePatcher.ClearDialogueString)) ); harmony.Patch( original: AccessTools.Method(typeof(IClickableMenu), nameof(IClickableMenu.drawHoverText), new Type[] { typeof(SpriteBatch), typeof(string), typeof(SpriteFont), typeof(int), typeof(int), typeof(int), typeof(string), typeof(int), typeof(string[]), typeof(Item), typeof(int), typeof(int), typeof(int), typeof(int), typeof(int), typeof(float), typeof(CraftingRecipe), typeof(IList) }), - postfix: new HarmonyMethod(typeof(DialoguePatch), nameof(DialoguePatch.HoverTextPatch)) + postfix: new HarmonyMethod(typeof(DialoguePatcher), nameof(DialoguePatcher.HoverTextPatch)) ); harmony.Patch( @@ -59,6 +64,7 @@ namespace stardew_access ); #endregion + helper.Events.Input.ButtonPressed += this.OnButtonPressed; } diff --git a/stardew-access/Patches/DialoguePatch.cs b/stardew-access/Patches/DialoguePatcher.cs similarity index 58% rename from stardew-access/Patches/DialoguePatch.cs rename to stardew-access/Patches/DialoguePatcher.cs index 60a58f7..4413270 100644 --- a/stardew-access/Patches/DialoguePatch.cs +++ b/stardew-access/Patches/DialoguePatcher.cs @@ -6,20 +6,62 @@ using System.Text; namespace stardew_access.Patches { - internal class DialoguePatch + internal class DialoguePatcher { - public static void CharachterDialoguePatch(DialogueBox __instance, SpriteBatch b) + private static string currentDialogue = " "; + + internal static void DialoguePatch(DialogueBox __instance, SpriteBatch b) { try { - Dialogue dialogue = __instance.characterDialogue; - string speakerName = dialogue.speaker.Name; - List dialogues = dialogue.dialogues; - int dialogueIndex = dialogue.currentDialogueIndex; - MainClass.monitor.Log("" + dialogue.isCurrentStringContinuedOnNextScreen, LogLevel.Debug); - string toSpeak = $"{speakerName} said, {dialogues[dialogueIndex]}"; + if (__instance.transitioning) + return; - ScreenReader.sayWithChecker(toSpeak, false); + if (__instance.characterDialogue != null) + { + // For Normal Character dialogues + Dialogue dialogue = __instance.characterDialogue; + string speakerName = dialogue.speaker.Name; + List dialogues = dialogue.dialogues; + int dialogueIndex = dialogue.currentDialogueIndex; + MainClass.monitor.Log("" + dialogue.isCurrentStringContinuedOnNextScreen, LogLevel.Debug); + string toSpeak = $"{speakerName} said, {dialogues[dialogueIndex]}"; + + if (currentDialogue != toSpeak) + { + currentDialogue = toSpeak; + ScreenReader.say(toSpeak, false); + } + } + else if (__instance.isQuestion) + { + // For Dialogues with responses/answers like the dialogue when we click on tv + string toSpeak = " "; + + if (currentDialogue != __instance.getCurrentString()) { + toSpeak = __instance.getCurrentString(); + currentDialogue = toSpeak; + } + + for (int i = 0; i < __instance.responses.Count; i++) + { + if (i == __instance.selectedResponse) + { + toSpeak += $" \t\n Selected response: {__instance.responses[i].responseText}"; + } + } + + ScreenReader.sayWithChecker(toSpeak, false); + } + else + { + // Basic dialogues like `No mails in the mail box` + if (currentDialogue != __instance.getCurrentString()) + { + currentDialogue = __instance.getCurrentString(); + ScreenReader.say(__instance.getCurrentString(), false); + } + } } catch (Exception e) { @@ -28,8 +70,13 @@ namespace stardew_access.Patches } + internal static void ClearDialogueString() + { + // CLears the currentDialogue string on closing dialog + currentDialogue = " "; + } - public static void HoverTextPatch(string? text, int moneyAmountToDisplayAtBottom = -1, string? boldTitleText = null, string[]? buffIconsToDisplay = null, Item? hoveredItem = null, CraftingRecipe? craftingIngredients = null) + internal static void HoverTextPatch(string? text, int moneyAmountToDisplayAtBottom = -1, string? boldTitleText = null, string[]? buffIconsToDisplay = null, Item? hoveredItem = null, CraftingRecipe? craftingIngredients = null) { try { diff --git a/stardew-access/Patches/MenuPatch.cs b/stardew-access/Patches/MenuPatch.cs index 002cecf..2593a4e 100644 --- a/stardew-access/Patches/MenuPatch.cs +++ b/stardew-access/Patches/MenuPatch.cs @@ -7,7 +7,7 @@ namespace stardew_access.Patches internal class MenuPatch { - public static void TitleMenuPatch(TitleMenu __instance) + internal static void TitleMenuPatch(TitleMenu __instance) { try { @@ -58,7 +58,7 @@ namespace stardew_access.Patches } } - public static void LoadGameMenuPatch(LoadGameMenu.SaveFileSlot __instance, LoadGameMenu ___menu, int i) + internal static void LoadGameMenuPatch(LoadGameMenu.SaveFileSlot __instance, LoadGameMenu ___menu, int i) { try { @@ -95,15 +95,23 @@ namespace stardew_access.Patches internal static void ExitPagePatch(ExitPage __instance) { - if (__instance.exitToTitle.visible && - __instance.exitToTitle.containsPoint(Game1.getMousePosition(true).X, Game1.getMousePosition(true).Y)) + try { - ScreenReader.sayWithChecker("Exit to Title Button", true); + if (__instance.exitToTitle.visible && + __instance.exitToTitle.containsPoint(Game1.getMousePosition(true).X, Game1.getMousePosition(true).Y)) + { + ScreenReader.sayWithChecker("Exit to Title Button", true); + } + if (__instance.exitToDesktop.visible && + __instance.exitToDesktop.containsPoint(Game1.getMousePosition(true).X, Game1.getMousePosition(true).Y)) + { + ScreenReader.sayWithChecker("Exit to Desktop Button", true); + } } - if (__instance.exitToDesktop.visible && - __instance.exitToDesktop.containsPoint(Game1.getMousePosition(true).X, Game1.getMousePosition(true).Y)) + catch (Exception e) { - ScreenReader.sayWithChecker("Exit to Desktop Button", true); + + MainClass.monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error); } } }