XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

DeathMod

【Terraria】DeathMod (now aka Soul Harvest)

公开
关注 0 Fork 0 Star 0
UTF-8
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 AltarEquipmentTreeDetailPanel : UIElement
{
    private readonly ReaperTreeButton upgradeButton;
    private AltarEquipmentTreeNode? node;
    private float layoutScale = 1f;

    public AltarEquipmentTreeDetailPanel(AltarEquipmentProgressionPanel owner)
    {
        SetPadding(0f);
        upgradeButton = new ReaperTreeButton(owner.RequestSelectedUpgrade, new Color(87, 25, 29), new Color(137, 32, 36), new Color(231, 69, 70));
        Append(upgradeButton);
    }

    public void ApplyLayoutScale(float scale)
    {
        layoutScale = scale;
        upgradeButton.Left.Set(12f * scale, 0f);
        upgradeButton.Top.Set(-50f * scale, 1f);
        upgradeButton.Width.Set(-24f * scale, 1f);
        upgradeButton.Height.Set(38f * scale, 0f);
        upgradeButton.ApplyLayoutScale(scale, 0.68f);
    }

    public void SetNode(AltarEquipmentTreeNode? selected) => node = selected;

    public void RefreshActionState()
    {
        upgradeButton.Enabled = node is { CanRequest: true, Affordable: true };
        string key = node is null || node.IsRoot
            ? "SelectNodeButton"
            : node.Completed
                ? "CompleteButton"
                : !node.CanRequest || !node.Affordable ? "LockedButton" : "UpgradeButton";
        upgradeButton.SetText(Language.GetTextValue($"Mods.SoulHarvest.UI.ReaperTree.{key}"));
    }

    protected override void DrawSelf(SpriteBatch spriteBatch)
    {
        Rectangle bounds = GetDimensions().ToRectangle();
        Texture2D pixel = TextureAssets.MagicPixel.Value;
        spriteBatch.Draw(pixel, bounds, new Color(13, 12, 15) * 0.995f);
        ReaperTreeDraw.DrawBorder(spriteBatch, pixel, bounds, new Color(76, 61, 60), Math.Max(1, (int)(2f * layoutScale)));
        ReaperTreeDraw.DrawInsetBorder(spriteBatch, pixel, bounds, Math.Max(3, (int)(6f * layoutScale)), new Color(128, 41, 48) * 0.68f, 1);
        if (node is null)
            return;
        float categoryScale = 0.51f * layoutScale;
        Utils.DrawBorderString(spriteBatch, AltarDrawHelpers.FitText(node.Category, bounds.Width - 28f * layoutScale, categoryScale), new Vector2(bounds.X + 14f * layoutScale, bounds.Y + 14f * layoutScale), new Color(198, 103, 106), categoryScale);
        float titleScale = 0.69f * layoutScale;
        string title = AltarDrawHelpers.FitText(node.Title, bounds.Width - 30f * layoutScale, titleScale);
        Utils.DrawBorderString(spriteBatch, title, new Vector2(bounds.X + 15f * layoutScale, bounds.Y + 50f * layoutScale), new Color(239, 226, 209), titleScale);
        int dividerY = bounds.Y + (int)(91f * layoutScale);
        spriteBatch.Draw(pixel, new Rectangle(bounds.X + (int)(14f * layoutScale), dividerY, bounds.Width - (int)(28f * layoutScale), Math.Max(1, (int)layoutScale)), new Color(106, 87, 81) * 0.52f);
        float textLeft = bounds.X + 15f * layoutScale;
        float textWidth = bounds.Width - 30f * layoutScale;
        ReaperTreeDraw.DrawWrappedText(spriteBatch, node.Description, new Vector2(textLeft, bounds.Y + 108f * layoutScale), textWidth, 0.55f * layoutScale, new Color(188, 178, 168), 10);
        int statusTop = Math.Max((int)(bounds.Y + 265f * layoutScale), (int)(bounds.Bottom - 151f * layoutScale));
        spriteBatch.Draw(pixel, new Rectangle(bounds.X + (int)(14f * layoutScale), statusTop, bounds.Width - (int)(28f * layoutScale), Math.Max(1, (int)layoutScale)), new Color(106, 87, 81) * 0.52f);
        ReaperTreeDraw.DrawWrappedText(spriteBatch, node.Status, new Vector2(textLeft, statusTop + 14f * layoutScale), textWidth, 0.56f * layoutScale, node.CanRequest && node.Affordable ? new Color(225, 91, 98) : new Color(211, 174, 164), 2);
        if (!string.IsNullOrWhiteSpace(node.Cost))
            ReaperTreeDraw.DrawWrappedText(spriteBatch, node.Cost, new Vector2(textLeft, statusTop + 49f * layoutScale), textWidth, 0.51f * layoutScale, new Color(165, 151, 142), 3);
    }
}