/// <summary>The prefix for the ReceiveLieftClick method.</summary> /// <param name="x">The X position of the cursor.</param> /// <param name="y">The Y position of the cursor.</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 ReceiveLeftClickPrefix(int x, int y, PurchaseAnimalsMenu __instance) { // get private members var freeze = (bool)typeof(PurchaseAnimalsMenu).GetField("freeze", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance); var onFarm = (bool)typeof(PurchaseAnimalsMenu).GetField("onFarm", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance); var namingAnimal = (bool)typeof(PurchaseAnimalsMenu).GetField("namingAnimal", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance); var animalBeingPurchased = (FarmAnimal)typeof(PurchaseAnimalsMenu).GetField("animalBeingPurchased", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance); var e = (TextBoxEvent)typeof(PurchaseAnimalsMenu).GetField("e", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance); var textBox = (TextBox)typeof(PurchaseAnimalsMenu).GetField("textBox", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance); var newAnimalHome = (Building)typeof(PurchaseAnimalsMenu).GetField("newAnimalHome", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance); var priceOfAnimal = (int)typeof(PurchaseAnimalsMenu).GetField("priceOfAnimal", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance); var multiplayer = (Multiplayer)typeof(Game1).GetField("multiplayer", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null); if (Game1.globalFade || freeze) { return(false); } if (__instance.okButton != null && __instance.okButton.containsPoint(x, y) && __instance.readyToClose()) { if (onFarm) { __instance.setUpForReturnToShopMenu(); Game1.playSound("smallSelect"); } else { Game1.exitActiveMenu(); Game1.playSound("bigDeSelect"); } } if (onFarm) // player is picking a house for the animal or naming the animal { Building buildingAt = (Game1.getLocationFromName("Farm") as Farm).getBuildingAt(new Vector2( (x + Game1.viewport.X) / 64, (y + Game1.viewport.Y) / 64 )); if (buildingAt != null && !namingAnimal) // picking a house for the animal and a building has been clicked { var buildingValid = false; // determine if building is valid if (!string.IsNullOrEmpty(animalBeingPurchased.buildingTypeILiveIn.Value)) // if 'buildingTypeILiveIn' is used, it's a default game animal { if (buildingAt.buildingType.Value.Contains(animalBeingPurchased.buildingTypeILiveIn.Value)) { buildingValid = true; } } else // animal is a custom animal { // get animal data var animal = ModEntry.Instance.Api.GetAnimalBySubTypeName(animalBeingPurchased.type); if (animal != null) { foreach (var building in animal.Data.Buildings) { if (buildingAt.buildingType.Value.ToLower() == building.ToLower()) { buildingValid = true; } } } } if (buildingValid) { // ensure building has space for animal if ((buildingAt.indoors.Value as AnimalHouse).isFull()) { // show 'That Building Is Full' message Game1.showRedMessage(Game1.content.LoadString("Strings\\StringsFromCSFiles:PurchaseAnimalsMenu.cs.11321")); } else if (animalBeingPurchased.harvestType.Value != 2) // animal 'lays' items { namingAnimal = true; newAnimalHome = buildingAt; if (animalBeingPurchased.sound.Value != null && Game1.soundBank != null) { ICue cue = Game1.soundBank.GetCue(animalBeingPurchased.sound.Value); cue.SetVariable("Pitch", 1200 + Game1.random.Next(-200, 201)); cue.Play(); } textBox.OnEnterPressed += e; textBox.Text = animalBeingPurchased.displayName; Game1.keyboardDispatcher.Subscriber = textBox; if (Game1.options.SnappyMenus) { __instance.currentlySnappedComponent = __instance.getComponentWithID(104); __instance.snapCursorToCurrentSnappedComponent(); } } else if (Game1.player.Money >= priceOfAnimal) { newAnimalHome = buildingAt; animalBeingPurchased.home = newAnimalHome; animalBeingPurchased.homeLocation.Value = new Vector2(newAnimalHome.tileX, newAnimalHome.tileY); animalBeingPurchased.setRandomPosition(animalBeingPurchased.home.indoors); (newAnimalHome.indoors.Value as AnimalHouse).animals.Add(animalBeingPurchased.myID, animalBeingPurchased); (newAnimalHome.indoors.Value as AnimalHouse).animalsThatLiveHere.Add(animalBeingPurchased.myID); newAnimalHome = null; namingAnimal = false; if (animalBeingPurchased.sound.Value != null && Game1.soundBank != null) { ICue cue = Game1.soundBank.GetCue(animalBeingPurchased.sound.Value); cue.SetVariable("Pitch", 1200 + Game1.random.Next(-200, 201)); cue.Play(); } Game1.player.Money -= priceOfAnimal; Game1.addHUDMessage(new HUDMessage(Game1.content.LoadString("Strings\\StringsFromCSFiles:PurchaseAnimalsMenu.cs.11324", animalBeingPurchased.type), Color.LimeGreen, 3500f)); animalBeingPurchased = new FarmAnimal(animalBeingPurchased.type, multiplayer.getNewID(), Game1.player.uniqueMultiplayerID); } else if (Game1.player.Money < priceOfAnimal) { Game1.dayTimeMoneyBox.moneyShakeTimer = 1000; } } else { // show '{0}s Can't Live There.' Game1.showRedMessage(Game1.content.LoadString("Strings\\StringsFromCSFiles:PurchaseAnimalsMenu.cs.11326", animalBeingPurchased.type)); } } if (!namingAnimal) { return(false); } if (__instance.doneNamingButton.containsPoint(x, y)) { __instance.textBoxEnter(textBox); Game1.playSound("smallSelect"); } else if (namingAnimal && __instance.randomButton.containsPoint(x, y)) { animalBeingPurchased.Name = Dialogue.randomName(); animalBeingPurchased.displayName = animalBeingPurchased.Name; textBox.Text = animalBeingPurchased.displayName; __instance.randomButton.scale = __instance.randomButton.baseScale; Game1.playSound("drumkit6"); } textBox.Update(); } else { foreach (ClickableTextureComponent textureComponent in __instance.animalsToPurchase) { if (textureComponent.containsPoint(x, y) && (textureComponent.item as StardewValley.Object).Type == null) { int num = textureComponent.item.salePrice(); if (Game1.player.Money >= num) { Game1.globalFadeToBlack(new Game1.afterFadeFunction(__instance.setUpForAnimalPlacement), 0.02f); Game1.playSound("smallSelect"); onFarm = true; animalBeingPurchased = new FarmAnimal(textureComponent.hoverText, multiplayer.getNewID(), Game1.player.UniqueMultiplayerID); priceOfAnimal = num; // calculate all the valid builds for the camera panning feature ValidBuildings = new List <Building>(); foreach (var building in Game1.getFarm().buildings) { // ensure the animal can live in the building var buildingValid = false; if (!string.IsNullOrEmpty(animalBeingPurchased.buildingTypeILiveIn.Value)) // if 'buildingTypeILiveIn' is used, it's a default game animal { if (building.buildingType.Value.Contains(animalBeingPurchased.buildingTypeILiveIn.Value)) { buildingValid = true; } } else // animal is a custom animal { // get animal data var animal = ModEntry.Instance.Api.GetAnimalBySubTypeName(animalBeingPurchased.type); if (animal != null) { foreach (var animalBuilding in animal.Data.Buildings) { if (building.buildingType.Value.ToLower() == animalBuilding.ToLower()) { buildingValid = true; } } break; } } // ensure the animal can live in the building if (!buildingValid) { continue; } // ensure the building isn't full var animalHouse = building.indoors.Value as AnimalHouse; if (animalHouse == null || animalHouse.isFull()) { continue; } ValidBuildings.Add(building); } } else { Game1.addHUDMessage(new HUDMessage(Game1.content.LoadString("Strings\\StringsFromCSFiles:PurchaseAnimalsMenu.cs.11325"), Color.Red, 3500f)); } } } } // reset potentially changed private members typeof(PurchaseAnimalsMenu).GetField("namingAnimal", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(__instance, namingAnimal); typeof(PurchaseAnimalsMenu).GetField("newAnimalHome", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(__instance, newAnimalHome); typeof(PurchaseAnimalsMenu).GetField("textBox", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(__instance, textBox); typeof(PurchaseAnimalsMenu).GetField("animalBeingPurchased", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(__instance, animalBeingPurchased); typeof(PurchaseAnimalsMenu).GetField("onFarm", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(__instance, onFarm); typeof(PurchaseAnimalsMenu).GetField("priceOfAnimal", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(__instance, priceOfAnimal); return(false); }
public static bool IsReadyToClose(PurchaseAnimalsMenu menu) { return(menu.readyToClose()); }