Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions MapHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Microsoft.Xna.Framework;
using System.Linq;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.DataStructures;
using Terraria.GameContent;
Expand All @@ -20,8 +20,25 @@ public override void Draw(ref MapOverlayDrawContext context, ref string text) {
continue; // do not draw items that are inacive or not whitelisted

Main.instance.LoadItem(item.type); // Items SHOULD already be loaded, but in case it isn't have a backup

SpriteFrame spriteFrame = new SpriteFrame(1, 1, 0, 0);
Texture2D itemTexture = TextureAssets.Item[item.type].Value;

// Support for item animations.
if (ItemID.Sets.AnimatesAsSoul[item.type]) {
Rectangle itemFrame = Main.itemAnimations[item.type].GetFrame(itemTexture);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these should just be Rectangle itemFrame = Main.itemAnimations[item.type]?.GetFrame(itemTexture) ?? itemTexture.Frame();. An item with an animation doesn't necessarily set ItemID.Sets.AnimatesAsSoul

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, this is the proper solution. I was convinced ItemID.Sets.AnimatesAsSoul was needed for the item animation. I see Terraria gets the frame the same way like you suggested. I'll make an update.


byte columns = (byte)(itemTexture.Width / itemFrame.Width);
byte rows = (byte)(itemTexture.Height / itemFrame.Height);

if (context.Draw(TextureAssets.Item[item.type].Value, item.VisualPosition / 16, Color.White, new SpriteFrame(1, 1, 0, 0), 1f, 1.2f, Alignment.Center).IsMouseOver)
spriteFrame = new SpriteFrame(
columns,
rows,
(byte)(itemFrame.X / (itemTexture.Width / columns)),
(byte)(itemFrame.Y / (itemTexture.Height / rows)));
}

if (context.Draw(itemTexture, item.VisualPosition / 16, Color.White, spriteFrame, 1f, 1.2f, Alignment.Center).IsMouseOver)
text = item.HoverName; // Display the item's hover name when hovering over the icon
}
}
Expand Down