コード例 #1
0
        public override void receiveLeftClick(int x, int y, bool playSound = true)
        {
            base.receiveLeftClick(x, y, !this.destroyItemOnClick);
            //   Item test= this.ItemsToGrabMenu.leftClick(x, y, this.heldItem, false);

            Item test = this.heldItem;

            if (test == expandableObject)
            {
                if ((test as ExpandableInventoryObject).inventory == expandableObject.inventory)
                {
                    if (this.ItemsToGrabMenu.isWithinBounds(x, y) == false)
                    {
                        //if this is within my inventory return. Don't want to shove a bag into itself.
                        return;
                    }
                }
            }



            if (this.organizeButton.containsPoint(x, y))
            {
                ExpandableItemGrabMenu.organizeItemsInList(this.ItemsToGrabMenu.actualInventory);
            }

            if (this.LeftButton.containsPoint(x, y))
            {
                this.getNextInventory(true);
            }
            if (this.RightButton.containsPoint(x, y))
            {
                this.getNextInventory(false);
            }

            if (ItemsToGrabMenu.isWithinBounds(x, y) == false)
            {
                //Log.AsyncC("AWESOME");
                bool f = Util.isInventoryFull(this.ItemsToGrabMenu.actualInventory);
                if (f == false)
                {
                    this.heldItem = this.ItemsToGrabMenu.leftClick(x, y, this.heldItem, false);
                    if (this.heldItem != null)
                    {
                        if (Serialize.WriteToXMLFileSafetyCheck(Path.Combine(Serialize.PlayerDataPath, ""), this.heldItem, false) == false)
                        {
                            return;
                        }
                    }
                    Util.addItemToOtherInventory(this.ItemsToGrabMenu.actualInventory, this.heldItem);
                    // Log.AsyncG("not full");
                }
                else
                {
                    // this.heldItem = this.ItemsToGrabMenu.leftClick(x, y, this.heldItem, false);
                    // Util.addItemToInventorySilently(this.heldItem);
                }
                // this.ItemsToGrabMenu.inventory.Add(new ClickableComponent(new Rectangle(ItemsToGrabMenu.xPositionOnScreen + ItemsToGrabMenu.actualInventory.Count-1 % (this.capacity / this.ItemsToGrabMenu.rows) * Game1.tileSize + this.ItemsToGrabMenu.horizontalGap * (ItemsToGrabMenu.actualInventory.Count-1 % (this.capacity / this.ItemsToGrabMenu.rows)), ItemsToGrabMenu.yPositionOnScreen + ItemsToGrabMenu.actualInventory.Count-1 / (this.capacity / this.ItemsToGrabMenu.rows) * (Game1.tileSize + this.ItemsToGrabMenu.verticalGap) + (ItemsToGrabMenu.actualInventory.Count-1 / (this.capacity / this.ItemsToGrabMenu.rows) - 1) * Game1.pixelZoom -  (Game1.tileSize / 5), Game1.tileSize, Game1.tileSize), string.Concat(ItemsToGrabMenu.actualInventory.Count-1)));
                if (this.okButton.containsPoint(x, y) == false && this.organizeButton.containsPoint(x, y) == false && f == false && this.LeftButton.containsPoint(x, y) == false && this.RightButton.containsPoint(x, y) == false)
                {
                    //
                    Game1.activeClickableMenu = new ExpandableItemGrabMenu(this.expandableObject, this.ItemsToGrabMenu.actualInventory, this.Rows, false, true, new InventoryMenu.highlightThisItem(InventoryMenu.highlightAllItems), this.behaviorFunction, null, this.behaviorOnItemGrab, false, true, true, true, true, this.source, this.sourceItem);
                    //  Game1.playSound("Ship");
                }
            }
            else
            {
                if (Util.isInventoryFull(this.ItemsToGrabMenu.actualInventory) == true)
                {
                    Item i = new StardewValley.Object();
                    Item j = new StardewValley.Object();
                    j = this.ItemsToGrabMenu.leftClick(x, y, this.heldItem, false);
                    i = this.heldItem;
                    if (i != null)
                    {
                        if (Serialize.WriteToXMLFileSafetyCheck(Path.Combine(Serialize.PlayerDataPath, ""), i, false) == false)
                        {
                            return;
                        }
                    }

                    Util.addItemToInventorySilently(j);
                    // this.heldItem = null;

                    foreach (ClickableComponent current in ItemsToGrabMenu.inventory)
                    {
                        if (current.containsPoint(x, y))
                        {
                            int num = Convert.ToInt32(current.name);
                            //   Log.AsyncO(num);
                            this.ItemsToGrabMenu.actualInventory.RemoveAt(num);
                            //  Log.AsyncO("Remaining " + ItemsToGrabMenu.actualInventory.Count);
                        }
                    }
                    //   j=  this.ItemsToGrabMenu.leftClick(x, y, this.heldItem, false);
                    Util.addItemToOtherInventory(this.ItemsToGrabMenu.actualInventory, i);
                    // Log.AsyncG("item swap");
                    Game1.activeClickableMenu = new ExpandableItemGrabMenu(this.expandableObject, this.ItemsToGrabMenu.actualInventory, this.Rows, false, true, new InventoryMenu.highlightThisItem(InventoryMenu.highlightAllItems), this.behaviorFunction, null, this.behaviorOnItemGrab, false, true, true, true, true, this.source, this.sourceItem);
                    // Game1.playSound("Ship");
                    this.heldItem = null;
                    return;
                }



                this.heldItem = this.ItemsToGrabMenu.leftClick(x, y, this.heldItem, false);
                Util.addItemToInventoryElseDrop(this.heldItem);
                this.heldItem = null;

                foreach (ClickableComponent current in ItemsToGrabMenu.inventory)
                {
                    if (current.containsPoint(x, y))
                    {
                        int num = Convert.ToInt32(current.name);
                        //   Log.AsyncO(num);
                        this.ItemsToGrabMenu.actualInventory.RemoveAt(num);
                        //  Log.AsyncO("Remaining " + ItemsToGrabMenu.actualInventory.Count);
                    }
                }
                Game1.activeClickableMenu = new ExpandableItemGrabMenu(this.expandableObject, this.ItemsToGrabMenu.actualInventory, this.Rows, false, true, new InventoryMenu.highlightThisItem(InventoryMenu.highlightAllItems), this.behaviorFunction, null, this.behaviorOnItemGrab, false, true, true, true, true, this.source, this.sourceItem);
                //  Game1.playSound("Ship");
            }
            return;

            if (this.shippingBin && this.lastShippedHolder.containsPoint(x, y))
            {
                if (Game1.getFarm().lastItemShipped != null && Game1.player.addItemToInventoryBool(Game1.getFarm().lastItemShipped, false))
                {
                    Game1.playSound("coin");
                    Game1.getFarm().shippingBin.Remove(Game1.getFarm().lastItemShipped);
                    Game1.getFarm().lastItemShipped = null;
                    if (Game1.player.ActiveObject != null)
                    {
                        Game1.player.showCarrying();
                        Game1.player.Halt();
                    }
                }
                return;
            }
            if (this.chestColorPicker != null)
            {
                this.chestColorPicker.receiveLeftClick(x, y, true);
                if (this.sourceItem != null && this.sourceItem is Chest)
                {
                    (this.sourceItem as Chest).playerChoiceColor = this.chestColorPicker.getColorFromSelection(this.chestColorPicker.colorSelection);
                }
            }
            if (this.colorPickerToggleButton != null && this.colorPickerToggleButton.containsPoint(x, y))
            {
                Game1.player.showChestColorPicker = !Game1.player.showChestColorPicker;
                this.chestColorPicker.visible     = Game1.player.showChestColorPicker;
                Game1.soundBank.PlayCue("drumkit6");
            }
            if (this.heldItem == null && this.showReceivingMenu)
            {
                this.heldItem = this.ItemsToGrabMenu.leftClick(x, y, this.heldItem, false);
                //  Log.AsyncC("YAY");



                if (this.heldItem != null && this.behaviorOnItemGrab != null)
                {
                    this.behaviorOnItemGrab(this.heldItem, Game1.player);
                    if (Game1.activeClickableMenu != null && Game1.activeClickableMenu is ExpandableItemGrabMenu)
                    {
                        (Game1.activeClickableMenu as ExpandableItemGrabMenu).setSourceItem(this.sourceItem);
                    }
                }
                if (this.heldItem is StardewValley.Object && (this.heldItem as StardewValley.Object).parentSheetIndex == 326)
                {
                    this.heldItem = null;
                    Game1.player.canUnderstandDwarves = true;
                    this.poof = new TemporaryAnimatedSprite(Game1.animations, new Rectangle(0, 320, 64, 64), 50f, 8, 0, new Vector2((float)(x - x % Game1.tileSize + Game1.tileSize / 4), (float)(y - y % Game1.tileSize + Game1.tileSize / 4)), false, false);
                    Game1.playSound("fireball");
                }
                else if (this.heldItem is StardewValley.Object && (this.heldItem as StardewValley.Object).parentSheetIndex == 102)
                {
                    this.heldItem = null;
                    Game1.player.foundArtifact(102, 1);
                    this.poof = new TemporaryAnimatedSprite(Game1.animations, new Rectangle(0, 320, 64, 64), 50f, 8, 0, new Vector2((float)(x - x % Game1.tileSize + Game1.tileSize / 4), (float)(y - y % Game1.tileSize + Game1.tileSize / 4)), false, false);
                    Game1.playSound("fireball");
                }
                else if (this.heldItem is StardewValley.Object && (this.heldItem as StardewValley.Object).isRecipe)
                {
                    string key = this.heldItem.Name.Substring(0, this.heldItem.Name.IndexOf("Recipe") - 1);
                    try
                    {
                        if ((this.heldItem as StardewValley.Object).category == -7)
                        {
                            Game1.player.cookingRecipes.Add(key, 0);
                        }
                        else
                        {
                            Game1.player.craftingRecipes.Add(key, 0);
                        }
                        this.poof = new TemporaryAnimatedSprite(Game1.animations, new Rectangle(0, 320, 64, 64), 50f, 8, 0, new Vector2((float)(x - x % Game1.tileSize + Game1.tileSize / 4), (float)(y - y % Game1.tileSize + Game1.tileSize / 4)), false, false);
                        Game1.playSound("newRecipe");
                    }
                    catch (Exception)
                    {
                    }
                    this.heldItem = null;
                }
                else if (Game1.player.addItemToInventoryBool(this.heldItem, false))
                {
                    this.heldItem = null;
                    Game1.playSound("coin");
                }
            }
            else if ((this.reverseGrab || this.behaviorFunction != null) && this.isWithinBounds(x, y))
            {
                this.behaviorFunction(this.heldItem, Game1.player);
                if (Game1.activeClickableMenu != null && Game1.activeClickableMenu is ExpandableItemGrabMenu)
                {
                    (Game1.activeClickableMenu as ExpandableItemGrabMenu).setSourceItem(this.sourceItem);
                }
                if (this.destroyItemOnClick)
                {
                    this.heldItem = null;
                    return;
                }
            }
            if (this.organizeButton != null && this.organizeButton.containsPoint(x, y))
            {
                ExpandableItemGrabMenu.organizeItemsInList(this.ItemsToGrabMenu.actualInventory);
                Game1.activeClickableMenu = new ExpandableItemGrabMenu(this.expandableObject, this.ItemsToGrabMenu.actualInventory, this.Rows, false, true, new InventoryMenu.highlightThisItem(InventoryMenu.highlightAllItems), this.behaviorFunction, null, this.behaviorOnItemGrab, false, true, true, true, true, this.source, this.sourceItem);
                Game1.playSound("Ship");
                return;
            }
            if (this.heldItem != null && !this.isWithinBounds(x, y) && this.heldItem.canBeTrashed())
            {
                Game1.playSound("throwDownITem");
                Game1.createItemDebris(this.heldItem, Game1.player.getStandingPosition(), Game1.player.FacingDirection);
                this.heldItem = null;
            }
        }
コード例 #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;
            }
        }