Files
GladiatorIdle/Mono/Arena/HubScene.Map.cs
2026-11-09 16:13:28 +01:00

238 lines
13 KiB
C#
Raw Permalink 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.Collections.Generic;
using System.Linq;
using GladiatorIdle.Gfx;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using D = GladiatorIdle.Gfx.Draw;
namespace GladiatorIdle.Arena
{
/// <summary>
/// Feldzugkarte (Vollbild über dem Hub): das Reich als gemalte Karte, Rom in der Mitte, die
/// Regionen als Feldzeichen. Offene Regionen sind über laufende Wege mit Rom verbunden,
/// gesperrte liegen im Nebel. Rechts die Tafel der gewählten Region (Bild, Chance, Dauer, Lohn,
/// Aufbruch); unterwegs zieht ein Feldzeichen über die Route.
/// </summary>
internal sealed partial class HubScene
{
enum Overlay { None, Map, Journey }
Overlay _overlay;
string? _mapHover;
/// Lage auf der Karte (Anteil am Bild 0–1).
static readonly Dictionary<string, Vector2> MapPos = new()
{
["rome"] = new(0.54f, 0.47f),
["gallia"] = new(0.41f, 0.32f), ["germania"] = new(0.52f, 0.22f), ["britannia"] = new(0.39f, 0.10f),
["hispania"] = new(0.31f, 0.52f), ["dacia"] = new(0.78f, 0.33f), ["aegyptus"] = new(0.83f, 0.79f),
};
Vector2 _mapPan; float _mapZoom = 1;
/// Mitte der Karte auf dem Bildschirm: nach links verschoben, damit rechts die Tafel Platz hat.
static readonly Vector2 MapCenter = new(640, Camera.H / 2);
Vector2 OnMap(Vector2 f) => MapCenter + (f - new Vector2(0.5f)) * new Vector2(Camera.W, Camera.H) * _mapZoom + _mapPan;
/// Punkt auf der gebogenen Route Rom → Region (t = 0 … 1).
Vector2 RoutePoint(string region, float t)
{
Vector2 a = OnMap(MapPos["rome"]), b = OnMap(MapPos[region]);
var d = b - a;
var n = new Vector2(-d.Y, d.X) * 0.18f; // Bogen zur Seite
var c = (a + b) / 2 + n;
float u = 1 - t;
return u * u * a + 2 * u * t * c + t * t * b;
}
void DrawRoute(SpriteBatch sb, string region, Color col, float thick, float phase, float upTo = 1)
{
float len = Vector2.Distance(OnMap(MapPos["rome"]), OnMap(MapPos[region]));
int n = Math.Max(6, (int)(len / 22));
for (int i = -1; i < n; i++)
{
float t0 = (i + phase) / n, t1 = t0 + 0.55f / n;
if (t1 <= 0 || t0 >= upTo) continue;
t0 = MathF.Max(0, t0); t1 = MathF.Min(upTo, t1);
Vector2 p0 = RoutePoint(region, t0), p1 = RoutePoint(region, t1), dv = p1 - p0;
sb.Draw(Assets.Pixel, p0, null, col, MathF.Atan2(dv.Y, dv.X), new Vector2(0, 0.5f), new Vector2(dv.Length(), thick), SpriteEffects.None, 0);
}
}
void DrawMap(SpriteBatch sb)
{
bool calm = AppSettings.ReduceMotion;
float t = (float)_t;
_mapZoom = calm ? 1.08f : 1.08f + 0.02f * MathF.Sin(t * 0.07f);
_mapPan = calm ? Vector2.Zero : new Vector2(14 * MathF.Sin(t * 0.05f), 8 * MathF.Sin(t * 0.04f + 1));
// Karte und Licht
D.Rect(sb, new RectangleF(0, 0, Camera.W, Camera.H), new Color(28, 22, 16));
if (Assets.Sprite("map_empire", "jpg") is Texture2D map)
{
var size = new Vector2(Camera.W, Camera.H) * _mapZoom;
sb.Draw(map, MapCenter + _mapPan, null, new Color(0.95f, 0.92f, 0.86f), 0,
new Vector2(map.Width / 2f, map.Height / 2f), size / new Vector2(map.Width, map.Height), SpriteEffects.None, 0);
}
else D.Rect(sb, new RectangleF(0, 0, Camera.W, Camera.H), new Color(60, 48, 34));
D.Glow(sb, new Vector2(-250, Camera.H / 2), new Vector2(1000, 2200), Color.Black * 0.55f);
D.Glow(sb, new Vector2(Camera.W + 250, Camera.H / 2), new Vector2(1300, 2200), Color.Black * 0.7f);
D.Glow(sb, new Vector2(Camera.W / 2, -200), new Vector2(3000, 600), Color.Black * 0.5f);
D.Glow(sb, new Vector2(Camera.W / 2, Camera.H + 200), new Vector2(3000, 600), Color.Black * 0.5f);
var away = _game.Away;
string sel = away?.Region ?? _expRegion;
if (away == null && !_game.RegionOpen(RegionDef.Get(sel)))
sel = _expRegion = RegionDef.All.Last(reg => _game.RegionOpen(reg)).Id;
// Nebel über gesperrten Regionen (treibende Wolken)
int ri = 0;
foreach (var reg in RegionDef.All)
{
ri++;
if (_game.RegionOpen(reg)) continue;
var c = OnMap(MapPos[reg.Id]);
for (int k = 0; k < 6; k++)
{
float a = t * 0.12f + k * 1.7f + ri, r = 70 + 25 * MathF.Sin(t * 0.3f + k);
var p = c + new Vector2(MathF.Cos(a) * r * 1.6f, MathF.Sin(a * 0.8f) * r * 0.7f);
D.Glow(sb, p, new Vector2(330, 200), new Color(120, 124, 136) * 0.75f);
D.Glow(sb, p + new Vector2(-20, -16), new Vector2(200, 120), new Color(225, 225, 232) * 0.45f);
}
D.Glow(sb, c, new Vector2(420, 290), new Color(90, 94, 108) * 0.85f);
}
// Wege von Rom zu den offenen Regionen; der gewählte leuchtet
float phase = calm ? 0 : t * 0.6f % 1;
foreach (var reg in RegionDef.All)
{
if (!_game.RegionOpen(reg)) continue;
bool on = reg.Id == sel || reg.Id == _mapHover;
if (on) DrawRoute(sb, reg.Id, D.Gold * 0.35f, 9, phase);
DrawRoute(sb, reg.Id, on ? new Color(255, 214, 120) : new Color(120, 72, 40) * 0.75f, on ? 4 : 3, phase);
}
// Rom
var rome = OnMap(MapPos["rome"]);
D.Glow(sb, rome, new Vector2(150), D.Gold * (0.45f + 0.15f * MathF.Sin(t * 2)));
sb.Draw(Assets.Disc, rome, null, new Color(150, 30, 30), 0, new Vector2(64), 26f / 128, SpriteEffects.None, 0);
sb.Draw(Assets.Disc, rome, null, D.Gold, 0, new Vector2(64), 16f / 128, SpriteEffects.None, 0);
Label(sb, L.t("exp.rome"), rome + new Vector2(0, 30), D.Gold, 24);
// Feldzeichen der Regionen
_mapHover = null;
var flag = Assets.Sprite("icon_vexillum");
foreach (var reg in RegionDef.All)
{
var p = OnMap(MapPos[reg.Id]);
bool open = _game.RegionOpen(reg), isSel = reg.Id == sel;
var hit = new RectangleF(p.X - 50, p.Y - 110, 100, 150);
bool hover = away == null && open && _ui.Hover(hit);
if (hover) _mapHover = reg.Id;
float pulse = 0.5f + 0.5f * MathF.Sin(t * 2.4f + reg.Unlock);
if (open) D.Glow(sb, p - new Vector2(0, 40), new Vector2(isSel ? 230 : 170), D.Gold * ((isSel ? 0.5f : 0.25f) + 0.15f * pulse));
if (flag != null)
{
float s = (isSel || hover ? 120f : 96f) / flag.Height;
float sway = calm ? 0 : 0.04f * MathF.Sin(t * 1.6f + reg.Tier);
sb.Draw(flag, p + new Vector2(0, 12), null, open ? Color.White : new Color(120, 116, 110) * 0.85f, sway,
new Vector2(flag.Width / 2f, flag.Height * 0.94f), s, SpriteEffects.None, 0);
}
Label(sb, L.t(reg.Key).ToUpperInvariant(), p + new Vector2(0, 34), open ? (isSel ? Color.White : D.Sand) : D.Dim, isSel ? 26 : 22);
if (!open)
Label(sb, string.Format(L.t("exp.locked"), L.t(ArenaDef.All[reg.Unlock].Key)), p + new Vector2(0, 62), D.Dim, 16);
else if (away == null)
Label(sb, NumberFormat.Percent(_game.ExpeditionChance(reg)), p + new Vector2(0, 62), ChanceColor(_game.ExpeditionChance(reg)), 18);
if (hover && _ui.Hit(hit)) { _expRegion = reg.Id; SoundManager.PlayDrawer(); }
}
// Unterwegs: Feldzeichen zieht über die Route, dahinter leuchtet der zurückgelegte Weg
if (away != null)
{
float k = (float)(1 - away.Left / Adventures.Durations[away.Duration]);
DrawRoute(sb, away.Region, new Color(255, 230, 160), 6, 0, k);
var m = RoutePoint(away.Region, k) + new Vector2(0, calm ? 0 : -4 * MathF.Abs(MathF.Sin(t * 5)));
for (int i = 0; i < 4; i++)
D.Glow(sb, m + new Vector2(-14 * i - 10, 18 + 3 * MathF.Sin(t * 7 + i)), new Vector2(46 - 6 * i), new Color(200, 170, 120) * (0.35f - 0.07f * i));
D.Glow(sb, m, new Vector2(140), D.Gold * 0.6f);
if (flag != null) sb.Draw(flag, m, null, Color.White, 0, new Vector2(flag.Width / 2f, flag.Height * 0.94f), 80f / flag.Height, SpriteEffects.None, 0);
}
DrawMapPanel(sb, RegionDef.Get(sel), away);
// Anleitung unten links
var gr = new RectangleF(40, Camera.H - 210, 640, 170);
Ui.Panel(sb, gr, D.Border, 0.9f);
D.TextWrap(sb, Assets.Serif, 19, L.t("guide.expedition.what"), new RectangleF(gr.X + 22, gr.Y + 18, gr.Width - 44, 60), D.Sand);
var (tip, tc) = Tip(Drawer.Expedition);
D.TextWrap(sb, Assets.Sans, 17, tip, new RectangleF(gr.X + 22, gr.Y + 88, gr.Width - 44, 70), tc);
}
/// Text mit dunklem Schatten (lesbar auf der hellen Karte).
static void Label(SpriteBatch sb, string text, Vector2 at, Color c, float size)
{
D.Text(sb, Assets.Serif, size, text, at + new Vector2(2, 2), Color.Black * 0.75f, Align.Center);
D.Text(sb, Assets.Serif, size, text, at, c, Align.Center);
}
/// Tafel rechts: Region, Chance, Dauer und Lohn, Aufbruch – oder der Stand der laufenden Reise.
void DrawMapPanel(SpriteBatch sb, RegionDef reg, Expedition? away)
{
var r = new RectangleF(Camera.W - 490, 30, 460, 1020);
Ui.Panel(sb, r, D.Gold, 0.93f);
float x = r.X + 24, w = r.Width - 48, y = r.Y + 30;
// Kopf: Titel und Zurück
string title = L.t("exp.map").ToUpperInvariant();
float ts = 34;
while (ts > 18 && D.Measure(Assets.Serif, ts, title).X > w - 150) ts -= 1; // längere Sprachen
D.Text(sb, Assets.Serif, ts, title, new Vector2(x, y + 2), D.Gold);
if (_ui.Button(sb, new RectangleF(r.Right - 24 - 130, y - 18, 130, 44), L.t("exp.close"), size: 18)) _overlay = Overlay.None;
y += 48;
DrawPicture(sb, Picture(reg.Art), new RectangleF(x, y, w, 250));
D.Frame(sb, new RectangleF(x, y, w, 250), D.Border, 2);
y += 278;
D.Text(sb, Assets.Serif, 38, L.t(reg.Key).ToUpperInvariant(), new Vector2(x, y), D.Gold);
y += 44;
if (away != null)
{
double total = Adventures.Durations[away.Duration];
float k = (float)(1 - away.Left / total);
D.Text(sb, Assets.SansBold, 21, string.Format(L.t("exp.away"), L.t(reg.Key)), new Vector2(x, y), D.Sand);
D.Text(sb, Assets.Sans, 19, string.Format(L.t("exp.left"), NumberFormat.Duration(away.Left)), new Vector2(x, y + 32), D.Sand);
D.Bar(sb, new RectangleF(x, y + 62, w, 16), k, k, D.Gold);
y += 110;
if (_ui.Button(sb, new RectangleF(x, y, w, 64), L.t("exp.watch"), selected: true, size: 24, accent: D.Gold))
OpenJourney();
if (_ui.Button(sb, new RectangleF(x, y + 80, w, 52), L.t("exp.recall"), size: 18, accent: D.Red))
{ _game.Recall(); SoundManager.PlayBoo(); }
return;
}
double chance = _game.ExpeditionChance(reg);
D.Text(sb, Assets.SansBold, 20, string.Format(L.t("exp.chance"), NumberFormat.Percent(chance)), new Vector2(x, y), ChanceColor(chance));
D.Bar(sb, new RectangleF(x, y + 28, w, 14), (float)chance, (float)chance, ChanceColor(chance));
y += 66;
for (int d = 0; d < 3; d++)
{
if (_ui.Button(sb, new RectangleF(x, y, w, 56), string.Format(L.t("exp.duration"), DurationLabel(d), LootCount(d)),
selected: _expDuration == d, size: 19))
_expDuration = d;
y += 66;
}
// erwarteter Lohn bei Erfolg (wie GameState.FinishExpedition)
double wins = Adventures.Wins[_expDuration];
double gold = Balance.GoldPerWin(reg.Tier) * _game.GoldMult * wins * 0.9, fame = Balance.FamePerWin(reg.Tier) * _game.FameMult * wins * 0.5,
xp = Balance.CharXpPerWin(reg.Tier) * wins * 0.8;
D.Text(sb, Assets.SansBold, 18, L.t("exp.reward"), new Vector2(x, y + 4), D.Sand);
D.Text(sb, Assets.Sans, 18, $"+{NumberFormat.Format(gold)} {L.t("exp.reward.gold")}", new Vector2(x, y + 32), D.Gold); // i18n-ok
D.Text(sb, Assets.Sans, 18, $"+{NumberFormat.Format(fame)} {L.t("exp.reward.fame")} · +{NumberFormat.Format(xp)} {L.t("exp.reward.xp")}", new Vector2(x, y + 58), D.Gold); // i18n-ok
y += 76;
if (_ui.Button(sb, new RectangleF(x, r.Bottom - 96, w, 70), L.t("exp.start"), _game.RegionOpen(reg) && !_game.FreedomEarned,
selected: true, size: 26, accent: D.Gold))
if (_game.StartExpedition(reg.Id, _expDuration)) SoundManager.PlayStart();
}
}
}