Esempio n. 1
0
 public override void receiveLeftClick(int x, int y, bool playSound = true)
 {
     base.receiveLeftClick(x, y);
     heldItem = inventory.leftClick(x, y, heldItem);
     if (upButton != null && upButton.containsPoint(x, y) && currentCraftingPage > 0)
     {
         Game1.playSound("coin");
         currentCraftingPage = Math.Max(0, currentCraftingPage - 1);
         _UpdateCurrentPageButtons();
         upButton.scale = upButton.baseScale;
     }
     if (downButton != null && downButton.containsPoint(x, y) && currentCraftingPage < pagesOfCraftingRecipes.Count - 1)
     {
         Game1.playSound("coin");
         currentCraftingPage = Math.Min(pagesOfCraftingRecipes.Count - 1, currentCraftingPage + 1);
         _UpdateCurrentPageButtons();
         downButton.scale = downButton.baseScale;
     }
     foreach (ClickableTextureComponent c in pagesOfCraftingRecipes[currentCraftingPage].Keys)
     {
         int times = ((!Game1.oldKBState.IsKeyDown(Keys.LeftShift)) ? 1 : 5);
         for (int i = 0; i < times; i++)
         {
             if (c.containsPoint(x, y) && !c.hoverText.Equals("ghosted") && pagesOfCraftingRecipes[currentCraftingPage][c].doesFarmerHaveIngredientsInInventory(getContainerContents()))
             {
                 clickCraftingRecipe(c, i == 0);
             }
         }
         if (heldItem != null && Game1.oldKBState.IsKeyDown(Keys.LeftShift) && heldItem.maximumStackSize() == 1 && Game1.player.couldInventoryAcceptThisItem(heldItem))
         {
             Game1.player.addItemToInventoryBool(heldItem);
             heldItem = null;
         }
     }
     if (trashCan != null && trashCan.containsPoint(x, y) && heldItem != null && heldItem.canBeTrashed())
     {
         Utility.trashItem(heldItem);
         heldItem = null;
     }
     else if (heldItem != null && !isWithinBounds(x, y) && heldItem.canBeTrashed())
     {
         Game1.playSound("throwDownITem");
         Game1.createItemDebris(heldItem, Game1.player.getStandingPosition(), Game1.player.FacingDirection);
         heldItem = null;
     }
 }
Esempio n. 2
0
 public override void receiveLeftClick(int x, int y, bool playSound = true)
 {
     heldItem = inventory.leftClick(x, y, heldItem, playSound);
     if (!isWithinBounds(x, y) && readyToClose() && trashCan != null)
     {
         trashCan.containsPoint(x, y);
     }
     if (okButton != null && okButton.containsPoint(x, y) && readyToClose())
     {
         exitThisMenu();
         if (Game1.currentLocation.currentEvent != null && Game1.currentLocation.currentEvent.CurrentCommand > 0)
         {
             Game1.currentLocation.currentEvent.CurrentCommand++;
         }
         Game1.playSound("bigDeSelect");
     }
     if (trashCan != null && 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)
 {
     if (!placingStructure)
     {
         heldItem = inventory.leftClick(x, y, heldItem);
         for (int i = 0; i < sideTabs.Count; i++)
         {
             if (sideTabs[i].containsPoint(x, y) && currentTab != i)
             {
                 Game1.playSound("smallSelect");
                 if (i == 3)
                 {
                     placingStructure = true;
                     demolishing      = true;
                     parent.invisible = true;
                 }
                 else
                 {
                     sideTabs[currentTab].bounds.X -= widthToMoveActiveTab;
                     currentTab            = i;
                     sideTabs[i].bounds.X += widthToMoveActiveTab;
                 }
             }
         }
         foreach (ClickableComponent c in blueprintButtons[currentTab].Keys)
         {
             if (c.containsPoint(x, y))
             {
                 if (blueprintButtons[currentTab][c].doesFarmerHaveEnoughResourcesToBuild())
                 {
                     structureForPlacement = blueprintButtons[currentTab][c];
                     placingStructure      = true;
                     parent.invisible      = true;
                     if (currentTab == 1)
                     {
                         upgrading = true;
                     }
                     Game1.playSound("smallSelect");
                 }
                 else
                 {
                     Game1.addHUDMessage(new HUDMessage(Game1.content.LoadString("Strings\\StringsFromCSFiles:BlueprintsMenu.cs.10002"), Color.Red, 3500f));
                 }
                 break;
             }
         }
     }
     else if (demolishing)
     {
         if (!(Game1.currentLocation is Farm))
         {
             return;
         }
         if (Game1.IsClient)
         {
             Game1.addHUDMessage(new HUDMessage(Game1.content.LoadString("Strings\\StringsFromCSFiles:CataloguePage.cs.10148"), Color.Red, 3500f));
             return;
         }
         Vector2  tileLocation = new Vector2((Game1.viewport.X + Game1.getOldMouseX()) / 64, (Game1.viewport.Y + Game1.getOldMouseY()) / 64);
         Building destroyed    = ((Farm)Game1.currentLocation).getBuildingAt(tileLocation);
         if (Game1.IsMultiplayer && destroyed != null && destroyed.indoors.Value.farmers.Count() > 0)
         {
             Game1.addHUDMessage(new HUDMessage(Game1.content.LoadString("Strings\\StringsFromCSFiles:CataloguePage.cs.10149"), Color.Red, 3500f));
         }
         else if (destroyed != null && ((Farm)Game1.currentLocation).destroyStructure(destroyed))
         {
             int groundYTile = (int)destroyed.tileY + (int)destroyed.tilesHigh;
             for (int j = 0; j < destroyed.texture.Value.Bounds.Height / 64; j++)
             {
                 Game1.createRadialDebris(Game1.currentLocation, destroyed.textureName(), new Microsoft.Xna.Framework.Rectangle(destroyed.texture.Value.Bounds.Center.X, destroyed.texture.Value.Bounds.Center.Y, 4, 4), (int)destroyed.tileX + Game1.random.Next(destroyed.tilesWide), (int)destroyed.tileY + (int)destroyed.tilesHigh - j, Game1.random.Next(20, 45), groundYTile);
             }
             Game1.playSound("explosion");
             Utility.spreadAnimalsAround(destroyed, (Farm)Game1.currentLocation);
         }
         else
         {
             parent.invisible = false;
             placingStructure = false;
             demolishing      = false;
         }
     }
     else if (upgrading && Game1.currentLocation is Farm)
     {
         (Game1.currentLocation as Farm).tryToUpgrade(((Farm)Game1.getLocationFromName("Farm")).getBuildingAt(new Vector2((Game1.viewport.X + Game1.getOldMouseX()) / 64, (Game1.viewport.Y + Game1.getOldMouseY()) / 64)), structureForPlacement);
     }
     else if (!canPlaceThisBuildingOnTheCurrentMap(structureForPlacement, Game1.currentLocation))
     {
         Game1.addHUDMessage(new HUDMessage(Game1.content.LoadString("Strings\\StringsFromCSFiles:CataloguePage.cs.10152"), Color.Red, 3500f));
     }
     else if (!structureForPlacement.doesFarmerHaveEnoughResourcesToBuild())
     {
         Game1.addHUDMessage(new HUDMessage(Game1.content.LoadString("Strings\\StringsFromCSFiles:BlueprintsMenu.cs.10002"), Color.Red, 3500f));
     }
     else if (tryToBuild())
     {
         structureForPlacement.consumeResources();
         if (!structureForPlacement.blueprintType.Equals("Animals"))
         {
             Game1.playSound("axe");
         }
     }
     else if (!Game1.IsClient)
     {
         Game1.addHUDMessage(new HUDMessage(Game1.content.LoadString("Strings\\StringsFromCSFiles:BlueprintsMenu.cs.10016"), Color.Red, 3500f));
     }
 }
Esempio n. 4
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. 5
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);
            }
        }