182 lines
9.4 KiB
C#
182 lines
9.4 KiB
C#
using System;
|
||
using GladiatorIdle.Gfx;
|
||
using Microsoft.Xna.Framework;
|
||
using Microsoft.Xna.Framework.Graphics;
|
||
using D = GladiatorIdle.Gfx.Draw;
|
||
|
||
namespace GladiatorIdle.Arena
|
||
{
|
||
/// <summary>
|
||
/// Heimkehr von der Expedition als Szene statt Textfenster: der Gladiator geht in den Ludus
|
||
/// (Erfolg: Siegerpose, Horn und Jubel; Misserfolg: langsam, angeschlagen), daneben fährt der
|
||
/// Bericht ein – Titel, Tagebuch Zeile für Zeile, Beutekarten drehen sich einzeln um (Glanz und
|
||
/// Klang nach Seltenheit), Denare/Ruhm/Erfahrung zählen hoch. Klick oder Leertaste: alles sofort.
|
||
/// </summary>
|
||
internal sealed partial class HubScene
|
||
{
|
||
ExpeditionReport? _homeRep;
|
||
float _homeT;
|
||
int _homeFlipped, _homeSounds;
|
||
bool _homeCoins;
|
||
|
||
bool Homecoming => _game.ExpeditionResult != null && Welcome == null;
|
||
|
||
/// Ankunftsdauer (Lauf in den Ludus); bei „Effekte reduzieren“ sofort da.
|
||
float HomeWalk => AppSettings.ReduceMotion ? 0 : _homeRep?.Success == false ? 3.2f : 2.4f;
|
||
|
||
/// Takt der Heimkehr; liefert die x-Position des Gladiators (läuft von links herein).
|
||
float UpdateHomecoming(float dt, Input input)
|
||
{
|
||
var rep = _game.ExpeditionResult!;
|
||
if (rep != _homeRep)
|
||
{
|
||
_homeRep = rep; _homeT = 0; _homeFlipped = 0; _homeSounds = 0; _homeCoins = false;
|
||
_dummy.Set(DuelState.Ready);
|
||
}
|
||
float before = _homeT;
|
||
_homeT += dt;
|
||
if (input.Pressed(Microsoft.Xna.Framework.Input.Keys.Space)) _homeT = MathF.Max(_homeT, HomeEnd(rep));
|
||
// Ankunft: Pose und Ton einmal
|
||
if (before < HomeWalk && _homeT >= HomeWalk)
|
||
{
|
||
if (rep.Success) { _dummy.Set(DuelState.Victory); SoundManager.PlayVictory(); SoundManager.PlayCheer(); _crowd.Wave(); }
|
||
else { _dummy.Set(DuelState.Stunned); _dummy.StunLeft = 99; SoundManager.PlayDefeat(); }
|
||
}
|
||
_dummy.StateTime += dt;
|
||
float k = HomeWalk <= 0 ? 1 : MathHelper.Clamp(_homeT / HomeWalk, 0, 1);
|
||
k = 1 - (1 - k) * (1 - k);
|
||
return MathHelper.Lerp(-260, HERO_X, k);
|
||
}
|
||
|
||
// Zeitplan (Sekunden nach der Ankunft)
|
||
static float LineAt(int i) => 0.4f + i * 0.75f;
|
||
static float CardsAt(ExpeditionReport r) => LineAt(r.Log.Count) + 0.2f;
|
||
static float CardAt(ExpeditionReport r, int i) => CardsAt(r) + i * 0.45f;
|
||
static float CountAt(ExpeditionReport r) => CardAt(r, r.Loot.Count) + 0.2f;
|
||
float HomeEnd(ExpeditionReport r) => HomeWalk + CountAt(r) + 1.3f;
|
||
|
||
void DrawHomecoming(SpriteBatch sb, ExpeditionReport rep)
|
||
{
|
||
var reg = RegionDef.Get(rep.Region);
|
||
float t = _homeT - HomeWalk; // Zeit seit der Ankunft
|
||
bool done = _homeT >= HomeEnd(rep);
|
||
var accent = rep.Success ? D.Gold : D.Red;
|
||
|
||
// Misserfolg: Licht gedämpft
|
||
if (!rep.Success) D.Rect(sb, new RectangleF(0, 0, Camera.W, Camera.H), new Color(10, 12, 24) * 0.35f);
|
||
if (t < 0) return;
|
||
|
||
float slide = 1 - MathF.Pow(1 - MathHelper.Clamp(t / 0.5f, 0, 1), 3);
|
||
var r = new RectangleF(Camera.W - 940 + (1 - slide) * 300, 110, 900, 880);
|
||
Ui.Panel(sb, r, accent, 0.94f * slide);
|
||
float x = r.X + 34, y = r.Y + 34, w = r.Width - 68;
|
||
|
||
// Kopf: Bild der Region und Titel
|
||
DrawPicture(sb, Picture(reg.Art), new RectangleF(x, y, 230, 140), slide);
|
||
D.Frame(sb, new RectangleF(x, y, 230, 140), accent * slide, 2);
|
||
D.TextWrap(sb, Assets.Serif, 38, string.Format(L.t(rep.Success ? "exp.back.ok" : "exp.back.fail"), L.t(reg.Key)),
|
||
new RectangleF(x + 260, y + 4, w - 260, 100), accent * slide);
|
||
if (!rep.Success) D.TextWrap(sb, Assets.Sans, 18, L.t("exp.back.failtext"), new RectangleF(x + 260, y + 96, w - 260, 50), D.Sand * slide);
|
||
y += 170;
|
||
|
||
// Tagebuch: Zeile für Zeile, Buchstaben laufen ein
|
||
for (int i = 0; i < rep.Log.Count; i++)
|
||
{
|
||
float lt = t - LineAt(i);
|
||
if (lt < 0) break;
|
||
string full = "· " + L.t("expedition.log." + rep.Log[i]); // i18n-ok
|
||
int n = done ? full.Length : Math.Min(full.Length, (int)(lt * 80));
|
||
D.TextWrap(sb, Assets.Serif, 21, full[..n], new RectangleF(x, y, w, 80), D.Sand);
|
||
y += 14 + 27 * D.WrapLines(Assets.Serif, 21, full, w);
|
||
}
|
||
// Platz für das ganze Tagebuch freihalten (Beute darunter springt nicht)
|
||
float logH = 0;
|
||
foreach (int n in rep.Log) logH += 14 + 27 * D.WrapLines(Assets.Serif, 21, "· " + L.t("expedition.log." + n), w); // i18n-ok
|
||
y = r.Y + 34 + 170 + logH + 18;
|
||
|
||
// Beute: Karten drehen sich einzeln um
|
||
if (rep.Loot.Count > 0 && t >= CardsAt(rep) - 0.2f)
|
||
{
|
||
D.Text(sb, Assets.SansBold, 20, L.t("exp.loot"), new Vector2(x, y), D.Sand);
|
||
float cw = 150, ch = 200, gap = 18, lx = r.Center.X - (rep.Loot.Count * (cw + gap) - gap) / 2, cy = y + 30;
|
||
var back = Assets.Sprite("icon_vexillum");
|
||
for (int i = 0; i < rep.Loot.Count; i++)
|
||
{
|
||
var it = rep.Loot[i];
|
||
float ft = done ? 1 : MathHelper.Clamp((t - CardAt(rep, i)) / 0.35f, 0, 1);
|
||
if (ft >= 0.5f && i >= _homeFlipped)
|
||
{
|
||
_homeFlipped = i + 1;
|
||
var c = new Vector2(lx + i * (cw + gap) + cw / 2, cy + ch / 2);
|
||
if (!AppSettings.ReduceMotion) _fx.Sparks(c, 10 + 10 * (int)it.Rarity, RarityColor(it.Rarity), -MathF.PI / 2, MathF.PI, 500);
|
||
if (it.Rarity >= Rarity.Legendary) SoundManager.PlayAchievement();
|
||
else if (it.Rarity >= Rarity.Epic) SoundManager.PlayLevelUp();
|
||
else SoundManager.PlayEquip();
|
||
}
|
||
float sx = MathF.Abs(MathF.Cos(MathF.PI * ft)); // 1 → 0 → 1
|
||
var cr = new RectangleF(lx + i * (cw + gap) + cw / 2 * (1 - sx), cy, cw * sx, ch);
|
||
if (ft < 0.5f)
|
||
{
|
||
// Rückseite: dunkle Karte mit Feldzeichen
|
||
D.Rect(sb, cr, new Color(40, 26, 18));
|
||
D.Frame(sb, cr, D.Gold * 0.8f, 3);
|
||
if (back != null && cr.Width > 4)
|
||
sb.Draw(back, new Rectangle((int)(cr.X + cr.Width * 0.15f), (int)(cr.Y + 30), (int)(cr.Width * 0.7f), (int)(ch - 60)), Color.White * 0.8f);
|
||
}
|
||
else
|
||
{
|
||
var col = RarityColor(it.Rarity);
|
||
if (it.Rarity >= Rarity.Rare) D.Glow(sb, cr.Center, new Vector2(cw * 1.6f, ch * 1.4f), col * (0.25f + 0.1f * MathF.Sin((float)_t * 4)));
|
||
D.Rect(sb, cr, new Color(28, 20, 14));
|
||
D.Frame(sb, cr, col, 3);
|
||
if (cr.Width > 20)
|
||
{
|
||
ItemTile(sb, new RectangleF(cr.X + (cr.Width - 110 * sx) / 2, cr.Y + 18, 110 * sx, 110), it, false);
|
||
if (sx > 0.8f) D.TextWrap(sb, Assets.SansBold, 15, ItemName(it), new RectangleF(cr.X + 8, cr.Y + 138, cr.Width - 16, 60), col);
|
||
}
|
||
// Klick auf eine aufgedeckte Karte: Stück im Gladiator-Reiter zeigen
|
||
if (done && _ui.Hover(cr) && _ui.Hit(cr))
|
||
{
|
||
_game.DismissExpeditionResult(); _dummy.Set(DuelState.Ready);
|
||
_drawer = Drawer.Gladiator; _page = Page.Gear; _sel = it.Id;
|
||
SoundManager.PlayDrawer();
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
y = cy + ch + 24;
|
||
}
|
||
|
||
// Lohn zählt hoch
|
||
float ct = t - CountAt(rep);
|
||
if (ct >= 0)
|
||
{
|
||
if (!_homeCoins) { _homeCoins = true; SoundManager.PlayCoins(); }
|
||
float k = done ? 1 : MathHelper.Clamp(ct / 1.2f, 0, 1);
|
||
k = 1 - (1 - k) * (1 - k);
|
||
void Line(string label, double value, Color c)
|
||
{
|
||
D.Text(sb, Assets.Sans, 21, label, new Vector2(x + 120, y), D.Sand);
|
||
D.Text(sb, Assets.SansBold, 26, "+" + NumberFormat.Format(value * k), new Vector2(r.Right - 154, y), c, Align.Right); // i18n-ok
|
||
y += 40;
|
||
}
|
||
Line(L.t("exp.reward.gold"), rep.Gold, D.Gold);
|
||
Line(L.t("exp.reward.fame"), rep.Fame, D.Gold);
|
||
Line(L.t("exp.reward.xp"), rep.Xp, D.Blue);
|
||
}
|
||
|
||
// Weiter (oder: Klick überspringt die Inszenierung)
|
||
if (done)
|
||
{
|
||
if (_ui.Button(sb, new RectangleF(r.Center.X - 200, r.Bottom - 92, 400, 66), L.t("exp.ok"), selected: true, size: 24, accent: accent))
|
||
{ _game.DismissExpeditionResult(); _dummy.Set(DuelState.Ready); SoundManager.PlayCoins(); }
|
||
}
|
||
else
|
||
{
|
||
D.Text(sb, Assets.Sans, 16, L.t("exp.skip"), new Vector2(r.Center.X, r.Bottom - 40), D.Dim, Align.Center);
|
||
if (_ui.Hit(r)) _homeT = HomeEnd(rep);
|
||
}
|
||
}
|
||
}
|
||
}
|