Made Load Game Menu accessible, organised code
This commit is contained in:
115
stardew-access/Patches/DialoguePatch.cs
Normal file
115
stardew-access/Patches/DialoguePatch.cs
Normal file
@@ -0,0 +1,115 @@
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using StardewModdingAPI;
|
||||
using StardewValley;
|
||||
using StardewValley.Menus;
|
||||
using System.Text;
|
||||
|
||||
namespace stardew_access.Patches
|
||||
{
|
||||
internal class DialoguePatch
|
||||
{
|
||||
public static void CharachterDialoguePatch(DialogueBox __instance, SpriteBatch b)
|
||||
{
|
||||
try
|
||||
{
|
||||
Dialogue dialogue = __instance.characterDialogue;
|
||||
string speakerName = dialogue.speaker.Name;
|
||||
List<string> dialogues = dialogue.dialogues;
|
||||
int dialogueIndex = dialogue.currentDialogueIndex;
|
||||
MainClass.monitor.Log("" + dialogue.isCurrentStringContinuedOnNextScreen, LogLevel.Debug);
|
||||
string toSpeak = $"{speakerName} said, {dialogues[dialogueIndex]}";
|
||||
|
||||
ScreenReader.sayWithChecker(toSpeak, false);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
MainClass.monitor.Log($"Unable to narrate dialog:\n{e.StackTrace}", LogLevel.Error);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void HoverTextPatch(string? text, int moneyAmountToDisplayAtBottom = -1, string? boldTitleText = null, string[]? buffIconsToDisplay = null, Item? hoveredItem = null, CraftingRecipe? craftingIngredients = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
StringBuilder toSpeak = new StringBuilder();
|
||||
|
||||
#region Add title if any
|
||||
if (boldTitleText != null)
|
||||
toSpeak.Append($"{boldTitleText}.\n");
|
||||
#endregion
|
||||
|
||||
#region Add the base text
|
||||
toSpeak.Append(text);
|
||||
#endregion
|
||||
|
||||
#region Add crafting ingredients
|
||||
if (craftingIngredients != null)
|
||||
{
|
||||
|
||||
toSpeak.Append($"\n{craftingIngredients.description}");
|
||||
toSpeak.Append("\nIngredients\n");
|
||||
|
||||
craftingIngredients.recipeList.ToList().ForEach(recipe =>
|
||||
{
|
||||
int count = recipe.Value;
|
||||
int item = recipe.Key;
|
||||
string name = craftingIngredients.getNameFromIndex(item);
|
||||
|
||||
toSpeak.Append($" ,{count} {name}");
|
||||
});
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Add health & stamina
|
||||
if (hoveredItem is StardewValley.Object && (hoveredItem as StardewValley.Object).Edibility != -300)
|
||||
{
|
||||
int stamina_recovery = (hoveredItem as StardewValley.Object).staminaRecoveredOnConsumption();
|
||||
toSpeak.Append($"{stamina_recovery} Energy\n");
|
||||
if (stamina_recovery >= 0)
|
||||
{
|
||||
int health_recovery = (hoveredItem as StardewValley.Object).healthRecoveredOnConsumption();
|
||||
toSpeak.Append($"{health_recovery} Health");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Add buff items (effects like +1 walking speed)
|
||||
if (buffIconsToDisplay != null)
|
||||
{
|
||||
for (int i = 0; i < buffIconsToDisplay.Length; i++)
|
||||
{
|
||||
string buffName = ((Convert.ToInt32(buffIconsToDisplay[i]) > 0) ? "+" : "") + buffIconsToDisplay[i] + " ";
|
||||
if (i <= 11)
|
||||
{
|
||||
buffName = Game1.content.LoadString("Strings\\UI:ItemHover_Buff" + i, buffName);
|
||||
}
|
||||
try
|
||||
{
|
||||
int count = int.Parse(buffName.Substring(0, buffName.IndexOf(' ')));
|
||||
MainClass.monitor.Log("" + count);
|
||||
if (count != 0)
|
||||
toSpeak.Append($"{buffName}\n");
|
||||
}
|
||||
catch (Exception) { }
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Add money
|
||||
if (moneyAmountToDisplayAtBottom != -1)
|
||||
toSpeak.Append($"\nValue: {moneyAmountToDisplayAtBottom} coins\n");
|
||||
#endregion
|
||||
|
||||
#region Narrate toSpeak
|
||||
ScreenReader.sayWithChecker(toSpeak.ToString(), true);
|
||||
#endregion
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
MainClass.monitor.Log($"Unable to narrate dialog:\n{e.StackTrace}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
91
stardew-access/Patches/MenuPatch.cs
Normal file
91
stardew-access/Patches/MenuPatch.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using StardewModdingAPI;
|
||||
using StardewValley;
|
||||
using StardewValley.Menus;
|
||||
|
||||
namespace stardew_access.Patches
|
||||
{
|
||||
internal class MenuPatch
|
||||
{
|
||||
|
||||
public static void TitleMenuPatch(TitleMenu __instance)
|
||||
{
|
||||
try
|
||||
{
|
||||
string toSpeak = "";
|
||||
|
||||
__instance.buttons.ForEach(component =>
|
||||
{
|
||||
if (component.containsPoint(Game1.getMousePosition(true).X, Game1.getMousePosition(true).Y))
|
||||
{
|
||||
string name = component.name;
|
||||
string label = component.label;
|
||||
toSpeak = $"{name} {label} Button";
|
||||
}
|
||||
});
|
||||
|
||||
if(__instance.muteMusicButton.containsPoint(Game1.getMousePosition(true).X,Game1.getMousePosition(true).Y))
|
||||
{
|
||||
toSpeak = "Mute Music Button";
|
||||
}
|
||||
|
||||
if (__instance.aboutButton.containsPoint(Game1.getMousePosition(true).X, Game1.getMousePosition(true).Y))
|
||||
{
|
||||
toSpeak = "About Button";
|
||||
}
|
||||
|
||||
if (__instance.languageButton.containsPoint(Game1.getMousePosition(true).X, Game1.getMousePosition(true).Y))
|
||||
{
|
||||
toSpeak = "Language Button";
|
||||
}
|
||||
|
||||
if (__instance.windowedButton.containsPoint(Game1.getMousePosition(true).X, Game1.getMousePosition(true).Y))
|
||||
{
|
||||
toSpeak = "Fullscreen toggle Button";
|
||||
}
|
||||
|
||||
if (TitleMenu.subMenu != null && __instance.backButton.containsPoint(Game1.getMousePosition(true).X, Game1.getMousePosition(true).Y))
|
||||
{
|
||||
string text = "Back Button";
|
||||
ScreenReader.sayWithChecker(text, true);
|
||||
}
|
||||
|
||||
if (TitleMenu.subMenu == null && toSpeak != "")
|
||||
ScreenReader.sayWithChecker(toSpeak, true);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
MainClass.monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
public static void LoadGameMenuPatch(LoadGameMenu.SaveFileSlot __instance, LoadGameMenu ___menu, int i)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (___menu.slotButtons[i].containsPoint(Game1.getMousePosition(true).X, Game1.getMousePosition(true).Y))
|
||||
{
|
||||
if (__instance.Farmer == null)
|
||||
return;
|
||||
|
||||
String farmerName = __instance.Farmer.Name;
|
||||
String farmName = __instance.Farmer.farmName;
|
||||
String money = __instance.Farmer.Money.ToString();
|
||||
String hoursPlayed = Utility.getHoursMinutesStringFromMilliseconds(__instance.Farmer.millisecondsPlayed);
|
||||
string dateStringForSaveGame = ((!__instance.Farmer.dayOfMonthForSaveGame.HasValue ||
|
||||
!__instance.Farmer.seasonForSaveGame.HasValue ||
|
||||
!__instance.Farmer.yearForSaveGame.HasValue) ? __instance.Farmer.dateStringForSaveGame : Utility.getDateStringFor(__instance.Farmer.dayOfMonthForSaveGame.Value, __instance.Farmer.seasonForSaveGame.Value, __instance.Farmer.yearForSaveGame.Value));
|
||||
|
||||
string toSpeak = $"{farmName} Farm, \t\n Farmer:{farmerName}, \t\nMoney:{money}, \t\nHours Played:{hoursPlayed}, \t\nDate:{dateStringForSaveGame}";
|
||||
|
||||
ScreenReader.sayWithChecker(toSpeak, true);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
MainClass.monitor.Log($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user