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) { // Detect when player clicks on a machine in their inventory while another machine of the same type is selected, and the CTRL key is held if (e.Button == SButton.MouseLeft && IsCombineKeyHeld(Helper.Input)) { if (Game1.activeClickableMenu is GameMenu GM && GM.currentTab == GameMenu.inventoryTab) { if (TryGetClickedInventoryItem(GM, e, out Item ClickedItem, out int ClickedItemIndex)) { if (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; } }); } } } } }