public override void draw(SpriteBatch b) { if (!this.onFarm && !Game1.dialogueUp && !Game1.globalFade) { b.Draw(Game1.fadeToBlackRect, Game1.graphics.GraphicsDevice.Viewport.Bounds, Color.Black * 0.75f); SpriteText.drawStringWithScrollBackground(b, Game1.content.LoadString("Strings\\StringsFromCSFiles:PurchaseAnimalsMenu.cs.11354"), this.xPositionOnScreen + 96, this.yPositionOnScreen, "", 1f, -1); Game1.drawDialogueBox(this.xPositionOnScreen, this.yPositionOnScreen, this.width, this.height, false, true, (string)null, false); Game1.dayTimeMoneyBox.drawMoneyBox(b, -1, -1); foreach (ClickableTextureComponent textureComponent in this.animalsToPurchase) { textureComponent.draw(b, (textureComponent.item as StardewValley.Object).Type != null ? Color.Black * 0.4f : Color.White, 0.87f); } SpriteText.drawStringWithScrollBackground(b, currentFarmDisplay, xPositionOnScreen + 86, yPositionOnScreen + 416, "farms farms ", 1f, -1); farmSelectForwardButton.draw(b); farmSelectBackButton.draw(b); } else if (!Game1.globalFade && this.onFarm) { string s = Game1.content.LoadString("Strings\\StringsFromCSFiles:PurchaseAnimalsMenu.cs.11355", (object)this.animalBeingPurchased.displayHouse, (object)this.animalBeingPurchased.displayType); SpriteText.drawStringWithScrollBackground(b, s, Game1.viewport.Width / 2 - SpriteText.getWidthOfString(s) / 2, 16, "", 1f, -1); if (this.namingAnimal) { b.Draw(Game1.fadeToBlackRect, Game1.graphics.GraphicsDevice.Viewport.Bounds, Color.Black * 0.75f); Game1.drawDialogueBox(Game1.viewport.Width / 2 - 256, Game1.viewport.Height / 2 - 192 - 32, 512, 192, false, true, (string)null, false); Utility.drawTextWithShadow(b, Game1.content.LoadString("Strings\\StringsFromCSFiles:PurchaseAnimalsMenu.cs.11357"), Game1.dialogueFont, new Vector2((float)(Game1.viewport.Width / 2 - 256 + 32 + 8), (float)(Game1.viewport.Height / 2 - 128 + 8)), Game1.textColor, 1f, -1f, -1, -1, 1f, 3); this.textBox.Draw(b, true); this.doneNamingButton.draw(b); this.randomButton.draw(b); } } if (!Game1.globalFade && this.okButton != null) { this.okButton.draw(b); } if (this.hovered != null) { if ((this.hovered.item as StardewValley.Object).Type != null) { IClickableMenu.drawHoverText(b, Game1.parseText((this.hovered.item as StardewValley.Object).Type, Game1.dialogueFont, 320), Game1.dialogueFont, 0, 0, -1, (string)null, -1, (string[])null, (Item)null, 0, -1, -1, -1, -1, 1f, (CraftingRecipe)null); } else { string animalTitle = PurchaseAnimalsMenu.getAnimalTitle(this.hovered.hoverText); SpriteText.drawStringWithScrollBackground(b, animalTitle, this.xPositionOnScreen + IClickableMenu.spaceToClearSideBorder + 64, this.yPositionOnScreen + this.height - 32 + IClickableMenu.spaceToClearTopBorder / 2 + 8, "Truffle Pig", 1f, -1); SpriteText.drawStringWithScrollBackground(b, "$" + Game1.content.LoadString("Strings\\StringsFromCSFiles:LoadGameMenu.cs.11020", (object)this.hovered.item.salePrice()), this.xPositionOnScreen + IClickableMenu.spaceToClearSideBorder + 128, this.yPositionOnScreen + this.height + 64 + IClickableMenu.spaceToClearTopBorder / 2 + 8, "$99999999g", Game1.player.Money >= this.hovered.item.salePrice() ? 1f : 0.5f, -1); string animalDescription = PurchaseAnimalsMenu.getAnimalDescription(this.hovered.hoverText); IClickableMenu.drawHoverText(b, Game1.parseText(animalDescription, Game1.smallFont, 320), Game1.smallFont, 0, 0, -1, animalTitle, -1, (string[])null, (Item)null, 0, -1, -1, -1, -1, 1f, (CraftingRecipe)null); } } Game1.mouseCursorTransparency = 1f; this.drawMouse(b); }
public override void draw(SpriteBatch b) { if (!this.onFarm && !Game1.dialogueUp && !Game1.globalFade) { b.Draw(Game1.fadeToBlackRect, Game1.graphics.GraphicsDevice.Viewport.Bounds, Color.Black * 0.75f); SpriteText.drawStringWithScrollBackground(b, farmName[framework.expansionSelected(currentFarm.Name) ? 1 : 0], xPositionOnScreen + width / 4 + Game1.tileSize / 5, yPositionOnScreen, "Expansion", 1f, -1); SpriteText.drawStringWithScrollBackground(b, Game1.content.LoadString("Strings\\StringsFromCSFiles:PurchaseAnimalsMenu.cs.11354", new object[0]), this.xPositionOnScreen + IClickableMenu.spaceToClearSideBorder + Game1.tileSize, this.yPositionOnScreen + this.height + -Game1.tileSize / 2 + IClickableMenu.spaceToClearTopBorder / 2, "Truffle Pig", 1f, -1); Game1.drawDialogueBox(this.xPositionOnScreen, this.yPositionOnScreen, this.width, this.height, false, true, null, false); Game1.dayTimeMoneyBox.drawMoneyBox(b, -1, -1); this.previousFarmButton.draw(b); this.nextFarmButton.draw(b); using (List <ClickableTextureComponent> .Enumerator enumerator = this.animalsToPurchase.GetEnumerator()) { while (enumerator.MoveNext()) { ClickableTextureComponent current = enumerator.Current; current.draw(b, ((current.item as Object).Type != null) ? (Color.Black * 0.4f) : Color.White, 0.87f); } goto IL_2AE; } } if (!Game1.globalFade && this.onFarm) { string s = Game1.content.LoadString("Strings\\StringsFromCSFiles:PurchaseAnimalsMenu.cs.11355", new object[] { this.animalBeingPurchased.displayHouse, this.animalBeingPurchased.displayType }); SpriteText.drawStringWithScrollBackground(b, s, Game1.viewport.Width / 2 - SpriteText.getWidthOfString(s) / 2, Game1.tileSize / 4, "", 1f, -1); if (this.namingAnimal) { b.Draw(Game1.fadeToBlackRect, Game1.graphics.GraphicsDevice.Viewport.Bounds, Color.Black * 0.75f); Game1.drawDialogueBox(Game1.viewport.Width / 2 - Game1.tileSize * 4, Game1.viewport.Height / 2 - Game1.tileSize * 3 - Game1.tileSize / 2, Game1.tileSize * 8, Game1.tileSize * 3, false, true, null, false); Utility.drawTextWithShadow(b, Game1.content.LoadString("Strings\\StringsFromCSFiles:PurchaseAnimalsMenu.cs.11357", new object[0]), Game1.dialogueFont, new Vector2((float)(Game1.viewport.Width / 2 - Game1.tileSize * 4 + Game1.tileSize / 2 + 8), (float)(Game1.viewport.Height / 2 - Game1.tileSize * 2 + 8)), Game1.textColor, 1f, -1f, -1, -1, 1f, 3); this.textBox.Draw(b); this.doneNamingButton.draw(b); this.randomButton.draw(b); } } IL_2AE: if (!Game1.globalFade && this.okButton != null) { this.okButton.draw(b); } if (this.hovered != null) { if ((this.hovered.item as Object).Type != null) { IClickableMenu.drawHoverText(b, Game1.parseText((this.hovered.item as Object).Type, Game1.dialogueFont, Game1.tileSize * 5), Game1.dialogueFont, 0, 0, -1, null, -1, null, null, 0, -1, -1, -1, -1, 1f, null); } else { string animalTitle = PurchaseAnimalsMenu.getAnimalTitle(this.hovered.hoverText); SpriteText.drawStringWithScrollBackground(b, animalTitle, this.xPositionOnScreen + IClickableMenu.spaceToClearSideBorder + Game1.tileSize + Game1.tileSize / 2, this.yPositionOnScreen + this.height + Game1.tileSize - Game1.tileSize / 4 + IClickableMenu.spaceToClearTopBorder / 2, "Truffle Pig", 1f, -1); SpriteText.drawStringWithScrollBackground(b, "$" + Game1.content.LoadString("Strings\\StringsFromCSFiles:LoadGameMenu.cs.11020", new object[] { this.hovered.item.salePrice() }), this.xPositionOnScreen + IClickableMenu.spaceToClearSideBorder + Game1.tileSize * 2, this.yPositionOnScreen + this.height + Game1.tileSize * 2 + IClickableMenu.spaceToClearTopBorder / 2, "$99999999g", (Game1.player.Money >= this.hovered.item.salePrice()) ? 1f : 0.5f, -1); string animalDescription = PurchaseAnimalsMenu.getAnimalDescription(this.hovered.hoverText); IClickableMenu.drawHoverText(b, Game1.parseText(animalDescription, Game1.smallFont, Game1.tileSize * 5), Game1.smallFont, 0, 0, -1, animalTitle, -1, null, null, 0, -1, -1, -1, -1, 1f, null); } } Game1.mouseCursorTransparency = 1f; base.drawMouse(b); }
/// <summary>The prefix for the Draw method.</summary> /// <param name="b">The spritebatch to draw the menu to.</param> /// <param name="__instance">The <see cref="PurchaseAnimalsMenu"/> instance being patched.</param> /// <returns>False meaning the original method won't get ran.</returns> internal static bool DrawPrefix(SpriteBatch b, PurchaseAnimalsMenu __instance) { // get required private members bool onFarm = (bool)typeof(PurchaseAnimalsMenu).GetField("onFarm", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance); bool namingAnimal = (bool)typeof(PurchaseAnimalsMenu).GetField("namingAnimal", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance); FarmAnimal animalBeingPurchased = (FarmAnimal)typeof(PurchaseAnimalsMenu).GetField("animalBeingPurchased", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance); TextBox textBox = (TextBox)typeof(PurchaseAnimalsMenu).GetField("textBox", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance); // draw menu to pick which animal to buy if (!onFarm && !Game1.dialogueUp && !Game1.globalFade) { // dark background b.Draw( texture: Game1.fadeToBlackRect, destinationRectangle: Game1.graphics.GraphicsDevice.Viewport.Bounds, color: Color.Black * 0.75f ); // 'livestock' label SpriteText.drawStringWithScrollBackground( b: b, s: "Livestock:", x: __instance.xPositionOnScreen + 96, y: __instance.yPositionOnScreen ); // menu background Game1.drawDialogueBox( x: __instance.xPositionOnScreen, y: __instance.yPositionOnScreen, width: __instance.width, height: __instance.height, speaker: false, drawOnlyBox: true ); // redraw the money box over the dark overlay Game1.dayTimeMoneyBox.drawMoneyBox(b, -1, -1); // animal icons foreach (ClickableTextureComponent textureComponent in __instance.animalsToPurchase) { textureComponent.draw(b, (textureComponent.item as StardewValley.Object).Type != null ? Color.Black * 0.4f : Color.White, 0.87f, 0); } } else if (!Game1.globalFade && onFarm) // the player is currently picking a house for the animal { string housingAnimalString = Game1.content.LoadString("Strings\\StringsFromCSFiles:PurchaseAnimalsMenu.cs.11355", animalBeingPurchased.displayHouse, animalBeingPurchased.displayType); // if the animal is a custom animal construct a different string to accomodate more than 1 possible building var animal = ModEntry.Instance.Api.GetAnimalBySubTypeName(animalBeingPurchased.type); if (animal != null) { var buildingsString = ""; for (var i = 0; i < animal.Data.Buildings.Count; i++) { var building = animal.Data.Buildings[i]; buildingsString += building; if (i != animal.Data.Buildings.Count - 1) { buildingsString += ", "; } } housingAnimalString = $"Choose a: {buildingsString} for your new {animalBeingPurchased.type}"; } // draw housing animal string; SpriteText.drawStringWithScrollBackground( b: b, s: housingAnimalString, x: Game1.viewport.Width / 2 - SpriteText.getWidthOfString(housingAnimalString, 999999) / 2, y: 16 ); // draw naming text box if (namingAnimal) { // dark background b.Draw( texture: Game1.fadeToBlackRect, destinationRectangle: Game1.graphics.GraphicsDevice.Viewport.Bounds, color: Color.Black * 0.75f ); // background Game1.drawDialogueBox( x: Game1.viewport.Width / 2 - 256, y: Game1.viewport.Height / 2 - 192 - 32, width: 512, height: 192, speaker: false, drawOnlyBox: true ); // 'Name your new animal' label Utility.drawTextWithShadow( b: b, text: Game1.content.LoadString("Strings\\StringsFromCSFiles:PurchaseAnimalsMenu.cs.11357"), font: Game1.dialogueFont, position: new Vector2((float)(Game1.viewport.Width / 2 - 256 + 32 + 8), (float)(Game1.viewport.Height / 2 - 128 + 8)), color: Game1.textColor ); // draw textbox textBox.Draw(b, true); // draw buttons __instance.doneNamingButton.draw(b); __instance.randomButton.draw(b); } } if (!Game1.globalFade && __instance.okButton != null) { __instance.okButton.draw(b); } if (__instance.hovered != null) { // check if the hovered item is available for purchase if ((__instance.hovered.item as StardewValley.Object).Type != null) { // display not available for purchase message IClickableMenu.drawHoverText( b, Game1.parseText((__instance.hovered.item as StardewValley.Object).Type, Game1.dialogueFont, 320), Game1.dialogueFont ); } else { // draw the animal type label SpriteText.drawStringWithScrollBackground( b: b, s: __instance.hovered.hoverText, x: __instance.xPositionOnScreen + 436, y: __instance.yPositionOnScreen, placeHolderWidthText: "Truffle Pig" ); // draw the animal price label SpriteText.drawStringWithScrollBackground( b: b, s: "$" + Game1.content.LoadString("Strings\\StringsFromCSFiles:LoadGameMenu.cs.11020", (object)__instance.hovered.item.salePrice()), x: __instance.xPositionOnScreen + 796, y: __instance.yPositionOnScreen, placeHolderWidthText: "$99999999g", alpha: Game1.player.Money >= __instance.hovered.item.salePrice() ? 1f : 0.5f ); // draw the animal description string animalDescription = PurchaseAnimalsMenu.getAnimalDescription(__instance.hovered.hoverText); IClickableMenu.drawHoverText( b, Game1.parseText(animalDescription, Game1.smallFont, 320), Game1.smallFont ); } } Game1.mouseCursorTransparency = 1f; __instance.drawMouse(b); return(false); }
internal static void PurchaseAnimalsMenuPatch(PurchaseAnimalsMenu __instance, bool ___onFarm, bool ___namingAnimal, TextBox ___textBox) { try { int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position purchaseAnimalsMenu = __instance; isOnFarm = ___onFarm; if (___onFarm && ___namingAnimal) { string toSpeak = ""; if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) { toSpeak = "Cancel Button"; } else if (__instance.doneNamingButton != null && __instance.doneNamingButton.containsPoint(x, y)) { toSpeak = "OK Button"; } else if (__instance.randomButton != null && __instance.randomButton.containsPoint(x, y)) { toSpeak = "Random Name Button"; } else if (__instance.textBoxCC != null && __instance.textBoxCC.containsPoint(x, y)) { toSpeak = "Name Text Box"; string?value = ___textBox.Text; if (value != "" && value != null && value != "null") { toSpeak = $"{toSpeak}, Value: {value}"; } } if (purchaseAnimalMenuQuery != toSpeak) { purchaseAnimalMenuQuery = toSpeak; if (firstTimeInNamingMenu) { toSpeak = $"Enter the name of animal in the name text box. {toSpeak}"; firstTimeInNamingMenu = false; } MainClass.ScreenReader.Say(toSpeak, true); } } else if (___onFarm && !___namingAnimal) { firstTimeInNamingMenu = true; } else if (!___onFarm && !___namingAnimal) { firstTimeInNamingMenu = true; if (__instance.hovered != null) { string toSpeak = ""; if (((StardewValley.Object)__instance.hovered.item).Type != null) { toSpeak = ((StardewValley.Object)__instance.hovered.item).Type; } else { string displayName = PurchaseAnimalsMenu.getAnimalTitle(__instance.hovered.hoverText); int price = __instance.hovered.item.salePrice(); string description = PurchaseAnimalsMenu.getAnimalDescription(__instance.hovered.hoverText); toSpeak = $"{displayName}, Price: {price}g, Description: {description}"; } if (purchaseAnimalMenuQuery != toSpeak) { purchaseAnimalMenuQuery = toSpeak; MainClass.ScreenReader.Say(toSpeak, true); } return; } } } catch (Exception e) { MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); } }