using SoulHarvest.Common; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; using System.Collections.Generic; using Terraria; using Terraria.Audio; using Terraria.GameContent; using Terraria.ID; using Terraria.Localization; using Terraria.ModLoader; using Terraria.UI; namespace SoulHarvest.UI; internal sealed class AltarEquipmentTreeNode { public DeathAltarUpgradeType? UpgradeType { get; } public Vector2 Position { get; } public float Radius { get; } public bool IsRoot => UpgradeType is null; public bool Completed { get; private set; } public bool CanRequest { get; private set; } public bool Affordable { get; private set; } public bool Lit => IsRoot || Completed || CanRequest && Affordable; public string Title { get; private set; } = string.Empty; public string Category { get; private set; } = string.Empty; public string Description { get; private set; } = string.Empty; public string Status { get; private set; } = string.Empty; public string Cost { get; private set; } = string.Empty; private AltarEquipmentTreeNode(DeathAltarUpgradeType? type, Vector2 position, float radius) { UpgradeType = type; Position = position; Radius = radius; } public static AltarEquipmentTreeNode Root(Vector2 position) => new(null, position, 48f); public static AltarEquipmentTreeNode Upgrade(DeathAltarUpgradeType type, Vector2 position, bool convergence) { return new AltarEquipmentTreeNode(type, position, convergence ? 40f : 32f); } public void Refresh(string itemName, IDeathAltarUpgradeable upgradeable, int essenceCount, int souls) { if (IsRoot) { Completed = true; CanRequest = false; Affordable = true; Title = itemName; Category = Text("RootCategory"); Description = Text("RootDescription"); Status = Text("RootStatus"); Cost = string.Empty; return; } DeathAltarUpgradeType type = UpgradeType!.Value; DeathAltarPrice price = upgradeable.GetUpgradePrice(type); DeathAltarUnavailableReason unavailableReason = upgradeable.GetUnavailableReason(type); Completed = !price.IsAvailable && unavailableReason == DeathAltarUnavailableReason.Maxed; CanRequest = price.IsAvailable; Affordable = price.Currency switch { DeathAltarCurrency.Souls => souls >= price.Amount, DeathAltarCurrency.SoulEssence => essenceCount >= price.Amount, _ => true }; Title = Language.GetTextValue($"Mods.SoulHarvest.UI.UpgradeNames.{type}"); Category = Text("NodeCategory"); if (price.IsAvailable) { string current = upgradeable.GetCurrentUpgradeValue(type); string next = upgradeable.GetNextUpgradeValue(type); Description = Text("ValueTransition", current, next); Status = Affordable ? Text("StatusReady") : Text("StatusInsufficient"); Cost = DeathAltarUIState.FormatPrice(price); } else { Description = Language.GetTextValue($"Mods.SoulHarvest.UI.UnavailableReasons.{unavailableReason}"); Status = Completed ? Text("StatusComplete") : Text("StatusLocked"); Cost = string.Empty; } } private static string Text(string key, params object[] args) { return Language.GetTextValue($"Mods.SoulHarvest.UI.EquipmentTree.{key}", args); } }