Refactored code

master
Mohammad Shoaib Khan 2023-02-22 17:03:33 +05:30
parent 31f3144bfd
commit cf0e46ecdd
No known key found for this signature in database
GPG Key ID: D8040D966320B620
2 changed files with 64 additions and 31 deletions

View File

@ -48,7 +48,7 @@ namespace stardew_access
harmony.Patch( harmony.Patch(
original: AccessTools.Method(typeof(CharacterCustomization), nameof(CharacterCustomization.draw), new Type[] { typeof(SpriteBatch) }), original: AccessTools.Method(typeof(CharacterCustomization), nameof(CharacterCustomization.draw), new Type[] { typeof(SpriteBatch) }),
postfix: new HarmonyMethod(typeof(CharacterCustomizationPatches), nameof(CharacterCustomizationPatches.CharacterCustomizationMenuPatch)) postfix: new HarmonyMethod(typeof(CharacterCustomizationMenuPatch), nameof(CharacterCustomizationMenuPatch.DrawPatch))
); );
harmony.Patch( harmony.Patch(

View File

@ -1,8 +1,10 @@
using StardewValley; using StardewValley;
using StardewValley.Menus; using StardewValley.Menus;
namespace stardew_access.Patches { namespace stardew_access.Patches
internal class CharacterCustomizationPatches { {
internal class CharacterCustomizationMenuPatch
{
private static bool isRunning = false; private static bool isRunning = false;
private static int saveGameIndex = -1; private static int saveGameIndex = -1;
public static string characterCreationMenuQueryKey = " "; public static string characterCreationMenuQueryKey = " ";
@ -28,7 +30,7 @@ namespace stardew_access.Patches {
public static bool characterDesignToggleShouldSpeak = true; public static bool characterDesignToggleShouldSpeak = true;
public static ClickableComponent? currentComponent = null; public static ClickableComponent? currentComponent = null;
internal static void CharacterCustomizationMenuPatch(CharacterCustomization __instance, bool ___skipIntro, internal static void DrawPatch(CharacterCustomization __instance, bool ___skipIntro,
ClickableComponent ___startingCabinsLabel, ClickableComponent ___difficultyModifierLabel, TextBox ___nameBox, ClickableComponent ___startingCabinsLabel, ClickableComponent ___difficultyModifierLabel, TextBox ___nameBox,
TextBox ___farmnameBox, TextBox ___favThingBox) TextBox ___farmnameBox, TextBox ___favThingBox)
{ {
@ -97,7 +99,9 @@ namespace stardew_access.Patches {
if (characterDesignToggle) if (characterDesignToggle)
{ {
displayState = "shown"; displayState = "shown";
} else { }
else
{
displayState = "hidden"; displayState = "hidden";
} }
toSpeak = $"Character design controls {displayState}. \n {toSpeak}"; toSpeak = $"Character design controls {displayState}. \n {toSpeak}";
@ -185,7 +189,9 @@ namespace stardew_access.Patches {
prevEyeColorHue = currentEyeColorHue; prevEyeColorHue = currentEyeColorHue;
if (currentEyeColorHue != "") if (currentEyeColorHue != "")
toSpeak = $"{toSpeak} \n Hue: {currentEyeColorHue}"; toSpeak = $"{toSpeak} \n Hue: {currentEyeColorHue}";
} else { }
else
{
prevEyeColorHue = ""; prevEyeColorHue = "";
} }
} }
@ -197,7 +203,9 @@ namespace stardew_access.Patches {
prevEyeColorSaturation = currentEyeColorSaturation; prevEyeColorSaturation = currentEyeColorSaturation;
if (currentEyeColorSaturation != "") if (currentEyeColorSaturation != "")
toSpeak = $"{toSpeak} \n Saturation: {currentEyeColorSaturation}"; toSpeak = $"{toSpeak} \n Saturation: {currentEyeColorSaturation}";
} else { }
else
{
prevEyeColorSaturation = ""; prevEyeColorSaturation = "";
} }
} }
@ -209,7 +217,9 @@ namespace stardew_access.Patches {
prevEyeColorValue = currentEyeColorValue; prevEyeColorValue = currentEyeColorValue;
if (currentEyeColorValue != "") if (currentEyeColorValue != "")
toSpeak = $"{toSpeak} \n Value: {currentEyeColorValue}"; toSpeak = $"{toSpeak} \n Value: {currentEyeColorValue}";
} else { }
else
{
prevEyeColorValue = ""; prevEyeColorValue = "";
} }
} }
@ -231,7 +241,9 @@ namespace stardew_access.Patches {
prevHairColorHue = currentHairColorHue; prevHairColorHue = currentHairColorHue;
if (currentHairColorHue != "") if (currentHairColorHue != "")
toSpeak = $"{toSpeak} \n Hue: {currentHairColorHue}"; toSpeak = $"{toSpeak} \n Hue: {currentHairColorHue}";
} else { }
else
{
prevHairColorHue = ""; prevHairColorHue = "";
} }
} }
@ -243,7 +255,9 @@ namespace stardew_access.Patches {
prevHairColorSaturation = currentHairColorSaturation; prevHairColorSaturation = currentHairColorSaturation;
if (currentHairColorSaturation != "") if (currentHairColorSaturation != "")
toSpeak = $"{toSpeak} \n Saturation: {currentHairColorSaturation}"; toSpeak = $"{toSpeak} \n Saturation: {currentHairColorSaturation}";
} else { }
else
{
prevHairColorSaturation = ""; prevHairColorSaturation = "";
} }
} }
@ -255,7 +269,9 @@ namespace stardew_access.Patches {
prevHairColorValue = currentHairColorValue; prevHairColorValue = currentHairColorValue;
if (currentHairColorValue != "") if (currentHairColorValue != "")
toSpeak = $"{toSpeak} \n Value: {currentHairColorValue}"; toSpeak = $"{toSpeak} \n Value: {currentHairColorValue}";
} else { }
else
{
prevHairColorValue = ""; prevHairColorValue = "";
} }
} }
@ -277,7 +293,9 @@ namespace stardew_access.Patches {
prevPantsColorHue = currentPantsColorHue; prevPantsColorHue = currentPantsColorHue;
if (currentPantsColorHue != "") if (currentPantsColorHue != "")
toSpeak = $"{toSpeak} \n Hue: {currentPantsColorHue}"; toSpeak = $"{toSpeak} \n Hue: {currentPantsColorHue}";
} else { }
else
{
prevPantsColorHue = ""; prevPantsColorHue = "";
} }
} }
@ -289,7 +307,9 @@ namespace stardew_access.Patches {
prevPantsColorSaturation = currentPantsColorSaturation; prevPantsColorSaturation = currentPantsColorSaturation;
if (currentPantsColorSaturation != "") if (currentPantsColorSaturation != "")
toSpeak = $"{toSpeak} \n Saturation: {currentPantsColorSaturation}"; toSpeak = $"{toSpeak} \n Saturation: {currentPantsColorSaturation}";
} else { }
else
{
prevPantsColorSaturation = ""; prevPantsColorSaturation = "";
} }
} }
@ -301,7 +321,9 @@ namespace stardew_access.Patches {
prevPantsColorValue = currentPantsColorValue; prevPantsColorValue = currentPantsColorValue;
if (currentPantsColorValue != "") if (currentPantsColorValue != "")
toSpeak = $"{toSpeak} \n Value: {currentPantsColorValue}"; toSpeak = $"{toSpeak} \n Value: {currentPantsColorValue}";
} else { }
else
{
prevPantsColorValue = ""; prevPantsColorValue = "";
} }
} }
@ -326,7 +348,6 @@ namespace stardew_access.Patches {
return toSpeak.Trim(); return toSpeak.Trim();
} }
private static string CycleThroughItems(bool increase, CharacterCustomization __instance, bool ___skipIntro, private static string CycleThroughItems(bool increase, CharacterCustomization __instance, bool ___skipIntro,
ClickableComponent ___startingCabinsLabel, ClickableComponent ___difficultyModifierLabel, TextBox ___nameBox, ClickableComponent ___startingCabinsLabel, ClickableComponent ___difficultyModifierLabel, TextBox ___nameBox,
TextBox ___farmnameBox, TextBox ___favThingBox) TextBox ___farmnameBox, TextBox ___favThingBox)
@ -344,7 +365,9 @@ namespace stardew_access.Patches {
if (___nameBox.Text != "") if (___nameBox.Text != "")
{ {
postText = $": {___nameBox.Text}"; postText = $": {___nameBox.Text}";
} else { }
else
{
postText = " Text Box"; postText = " Text Box";
} }
buttons.Add(__instance.nameBoxCC, $"Farmer's Name{postText}"); buttons.Add(__instance.nameBoxCC, $"Farmer's Name{postText}");
@ -355,7 +378,9 @@ namespace stardew_access.Patches {
if (___farmnameBox.Text != "") if (___farmnameBox.Text != "")
{ {
postText = $": {___farmnameBox.Text}"; postText = $": {___farmnameBox.Text}";
} else { }
else
{
postText = " Text Box"; postText = " Text Box";
} }
buttons.Add(__instance.farmnameBoxCC, $"Farm's Name{postText}"); buttons.Add(__instance.farmnameBoxCC, $"Farm's Name{postText}");
@ -366,7 +391,9 @@ namespace stardew_access.Patches {
if (___favThingBox.Text != "") if (___favThingBox.Text != "")
{ {
postText = $": {___favThingBox.Text}"; postText = $": {___favThingBox.Text}";
} else { }
else
{
postText = " Text Box"; postText = " Text Box";
} }
buttons.Add(__instance.favThingBoxCC, $"Favourite Thing{postText}"); buttons.Add(__instance.favThingBoxCC, $"Favourite Thing{postText}");
@ -630,7 +657,9 @@ namespace stardew_access.Patches {
break; break;
} }
return sb; return sb;
} else { }
else
{
return null; return null;
} }
} }
@ -650,7 +679,9 @@ namespace stardew_access.Patches {
{ {
value = Math.Min(value + amount, 99d); value = Math.Min(value + amount, 99d);
x = Math.Min(Math.Ceiling((value * step)), (double)sb.bounds.Width); x = Math.Min(Math.Ceiling((value * step)), (double)sb.bounds.Width);
} else { }
else
{
value = Math.Max(value - amount, 0d); value = Math.Max(value - amount, 0d);
x = Math.Max(Math.Ceiling((value * step)), 0d); x = Math.Max(Math.Ceiling((value * step)), 0d);
} }
@ -796,7 +827,9 @@ namespace stardew_access.Patches {
if (currentComponent != null && currentComponent.name == "Pet") if (currentComponent != null && currentComponent.name == "Pet")
{ {
return ((Game1.player.catPerson) ? "Cat" : "Dog") + " Breed: " + Game1.player.whichPetBreed; return ((Game1.player.catPerson) ? "Cat" : "Dog") + " Breed: " + Game1.player.whichPetBreed;
} else { }
else
{
return ""; return "";
} }
} }