using SoulHarvest.Common; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using ReLogic.Content; using System; using System.Collections.Generic; using Terraria; using Terraria.GameContent; using Terraria.Localization; using Terraria.ModLoader; using Terraria.UI; namespace SoulHarvest.UI; internal class SoulIconElement : UIElement { private readonly Asset texture = ModContent.Request("SoulHarvest/UI/SoulIcon"); public override void Update(GameTime gameTime) { base.Update(gameTime); // Keep the soul icon below the minimap and its vertical zoom controls. UI coordinates are // scaled, so clamp against the usable UI height for smaller resolutions as well. float uiHeight = Main.screenHeight / Main.UIScale; float targetTop = Main.mapStyle == 1 && !Main.mapFullscreen ? 430f : 170f; targetTop = MathHelper.Clamp(targetTop, 120f, Math.Max(120f, uiHeight - 112f)); if (Math.Abs(Top.Pixels - targetTop) > 0.5f) { Top.Set(targetTop, 0f); Recalculate(); } if (ContainsPoint(Main.MouseScreen)) Main.LocalPlayer.mouseInterface = true; } public override void RightClick(UIMouseEvent evt) { base.RightClick(evt); SoulIconUISystem.RequestEssenceExtraction(); } public override void LeftClick(UIMouseEvent evt) { base.LeftClick(evt); SoulIconUISystem.RequestEssenceAbsorption(); } protected override void DrawSelf(SpriteBatch spriteBatch) { base.DrawSelf(spriteBatch); CalculatedStyle dimensions = GetDimensions(); Vector2 center = new(dimensions.X + dimensions.Width / 2f, dimensions.Y + 41f); float pulse = 1f + (float)Math.Sin(Main.GlobalTimeWrappedHourly * 3.2f) * 0.035f; float scale = 76f / texture.Value.Height * pulse; Vector2 origin = texture.Value.Size() / 2f; Color aura = new Color(70, 125, 255, 0) * 0.22f; for (int direction = 0; direction < 4; direction++) { Vector2 offset = (MathHelper.PiOver2 * direction + Main.GlobalTimeWrappedHourly).ToRotationVector2() * 2.5f; spriteBatch.Draw(texture.Value, center + offset, null, aura, 0f, origin, scale, SpriteEffects.None, 0f); } spriteBatch.Draw(texture.Value, center, null, Color.White, 0f, origin, scale, SpriteEffects.None, 0f); for (int index = 0; index < 3; index++) { float angle = Main.GlobalTimeWrappedHourly * (1.3f + index * 0.2f) + index * MathHelper.TwoPi / 3f; Vector2 wisp = center + angle.ToRotationVector2() * (29f + index * 3f); Color color = index % 2 == 0 ? new Color(80, 235, 255) : new Color(195, 90, 255); spriteBatch.Draw(TextureAssets.MagicPixel.Value, new Rectangle((int)wisp.X, (int)wisp.Y, 3, 3), color * 0.85f); } int souls = Main.LocalPlayer.GetModPlayer().Souls; string countText = Language.GetTextValue("Mods.SoulHarvest.UI.SoulCount", souls); Vector2 textSize = FontAssets.MouseText.Value.MeasureString(countText) * 0.8f; Utils.DrawBorderString(spriteBatch, countText, new Vector2(center.X - textSize.X / 2f, dimensions.Y + 82f), new Color(120, 235, 255), 0.8f); if (IsMouseHovering) Main.instance.MouseText(Language.GetTextValue("Mods.SoulHarvest.UI.SoulIconHint", MyPlayer.SoulsPerEssence)); } }