static public void DrawEquipment(StardewValley.Menus.ClickableComponent icon, Microsoft.Xna.Framework.Graphics.SpriteBatch b) { if (icon.item != null) { b.Draw(Game1.menuTexture, icon.bounds, Game1.getSourceRectForStandardTileSheet(Game1.menuTexture, 10, -1, -1), Color.White); icon.item.drawInMenu(b, new Vector2(icon.bounds.X, icon.bounds.Y), icon.scale, 1f, 0.866f, false); } else { int tile = 41; if (icon.name == "Hat") { tile = 42; } if (icon.name == "Boots") { tile = 40; } b.Draw(Game1.menuTexture, icon.bounds, Game1.getSourceRectForStandardTileSheet(Game1.menuTexture, tile, -1, -1), Color.White); } }
static public void EquipmentClick(StardewValley.Menus.ClickableComponent icon) { // Check that item type is compatible. // And play corresponding sound. var helditem = Game1.player.CursorSlotItem; if (helditem == null) { if (icon.item == null) { return; } Game1.playSound("dwop"); } else { switch (icon.name) { case "Hat": if (!(helditem is Hat)) { return; } Game1.playSound("grassyStep"); break; case "Boots": if (!(helditem is Boots)) { return; } Game1.playSound("sandyStep"); DelayedAction.playSoundAfterDelay("sandyStep", 150, null); break; default: if (!(helditem is Ring)) { return; } Game1.playSound("crit"); break; } } // I have no idea why StardewValley does this in InventoryPage::setHeldItem, but I guess it might be important. if (helditem != null) { helditem.NetFields.Parent = null; } // Update inventory ActualRings ar = actualdata.GetValue(Game1.player, FarmerNotFound); switch (icon.name) { case "Hat": Game1.player.hat.Set(helditem as Hat); break; case "Left Ring": Game1.player.leftRing.Set(helditem as Ring); break; case "Right Ring": Game1.player.rightRing.Set(helditem as Ring); break; case "Boots": Game1.player.boots.Set(helditem as Boots); break; case "Extra Ring 1": ar.ring1.Set(helditem as Ring); break; case "Extra Ring 2": ar.ring2.Set(helditem as Ring); break; case "Extra Ring 3": ar.ring3.Set(helditem as Ring); break; case "Extra Ring 4": ar.ring4.Set(helditem as Ring); break; default: mon.Log($"ERROR: Trying to fit equipment item into invalid slot '{icon.name}'", LogLevel.Error); return; } // Equip/unequip (icon.item as Ring)?.onUnequip(Game1.player, Game1.currentLocation); (icon.item as Boots)?.onUnequip(); (helditem as Ring)?.onEquip(Game1.player, Game1.currentLocation); (helditem as Boots)?.onEquip(); // Swap items Game1.player.CursorSlotItem = icon.item; icon.item = helditem; }
static public void AddEquipmentIcon(StardewValley.Menus.InventoryPage page, int x, int y, string name) { var rect = new Rectangle( page.xPositionOnScreen + 48 + x * 64, page.yPositionOnScreen + StardewValley.Menus.IClickableMenu.borderWidth + StardewValley.Menus.IClickableMenu.spaceToClearTopBorder + 256 - 12 + y * 64, 64, 64 ); // Get the item that should be in this slot. Item item = null; if (x == 0) { if (y == 0) { item = Game1.player.hat.Value; } if (y == 1) { item = Game1.player.leftRing.Value; } if (y == 2) { item = Game1.player.rightRing.Value; } if (y == 3) { item = Game1.player.boots.Value; } } else { ActualRings ar = actualdata.GetValue(Game1.player, FarmerNotFound); if (y == 0) { item = ar.ring1.Value; } if (y == 1) { item = ar.ring2.Value; } if (y == 2) { item = ar.ring3.Value; } if (y == 3) { item = ar.ring4.Value; } } // Create the GUI element. int id = 101 + 10 * x + y; var component = new StardewValley.Menus.ClickableComponent(rect, name) { myID = id, downNeighborID = y < 3 ? id + 1 : -1, upNeighborID = y == 0 ? Game1.player.MaxItems - 12 + x : id - 1, upNeighborImmutable = y == 0, rightNeighborID = x == 0 ? id + 10 : 105, leftNeighborID = x == 0 ? -1 : id - 10, item = item }; page.equipmentIcons.Add(component); }
static public void EquipmentClick(StardewValley.Menus.ClickableComponent icon) { // Check that item type is compatible. // And play corresponding sound. var helditem = Game1.player.CursorSlotItem; if (helditem == null) { if (icon.item == null) { return; } Game1.playSound("dwop"); } else { switch (icon.name) { case "Hat": if (!(helditem is Hat)) { return; } Game1.playSound("grassyStep"); break; case "Boots": if (!(helditem is Boots)) { return; } Game1.playSound("sandyStep"); DelayedAction.playSoundAfterDelay("sandyStep", 150, null); break; default: if (!(helditem is Ring)) { return; } Game1.playSound("crit"); break; } } // Equip/unequip (icon.item as Ring)?.onUnequip(Game1.player, Game1.currentLocation); (icon.item as Boots)?.onUnequip(); (helditem as Ring)?.onEquip(Game1.player, Game1.currentLocation); (helditem as Boots)?.onEquip(); // Swap items Game1.player.CursorSlotItem = icon.item; icon.item = helditem; // Update inventory ActualRings ar = actualdata.GetValue(Game1.player, FarmerNotFound); if (icon.name == "Hat") { Game1.player.hat.Set(helditem as Hat); } if (icon.name == "Left Ring") { Game1.player.leftRing.Set(helditem as Ring); } if (icon.name == "Right Ring") { Game1.player.rightRing.Set(helditem as Ring); } if (icon.name == "Boots") { Game1.player.boots.Set(helditem as Boots); } if (icon.name == "Extra Ring 1") { ar.ring1.Set(helditem as Ring); } if (icon.name == "Extra Ring 2") { ar.ring2.Set(helditem as Ring); } if (icon.name == "Extra Ring 3") { ar.ring3.Set(helditem as Ring); } if (icon.name == "Extra Ring 4") { ar.ring4.Set(helditem as Ring); } }