diff --git a/Items/Accessories/Vanity/PunchCard.cs b/Items/Accessories/Vanity/PunchCard.cs index e591edd352..4fef249a0e 100644 --- a/Items/Accessories/Vanity/PunchCard.cs +++ b/Items/Accessories/Vanity/PunchCard.cs @@ -1,4 +1,5 @@ -using Terraria; +using CalamityMod.UI; +using Terraria; using Terraria.ID; using Terraria.ModLoader; @@ -42,6 +43,15 @@ namespace CalamityMod.Items.Accessories.Vanity Item.rare = ItemRarityID.Purple; Item.vanity = true; Item.Calamity().devItem = true; + Item.useAnimation = Item.useTime = 20; + Item.useStyle = ItemUseStyleID.HoldUp; + } + + public override bool? UseItem(Player player) + { + if (Main.myPlayer == player.whoAmI) + PopupGUIManager.FlipActivityOfGUIWithType(typeof(PunchCardGUI)); + return true; } public override void UpdateVanity(Player player) diff --git a/UI/MiscTextures/PunchCardPopup.png b/UI/MiscTextures/PunchCardPopup.png new file mode 100644 index 0000000000..f293a646f9 Binary files /dev/null and b/UI/MiscTextures/PunchCardPopup.png differ diff --git a/UI/PunchCardGUI.cs b/UI/PunchCardGUI.cs new file mode 100644 index 0000000000..3dbe2fac1a --- /dev/null +++ b/UI/PunchCardGUI.cs @@ -0,0 +1,59 @@ +using System.Collections.Generic; +using System.Linq; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.GameContent; +using Terraria.ModLoader; + +namespace CalamityMod.UI +{ + public class PunchCardGUI : PopupGUI + { + public bool HoveringOverBook = false; + + public override void Update() + { + if (Active) + { + if (FadeTime < FadeTimeMax) + FadeTime++; + } + else if (FadeTime > 0) + { + FadeTime--; + } + + if (Main.mouseLeft && !HoveringOverBook && FadeTime >= 30) + { + Active = false; + } + + HoveringOverBook = false; + } + + public override void Draw(SpriteBatch spriteBatch) + { + Texture2D pageTexture = ModContent.Request("CalamityMod/UI/MiscTextures/PunchCardPopup").Value; + float xScale = MathHelper.Lerp(0.004f, 1f, FadeTime / (float)FadeTimeMax); + Vector2 scale = new Vector2(xScale, 1f) * new Vector2(Main.screenWidth, Main.screenHeight) / pageTexture.Size(); + scale.Y *= 1.5f; + scale *= 0.5f; + + float bookScale = 0.5f; + scale *= bookScale; + + float yPageTop = MathHelper.Lerp(Main.screenHeight * 2, Main.screenHeight * 0.5f, FadeTime / (float)FadeTimeMax); + + Rectangle mouseRectangle = new Rectangle((int)Main.MouseScreen.X, (int)Main.MouseScreen.Y, 2, 2); + float drawPositionX = Main.screenWidth * 0.5f; + Vector2 drawPosition = new Vector2(drawPositionX, yPageTop); + Rectangle pageRectangle = new Rectangle((int)drawPosition.X - (int)(pageTexture.Width * 0.5f * scale.X), (int)drawPosition.Y - (int)(pageTexture.Height * 0.5f * scale.Y), (int)(pageTexture.Width * scale.X), (int)(pageTexture.Height * scale.Y)); + + spriteBatch.Draw(pageTexture, drawPosition, null, Color.White, 0f, pageTexture.Size() / 2, scale, SpriteEffects.None, 0f); + + if (!HoveringOverBook) + HoveringOverBook = mouseRectangle.Intersects(pageRectangle); + } + } +}