Improved and organised code in SocialPagePatch.cs

master
Mohammad Shoaib Khan 2023-03-07 11:29:23 +05:30
parent 774454ce0e
commit b22af63b97
No known key found for this signature in database
GPG Key ID: D8040D966320B620
2 changed files with 168 additions and 165 deletions

View File

@ -15,8 +15,9 @@ namespace stardew_access.Patches
int x = Game1.getMouseX(true), y = Game1.getMouseY(true); int x = Game1.getMouseX(true), y = Game1.getMouseY(true);
for (int i = 0; i < __instance.optionSlots.Count; i++) for (int i = 0; i < __instance.optionSlots.Count; i++)
{ {
if (__instance.optionSlots[i].bounds.Contains(x, y) && currentItemIndex + i < __instance.options.Count && __instance.options[currentItemIndex + i].bounds.Contains(x - __instance.optionSlots[i].bounds.X, y - __instance.optionSlots[i].bounds.Y)) if (!__instance.optionSlots[i].bounds.Contains(x, y) || currentItemIndex + i >= __instance.options.Count || !__instance.options[currentItemIndex + i].bounds.Contains(x - __instance.optionSlots[i].bounds.X, y - __instance.optionSlots[i].bounds.Y))
{ continue;
OptionsElement optionsElement = __instance.options[currentItemIndex + i]; OptionsElement optionsElement = __instance.options[currentItemIndex + i];
string toSpeak = optionsElement.label; string toSpeak = optionsElement.label;
@ -52,7 +53,6 @@ namespace stardew_access.Patches
return; return;
} }
} }
}
catch (Exception e) catch (Exception e)
{ {
MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}");

View File

@ -14,13 +14,30 @@ namespace stardew_access.Patches
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
for (int i = ___slotPosition; i < ___slotPosition + 5; i++) for (int i = ___slotPosition; i < ___slotPosition + 5; i++)
{ {
if (i < ___sprites.Count) if (i >= ___sprites.Count)
continue;
if (__instance.names[i] is string && narrateNPCDetails(__instance, i, ___kidsNames, x, y))
{ {
if (__instance.names[i] is string) return;
}
else if (__instance.names[i] is long && narrateFarmerDetails(__instance, i, ___sprites, x, y))
{ {
#region For NPCs return;
if (__instance.characterSlots[i].bounds.Contains(Game1.getMouseX(true), Game1.getMouseY(true))) }
}
}
catch (Exception e)
{ {
MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}");
}
}
private static bool narrateNPCDetails(SocialPage __instance, int i, List<string> ___kidsNames, int x, int y)
{
if (!__instance.characterSlots[i].bounds.Contains(x, y))
return false;
string name = $"{__instance.names[i] as string}"; string name = $"{__instance.names[i] as string}";
int heartLevel = Game1.player.getFriendshipHeartLevelForNPC(name); int heartLevel = Game1.player.getFriendshipHeartLevelForNPC(name);
bool datable = SocialPage.isDatable(name); bool datable = SocialPage.isDatable(name);
@ -38,8 +55,6 @@ namespace stardew_access.Patches
___kidsNames.Add("Evelyn"); ___kidsNames.Add("Evelyn");
___kidsNames.Add("Demetrius"); ___kidsNames.Add("Demetrius");
string toSpeak = $"{name}"; string toSpeak = $"{name}";
if (!hasTalked) if (!hasTalked)
@ -74,10 +89,12 @@ namespace stardew_access.Patches
toSpeak = $"{toSpeak}, {text2}"; toSpeak = $"{toSpeak}, {text2}";
} }
if (!__instance.getFriendship(name).IsMarried() && ___kidsNames.Contains(name)) if (!__instance.getFriendship(name).IsMarried() && ___kidsNames.Contains(name))
{ {
toSpeak = $"{toSpeak}, married"; toSpeak = $"{toSpeak}, married";
} }
if (spouse) if (spouse)
{ {
toSpeak = $"{toSpeak}, spouse"; toSpeak = $"{toSpeak}, spouse";
@ -89,28 +106,26 @@ namespace stardew_access.Patches
toSpeak = $"{toSpeak}, {heartLevel} hearts, {giftsThisWeek} gifts given this week."; toSpeak = $"{toSpeak}, {heartLevel} hearts, {giftsThisWeek} gifts given this week.";
if (socialPageQuery != toSpeak) if (socialPageQuery != toSpeak)
{ {
socialPageQuery = toSpeak; socialPageQuery = toSpeak;
MainClass.ScreenReader.Say(toSpeak, true); MainClass.ScreenReader.Say(toSpeak, true);
} }
return; return true;
} }
#endregion
}
else if (__instance.names[i] is long)
{
#region For Farmers
private static bool narrateFarmerDetails(SocialPage __instance, int i, List<ClickableTextureComponent> ___sprites, int x, int y)
{
long farmerID = (long)__instance.names[i]; long farmerID = (long)__instance.names[i];
Farmer farmer = Game1.getFarmerMaybeOffline(farmerID); Farmer farmer = Game1.getFarmerMaybeOffline(farmerID);
if (farmer != null) if (farmer == null)
{ return false;
int gender = (!farmer.IsMale) ? 1 : 0; int gender = (!farmer.IsMale) ? 1 : 0;
ClickableTextureComponent clickableTextureComponent = ___sprites[i]; ClickableTextureComponent clickableTextureComponent = ___sprites[i];
if (clickableTextureComponent.containsPoint(x, y)) if (!clickableTextureComponent.containsPoint(x, y))
{ return false;
Friendship friendship = Game1.player.team.GetFriendship(Game1.player.UniqueMultiplayerID, farmerID); Friendship friendship = Game1.player.team.GetFriendship(Game1.player.UniqueMultiplayerID, farmerID);
bool spouse = friendship.IsMarried(); bool spouse = friendship.IsMarried();
string toSpeak = ""; string toSpeak = "";
@ -140,19 +155,7 @@ namespace stardew_access.Patches
socialPageQuery = toSpeak; socialPageQuery = toSpeak;
MainClass.ScreenReader.Say(toSpeak, true); MainClass.ScreenReader.Say(toSpeak, true);
} }
return; return true;
}
}
#endregion
}
}
}
}
catch (Exception e)
{
MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}");
}
} }
internal static void Cleanup() internal static void Cleanup()