/********* ** Private methods *********/ /// <summary>Add an item to the container from the player inventory.</summary> /// <param name="item">The item taken.</param> /// <param name="player">The player taking the item.</param> /// <remarks>This implementation replicates <see cref="StardewValley.Objects.Chest.grabItemFromInventory"/> without the slot limit (instead of using <c>Farm::shipItem</c> which does some weird things that don't work well with a full chest UI).</remarks> private void GrabItemFromInventoryImpl(Item item, SFarmer player) { // normalise if (item.Stack == 0) { item.Stack = 1; } // add to shipping bin this.ShippingBin.Filter(p => p != null); foreach (Item slot in this.Inventory) { if (!slot.canStackWith(item)) { continue; } item.Stack = slot.addToStack(item.Stack); if (item.Stack <= 0) { break; } } if (item.Stack > 0) { this.ShippingBin.Add(item); } // remove from player inventory player.removeItemFromInventory(item); // reopen menu IClickableMenu menu = Game1.activeClickableMenu; int snappedComponentID = menu.currentlySnappedComponent?.myID ?? -1; Game1.activeClickableMenu = menu = this.OpenMenu(); if (snappedComponentID != -1) { menu.currentlySnappedComponent = menu.getComponentWithID(snappedComponentID); menu.snapCursorToCurrentSnappedComponent(); } }
private void waitForServerConnection(Action onConnection) { if (Game1.server != null) { if (Game1.server.connected()) { onConnection(); return; } IClickableMenu thisMenu = Game1.activeClickableMenu; ConfirmationDialog.behavior onClose = delegate { Game1.activeClickableMenu = thisMenu; thisMenu.snapCursorToCurrentSnappedComponent(); }; Game1.activeClickableMenu = new ServerConnectionDialog(delegate(Farmer who) { onClose(who); onConnection(); }, onClose); } }