public void Draw(SpriteBatch b) { if (IsEmptyMenu) { return; } //b.Draw(TextureHelpers.GetSolidColorTexture(Game1.graphics.GraphicsDevice, Color.Cyan), Bounds, Color.White); // Draw the backgrounds of each slot foreach (Rectangle LockedSlot in LockedSlotBounds) { b.Draw(Game1.menuTexture, LockedSlot, new Rectangle(64, 896, 64, 64), Color.White); } foreach (Rectangle UnlockedSlot in SlotBounds) { b.Draw(Game1.menuTexture, UnlockedSlot, new Rectangle(128, 128, 64, 64), Color.White); } // Draw the items of each slot for (int i = 0; i < SlotBounds.Count; i++) { Rectangle Destination = SlotBounds[i]; // Draw a thin yellow border if mouse is hovering this slot bool IsHovered = Destination == HoveredSlot; if (IsHovered) { Color HighlightColor = Color.Yellow; Texture2D Highlight = TextureHelpers.GetSolidColorTexture(Game1.graphics.GraphicsDevice, HighlightColor); b.Draw(Highlight, Destination, Color.White * 0.25f); int BorderThickness = Destination.Width / 16; DrawHelpers.DrawBorder(b, Destination, BorderThickness, HighlightColor); } Object CurrentItem = PlaceholderItems[i]; float IconScale = IsHovered ? 1.25f : 1.0f; Color Overlay = CurrentItem.Stack == 0 ? Color.White * 0.30f : Color.White; DrawHelpers.DrawItem(b, Destination, CurrentItem, CurrentItem.Stack > 0, true, IconScale, 1.0f, Overlay, CurrentItem.Stack >= Bag.MaxStackSize ? Color.Red : Color.White); OnItemSlotRendered?.Invoke(this, new ItemSlotRenderedEventArgs(b, Destination, CurrentItem, IsHovered)); } foreach (Rectangle LockedSlot in LockedSlotBounds) { if (HoveredSlot == LockedSlot) { Color HighlightColor = Color.Yellow; Texture2D Highlight = TextureHelpers.GetSolidColorTexture(Game1.graphics.GraphicsDevice, HighlightColor); b.Draw(Highlight, LockedSlot, Color.White * 0.25f); int BorderThickness = LockedSlot.Width / 16; DrawHelpers.DrawBorder(b, LockedSlot, BorderThickness, HighlightColor); } } }
public void Draw(SpriteBatch b) { //b.Draw(TextureHelpers.GetSolidColorTexture(Game1.graphics.GraphicsDevice, Color.Cyan), Bounds, Color.White); // Draw the backgrounds of each slot for (int i = 0; i < SlotBounds.Count; i++) { if (i < Placeholders.Count) { b.Draw(Game1.menuTexture, SlotBounds[i], new Rectangle(128, 128, 64, 64), Color.White); } else if (ShowLockedSlots) { b.Draw(Game1.menuTexture, SlotBounds[i], new Rectangle(64, 896, 64, 64), Color.White); } } // Draw the items of each slot for (int i = 0; i < SlotBounds.Count; i++) { if (i < Placeholders.Count) { Rectangle Destination = SlotBounds[i]; // Draw a thin yellow border if mouse is hovering this slot bool IsHovered = Destination == HoveredSlot; if (IsHovered) { Color HighlightColor = Color.Yellow; Texture2D Highlight = TextureHelpers.GetSolidColorTexture(Game1.graphics.GraphicsDevice, HighlightColor); b.Draw(Highlight, Destination, Color.White * 0.25f); int BorderThickness = Destination.Width / 16; DrawHelpers.DrawBorder(b, Destination, BorderThickness, HighlightColor); } float IconScale = IsHovered ? 1.25f : 1.0f; if (ActualContents[i] != null) { ItemBag CurrentItem = ActualContents[i]; DrawHelpers.DrawItem(b, Destination, CurrentItem, CurrentItem.Stack > 0, true, IconScale, 1f, Color.White, CurrentItem.Stack >= Bag.MaxStackSize ? Color.Red : Color.White); } else { ItemBag CurrentItem = Placeholders[i]; DrawHelpers.DrawItem(b, Destination, CurrentItem, CurrentItem.Stack > 0, true, IconScale, 0.35f, Color.White * 0.3f, CurrentItem.Stack >= Bag.MaxStackSize ? Color.Red : Color.White); } } } }
public void Draw(SpriteBatch b) { Color HighlightColor = Color.Yellow; Texture2D Highlight = TextureHelpers.GetSolidColorTexture(Game1.graphics.GraphicsDevice, HighlightColor); DrawHelpers.DrawBox(b, Bounds); // Draw preview image b.Draw(Game1.menuTexture, PreviewDestination, new Rectangle(128, 128, 64, 64), Color.White); ItemBag CurrentBag = HoveredSprite.HasValue ? PreviewBag : Bag; DrawHelpers.DrawItem(b, PreviewDestination, CurrentBag, false, false, 1f, 1f, Color.White, Color.White); // Draw instructional text b.DrawString(InstructionFont, InstructionText, InstructionDestination, Color.Black, 0f, Vector2.Zero, InstructionScale, SpriteEffects.None, 1f); // Draw spritesheet with all icons to choose from DrawHelpers.DrawBorder(b, new Rectangle(TextureDestination.Left - 2, TextureDestination.Top - 2, TextureDestination.Width + 4, TextureDestination.Height + 4), 2, Color.Black); b.Draw(Texture, TextureDestination, new Rectangle(0, 0, TextureWidth, TextureHeight), Color.White); if (HoveredSprite.HasValue) { Rectangle Destination = HoveredSprite.Value.GetOffseted(new Point(TextureDestination.X, TextureDestination.Y)); b.Draw(Highlight, Destination, Color.White * 0.25f); int BorderThickness = Math.Max(2, HoveredSprite.Value.Width / SpriteSize); DrawHelpers.DrawBorder(b, Destination, BorderThickness, HighlightColor); } // Draw buttons b.Draw(Game1.menuTexture, DefaultButtonDestination, new Rectangle(128, 128, 64, 64), Color.White); b.DrawString(ButtonFont, DefaultButtonText, DefaultButtonTextDestination, Color.Black, 0f, Vector2.Zero, ButtonFontScale, SpriteEffects.None, 1f); b.Draw(Game1.menuTexture, CloseButtonDestination, new Rectangle(128, 128, 64, 64), Color.White); b.DrawString(ButtonFont, CloseButtonText, CloseButtonTextDestination, Color.Black, 0f, Vector2.Zero, ButtonFontScale, SpriteEffects.None, 1f); if (HoveredButton.HasValue) { Rectangle Destination = HoveredButton.Value; b.Draw(Highlight, Destination, Color.White * 0.25f); int BorderThickness = Math.Max(2, HoveredButton.Value.Width / 16); DrawHelpers.DrawBorder(b, Destination, BorderThickness, HighlightColor); } }
public override void drawTooltip(SpriteBatch spriteBatch, ref int x, ref int y, SpriteFont font, float alpha, StringBuilder overrideText) { // If viewing this bag from a Shop, draw a custom tooltip that displays icons for each item the bag is capable of storing if (Game1.activeClickableMenu is ShopMenu) { int SlotSize = 32; // May want to try 48. 64 is probably too big especially for bags that can store a large # of different items int NumItems = SizeInfo.Items.Count; int Columns = Math.Min(12, NumItems); int Rows = NumItems == 0 ? 0 : (NumItems - 1) / Columns + 1; int TitleWidth = (int)(font.MeasureString(this.DisplayName).X * 1.5) + 24; // Not sure if this is the correct scale and margin that the game's default rendering of the title bar uses int TextWidth = (int)font.MeasureString(overrideText).X + 32; // Do not change this 32, it's the additional margin that the game uses around the description text int ItemsMargin = 24; int ItemsWidth = SlotSize * Columns + ItemsMargin * 2; int RequiredWidth = Math.Max(Math.Max(TextWidth, TitleWidth), ItemsWidth); int MarginAfterDescription = 24; int RequiredHeight = (int)font.MeasureString(overrideText).Y + MarginAfterDescription + Rows * SlotSize - 8 + (int)font.MeasureString("999").Y + 32; DrawHelpers.DrawBox(spriteBatch, new Rectangle(x, y, RequiredWidth, RequiredHeight)); // Draw the description text if (overrideText != null && !string.IsNullOrEmpty(overrideText.ToString()) && overrideText.ToString() != " ") { spriteBatch.DrawString(font, overrideText, new Vector2((float)(x + 16), (float)(y + 16 + 4)) + new Vector2(2f, 2f), Game1.textShadowColor * alpha); spriteBatch.DrawString(font, overrideText, new Vector2((float)(x + 16), (float)(y + 16 + 4)) + new Vector2(0f, 2f), Game1.textShadowColor * alpha); spriteBatch.DrawString(font, overrideText, new Vector2((float)(x + 16), (float)(y + 16 + 4)) + new Vector2(2f, 0f), Game1.textShadowColor * alpha); spriteBatch.DrawString(font, overrideText, new Vector2((float)(x + 16), (float)(y + 16 + 4)), (Game1.textColor * 0.9f) * alpha); y = y + (int)font.MeasureString(overrideText).Y; } // Draw icons for each item that this bag is capable of storing y += MarginAfterDescription; int RowStartX = x + (RequiredWidth - SlotSize * Columns) / 2; int CurrentX = RowStartX; int CurrentIndex = 0; foreach (StoreableBagItem ItemInfo in SizeInfo.Items) { if (CurrentIndex == Columns) { CurrentIndex = 0; CurrentX = RowStartX; y += SlotSize; } Object Item = ItemInfo.IsBigCraftable ? new Object(Vector2.Zero, ItemInfo.Id, false) : new Object(ItemInfo.Id, 0, false, -1, 0); Rectangle Destination = new Rectangle(CurrentX, y, SlotSize, SlotSize); spriteBatch.Draw(Game1.menuTexture, Destination, new Rectangle(128, 128, 64, 64), Color.White); DrawHelpers.DrawItem(spriteBatch, Destination, Item, false, false, 1f, 1f, Color.White, Color.White); CurrentX += SlotSize; CurrentIndex++; } // Finish filling in the current row with empty slots while (CurrentIndex < Columns) { Rectangle Destination = new Rectangle(CurrentX, y, SlotSize, SlotSize); spriteBatch.Draw(Game1.menuTexture, Destination, new Rectangle(64, 896, 64, 64), Color.White); CurrentX += SlotSize; CurrentIndex++; } y += SlotSize - 8; } else { base.drawTooltip(spriteBatch, ref x, ref y, font, alpha, overrideText); } }
public void DrawToolTips(SpriteBatch b) { if (!IsJojaMember) { if (HoveredBundleItem != null) { Object HoveredItem = GetHoveredItem(); if (HoveredItem != null) { Rectangle Location; if (IsNavigatingWithGamepad) { Location = ItemSlotPositions[HoveredBundleItem].GetOffseted(TopLeftScreenPosition); } else { Location = new Rectangle(Game1.getMouseX() - 8, Game1.getMouseY() + 36, 8 + 36, 1); } DrawHelpers.DrawToolTipInfo(b, Location, HoveredItem, true, true, true, true, true, true, HoveredBundleItem.Quantity, !HoveredBundleItem.IsCompleted, Color.White); } } if (HoveredBundleTask != null) { Rectangle ToolTipAnchorPoint = TaskHeaderPositions[HoveredBundleTask].GetOffseted(TopLeftScreenPosition); int Padding = 20; int TaskImageSize = 96; int RewardIconSize = 48; int RewardWidth = RewardIconSize + 12 + RewardIconSize; // Compute header SpriteFont HeaderFont = Game1.dialogueFont; float HeaderScale = 1f; string HeaderText = !string.IsNullOrEmpty(HoveredBundleTask.TranslatedName) ? HoveredBundleTask.TranslatedName : HoveredBundleTask.Name + " Bundle"; Vector2 HeaderSize = HeaderFont.MeasureString(HeaderText) * HeaderScale; // Compute description int ReadyToComplete = 0; foreach (BundleItem BI in HoveredBundleTask.Items) { if (!BI.IsCompleted && ItemPlaceholders.TryGetValue(BI, out Object Placeholder) && Placeholder.Stack >= BI.Quantity) { ReadyToComplete++; } } SpriteFont BodyFont = Game1.smallFont; float BodyScale = 1.0f; string BodyText = HoveredBundleTask.IsCompleted ? ItemBagsMod.Translate("BundleTaskCompletedToolTip") : ItemBagsMod.Translate("BundleTaskIncompleteToolTip", new Dictionary <string, string>() { { "CompletedCount", HoveredBundleTask.Items.Count(x => x.IsCompleted).ToString() }, { "TotalCount", HoveredBundleTask.Items.Count.ToString() }, { "ReadyToCompleteCount", ReadyToComplete.ToString() }, { "RequiredCount", HoveredBundleTask.RequiredItemCount.ToString() } }); Vector2 BodySize = BodyFont.MeasureString(BodyText) * BodyScale; int ToolTipWidth = (int)new List <float>() { TaskImageSize, HeaderSize.X, BodySize.X, RewardWidth }.Max() + Padding * 2; int ToolTipHeight = Padding + TaskImageSize + 16 + (int)HeaderSize.Y + 12 + (int)BodySize.Y + 12 + RewardIconSize + Padding; // Ensure tooltip is fully visible on screen Rectangle Position = new Rectangle(ToolTipAnchorPoint.Right, ToolTipAnchorPoint.Top, ToolTipWidth, ToolTipHeight); if (Position.Right > Game1.viewport.Size.Width) { Position = new Rectangle(ToolTipAnchorPoint.Left - ToolTipWidth, Position.Top, Position.Width, Position.Height); } if (Position.Bottom > Game1.viewport.Size.Height) { Position = new Rectangle(Position.X, ToolTipAnchorPoint.Bottom - ToolTipHeight, Position.Width, Position.Height); } DrawHelpers.DrawBox(b, Position); int CurrentY = Position.Y + Padding; // Draw image associated with this task Rectangle TaskImagePosition = new Rectangle(Position.X + (Position.Width - TaskImageSize) / 2, CurrentY, TaskImageSize, TaskImageSize); DrawHelpers.DrawBorder(b, new Rectangle(TaskImagePosition.Left - 4, TaskImagePosition.Top - 4, TaskImagePosition.Width + 8, TaskImagePosition.Height + 8), 4, Color.Black); b.Draw(HoveredBundleTask.ActualLargeIconTexture, TaskImagePosition, HoveredBundleTask.ActualLargeIconPosition, Color.White); CurrentY += TaskImageSize + 16; // Draw header text (Task's name) Vector2 HeaderPosition = new Vector2(Position.X + (Position.Width - HeaderSize.X) / 2, CurrentY); b.DrawString(HeaderFont, HeaderText, HeaderPosition, Color.Black, 0f, Vector2.Zero, HeaderScale, SpriteEffects.None, 1f); CurrentY += (int)(HeaderSize.Y + 12); // Draw description text Vector2 BodyPosition = new Vector2(Position.X + (Position.Width - BodySize.X) / 2, CurrentY); b.DrawString(BodyFont, BodyText, BodyPosition, Color.SlateGray, 0f, Vector2.Zero, BodyScale, SpriteEffects.None, 1f); CurrentY += (int)(BodySize.Y + 12); // Draw reward item Rectangle RewardPosition = new Rectangle(Position.X + (Position.Width - RewardWidth) / 2, CurrentY, RewardWidth, RewardIconSize); b.Draw(TextureHelpers.JunimoNoteTexture, new Rectangle(RewardPosition.X, RewardPosition.Y, RewardIconSize, RewardIconSize), new Rectangle(548, 264, 18, 18), Color.White); if (HoveredBundleTask.Reward != null) { DrawHelpers.DrawItem(b, new Rectangle(RewardPosition.Right - RewardIconSize, RewardPosition.Y, RewardIconSize, RewardIconSize), HoveredBundleTask.Reward.ToItem(), true, true, 1f, 1f, Color.White, Color.White); } } } }
public void Draw(SpriteBatch b) { if (IsJojaMember) { Rectangle BackgroundDestination = new Rectangle(Padding, Padding, RelativeBounds.Width - Padding * 2, RelativeBounds.Height - Padding * 2).GetOffseted(TopLeftScreenPosition); b.Draw(TextureHelpers.JojaCDForm, BackgroundDestination, new Rectangle(0, 0, TextureHelpers.JojaCDForm.Width, TextureHelpers.JojaCDForm.Height - 16), Color.White); string Text = "You Traitor!"; SpriteFont Font = Game1.smallFont; Vector2 TextSize = Font.MeasureString(Text) * 2; int JojaSuxDestinationSize = 128; int BoxPadding = 32; int BoxWidth = Math.Max((int)TextSize.X, JojaSuxDestinationSize) + BoxPadding * 2; int BoxHeight = (int)TextSize.Y + BoxPadding * 2 + JojaSuxDestinationSize - JojaSuxDestinationSize / 8; Rectangle BoxDestination = new Rectangle((RelativeBounds.Width - BoxWidth) / 2, (RelativeBounds.Height - BoxHeight) / 2, BoxWidth, BoxHeight).GetOffseted(TopLeftScreenPosition); DrawHelpers.DrawBox(b, BoxDestination); Vector2 TextDestination = new Vector2(BoxDestination.X + (BoxDestination.Width - TextSize.X) / 2, BoxDestination.Y + BoxPadding); b.DrawString(Font, Text, TextDestination, Color.Black, 0f, Vector2.Zero, 2f, SpriteEffects.None, 1f); Rectangle JojaSuxSourcePosition = new Rectangle(258, 640, 32, 32); Rectangle JojaSuxDestination = new Rectangle(BoxDestination.X + (BoxDestination.Width - JojaSuxDestinationSize) / 2, BoxDestination.Bottom - BoxPadding - JojaSuxDestinationSize, JojaSuxDestinationSize, JojaSuxDestinationSize); b.Draw(Game1.mouseCursors, JojaSuxDestination, JojaSuxSourcePosition, Color.White); } else { // Draw room names foreach (KeyValuePair <BundleRoom, Rectangle> RoomHeader in RoomHeaderPositions) { bool IsCompleted = RoomHeader.Key.IsCompleted; Rectangle Position = RoomHeader.Value.GetOffseted(TopLeftScreenPosition); DrawHelpers.DrawBox(b, Position); string Text = RoomHeader.Key.DisplayName; Vector2 Size = RoomHeaderFont.MeasureString(Text) * RoomHeaderScale; b.DrawString(RoomHeaderFont, Text, new Vector2(Position.X + (Position.Width - Size.X) / 2, Position.Y + (Position.Height - Size.Y) / 2), IsCompleted ? Color.Green : Color.Black, 0f, Vector2.Zero, RoomHeaderScale, SpriteEffects.None, 1f); if (IsCompleted) { Rectangle CheckMarkDestination = new Rectangle(Position.Right - SlotSize / 6 - CheckMark.Width * CheckMarkScale, Position.Bottom - SlotSize / 6 - CheckMark.Height * CheckMarkScale, CheckMark.Width * CheckMarkScale, CheckMark.Height * CheckMarkScale); b.Draw(TextureHelpers.PlayerStatusList, CheckMarkDestination, CheckMark, Color.White); } } // Draw the backgrounds of each slot foreach (Rectangle LockedSlot in LockedSlotPositions) { b.Draw(Game1.menuTexture, LockedSlot.GetOffseted(TopLeftScreenPosition), new Rectangle(64, 896, 64, 64), Color.White); } foreach (KeyValuePair <BundleItem, Rectangle> ItemSlot in ItemSlotPositions) { Rectangle TexturePosition; if (ItemSlot.Key.IsCompleted) { TexturePosition = SlotDarkBackground; } else { Object Item = ItemPlaceholders[ItemSlot.Key]; if (Item.Stack == 0) { TexturePosition = SlotLightBackground; } else if (Item.Stack == ItemSlot.Key.Quantity) { TexturePosition = SlotDarkBackground; } else { TexturePosition = SlotMediumBackground; } } b.Draw(TextureHelpers.JunimoNoteTexture, ItemSlot.Value.GetOffseted(TopLeftScreenPosition), TexturePosition, Color.White); } foreach (KeyValuePair <BundleTask, Rectangle> TaskHeader in TaskHeaderPositions) { Rectangle TexturePosition = SlotMediumBackground; if (TaskHeader.Key.IsCompleted) { TexturePosition = SlotDarkBackground; } b.Draw(TextureHelpers.JunimoNoteTexture, TaskHeader.Value.GetOffseted(TopLeftScreenPosition), TexturePosition, Color.White); } // Draw the Task headers foreach (KeyValuePair <BundleTask, Rectangle> TaskHeader in TaskHeaderPositions) { bool IsCompleted = TaskHeader.Key.IsCompleted; // Draw a thin yellow border if mouse is hovering this slot bool IsHovered = TaskHeader.Key == HoveredBundleTask; if (IsHovered) { Rectangle Destination = TaskHeader.Value.GetOffseted(TopLeftScreenPosition); Color HighlightColor = Color.Yellow; Texture2D Highlight = TextureHelpers.GetSolidColorTexture(Game1.graphics.GraphicsDevice, HighlightColor); b.Draw(Highlight, Destination, Color.White * 0.25f); int BorderThickness = Destination.Width / 16; DrawHelpers.DrawBorder(b, Destination, BorderThickness, HighlightColor); } Rectangle Slot = TaskHeader.Value; Rectangle ScaledSlot = new Rectangle(Slot.X + Slot.Width / 6, Slot.Y + Slot.Height / 6, Slot.Width - Slot.Width / 3, Slot.Height - Slot.Height / 3); Rectangle SourceIconPosition = IsCompleted ? TaskHeader.Key.SpriteSmallIconOpenedPosition : TaskHeader.Key.SpriteSmallIconClosedPosition; b.Draw(TextureHelpers.JunimoNoteTexture, ScaledSlot.GetOffseted(TopLeftScreenPosition), SourceIconPosition, Color.White); if (IsCompleted) { Rectangle CheckMarkDestination = new Rectangle(Slot.Right - 1 - CheckMark.Width * CheckMarkScale, Slot.Bottom - 1 - CheckMark.Height * CheckMarkScale, CheckMark.Width * CheckMarkScale, CheckMark.Height * CheckMarkScale).GetOffseted(TopLeftScreenPosition); b.Draw(TextureHelpers.PlayerStatusList, CheckMarkDestination, CheckMark, Color.White); } } // Draw the items of each slot foreach (KeyValuePair <BundleItem, Rectangle> ItemSlot in ItemSlotPositions) { Rectangle Destination = ItemSlot.Value.GetOffseted(TopLeftScreenPosition); Object CurrentItem; if (!ItemPlaceholders.TryGetValue(ItemSlot.Key, out CurrentItem)) { CurrentItem = ItemSlot.Key.ToObject(); } bool IsCompleted = ItemSlot.Key.IsCompleted; // Draw a thin yellow border if mouse is hovering this slot bool IsHovered = ItemSlot.Key == HoveredBundleItem; if (IsHovered) { Color HighlightColor = Color.Yellow; Texture2D Highlight = TextureHelpers.GetSolidColorTexture(Game1.graphics.GraphicsDevice, HighlightColor); b.Draw(Highlight, Destination, Color.White * 0.25f); int BorderThickness = Destination.Width / 16; DrawHelpers.DrawBorder(b, Destination, BorderThickness, HighlightColor); } float IconScale = IsHovered ? 1.25f : 1.0f; Color Overlay = CurrentItem.Stack == 0 || IsCompleted ? Color.White * 0.30f : Color.White; bool DrawQuantity = CurrentItem.Stack > 0 && !IsCompleted && ItemSlot.Key.Quantity > 1; DrawHelpers.DrawItem(b, Destination, CurrentItem, DrawQuantity, true, IconScale, 1.0f, Overlay, CurrentItem.Stack >= ItemSlot.Key.Quantity ? Color.Green : Color.White); if (IsCompleted) { Rectangle CheckMarkDestination = new Rectangle(Destination.Right - 1 - CheckMark.Width * CheckMarkScale, Destination.Bottom - 1 - CheckMark.Height * CheckMarkScale, CheckMark.Width * CheckMarkScale, CheckMark.Height * CheckMarkScale); b.Draw(TextureHelpers.PlayerStatusList, CheckMarkDestination, CheckMark, Color.White); } } } }
public void Draw(SpriteBatch b) { //b.Draw(TextureHelpers.GetSolidColorTexture(Game1.graphics.GraphicsDevice, Color.Cyan), Bounds, Color.White); // Draw the backgrounds of each slot for (int i = 0; i < SlotBounds.Count; i++) { if (i < Rucksack.NumSlots) { b.Draw(Game1.menuTexture, SlotBounds[i], new Rectangle(128, 128, 64, 64), Color.White); } else if (ShowLockedSlots) { b.Draw(Game1.menuTexture, SlotBounds[i], new Rectangle(64, 896, 64, 64), Color.White); } } // Draw the items of each slot for (int i = 0; i < SlotBounds.Count; i++) { Rectangle Destination = SlotBounds[i]; if (i < PlaceholderItems.Count) { Object CurrentItem = PlaceholderItems[i]; // Apply some visual feedback if the bag has a large grid of items: // If this item was recently added to the bag or had its quantity changed, Draw a thin green border around it for a couple seconds if (Rucksack.NumSlots >= 24 && TempVisualFeedback.TryGetValue(CurrentItem, out DateTime ModifiedTime)) { TimeSpan TotalDuration = TimeSpan.FromSeconds(2.0); TimeSpan Elapsed = DateTime.Now.Subtract(ModifiedTime); if (Elapsed < TotalDuration) { TimeSpan RemainingDuration = TotalDuration.Subtract(Elapsed); float Transparency = Math.Min(1.0f, (float)(RemainingDuration.TotalSeconds / 1.0)); Color HighlightColor = Color.DarkGreen * Transparency; Texture2D Highlight = TextureHelpers.GetSolidColorTexture(Game1.graphics.GraphicsDevice, HighlightColor); b.Draw(Highlight, Destination, Color.White * 0.40f); int BorderThickness = Math.Max(Destination.Width / 8, 6); DrawHelpers.DrawBorder(b, Destination, BorderThickness, HighlightColor); } } // Draw a thin yellow border if mouse is hovering this slot bool IsHovered = Destination == HoveredSlot; if (IsHovered) { Color HighlightColor = Color.Yellow; Texture2D Highlight = TextureHelpers.GetSolidColorTexture(Game1.graphics.GraphicsDevice, HighlightColor); b.Draw(Highlight, Destination, Color.White * 0.25f); int BorderThickness = Destination.Width / 16; DrawHelpers.DrawBorder(b, Destination, BorderThickness, HighlightColor); } float IconScale = IsHovered ? 1.25f : 1.0f; Color Overlay = CurrentItem.Stack == 0 ? Color.White * 0.30f : Color.White; DrawHelpers.DrawItem(b, Destination, CurrentItem, CurrentItem.Stack > 0, true, IconScale, 1.0f, Overlay, CurrentItem.Stack >= Bag.MaxStackSize ? Color.Red : Color.White); } else if (Destination == HoveredSlot) { Color HighlightColor = Color.Yellow; Texture2D Highlight = TextureHelpers.GetSolidColorTexture(Game1.graphics.GraphicsDevice, HighlightColor); b.Draw(Highlight, Destination, Color.White * 0.25f); int BorderThickness = Destination.Width / 16; DrawHelpers.DrawBorder(b, Destination, BorderThickness, HighlightColor); } } // Draw the sidebar buttons if (IsRightSidebarVisible) { // Draw Sort Property icons b.Draw(Game1.menuTexture, SortingPropertyBounds, new Rectangle(128, 128, 64, 64), Color.White); if (Rucksack.SortProperty == SortingProperty.Time) { // Clock icon Texture2D SourceTexture = Game1.mouseCursors; Rectangle SourceRect = new Rectangle(410, 501, 9, 9); int IconSize = (int)(SourceRect.Width * 2.0 / 32.0 * SortingPropertyBounds.Width); b.Draw(Game1.mouseCursors, new Rectangle(SortingPropertyBounds.X + (SortingPropertyBounds.Width - IconSize) / 2, SortingPropertyBounds.Y + (SortingPropertyBounds.Height - IconSize) / 2, IconSize, IconSize), SourceRect, Color.White); } else if (Rucksack.SortProperty == SortingProperty.Name) { // Alphabetical letter icon Texture2D SourceTexture = Game1.mouseCursors; Rectangle SourceRect = new Rectangle(279, 25, 9, 9); int IconSize = (int)(SourceRect.Width * 2.0 / 32.0 * SortingPropertyBounds.Width); b.Draw(Game1.mouseCursors, new Rectangle(SortingPropertyBounds.X + (SortingPropertyBounds.Width - IconSize) / 2, SortingPropertyBounds.Y + (SortingPropertyBounds.Height - IconSize) / 2, IconSize, IconSize), SourceRect, Color.White); } else if (Rucksack.SortProperty == SortingProperty.Id) { // Open book icon Texture2D SourceTexture = Game1.mouseCursors; Rectangle SourceRect = new Rectangle(146, 447, 11, 10); int IconSize = (int)(SourceRect.Width * 1.5 / 32.0 * SortingPropertyBounds.Width); b.Draw(Game1.mouseCursors, new Rectangle(SortingPropertyBounds.X + (SortingPropertyBounds.Width - IconSize) / 2, SortingPropertyBounds.Y + (SortingPropertyBounds.Height - IconSize) / 2, IconSize, IconSize), SourceRect, Color.White); } else if (Rucksack.SortProperty == SortingProperty.Category) { // Magnifying glass icon Texture2D SourceTexture = Game1.mouseCursors; Rectangle SourceRect = new Rectangle(80, 0, 13, 13); int IconSize = (int)(SourceRect.Width * 1.5 / 32.0 * SortingPropertyBounds.Width); b.Draw(Game1.mouseCursors, new Rectangle(SortingPropertyBounds.X + (SortingPropertyBounds.Width - IconSize) / 2, SortingPropertyBounds.Y + (SortingPropertyBounds.Height - IconSize) / 2, IconSize, IconSize), SourceRect, Color.White); } else if (Rucksack.SortProperty == SortingProperty.Quantity) { // Large # '9' icon Texture2D SourceTexture = Game1.mouseCursors; Rectangle SourceRect = new Rectangle(537, 136, 7, 8); int IconSize = (int)(SourceRect.Width * 2.5 / 32.0 * SortingPropertyBounds.Width); b.Draw(Game1.mouseCursors, new Rectangle(SortingPropertyBounds.X + (SortingPropertyBounds.Width - IconSize) / 2, SortingPropertyBounds.Y + (SortingPropertyBounds.Height - IconSize) / 2, IconSize, IconSize), SourceRect, Color.White); } else if (Rucksack.SortProperty == SortingProperty.SingleValue) { // 'G' with golden background icon Texture2D SourceTexture = Game1.mouseCursors; Rectangle SourceRect = new Rectangle(408, 476, 9, 11); int IconSize = (int)(SourceRect.Width * 2.0 / 32.0 * SortingPropertyBounds.Width); b.Draw(Game1.mouseCursors, new Rectangle(SortingPropertyBounds.X + (SortingPropertyBounds.Width - IconSize) / 2, SortingPropertyBounds.Y + (SortingPropertyBounds.Height - IconSize) / 2, IconSize, IconSize), SourceRect, Color.White); } else if (Rucksack.SortProperty == SortingProperty.StackValue) { // Big bag of gold icon Texture2D SourceTexture = Game1.mouseCursors; Rectangle SourceRect = new Rectangle(397, 1941, 19, 20); int IconSize = (int)(SourceRect.Width * 1.0 / 32.0 * SortingPropertyBounds.Width); b.Draw(Game1.mouseCursors, new Rectangle(SortingPropertyBounds.X + (SortingPropertyBounds.Width - IconSize) / 2, SortingPropertyBounds.Y + (SortingPropertyBounds.Height - IconSize) / 2, IconSize, IconSize), SourceRect, Color.White); } else if (Rucksack.SortProperty == SortingProperty.Similarity) { // Star icon Texture2D SourceTexture = Game1.mouseCursors; Rectangle SourceRect = new Rectangle(310, 392, 16, 16); int IconSize = (int)(SourceRect.Width * 1.0 / 32.0 * SortingPropertyBounds.Width); b.Draw(Game1.mouseCursors, new Rectangle(SortingPropertyBounds.X + (SortingPropertyBounds.Width - IconSize) / 2, SortingPropertyBounds.Y + (SortingPropertyBounds.Height - IconSize) / 2, IconSize, IconSize), SourceRect, Color.White); } // Draw Sort Order icons b.Draw(Game1.menuTexture, SortingOrderBounds, new Rectangle(128, 128, 64, 64), Color.White); if (Rucksack.SortOrder == SortingOrder.Ascending) { Rectangle ArrowUpIconSourceRect = new Rectangle(421, 459, 12, 12); int ArrowSize = (int)(ArrowUpIconSourceRect.Width * 1.5 / 32.0 * SortingOrderBounds.Width); b.Draw(Game1.mouseCursors, new Rectangle(SortingOrderBounds.X + (SortingOrderBounds.Width - ArrowSize) / 2, SortingOrderBounds.Y + (SortingOrderBounds.Height - ArrowSize) / 2, ArrowSize, ArrowSize), ArrowUpIconSourceRect, Color.White); } else if (Rucksack.SortOrder == SortingOrder.Descending) { Rectangle ArrowDownIconSourceRect = new Rectangle(421, 472, 12, 12); int ArrowSize = (int)(ArrowDownIconSourceRect.Width * 1.5 / 32.0 * SortingOrderBounds.Width); b.Draw(Game1.mouseCursors, new Rectangle(SortingOrderBounds.X + (SortingOrderBounds.Width - ArrowSize) / 2, SortingOrderBounds.Y + (SortingOrderBounds.Height - ArrowSize) / 2, ArrowSize, ArrowSize), ArrowDownIconSourceRect, Color.White); } // Draw a yellow border around the hovered sidebar button if (HoveredContentsButton.HasValue) { Rectangle HoveredBounds = HoveredContentsButtonBounds.Value; Color HighlightColor = Color.Yellow; Texture2D Highlight = TextureHelpers.GetSolidColorTexture(Game1.graphics.GraphicsDevice, HighlightColor); b.Draw(Highlight, HoveredBounds, Color.White * 0.25f); int BorderThickness = HoveredBounds.Width / 16; DrawHelpers.DrawBorder(b, HoveredBounds, BorderThickness, HighlightColor); } } }
public void Draw(SpriteBatch b) { if (IsEmptyMenu) { return; } //b.Draw(TextureHelpers.GetSolidColorTexture(Game1.graphics.GraphicsDevice, Color.Orange), Bounds, Color.White); // Draw column headers for (int i = 0; i < ColumnHeaderBounds.Count; i++) { Rectangle Destination = ColumnHeaderBounds[i]; b.Draw(Game1.menuTexture, Destination, new Rectangle(64, 896, 64, 64), Color.White); Rectangle IconDestination = new Rectangle(Destination.X + Destination.Width / 4, Destination.Y + Destination.Height / 4, Destination.Width / 2, Destination.Height / 2); ColumnType Type = (ColumnType)(i % ColumnsPerGroup); if (Type == ColumnType.RowValue) { //Could also use Game1.mouseCursors with SourceSprite = new Rectangle(280, 411, 16, 16); b.Draw(GoldIconTexture, IconDestination, GoldIconSourceRect, Color.White); } else { Rectangle SourceRect = ItemBag.QualityIconTexturePositions[ConvertColumnTypeToObjectQuality(Type)]; b.Draw(Game1.mouseCursors, IconDestination, SourceRect, Color.White); } } // Draw cells foreach (var KVP in SlotBounds) { int ItemId = KVP.Key; foreach (var KVP2 in KVP.Value) { ColumnType ColumnType = KVP2.Key; Rectangle Destination = KVP2.Value; b.Draw(Game1.menuTexture, Destination, new Rectangle(128, 128, 64, 64), Color.White); // Draw a thin yellow border if mouse is hovering this slot bool IsHovered = Destination == HoveredSlot; if (IsHovered) { Color HighlightColor = Color.Yellow; Texture2D Highlight = TextureHelpers.GetSolidColorTexture(Game1.graphics.GraphicsDevice, HighlightColor); b.Draw(Highlight, Destination, Color.White * 0.25f); int BorderThickness = Destination.Width / 16; DrawHelpers.DrawBorder(b, Destination, BorderThickness, HighlightColor); } if (ColumnType != ColumnType.RowValue) { ObjectQuality Quality = ConvertColumnTypeToObjectQuality(ColumnType); Object CurrentItem = Placeholders[ItemId][Quality]; float IconScale = IsHovered ? 1.25f : 1.0f; Color Overlay = CurrentItem.Stack == 0 ? Color.White * 0.30f : Color.White; DrawHelpers.DrawItem(b, Destination, CurrentItem, CurrentItem.Stack > 0, true, IconScale, 1.0f, Overlay, CurrentItem.Stack >= Bag.MaxStackSize ? Color.Red : Color.White); OnItemSlotRendered?.Invoke(this, new ItemSlotRenderedEventArgs(b, Destination, CurrentItem, IsHovered)); } else { // Sum up the value of all different qualities of this item int SummedValue = Placeholders[ItemId].Values.Sum(x => x.Stack * ItemBag.GetSingleItemPrice(x)); int NumDigits = DrawHelpers.GetNumDigits(SummedValue); // Compute width/height of the number float ValueScale; int ValueWidth, ValueHeight, CurrentIteration = 0; do { ValueScale = (2.7f - CurrentIteration * 0.1f) * Destination.Width / (float)BagInventoryMenu.DefaultInventoryIconSize; ValueWidth = (int)DrawHelpers.MeasureNumber(SummedValue, ValueScale); ValueHeight = (int)(DrawHelpers.TinyDigitBaseHeight * ValueScale); CurrentIteration++; } while (ValueWidth > Destination.Width * 1.04); // * 1.04 to let the value extend very slightly outside the bounds of the slot // Draw the number in the center of the slot Vector2 TopLeftPosition = new Vector2(Destination.X + (Destination.Width - ValueWidth) / 2 + 1, Destination.Y + (Destination.Height - ValueHeight) / 2); Color ValueColor = GetValueColor(SummedValue); Utility.drawTinyDigits(SummedValue, b, TopLeftPosition, ValueScale, 0f, ValueColor); } } } }