private void Input_ButtonPressed(object sender, ButtonPressedEventArgs e) { Vector2 tile = e.Cursor.GrabTile; GameLocation location = Game1.currentLocation; if ( Context.IsPlayerFree && SButtonExtensions.IsActionButton(e.Button) && (location.furniture.Count > 0) && IsHutchAtTile(location, tile) ) { location.playSound("leafrustle"); if (CanSpawn(location)) { bool island = location.GetLocationContext() == GameLocation.LocationContext.Island; if (!location.IsOutdoors && Config.IslandButterflies) { island = true; } do { Vector2 v = new Vector2(tile.X + (float)Game1.random.Next(1, 3), tile.Y - 2f + (float)Game1.random.Next(-1, 2)); location.addCritter(new Butterfly(v, island).setStayInbounds(true)); } while (Game1.random.NextDouble() < 0.8); } } }
/// <summary>Raised after the player presses a button on the keyboard, controller, or mouse. /// This method implements... /// </summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event arguments.</param> private void Input_ButtonPressed(object sender, ButtonPressedEventArgs e) { Farmer who = Game1.player; bool useToolButtonPressed = SButtonExtensions.IsUseToolButton(e.Button); bool actionButtonPressed = SButtonExtensions.IsActionButton(e.Button); if ( (useToolButtonPressed || actionButtonPressed) && (who.CurrentTool != null) && Context.IsPlayerFree ) { } }
private void Input_ButtonPressed(object sender, ButtonPressedEventArgs e) { #if NEVER //DEBUG // Testing the Scarecrow transpiler harmony patch if (e.Button == SButton.R && Game1.activeClickableMenu == null && Game1.player.currentLocation is Farm farm) { farm.addCrows(); } #endif if (IsCombineKeyHeld(Helper.Input)) { if (Game1.activeClickableMenu is GameMenu GM && GM.currentTab == GameMenu.inventoryTab && TryGetClickedInventoryItem(GM, e, out Item ClickedItem, out int ClickedItemIndex)) { // Detect when player clicks on a machine in their inventory while another machine of the same type is selected if (SButtonExtensions.IsUseToolButton(e.Button) /*e.Button == SButton.MouseLeft*/ && Game1.player.CursorSlotItem is SObject SourceObj && ClickedItem is SObject TargetObj && CanCombine(SourceObj, TargetObj)) { if (!SourceObj.TryGetCombinedQuantity(out int SourceQuantity)) { SourceQuantity = SourceObj.Stack; } if (!TargetObj.TryGetCombinedQuantity(out int TargetQuantity)) { TargetQuantity = TargetObj.Stack; } TargetObj.SetCombinedQuantity(SourceQuantity + TargetQuantity); Game1.player.CursorSlotItem = null; // Clicking an item will make the game set it to the new CursorSlotItem, but since we just combined them, we want the CursorSlotItem to be empty DelayHelpers.InvokeLater(1, () => { if (Game1.player.CursorSlotItem != null && Game1.player.Items[ClickedItemIndex] == null) { Game1.player.Items[ClickedItemIndex] = Game1.player.CursorSlotItem; Game1.player.CursorSlotItem = null; } }); } // Right-clicking a combined machine splits it to its un-combined state else if (SButtonExtensions.IsActionButton(e.Button) /*e.Button == SButton.MouseRight*/ && Game1.player.CursorSlotItem == null && ClickedItem is SObject ClickedObject && ClickedObject.IsCombinedMachine() && ClickedObject.TryGetCombinedQuantity(out int CombinedQuantity) && CombinedQuantity > 1) { ClickedObject.modData.Remove(ModDataQuantityKey); ClickedObject.Stack += CombinedQuantity - 1; Logger.Log(string.Format("De-combined {0} (Stack={1})", ClickedObject.DisplayName, CombinedQuantity), InfoLogLevel); } }
private void Input_ButtonPressed(object sender, ButtonPressedEventArgs e) { if (!Context.IsWorldReady || !Context.IsPlayerFree || Game1.activeClickableMenu != null || !SButtonExtensions.IsActionButton(e.Button)) { return; } string str = Game1.currentLocation.doesTileHaveProperty((int)e.Cursor.GrabTile.X, (int)e.Cursor.GrabTile.Y, "Action", "Buildings"); if (str == "Buy General") { if (this._config.Pierre && (this._config.ShopsAlwaysOpen || this.IsNpcInLocation("Pierre", ""))) { base.Helper.Input.Suppress(e.Button); Game1.activeClickableMenu = new ShopMenu(((SeedShop)Game1.currentLocation).shopStock(), 0, "Pierre"); return; } return; } else { if (str == "Carpenter") { if (this._config.ShopsAlwaysOpen) { NPC npc = Game1.currentLocation.characters.Find("Robin"); if (npc != null) { Vector2 vector = npc.getTileLocation(); object[] objArray1 = new object[] { new Location((int)vector.X, (int)vector.Y) }; base.Helper.Reflection.GetMethod(Game1.currentLocation, "carpenters", true).Invoke(objArray1); goto TR_0016; } } else { this.Carpenter(); goto TR_0016; } } else if (str == "AnimalShop") { if (this._config.Ranch) { if (!this._config.ShopsAlwaysOpen) { NPC npc = Game1.currentLocation.characters.Find("Marnie"); if (npc != null) { Vector2 vector = npc.getTileLocation(); object[] objArray = new object[] { new Location((int)vector.X, ((int)vector.Y) + 1) }; base.Helper.Reflection.GetMethod(Game1.currentLocation, "animalShop", true).Invoke(objArray); goto TR_000F; } } else { this.AnimalShop(); goto TR_000F; } } } else if (str == "Buy Fish") { if (this._config.FishShop && this._config.ShopsAlwaysOpen || this.IsNpcInLocation("Willy", "") || this.IsNpcInLocation("Willy", "Beach")) { base.Helper.Input.Suppress(e.Button); Game1.activeClickableMenu = new ShopMenu(Utility.getFishShopStock(Game1.player), 0, "Willy"); return; } } else if (str == "Blacksmith") { if (this._config.Blacksmith) { if (!this._config.ShopsAlwaysOpen) { NPC npc = Game1.currentLocation.characters.Find("Clint"); if (npc != null) { this.BlackSmith(npc); goto TR_0005; } } else { this.BlackSmith(Game1.getCharacterFromName("Clint", false)); goto TR_0005; } } } else { if (str != "IceCreamStand") { return; } if (this._config.IceCreamStand && this._config.ShopsAlwaysOpen || this._config.IceCreamInAllSeasons || SDate.Now().Season == "summer") { Dictionary <StardewValley.ISalable, int[]> dictionary = new Dictionary <StardewValley.ISalable, int[]>(); int[] numArray = new int[] { 250, 0x7fff_ffff }; dictionary.Add(new StardewValley.Object(0xe9, 1, false, -1, 0), numArray); Game1.activeClickableMenu = new ShopMenu(dictionary, 0, null); base.Helper.Input.Suppress(e.Button); } } return; } TR_0005: base.Helper.Input.Suppress(e.Button); return; TR_000F: base.Helper.Input.Suppress(e.Button); return; TR_0016: base.Helper.Input.Suppress(e.Button); }