Added more(all) dialogue options

master
shoaib11120 2021-12-10 23:35:04 +05:30
parent 24a5c906b8
commit 3591c2cec6
4 changed files with 85 additions and 24 deletions

View File

@ -16,7 +16,7 @@ namespace stardew_access.Game
player = Game1.player; player = Game1.player;
} }
public static int getHealth() internal static int getHealth()
{ {
if(player == null) if(player == null)
initPlayer(); initPlayer();
@ -28,7 +28,7 @@ namespace stardew_access.Game
return healthPercentage; return healthPercentage;
} }
public static int getStamina() internal static int getStamina()
{ {
if (player == null) if (player == null)
initPlayer(); initPlayer();
@ -41,7 +41,7 @@ namespace stardew_access.Game
return staminaPercentage; return staminaPercentage;
} }
public static int getPositionX() internal static int getPositionX()
{ {
if (player == null) if (player == null)
initPlayer(); initPlayer();
@ -50,7 +50,7 @@ namespace stardew_access.Game
return x; return x;
} }
public static int getPositionY() internal static int getPositionY()
{ {
if (player == null) if (player == null)
initPlayer(); initPlayer();

View File

@ -35,12 +35,17 @@ namespace stardew_access
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(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( 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<Item>) }), 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<Item>) }),
postfix: new HarmonyMethod(typeof(DialoguePatch), nameof(DialoguePatch.HoverTextPatch)) postfix: new HarmonyMethod(typeof(DialoguePatcher), nameof(DialoguePatcher.HoverTextPatch))
); );
harmony.Patch( harmony.Patch(
@ -59,6 +64,7 @@ namespace stardew_access
); );
#endregion #endregion
helper.Events.Input.ButtonPressed += this.OnButtonPressed; helper.Events.Input.ButtonPressed += this.OnButtonPressed;
} }

View File

@ -6,12 +6,20 @@ using System.Text;
namespace stardew_access.Patches 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 try
{ {
if (__instance.transitioning)
return;
if (__instance.characterDialogue != null)
{
// For Normal Character dialogues
Dialogue dialogue = __instance.characterDialogue; Dialogue dialogue = __instance.characterDialogue;
string speakerName = dialogue.speaker.Name; string speakerName = dialogue.speaker.Name;
List<string> dialogues = dialogue.dialogues; List<string> dialogues = dialogue.dialogues;
@ -19,8 +27,42 @@ namespace stardew_access.Patches
MainClass.monitor.Log("" + dialogue.isCurrentStringContinuedOnNextScreen, LogLevel.Debug); MainClass.monitor.Log("" + dialogue.isCurrentStringContinuedOnNextScreen, LogLevel.Debug);
string toSpeak = $"{speakerName} said, {dialogues[dialogueIndex]}"; 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); 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) catch (Exception e)
{ {
MainClass.monitor.Log($"Unable to narrate dialog:\n{e.StackTrace}", LogLevel.Error); MainClass.monitor.Log($"Unable to narrate dialog:\n{e.StackTrace}", LogLevel.Error);
@ -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 try
{ {

View File

@ -7,7 +7,7 @@ namespace stardew_access.Patches
internal class MenuPatch internal class MenuPatch
{ {
public static void TitleMenuPatch(TitleMenu __instance) internal static void TitleMenuPatch(TitleMenu __instance)
{ {
try 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 try
{ {
@ -94,6 +94,8 @@ namespace stardew_access.Patches
} }
internal static void ExitPagePatch(ExitPage __instance) internal static void ExitPagePatch(ExitPage __instance)
{
try
{ {
if (__instance.exitToTitle.visible && if (__instance.exitToTitle.visible &&
__instance.exitToTitle.containsPoint(Game1.getMousePosition(true).X, Game1.getMousePosition(true).Y)) __instance.exitToTitle.containsPoint(Game1.getMousePosition(true).X, Game1.getMousePosition(true).Y))
@ -106,5 +108,11 @@ namespace stardew_access.Patches
ScreenReader.sayWithChecker("Exit to Desktop Button", true); ScreenReader.sayWithChecker("Exit to Desktop Button", true);
} }
} }
catch (Exception e)
{
MainClass.monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error);
}
}
} }
} }