Improved and organised code in carpenter menu patch
parent
baede57965
commit
6141447c13
|
@ -29,21 +29,57 @@ namespace stardew_access.Patches
|
|||
isMoving = false;
|
||||
isConstructing = false;
|
||||
|
||||
#region The blueprint menu
|
||||
BluePrint currentBluprint = __instance.CurrentBlueprint;
|
||||
if (currentBluprint == null)
|
||||
BluePrint currentBlueprint = __instance.CurrentBlueprint;
|
||||
if (currentBlueprint == null)
|
||||
return;
|
||||
|
||||
int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position
|
||||
bool isPrimaryInfoKeyPressed = MainClass.Config.PrimaryInfoKey.JustPressed();
|
||||
string blueprintInfo = getCurrentBlueprintInfo(currentBlueprint, ___price, ___ingredients);
|
||||
|
||||
if (isPrimaryInfoKeyPressed && !isSayingBlueprintInfo)
|
||||
{
|
||||
SpeakAndWait(blueprintInfo);
|
||||
}
|
||||
else if (prevBlueprintInfo != blueprintInfo)
|
||||
{
|
||||
prevBlueprintInfo = blueprintInfo;
|
||||
SpeakAndWait(blueprintInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
narrateHoveredButton(__instance, ___blueprints, ___currentBlueprintIndex, x, y);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (___demolishing)
|
||||
isDemolishing = true;
|
||||
else if (___upgrading)
|
||||
isUpgrading = true;
|
||||
else if (___painting)
|
||||
isPainting = true;
|
||||
else if (___moving)
|
||||
isMoving = true;
|
||||
else
|
||||
isConstructing = true;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}");
|
||||
}
|
||||
}
|
||||
|
||||
private static string getCurrentBlueprintInfo(BluePrint currentBlueprint, int ___price, List<Item> ___ingredients)
|
||||
{
|
||||
string ingredients = "";
|
||||
string name = currentBluprint.displayName;
|
||||
string upgradeName = currentBluprint.nameOfBuildingToUpgrade;
|
||||
string description = currentBluprint.description;
|
||||
string name = currentBlueprint.displayName;
|
||||
string upgradeName = currentBlueprint.nameOfBuildingToUpgrade;
|
||||
string description = currentBlueprint.description;
|
||||
string price = $"{___price}g";
|
||||
string blueprintInfo;
|
||||
int width = currentBluprint.tilesWidth;
|
||||
int height = currentBluprint.tilesHeight;
|
||||
int width = currentBlueprint.tilesWidth;
|
||||
int height = currentBlueprint.tilesHeight;
|
||||
|
||||
#region Get ingredients
|
||||
for (int i = 0; i < ___ingredients.Count; i++)
|
||||
|
@ -70,126 +106,58 @@ namespace stardew_access.Patches
|
|||
}
|
||||
#endregion
|
||||
|
||||
blueprintInfo = $"{name}, Price: {price}, Ingredients: {ingredients}, Dimensions: {width} width and {height} height, Description: {description}";
|
||||
|
||||
if (isPrimaryInfoKeyPressed && !isSayingBlueprintInfo)
|
||||
{
|
||||
SayBlueprintInfo(blueprintInfo);
|
||||
}
|
||||
else if (prevBlueprintInfo != blueprintInfo)
|
||||
{
|
||||
prevBlueprintInfo = blueprintInfo;
|
||||
SayBlueprintInfo(blueprintInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (__instance.backButton != null && __instance.backButton.containsPoint(x, y))
|
||||
{
|
||||
string toSpeak = "Previous Blueprint";
|
||||
if (carpenterMenuQuery != toSpeak)
|
||||
{
|
||||
carpenterMenuQuery = toSpeak;
|
||||
MainClass.ScreenReader.Say(toSpeak, true);
|
||||
}
|
||||
return;
|
||||
return $"{name}, Price: {price}, Ingredients: {ingredients}, Dimensions: {width} width and {height} height, Description: {description}";
|
||||
}
|
||||
|
||||
if (__instance.forwardButton != null && __instance.forwardButton.containsPoint(x, y))
|
||||
{
|
||||
string toSpeak = "Next Blueprint";
|
||||
if (carpenterMenuQuery != toSpeak)
|
||||
{
|
||||
carpenterMenuQuery = toSpeak;
|
||||
MainClass.ScreenReader.Say(toSpeak, true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (__instance.demolishButton != null && __instance.demolishButton.containsPoint(x, y))
|
||||
{
|
||||
string toSpeak = $"Demolish Building" + (__instance.CanDemolishThis(___blueprints[___currentBlueprintIndex]) ? "" : ", cannot demolish building");
|
||||
if (carpenterMenuQuery != toSpeak)
|
||||
{
|
||||
carpenterMenuQuery = toSpeak;
|
||||
MainClass.ScreenReader.Say(toSpeak, true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (__instance.okButton != null && __instance.okButton.containsPoint(x, y))
|
||||
{
|
||||
string toSpeak = "Construct Building" + (___blueprints[___currentBlueprintIndex].doesFarmerHaveEnoughResourcesToBuild() ? "" : ", cannot cunstrut building, not enough resources to build.");
|
||||
if (carpenterMenuQuery != toSpeak)
|
||||
{
|
||||
carpenterMenuQuery = toSpeak;
|
||||
MainClass.ScreenReader.Say(toSpeak, true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (__instance.moveButton != null && __instance.moveButton.containsPoint(x, y))
|
||||
{
|
||||
string toSpeak = "Move Building";
|
||||
if (carpenterMenuQuery != toSpeak)
|
||||
{
|
||||
carpenterMenuQuery = toSpeak;
|
||||
MainClass.ScreenReader.Say(toSpeak, true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (__instance.paintButton != null && __instance.paintButton.containsPoint(x, y))
|
||||
{
|
||||
string toSpeak = "Paint Building";
|
||||
if (carpenterMenuQuery != toSpeak)
|
||||
{
|
||||
carpenterMenuQuery = toSpeak;
|
||||
MainClass.ScreenReader.Say(toSpeak, true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (__instance.cancelButton != null && __instance.cancelButton.containsPoint(x, y))
|
||||
{
|
||||
string toSpeak = "Cancel Button";
|
||||
if (carpenterMenuQuery != toSpeak)
|
||||
{
|
||||
carpenterMenuQuery = toSpeak;
|
||||
MainClass.ScreenReader.Say(toSpeak, true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
else
|
||||
{
|
||||
if (___demolishing)
|
||||
isDemolishing = true;
|
||||
else if (___upgrading)
|
||||
isUpgrading = true;
|
||||
else if (___painting)
|
||||
isPainting = true;
|
||||
else if (___moving)
|
||||
isMoving = true;
|
||||
else
|
||||
isConstructing = true;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}");
|
||||
}
|
||||
}
|
||||
|
||||
private static async void SayBlueprintInfo(string info)
|
||||
private static async void SpeakAndWait(string toSpeak)
|
||||
{
|
||||
isSayingBlueprintInfo = true;
|
||||
MainClass.ScreenReader.Say(info, true);
|
||||
MainClass.ScreenReader.Say(toSpeak, true);
|
||||
await Task.Delay(300);
|
||||
isSayingBlueprintInfo = false;
|
||||
}
|
||||
|
||||
private static void narrateHoveredButton(CarpenterMenu __instance, List<BluePrint> ___blueprints, int ___currentBlueprintIndex, int x, int y)
|
||||
{
|
||||
string toSpeak = "";
|
||||
if (__instance.backButton != null && __instance.backButton.containsPoint(x, y))
|
||||
{
|
||||
toSpeak = "Previous Blueprint";
|
||||
}
|
||||
else if (__instance.forwardButton != null && __instance.forwardButton.containsPoint(x, y))
|
||||
{
|
||||
toSpeak = "Next Blueprint";
|
||||
}
|
||||
else if (__instance.demolishButton != null && __instance.demolishButton.containsPoint(x, y))
|
||||
{
|
||||
toSpeak = $"Demolish Building" + (__instance.CanDemolishThis(___blueprints[___currentBlueprintIndex]) ? "" : ", cannot demolish building");
|
||||
}
|
||||
else if (__instance.okButton != null && __instance.okButton.containsPoint(x, y))
|
||||
{
|
||||
toSpeak = "Construct Building" + (___blueprints[___currentBlueprintIndex].doesFarmerHaveEnoughResourcesToBuild() ? "" : ", cannot cunstrut building, not enough resources to build.");
|
||||
}
|
||||
else if (__instance.moveButton != null && __instance.moveButton.containsPoint(x, y))
|
||||
{
|
||||
toSpeak = "Move Building";
|
||||
}
|
||||
else if (__instance.paintButton != null && __instance.paintButton.containsPoint(x, y))
|
||||
{
|
||||
toSpeak = "Paint Building";
|
||||
}
|
||||
else if (__instance.cancelButton != null && __instance.cancelButton.containsPoint(x, y))
|
||||
{
|
||||
toSpeak = "Cancel Button";
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (carpenterMenuQuery != toSpeak)
|
||||
{
|
||||
carpenterMenuQuery = toSpeak;
|
||||
MainClass.ScreenReader.Say(toSpeak, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue