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 { /// Expeditionen (Schublade: Regionen, Dauer, Aufbruch; unterwegs: Fortschritt statt Gegnerwahl), /// Rückkehr-Bericht und Ereignis-Karten mit Entscheidungen (beides als Fenster über dem Hub), /// dazu die laufenden Segen unter der Kopfleiste. internal sealed partial class HubScene { string _expRegion = "gallia"; int _expDuration; string? _eventShown; // Ereignis, dessen Karte offen ist string? _eventOutcome; // Text-Key des Ausgangs, nach der Entscheidung string? _eventSeen; // für den Klang beim Erscheinen static string DurationLabel(int i) => NumberFormat.Duration(Adventures.Durations[i]); static int LootCount(int duration) => 1 + 2 * duration; static Color ChanceColor(double c) => c >= 0.75 ? D.Green : c >= 0.4 ? D.Gold : D.Red; /// Ein Fenster liegt über dem Hub (Bericht oder Ereignis): darunter nichts anklickbar. bool Modal => Welcome != null || _game.ExpeditionResult != null || _game.PendingEvent != null || _eventShown != null; /// Bericht über die Zeit, in der das Spiel zu war (ab 2 Minuten), als erstes Fenster. public OfflineReport? Welcome { get; set; } void UpdateAdventure() { if (_game.PendingEvent is string id && _eventSeen != id) { _eventSeen = id; SoundManager.PlayChapterSting(); } } Texture2D? Picture(string art) => Assets.Sprite(art, "jpg"); static void DrawPicture(SpriteBatch sb, Texture2D? tex, RectangleF r, float alpha = 1) { if (tex == null) { D.Rect(sb, r, new Color(30, 22, 15)); return; } // "cover": Bild füllt das Rechteck, mittig beschnitten float k = MathF.Max(r.Width / tex.Width, r.Height / tex.Height); int sw = (int)(r.Width / k), sh = (int)(r.Height / k); var src = new Rectangle((tex.Width - sw) / 2, (tex.Height - sh) / 2, sw, sh); sb.Draw(tex, new Rectangle((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height), src, Color.White * alpha); } void DrawAwayStatus(SpriteBatch sb, RectangleF r, Expedition a) { var reg = RegionDef.Get(a.Region); double total = Adventures.Durations[a.Duration]; float bw = r.Width - 380; D.Text(sb, Assets.SansBold, 22, string.Format(L.t("exp.away"), L.t(reg.Key)), new Vector2(r.X, r.Y + 14), D.Gold); D.Text(sb, Assets.Sans, 18, string.Format(L.t("exp.left"), NumberFormat.Duration(a.Left)), new Vector2(r.X, r.Y + 44), D.Sand); D.Bar(sb, new RectangleF(r.X, r.Y + 64, bw, 14), (float)(1 - a.Left / total), (float)(1 - a.Left / total), D.Gold); if (_ui.Button(sb, new RectangleF(r.Right - 340, r.Y + 10, 340, 60), L.t("exp.recall"), size: 18, accent: D.Red)) { _game.Recall(); SoundManager.PlayBoo(); } } /// Statt der Gegnerwahl, solange der Gladiator unterwegs ist: Bild der Region und Fortschritt. void DrawAwayCard(SpriteBatch sb, Expedition a) { var reg = RegionDef.Get(a.Region); var r = new RectangleF(Camera.W - 860, 150, 820, 640); Ui.Panel(sb, r, D.Gold, 0.92f); DrawPicture(sb, Picture(reg.Art), new RectangleF(r.X + 20, r.Y + 20, r.Width - 40, 430)); DrawAwayStatus(sb, new RectangleF(r.X + 30, r.Y + 470, r.Width - 60, 90), a); // Reise in 3D ansehen / Karte if (_ui.Button(sb, new RectangleF(r.X + 30, r.Bottom - 70, (r.Width - 76) / 2, 54), L.t("exp.watch"), selected: true, size: 20, accent: D.Gold)) OpenJourney(); if (_ui.Button(sb, new RectangleF(r.X + 46 + (r.Width - 76) / 2, r.Bottom - 70, (r.Width - 76) / 2, 54), L.t("exp.map"), size: 20)) { _overlay = Overlay.Map; SoundManager.PlayDrawer(); } } // ── Segen ─────────────────────────────────────────────────── void DrawBuffs(SpriteBatch sb) { float y = 136; foreach (var b in _game.Buffs) { string text = string.Format(L.t("buff." + b.Kind.ToString().ToLowerInvariant()), NumberFormat.Percent(b.Mult - 1), NumberFormat.Duration(b.Left)); D.Text(sb, Assets.SansBold, 17, text, new Vector2(40, y), D.Blue); y += 24; } } // ── Fenster: Rückkehr-Bericht und Ereignis ────────────────── void DrawModal(SpriteBatch sb) { if (Homecoming) { DrawHomecoming(sb, _game.ExpeditionResult!); return; } // Heimkehr als Szene D.Rect(sb, new RectangleF(0, 0, Camera.W, Camera.H), Color.Black * 0.65f); if (Welcome is { } w) DrawWelcome(sb, w); else if (_game.ExpeditionResult is { } rep) DrawReport(sb, rep); else if (_eventShown != null || _game.PendingEvent != null) DrawEvent(sb); } void DrawWelcome(SpriteBatch sb, OfflineReport w) { var r = new RectangleF(Camera.W / 2 - 480, 200, 960, 640); Ui.Panel(sb, r, D.Gold, 0.97f); float y = r.Y + 70; D.Text(sb, Assets.Serif, 52, L.t("offline.title"), new Vector2(r.Center.X, y), D.Gold, Align.Center); y += 70; D.Text(sb, Assets.Serif, 24, string.Format(L.t("offline.away"), NumberFormat.Duration(w.Seconds)), new Vector2(r.Center.X, y), D.Sand, Align.Center); if (w.Seconds >= _game.OfflineCapSeconds - 1) D.Text(sb, Assets.Sans, 17, string.Format(L.t("offline.capped"), NumberFormat.Duration(_game.OfflineCapSeconds)), new Vector2(r.Center.X, y + 34), D.Dim, Align.Center); y += 90; void Line(string label, string value, Color c) { D.Text(sb, Assets.Sans, 24, label, new Vector2(r.X + 160, y), D.Sand); D.Text(sb, Assets.SansBold, 28, value, new Vector2(r.Right - 160, y), c, Align.Right); D.Rect(sb, new RectangleF(r.X + 160, y + 26, r.Width - 320, 1), D.Border * 0.6f); y += 62; } if (w.Gold > 0) Line(L.t("offline.gold"), "+" + NumberFormat.Format(w.Gold), D.Gold); // i18n-ok (nur von Expeditionen) if (w.Fame > 0) Line(L.t("offline.fame"), "+" + NumberFormat.Format(w.Fame), D.Gold); // i18n-ok Line(L.t("offline.levels"), "+" + w.LevelUps.ToString(NumberFormat.Culture), D.Green); // i18n-ok if (w.Wins + w.Losses > 0) Line(L.t("offline.fights"), string.Format(L.t("offline.fights.value"), w.Wins, w.Losses), D.Sand); if (_ui.Button(sb, new RectangleF(r.Center.X - 200, r.Bottom - 100, 400, 68), L.t("offline.ok"), selected: true, size: 26)) { Welcome = null; SoundManager.PlayCoins(); } } void DrawReport(SpriteBatch sb, ExpeditionReport rep) { var reg = RegionDef.Get(rep.Region); var r = new RectangleF(Camera.W / 2 - 520, 70, 1040, 940); Ui.Panel(sb, r, rep.Success ? D.Gold : D.Red, 0.97f); DrawPicture(sb, Picture(reg.Art), new RectangleF(r.X + 30, r.Y + 30, r.Width - 60, 300)); float y = r.Y + 370; D.Text(sb, Assets.Serif, 36, string.Format(L.t(rep.Success ? "exp.back.ok" : "exp.back.fail"), L.t(reg.Key)), new Vector2(r.Center.X, y), rep.Success ? D.Gold : D.Red, Align.Center); y += 44; if (!rep.Success) { D.Text(sb, Assets.Sans, 18, L.t("exp.back.failtext"), new Vector2(r.Center.X, y), D.Sand, Align.Center); y += 34; } foreach (int n in rep.Log) { D.TextWrap(sb, Assets.Serif, 19, "· " + L.t("expedition.log." + n), new RectangleF(r.X + 80, y - 10, r.Width - 160, 40), D.Sand); // i18n-ok y += 32; } y += 14; void Line(string label, string value) { D.Text(sb, Assets.Sans, 20, label, new Vector2(r.X + 220, y), D.Dim); D.Text(sb, Assets.SansBold, 22, value, new Vector2(r.Right - 220, y), D.Sand, Align.Right); y += 34; } Line(L.t("exp.reward.gold"), "+" + NumberFormat.Format(rep.Gold)); // i18n-ok Line(L.t("exp.reward.fame"), "+" + NumberFormat.Format(rep.Fame)); // i18n-ok Line(L.t("exp.reward.xp"), "+" + NumberFormat.Format(rep.Xp)); // i18n-ok if (rep.Loot.Count > 0) { float size = 88, lx = r.Center.X - (rep.Loot.Count * (size + 12) - 12) / 2; for (int i = 0; i < rep.Loot.Count; i++) ItemTile(sb, new RectangleF(lx + i * (size + 12), y + 4, size, size), rep.Loot[i], false); } if (_ui.Button(sb, new RectangleF(r.Center.X - 170, r.Bottom - 80, 340, 60), L.t("exp.ok"), selected: true, size: 24)) { _game.DismissExpeditionResult(); SoundManager.PlayCoins(); } } void DrawEvent(SpriteBatch sb) { _eventShown ??= _game.PendingEvent; var ev = Adventures.GetEvent(_eventShown!); var r = new RectangleF(Camera.W / 2 - 700, 110, 1400, 860); Ui.Panel(sb, r, D.Gold, 0.97f); var pic = new RectangleF(r.X + 34, r.Y + 34, 640, 360); DrawPicture(sb, Picture(ev.Art), pic); D.Frame(sb, pic, D.Border, 2); float tx = pic.Right + 34, tw = r.Right - 34 - tx; D.TextWrap(sb, Assets.Serif, 34, L.t(ev.Title), new RectangleF(tx, r.Y + 30, tw, 100), D.Gold); D.TextWrap(sb, Assets.Serif, 21, L.t(ev.Text), new RectangleF(tx, r.Y + 140, tw, 250), D.Sand); float y = pic.Bottom + 34; if (_eventOutcome != null) { D.TextWrap(sb, Assets.Serif, 26, L.t(_eventOutcome), new RectangleF(r.X + 80, y + 20, r.Width - 160, 200), new Color(245, 236, 214)); if (_ui.Button(sb, new RectangleF(r.Center.X - 170, r.Bottom - 90, 340, 62), L.t("event.ok"), selected: true, size: 24)) { _eventShown = null; _eventOutcome = null; SoundManager.PlayClick(); } return; } for (int i = 0; i < ev.Choices.Length; i++) { var c = ev.Choices[i]; double cost = _game.ChoiceCost(c); string label = L.t(ev.ChoiceKey(c)); if (cost > 0) label += " · " + string.Format(L.t("event.cost"), NumberFormat.Format(cost)); // i18n-ok if (c.Chance < 1) label += " · " + L.t("event.risky") + " " + NumberFormat.Percent(c.Chance); // i18n-ok if (_ui.Button(sb, new RectangleF(r.X + 60, y, r.Width - 120, 64), label, _game.Gold >= cost, size: 21)) { var outcome = _game.Choose(i); if (outcome != null) { _eventOutcome = outcome; if (outcome.EndsWith(".fail", StringComparison.Ordinal)) SoundManager.PlayBoo(); else SoundManager.PlayGoodEvent(); } } y += 76; } } } }