Added heart count to animal query menu

master^2
Mohammad Shoaib Khan 2023-04-08 15:44:08 +05:30
parent 5f612a20c1
commit 4ffd9bc9bc
3 changed files with 51 additions and 14 deletions

View File

@ -346,6 +346,20 @@ namespace stardew_access
TileViewerFeature.HandleInput(); TileViewerFeature.HandleInput();
} }
public static string Translate(string translationKey)
{
if (ModHelper == null) return "null";
return ModHelper.Translation.Get(translationKey);
}
public static string Translate(string translationKey, object? tokens)
{
if (ModHelper == null) return "null";
return ModHelper.Translation.Get(translationKey, tokens);
}
private static void LogMessage(string message, LogLevel logLevel) private static void LogMessage(string message, LogLevel logLevel)
{ {
if (monitor == null) if (monitor == null)

View File

@ -11,7 +11,9 @@ namespace stardew_access.Patches
internal static FarmAnimal? animalBeingMoved = null; internal static FarmAnimal? animalBeingMoved = null;
internal static bool isOnFarm = false; internal static bool isOnFarm = false;
internal static void DrawPatch(AnimalQueryMenu __instance, bool ___confirmingSell, FarmAnimal ___animal, TextBox ___textBox, string ___parentName, bool ___movingAnimal) private static double loveLevel;
internal static void DrawPatch(AnimalQueryMenu __instance, bool ___confirmingSell, FarmAnimal ___animal, TextBox ___textBox, string ___parentName, bool ___movingAnimal, double ___loveLevel)
{ {
try try
{ {
@ -23,6 +25,8 @@ namespace stardew_access.Patches
animalQueryMenu = __instance; animalQueryMenu = __instance;
animalBeingMoved = ___animal; animalBeingMoved = ___animal;
loveLevel = ___loveLevel;
narrateAnimalDetailsOnKeyPress(___animal, ___parentName); narrateAnimalDetailsOnKeyPress(___animal, ___parentName);
narrateHoveredButton(__instance, ___animal, ___confirmingSell, x, y); narrateHoveredButton(__instance, ___animal, ___confirmingSell, x, y);
@ -44,6 +48,7 @@ namespace stardew_access.Patches
int age = (___animal.GetDaysOwned() + 1) / 28 + 1; int age = (___animal.GetDaysOwned() + 1) / 28 + 1;
string ageText = (age <= 1) ? Game1.content.LoadString("Strings\\UI:AnimalQuery_Age1") : Game1.content.LoadString("Strings\\UI:AnimalQuery_AgeN", age); string ageText = (age <= 1) ? Game1.content.LoadString("Strings\\UI:AnimalQuery_Age1") : Game1.content.LoadString("Strings\\UI:AnimalQuery_AgeN", age);
string parent = ""; string parent = "";
if ((int)___animal.age.Value < (byte)___animal.ageWhenMature.Value) if ((int)___animal.age.Value < (byte)___animal.ageWhenMature.Value)
{ {
ageText += Game1.content.LoadString("Strings\\UI:AnimalQuery_AgeBaby"); ageText += Game1.content.LoadString("Strings\\UI:AnimalQuery_AgeBaby");
@ -53,10 +58,26 @@ namespace stardew_access.Patches
parent = Game1.content.LoadString("Strings\\UI:AnimalQuery_Parent", ___parentName); parent = Game1.content.LoadString("Strings\\UI:AnimalQuery_Parent", ___parentName);
} }
// The loveLevel varies between 0 and 1
// 1 indicates 5 hearts and similarily 0 indicates 0 hearts
// the below code multiplies the loveLevel by 10 and
// the numeric value of the resultent is divided by 2 to give the number of full hearts and
// if its decimal value is above 0.5, then that indicates half a heart
double heartCount = Math.Floor(loveLevel * 10);
double remainder = (loveLevel * 10) % 1;
heartCount /= 2;
if (remainder >= 0.5)
{
heartCount += 0.5;
}
MainClass.DebugLog($"Lovelevel: {loveLevel}");
string heart = MainClass.Translate("patch.animal_query_menu.heart", new { count = heartCount });
isNarratingAnimalInfo = true; isNarratingAnimalInfo = true;
Task.Delay(200).ContinueWith(_ => { isNarratingAnimalInfo = false; }); // Adds delay Task.Delay(200).ContinueWith(_ => { isNarratingAnimalInfo = false; }); // Adds delay
MainClass.ScreenReader.Say($"Name: {name} Type: {type} \n\t Age: {ageText} {parent}", true); MainClass.ScreenReader.Say($"Name: {name} Type: {type} \n\t {ageText} {parent} \n\t {heart}", true);
} }
private static void narrateHoveredButton(AnimalQueryMenu __instance, FarmAnimal ___animal, bool ___confirmingSell, int x, int y) private static void narrateHoveredButton(AnimalQueryMenu __instance, FarmAnimal ___animal, bool ___confirmingSell, int x, int y)

View File

@ -2,15 +2,17 @@
"warnings.health": "Warning! Health is at {{value}} percent!", "warnings.health": "Warning! Health is at {{value}} percent!",
"warnings.stamina": "Warning! Stamina is at {{value}} percent!", "warnings.stamina": "Warning! Stamina is at {{value}} percent!",
"warnings.time": "Warning! Time is {{value}}", "warnings.time": "Warning! Time is {{value}}",
"grandpastory.scene0":"Grandpa, on his deathbed.", "grandpastory.scene0": "Grandpa, on his deathbed.",
"grandpastory.scene4":"Employees working in JoJa corp.", "grandpastory.scene4": "Employees working in JoJa corp.",
"grandpastory.scene5":"Employees in their cubicles, some of them look exhausted including yourself.", "grandpastory.scene5": "Employees in their cubicles, some of them look exhausted including yourself.",
"grandpastory.scene6":"You reach your desk finding grandpa's letter.", "grandpastory.scene6": "You reach your desk finding grandpa's letter.",
"grandpastory.letteropen":"Left click to open grandpa's letter", "grandpastory.letteropen": "Left click to open grandpa's letter",
"intro.scene3":"Travelling to Stardew Valley bus stop", "intro.scene3": "Travelling to Stardew Valley bus stop",
"intro.scene4":"Stardew valley 0.5 miles away", "intro.scene4": "Stardew valley 0.5 miles away",
"manuallytriggered.healthnstamina.percent":"Health is {{health}} % and Stamina is {{stamina}} %", "manuallytriggered.healthnstamina.percent": "Health is {{health}} % and Stamina is {{stamina}} %",
"manuallytriggered.healthnstamina.normal":"Health is {{health}} and Stamina is {{stamina}}", "manuallytriggered.healthnstamina.normal": "Health is {{health}} and Stamina is {{stamina}}",
"readtile.sprinkler.pressurenozzle":"Pressurized {{value}}", "readtile.sprinkler.pressurenozzle": "Pressurized {{value}}",
"readtile.sprinkler.enricher":"Enriching {{value}}" "readtile.sprinkler.enricher": "Enriching {{value}}",
} // Animal Query Menu Patch
"patch.animal_query_menu.heart": "Heart Count: {{count}}"
}