+ Narrate Hovered Texts
parent
218e418945
commit
09fdbd59aa
|
@ -4,6 +4,9 @@ using StardewModdingAPI;
|
||||||
using StardewModdingAPI.Events;
|
using StardewModdingAPI.Events;
|
||||||
using StardewValley;
|
using StardewValley;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
|
using StardewValley.Menus;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace stardew_access
|
namespace stardew_access
|
||||||
{
|
{
|
||||||
|
@ -13,6 +16,7 @@ namespace stardew_access
|
||||||
public static IAccessibleOutput screenReader;
|
public static IAccessibleOutput screenReader;
|
||||||
Harmony harmony;
|
Harmony harmony;
|
||||||
public static IMonitor monitor;
|
public static IMonitor monitor;
|
||||||
|
private static string prevText = "";
|
||||||
/*********
|
/*********
|
||||||
** Public methods
|
** Public methods
|
||||||
*********/
|
*********/
|
||||||
|
@ -31,20 +35,64 @@ namespace stardew_access
|
||||||
|
|
||||||
// Add patches
|
// Add patches
|
||||||
harmony.Patch(
|
harmony.Patch(
|
||||||
original: AccessTools.Constructor(typeof(StardewValley.Menus.DialogueBox), new Type[] { typeof(Dialogue) }),
|
original: AccessTools.Constructor(typeof(DialogueBox), new Type[] { typeof(Dialogue) }),
|
||||||
postfix: new HarmonyMethod(typeof(MainClass), nameof(MainClass.Dialog_post))
|
postfix: new HarmonyMethod(typeof(MainClass), nameof(MainClass.dialogBoxPostfix))
|
||||||
);
|
);
|
||||||
|
/*harmony.Patch(
|
||||||
|
original: AccessTools.Method(typeof(DialogueBox), nameof(DialogueBox.receiveLeftClick)),
|
||||||
|
postfix: new HarmonyMethod(typeof(MainClass), nameof(MainClass.dialogBoxRecieveLeftClickPostfix))
|
||||||
|
);*/
|
||||||
|
|
||||||
harmony.Patch(
|
harmony.Patch(
|
||||||
original:,
|
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:
|
postfix: new HarmonyMethod(typeof(MainClass), nameof(MainClass.iClickableMenuDrawHoverTextPostFix))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
helper.Events.Input.ButtonPressed += this.OnButtonPressed;
|
helper.Events.Input.ButtonPressed += this.OnButtonPressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Dialog_post(Dialogue dialogue)
|
private static void iClickableMenuDrawHoverTextPostFix(SpriteBatch b, string text, SpriteFont font, int xOffset = 0, int yOffset = 0, int moneyAmountToDisplayAtBottom = -1, string boldTitleText = null, int healAmountToDisplay = -1, string[] buffIconsToDisplay = null, Item hoveredItem = null, int currencySymbol = 0, int extraItemToShowIndex = -1, int extraItemToShowAmount = -1, int overrideX = -1, int overrideY = -1, float alpha = 1f, CraftingRecipe craftingIngredients = null, IList<Item> additional_craft_materials = null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
StringBuilder toSpeak = new StringBuilder();
|
||||||
|
|
||||||
|
if (hoveredItem != null)
|
||||||
|
toSpeak.AppendLine(hoveredItem.DisplayName);
|
||||||
|
|
||||||
|
toSpeak.AppendLine(text);
|
||||||
|
|
||||||
|
if (prevText != toSpeak.ToString())
|
||||||
|
{
|
||||||
|
prevText = toSpeak.ToString();
|
||||||
|
screenReader.Speak(toSpeak.ToString(), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
monitor.Log($"Unable to narrate dialog:\n{e.StackTrace}", LogLevel.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void dialogBoxRecieveLeftClickPostfix(DialogueBox dialogueBox)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if(!dialogueBox.transitioning && dialogueBox.characterDialogue!=null)
|
||||||
|
{
|
||||||
|
string speakerName = dialogueBox.characterDialogue.speaker.Name;
|
||||||
|
List<string> dialogues = dialogueBox.characterDialogue.dialogues;
|
||||||
|
int dialogueIndex = dialogueBox.characterDialogue.currentDialogueIndex;
|
||||||
|
|
||||||
|
screenReader.Speak($"{speakerName} said, {dialogues[dialogueIndex]}", false);
|
||||||
|
}
|
||||||
|
} catch (Exception e)
|
||||||
|
{
|
||||||
|
monitor.Log($"Unable to narrate dialog:\n{e.StackTrace}", LogLevel.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void dialogBoxPostfix(Dialogue dialogue)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -53,8 +101,7 @@ namespace stardew_access
|
||||||
int dialogueIndex = dialogue.currentDialogueIndex;
|
int dialogueIndex = dialogue.currentDialogueIndex;
|
||||||
|
|
||||||
screenReader.Speak($"{speakerName} said, {dialogues[dialogueIndex]}", false);
|
screenReader.Speak($"{speakerName} said, {dialogues[dialogueIndex]}", false);
|
||||||
monitor.Log($"Dialogue", LogLevel.Info);
|
} catch (Exception e)
|
||||||
}catch (Exception e)
|
|
||||||
{
|
{
|
||||||
monitor.Log($"Unable to narrate dialog:\n{e.StackTrace}", LogLevel.Error);
|
monitor.Log($"Unable to narrate dialog:\n{e.StackTrace}", LogLevel.Error);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue