/// <summary> /// Puts an item into the trash. /// </summary> /// <param name="From"></param> private void trashItem(ref InventoryMenu From) { if (From.activeItem != null) { this.trashedItem.item = From.activeItem; From.items.Remove(From.activeItem); From.activeItem = null; From.populateClickableItems(); } }
public InventoryTransferMenu(int x, int y, int width, int height, IList <Item> OtherItems, int OtherCapacity, int OtherRows = 6, int OtherCollumns = 6) : base(x, y, width, height, true) { this.playerInventory = new InventoryMenu(x, y, width, height, 6, 6, true, Game1.player.Items, Game1.player.MaxItems, Color.SandyBrown); this.otherItems = OtherItems; this.otherInventory = new InventoryMenu(this.playerInventory.xPositionOnScreen + this.playerInventory.width + 128, y, width, height, OtherRows, OtherCollumns, true, this.otherItems, OtherCapacity, Color.SandyBrown); this.isPlayerInventory = true; this.currentMode = CurrentMode.TransferItems; this.transferButton = new AnimatedButton(new StardustCore.Animations.AnimatedSprite("Transfer Button", new Vector2(this.playerInventory.xPositionOnScreen + this.playerInventory.width + 64, this.playerInventory.yPositionOnScreen + (this.playerInventory.height * .3f)), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "InventoryMenu", "ItemTransferButton"), new Animation(0, 0, 32, 32)), Color.White), new Rectangle(0, 0, 32, 32), 2f); this.trashButton = new AnimatedButton(new StardustCore.Animations.AnimatedSprite("Trash Button", new Vector2(this.playerInventory.xPositionOnScreen + this.playerInventory.width + 64, this.playerInventory.yPositionOnScreen + (this.playerInventory.height * .3f) + 96), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "InventoryMenu", "TrashButton"), new Animation(0, 0, 32, 32)), Color.White), new Rectangle(0, 0, 32, 32), 2f); this.trashedItem = new ItemDisplayButton(null, new StardustCore.Animations.AnimatedSprite("ItemBackground", new Vector2(this.playerInventory.xPositionOnScreen + this.playerInventory.width + 64, this.playerInventory.yPositionOnScreen + (this.playerInventory.height * .3f) + 180), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "InventoryMenu", "ItemBackground"), new Animation(0, 0, 32, 32)), Color.White), new Vector2(this.playerInventory.xPositionOnScreen + this.playerInventory.width + 64, this.playerInventory.yPositionOnScreen + (this.playerInventory.height * .3f) + 180), new Rectangle(0, 0, 32, 32), 2f, true, Color.White); }
/// <summary> /// Transfers an item between inventories. /// </summary> /// <param name="From"></param> /// <param name="To"></param> private void transferItem(ref InventoryMenu From, ref InventoryMenu To) { //Stack size control logic. foreach (Item I in To.items) { if (I == null) { continue; } if (From.activeItem.canStackWith(I)) { I.addToStack(From.activeItem.Stack); From.items.Remove(From.activeItem); From.activeItem = null; From.populateClickableItems(); To.populateClickableItems(); return; } else if (I.maximumStackSize() > I.Stack + From.activeItem.Stack && From.activeItem.canStackWith(I)) { int sizeLeft = I.getRemainingStackSpace(); I.Stack = I.maximumStackSize(); From.activeItem.Stack -= sizeLeft; break; } } if (To.isFull == false) { // bool addedItem = false; for (int i = 0; i < To.items.Count; i++) { if (To.items[i] == null) { To.items[i] = From.activeItem; addedItem = true; break; } } if (addedItem == false) { To.items.Add(From.activeItem); } From.items.Remove(From.activeItem); From.activeItem = null; From.populateClickableItems(); To.populateClickableItems(); } }
/// <summary> /// Trashes a single item from the given inventory. /// </summary> /// <param name="From"></param> private void transhOneItem(ref InventoryMenu From) { if (From.activeItem != null) { if (this.trashedItem.item == null) { this.trashedItem.item = From.activeItem.getOne(); From.activeItem.Stack--; if (From.activeItem.Stack == 0) { From.items.Remove(From.activeItem); } From.activeItem = null; From.populateClickableItems(); } else if (this.trashedItem.item != null) { if (From.activeItem.canStackWith(this.trashedItem.item)) { this.trashedItem.item.Stack += 1; From.activeItem.Stack--; if (From.activeItem.Stack == 0) { From.items.Remove(From.activeItem); } From.activeItem = null; From.populateClickableItems(); return; } else { this.trashedItem.item = From.activeItem.getOne(); From.activeItem.Stack--; if (From.activeItem.Stack == 0) { From.items.Remove(From.activeItem); } From.activeItem = null; From.populateClickableItems(); return; } } } }
/// <summary> /// Transfers exactly one item across inventories. /// </summary> /// <param name="From"></param> /// <param name="To"></param> private void transferOneItem(ref InventoryMenu From, ref InventoryMenu To) { //Stack size control logic. foreach (Item I in To.items) { if (I == null) { continue; } if (From.activeItem.canStackWith(I)) { //I.addToStack(I); I.Stack++; From.activeItem.Stack--; if (From.activeItem.Stack <= 0) { From.items.Remove(From.activeItem); } From.activeItem = null; From.populateClickableItems(); To.populateClickableItems(); return; } } if (To.isFull == false) { To.items.Add(From.activeItem.getOne()); From.activeItem.Stack--; if (From.activeItem.Stack <= 0) { From.items.Remove(From.activeItem); } From.activeItem = null; From.populateClickableItems(); To.populateClickableItems(); } }