Added hud message narration
parent
db1cc7f58d
commit
b19e9fda43
|
@ -8,9 +8,8 @@ using Microsoft.Xna.Framework.Graphics;
|
||||||
using stardew_access.Patches;
|
using stardew_access.Patches;
|
||||||
using AutoHotkey.Interop;
|
using AutoHotkey.Interop;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using StardewValley.TerrainFeatures;
|
|
||||||
using StardewValley.Locations;
|
|
||||||
using Microsoft.Xna.Framework.Audio;
|
using Microsoft.Xna.Framework.Audio;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace stardew_access
|
namespace stardew_access
|
||||||
{
|
{
|
||||||
|
@ -18,9 +17,10 @@ namespace stardew_access
|
||||||
public class MainClass : Mod
|
public class MainClass : Mod
|
||||||
{
|
{
|
||||||
private Harmony? harmony;
|
private Harmony? harmony;
|
||||||
private static bool readTile = true, snapMouse = true;
|
private static bool readTile = true, snapMouse = true, isNarratingHudMessage = false;
|
||||||
public static IMonitor? monitor;
|
public static IMonitor? monitor;
|
||||||
AutoHotkeyEngine ahk;
|
AutoHotkeyEngine ahk;
|
||||||
|
public static string hudMessageQueryKey = "";
|
||||||
|
|
||||||
/*********
|
/*********
|
||||||
** Public methods
|
** Public methods
|
||||||
|
@ -45,7 +45,6 @@ namespace stardew_access
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
||||||
monitor.Log($"Unable to initialize AutoHotKey:\n{e.Message}\n{e.StackTrace}", LogLevel.Error);
|
monitor.Log($"Unable to initialize AutoHotKey:\n{e.Message}\n{e.StackTrace}", LogLevel.Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,6 +172,11 @@ namespace stardew_access
|
||||||
original: AccessTools.Method(typeof(LanguageSelectionMenu), nameof(LanguageSelectionMenu.draw), new Type[] { typeof(SpriteBatch) }),
|
original: AccessTools.Method(typeof(LanguageSelectionMenu), nameof(LanguageSelectionMenu.draw), new Type[] { typeof(SpriteBatch) }),
|
||||||
postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.LanguageSelectionMenuPatch))
|
postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.LanguageSelectionMenuPatch))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/*harmony.Patch(
|
||||||
|
original: AccessTools.Method(typeof(HUDMessage), nameof(HUDMessage.draw), new Type[] { typeof(SpriteBatch), typeof(int) }),
|
||||||
|
postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.HUDMessagePatch))
|
||||||
|
);*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Quest Patches
|
#region Quest Patches
|
||||||
|
@ -236,6 +240,8 @@ namespace stardew_access
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Custom Drop Item Sound
|
#region Custom Drop Item Sound
|
||||||
|
try
|
||||||
|
{
|
||||||
CueDefinition sa_drop_item = new CueDefinition();
|
CueDefinition sa_drop_item = new CueDefinition();
|
||||||
sa_drop_item.name = "sa_drop_item";
|
sa_drop_item.name = "sa_drop_item";
|
||||||
sa_drop_item.instanceLimit = 1;
|
sa_drop_item.instanceLimit = 1;
|
||||||
|
@ -248,6 +254,11 @@ namespace stardew_access
|
||||||
}
|
}
|
||||||
sa_drop_item.SetSound(audio, Game1.audioEngine.GetCategoryIndex("Sound"), false);
|
sa_drop_item.SetSound(audio, Game1.audioEngine.GetCategoryIndex("Sound"), false);
|
||||||
Game1.soundBank.AddCue(sa_drop_item);
|
Game1.soundBank.AddCue(sa_drop_item);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
MainClass.monitor.Log($"Unable to initialize custom sounds:\n{e.Message}\n{e.StackTrace}", LogLevel.Error);
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
helper.Events.Input.ButtonPressed += this.OnButtonPressed;
|
helper.Events.Input.ButtonPressed += this.OnButtonPressed;
|
||||||
|
@ -272,6 +283,11 @@ namespace stardew_access
|
||||||
|
|
||||||
if(!ReadTile.isReadingTile && readTile)
|
if(!ReadTile.isReadingTile && readTile)
|
||||||
ReadTile.run();
|
ReadTile.run();
|
||||||
|
|
||||||
|
if (!isNarratingHudMessage)
|
||||||
|
{
|
||||||
|
narrateHudMessages();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnButtonPressed(object sender, ButtonPressedEventArgs e)
|
private void OnButtonPressed(object sender, ButtonPressedEventArgs e)
|
||||||
|
@ -339,5 +355,41 @@ namespace stardew_access
|
||||||
|
|
||||||
Game1.setMousePosition(x, y);
|
Game1.setMousePosition(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async void narrateHudMessages()
|
||||||
|
{
|
||||||
|
isNarratingHudMessage = true;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if(Game1.hudMessages.Count > 0)
|
||||||
|
{
|
||||||
|
int lastIndex = Game1.hudMessages.Count - 1;
|
||||||
|
HUDMessage lastMessage = Game1.hudMessages[lastIndex];
|
||||||
|
if (!lastMessage.noIcon)
|
||||||
|
{
|
||||||
|
string toSpeak = lastMessage.Message;
|
||||||
|
string searchQuery = toSpeak;
|
||||||
|
|
||||||
|
searchQuery = Regex.Replace(toSpeak, @"[\d+]", string.Empty);
|
||||||
|
searchQuery.Trim();
|
||||||
|
|
||||||
|
|
||||||
|
if (hudMessageQueryKey != searchQuery)
|
||||||
|
{
|
||||||
|
hudMessageQueryKey = searchQuery;
|
||||||
|
|
||||||
|
ScreenReader.say(toSpeak, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
MainClass.monitor.Log($"Unable to narrate hud messages:\n{e.Message}\n{e.StackTrace}", LogLevel.Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
await Task.Delay(1000);
|
||||||
|
isNarratingHudMessage = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue