Esempio n. 1
0
 public override void receiveLeftClick(int x, int y, bool playSound = true)
 {
     if (isWithinBounds(x, y))
     {
         Item clicked_item2 = inventory.getItemAt(x, y);
         if (clicked_item2 != null)
         {
             int clicked_index2 = inventory.getInventoryPositionOfClick(x, y);
             inventory.actualInventory[clicked_index2] = TryToPlace(clicked_item2, clicked_item2.Stack);
         }
     }
     if (ItemsToGrabMenu.isWithinBounds(x, y))
     {
         Item clicked_item = ItemsToGrabMenu.getItemAt(x, y);
         if (clicked_item != null)
         {
             int clicked_index = ItemsToGrabMenu.getInventoryPositionOfClick(x, y);
             ItemsToGrabMenu.actualInventory[clicked_index] = TryToGrab(clicked_item, clicked_item.Stack);
         }
     }
     if (okButton.containsPoint(x, y) && readyToClose())
     {
         exitThisMenu();
     }
 }
Esempio n. 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;
            }
        }
Esempio n. 3
0
        public override void receiveLeftClick(int x, int y, bool playSound = true)
        {
            foreach (ClickableComponent c in equipmentIcons)
            {
                if (c.containsPoint(x, y))
                {
                    bool heldItemWasNull = !checkHeldItem();
                    switch (c.name)
                    {
                    case "Hat":
                        if (checkHeldItem((Item i) => i == null || i is Hat || i is Pan))
                        {
                            Hat  tmp       = (Game1.player.CursorSlotItem is Pan) ? new Hat(71) : ((Hat)takeHeldItem());
                            Item heldItem2 = (Hat)Game1.player.hat;
                            heldItem2 = Utility.PerformSpecialItemGrabReplacement(heldItem2);
                            setHeldItem(heldItem2);
                            Game1.player.hat.Value = tmp;
                            if (Game1.player.hat.Value != null)
                            {
                                Game1.playSound("grassyStep");
                            }
                            else if (checkHeldItem())
                            {
                                Game1.playSound("dwop");
                            }
                        }
                        break;

                    case "Left Ring":
                        if (checkHeldItem((Item i) => i == null || i is Ring))
                        {
                            Ring tmp2 = (Ring)takeHeldItem();
                            if (Game1.player.leftRing.Value != null)
                            {
                                Game1.player.leftRing.Value.onUnequip(Game1.player, Game1.currentLocation);
                            }
                            setHeldItem((Ring)Game1.player.leftRing);
                            Game1.player.leftRing.Value = tmp2;
                            if (Game1.player.leftRing.Value != null)
                            {
                                Game1.player.leftRing.Value.onEquip(Game1.player, Game1.currentLocation);
                                Game1.playSound("crit");
                            }
                            else if (checkHeldItem())
                            {
                                Game1.playSound("dwop");
                            }
                        }
                        break;

                    case "Right Ring":
                        if (checkHeldItem((Item i) => i == null || i is Ring))
                        {
                            Ring tmp3 = (Ring)takeHeldItem();
                            if (Game1.player.rightRing.Value != null)
                            {
                                Game1.player.rightRing.Value.onUnequip(Game1.player, Game1.currentLocation);
                            }
                            setHeldItem((Ring)Game1.player.rightRing);
                            Game1.player.rightRing.Value = tmp3;
                            if (Game1.player.rightRing.Value != null)
                            {
                                Game1.player.rightRing.Value.onEquip(Game1.player, Game1.currentLocation);
                                Game1.playSound("crit");
                            }
                            else if (checkHeldItem())
                            {
                                Game1.playSound("dwop");
                            }
                        }
                        break;

                    case "Boots":
                        if (checkHeldItem((Item i) => i == null || i is Boots))
                        {
                            Boots tmp4 = (Boots)takeHeldItem();
                            if (Game1.player.boots.Value != null)
                            {
                                Game1.player.boots.Value.onUnequip();
                            }
                            setHeldItem((Boots)Game1.player.boots);
                            Game1.player.boots.Value = tmp4;
                            if (Game1.player.boots.Value != null)
                            {
                                Game1.player.boots.Value.onEquip();
                                Game1.playSound("sandyStep");
                                DelayedAction.playSoundAfterDelay("sandyStep", 150);
                            }
                            else if (checkHeldItem())
                            {
                                Game1.playSound("dwop");
                            }
                        }
                        break;

                    case "Shirt":
                        if (checkHeldItem((Item i) => i == null || (i is Clothing && (i as Clothing).clothesType.Value == 0)))
                        {
                            Clothing tmp5      = (Clothing)takeHeldItem();
                            Item     heldItem4 = (Clothing)Game1.player.shirtItem;
                            heldItem4 = Utility.PerformSpecialItemGrabReplacement(heldItem4);
                            setHeldItem(heldItem4);
                            Game1.player.shirtItem.Value = tmp5;
                            if (Game1.player.shirtItem.Value != null)
                            {
                                Game1.playSound("sandyStep");
                            }
                            else if (checkHeldItem())
                            {
                                Game1.playSound("dwop");
                            }
                        }
                        break;

                    case "Pants":
                        if (checkHeldItem((Item i) => i == null || (i is Clothing && (i as Clothing).clothesType.Value == 1) || (i is Object && (int)i.parentSheetIndex == 71)))
                        {
                            Clothing tmp6      = (Game1.player.CursorSlotItem is Object && (int)Game1.player.CursorSlotItem.parentSheetIndex == 71) ? new Clothing(15) : ((Clothing)takeHeldItem());
                            Item     heldItem6 = (Clothing)Game1.player.pantsItem;
                            heldItem6 = Utility.PerformSpecialItemGrabReplacement(heldItem6);
                            setHeldItem(heldItem6);
                            Game1.player.pantsItem.Value = tmp6;
                            if (Game1.player.pantsItem.Value != null)
                            {
                                Game1.playSound("sandyStep");
                            }
                            else if (checkHeldItem())
                            {
                                Game1.playSound("dwop");
                            }
                        }
                        break;
                    }
                    if (heldItemWasNull && checkHeldItem() && Game1.oldKBState.IsKeyDown(Keys.LeftShift))
                    {
                        int l;
                        for (l = 0; l < Game1.player.items.Count; l++)
                        {
                            if (Game1.player.items[l] == null || checkHeldItem((Item item) => Game1.player.items[l].canStackWith(item)))
                            {
                                if (Game1.player.CurrentToolIndex == l && checkHeldItem())
                                {
                                    Game1.player.CursorSlotItem.actionWhenBeingHeld(Game1.player);
                                }
                                setHeldItem(Utility.addItemToInventory(takeHeldItem(), l, inventory.actualInventory));
                                if (Game1.player.CurrentToolIndex == l && checkHeldItem())
                                {
                                    Game1.player.CursorSlotItem.actionWhenStopBeingHeld(Game1.player);
                                }
                                Game1.playSound("stoneStep");
                                return;
                            }
                        }
                    }
                }
            }
            setHeldItem(inventory.leftClick(x, y, takeHeldItem(), !Game1.oldKBState.IsKeyDown(Keys.LeftShift)));
            if (checkHeldItem((Item i) => i != null && Utility.IsNormalObjectAtParentSheetIndex(i, 434)))
            {
                Game1.playSound("smallSelect");
                Game1.player.eatObject(takeHeldItem() as Object, overrideFullness: true);
                Game1.exitActiveMenu();
            }
            else if (checkHeldItem() && Game1.oldKBState.IsKeyDown(Keys.LeftShift))
            {
                if (checkHeldItem((Item i) => i is Ring))
                {
                    if (Game1.player.leftRing.Value == null)
                    {
                        Game1.player.leftRing.Value = (takeHeldItem() as Ring);
                        Game1.player.leftRing.Value.onEquip(Game1.player, Game1.currentLocation);
                        Game1.playSound("crit");
                        return;
                    }
                    if (Game1.player.rightRing.Value == null)
                    {
                        Game1.player.rightRing.Value = (takeHeldItem() as Ring);
                        Game1.player.rightRing.Value.onEquip(Game1.player, Game1.currentLocation);
                        Game1.playSound("crit");
                        return;
                    }
                }
                else if (checkHeldItem((Item i) => i is Hat))
                {
                    if (Game1.player.hat.Value == null)
                    {
                        Game1.player.hat.Value = (takeHeldItem() as Hat);
                        Game1.playSound("grassyStep");
                        return;
                    }
                }
                else if (checkHeldItem((Item i) => i is Boots))
                {
                    if (Game1.player.boots.Value == null)
                    {
                        Game1.player.boots.Value = (takeHeldItem() as Boots);
                        Game1.player.boots.Value.onEquip();
                        Game1.playSound("sandyStep");
                        DelayedAction.playSoundAfterDelay("sandyStep", 150);
                        return;
                    }
                }
                else if (checkHeldItem((Item i) => i is Clothing && (i as Clothing).clothesType.Value == 0))
                {
                    if (Game1.player.shirtItem.Value == null)
                    {
                        Game1.player.shirtItem.Value = (takeHeldItem() as Clothing);
                        Game1.playSound("sandyStep");
                        DelayedAction.playSoundAfterDelay("sandyStep", 150);
                        return;
                    }
                }
                else if (checkHeldItem((Item i) => i is Clothing && (i as Clothing).clothesType.Value == 1) && Game1.player.pantsItem.Value == null)
                {
                    Game1.player.pantsItem.Value = (takeHeldItem() as Clothing);
                    Game1.playSound("sandyStep");
                    DelayedAction.playSoundAfterDelay("sandyStep", 150);
                    return;
                }
                if (inventory.getInventoryPositionOfClick(x, y) >= 12)
                {
                    int k;
                    for (k = 0; k < 12; k++)
                    {
                        if (Game1.player.items[k] == null || checkHeldItem((Item item) => Game1.player.items[k].canStackWith(item)))
                        {
                            if (Game1.player.CurrentToolIndex == k && checkHeldItem())
                            {
                                Game1.player.CursorSlotItem.actionWhenBeingHeld(Game1.player);
                            }
                            setHeldItem(Utility.addItemToInventory(takeHeldItem(), k, inventory.actualInventory));
                            if (checkHeldItem())
                            {
                                Game1.player.CursorSlotItem.actionWhenStopBeingHeld(Game1.player);
                            }
                            Game1.playSound("stoneStep");
                            return;
                        }
                    }
                }
                else if (inventory.getInventoryPositionOfClick(x, y) < 12)
                {
                    int j;
                    for (j = 12; j < Game1.player.items.Count; j++)
                    {
                        if (Game1.player.items[j] == null || checkHeldItem((Item item) => Game1.player.items[j].canStackWith(item)))
                        {
                            if (Game1.player.CurrentToolIndex == j && checkHeldItem())
                            {
                                Game1.player.CursorSlotItem.actionWhenBeingHeld(Game1.player);
                            }
                            setHeldItem(Utility.addItemToInventory(takeHeldItem(), j, inventory.actualInventory));
                            if (checkHeldItem())
                            {
                                Game1.player.CursorSlotItem.actionWhenStopBeingHeld(Game1.player);
                            }
                            Game1.playSound("stoneStep");
                            return;
                        }
                    }
                }
            }
            if (portrait.containsPoint(x, y))
            {
                portrait.name = (portrait.name.Equals("32") ? "8" : "32");
            }
            if (trashCan.containsPoint(x, y) && checkHeldItem((Item i) => i?.canBeTrashed() ?? false))
            {
                Utility.trashItem(takeHeldItem());
                if (Game1.options.SnappyMenus)
                {
                    snapCursorToCurrentSnappedComponent();
                }
            }
            else if (!isWithinBounds(x, y) && checkHeldItem((Item i) => i?.canBeTrashed() ?? false))
            {
                Game1.playSound("throwDownITem");
                Game1.createItemDebris(takeHeldItem(), Game1.player.getStandingPosition(), Game1.player.FacingDirection).DroppedByPlayerID.Value = Game1.player.UniqueMultiplayerID;
            }
            if (organizeButton != null && organizeButton.containsPoint(x, y))
            {
                ItemGrabMenu.organizeItemsInList(Game1.player.items);
                Game1.playSound("Ship");
            }
            if (junimoNoteIcon != null && junimoNoteIcon.containsPoint(x, y) && readyToClose())
            {
                Game1.activeClickableMenu = new JunimoNoteMenu(fromGameMenu: true);
            }
        }