public override void draw(SpriteBatch b) { if ((fadeTimer <= 0 || !fadeIntoBlack) && state != 3) { if (heldItem != null) { for (int y = Game1.viewport.Y / 64 - 1; y < (Game1.viewport.Y + Game1.viewport.Height) / 64 + 2; ++y) { for (int x = Game1.viewport.X / 64 - 1; x < (Game1.viewport.X + Game1.viewport.Width) / 64 + 1; ++x) { var tileClassification = LibraryMuseumHelper.GetTileMuseumClassification(x, y, ModEntry.ModConfig.ShowVisualSwapIndicator); if (tileClassification != MuseumTileClassification.Invalid) { Color tileBorderColor = Color.LightGreen; if (tileClassification == MuseumTileClassification.Limited) { tileBorderColor = Color.Black; } b.Draw(Game1.mouseCursors, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)x, (float)y) * 64f), new Microsoft.Xna.Framework.Rectangle?(Game1.getSourceRectForStandardTileSheet(Game1.mouseCursors, 29, -1, -1)), tileBorderColor); } } } } heldItem?.drawInMenu(b, new Vector2((float)(Game1.getOldMouseX() + 8), (float)(Game1.getOldMouseY() + 8)), 1f); drawMouse(b); //draw clicked item information if (selectedItemDescription != null && !selectedItemDescription.Equals("")) { if (infoFadeTimerCurrentValue > 0) { // Show selected item information drawToolTip(b, this.selectedItemDescription, this.selectedItemTitle, selectedItem, selectedItem != null, -1, 0, -1, -1, (CraftingRecipe)null, -1); } else { infoFadeTimer?.Stop(); } } } b.Draw(Game1.fadeToBlackRect, new Microsoft.Xna.Framework.Rectangle(0, 0, Game1.viewport.Width, Game1.viewport.Height), Color.Black * blackFadeAlpha); }
private void MuseumDialogAnswerHandler(Farmer farmer, string whichAnswer) { switch (whichAnswer) { case DialogOption_Donate: Game1.activeClickableMenu = new MuseumMenuEx(); break; case DialogOption_Rearrange: Game1.activeClickableMenu = new MuseumMenuNoInventory(); break; case DialogOption_Collect: Game1.activeClickableMenu = new ItemGrabMenu(LibraryMuseumHelper.GetRewardsForPlayer(Game1.player), false, true, null, null, "Rewards", new ItemGrabMenu.behaviorOnItemSelect(LibraryMuseumHelper.CollectedReward), false, false, false, false, false, 0, null, -1, this); break; case DialogOption_Status: if (LibraryMuseumHelper.HasCollectedAllBooks && LibraryMuseumHelper.HasDonatedAllMuseumPieces) { Game1.drawDialogue(gunther, translationHelper.Get(Translation.GUNTHER_ARCHAEOLOGY_HOUSE_STATUS_COMPLETED)); } else { DialogHelper.DrawDialog(translationHelper.Get(Translation.GUNTHER_ARCHAEOLOGY_HOUSE_STATUS_INTRO) + DialogHelper.DIALOG_NEWLINE + translationHelper.Get(Translation.GUNTHER_ARCHAEOLOGY_HOUSE_LIBRARY_STATUS) + LibraryMuseumHelper.LibraryBooks + "/" + LibraryMuseumHelper.TotalLibraryBooks + DialogHelper.DIALOG_NEWLINE + translationHelper.Get(Translation.GUNTHER_ARCHAEOLOGY_HOUSE_MUSEUM_STATUS) + LibraryMuseumHelper.MuseumPieces + "/" + LibraryMuseumHelper.TotalMuseumPieces, gunther); } break; case DialogOption_Leave: break; } }
// 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"); }
// 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"); }
/// <summary>The method invoked when the player presses a controller, keyboard, or mouse button.</summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event data.</param> private void InputEvents_ButtonPressed(object sender, EventArgsInput e) { if (e.IsActionButton && Context.IsPlayerFree && LibraryMuseumHelper.IsPlayerAtCounter(Game1.player)) { LibraryMuseum museum = Game1.currentLocation as LibraryMuseum; bool canDonate = museum.doesFarmerHaveAnythingToDonate(Game1.player); int donatedItems = LibraryMuseumHelper.MuseumPieces; if (canDonate) { if (donatedItems > 0) { // Can donate, rearrange museum and collect rewards if (LibraryMuseumHelper.HasPlayerCollectibleRewards(Game1.player)) { ShowDialog(MuseumInteractionDialogType.DonateRearrangeCollect); } // Can donate and rearrange museum else { ShowDialog(MuseumInteractionDialogType.DonateRearrange); } } // Can donate & collect rewards & no item donated yet (cannot rearrange museum) else if (LibraryMuseumHelper.HasPlayerCollectibleRewards(Game1.player)) { ShowDialog(MuseumInteractionDialogType.DonateCollect); } // Can donate & no item donated yet (cannot rearrange) else { ShowDialog(MuseumInteractionDialogType.Donate); } } // No item to donate, donated at least one item and can potentially collect a reward else if (donatedItems > 0) { // Can rearrange and collect a reward if (LibraryMuseumHelper.HasPlayerCollectibleRewards(Game1.player)) { ShowDialog(MuseumInteractionDialogType.RearrangeCollect); } // Can rearrange and no rewards available else { ShowDialog(MuseumInteractionDialogType.Rearrange); } } else { // Show original game message. Currently in the following cases: // - When no item has been donated yet } } }
private void MuseumDialogAnswerHandler(Farmer farmer, string whichAnswer) { switch (whichAnswer) { case DialogOption_Donate: Game1.activeClickableMenu = new MuseumMenuEx(); break; case DialogOption_Rearrange: Game1.activeClickableMenu = new MuseumMenuNoInventory(); break; case DialogOption_Collect: Game1.activeClickableMenu = (IClickableMenu) new ItemGrabMenu((IList <Item>)LibraryMuseumHelper.GetRewardsForPlayer(Game1.player), false, true, (InventoryMenu.highlightThisItem)null, (ItemGrabMenu.behaviorOnItemSelect)null, "Rewards", new ItemGrabMenu.behaviorOnItemSelect(LibraryMuseumHelper.CollectedReward), false, false, false, false, false, 0, (Item)null, -1, (object)this); break; case DialogOption_Status: if (LibraryMuseumHelper.HasCollectedAllBooks && LibraryMuseumHelper.HasDonatedAllMuseumPieces) { Game1.drawDialogue(gunther, translationHelper.Get(Translation.GUNTHER_ARCHAEOLOGY_HOUSE_STATUS_COMPLETED)); } else { // Work-around to create newlines string statusIntroLinePadding = translationHelper.Get(Translation.GUNTHER_ARCHAEOLOGY_HOUSE_STATUS_INTRO_LINE_PADDING); if (statusIntroLinePadding.StartsWith("(no translation:")) { statusIntroLinePadding = ""; } string libraryStatusLinePadding = translationHelper.Get(Translation.GUNTHER_ARCHAEOLOGY_HOUSE_LIBRARY_STATUS_LINE_PADDING); if (libraryStatusLinePadding.StartsWith("(no translation:")) { libraryStatusLinePadding = ""; } Game1.drawDialogue(gunther, translationHelper.Get(Translation.GUNTHER_ARCHAEOLOGY_HOUSE_STATUS_INTRO) + statusIntroLinePadding + translationHelper.Get(Translation.GUNTHER_ARCHAEOLOGY_HOUSE_LIBRARY_STATUS) + $"{ LibraryMuseumHelper.LibraryBooks}/{LibraryMuseumHelper.TotalLibraryBooks}" + libraryStatusLinePadding + translationHelper.Get(Translation.GUNTHER_ARCHAEOLOGY_HOUSE_MUSEUM_STATUS) + $"{LibraryMuseumHelper.MuseumPieces}/{LibraryMuseumHelper.TotalMuseumPieces} "); } break; case DialogOption_Leave: break; } }