using SoulHarvest.Common; using SoulHarvest.Items; using SoulHarvest.Tiles; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using System; using System.Collections.Generic; using Terraria; using Terraria.Audio; using Terraria.GameContent; using Terraria.GameContent.UI.Elements; using Terraria.ID; using Terraria.Localization; using Terraria.ModLoader; using Terraria.UI; namespace SoulHarvest.UI; internal sealed class AltarItemSelector : UIElement { private readonly DeathAltarUIState owner; private readonly AltarEquipmentEntry entry; private readonly Item item; private readonly bool selected; private readonly float layoutScale; public AltarItemSelector(DeathAltarUIState owner, AltarEquipmentEntry entry, Item item, bool selected, float layoutScale) { this.owner = owner; this.entry = entry; this.item = item.Clone(); this.selected = selected; this.layoutScale = layoutScale; Width.Set(0f, 1f); Height.Set(58f * layoutScale, 0f); } protected override void DrawSelf(SpriteBatch spriteBatch) { Rectangle bounds = GetDimensions().ToRectangle(); Texture2D pixel = TextureAssets.MagicPixel.Value; Color accent = entry.IsCharacterSickle ? new Color(194, 48, 61) : entry.IsCharacterDeathDomain ? new Color(90, 185, 205) : new Color(153, 64, 70); Color background = selected ? new Color(65, 30, 34) : IsMouseHovering ? new Color(43, 31, 34) : new Color(23, 21, 24); Color border = selected ? accent : new Color(77, 55, 58); spriteBatch.Draw(pixel, bounds, background * 0.95f); int borderThickness = Math.Max(1, (int)MathF.Round((selected ? 2f : 1f) * layoutScale)); AltarDrawHelpers.DrawBorder(spriteBatch, pixel, bounds, border, borderThickness); if (selected) spriteBatch.Draw(pixel, new Rectangle(bounds.X, bounds.Y + borderThickness, Math.Max(2, (int)MathF.Round(4f * layoutScale)), bounds.Height - borderThickness * 2), accent); Vector2 iconCenter = new(bounds.X + 28f * layoutScale, bounds.Center.Y); AltarDrawHelpers.DrawItemSlot(spriteBatch, pixel, iconCenter, 42f * layoutScale, new Color(31, 25, 28), selected ? accent : new Color(76, 55, 58)); if (entry.IsCharacterDeathDomain) { int iconSize = Math.Max(1, (int)MathF.Round(32f * layoutScale)); DeathDomainBackdropTextureSystem.DrawUiIcon( spriteBatch, new Rectangle( (int)MathF.Round(iconCenter.X - iconSize * 0.5f), (int)MathF.Round(iconCenter.Y - iconSize * 0.5f), iconSize, iconSize), Main.MouseScreen); } else { AltarDrawHelpers.DrawItemIcon(spriteBatch, item, iconCenter, 34f * layoutScale); } string location = entry.IsCharacterProgression ? Language.GetTextValue("Mods.SoulHarvest.UI.CharacterBoundLocation") : Language.GetTextValue(entry.ItemReference?.Storage == DeathAltarItemStorage.Inventory ? "Mods.SoulHarvest.UI.InventoryLocation" : "Mods.SoulHarvest.UI.EquipmentLocation"); float nameScale = 0.74f * layoutScale; string visibleName = AltarDrawHelpers.FitText(item.Name, Math.Max(20f, bounds.Width - 62f * layoutScale), nameScale); Utils.DrawBorderString(spriteBatch, visibleName, new Vector2(bounds.X + 55f * layoutScale, bounds.Y + 8f * layoutScale), Color.White, nameScale); Utils.DrawBorderString(spriteBatch, location, new Vector2(bounds.X + 55f * layoutScale, bounds.Y + 32f * layoutScale), selected ? new Color(226, 128, 134) : new Color(164, 139, 140), 0.6f * layoutScale); if (IsMouseHovering && visibleName != item.Name) Main.instance.MouseText($"{item.Name}\n{location}"); } public override void LeftClick(UIMouseEvent evt) { base.LeftClick(evt); owner.SelectEquipment(entry); } }