Improved and organised code in SocialPagePatch.cs
parent
774454ce0e
commit
b22af63b97
|
@ -15,42 +15,42 @@ namespace stardew_access.Patches
|
|||
int x = Game1.getMouseX(true), y = Game1.getMouseY(true);
|
||||
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];
|
||||
string toSpeak = optionsElement.label;
|
||||
|
||||
if (optionsElement is OptionsButton)
|
||||
toSpeak = $" {toSpeak} Button";
|
||||
else if (optionsElement is OptionsCheckbox)
|
||||
toSpeak = (((OptionsCheckbox)optionsElement).isChecked ? "Enabled" : "Disabled") + $" {toSpeak} Checkbox";
|
||||
else if (optionsElement is OptionsDropDown)
|
||||
toSpeak = $"{toSpeak} Dropdown, option {((OptionsDropDown)optionsElement).dropDownDisplayOptions[((OptionsDropDown)optionsElement).selectedOption]} selected";
|
||||
else if (optionsElement is OptionsSlider)
|
||||
toSpeak = $"{((OptionsSlider)optionsElement).value}% {toSpeak} Slider";
|
||||
else if (optionsElement is OptionsPlusMinus)
|
||||
toSpeak = $"{((OptionsPlusMinus)optionsElement).displayOptions[((OptionsPlusMinus)optionsElement).selected]} selected of {toSpeak}";
|
||||
else if (optionsElement is OptionsInputListener)
|
||||
{
|
||||
OptionsElement optionsElement = __instance.options[currentItemIndex + i];
|
||||
string toSpeak = optionsElement.label;
|
||||
|
||||
if (optionsElement is OptionsButton)
|
||||
toSpeak = $" {toSpeak} Button";
|
||||
else if (optionsElement is OptionsCheckbox)
|
||||
toSpeak = (((OptionsCheckbox)optionsElement).isChecked ? "Enabled" : "Disabled") + $" {toSpeak} Checkbox";
|
||||
else if (optionsElement is OptionsDropDown)
|
||||
toSpeak = $"{toSpeak} Dropdown, option {((OptionsDropDown)optionsElement).dropDownDisplayOptions[((OptionsDropDown)optionsElement).selectedOption]} selected";
|
||||
else if (optionsElement is OptionsSlider)
|
||||
toSpeak = $"{((OptionsSlider)optionsElement).value}% {toSpeak} Slider";
|
||||
else if (optionsElement is OptionsPlusMinus)
|
||||
toSpeak = $"{((OptionsPlusMinus)optionsElement).displayOptions[((OptionsPlusMinus)optionsElement).selected]} selected of {toSpeak}";
|
||||
else if (optionsElement is OptionsInputListener)
|
||||
{
|
||||
string buttons = "";
|
||||
((OptionsInputListener)optionsElement).buttonNames.ForEach(name => { buttons += $", {name}"; });
|
||||
toSpeak = $"{toSpeak} is bound to {buttons}. Left click to change.";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (toSpeak.Contains(":"))
|
||||
toSpeak = toSpeak.Replace(":", "");
|
||||
|
||||
toSpeak = $"{toSpeak} Options:";
|
||||
}
|
||||
|
||||
if (optionsPageQueryKey != toSpeak)
|
||||
{
|
||||
optionsPageQueryKey = toSpeak;
|
||||
MainClass.ScreenReader.Say(toSpeak, true);
|
||||
}
|
||||
return;
|
||||
string buttons = "";
|
||||
((OptionsInputListener)optionsElement).buttonNames.ForEach(name => { buttons += $", {name}"; });
|
||||
toSpeak = $"{toSpeak} is bound to {buttons}. Left click to change.";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (toSpeak.Contains(":"))
|
||||
toSpeak = toSpeak.Replace(":", "");
|
||||
|
||||
toSpeak = $"{toSpeak} Options:";
|
||||
}
|
||||
|
||||
if (optionsPageQueryKey != toSpeak)
|
||||
{
|
||||
optionsPageQueryKey = toSpeak;
|
||||
MainClass.ScreenReader.Say(toSpeak, true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
|
@ -14,138 +14,16 @@ namespace stardew_access.Patches
|
|||
int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position
|
||||
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)
|
||||
{
|
||||
#region For NPCs
|
||||
if (__instance.characterSlots[i].bounds.Contains(Game1.getMouseX(true), Game1.getMouseY(true)))
|
||||
{
|
||||
string name = $"{__instance.names[i] as string}";
|
||||
int heartLevel = Game1.player.getFriendshipHeartLevelForNPC(name);
|
||||
bool datable = SocialPage.isDatable(name);
|
||||
Friendship friendship = __instance.getFriendship(name);
|
||||
int giftsThisWeek = friendship.GiftsThisWeek;
|
||||
bool hasTalked = Game1.player.hasPlayerTalkedToNPC(name);
|
||||
bool spouse = friendship.IsMarried();
|
||||
bool housemate = spouse && SocialPage.isRoommateOfAnyone(name);
|
||||
___kidsNames.Add("Robin");
|
||||
___kidsNames.Add("Pierre");
|
||||
___kidsNames.Add("Caroline");
|
||||
___kidsNames.Add("Jodi");
|
||||
___kidsNames.Add("Kent");
|
||||
___kidsNames.Add("George");
|
||||
___kidsNames.Add("Evelyn");
|
||||
___kidsNames.Add("Demetrius");
|
||||
|
||||
|
||||
|
||||
string toSpeak = $"{name}";
|
||||
|
||||
if (!hasTalked)
|
||||
{
|
||||
toSpeak = $"{toSpeak}, not talked yet";
|
||||
}
|
||||
|
||||
|
||||
if (datable | housemate)
|
||||
{
|
||||
string text2 = (LocalizedContentManager.CurrentLanguageCode != LocalizedContentManager.LanguageCode.pt) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635") : ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').First() : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').Last());
|
||||
if (housemate)
|
||||
{
|
||||
text2 = Game1.content.LoadString("Strings\\StringsFromCSFiles:Housemate");
|
||||
}
|
||||
else if (spouse)
|
||||
{
|
||||
text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11636") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11637"));
|
||||
}
|
||||
else if (__instance.isMarriedToAnyone(name))
|
||||
{
|
||||
text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_MaleNPC") : Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_FemaleNPC"));
|
||||
}
|
||||
else if (!Game1.player.isMarried() && friendship.IsDating())
|
||||
{
|
||||
text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11639") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11640"));
|
||||
}
|
||||
else if (__instance.getFriendship(name).IsDivorced())
|
||||
{
|
||||
text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11642") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11643"));
|
||||
}
|
||||
|
||||
toSpeak = $"{toSpeak}, {text2}";
|
||||
}
|
||||
if (!__instance.getFriendship(name).IsMarried() && ___kidsNames.Contains(name))
|
||||
{
|
||||
toSpeak = $"{toSpeak}, married";
|
||||
}
|
||||
if (spouse)
|
||||
{
|
||||
toSpeak = $"{toSpeak}, spouse";
|
||||
}
|
||||
else if (friendship.IsDating())
|
||||
{
|
||||
toSpeak = $"{toSpeak}, dating";
|
||||
}
|
||||
|
||||
toSpeak = $"{toSpeak}, {heartLevel} hearts, {giftsThisWeek} gifts given this week.";
|
||||
|
||||
|
||||
if (socialPageQuery != toSpeak)
|
||||
{
|
||||
socialPageQuery = toSpeak;
|
||||
MainClass.ScreenReader.Say(toSpeak, true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
else if (__instance.names[i] is long)
|
||||
{
|
||||
#region For Farmers
|
||||
|
||||
long farmerID = (long)__instance.names[i];
|
||||
Farmer farmer = Game1.getFarmerMaybeOffline(farmerID);
|
||||
if (farmer != null)
|
||||
{
|
||||
int gender = (!farmer.IsMale) ? 1 : 0;
|
||||
ClickableTextureComponent clickableTextureComponent = ___sprites[i];
|
||||
if (clickableTextureComponent.containsPoint(x, y))
|
||||
{
|
||||
Friendship friendship = Game1.player.team.GetFriendship(Game1.player.UniqueMultiplayerID, farmerID);
|
||||
bool spouse = friendship.IsMarried();
|
||||
string toSpeak = "";
|
||||
|
||||
string text2 = (LocalizedContentManager.CurrentLanguageCode != LocalizedContentManager.LanguageCode.pt) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635") : ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').First() : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').Last());
|
||||
if (spouse)
|
||||
{
|
||||
text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11636") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11637"));
|
||||
}
|
||||
else if (farmer.isMarried() && !farmer.hasRoommate())
|
||||
{
|
||||
text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_MaleNPC") : Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_FemaleNPC"));
|
||||
}
|
||||
else if (!Game1.player.isMarried() && friendship.IsDating())
|
||||
{
|
||||
text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11639") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11640"));
|
||||
}
|
||||
else if (friendship.IsDivorced())
|
||||
{
|
||||
text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11642") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11643"));
|
||||
}
|
||||
|
||||
toSpeak = $"{farmer.displayName}, {text2}";
|
||||
|
||||
if (socialPageQuery != toSpeak)
|
||||
{
|
||||
socialPageQuery = toSpeak;
|
||||
MainClass.ScreenReader.Say(toSpeak, true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if (__instance.names[i] is long && narrateFarmerDetails(__instance, i, ___sprites, x, y))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -155,6 +33,131 @@ namespace stardew_access.Patches
|
|||
}
|
||||
}
|
||||
|
||||
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}";
|
||||
int heartLevel = Game1.player.getFriendshipHeartLevelForNPC(name);
|
||||
bool datable = SocialPage.isDatable(name);
|
||||
Friendship friendship = __instance.getFriendship(name);
|
||||
int giftsThisWeek = friendship.GiftsThisWeek;
|
||||
bool hasTalked = Game1.player.hasPlayerTalkedToNPC(name);
|
||||
bool spouse = friendship.IsMarried();
|
||||
bool housemate = spouse && SocialPage.isRoommateOfAnyone(name);
|
||||
___kidsNames.Add("Robin");
|
||||
___kidsNames.Add("Pierre");
|
||||
___kidsNames.Add("Caroline");
|
||||
___kidsNames.Add("Jodi");
|
||||
___kidsNames.Add("Kent");
|
||||
___kidsNames.Add("George");
|
||||
___kidsNames.Add("Evelyn");
|
||||
___kidsNames.Add("Demetrius");
|
||||
|
||||
string toSpeak = $"{name}";
|
||||
|
||||
if (!hasTalked)
|
||||
{
|
||||
toSpeak = $"{toSpeak}, not talked yet";
|
||||
}
|
||||
|
||||
|
||||
if (datable | housemate)
|
||||
{
|
||||
string text2 = (LocalizedContentManager.CurrentLanguageCode != LocalizedContentManager.LanguageCode.pt) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635") : ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').First() : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').Last());
|
||||
if (housemate)
|
||||
{
|
||||
text2 = Game1.content.LoadString("Strings\\StringsFromCSFiles:Housemate");
|
||||
}
|
||||
else if (spouse)
|
||||
{
|
||||
text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11636") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11637"));
|
||||
}
|
||||
else if (__instance.isMarriedToAnyone(name))
|
||||
{
|
||||
text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_MaleNPC") : Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_FemaleNPC"));
|
||||
}
|
||||
else if (!Game1.player.isMarried() && friendship.IsDating())
|
||||
{
|
||||
text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11639") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11640"));
|
||||
}
|
||||
else if (__instance.getFriendship(name).IsDivorced())
|
||||
{
|
||||
text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11642") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11643"));
|
||||
}
|
||||
|
||||
toSpeak = $"{toSpeak}, {text2}";
|
||||
}
|
||||
|
||||
if (!__instance.getFriendship(name).IsMarried() && ___kidsNames.Contains(name))
|
||||
{
|
||||
toSpeak = $"{toSpeak}, married";
|
||||
}
|
||||
|
||||
if (spouse)
|
||||
{
|
||||
toSpeak = $"{toSpeak}, spouse";
|
||||
}
|
||||
else if (friendship.IsDating())
|
||||
{
|
||||
toSpeak = $"{toSpeak}, dating";
|
||||
}
|
||||
|
||||
toSpeak = $"{toSpeak}, {heartLevel} hearts, {giftsThisWeek} gifts given this week.";
|
||||
|
||||
if (socialPageQuery != toSpeak)
|
||||
{
|
||||
socialPageQuery = toSpeak;
|
||||
MainClass.ScreenReader.Say(toSpeak, true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool narrateFarmerDetails(SocialPage __instance, int i, List<ClickableTextureComponent> ___sprites, int x, int y)
|
||||
{
|
||||
long farmerID = (long)__instance.names[i];
|
||||
Farmer farmer = Game1.getFarmerMaybeOffline(farmerID);
|
||||
if (farmer == null)
|
||||
return false;
|
||||
|
||||
int gender = (!farmer.IsMale) ? 1 : 0;
|
||||
ClickableTextureComponent clickableTextureComponent = ___sprites[i];
|
||||
if (!clickableTextureComponent.containsPoint(x, y))
|
||||
return false;
|
||||
|
||||
Friendship friendship = Game1.player.team.GetFriendship(Game1.player.UniqueMultiplayerID, farmerID);
|
||||
bool spouse = friendship.IsMarried();
|
||||
string toSpeak = "";
|
||||
|
||||
string text2 = (LocalizedContentManager.CurrentLanguageCode != LocalizedContentManager.LanguageCode.pt) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635") : ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').First() : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').Last());
|
||||
if (spouse)
|
||||
{
|
||||
text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11636") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11637"));
|
||||
}
|
||||
else if (farmer.isMarried() && !farmer.hasRoommate())
|
||||
{
|
||||
text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_MaleNPC") : Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_FemaleNPC"));
|
||||
}
|
||||
else if (!Game1.player.isMarried() && friendship.IsDating())
|
||||
{
|
||||
text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11639") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11640"));
|
||||
}
|
||||
else if (friendship.IsDivorced())
|
||||
{
|
||||
text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11642") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11643"));
|
||||
}
|
||||
|
||||
toSpeak = $"{farmer.displayName}, {text2}";
|
||||
|
||||
if (socialPageQuery != toSpeak)
|
||||
{
|
||||
socialPageQuery = toSpeak;
|
||||
MainClass.ScreenReader.Say(toSpeak, true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
internal static void Cleanup()
|
||||
{
|
||||
socialPageQuery = "";
|
||||
|
|
Loading…
Reference in New Issue