Пример #1
0
        public virtual Item TryToPlace(Item item, int amount)
        {
            Math.Min(amount, item.Stack);
            int stack_capacity = Math.Min(amount, GetDonatableAmount(item));

            if (stack_capacity == 0)
            {
                return(item);
            }
            Item donation_stack = item.getOne();

            donation_stack.Stack = stack_capacity;
            item.Stack          -= stack_capacity;
            Item leftover_items = ItemsToGrabMenu.tryToAddItem(donation_stack, "Ship");

            if (leftover_items != null)
            {
                item.Stack += leftover_items.Stack;
            }
            if (onItemChanged != null)
            {
                onItemChanged();
            }
            if (item.Stack <= 0)
            {
                return(null);
            }
            return(item);
        }
Пример #2
0
        public override void receiveLeftClick(int x, int y, bool playSound = true)
        {
            Item old      = heldItem;
            int  oldStack = old?.Stack ?? (-1);

            if (isWithinBounds(x, y))
            {
                base.receiveLeftClick(x, y, playSound: false);
                if (itemChangeBehavior == null && old == null && heldItem != null && Game1.oldKBState.IsKeyDown(Keys.LeftShift))
                {
                    heldItem = ItemsToGrabMenu.tryToAddItem(heldItem, "Ship");
                }
            }
            bool sound = true;

            if (ItemsToGrabMenu.isWithinBounds(x, y))
            {
                heldItem = ItemsToGrabMenu.leftClick(x, y, heldItem, playSound: false);
                if ((heldItem != null && old == null) || (heldItem != null && old != null && !heldItem.Equals(old)))
                {
                    if (itemChangeBehavior != null)
                    {
                        sound = itemChangeBehavior(heldItem, ItemsToGrabMenu.getInventoryPositionOfClick(x, y), old, this, onRemoval: true);
                    }
                    if (sound)
                    {
                        Game1.playSound("dwop");
                    }
                }
                if ((heldItem == null && old != null) || (heldItem != null && old != null && !heldItem.Equals(old)))
                {
                    Item tmp = heldItem;
                    if (heldItem == null && ItemsToGrabMenu.getItemAt(x, y) != null && oldStack < ItemsToGrabMenu.getItemAt(x, y).Stack)
                    {
                        tmp       = old.getOne();
                        tmp.Stack = oldStack;
                    }
                    if (itemChangeBehavior != null)
                    {
                        sound = itemChangeBehavior(old, ItemsToGrabMenu.getInventoryPositionOfClick(x, y), tmp, this);
                    }
                    if (sound)
                    {
                        Game1.playSound("Ship");
                    }
                }
                if (heldItem is Object && (bool)(heldItem as Object).isRecipe)
                {
                    string recipeName = heldItem.Name.Substring(0, heldItem.Name.IndexOf("Recipe") - 1);
                    try
                    {
                        if ((heldItem as Object).Category == -7)
                        {
                            Game1.player.cookingRecipes.Add(recipeName, 0);
                        }
                        else
                        {
                            Game1.player.craftingRecipes.Add(recipeName, 0);
                        }
                        poof = new TemporaryAnimatedSprite("TileSheets\\animations", new Rectangle(0, 320, 64, 64), 50f, 8, 0, new Vector2(x - x % 64 + 16, y - y % 64 + 16), flicker: false, flipped: false);
                        Game1.playSound("newRecipe");
                    }
                    catch (Exception)
                    {
                    }
                    heldItem = null;
                }
                else if (Game1.oldKBState.IsKeyDown(Keys.LeftShift) && Game1.player.addItemToInventoryBool(heldItem))
                {
                    heldItem = null;
                    if (itemChangeBehavior != null)
                    {
                        sound = itemChangeBehavior(heldItem, ItemsToGrabMenu.getInventoryPositionOfClick(x, y), old, this, onRemoval: true);
                    }
                    if (sound)
                    {
                        Game1.playSound("coin");
                    }
                }
            }
            if (okButton.containsPoint(x, y) && readyToClose())
            {
                Game1.playSound("bigDeSelect");
                Game1.exitActiveMenu();
            }
            if (trashCan.containsPoint(x, y) && heldItem != null && heldItem.canBeTrashed())
            {
                Utility.trashItem(heldItem);
                heldItem = null;
            }
        }