From 4ffd9bc9bcc35ea2b6a29536fd2044ea90b3f109 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Sat, 8 Apr 2023 15:44:08 +0530 Subject: [PATCH] Added heart count to animal query menu --- stardew-access/ModEntry.cs | 14 ++++++++++ .../OtherMenuPatches/AnimalQueryMenuPatch.cs | 25 ++++++++++++++++-- stardew-access/i18n/default.json | 26 ++++++++++--------- 3 files changed, 51 insertions(+), 14 deletions(-) diff --git a/stardew-access/ModEntry.cs b/stardew-access/ModEntry.cs index 7e89a4d..9d96e2d 100644 --- a/stardew-access/ModEntry.cs +++ b/stardew-access/ModEntry.cs @@ -346,6 +346,20 @@ namespace stardew_access 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) { if (monitor == null) diff --git a/stardew-access/Patches/OtherMenuPatches/AnimalQueryMenuPatch.cs b/stardew-access/Patches/OtherMenuPatches/AnimalQueryMenuPatch.cs index 334e580..324feb2 100644 --- a/stardew-access/Patches/OtherMenuPatches/AnimalQueryMenuPatch.cs +++ b/stardew-access/Patches/OtherMenuPatches/AnimalQueryMenuPatch.cs @@ -11,7 +11,9 @@ namespace stardew_access.Patches internal static FarmAnimal? animalBeingMoved = null; 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 { @@ -23,6 +25,8 @@ namespace stardew_access.Patches animalQueryMenu = __instance; animalBeingMoved = ___animal; + loveLevel = ___loveLevel; + narrateAnimalDetailsOnKeyPress(___animal, ___parentName); narrateHoveredButton(__instance, ___animal, ___confirmingSell, x, y); @@ -44,6 +48,7 @@ namespace stardew_access.Patches 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 parent = ""; + if ((int)___animal.age.Value < (byte)___animal.ageWhenMature.Value) { 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); } + // 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; 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) diff --git a/stardew-access/i18n/default.json b/stardew-access/i18n/default.json index 60169b4..78b2e3e 100644 --- a/stardew-access/i18n/default.json +++ b/stardew-access/i18n/default.json @@ -2,15 +2,17 @@ "warnings.health": "Warning! Health is at {{value}} percent!", "warnings.stamina": "Warning! Stamina is at {{value}} percent!", "warnings.time": "Warning! Time is {{value}}", - "grandpastory.scene0":"Grandpa, on his deathbed.", - "grandpastory.scene4":"Employees working in JoJa corp.", - "grandpastory.scene5":"Employees in their cubicles, some of them look exhausted including yourself.", - "grandpastory.scene6":"You reach your desk finding grandpa's letter.", - "grandpastory.letteropen":"Left click to open grandpa's letter", - "intro.scene3":"Travelling to Stardew Valley bus stop", - "intro.scene4":"Stardew valley 0.5 miles away", - "manuallytriggered.healthnstamina.percent":"Health is {{health}} % and Stamina is {{stamina}} %", - "manuallytriggered.healthnstamina.normal":"Health is {{health}} and Stamina is {{stamina}}", - "readtile.sprinkler.pressurenozzle":"Pressurized {{value}}", - "readtile.sprinkler.enricher":"Enriching {{value}}" -} \ No newline at end of file + "grandpastory.scene0": "Grandpa, on his deathbed.", + "grandpastory.scene4": "Employees working in JoJa corp.", + "grandpastory.scene5": "Employees in their cubicles, some of them look exhausted including yourself.", + "grandpastory.scene6": "You reach your desk finding grandpa's letter.", + "grandpastory.letteropen": "Left click to open grandpa's letter", + "intro.scene3": "Travelling to Stardew Valley bus stop", + "intro.scene4": "Stardew valley 0.5 miles away", + "manuallytriggered.healthnstamina.percent": "Health is {{health}} % and Stamina is {{stamina}} %", + "manuallytriggered.healthnstamina.normal": "Health is {{health}} and Stamina is {{stamina}}", + "readtile.sprinkler.pressurenozzle": "Pressurized {{value}}", + "readtile.sprinkler.enricher": "Enriching {{value}}", + // Animal Query Menu Patch + "patch.animal_query_menu.heart": "Heart Count: {{count}}" +}