Improved and organised code in AnimalQueryMenuPatch.cs

master
Mohammad Shoaib Khan 2023-03-07 12:03:08 +05:30
parent b22af63b97
commit 403a97b633
No known key found for this signature in database
GPG Key ID: D8040D966320B620
2 changed files with 60 additions and 46 deletions

View File

@ -18,15 +18,27 @@ namespace stardew_access.Patches
if (TextBoxPatch.isAnyTextBoxActive) return; if (TextBoxPatch.isAnyTextBoxActive) return;
int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position
bool isPrimaryInfoKeyPressed = MainClass.Config.PrimaryInfoKey.JustPressed(); // For narrating animal details
string toSpeak = " ", details = " ";
isOnFarm = ___movingAnimal; isOnFarm = ___movingAnimal;
animalQueryMenu = __instance; animalQueryMenu = __instance;
animalBeingMoved = ___animal; animalBeingMoved = ___animal;
if (isPrimaryInfoKeyPressed & !isNarratingAnimalInfo) narrateAnimalDetailsOnKeyPress(___animal, ___parentName);
narrateHoveredButton(__instance, ___animal, ___confirmingSell, x, y);
}
catch (System.Exception e)
{ {
MainClass.ErrorLog($"An error occured in AnimalQueryMenuPatch()->DrawPatch():\n{e.Message}\n{e.StackTrace}");
}
}
private static void narrateAnimalDetailsOnKeyPress(FarmAnimal ___animal, string ___parentName)
{
bool isPrimaryInfoKeyPressed = MainClass.Config.PrimaryInfoKey.JustPressed();
if (!isPrimaryInfoKeyPressed | isNarratingAnimalInfo)
return;
string name = ___animal.displayName; string name = ___animal.displayName;
string type = ___animal.displayType; string type = ___animal.displayType;
int age = (___animal.GetDaysOwned() + 1) / 28 + 1; int age = (___animal.GetDaysOwned() + 1) / 28 + 1;
@ -41,13 +53,15 @@ namespace stardew_access.Patches
parent = Game1.content.LoadString("Strings\\UI:AnimalQuery_Parent", ___parentName); parent = Game1.content.LoadString("Strings\\UI:AnimalQuery_Parent", ___parentName);
} }
details = $"Name: {name} Type: {type} \n\t Age: {ageText} {parent}";
animalQueryMenuQuery = "";
isNarratingAnimalInfo = true; isNarratingAnimalInfo = true;
Task.Delay(200).ContinueWith(_ => { isNarratingAnimalInfo = false; }); Task.Delay(200).ContinueWith(_ => { isNarratingAnimalInfo = false; }); // Adds delay
MainClass.ScreenReader.Say($"Name: {name} Type: {type} \n\t Age: {ageText} {parent}", true);
} }
private static void narrateHoveredButton(AnimalQueryMenu __instance, FarmAnimal ___animal, bool ___confirmingSell, int x, int y)
{
string toSpeak = "";
if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) if (__instance.okButton != null && __instance.okButton.containsPoint(x, y))
toSpeak = "OK button"; toSpeak = "OK button";
else if (__instance.sellButton != null && __instance.sellButton.containsPoint(x, y)) else if (__instance.sellButton != null && __instance.sellButton.containsPoint(x, y))
@ -66,13 +80,14 @@ namespace stardew_access.Patches
if (animalQueryMenuQuery != toSpeak) if (animalQueryMenuQuery != toSpeak)
{ {
animalQueryMenuQuery = toSpeak; animalQueryMenuQuery = toSpeak;
MainClass.ScreenReader.Say($"{details} {toSpeak}", true); MainClass.ScreenReader.Say($"{toSpeak}", true);
} }
} }
catch (System.Exception e)
internal static void Cleanup()
{ {
MainClass.ErrorLog($"An error occured in AnimalQueryMenuPatch()->DrawPatch():\n{e.Message}\n{e.StackTrace}"); AnimalQueryMenuPatch.animalQueryMenuQuery = "";
} AnimalQueryMenuPatch.animalQueryMenu = null;
} }
} }
} }

View File

@ -77,8 +77,7 @@ namespace stardew_access.Patches
} }
else if (menu is AnimalQueryMenu) else if (menu is AnimalQueryMenu)
{ {
AnimalQueryMenuPatch.animalQueryMenuQuery = ""; AnimalQueryMenuPatch.Cleanup();
AnimalQueryMenuPatch.animalQueryMenu = null;
} }
else if (menu is DialogueBox) else if (menu is DialogueBox)
{ {