Files
GladiatorIdle/Mono/Arena/HubScene.Skills.cs

97 lines
5.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Linq;
using GladiatorIdle.Gfx;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using D = GladiatorIdle.Gfx.Draw;
namespace GladiatorIdle.Arena
{
/// Fähigkeitenbaum: drei Zweige (Angriff, Verteidigung, Kampfstil der Klasse), je vier Stufen.
/// Eine Stufe braucht 2 × Stufe Punkte im Zweig. Zeigen = Beschreibung, Klick = lernen.
internal sealed partial class HubScene
{
string? _skillHover;
float _learnFlash;
string? _learnedId;
void DrawSkills(SpriteBatch sb, RectangleF r)
{
float x = r.X + 30, y = r.Y + 46;
D.Text(sb, Assets.SansBold, 22, string.Format(L.t("char.skillpoints"), _game.SkillPoints),
new Vector2(x + 650, y - 2), _game.SkillPoints > 0 ? D.Gold : D.Dim);
if (_ui.Button(sb, new RectangleF(r.Right - 330, y - 22, 300, 44),
string.Format(L.t("char.skillreset"), NumberFormat.Format(_game.SkillResetCost)),
_game.SkillRanks.Count > 0 && _game.Gold >= _game.SkillResetCost, size: 16))
if (_game.ResetSkills()) SoundManager.PlayCoins();
_skillHover = null;
_learnFlash = MathF.Max(0, _learnFlash - 1 / 60f * 2.5f);
var branches = new[] { SkillBranch.Offense, SkillBranch.Defense, SkillBranch.Class };
float colW = (r.Width - 60) / 3, top = y + 66, rowH = 132;
for (int b = 0; b < 3; b++)
{
var branch = branches[b];
float cx = r.X + 30 + colW * b + colW / 2;
int pts = _game.BranchPoints(branch);
D.Text(sb, Assets.Serif, 24, $"{L.t("branch." + branch.ToString().ToLowerInvariant()).ToUpperInvariant()} · {pts}", // i18n-ok
new Vector2(cx, top), D.Gold, Align.Center);
var skills = SkillDef.For(_game.Class).Where(s => s.Branch == branch).OrderBy(s => s.Tier).ToList();
// Verbindungslinien zwischen den Stufen
for (int i = 0; i + 1 < skills.Count; i++)
{
float y0 = top + 82 + i * rowH, y1 = y0 + rowH;
bool open = pts >= skills[i + 1].Requires;
D.Rect(sb, new RectangleF(cx - 2, y0 + 80, 4, y1 - y0 - 124), open ? D.Gold * 0.7f : D.Border * 0.6f);
}
foreach (var s in skills) DrawSkillNode(sb, s, new Vector2(cx, top + 82 + s.Tier * rowH), pts);
}
// Beschreibung (Zeigen) oder Hinweis
var info = new RectangleF(r.X + 30, r.Bottom - 96, r.Width - 60, 76);
Ui.Panel(sb, info, D.Border, 0.9f);
if (_skillHover is string id)
{
var s = SkillDef.Get(id);
string head = L.t(s.Key) + (s.Active ? " · " + L.t("char.skill.active") : ""); // i18n-ok
D.Text(sb, Assets.SansBold, 21, head, new Vector2(info.X + 20, info.Y + 22), s.Active ? new Color(255, 170, 70) : D.Gold);
D.Text(sb, Assets.Sans, 18, L.t(s.Desc), new Vector2(info.X + 20, info.Y + 52), D.Sand);
}
else D.Text(sb, Assets.Sans, 18, L.t("char.skill.hint"), info.Center, D.Dim, Align.Center);
}
void DrawSkillNode(SpriteBatch sb, SkillDef s, Vector2 c, int branchPts)
{
int rank = _game.SkillRank(s.Id);
bool unlocked = branchPts >= s.Requires, can = _game.CanLearn(s), max = rank >= s.MaxRank;
var r = new RectangleF(c.X - 44, c.Y - 44, 88, 88);
bool hover = _ui.Hover(r);
if (hover) _skillHover = s.Id;
if (can) D.Glow(sb, c, new Vector2(150 + 12 * MathF.Sin((float)_t * 4)), D.Gold * 0.45f);
if (_learnedId == s.Id && _learnFlash > 0) D.Glow(sb, c, new Vector2(200 + 120 * (1 - _learnFlash)), Color.White * _learnFlash);
if (Assets.Sprite(s.Icon) is Texture2D icon)
{
var tint = !unlocked ? new Color(55, 48, 40) : rank == 0 ? new Color(150, 140, 125) : Color.White;
sb.Draw(icon, c, null, tint, 0, new Vector2(icon.Width / 2f, icon.Height / 2f), (hover ? 88f : 80f) / icon.Width, SpriteEffects.None, 0);
}
if (s.Active) D.Text(sb, Assets.SansBold, 14, L.t("char.skill.active").ToUpperInvariant(), c + new Vector2(56, 0), new Color(255, 170, 70));
// Rang als Punkte unter dem Medaillon
for (int i = 0; i < s.MaxRank; i++)
{
var p = c + new Vector2((i - (s.MaxRank - 1) / 2f) * 18, 50);
sb.Draw(Assets.Disc, p, null, i < rank ? D.Gold : new Color(40, 32, 24), 0, new Vector2(64), 14f / 128, SpriteEffects.None, 0);
}
string label = unlocked ? L.t(s.Key) : string.Format(L.t("char.skill.requires"), s.Requires);
D.Text(sb, Assets.SansBold, 16, label, c + new Vector2(0, 70), !unlocked ? D.Dim : max ? D.Gold : Color.White, Align.Center);
if (can && _ui.Hit(r) && _game.Learn(s.Id))
{
SoundManager.PlayLevelUp();
_learnedId = s.Id; _learnFlash = 1;
}
}
}
}