コード例 #1
0
        // Added [item swap] support
        public override void receiveLeftClick(int x, int y, bool playSound = true)
        {
            Item heldItem = this.heldItem;

            if (!holdingMuseumPiece)
            {
                this.heldItem = null;
            }

            LibraryMuseum museum = Game1.currentLocation as LibraryMuseum;

            // Place item at a museum slot
            if (heldItem != null && this.heldItem != null &&
                (y < Game1.viewport.Height - (height - (IClickableMenu.borderWidth + IClickableMenu.spaceToClearTopBorder + 192))))
            {
                int x1 = (x + Game1.viewport.X) / 64;
                int y1 = (y + Game1.viewport.Y) / 64;

                // Place item at an empty museum slot
                if (museum.isTileSuitableForMuseumPiece(x1, y1) &&
                    museum.isItemSuitableForDonation(this.heldItem))
                {
                    int parentSheetIndex = this.heldItem.ParentSheetIndex;
                    int count            = museum.getRewardsForPlayer(Game1.player).Count;

                    // Add item to the current position
                    museum.museumPieces.Add(new Vector2((float)x1, (float)y1), (this.heldItem as StardewValley.Object).ParentSheetIndex);


                    Game1.playSound("stoneStep");
                    holdingMuseumPiece = false;

                    // Clear hover information
                    selectedItemDescription = null;
                    selectedItemTitle       = null;
                    selectedItem            = null;

                    // Play item placement sound
                    Game1.playSound("newArtifact");

                    // If the player has no donatable item in his inventory, hide the inventory
                    //if (!museum.doesFarmerHaveAnythingToDonate(Game1.player))
                    //{
                    //    showInventory = false;
                    //}

                    //Game1.player.completeQuest(24);
                    --this.heldItem.Stack;
                    if (this.heldItem.Stack <= 0)
                    {
                        this.heldItem = (Item)null;
                    }

                    //int num = museum.museumPieces.Count();
                    //if (num >= 95)
                    //{
                    //    Game1.getAchievement(5);
                    //}
                    //else if (num >= 40)
                    //{
                    //    Game1.getAchievement(28);
                    //}
                }

                // Place item at an already in-use museum slot and swap it with its current item
                else if (LibraryMuseumHelper.IsTileSuitableForMuseumPiece(x1, y1) &&
                         museum.isItemSuitableForDonation(this.heldItem))
                {
                    Vector2 keySrc  = new Vector2((float)oldX1, (float)oldY1);
                    Vector2 keyDest = new Vector2((float)x1, (float)y1);

                    Item swapItem = null;

                    // Remove current item at museum slot
                    LibraryMuseum currentLocation = Game1.currentLocation as LibraryMuseum;
                    if (currentLocation.museumPieces.ContainsKey(keyDest))
                    {
                        swapItem = (Item) new StardewValley.Object(currentLocation.museumPieces[keyDest], 1, false, -1, 0);
                        currentLocation.museumPieces.Remove(keyDest);
                    }

                    // Place held item at the museum slot
                    currentLocation.museumPieces.Add(keyDest, (this.heldItem as StardewValley.Object).ParentSheetIndex);

                    // Place removed item at the old location of the held item to complete the swap
                    if (swapItem != null)
                    {
                        currentLocation.museumPieces.Add(keySrc, (swapItem as StardewValley.Object).ParentSheetIndex);
                    }

                    Game1.playSound("stoneStep");
                    holdingMuseumPiece = false;

                    // Clear hover information
                    selectedItemDescription = null;
                    selectedItemTitle       = null;
                    selectedItem            = null;

                    Game1.playSound("newArtifact");

                    --this.heldItem.Stack;
                    if (this.heldItem.Stack <= 0)
                    {
                        this.heldItem = (Item)null;
                    }
                }
            }

            // Grab an item which is already located in the museum
            else if (this.heldItem == null)
            {
                Vector2       key             = new Vector2((float)((x + Game1.viewport.X) / 64), (float)((y + Game1.viewport.Y) / 64));
                LibraryMuseum currentLocation = Game1.currentLocation as LibraryMuseum;
                if (currentLocation.museumPieces.ContainsKey(key))
                {
                    // save current slot of the item so it can be swapped
                    this.heldItem = (Item) new StardewValley.Object(currentLocation.museumPieces[key], 1, false, -1, 0);
                    oldX1         = (int)key.X;
                    oldY1         = (int)key.Y;

                    // Hover information
                    selectedItemDescription = this.heldItem?.getDescription();
                    selectedItemTitle       = this.heldItem?.DisplayName;

                    selectedItem = this.heldItem;

                    // Restart the info fade timer
                    lock (lockInfoFadeTimer)
                    {
                        if (infoFadeTimer != null)
                        {
                            infoFadeTimerCurrentValue = infoFadeTimerStartValue;
                            infoFadeTimer.Start();
                        }
                    }

                    currentLocation.museumPieces.Remove(key);
                    holdingMuseumPiece = !currentLocation.museumAlreadyHasArtifact(this.heldItem.ParentSheetIndex);
                }
            }

            //if (this.heldItem != null && heldItem == null)
            //{
            //    this.menuMovingDown = true;
            //}

            //if (!readyToClose())
            //{
            //    return;
            //}

            //state = 2;
            //fadeTimer = 800;
            //fadeIntoBlack = true;
            //Game1.playSound("bigDeSelect");
        }
コード例 #2
0
        // Added [item swap] support
        public override void receiveLeftClick(int x, int y, bool playSound = true)
        {
            if (this.fadeTimer > 0)
            {
                return;
            }

            Item heldItem = this.heldItem;

            if (!holdingMuseumPieceRef.GetValue())
            {
                this.heldItem         = this.inventory.leftClick(x, y, this.heldItem, true);
                selectedInventoryItem = this.heldItem != null;
            }

            LibraryMuseum museum = Game1.currentLocation as LibraryMuseum;

            // Place item at a museum slot
            if (heldItem != null && this.heldItem != null &&
                (y < Game1.viewport.Height - (height - (IClickableMenu.borderWidth + IClickableMenu.spaceToClearTopBorder + 192)) ||
                 this.menuMovingDown || !selectedInventoryItem || !inventory.isWithinBounds(x, y)))
            {
                int x1 = (x + Game1.viewport.X) / 64;
                int y1 = (y + Game1.viewport.Y) / 64;

                // Place item at an empty museum slot
                if (museum.isTileSuitableForMuseumPiece(x1, y1) &&
                    museum.isItemSuitableForDonation(this.heldItem))
                {
                    int parentSheetIndex = this.heldItem.ParentSheetIndex;
                    int count            = museum.getRewardsForPlayer(Game1.player).Count;

                    // Add item to the current position
                    museum.museumPieces.Add(new Vector2((float)x1, (float)y1), (this.heldItem as StardewValley.Object).ParentSheetIndex);


                    Game1.playSound("stoneStep");
                    holdingMuseumPieceRef.SetValue(false);

                    PrepareHideItemInfoTooltip();

                    // Rewards
                    if (museum.getRewardsForPlayer(Game1.player).Count > count)
                    {
                        this.sparkleText = new SparklingText(Game1.dialogueFont, Game1.content.LoadString("Strings\\StringsFromCSFiles:NewReward"), Color.MediumSpringGreen, Color.White, false, 0.1, 2500, -1, 500);
                        Game1.playSound("reward");
                        this.globalLocationOfSparklingArtifact = new Vector2((float)(x1 * 64 + 32) - this.sparkleText.textWidth / 2f, (float)(y1 * 64 - 48));
                    }

                    else
                    {
                        Game1.playSound("newArtifact");
                    }

                    // If the player has no donatable item in his inventory, hide the inventory
                    if (!museum.doesFarmerHaveAnythingToDonate(Game1.player))
                    {
                        showInventory = false;
                    }

                    Game1.player.completeQuest(24);
                    --this.heldItem.Stack;
                    if (this.heldItem.Stack <= 0)
                    {
                        this.heldItem = (Item)null;
                    }

                    this.menuMovingDown = false;
                    int num = museum.museumPieces.Count();
                    if (num >= 95)
                    {
                        Game1.getAchievement(5);
                    }
                    else if (num >= 40)
                    {
                        Game1.getAchievement(28);
                    }
                    else if (selectedInventoryItem)
                    {
                        multiplayer.globalChatInfoMessage("donation", Game1.player.Name, "object:" + (object)parentSheetIndex);
                    }
                }

                // Place item at an already in-use museum slot and swap it with its current item
                else if (LibraryMuseumHelper.IsTileSuitableForMuseumPiece(x1, y1) &&
                         museum.isItemSuitableForDonation(this.heldItem) && !selectedInventoryItem)
                {
                    Vector2 keySrc  = new Vector2((float)oldX1, (float)oldY1);
                    Vector2 keyDest = new Vector2((float)x1, (float)y1);

                    Item swapItem = null;

                    // Remove current item at museum slot
                    LibraryMuseum currentLocation = Game1.currentLocation as LibraryMuseum;
                    if (currentLocation.museumPieces.ContainsKey(keyDest))
                    {
                        swapItem = (Item) new StardewValley.Object(currentLocation.museumPieces[keyDest], 1, false, -1, 0);
                        currentLocation.museumPieces.Remove(keyDest);
                    }

                    // Place held item at the museum slot
                    currentLocation.museumPieces.Add(keyDest, (this.heldItem as StardewValley.Object).ParentSheetIndex);

                    // Place removed item at the old location of the held item to complete the swap
                    if (swapItem != null)
                    {
                        currentLocation.museumPieces.Add(keySrc, (swapItem as StardewValley.Object).ParentSheetIndex);
                    }

                    Game1.playSound("stoneStep");
                    holdingMuseumPieceRef.SetValue(false);

                    PrepareHideItemInfoTooltip();

                    Game1.playSound("newArtifact");

                    --this.heldItem.Stack;
                    if (this.heldItem.Stack <= 0)
                    {
                        this.heldItem = (Item)null;
                    }
                }
            }

            // Grab an item which is already located in the museum
            else if (this.heldItem == null && (!inventory.isWithinBounds(x, y) || !showInventory) &&
                     (okButton == null || !okButton.containsPoint(x, y)))
            {
                Vector2       key             = new Vector2((float)((x + Game1.viewport.X) / 64), (float)((y + Game1.viewport.Y) / 64));
                LibraryMuseum currentLocation = Game1.currentLocation as LibraryMuseum;
                if (currentLocation.museumPieces.ContainsKey(key))
                {
                    // save current slot of the item so it can be swapped
                    this.heldItem = (Item) new StardewValley.Object(currentLocation.museumPieces[key], 1, false, -1, 0);
                    oldX1         = (int)key.X;
                    oldY1         = (int)key.Y;

                    // Hover information
                    selectedItemDescription = this.heldItem?.getDescription();
                    selectedItemTitle       = this.heldItem?.DisplayName;

                    selectedItem = this.heldItem;

                    // Restart the info fade timer
                    lock (lockInfoFadeTimer)
                    {
                        if (infoFadeTimer != null)
                        {
                            infoFadeTimerCurrentValue = infoFadeTimerStartValue;
                            infoFadeTimer.Start();
                        }
                    }

                    currentLocation.museumPieces.Remove(key);
                    holdingMuseumPieceRef.SetValue(!currentLocation.museumAlreadyHasArtifact(this.heldItem.ParentSheetIndex));
                }
            }

            if (this.heldItem != null && heldItem == null)
            {
                this.menuMovingDown = true;
            }

            if (!showInventory || okButton == null || !okButton.containsPoint(x, y) || !readyToClose())
            {
                return;
            }

            state         = 2;
            fadeTimer     = 800;
            fadeIntoBlack = true;
            Game1.playSound("bigDeSelect");
        }