Added an api for the ScreenReader.cs

master
shoaib11120 2022-01-21 15:30:16 +05:30
parent 94ca19f3bb
commit ce5e85c9b9
11 changed files with 133 additions and 100 deletions

View File

@ -107,7 +107,7 @@ namespace stardew_access
helper.ConsoleCommands.Add("refsr", "Refresh screen reader", (string commmand, string[] args) => helper.ConsoleCommands.Add("refsr", "Refresh screen reader", (string commmand, string[] args) =>
{ {
ScreenReader.initializeScreenReader(); MainClass.screenReader.InitializeScreenReader();
MainClass.monitor.Log("Screen Reader refreshed!", LogLevel.Info); MainClass.monitor.Log("Screen Reader refreshed!", LogLevel.Info);
}); });

View File

@ -23,7 +23,7 @@ namespace stardew_access.Game
return; return;
previousSlotItem = currentSlotItem; previousSlotItem = currentSlotItem;
ScreenReader.say($"{currentSlotItem.DisplayName} Selected", true); MainClass.screenReader.Say($"{currentSlotItem.DisplayName} Selected", true);
} }
// Narrates current location's name // Narrates current location's name
@ -38,7 +38,7 @@ namespace stardew_access.Game
return; return;
previousLocation = currentLocation; previousLocation = currentLocation;
ScreenReader.say($"{currentLocation.Name} Entered",true); MainClass.screenReader.Say($"{currentLocation.Name} Entered",true);
} }
public static void SnapMouseToPlayer() public static void SnapMouseToPlayer()
@ -89,7 +89,7 @@ namespace stardew_access.Game
{ {
MainClass.hudMessageQueryKey = searchQuery; MainClass.hudMessageQueryKey = searchQuery;
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
} }
} }
} }

View File

@ -33,7 +33,7 @@ namespace stardew_access.Game
{ {
if (!manuallyTriggered && prevTile != gt) if (!manuallyTriggered && prevTile != gt)
{ {
ScreenReader.prevTextTile = " "; MainClass.screenReader.prevTextTile = " ";
} }
Dictionary<Vector2, Netcode.NetRef<TerrainFeature>> terrainFeature = Game1.currentLocation.terrainFeatures.FieldDict; Dictionary<Vector2, Netcode.NetRef<TerrainFeature>> terrainFeature = Game1.currentLocation.terrainFeatures.FieldDict;
@ -45,7 +45,7 @@ namespace stardew_access.Game
NPC npc = Game1.currentLocation.isCharacterAtTile(gt); NPC npc = Game1.currentLocation.isCharacterAtTile(gt);
toSpeak = npc.displayName; toSpeak = npc.displayName;
} }
else if(getFarmAnimalAt(Game1.currentLocation, x, y) != null) else if (getFarmAnimalAt(Game1.currentLocation, x, y) != null)
{ {
toSpeak = getFarmAnimalAt(Game1.currentLocation, x, y); toSpeak = getFarmAnimalAt(Game1.currentLocation, x, y);
} }
@ -77,11 +77,11 @@ namespace stardew_access.Game
{ {
toSpeak = "Ladder"; toSpeak = "Ladder";
} }
else if(getBuildingAtTile(x, y) != null) else if (getBuildingAtTile(x, y) != null)
{ {
toSpeak = getBuildingAtTile(x, y); toSpeak = getBuildingAtTile(x, y);
} }
else if(getJunimoBundleAt(x, y) != null) else if (getJunimoBundleAt(x, y) != null)
{ {
toSpeak = getJunimoBundleAt(x, y); toSpeak = getJunimoBundleAt(x, y);
} }
@ -89,17 +89,17 @@ namespace stardew_access.Game
#region Narrate toSpeak #region Narrate toSpeak
if (toSpeak != " ") if (toSpeak != " ")
if (manuallyTriggered) if (manuallyTriggered)
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
else else
ScreenReader.sayWithTileQuery(toSpeak, x, y, true); MainClass.screenReader.SayWithTileQuery(toSpeak, x, y, true);
#endregion #endregion
#region Play colliding sound effect #region Play colliding sound effect
if (isCollidingAtTile(x, y) && prevTile != gt) if (isCollidingAtTile(x, y) && prevTile != gt)
{ {
Game1.playSound("colliding"); Game1.playSound("colliding");
} }
#endregion #endregion
prevTile = gt; prevTile = gt;

View File

@ -22,6 +22,7 @@ namespace stardew_access
AutoHotkeyEngine ahk; AutoHotkeyEngine ahk;
public static string hudMessageQueryKey = ""; public static string hudMessageQueryKey = "";
public static Radar radarFeature; public static Radar radarFeature;
public static ScreenReader screenReader;
/********* /*********
** Public methods ** Public methods
@ -50,7 +51,8 @@ namespace stardew_access
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);
} }
ScreenReader.initializeScreenReader(); screenReader = new ScreenReader();
screenReader.InitializeScreenReader();
CustomSoundEffects.Initialize(helper); CustomSoundEffects.Initialize(helper);
@ -67,6 +69,12 @@ namespace stardew_access
helper.Events.GameLoop.UpdateTicked += this.onUpdateTicked; helper.Events.GameLoop.UpdateTicked += this.onUpdateTicked;
} }
/// <summary>Returns the Screen Reader class for other mods to use.</summary>
public override object GetApi()
{
return new ScreenReader();
}
private void onUpdateTicked(object sender, UpdateTickedEventArgs e) private void onUpdateTicked(object sender, UpdateTickedEventArgs e)
{ {
if (!Context.IsPlayerFree) if (!Context.IsPlayerFree)
@ -104,28 +112,28 @@ namespace stardew_access
if (Equals(e.Button, SButton.H)) if (Equals(e.Button, SButton.H))
{ {
string toSpeak = $"Health is {CurrentPlayer.getHealth()} and Stamina is {CurrentPlayer.getStamina()}"; string toSpeak = $"Health is {CurrentPlayer.getHealth()} and Stamina is {CurrentPlayer.getStamina()}";
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
} }
// Narrate Position // Narrate Position
if (Equals(e.Button, SButton.K)) if (Equals(e.Button, SButton.K))
{ {
string toSpeak = $"X: {CurrentPlayer.getPositionX()} , Y: {CurrentPlayer.getPositionY()}"; string toSpeak = $"X: {CurrentPlayer.getPositionX()} , Y: {CurrentPlayer.getPositionY()}";
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
} }
// Narrate money at hand // Narrate money at hand
if (Equals(e.Button, SButton.R)) if (Equals(e.Button, SButton.R))
{ {
string toSpeak = $"You have {CurrentPlayer.getMoney()}g"; string toSpeak = $"You have {CurrentPlayer.getMoney()}g";
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
} }
// Narrate time and season // Narrate time and season
if (Equals(e.Button, SButton.Q)) if (Equals(e.Button, SButton.Q))
{ {
string toSpeak = $"Time is {CurrentPlayer.getTimeOfDay()} and it is {CurrentPlayer.getDay()} {CurrentPlayer.getDate()} of {CurrentPlayer.getSeason()}"; string toSpeak = $"Time is {CurrentPlayer.getTimeOfDay()} and it is {CurrentPlayer.getDay()} {CurrentPlayer.getDate()} of {CurrentPlayer.getSeason()}";
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
} }
// Manual read tile // Manual read tile

View File

@ -42,7 +42,7 @@ namespace stardew_access.Patches
toSpeak += $"{message.message}, "; toSpeak += $"{message.message}, ";
}); });
if (toSpeak != " ") if (toSpeak != " ")
ScreenReader.sayWithChatChecker(toSpeak, false); MainClass.screenReader.SayWithChatChecker(toSpeak, false);
#endregion #endregion
} }
} }
@ -78,7 +78,7 @@ namespace stardew_access.Patches
toSpeak += $"{message.message}, "; toSpeak += $"{message.message}, ";
}); });
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
isChatRunning = false; isChatRunning = false;
} }
} }

View File

@ -49,9 +49,9 @@ namespace stardew_access.Patches
if (toSpeak != " ") if (toSpeak != " ")
{ {
if (hasResponses) if (hasResponses)
ScreenReader.sayWithChecker(toSpeak, false); MainClass.screenReader.SayWithChecker(toSpeak, false);
else else
ScreenReader.sayWithChecker(toSpeak, true); MainClass.screenReader.SayWithChecker(toSpeak, true);
} }
} }
else if (__instance.isQuestion) else if (__instance.isQuestion)
@ -80,9 +80,9 @@ namespace stardew_access.Patches
if (toSpeak != " ") if (toSpeak != " ")
{ {
if (hasResponses) if (hasResponses)
ScreenReader.sayWithChecker(toSpeak, false); MainClass.screenReader.SayWithChecker(toSpeak, false);
else else
ScreenReader.sayWithChecker(toSpeak, true); MainClass.screenReader.SayWithChecker(toSpeak, true);
} }
} }
else if (Game1.activeClickableMenu is DialogueBox) else if (Game1.activeClickableMenu is DialogueBox)
@ -91,7 +91,7 @@ namespace stardew_access.Patches
if (currentDialogue != __instance.getCurrentString()) if (currentDialogue != __instance.getCurrentString())
{ {
currentDialogue = __instance.getCurrentString(); currentDialogue = __instance.getCurrentString();
ScreenReader.say(__instance.getCurrentString(), true); MainClass.screenReader.Say(__instance.getCurrentString(), true);
} }
} }
} }
@ -261,9 +261,9 @@ namespace stardew_access.Patches
if (toSpeak.ToString() != " ") if (toSpeak.ToString() != " ")
{ {
if (Context.IsPlayerFree) if (Context.IsPlayerFree)
ScreenReader.sayWithChecker(toSpeak.ToString(), true); // Normal Checker MainClass.screenReader.SayWithChecker(toSpeak.ToString(), true); // Normal Checker
else else
ScreenReader.sayWithMenuChecker(toSpeak.ToString(), true); // Menu Checker MainClass.screenReader.SayWithMenuChecker(toSpeak.ToString(), true); // Menu Checker
} }
#endregion #endregion
} }

View File

@ -47,7 +47,7 @@ namespace stardew_access.Patches
{ {
shopMenuQueryKey = toSpeak; shopMenuQueryKey = toSpeak;
hoveredItemQueryKey = ""; hoveredItemQueryKey = "";
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
Game1.playSound("drop_item"); Game1.playSound("drop_item");
} }
return; return;
@ -59,7 +59,7 @@ namespace stardew_access.Patches
{ {
shopMenuQueryKey = toSpeak; shopMenuQueryKey = toSpeak;
hoveredItemQueryKey = ""; hoveredItemQueryKey = "";
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
} }
return; return;
} }
@ -70,7 +70,7 @@ namespace stardew_access.Patches
{ {
shopMenuQueryKey = toSpeak; shopMenuQueryKey = toSpeak;
hoveredItemQueryKey = ""; hoveredItemQueryKey = "";
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
} }
return; return;
} }
@ -117,7 +117,7 @@ namespace stardew_access.Patches
{ {
shopMenuQueryKey = toSpeak; shopMenuQueryKey = toSpeak;
hoveredItemQueryKey = ""; hoveredItemQueryKey = "";
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
} }
} }
#endregion #endregion
@ -146,7 +146,7 @@ namespace stardew_access.Patches
if (gameMenuQueryKey != toSpeak) if (gameMenuQueryKey != toSpeak)
{ {
gameMenuQueryKey = toSpeak; gameMenuQueryKey = toSpeak;
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
} }
return; return;
} }
@ -175,7 +175,7 @@ namespace stardew_access.Patches
if (geodeMenuQueryKey != toSpeak) if (geodeMenuQueryKey != toSpeak)
{ {
geodeMenuQueryKey = toSpeak; geodeMenuQueryKey = toSpeak;
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
} }
return; return;
} }
@ -188,7 +188,7 @@ namespace stardew_access.Patches
if (geodeMenuQueryKey != toSpeak) if (geodeMenuQueryKey != toSpeak)
{ {
geodeMenuQueryKey = toSpeak; geodeMenuQueryKey = toSpeak;
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
} }
return; return;
} }
@ -200,7 +200,7 @@ namespace stardew_access.Patches
if (geodeMenuQueryKey != toSpeak) if (geodeMenuQueryKey != toSpeak)
{ {
geodeMenuQueryKey = toSpeak; geodeMenuQueryKey = toSpeak;
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
Game1.playSound("drop_item"); Game1.playSound("drop_item");
} }
return; return;
@ -213,7 +213,7 @@ namespace stardew_access.Patches
if (geodeMenuQueryKey != toSpeak) if (geodeMenuQueryKey != toSpeak)
{ {
geodeMenuQueryKey = toSpeak; geodeMenuQueryKey = toSpeak;
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
} }
return; return;
} }
@ -225,7 +225,7 @@ namespace stardew_access.Patches
if (geodeMenuQueryKey != toSpeak) if (geodeMenuQueryKey != toSpeak)
{ {
geodeMenuQueryKey = toSpeak; geodeMenuQueryKey = toSpeak;
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
} }
return; return;
} }
@ -270,7 +270,7 @@ namespace stardew_access.Patches
itemGrabMenuQueryKey = toSpeak; itemGrabMenuQueryKey = toSpeak;
hoveredItemQueryKey = ""; hoveredItemQueryKey = "";
gameMenuQueryKey = ""; gameMenuQueryKey = "";
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
} }
return; return;
} }
@ -282,7 +282,7 @@ namespace stardew_access.Patches
itemGrabMenuQueryKey = toSpeak; itemGrabMenuQueryKey = toSpeak;
gameMenuQueryKey = ""; gameMenuQueryKey = "";
hoveredItemQueryKey = ""; hoveredItemQueryKey = "";
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
} }
return; return;
} }
@ -295,7 +295,7 @@ namespace stardew_access.Patches
itemGrabMenuQueryKey = toSpeak; itemGrabMenuQueryKey = toSpeak;
gameMenuQueryKey = ""; gameMenuQueryKey = "";
hoveredItemQueryKey = ""; hoveredItemQueryKey = "";
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
} }
return; return;
} }
@ -308,7 +308,7 @@ namespace stardew_access.Patches
itemGrabMenuQueryKey = toSpeak; itemGrabMenuQueryKey = toSpeak;
gameMenuQueryKey = ""; gameMenuQueryKey = "";
hoveredItemQueryKey = ""; hoveredItemQueryKey = "";
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
} }
return; return;
} }
@ -321,7 +321,7 @@ namespace stardew_access.Patches
itemGrabMenuQueryKey = toSpeak; itemGrabMenuQueryKey = toSpeak;
gameMenuQueryKey = ""; gameMenuQueryKey = "";
hoveredItemQueryKey = ""; hoveredItemQueryKey = "";
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
} }
return; return;
} }
@ -335,7 +335,7 @@ namespace stardew_access.Patches
itemGrabMenuQueryKey = toSpeak; itemGrabMenuQueryKey = toSpeak;
gameMenuQueryKey = ""; gameMenuQueryKey = "";
hoveredItemQueryKey = ""; hoveredItemQueryKey = "";
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
} }
return; return;
} }
@ -349,7 +349,7 @@ namespace stardew_access.Patches
itemGrabMenuQueryKey = toSpeak; itemGrabMenuQueryKey = toSpeak;
gameMenuQueryKey = ""; gameMenuQueryKey = "";
hoveredItemQueryKey = ""; hoveredItemQueryKey = "";
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
} }
return; return;
} }
@ -362,7 +362,7 @@ namespace stardew_access.Patches
itemGrabMenuQueryKey = toSpeak; itemGrabMenuQueryKey = toSpeak;
gameMenuQueryKey = ""; gameMenuQueryKey = "";
hoveredItemQueryKey = ""; hoveredItemQueryKey = "";
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
Game1.playSound("drop_item"); Game1.playSound("drop_item");
} }
return; return;
@ -404,7 +404,7 @@ namespace stardew_access.Patches
itemGrabMenuQueryKey = toSpeak; itemGrabMenuQueryKey = toSpeak;
gameMenuQueryKey = ""; gameMenuQueryKey = "";
hoveredItemQueryKey = ""; hoveredItemQueryKey = "";
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
} }
return; return;
} }
@ -542,7 +542,7 @@ namespace stardew_access.Patches
{ {
craftingPageQueryKey = toSpeak; craftingPageQueryKey = toSpeak;
hoveredItemQueryKey = ""; hoveredItemQueryKey = "";
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
} }
return; return;
} }
@ -554,7 +554,7 @@ namespace stardew_access.Patches
{ {
craftingPageQueryKey = toSpeak; craftingPageQueryKey = toSpeak;
hoveredItemQueryKey = ""; hoveredItemQueryKey = "";
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
} }
return; return;
} }
@ -566,7 +566,7 @@ namespace stardew_access.Patches
{ {
craftingPageQueryKey = toSpeak; craftingPageQueryKey = toSpeak;
hoveredItemQueryKey = ""; hoveredItemQueryKey = "";
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
} }
return; return;
} }
@ -578,7 +578,7 @@ namespace stardew_access.Patches
{ {
craftingPageQueryKey = toSpeak; craftingPageQueryKey = toSpeak;
hoveredItemQueryKey = ""; hoveredItemQueryKey = "";
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
Game1.playSound("drop_item"); Game1.playSound("drop_item");
} }
return; return;
@ -655,7 +655,7 @@ namespace stardew_access.Patches
craftingPageQueryKey = toSpeak; craftingPageQueryKey = toSpeak;
gameMenuQueryKey = ""; gameMenuQueryKey = "";
hoveredItemQueryKey = ""; hoveredItemQueryKey = "";
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
} }
return; return;
} }
@ -722,7 +722,7 @@ namespace stardew_access.Patches
inventoryPageQueryKey = toSpeak; inventoryPageQueryKey = toSpeak;
gameMenuQueryKey = ""; gameMenuQueryKey = "";
hoveredItemQueryKey = ""; hoveredItemQueryKey = "";
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
Game1.playSound("drop_item"); Game1.playSound("drop_item");
} }
return; return;
@ -736,7 +736,7 @@ namespace stardew_access.Patches
inventoryPageQueryKey = toSpeak; inventoryPageQueryKey = toSpeak;
gameMenuQueryKey = ""; gameMenuQueryKey = "";
hoveredItemQueryKey = ""; hoveredItemQueryKey = "";
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
} }
return; return;
} }
@ -749,7 +749,7 @@ namespace stardew_access.Patches
inventoryPageQueryKey = toSpeak; inventoryPageQueryKey = toSpeak;
gameMenuQueryKey = ""; gameMenuQueryKey = "";
hoveredItemQueryKey = ""; hoveredItemQueryKey = "";
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
} }
return; return;
} }
@ -762,7 +762,7 @@ namespace stardew_access.Patches
itemGrabMenuQueryKey = toSpeak; itemGrabMenuQueryKey = toSpeak;
gameMenuQueryKey = ""; gameMenuQueryKey = "";
hoveredItemQueryKey = ""; hoveredItemQueryKey = "";
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
} }
return; return;
} }
@ -776,7 +776,7 @@ namespace stardew_access.Patches
itemGrabMenuQueryKey = toSpeak; itemGrabMenuQueryKey = toSpeak;
gameMenuQueryKey = ""; gameMenuQueryKey = "";
hoveredItemQueryKey = ""; hoveredItemQueryKey = "";
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
} }
return; return;
} }
@ -872,7 +872,7 @@ namespace stardew_access.Patches
inventoryPageQueryKey = toSpeak; inventoryPageQueryKey = toSpeak;
gameMenuQueryKey = ""; gameMenuQueryKey = "";
hoveredItemQueryKey = ""; hoveredItemQueryKey = "";
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
} }
return; return;
} }
@ -935,7 +935,7 @@ namespace stardew_access.Patches
{ {
gameMenuQueryKey = ""; gameMenuQueryKey = "";
optionsPageQueryKey = toSpeak; optionsPageQueryKey = toSpeak;
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
} }
return; return;
} }
@ -959,7 +959,7 @@ namespace stardew_access.Patches
{ {
gameMenuQueryKey = ""; gameMenuQueryKey = "";
exitPageQueryKey = toSpeak; exitPageQueryKey = toSpeak;
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
} }
return; return;
} }
@ -971,7 +971,7 @@ namespace stardew_access.Patches
{ {
gameMenuQueryKey = ""; gameMenuQueryKey = "";
exitPageQueryKey = toSpeak; exitPageQueryKey = toSpeak;
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
} }
return; return;
} }
@ -1110,7 +1110,7 @@ namespace stardew_access.Patches
if (hoveredItemQueryKey != $"{toSpeak}:{i}") if (hoveredItemQueryKey != $"{toSpeak}:{i}")
{ {
hoveredItemQueryKey = $"{toSpeak}:{i}"; hoveredItemQueryKey = $"{toSpeak}:{i}";
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
} }
return true; return true;
} }

View File

@ -52,13 +52,13 @@ namespace stardew_access.Patches
if(__instance.nextPageButton != null && __instance.nextPageButton.containsPoint(x, y)) if(__instance.nextPageButton != null && __instance.nextPageButton.containsPoint(x, y))
{ {
ScreenReader.sayWithMenuChecker($"Next Page Button", true); MainClass.screenReader.SayWithMenuChecker($"Next Page Button", true);
return; return;
} }
if (__instance.previousPageButton != null && __instance.previousPageButton.containsPoint(x, y)) if (__instance.previousPageButton != null && __instance.previousPageButton.containsPoint(x, y))
{ {
ScreenReader.sayWithMenuChecker($"Previous Page Button", true); MainClass.screenReader.SayWithMenuChecker($"Previous Page Button", true);
return; return;
} }
@ -66,7 +66,7 @@ namespace stardew_access.Patches
{ {
if(__instance.languages[i].containsPoint(x, y)) if(__instance.languages[i].containsPoint(x, y))
{ {
ScreenReader.sayWithMenuChecker($"{__instance.languageList[i]} Button", true); MainClass.screenReader.SayWithMenuChecker($"{__instance.languageList[i]} Button", true);
break; break;
} }
} }
@ -86,7 +86,7 @@ namespace stardew_access.Patches
{ {
if(___elevators[i].containsPoint(x, y)) if(___elevators[i].containsPoint(x, y))
{ {
ScreenReader.sayWithMenuChecker($"{___elevators[i].name} level", true); MainClass.screenReader.SayWithMenuChecker($"{___elevators[i].name} level", true);
break; break;
} }
} }
@ -105,7 +105,7 @@ namespace stardew_access.Patches
___textBox.SelectMe(); ___textBox.SelectMe();
string toSpeak = $"{title}"; string toSpeak = $"{title}";
ScreenReader.sayWithChecker(toSpeak, true); MainClass.screenReader.SayWithChecker(toSpeak, true);
} }
catch (Exception e) catch (Exception e)
{ {
@ -119,13 +119,13 @@ namespace stardew_access.Patches
{ {
int x = Game1.getMousePosition(true).X, y = Game1.getMousePosition(true).Y; int x = Game1.getMousePosition(true).X, y = Game1.getMousePosition(true).Y;
ScreenReader.sayWithMenuChecker(___message, true); MainClass.screenReader.SayWithMenuChecker(___message, true);
if(__instance.okButton.containsPoint(x, y)) if(__instance.okButton.containsPoint(x, y))
{ {
ScreenReader.sayWithMenuChecker("Ok Button", false); MainClass.screenReader.SayWithMenuChecker("Ok Button", false);
} else if (__instance.cancelButton.containsPoint(x, y)) } else if (__instance.cancelButton.containsPoint(x, y))
{ {
ScreenReader.sayWithMenuChecker("Cancel Button", false); MainClass.screenReader.SayWithMenuChecker("Cancel Button", false);
} }
} }
catch (Exception e) catch (Exception e)
@ -187,10 +187,10 @@ namespace stardew_access.Patches
} }
if (toSpeak != " ") if (toSpeak != " ")
ScreenReader.sayWithMenuChecker(toSpeak, true); MainClass.screenReader.SayWithMenuChecker(toSpeak, true);
else if (__instance.isProfessionChooser && currentLevelUpTitle != $"{___title}. Select a new profession.") else if (__instance.isProfessionChooser && currentLevelUpTitle != $"{___title}. Select a new profession.")
{ {
ScreenReader.sayWithMenuChecker($"{___title}. Select a new profession.", true); MainClass.screenReader.SayWithMenuChecker($"{___title}. Select a new profession.", true);
currentLevelUpTitle = $"{___title}. Select a new profession."; currentLevelUpTitle = $"{___title}. Select a new profession.";
} }
} }
@ -211,14 +211,14 @@ namespace stardew_access.Patches
if (__instance.okButton.containsPoint(Game1.getMousePosition(true).X, Game1.getMousePosition(true).Y)) if (__instance.okButton.containsPoint(Game1.getMousePosition(true).X, Game1.getMousePosition(true).Y))
{ {
toSpeak = $"{total}g in total. Press left mouse button to save."; toSpeak = $"{total}g in total. Press left mouse button to save.";
ScreenReader.sayWithChecker(toSpeak, true); MainClass.screenReader.SayWithChecker(toSpeak, true);
} }
for (int i = 0; i < __instance.categories.Count; i++) for (int i = 0; i < __instance.categories.Count; i++)
{ {
if (__instance.categories[i].containsPoint(Game1.getMousePosition(true).X, Game1.getMousePosition(true).Y)) if (__instance.categories[i].containsPoint(Game1.getMousePosition(true).X, Game1.getMousePosition(true).Y))
{ {
toSpeak = $"Money recieved from {__instance.getCategoryName(i)}: {___categoryTotals[i]}g."; toSpeak = $"Money recieved from {__instance.getCategoryName(i)}: {___categoryTotals[i]}g.";
ScreenReader.sayWithChecker(toSpeak, true); MainClass.screenReader.SayWithChecker(toSpeak, true);
} }
} }
} }
@ -265,7 +265,7 @@ namespace stardew_access.Patches
toSpeak += "\t\n Left click to accept quest."; toSpeak += "\t\n Left click to accept quest.";
__instance.acceptQuestButton.snapMouseCursorToCenter(); __instance.acceptQuestButton.snapMouseCursorToCenter();
} }
ScreenReader.say(toSpeak, false); MainClass.screenReader.Say(toSpeak, false);
} }
#endregion #endregion
@ -278,7 +278,7 @@ namespace stardew_access.Patches
string label = c.label; string label = c.label;
if (c.containsPoint(Game1.getMousePosition().X, Game1.getMousePosition().Y)) if (c.containsPoint(Game1.getMousePosition().X, Game1.getMousePosition().Y))
ScreenReader.sayWithChecker($"Grab: {name} \t\n {label}", false); MainClass.screenReader.SayWithChecker($"Grab: {name} \t\n {label}", false);
} }
} }
#endregion #endregion

View File

@ -23,7 +23,7 @@ namespace stardew_access.Patches
toSpeak = $"Left Quest:\n\t{toSpeak}\n\tPress left click to accept this quest."; toSpeak = $"Left Quest:\n\t{toSpeak}\n\tPress left click to accept this quest.";
ScreenReader.sayWithMenuChecker(toSpeak, true); MainClass.screenReader.SayWithMenuChecker(toSpeak, true);
return; return;
} }
@ -33,7 +33,7 @@ namespace stardew_access.Patches
toSpeak = $"Right Quest:\n\t{toSpeak}\n\tPress left click to accept this quest."; toSpeak = $"Right Quest:\n\t{toSpeak}\n\tPress left click to accept this quest.";
ScreenReader.sayWithMenuChecker(toSpeak, true); MainClass.screenReader.SayWithMenuChecker(toSpeak, true);
return; return;
} }
} }
@ -99,7 +99,7 @@ namespace stardew_access.Patches
if (Game1.dayOfMonth == i + 1) if (Game1.dayOfMonth == i + 1)
toSpeak += $", Current"; toSpeak += $", Current";
ScreenReader.sayWithChecker(toSpeak, true); MainClass.screenReader.SayWithChecker(toSpeak, true);
} }
} }
#endregion #endregion
@ -114,7 +114,7 @@ namespace stardew_access.Patches
if (currentDailyQuestText != toSpeak) if (currentDailyQuestText != toSpeak)
{ {
currentDailyQuestText = toSpeak; currentDailyQuestText = toSpeak;
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
} }
} }
else else
@ -134,7 +134,7 @@ namespace stardew_access.Patches
__instance.acceptQuestButton.snapMouseCursorToCenter(); __instance.acceptQuestButton.snapMouseCursorToCenter();
} }
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
} }
} }
#endregion #endregion
@ -171,7 +171,7 @@ namespace stardew_access.Patches
toSpeak += ___pages[___currentPage][i].ShouldDisplayAsComplete() ? " completed!" : ""; toSpeak += ___pages[___currentPage][i].ShouldDisplayAsComplete() ? " completed!" : "";
if (__instance.questLogButtons[i].containsPoint(Game1.getOldMouseX(), Game1.getOldMouseY())) if (__instance.questLogButtons[i].containsPoint(Game1.getOldMouseX(), Game1.getOldMouseY()))
{ {
ScreenReader.sayWithChecker(toSpeak, true); MainClass.screenReader.SayWithChecker(toSpeak, true);
} }
} }
} }
@ -229,7 +229,7 @@ namespace stardew_access.Patches
if (snapMouseToRewardBox) if (snapMouseToRewardBox)
__instance.rewardBox.snapMouseCursorToCenter(); __instance.rewardBox.snapMouseCursorToCenter();
ScreenReader.sayWithChecker(toSpeak, true); MainClass.screenReader.SayWithChecker(toSpeak, true);
#endregion #endregion
} }
} }

View File

@ -45,7 +45,7 @@ namespace stardew_access.Patches
#endregion #endregion
if (toSpeak != " ") if (toSpeak != " ")
ScreenReader.sayWithChecker(toSpeak, true); MainClass.screenReader.SayWithChecker(toSpeak, true);
} }
catch (Exception e) catch (Exception e)
{ {
@ -95,11 +95,11 @@ namespace stardew_access.Patches
if (TitleMenu.subMenu != null && __instance.backButton.containsPoint(Game1.getMousePosition(true).X, Game1.getMousePosition(true).Y)) if (TitleMenu.subMenu != null && __instance.backButton.containsPoint(Game1.getMousePosition(true).X, Game1.getMousePosition(true).Y))
{ {
string text = "Back Button"; string text = "Back Button";
ScreenReader.sayWithChecker(text, true); MainClass.screenReader.SayWithChecker(text, true);
} }
if (TitleMenu.subMenu == null && toSpeak != "") if (TitleMenu.subMenu == null && toSpeak != "")
ScreenReader.sayWithChecker(toSpeak, true); MainClass.screenReader.SayWithChecker(toSpeak, true);
} }
catch (Exception e) catch (Exception e)
{ {
@ -119,7 +119,7 @@ namespace stardew_access.Patches
#region Farms #region Farms
if (___menu.deleteButtons.Count > 0 && ___menu.deleteButtons[i].containsPoint(x, y)) if (___menu.deleteButtons.Count > 0 && ___menu.deleteButtons[i].containsPoint(x, y))
{ {
ScreenReader.sayWithChecker($"Delete {__instance.Farmer.farmName} Farm", true); MainClass.screenReader.SayWithChecker($"Delete {__instance.Farmer.farmName} Farm", true);
return; return;
} }
@ -128,14 +128,14 @@ namespace stardew_access.Patches
// Used diff. functions to narrate to prevent it from speaking the message again on selecting another button. // Used diff. functions to narrate to prevent it from speaking the message again on selecting another button.
string message = "Really delete farm?"; string message = "Really delete farm?";
ScreenReader.sayWithChecker(message, true); MainClass.screenReader.SayWithChecker(message, true);
if (___menu.okDeleteButton.containsPoint(x, y)) if (___menu.okDeleteButton.containsPoint(x, y))
{ {
ScreenReader.sayWithMenuChecker("Ok Button", false); MainClass.screenReader.SayWithMenuChecker("Ok Button", false);
} }
else if (___menu.cancelDeleteButton.containsPoint(x, y)) else if (___menu.cancelDeleteButton.containsPoint(x, y))
{ {
ScreenReader.sayWithMenuChecker("Cancel Button", false); MainClass.screenReader.SayWithMenuChecker("Cancel Button", false);
} }
return; return;
} }
@ -150,7 +150,7 @@ namespace stardew_access.Patches
string toSpeak = $"{farmName} Farm Selected, \t\n Farmer:{farmerName}, \t\nMoney:{money}, \t\nHours Played:{hoursPlayed}, \t\nDate:{dateStringForSaveGame}"; string toSpeak = $"{farmName} Farm Selected, \t\n Farmer:{farmerName}, \t\nMoney:{money}, \t\nHours Played:{hoursPlayed}, \t\nDate:{dateStringForSaveGame}";
ScreenReader.sayWithChecker(toSpeak, true); MainClass.screenReader.SayWithChecker(toSpeak, true);
#endregion #endregion
} }
} }
@ -640,7 +640,7 @@ namespace stardew_access.Patches
if(toSpeak!=" ") if(toSpeak!=" ")
{ {
ScreenReader.say(toSpeak, true); MainClass.screenReader.Say(toSpeak, true);
} }
await Task.Delay(200); await Task.Delay(200);

View File

@ -3,12 +3,13 @@ using StardewModdingAPI;
namespace stardew_access namespace stardew_access
{ {
internal class ScreenReader public class ScreenReader
{ {
public static IAccessibleOutput? screenReader = null; public IAccessibleOutput? screenReader = null;
internal static string prevText = "", prevTextTile = " ", prevChatText = "", prevMenuText = ""; public string prevText = "", prevTextTile = " ", prevChatText = "", prevMenuText = "";
public static void initializeScreenReader() /// <summary>Initializes the screen reader.</summary>
public void InitializeScreenReader()
{ {
NvdaOutput? nvdaOutput = null; NvdaOutput? nvdaOutput = null;
JawsOutput? jawsOutput = null; JawsOutput? jawsOutput = null;
@ -45,7 +46,10 @@ namespace stardew_access
MainClass.monitor.Log($"Unable to load any screen reader!", LogLevel.Error); MainClass.monitor.Log($"Unable to load any screen reader!", LogLevel.Error);
} }
public static void say(string text, bool interrupt) /// <summary>Speaks the text via the loaded screen reader (if any).</summary>
/// <param name="text">The text to be narrated.</param>
/// <param name="interrupt">Whether to skip the currently speaking text or not.</param>
public void Say(string text, bool interrupt)
{ {
if (screenReader == null) if (screenReader == null)
return; return;
@ -53,7 +57,11 @@ namespace stardew_access
screenReader.Speak(text, interrupt); screenReader.Speak(text, interrupt);
} }
public static void sayWithChecker(string text, bool interrupt) /// <summary>Speaks the text via the loaded screen reader (if any).
/// <br/>Skips the text narration if the previously narrated text was the same as the one provided.</summary>
/// <param name="text">The text to be narrated.</param>
/// <param name="interrupt">Whether to skip the currently speaking text or not.</param>
public void SayWithChecker(string text, bool interrupt)
{ {
if (screenReader == null) if (screenReader == null)
return; return;
@ -65,7 +73,12 @@ namespace stardew_access
} }
} }
public static void sayWithMenuChecker(string text, bool interrupt) /// <summary>Speaks the text via the loaded screen reader (if any).
/// <br/>Skips the text narration if the previously narrated text was the same as the one provided.
/// <br/><br/>Use this when narrating hovered component in menus to avoid interference.</summary>
/// <param name="text">The text to be narrated.</param>
/// <param name="interrupt">Whether to skip the currently speaking text or not.</param>
public void SayWithMenuChecker(string text, bool interrupt)
{ {
if (screenReader == null) if (screenReader == null)
return; return;
@ -77,7 +90,12 @@ namespace stardew_access
} }
} }
public static void sayWithChatChecker(string text, bool interrupt) /// <summary>Speaks the text via the loaded screen reader (if any).
/// <br/>Skips the text narration if the previously narrated text was the same as the one provided.
/// <br/><br/>Use this when narrating chat messages to avoid interference.</summary>
/// <param name="text">The text to be narrated.</param>
/// <param name="interrupt">Whether to skip the currently speaking text or not.</param>
public void SayWithChatChecker(string text, bool interrupt)
{ {
if (screenReader == null) if (screenReader == null)
return; return;
@ -89,7 +107,14 @@ namespace stardew_access
} }
} }
public static void sayWithTileQuery(string text, int x, int y, bool interrupt) /// <summary>Speaks the text via the loaded screen reader (if any).
/// <br/>Skips the text narration if the previously narrated text was the same as the one provided.
/// <br/><br/>Use this when narrating texts based on tile position to avoid interference.</summary>
/// <param name="text">The text to be narrated.</param>
/// <param name="x">The X location of tile.</param>
/// <param name="y">The Y location of tile.</param>
/// <param name="interrupt">Whether to skip the currently speaking text or not.</param>
public void SayWithTileQuery(string text, int x, int y, bool interrupt)
{ {
if (screenReader == null) if (screenReader == null)
return; return;