Gladiator Idle (MonoGame) – Spiel mit 3D-Gladiatoren

Nur was zum Bauen und Starten nötig ist: Mono/ (Spiel), Game/, Core/,
Languages/, Assets/ (Bilder, Clips, 3D-Figuren, Ton), build-release.bat.
Bauen: build-release.bat → Spiel\GladiatorIdle.exe

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-08 12:57:20 +01:00
commit a7134b2753
1112 changed files with 10806 additions and 0 deletions

151
Mono/Arena/AbilityBar.cs Normal file
View File

@@ -0,0 +1,151 @@
using System;
using GladiatorIdle.Gfx;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using D = GladiatorIdle.Gfx.Draw;
namespace GladiatorIdle.Arena
{
/// <summary>
/// Fähigkeiten-Leiste unten (Q, W, E): Bronze-Unterlage, Medaillons mit Tasten-Abzeichen,
/// Abklingzeit als Uhrzeiger-Schatten mit Sekunden, Leuchten und Aufblitzen wenn bereit.
/// Nicht gelernte Fähigkeiten sind als dunkle Fassung zu sehen.
/// </summary>
internal sealed class AbilityBar
{
public sealed class Slot
{
public string Key = "", Name = "";
public Texture2D? Icon;
public double Cooldown, Total = 1;
public bool Learned = true, Usable = true;
public Color Glow = D.Gold;
internal float ReadyFlash;
internal bool WasCooling;
}
public readonly Slot[] Slots = { new(), new(), new() };
const float SIZE = 118, GAP = 64;
readonly Texture2D? _bar = Assets.Sprite("hud_bar");
BasicEffect? _flat;
readonly VertexPositionColor[] _fan = new VertexPositionColor[3 * 64];
double _t;
public void Update(float dt)
{
_t += dt;
foreach (var s in Slots)
{
bool cooling = s.Cooldown > 0;
if (s.WasCooling && !cooling) s.ReadyFlash = 1; // gerade bereit geworden
s.WasCooling = cooling;
s.ReadyFlash = MathF.Max(0, s.ReadyFlash - dt * 2.2f);
}
}
Vector2 Badge(int i) => Center(i) + new Vector2(-SIZE * 0.40f, -SIZE * 0.40f);
Vector2 Center(int i) => new(Camera.W / 2 + (i - 1) * (SIZE + GAP), Camera.H - 112);
public void Draw(GraphicsDevice gd, SpriteBatch sb, Matrix ui)
{
_flat ??= new BasicEffect(gd) { VertexColorEnabled = true, TextureEnabled = false, World = Matrix.Identity };
_flat.View = ui;
_flat.Projection = Matrix.CreateOrthographicOffCenter(0, gd.Viewport.Width, gd.Viewport.Height, 0, 0, 1);
// Unterlage und Medaillons
sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, ui);
if (_bar != null)
{
float w = 3 * SIZE + 2 * GAP + 190, h = w * _bar.Height / _bar.Width;
sb.Draw(_bar, new Vector2(Camera.W / 2, Camera.H - 112), null, Color.White * 0.95f, 0,
new Vector2(_bar.Width / 2f, _bar.Height / 2f), w / _bar.Width, SpriteEffects.None, 0);
}
else D.Glow(sb, new Vector2(Camera.W / 2, Camera.H - 112), new Vector2(760, 240), Color.Black * 0.7f);
for (int i = 0; i < 3; i++)
{
var s = Slots[i]; var c = Center(i);
D.Glow(sb, c + new Vector2(0, 8), new Vector2(SIZE * 1.25f), Color.Black * 0.7f); // Schatten
if (s.Icon != null)
{
var tint = !s.Learned ? new Color(40, 34, 28) : s.Cooldown > 0 ? new Color(150, 140, 125) : !s.Usable ? new Color(200, 120, 110) : Color.White;
float pop = 1 + 0.12f * s.ReadyFlash;
sb.Draw(s.Icon, c, null, tint, 0, new Vector2(s.Icon.Width / 2f, s.Icon.Height / 2f), SIZE * pop / s.Icon.Width, SpriteEffects.None, 0);
}
}
sb.End();
// Abklingzeit: dunkler Uhrzeiger-Schatten über dem Rest
gd.BlendState = BlendState.AlphaBlend;
gd.RasterizerState = RasterizerState.CullNone;
for (int i = 0; i < 3; i++)
{
var s = Slots[i];
if (!s.Learned || s.Cooldown <= 0) continue;
Pie(gd, Center(i), SIZE * 0.47f, (float)Math.Clamp(s.Cooldown / s.Total, 0, 1), Color.Black * 0.62f);
}
// Tasten-Abzeichen: Münze mit farbigem Rand
for (int i = 0; i < 3; i++)
{
var s = Slots[i];
var badge = Badge(i);
Pie(gd, badge, 25, 1, Color.Black * 0.8f);
Pie(gd, badge, 21, 1, s.Learned ? s.Glow : D.Border);
Pie(gd, badge, 17.5f, 1, new Color(22, 16, 10));
}
// Leuchten wenn bereit (additiv)
sb.Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.LinearClamp, null, null, null, ui);
for (int i = 0; i < 3; i++)
{
var s = Slots[i]; var c = Center(i);
if (!s.Learned) continue;
if (s.Cooldown <= 0 && s.Usable)
{
float pulse = 0.22f + 0.1f * MathF.Sin((float)_t * 3 + i);
D.Glow(sb, c, new Vector2(SIZE * 1.55f), s.Glow * pulse);
}
if (s.ReadyFlash > 0) D.Glow(sb, c, new Vector2(SIZE * (1.4f + 1.2f * (1 - s.ReadyFlash))), Color.White * (0.8f * s.ReadyFlash));
}
sb.End();
// Tasten-Abzeichen, Sekunden, Namen
sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, ui);
for (int i = 0; i < 3; i++)
{
var s = Slots[i]; var c = Center(i);
var badge = Badge(i);
D.Text(sb, Assets.SansBold, 22, s.Key, badge + new Vector2(0, 1), s.Learned ? Color.White : D.Dim, Align.Center, 1, false);
if (s.Learned && s.Cooldown > 0)
D.Text(sb, Assets.SansBold, 38, Math.Ceiling(s.Cooldown).ToString(NumberFormat.Culture), c, Color.White, Align.Center);
if (s.Learned)
D.Text(sb, Assets.SansBold, 17, s.Name.ToUpperInvariant(), c + new Vector2(0, SIZE * 0.57f),
s.Cooldown <= 0 ? D.Sand : D.Dim, Align.Center);
}
sb.End();
}
/// Kreisausschnitt ab 12 Uhr im Uhrzeigersinn über <paramref name="frac"/> des Kreises.
void Pie(GraphicsDevice gd, Vector2 c, float r, float frac, Color color)
{
const int SEG = 64;
int n = Math.Max(1, (int)MathF.Ceiling(SEG * frac));
float start = -MathF.PI / 2, sweep = MathF.Tau * frac;
int v = 0;
for (int k = 0; k < n; k++)
{
float a0 = start + sweep * k / n, a1 = start + sweep * (k + 1) / n;
_fan[v++] = new VertexPositionColor(new Vector3(c, 0), color);
_fan[v++] = new VertexPositionColor(new Vector3(c + new Vector2(MathF.Cos(a0), MathF.Sin(a0)) * r, 0), color);
_fan[v++] = new VertexPositionColor(new Vector3(c + new Vector2(MathF.Cos(a1), MathF.Sin(a1)) * r, 0), color);
}
foreach (var pass in _flat!.CurrentTechnique.Passes)
{
pass.Apply();
gd.DrawUserPrimitives(PrimitiveType.TriangleList, _fan, 0, n);
}
}
}
}

63
Mono/Arena/Camera.cs Normal file
View File

@@ -0,0 +1,63 @@
using System;
using Microsoft.Xna.Framework;
namespace GladiatorIdle.Arena
{
/// <summary>
/// Kamera der Arena in Design-Pixeln: folgt den Kämpfern, zoomt bei Nähe heran, ruckt bei
/// Treffern (Trauma² als Stärke) und stößt kurz in Richtung des Aufpralls (Punch).
/// </summary>
internal sealed class Camera
{
public const float W = 1920, H = 1080;
public Vector2 Center = new(W / 2, H / 2);
public float Zoom = 1f;
float _trauma, _punch;
Vector2 _punchAt;
double _t;
public void Shake(float amount) => _trauma = MathF.Min(1, _trauma + amount);
/// Nach dem Kampf: langsam auf den Sieger zufahren (null = wieder beide zeigen).
public float? FocusX;
public void Punch(float amount, Vector2 at) { _punch = MathF.Max(_punch, amount); _punchAt = at; }
/// Ziel: Mitte zwischen den Kämpfern, je näher, desto enger.
public void Update(float dt, float x1, float x2, bool calm)
{
_t += dt;
float mid = (x1 + x2) / 2, dist = MathF.Abs(x2 - x1);
float targetZoom = MathHelper.Clamp(1.2f - dist / 3000f, 1.0f, 1.12f);
var target = new Vector2(MathHelper.Clamp(mid, W / 2 - 220, W / 2 + 220), H / 2 + 40);
float k = 1 - MathF.Exp(-dt * 3.5f);
if (FocusX is float fx) { targetZoom = 1.4f; target = new Vector2(fx, H / 2 + 30); k = 1 - MathF.Exp(-dt * 1.2f); }
Center += (target - Center) * k;
Zoom += (targetZoom - Zoom) * k;
_trauma = MathF.Max(0, _trauma - dt * 1.7f);
_punch *= MathF.Exp(-dt * 9f);
if (calm) { _trauma = 0; _punch = 0; }
}
/// Kameraverschiebung durch Rütteln (Design-Pixel).
Vector2 ShakeOffset()
{
float s = _trauma * _trauma * 26;
return new Vector2(
s * (MathF.Sin((float)_t * 71) + 0.6f * MathF.Sin((float)_t * 133 + 1.3f)) / 1.6f,
s * (MathF.Cos((float)_t * 89) + 0.6f * MathF.Sin((float)_t * 151 + 0.7f)) / 1.6f);
}
/// Design-Pixel → Bildschirm. <paramref name="parallax"/>: 1 = Ebene der Kämpfer, &lt;1 weiter hinten.
public Matrix View(float screenScale, Vector2 offset, float parallax = 1f)
{
float zoom = 1 + (Zoom - 1) * parallax + _punch * parallax;
var c = new Vector2(W / 2, H / 2) + (Center - new Vector2(W / 2, H / 2)) * parallax
+ (_punchAt - Center) * _punch * 0.6f * parallax;
var shake = ShakeOffset() * parallax;
return Matrix.CreateTranslation(-c.X, -c.Y, 0) * Matrix.CreateScale(zoom)
* Matrix.CreateTranslation(W / 2 + shake.X, H / 2 + shake.Y, 0)
* Matrix.CreateScale(screenScale) * Matrix.CreateTranslation(offset.X, offset.Y, 0);
}
}
}

308
Mono/Arena/CreatorScene.cs Normal file
View File

@@ -0,0 +1,308 @@
using System;
using System.Collections.Generic;
using System.Linq;
using GladiatorIdle.Gfx;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using D = GladiatorIdle.Gfx.Draw;
namespace GladiatorIdle.Arena
{
/// <summary>
/// Eigenen Gladiator zusammenstellen: Klasse, Vorlage, Teamfarbe, Wappen, Startpunkte,
/// Startfähigkeit und Name. Links eine große Vorschau, die ab und zu zuschlägt, blockt und jubelt.
/// </summary>
internal sealed class CreatorScene
{
public GladiatorClass Class { get; private set; } = GladiatorClass.Murmillo;
public int Preset { get; private set; } = 1;
public int Tint { get; private set; }
public int Emblem { get; private set; }
public int[] Bonus { get; } = new int[4];
public string? StartSkill { get; private set; }
public string Name { get; private set; }
public bool Done { get; private set; }
readonly Ui _ui = new();
readonly Particles _fx = new();
readonly Texture2D? _backdrop = Assets.Sprite("arena_ludus", "jpg");
FighterView _preview = null!;
readonly DuelFighter _dummy = new() { IsPlayer = true, X = 0, Facing = 1, MaxHp = 1, Hp = 1 };
double _t, _showAt = 2.5;
int _show;
string? _hoverSkill;
public Appearance Look => new(Preset, Tint, Emblem);
int Left => GameState.CREATE_POINTS - Bonus.Sum();
public CreatorScene(string name)
{
Name = name;
SetClass(Class);
SoundManager.StartAmbient("music_menu");
}
void SetClass(GladiatorClass c)
{
Class = c;
if (StartSkill == null || !GameState.StartSkills(c).Any(s => s.Id == StartSkill))
StartSkill = GameState.StartSkills(c).First().Id;
Rebuild();
}
void Rebuild() => _preview = new FighterView(Art.Hero(Class, Preset), 0, Tint);
/// Getippte Zeichen (vom Fenster) für den Namen.
public void OnText(char c, Keys key)
{
if (key == Keys.Back) { if (Name.Length > 0) Name = Name[..^1]; return; }
if (key == Keys.Enter) return;
if (!char.IsControl(c) && Name.Length < 18) Name += c;
}
// ── Takt ────────────────────────────────────────────────────
public void Update(float dt, Input input, Matrix ui)
{
_t += dt;
_ui.Begin(input, ui);
ShowcaseStep(dt);
_preview.Update(dt, dt, _dummy, 0, AppSettings.ReduceMotion);
_fx.Motes(AppSettings.ReduceMotion ? 0 : 50, Camera.W, Camera.H);
_fx.Update(dt);
}
/// Vorschau: meist ruhig, dazwischen Schlag, Block oder Siegerpose.
void ShowcaseStep(float dt)
{
_dummy.StateTime += dt;
if (_dummy.State == DuelState.Ready && _t >= _showAt)
{
_show++;
_dummy.Set(_show % 3 == 0 ? DuelState.Victory : _show % 3 == 1 ? DuelState.Windup : DuelState.Block);
}
switch (_dummy.State)
{
case DuelState.Windup when _dummy.StateTime > 0.35: _dummy.Set(DuelState.Strike); break;
case DuelState.Strike when _dummy.StateTime > 0.15: _dummy.Set(DuelState.Recover); break;
case DuelState.Recover when _dummy.StateTime > 0.5:
case DuelState.Block when _dummy.StateTime > 1.2:
case DuelState.Victory when _dummy.StateTime > 1.6:
_dummy.Set(DuelState.Ready); _showAt = _t + 2.8; break;
}
}
// ── Zeichnen ────────────────────────────────────────────────
public void Draw(GraphicsDevice gd, SpriteBatch sb, BasicEffect fx, float scale, Vector2 offset)
{
D.UiScale = scale;
var ui = Matrix.CreateScale(scale) * Matrix.CreateTranslation(offset.X, offset.Y, 0);
sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, ui);
if (_backdrop != null)
{
float k = 1.1f * MathF.Max(Camera.W / _backdrop.Width, Camera.H / _backdrop.Height);
sb.Draw(_backdrop, new Vector2(Camera.W / 2, Camera.H / 2), null, new Color(0.42f, 0.38f, 0.34f), 0,
new Vector2(_backdrop.Width / 2f, _backdrop.Height / 2f), k, SpriteEffects.None, 0);
}
D.Glow(sb, new Vector2(-200, Camera.H / 2), new Vector2(900, 2000), Color.Black * 0.7f);
D.Glow(sb, new Vector2(Camera.W + 200, Camera.H / 2), new Vector2(900, 2000), Color.Black * 0.7f);
D.Text(sb, Assets.Serif, 56, L.t("create.title").ToUpperInvariant(), new Vector2(110, 78), D.Gold);
sb.End();
// Vorschau: eigene Kamera (größer), Lichtkegel, Schatten, Figur
var view = Matrix.CreateTranslation(0, -Stage.FloorY, 0) * Matrix.CreateScale(1.25f) * Matrix.CreateTranslation(470, 905, 0) * ui;
sb.Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.LinearClamp, null, null, null, view);
D.Glow(sb, new Vector2(0, Stage.FloorY - 300), new Vector2(900, 1100), new Color(255, 190, 120) * 0.16f);
D.Glow(sb, new Vector2(0, Stage.FloorY + 6), new Vector2(700, 120), new Color(255, 180, 110) * 0.25f);
sb.End();
sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, view);
_preview.DrawShadow(sb);
sb.End();
fx.View = view;
fx.Projection = Matrix.CreateOrthographicOffCenter(0, gd.Viewport.Width, gd.Viewport.Height, 0, 0, 1);
gd.BlendState = BlendState.AlphaBlend; gd.SamplerStates[0] = SamplerState.LinearClamp;
gd.RasterizerState = RasterizerState.CullNone; gd.DepthStencilState = DepthStencilState.None;
_preview.DrawBody(gd, fx, _dummy, AppSettings.ReduceMotion);
sb.Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.LinearClamp, null, null, null, ui);
_fx.DrawAdd(sb);
sb.End();
sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, ui);
DrawNameField(sb);
DrawOptions(sb);
sb.End();
}
void DrawNameField(SpriteBatch sb)
{
var r = new RectangleF(170, 968, 600, 68);
D.Text(sb, Assets.SansBold, 20, L.t("create.name"), new Vector2(r.X, r.Y - 22), D.Sand);
Ui.Panel(sb, r, D.Gold);
// Wappen vor dem Namen
if (Assets.Sprite(Look.EmblemArt) is Texture2D em)
sb.Draw(em, new Vector2(r.X + 36, r.Center.Y), null, Color.White, 0, new Vector2(em.Width / 2f, em.Height / 2f), 54f / em.Width, SpriteEffects.None, 0);
bool caret = _t % 1 < 0.55;
D.Text(sb, Assets.Serif, 34, Name + (caret ? "|" : " "), new Vector2(r.X + 76, r.Center.Y), Color.White); // i18n-ok
}
static void Header(SpriteBatch sb, string text, float y, float x = 930) =>
D.Text(sb, Assets.Serif, 26, text, new Vector2(x, y), D.Gold);
void DrawOptions(SpriteBatch sb)
{
Ui.Panel(sb, new RectangleF(900, 40, 940, 900), null, 0.78f);
float x0 = 930;
// Klasse
Header(sb, L.t("create.class"), 76);
for (int i = 0; i < 4; i++)
{
var c = (GladiatorClass)i;
if (_ui.Button(sb, new RectangleF(x0 + i * 222, 100, 210, 58), L.t(ClassDef.Of(c).Key), selected: Class == c, size: 22))
SetClass(c);
}
// Aussehen: drei Vorlagen in der gewählten Farbe
Header(sb, L.t("create.look"), 192);
for (int p = 1; p <= Appearance.PRESETS; p++)
{
var r = new RectangleF(x0 + (p - 1) * 160, 214, 148, 170);
bool sel = Preset == p, hover = _ui.Hover(r);
D.Rect(sb, r, new Color(30, 22, 15) * 0.9f);
if (Assets.Sprite(Art.Hero(Class, p)) is Texture2D t)
{
var painted = Assets.Paint(t, Tint);
float k = r.Height * 1.02f / t.Height;
sb.Draw(painted, new Vector2(r.Center.X, r.Bottom - 2), null, Color.White, 0,
new Vector2(t.Width / 2f, Stage.Feet), k, SpriteEffects.None, 0);
}
D.Frame(sb, r, sel ? D.Gold : hover ? D.Sand : D.Border, sel ? 3 : 2);
if (_ui.Hit(r)) { Preset = p; Rebuild(); }
}
// Klassenbeschreibung neben den Vorlagen
float dy = DrawWrapped(sb, L.t(ClassDef.Of(Class).Key + ".desc"), new RectangleF(x0 + 490, 226, 400, 120), 19, Align.Left);
D.Text(sb, Assets.SansBold, 19, string.Format(L.t("select.special"), L.t(TextKeys.Of(ClassDef.Of(Class).Special))),
new Vector2(x0 + 490, dy + 18), D.Blue);
// Farbe
Header(sb, L.t("create.color"), 418);
for (int i = 0; i < Appearance.Colors.Length; i++)
{
var tc = Appearance.Colors[i];
var center = new Vector2(x0 + 30 + i * 74, 468);
var r = new RectangleF(center.X - 30, center.Y - 30, 60, 60);
bool sel = Tint == i, hover = _ui.Hover(r);
var (cr, cg, cb) = Rgb(tc);
Disc(sb, center, sel ? 64 : 56, sel ? D.Gold : hover ? D.Sand : D.Border);
Disc(sb, center, sel ? 54 : 48, new Color(cr, cg, cb));
if (_ui.Hit(r)) { Tint = i; Rebuild(); }
}
// Wappen
Header(sb, L.t("create.emblem"), 530);
for (int i = 0; i < Appearance.Emblems.Length; i++)
{
var center = new Vector2(x0 + 36 + i * 74, 590);
var r = new RectangleF(center.X - 34, center.Y - 34, 68, 68);
bool sel = Emblem == i, hover = _ui.Hover(r);
if (sel) D.Glow(sb, center, new Vector2(110), D.Gold * 0.5f);
if (Assets.Sprite("emblem_" + Appearance.Emblems[i]) is Texture2D em)
sb.Draw(em, center, null, sel || hover ? Color.White : new Color(160, 150, 140), 0,
new Vector2(em.Width / 2f, em.Height / 2f), (sel ? 70f : 62f) / em.Width, SpriteEffects.None, 0);
else Disc(sb, center, 56, sel ? D.Gold : D.Border); // Bild fehlt noch
if (_ui.Hit(r)) Emblem = i;
}
if (Emblem >= 0) D.Text(sb, Assets.Sans, 18, L.t(Look.EmblemKey), new Vector2(x0 + 600, 530), D.Sand, Align.Right);
// Startpunkte
Header(sb, string.Format(L.t("create.points"), Left), 662);
var start = ClassDef.Of(Class).StartLevels;
for (int s = 0; s < 4; s++)
{
float y = 700 + s * 46;
D.Text(sb, Assets.Sans, 21, L.t(TextKeys.Of((Stat)s)), new Vector2(x0, y), D.Sand);
D.Text(sb, Assets.SansBold, 24, (start[s] + Bonus[s]).ToString(NumberFormat.Culture), new Vector2(x0 + 260, y),
Bonus[s] > 0 ? D.Gold : Color.White, Align.Right);
int ss = s;
if (_ui.Button(sb, new RectangleF(x0 + 290, y - 18, 44, 36), "−", Bonus[s] > 0, size: 22)) Bonus[ss]--; // i18n-ok
if (_ui.Button(sb, new RectangleF(x0 + 342, y - 18, 44, 36), "+", Left > 0, size: 22)) Bonus[ss]++; // i18n-ok
}
// Startfähigkeit
Header(sb, L.t("create.skill"), 662, x0 + 450);
_hoverSkill = null;
var skills = GameState.StartSkills(Class).ToList();
for (int i = 0; i < skills.Count; i++)
{
var sk = skills[i];
var center = new Vector2(x0 + 520 + i * 120, 730);
var r = new RectangleF(center.X - 46, center.Y - 46, 92, 92);
bool sel = StartSkill == sk.Id, hover = _ui.Hover(r);
if (hover) _hoverSkill = sk.Id;
if (sel) D.Glow(sb, center, new Vector2(150), D.Gold * 0.55f);
if (Assets.Sprite(sk.Icon) is Texture2D icon)
sb.Draw(icon, center, null, sel || hover ? Color.White : new Color(150, 140, 125), 0,
new Vector2(icon.Width / 2f, icon.Height / 2f), (sel ? 92f : 82f) / icon.Width, SpriteEffects.None, 0);
if (_ui.Hit(r)) StartSkill = sk.Id;
}
string shown = _hoverSkill ?? StartSkill ?? skills[0].Id;
var def = SkillDef.Get(shown);
D.Text(sb, Assets.SansBold, 21, L.t(def.Key), new Vector2(x0 + 640, 806), D.Gold, Align.Center);
DrawWrapped(sb, L.t(def.Desc), new RectangleF(x0 + 450, 826, 380, 90), 17);
// Los
if (_ui.Button(sb, new RectangleF(1420, 962, 420, 80), L.t("create.start"), Name.Trim().Length > 0, size: 32))
Done = true;
}
void Disc(SpriteBatch sb, Vector2 c, float size, Color color) =>
sb.Draw(Assets.Disc, c, null, color, 0, new Vector2(64), size / 128f, SpriteEffects.None, 0);
/// Einfacher Zeilenumbruch nach Wörtern.
/// Liefert die y-Position unter der letzten Zeile.
static float DrawWrapped(SpriteBatch sb, string text, RectangleF r, float px, Align align = Align.Center)
{
float x = align == Align.Left ? r.X : r.Center.X;
var words = text.Split(' ');
string line = "";
float y = r.Y + px * 0.7f;
foreach (var w in words)
{
string test = line.Length == 0 ? w : line + " " + w;
if (D.Measure(Assets.Sans, px, test).X > r.Width && line.Length > 0)
{
D.Text(sb, Assets.Sans, px, line, new Vector2(x, y), D.Sand, align);
y += px * 1.35f; line = w;
}
else line = test;
}
if (line.Length > 0) D.Text(sb, Assets.Sans, px, line, new Vector2(x, y), D.Sand, align);
return y + px * 0.7f;
}
/// Anzeigefarbe einer Teamfarbe (wie ein kräftiges Magenta nach dem Umfärben).
static (float, float, float) Rgb(TeamColor c)
{
float s = MathHelper.Clamp(0.85f * c.Sat, 0, 1), v = MathHelper.Clamp(0.85f * c.Val, 0, 1);
float h = c.Hue, ch = v * s, x = ch * (1 - MathF.Abs(h / 60 % 2 - 1)), m = v - ch;
var (r, g, b) = h < 60 ? (ch, x, 0f) : h < 120 ? (x, ch, 0f) : h < 180 ? (0f, ch, x) : h < 240 ? (0f, x, ch) : h < 300 ? (x, 0f, ch) : (ch, 0f, x);
return (r + m, g + m, b + m);
}
// ── Testläufe ───────────────────────────────────────────────
/// Testlauf: eine bestimmte Zusammenstellung wählen.
public void DevPick(GladiatorClass c, int preset, int color, int emblem)
{
SetClass(c); Preset = preset; Tint = color; Emblem = emblem;
Bonus[0] = 2; Bonus[2] = 3;
StartSkill = GameState.StartSkills(c).Last().Id;
Rebuild();
}
public void Finish() => Done = true;
}
}

157
Mono/Arena/Crowd.cs Normal file
View File

@@ -0,0 +1,157 @@
using System;
using System.Collections.Generic;
using GladiatorIdle.Gfx;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace GladiatorIdle.Arena
{
/// <summary>
/// Publikum im Vordergrund: zwei Reihen dunkler Zuschauer am unteren Rand (Gegenlicht). Jeder
/// lebt für sich — atmet, wippt, dreht sich, jubelt mal spontan. Mit der Stimmung springen sie,
/// recken die Fäuste (Wechsel ruhig/jubelnd im eigenen Takt) und schwanken; bei großen Momenten
/// läuft eine Welle (La Ola) durch die Reihen und Blütenblätter fliegen in die Arena.
/// Liegt vor der Kampfebene (Parallaxe &gt; 1).
/// </summary>
internal sealed class Crowd
{
sealed class Fan
{
public Texture2D Calm = null!;
public Texture2D? Cheer;
public float X, H, Threshold, Phase, Shade, Pump, Temper;
public bool Mirror, Cheering;
public float Y, Vy, Tilt, Solo; // Sprunghöhe, Tempo nach oben, Neigung, spontaner Jubel (s)
}
sealed class Petal { public Vector2 Pos, Vel; public float Spin, Angle, Life, Size; public Color Color; }
readonly List<Fan> _fans = new();
readonly List<Petal> _petals = new();
readonly Random _rng;
float _excite;
double _t;
float _wave = -1; // Fortschritt der Welle (−1: keine)
public float Excitement => _excite;
public Crowd(int seed)
{
_rng = new Random(seed);
var kinds = new List<(Texture2D, Texture2D?)>();
for (int i = 1; i <= 6; i++)
if (Assets.Sprite($"spectator_{i}") is Texture2D calm)
kinds.Add((calm, Assets.Sprite($"spectator_{i}_cheer")));
if (kinds.Count == 0) return;
// zwei Reihen: hinten kleiner und heller, vorne größer und dunkler
for (int row = 0; row < 2; row++)
for (float x = -260 + _rng.Next(80); x < Camera.W + 260; x += row == 0 ? 95 : 130)
{
var (calm, cheer) = kinds[_rng.Next(kinds.Count)];
_fans.Add(new Fan
{
Calm = calm, Cheer = cheer, X = x + _rng.Next(-30, 30), H = row == 0 ? 230 : 300,
Threshold = 0.12f + (float)_rng.NextDouble() * 0.7f, Phase = (float)_rng.NextDouble() * 6.28f,
Shade = row == 0 ? 0.13f : 0.07f, Mirror = _rng.Next(2) == 0,
Pump = 2.2f + (float)_rng.NextDouble() * 2.4f, // Fäuste recken: eigener Takt
Temper = 0.6f + (float)_rng.NextDouble() * 0.8f // wie wild gesprungen wird
});
}
}
/// Stimmung steigern (0..1).
public void Excite(float amount) => _excite = MathF.Min(1, _excite + amount);
/// La-Ola-Welle durch beide Reihen und Blütenblätter (Raserei, Sieg).
public void Wave(bool petals = true)
{
_wave = 0;
Excite(1);
if (!petals) return;
for (int i = 0; i < 70; i++)
{
var f = _fans.Count > 0 ? _fans[_rng.Next(_fans.Count)] : null;
float x = f?.X ?? (float)_rng.NextDouble() * Camera.W;
_petals.Add(new Petal
{
Pos = new Vector2(x, Camera.H + 40), Vel = new Vector2(((float)_rng.NextDouble() - 0.5f) * 500, -700 - (float)_rng.NextDouble() * 650),
Spin = ((float)_rng.NextDouble() - 0.5f) * 14, Life = 2.6f + (float)_rng.NextDouble() * 1.4f,
Size = 9 + (float)_rng.NextDouble() * 9,
Color = _rng.Next(3) switch { 0 => new Color(220, 40, 50), 1 => new Color(255, 235, 220), _ => new Color(240, 170, 40) }
});
}
}
public void Update(float dt)
{
_t += dt;
_excite = MathF.Max(0.05f, _excite - dt * 0.18f);
float waveX = _wave < 0 ? -9999 : -300 + _wave * 2200;
if (_wave >= 0 && (_wave += dt) > 1.4f) _wave = -1;
foreach (var f in _fans)
{
// spontaner Jubel einzelner, auch wenn es ruhig ist
if (f.Solo > 0) f.Solo -= dt;
else if (_rng.NextDouble() < dt * 0.035) f.Solo = 0.8f + (float)_rng.NextDouble() * 1.2f;
bool inWave = MathF.Abs(f.X - waveX) < 170;
f.Cheering = inWave || f.Solo > 0 || (f.Cheering ? _excite > f.Threshold - 0.08f : _excite > f.Threshold);
// Sprünge mit Schwerkraft: jubelnd öfter und höher
f.Vy -= 1900 * dt;
f.Y = MathF.Max(0, f.Y + f.Vy * dt);
if (f.Y <= 0)
{
f.Vy = 0;
float chance = inWave ? 1 : f.Cheering ? 2.2f * f.Temper * dt : 0;
if (_rng.NextDouble() < chance)
f.Vy = (inWave ? 520 : 260 + 260 * _excite) * (0.7f + 0.5f * (float)_rng.NextDouble());
}
float tiltTarget = f.Cheering ? MathF.Sin((float)_t * 3.1f + f.Phase) * 0.09f * f.Temper
: MathF.Sin((float)_t * 0.7f + f.Phase) * 0.025f;
f.Tilt += (tiltTarget - f.Tilt) * MathF.Min(1, dt * 6);
}
for (int i = _petals.Count - 1; i >= 0; i--)
{
var p = _petals[i];
p.Vel.Y += 520 * dt;
p.Vel *= MathF.Exp(-dt * 0.9f);
p.Vel.X += MathF.Sin((float)_t * 2 + i) * 40 * dt; // flattern
p.Pos += p.Vel * dt;
p.Angle += p.Spin * dt;
if ((p.Life -= dt) <= 0) _petals.RemoveAt(i);
}
}
/// Zeichnen in der Vordergrund-Ebene (eigene Kamera-Matrix mit Parallaxe).
public void Draw(SpriteBatch sb, bool calm)
{
foreach (var f in _fans)
{
// jubelnd: Fäuste im eigenen Takt hoch und runter (Wechsel der Bilder)
bool armsUp = f.Cheering && f.Cheer != null && (calm || MathF.Sin((float)_t * f.Pump + f.Phase) > -0.35f);
var tex = armsUp ? f.Cheer! : f.Calm;
float breathe = 1 + MathF.Sin((float)_t * 1.3f + f.Phase) * 0.012f;
float bob = calm ? 0 : f.Cheering
? f.Y + MathF.Abs(MathF.Sin((float)_t * 7.5f + f.Phase)) * 10
: MathF.Sin((float)_t * 1.6f + f.Phase) * 3 + _excite * MathF.Abs(MathF.Sin((float)_t * 5 + f.Phase)) * 8;
// in der Luft gestreckt, bei der Landung gestaucht
float stretch = calm ? 1 : 1 + Math.Clamp(f.Vy / 4000f, -0.06f, 0.08f);
float scale = f.H / tex.Height;
float bottom = f.H > 260 ? Camera.H + 175 : Camera.H + 70;
var pos = new Vector2(f.X, bottom - bob);
var c = new Color(f.Shade * 1.1f, f.Shade * 0.9f, f.Shade * 0.75f);
sb.Draw(tex, pos, null, c, calm ? 0 : f.Tilt, new Vector2(tex.Width / 2f, tex.Height),
new Vector2(scale / MathF.Sqrt(stretch), scale * stretch * breathe),
f.Mirror ? SpriteEffects.FlipHorizontally : SpriteEffects.None, 0);
}
if (calm) return;
foreach (var p in _petals)
{
float a = MathF.Min(1, p.Life * 1.5f);
float flip = MathF.Abs(MathF.Cos(p.Angle * 1.7f)); // dreht sich in der Luft
sb.Draw(Assets.Disc, p.Pos, null, p.Color * a, p.Angle, new Vector2(64), new Vector2(p.Size / 128f, p.Size * (0.35f + 0.65f * flip) / 128f / 1.6f),
SpriteEffects.None, 0);
}
}
}
}

570
Mono/Arena/DuelScene.cs Normal file
View File

@@ -0,0 +1,570 @@
using System;
using System.Collections.Generic;
using GladiatorIdle.Gfx;
using D = GladiatorIdle.Gfx.Draw;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace GladiatorIdle.Arena
{
/// Eingaben eines Bilds (vom Spiel gesammelt).
internal sealed class Input
{
public KeyboardState Keys, PrevKeys;
public MouseState Mouse, PrevMouse;
public bool Down(params Keys[] ks) { foreach (var k in ks) if (Keys.IsKeyDown(k)) return true; return false; }
public bool Pressed(Keys k) => Keys.IsKeyDown(k) && !PrevKeys.IsKeyDown(k);
public bool LeftClick => Mouse.LeftButton == ButtonState.Pressed && PrevMouse.LeftButton == ButtonState.Released;
public bool RightHeld => Mouse.RightButton == ButtonState.Pressed;
}
/// <summary>
/// Ein Echtzeit-Duell in der Arena: Logik aus <see cref="Duel"/>, Darstellung mit Kamera,
/// Trefferstopp, Zeitlupe, Partikeln, Publikum und knappem HUD.
/// </summary>
internal sealed class DuelScene
{
enum Phase { Countdown, Fight, End }
const float COUNTDOWN = 2.2f, SPREAD = 1.3f;
readonly GameState _game;
readonly Enemy _enemy;
public Duel Duel { get; }
readonly FighterView _pv, _ev;
readonly Camera _cam = new();
readonly Particles _fx = new();
readonly Crowd _crowd;
readonly Texture2D? _backdrop;
readonly string? _loopName;
readonly bool _calm = AppSettings.ReduceMotion;
readonly AbilityBar _bar = new();
/// Medaillon des Spezialschlags der Klasse.
static string SpecialIcon(Special s) => s switch
{
Special.ShieldBash => "skill_shieldbash2", Special.Net => "skill_widenet",
Special.Sica => "skill_sicawhirl", _ => "skill_endure2"
};
Phase _phase = Phase.Countdown;
float _phaseTime, _hitstop, _slowmo, _screenFlash;
float _furyDark, _emberIn; // Raserei: Abdunkeln der Arena, Takt der Funken
Color _flashColor = Color.White;
float _pLag = 1, _eLag = 1;
double _time;
int _countShown = -1;
public bool Paused;
public bool Won { get; private set; }
public bool Finished => _phase == Phase.End && _phaseTime > 1.2f;
public bool Over => _phase == Phase.End;
sealed class Floater { public string Text = ""; public Vector2 Pos; public Color Color; public float Size, Age, Life = 1.1f; public bool Big; }
readonly List<Floater> _floaters = new();
/// Testlauf: Bot steuert den Spieler.
public DuelBot? Bot;
public DuelScene(GameState game, Enemy enemy, int seed)
{
_game = game;
_enemy = enemy;
var pc = game.PlayerCombat();
Duel = new Duel(pc.MaxHp, pc.Crit, game.ClassDef.Special, enemy.Hp, game.DuelRatio(enemy), enemy.IsChampion,
game.Equipped[(int)ItemSlot.Weapon]?.Base == "trident", new Random(seed), game.Perks);
// eigener Gladiator: Vorlage in Teamfarbe (sonst das Klassenbild)
string hero = Art.Hero(game.Class, game.Look.Preset);
_pv = Assets.Has(hero) ? new FighterView(hero, 0, game.Look.Color) : new FighterView(Art.Fighter(game.Class), 0, -1, game.Look.Color);
_pv.Preload();
// 3D: Gegner vorerst mit derselben Figur in einer anderen Teamfarbe (Rot, oder Schwarz gegen Rot)
_ev = new FighterView(enemy.Art ?? Art.Enemy(enemy.NameKey), 1.7f, -1, game.Look.Color == 0 ? 6 : 0);
_crowd = new Crowd(seed);
_fx.Calm = _calm;
string arena = Art.Arena(ArenaDef.All[game.Arena]);
_backdrop = Assets.Sprite(arena, "jpg");
_loopName = _calm ? null : arena;
_cam.Center = new Vector2(Camera.W / 2, Camera.H / 2 + 40);
_cam.Zoom = 1.45f; // Auftakt: nah, dann fährt die Kamera auf
_crowd.Excite(0.5f);
var sl = _bar.Slots;
sl[0].Key = "Q"; sl[0].Name = L.t(TextKeys.Of(Duel.PlayerSpecial)); sl[0].Icon = Assets.Sprite(SpecialIcon(Duel.PlayerSpecial)); sl[0].Glow = D.Blue; // i18n-ok
sl[1].Key = "W"; sl[1].Name = L.t("skill.heavystrike"); sl[1].Icon = Assets.Sprite("skill_heavystrike"); sl[1].Glow = new Color(255, 150, 40); // i18n-ok
sl[2].Key = "E"; sl[2].Name = L.t("skill.shieldwall"); sl[2].Icon = Assets.Sprite("skill_shieldwall"); sl[2].Glow = D.Blue; // i18n-ok
sl[1].Learned = Duel.Perks.HeavyStrike;
sl[2].Learned = Duel.Perks.ShieldWall;
SoundManager.StartAmbient(enemy.IsChampion ? "music_champion" : "music_arena");
}
// ── Takt ────────────────────────────────────────────────────
public void Update(float realDt, Input input)
{
if (Paused) return;
_time += realDt;
// Trefferstopp friert die Kämpfer kurz ein, Zeitlupe verlangsamt das Ende
float dt = realDt;
if (_hitstop > 0) { _hitstop -= realDt; dt = 0; }
if (_slowmo > 0) { _slowmo -= realDt; dt *= 0.28f; }
_phaseTime += realDt;
switch (_phase)
{
case Phase.Countdown:
int n = 3 - (int)(_phaseTime / (COUNTDOWN / 3));
if (n != _countShown) { _countShown = n; if (n >= 1) SoundManager.PlayTick(); }
if (_phaseTime >= COUNTDOWN)
{
_phase = Phase.Fight; _phaseTime = 0;
SoundManager.PlayGong(); _cam.Shake(0.4f); _crowd.Excite(0.6f);
Big(L.t("duel.fight"), D.Gold);
}
break;
case Phase.Fight:
if (Bot != null) Bot.Act(Duel);
else Controls(input);
Duel.Step(dt);
HandleEvents();
if (Duel.Over)
{
_phase = Phase.End; _phaseTime = 0; Won = Duel.PlayerWon;
_cam.FocusX = Won ? _pv.X : _ev.X;
if (Won) SoundManager.PlayVictory(); else SoundManager.PlayDefeat();
}
break;
case Phase.End:
Duel.Step(dt);
HandleEvents();
break;
}
// Anzeige: Abstand um ein Viertel gespreizt (die Figuren sind breiter als ihre Trefferzone)
float mid = (float)(Duel.Player.X + Duel.Enemy.X) / 2;
float Spread(double x) => mid + ((float)x - mid) * SPREAD;
if (_pv.Update(dt, realDt, Duel.Player, Spread(Duel.Player.X), _calm)) _fx.Dust(new Vector2(_pv.X, Stage.FloorY), 2, 30, 30, 40);
if (_ev.Update(dt, realDt, Duel.Enemy, Spread(Duel.Enemy.X), _calm)) _fx.Dust(new Vector2(_ev.X, Stage.FloorY), 2, 30, 30, 40);
FuryUpdate(realDt);
_cam.Update(realDt, _pv.X, _ev.X, _calm);
_fx.Motes(_calm ? 0 : 60, Camera.W, Camera.H);
_fx.Update(dt > 0 ? dt : realDt * 0.15f);
_crowd.Update(realDt);
var p = Duel.Player; var sl = _bar.Slots;
sl[0].Cooldown = p.SpecialCooldown; sl[0].Total = Duel.SpecialCooldownTotal;
sl[1].Cooldown = p.HeavyCd; sl[1].Total = Duel.HEAVY_COOLDOWN; sl[1].Usable = p.Stamina >= Duel.HEAVY_COST;
sl[2].Cooldown = p.WallCd; sl[2].Total = Duel.WALL_COOLDOWN;
_bar.Update(realDt);
_screenFlash = MathF.Max(0, _screenFlash - realDt * 4);
_pLag = Lag(_pLag, (float)(Duel.Player.Hp / Duel.Player.MaxHp), realDt);
_eLag = Lag(_eLag, (float)(Duel.Enemy.Hp / Duel.Enemy.MaxHp), realDt);
for (int i = _floaters.Count - 1; i >= 0; i--)
if ((_floaters[i].Age += realDt) >= _floaters[i].Life) _floaters.RemoveAt(i);
}
/// Raserei: Kamera fährt heran, Arena wird dunkel, Funken wirbeln erst zur Brust (Aufladen)
/// und steigen dann als Glut auf; bei voller Wut glimmt der Gladiator.
void FuryUpdate(float realDt)
{
var pl = Duel.Player;
bool fury = pl.State == DuelState.Super;
_furyDark += ((fury ? 1f : 0f) - _furyDark) * (1 - MathF.Exp(-realDt * (fury ? 7 : 2.5f)));
if (fury && _phase == Phase.Fight) _cam.FocusX = (_pv.X + _ev.X) / 2;
else if (_phase == Phase.Fight && _cam.FocusX != null) _cam.FocusX = null;
if (_calm || !(fury || pl.Rage >= 100)) return;
if ((_emberIn -= realDt) > 0) return;
var rnd = Random.Shared;
var chest = _pv.Chest;
float r = Stage.FigH;
if (!fury)
{
_emberIn = 0.09f; // volle Wut: leises Glimmen
_fx.Sparks(chest + new Vector2((float)(rnd.NextDouble() - 0.5) * r * 0.5f, (float)rnd.NextDouble() * r * 0.4f), 1,
new Color(255, 140, 40), -MathF.PI / 2, 0.4f, 220);
return;
}
_emberIn = 0.016f;
if (pl.StateTime < Duel.SUPER_CHARGE)
{
// Aufladen: Funken strömen von allen Seiten zur Brust
for (int i = 0; i < 3; i++)
{
float a = (float)(rnd.NextDouble() * MathF.Tau);
var from = chest + new Vector2(MathF.Cos(a), MathF.Sin(a)) * r * (0.7f + (float)rnd.NextDouble() * 0.5f);
_fx.Sparks(from, 1, rnd.Next(2) == 0 ? new Color(255, 170, 50) : new Color(255, 80, 30), a + MathF.PI, 0.15f, 700);
}
if (rnd.NextDouble() < 0.3) _fx.Dust(new Vector2(_pv.X, Stage.FloorY), 2, 160, 40, 70);
}
else
{
// Hiebe: Glut steigt auf, Feuer am Boden
_fx.Sparks(chest + new Vector2((float)(rnd.NextDouble() - 0.5) * r * 0.6f, (float)(rnd.NextDouble() - 0.2) * r * 0.6f), 2,
rnd.Next(3) == 0 ? new Color(255, 230, 120) : new Color(255, 110, 30), -MathF.PI / 2, 0.6f, 380);
}
}
static float Lag(float lag, float value, float dt) => lag <= value ? value : MathF.Max(value, lag - dt * 0.6f);
void Controls(Input i)
{
Duel.MoveDir = (i.Down(Keys.D, Keys.Right) ? 1 : 0) - (i.Down(Keys.A, Keys.Left) ? 1 : 0);
Duel.BlockHeld = i.RightHeld || i.Down(Keys.K, Keys.LeftShift);
if (i.LeftClick || i.Pressed(Keys.J)) Duel.PressAttack();
if (i.Pressed(Keys.Space)) Duel.PressLeap();
if (i.Pressed(Keys.S) || i.Pressed(Keys.Down)) Duel.PressDodge();
if (i.Pressed(Keys.R)) Duel.PressSuper();
if (i.Pressed(Keys.Q)) Duel.PressSpecial();
if (i.Pressed(Keys.W)) Duel.PressHeavy();
if (i.Pressed(Keys.E)) Duel.PressWall();
}
void HandleEvents()
{
foreach (var e in Duel.Events)
{
var targetView = e.ByPlayer ? _ev : _pv;
var actorView = e.ByPlayer ? _pv : _ev;
var target = e.ByPlayer ? Duel.Enemy : Duel.Player;
var at = targetView.Chest - new Vector2(target.Facing * 60, 0);
switch (e.Type)
{
case DuelEventType.Hit:
if (e.ByPlayer && Duel.Player.State == DuelState.Super && !_calm)
{
bool last = Duel.Player.SuperHits >= Duel.SUPER_HITS.Length;
_hitstop = Math.Max(_hitstop, last ? 0.22f : 0.14f);
_cam.Shake(last ? 1f : 0.75f); _cam.Punch(last ? 0.14f : 0.09f, at);
_screenFlash = last ? 0.7f : 0.35f; _flashColor = last ? new Color(255, 240, 210) : new Color(255, 130, 40);
_fx.Ring(at, new Color(255, 120, 30), last ? 1100 : 650, last ? 0.7f : 0.4f);
_fx.Ring(at, new Color(255, 220, 140), last ? 600 : 360, 0.3f);
_fx.Sparks(at, last ? 110 : 55, new Color(255, 160, 50), target.Facing > 0 ? MathF.PI : 0, last ? MathF.PI : 1.4f, last ? 1700 : 1300);
_fx.Dust(new Vector2(targetView.X, Stage.FloorY), last ? 26 : 12, 160, 120, 110);
_crowd.Excite(last ? 1 : 0.5f);
if (last) { _crowd.Wave(); SoundManager.PlayCheer(); }
}
bool heavy = e.ByPlayer && (Duel.Player.Heavy || Duel.Player.State is DuelState.Leap or DuelState.Super);
_hitstop = Math.Max(_hitstop, e.Crit || heavy ? 0.13f : 0.075f);
_cam.Shake(e.Crit || heavy ? 0.6f : 0.38f);
_cam.Punch(e.Crit ? 0.07f : 0.04f, at);
_fx.Sparks(at, e.Crit ? 34 : 18, e.Crit ? D.Gold : new Color(255, 230, 190), target.Facing > 0 ? MathF.PI : 0, 1.1f);
_fx.Dust(new Vector2(targetView.X, Stage.FloorY), 6, 50, 80, 70);
targetView.Hurt(e.Crit);
_crowd.Excite(e.Crit ? 0.45f : 0.2f);
Float("-" + NumberFormat.Format(e.Amount) + (e.Crit ? "!" : ""), at - new Vector2(0, 120),
e.ByPlayer ? (e.Crit ? D.Gold : Color.White) : D.Red, e.Crit ? 62 : 44);
SoundManager.PlayHit();
if (e.Crit) SoundManager.PlayCheer();
break;
case DuelEventType.Blocked:
var blockerView = e.ByPlayer ? _pv : _ev;
var blocker = e.ByPlayer ? Duel.Player : Duel.Enemy;
var bp = blockerView.Front;
_hitstop = Math.Max(_hitstop, 0.045f);
_cam.Shake(0.18f);
_fx.Sparks(bp, 14, new Color(190, 215, 255), blocker.Facing > 0 ? 0 : MathF.PI, 0.9f, 700);
_fx.Chips(bp, 4, new Color(120, 95, 70), -blocker.Facing);
blockerView.Blocked();
Float(L.t("duel.blocked"), bp - new Vector2(0, 150), D.Blue, 30);
SoundManager.PlayBlock();
break;
case DuelEventType.Parry:
var pv = e.ByPlayer ? _pv : _ev;
_hitstop = Math.Max(_hitstop, 0.17f);
_cam.Shake(0.55f); _cam.Punch(0.08f, pv.Front);
_screenFlash = 0.35f; _flashColor = new Color(220, 235, 255);
_fx.Ring(pv.Front, new Color(200, 225, 255));
_fx.Sparks(pv.Front, 40, Color.White, 0, MathF.PI, 1100);
pv.Parried();
_crowd.Excite(0.6f);
Big(L.t("duel.parry"), new Color(220, 235, 255));
SoundManager.PlayBlock(); SoundManager.PlayCheer();
break;
case DuelEventType.Dodged:
Float(L.t("duel.dodged"), targetView.Chest - new Vector2(0, 180), D.Sand, 30);
_fx.Dust(new Vector2(targetView.X, Stage.FloorY), 8, 80, 40, 60);
_crowd.Excite(0.15f);
break;
case DuelEventType.GuardBreak:
_cam.Shake(0.45f);
_fx.Chips(targetView.Front, 12, new Color(140, 110, 80), target.Facing);
Big(L.t("duel.guardbreak"), D.Red);
break;
case DuelEventType.Special:
_cam.Shake(0.3f); _crowd.Excite(0.35f);
_fx.Ring(_pv.Chest, D.Blue, 520, 0.45f);
Big(L.t(TextKeys.Of(Duel.PlayerSpecial)), D.Blue);
SoundManager.PlayCheer();
break;
case DuelEventType.Leap:
_fx.Dust(new Vector2(_pv.X, Stage.FloorY), 10, 90, 50, 70);
_crowd.Excite(0.15f);
break;
case DuelEventType.Super:
_slowmo = _calm ? 0 : 0.9f;
_cam.Shake(0.5f); _cam.Punch(0.08f, _pv.Chest);
_screenFlash = 0.4f; _flashColor = new Color(255, 170, 60);
_fx.Ring(_pv.Chest, new Color(255, 150, 40), 700, 0.6f);
_fx.Sparks(_pv.Chest, 50, D.Gold, -MathF.PI / 2, MathF.PI, 1000);
Big(L.t("duel.super"), new Color(255, 170, 60));
_fx.Ring(new Vector2(_pv.X, Stage.FloorY), new Color(255, 120, 30), 1400, 0.8f); // Druckwelle am Boden
_fx.Dust(new Vector2(_pv.X, Stage.FloorY), 40, 260, 70, 130);
_crowd.Wave(petals: false);
SoundManager.PlayLevelUp(); SoundManager.PlayCheer();
break;
case DuelEventType.SuperReady:
Float(L.t("duel.super.ready"), _pv.Chest - new Vector2(0, 230), new Color(255, 170, 60), 34);
break;
case DuelEventType.Heal:
_pv.Heal();
_fx.Sparks(_pv.Chest, 20, D.Green, -MathF.PI / 2, 0.6f, 500);
Float("+" + NumberFormat.Format(e.Amount), _pv.Chest - new Vector2(0, 160), D.Green, 40);
break;
case DuelEventType.Ko:
_slowmo = _calm ? 0 : 1.4f;
_hitstop = 0.2f;
_cam.Shake(0.9f); _cam.Punch(0.12f, at);
_screenFlash = 0.5f; _flashColor = Color.White;
_fx.Sparks(at, 60, D.Gold, 0, MathF.PI, 1300);
_fx.Ring(at, D.Gold, 700, 0.6f);
_fx.Dust(new Vector2(targetView.X, Stage.FloorY), 20, 120, 120, 110);
_crowd.Excite(1f);
if (e.ByPlayer) _crowd.Wave();
if (e.ByPlayer) SoundManager.PlayCheer(); else SoundManager.PlayBoo();
break;
}
}
Duel.Events.Clear();
}
void Float(string text, Vector2 pos, Color c, float size) =>
_floaters.Add(new Floater { Text = text, Pos = pos, Color = c, Size = size });
void Big(string text, Color c) =>
_floaters.Add(new Floater { Text = text, Pos = new Vector2(Camera.W / 2, 230), Color = c, Size = 96, Big = true, Life = 1.0f });
// ── Zeichnen ────────────────────────────────────────────────
public void Draw(GraphicsDevice gd, SpriteBatch sb, BasicEffect fx, float scale, Vector2 offset)
{
D.UiScale = scale;
var view = _cam.View(scale, offset);
fx.View = view;
fx.Projection = Matrix.CreateOrthographicOffCenter(0, gd.Viewport.Width, gd.Viewport.Height, 0, 0, 1);
// Hintergrund: Arena (Wan-Loop, sonst Standbild) mit Parallaxe, abgedunkelt, Vignette
sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, _cam.View(scale, offset, 0.35f));
var loop = _loopName != null ? ClipCache.Video(_loopName) : null;
var bg = loop != null ? loop[PingPong(_time * 8, loop.Length)] : _backdrop;
if (bg != null)
{
float k = 1.18f * MathF.Max(Camera.W / bg.Width, Camera.H / bg.Height);
sb.Draw(bg, new Vector2(Camera.W / 2, Camera.H / 2), null, new Color(0.66f, 0.62f, 0.58f), 0,
new Vector2(bg.Width / 2f, bg.Height / 2f), k, SpriteEffects.None, 0);
}
sb.End();
// Boden, Schatten, Staub (Kampfebene)
sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, view);
if (_furyDark > 0.01f) // Raserei: Arena versinkt im Dunkel, nur die Kämpfer bleiben im Licht
D.Rect(sb, new RectangleF(-3000, -3000, Camera.W + 6000, Camera.H + 6000), new Color(20, 4, 0) * (0.62f * _furyDark));
D.Rect(sb, new RectangleF(-1200, Stage.FloorY + 30, Camera.W + 2400, 900), Color.Black * 0.35f);
D.Glow(sb, new Vector2(Camera.W / 2, Stage.FloorY + 20), new Vector2(3600, 260), Color.Black * 0.45f);
_pv.DrawShadow(sb);
_ev.DrawShadow(sb);
sb.End();
// warmer Lichtkegel auf dem Sand, wo gekämpft wird
sb.Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.LinearClamp, null, null, null, view);
D.Glow(sb, new Vector2((_pv.X + _ev.X) / 2, Stage.FloorY + 10), new Vector2(1500, 230), new Color(255, 180, 110) * 0.22f);
if (_furyDark > 0.01f)
{
float flicker = 0.8f + 0.2f * MathF.Sin((float)_time * 23) * MathF.Sin((float)_time * 7.3f);
D.Glow(sb, new Vector2(_pv.X, Stage.FloorY), new Vector2(900, 220), new Color(255, 100, 20) * (0.75f * _furyDark * flicker));
D.Glow(sb, _pv.Chest, new Vector2(Stage.FigH * 2.2f), new Color(255, 120, 30) * (0.35f * _furyDark * flicker));
}
sb.End();
sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, view);
_fx.DrawSoft(sb);
DrawSmear(sb, _pv, Duel.Player); DrawSmear(sb, _ev, Duel.Enemy);
sb.End();
// Kämpfer (Gitter auf der GPU)
gd.BlendState = BlendState.AlphaBlend;
gd.SamplerStates[0] = SamplerState.LinearClamp;
gd.RasterizerState = RasterizerState.CullNone;
gd.DepthStencilState = DepthStencilState.None;
if (_pv.Is3D || _ev.Is3D) gd.Clear(ClearOptions.DepthBuffer, Color.Transparent, 1, 0); // 3D-Figuren verdecken sich richtig
var e = Duel.Enemy; var p = Duel.Player;
if (e.State == DuelState.Windup) // fair: der Schlag kündigt sich rot an
{
float k = (float)Math.Min(1, e.StateTime / e.Windup);
_ev.DrawAura(gd, fx, new Color(255, 60, 40) * (0.55f * k), 0.035f * k);
}
if (p.State == DuelState.Wall || p.Invulnerable > 0) _pv.DrawAura(gd, fx, D.Blue * 0.5f, 0.03f);
if (p.Heavy && p.State == DuelState.Windup) _pv.DrawAura(gd, fx, new Color(255, 150, 40) * 0.6f, 0.035f);
if (p.State == DuelState.Super) // Raserei: lodernde Doppel-Aura
{
float pulse = 0.65f + 0.35f * MathF.Sin((float)_time * 18);
_pv.DrawAura(gd, fx, new Color(255, 60, 10) * (0.45f * pulse), 0.11f);
_pv.DrawAura(gd, fx, new Color(255, 170, 50) * (0.8f * pulse), 0.05f);
}
else if (p.Rage >= 100) _pv.DrawAura(gd, fx, new Color(255, 130, 30) * (0.28f + 0.14f * MathF.Sin((float)_time * 6)), 0.03f);
// wer gerade zuschlägt, liegt vorn
bool enemyFront = e.State is DuelState.Strike or DuelState.Windup && p.State is not (DuelState.Strike or DuelState.Windup);
if (enemyFront) { _pv.DrawBody(gd, fx, p, _calm); _ev.DrawBody(gd, fx, e, _calm); }
else { _ev.DrawBody(gd, fx, e, _calm); _pv.DrawBody(gd, fx, p, _calm); }
// Licht und Funken (additiv)
sb.Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.LinearClamp, null, null, null, view);
_fx.DrawAdd(sb);
if (e.State == DuelState.Windup)
{
float k = (float)Math.Min(1, e.StateTime / e.Windup);
D.Text(sb, Assets.Serif, 90, "!", new Vector2(_ev.X, Stage.FloorY - Stage.FigH - 40), new Color(255, 90, 60) * k, Align.Center, 1 + 0.3f * (1 - k), false); // i18n-ok
}
if (p.State == DuelState.Stunned || e.State == DuelState.Stunned)
foreach (var (v, f) in new[] { (_pv, p), (_ev, e) })
if (f.State == DuelState.Stunned)
for (int i = 0; i < 3; i++)
{
double a = _time * 5 + i * 2.1;
D.Glow(sb, new Vector2(v.X + (float)Math.Cos(a) * 60, Stage.FloorY - Stage.FigH + 10 + (float)Math.Sin(a) * 14), new Vector2(34), D.Gold);
}
sb.End();
// Publikum vorne (Parallaxe > 1), Licht von oben, Vignette
sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, _cam.View(scale, offset, 1.35f));
_crowd.Draw(sb, _calm);
sb.End();
var ui = Matrix.CreateScale(scale) * Matrix.CreateTranslation(offset.X, offset.Y, 0);
sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, ui);
DrawVignette(sb);
// wenig Leben: roter Puls am Rand
float low = (float)(Duel.Player.Hp / Duel.Player.MaxHp);
if (low < 0.3f && Duel.Player.Alive)
{
float pulse = (0.3f - low) / 0.3f * (0.55f + 0.45f * MathF.Sin((float)_time * 6));
var red = new Color(160, 10, 0) * (0.6f * pulse);
D.Glow(sb, new Vector2(-150, Camera.H / 2), new Vector2(800, 1800), red);
D.Glow(sb, new Vector2(Camera.W + 150, Camera.H / 2), new Vector2(800, 1800), red);
}
sb.End();
sb.Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.LinearClamp, null, null, null, ui);
D.Glow(sb, new Vector2(Camera.W * 0.5f, -120), new Vector2(2400, 900), new Color(255, 190, 120) * 0.16f);
if (_screenFlash > 0) D.Rect(sb, new RectangleF(0, 0, Camera.W, Camera.H), _flashColor * (_screenFlash * 0.5f));
sb.End();
// Zahlen über den Köpfen (Kamera) und HUD (Bildschirm)
sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, view);
foreach (var f in _floaters) if (!f.Big) DrawFloater(sb, f);
sb.End();
sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, ui);
foreach (var f in _floaters) if (f.Big) DrawFloater(sb, f);
DrawHud(sb);
sb.End();
_bar.Draw(gd, sb, ui);
}
static int PingPong(double t, int n)
{
int period = 2 * (n - 1), i = (int)t % period;
return i < n ? i : period - i;
}
void DrawVignette(SpriteBatch sb)
{
// Ränder abdunkeln: vier weiche, große Flecken außerhalb des Bilds
var c = Color.Black * 0.75f;
D.Glow(sb, new Vector2(-200, Camera.H / 2), new Vector2(900, 2000), c);
D.Glow(sb, new Vector2(Camera.W + 200, Camera.H / 2), new Vector2(900, 2000), c);
D.Glow(sb, new Vector2(Camera.W / 2, -160), new Vector2(3200, 520), Color.Black * 0.5f);
}
/// Wischspur der Waffe beim Schlag: Bogen aus weichen Lichtpunkten vor der Figur.
void DrawSmear(SpriteBatch sb, FighterView v, DuelFighter f)
{
if (_calm || f.State != DuelState.Strike) return;
float k = MathHelper.Clamp((float)(f.StateTime / f.StrikeTime), 0, 1);
var c = new Vector2(v.X + f.Facing * 60, Stage.FloorY - Stage.FigH * 0.55f);
const int N = 16;
for (int i = 0; i < N; i++)
{
float s = i / (float)(N - 1);
if (s > k + 0.15f) break;
float a = MathHelper.Lerp(-1.9f, 0.7f, s);
var pos = c + new Vector2(MathF.Cos(a) * f.Facing, MathF.Sin(a)) * (250 + 20 * s);
float fade = MathF.Max(0, 1 - (k - s) * 2.2f) * (f.Heavy ? 0.9f : 0.6f);
var col = f.Heavy ? new Color(255, 170, 70) : new Color(255, 245, 225);
D.Glow(sb, pos, new Vector2(70, 26), col * fade);
}
}
void DrawFloater(SpriteBatch sb, Floater f)
{
float k = f.Age / f.Life;
float pop = f.Big ? 1 + 0.6f * MathF.Max(0, 1 - f.Age * 6) : 1 + 0.5f * MathF.Max(0, 1 - f.Age * 8);
float a = MathHelper.Clamp((1 - k) * 2.5f, 0, 1);
var pos = f.Pos - new Vector2(0, f.Big ? 0 : 110 * MathF.Sqrt(k));
D.Text(sb, f.Big ? Assets.Serif : Assets.SansBold, f.Size, f.Text, pos, f.Color * a, Align.Center, pop);
}
void DrawHud(SpriteBatch sb)
{
var p = Duel.Player; var e = Duel.Enemy;
float a = _phase == Phase.Countdown ? MathHelper.Clamp(_phaseTime * 2, 0, 1) : 1;
// Spieler links oben
float nx = 70;
if (Assets.Sprite(_game.Look.EmblemArt) is Texture2D em)
{
sb.Draw(em, new Vector2(100, 62), null, Color.White * a, 0, new Vector2(em.Width / 2f, em.Height / 2f), 64f / em.Width, SpriteEffects.None, 0);
nx = 144;
}
D.Text(sb, Assets.Serif, 34, $"{_game.Name} · {L.t(_game.ClassDef.Key)}", new Vector2(nx, 58), D.Gold * a);
D.Bar(sb, new RectangleF(70, 88, 700, 34), (float)(p.Hp / p.MaxHp), _pLag, D.Green);
D.Bar(sb, new RectangleF(70, 128, 460, 16), (float)(p.Stamina / 100), (float)(p.Stamina / 100), D.Gold);
// Wut: voll → R für den Super-Angriff (pulsiert)
bool full = p.Rage >= 100;
float pulse = full ? 0.75f + 0.25f * MathF.Sin((float)_time * 8) : 1;
D.Bar(sb, new RectangleF(70, 150, 460, 12), (float)(p.Rage / 100), (float)(p.Rage / 100), new Color(255, 140, 40) * pulse);
D.Text(sb, Assets.SansBold, 16, L.t(full ? "duel.super.key" : "duel.rage"), new Vector2(544, 156),
full ? new Color(255, 170, 60) * pulse : D.Sand * 0.8f);
// Gegner rechts oben
D.Text(sb, Assets.Serif, 34, _enemy.Name, new Vector2(Camera.W - 70, 58), D.Red * a, Align.Right);
D.Bar(sb, new RectangleF(Camera.W - 770, 88, 700, 34), (float)(e.Hp / e.MaxHp), _eLag, D.Red, fromRight: true);
D.Text(sb, Assets.Sans, 15, L.t("mono.help"), new Vector2(Camera.W / 2, Camera.H - 13), D.Sand * 0.8f, Align.Center);
if (_phase == Phase.Countdown)
{
int n = 3 - (int)(_phaseTime / (COUNTDOWN / 3));
float k = _phaseTime % (COUNTDOWN / 3) / (COUNTDOWN / 3);
if (n >= 1)
D.Text(sb, Assets.Serif, 200, n.ToString(NumberFormat.Culture), new Vector2(Camera.W / 2, 420),
D.Gold * (1 - k * 0.7f), Align.Center, 1.5f - 0.5f * k);
D.Text(sb, Assets.SansBold, 28, L.t(_enemy.Display != null ? "duel.legend" : _enemy.IsChampion ? "duel.champion" : "duel.practice").ToUpperInvariant(),
new Vector2(Camera.W / 2, 600), D.Sand, Align.Center);
}
if (_phase == Phase.End)
{
float k = MathHelper.Clamp(_phaseTime / 0.6f, 0, 1);
D.Rect(sb, new RectangleF(0, 0, Camera.W, Camera.H), Color.Black * (0.35f * k));
D.Text(sb, Assets.Serif, 170, L.t(Won ? "duel.win" : "duel.lose"), new Vector2(Camera.W / 2, 400),
(Won ? D.Gold : D.Red) * k, Align.Center, 1 + 0.4f * (1 - k));
if (Finished)
D.Text(sb, Assets.SansBold, 30, L.t("mono.next"), new Vector2(Camera.W / 2, 600), Color.White, Align.Center);
}
if (Paused)
{
D.Rect(sb, new RectangleF(0, 0, Camera.W, Camera.H), Color.Black * 0.6f);
D.Text(sb, Assets.Serif, 110, L.t("duel.pause").ToUpperInvariant(), new Vector2(Camera.W / 2, 420), D.Gold, Align.Center);
D.Text(sb, Assets.SansBold, 28, L.t("mono.pausehelp"), new Vector2(Camera.W / 2, 560), Color.White, Align.Center);
}
}
public void GiveUp()
{
Paused = false;
Duel.Surrender();
_phase = Phase.End; _phaseTime = 0; Won = false;
SoundManager.PlayDefeat();
}
}
}

View File

@@ -0,0 +1,181 @@
using System;
using GladiatorIdle.Gfx;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace GladiatorIdle.Arena
{
/// 3D-Darstellung eines Kämpfers (Mixamo-Bewegungen, siehe <see cref="Model3D"/>): gibt es für das
/// Bild ein Modell (Assets/Models/&lt;art&gt;.gim), sonst das Standardmodell, zeichnet die Figur in 3D
/// statt der Sprites. Zustände der Kampflogik werden auf Clips gelegt, der Treffer fällt auf den
/// Moment, in dem der Schwertarm am weitesten vorn ist.
internal sealed partial class FighterView
{
public const string DefaultModel = "hero_murmillo_1";
Model3D? _model;
BasicEffect? _mfx;
Matrix _fit;
string _mClip = "";
float _mTime, _mBlend = 1;
bool _mFree;
public bool Is3D => _model != null;
void InitModel(int color)
{
_model = Model3D.Load(_art);
foreach (var alt in Fallbacks(_art)) _model ??= Model3D.Load(alt);
_model ??= Model3D.Load(DefaultModel);
if (_model == null || _model.Clips.Count == 0) { _model = null; return; }
_model.AddSword();
_model.AddShield();
_model.SetColor(color);
var idle = Clip3("idle");
_model.Pose(idle, 0, true);
_fit = _model.FitNow();
foreach (var c in new[] { "slash", "slash2", "slash3", "attack", "attack2" }) _model.ImpactTime(Clip3(c));
_mfx = new BasicEffect(Assets.Device) { VertexColorEnabled = true, LightingEnabled = true, PreferPerPixelLighting = true };
// Kamera-Raum der Arena: x rechts, y nach unten, z zum Betrachter
_mfx.AmbientLightColor = new Vector3(0.45f, 0.40f, 0.37f);
_mfx.DirectionalLight0.Enabled = true; // warmes Licht von oben links vorn
_mfx.DirectionalLight0.Direction = Vector3.Normalize(new Vector3(0.45f, 0.75f, -0.5f));
_mfx.DirectionalLight0.DiffuseColor = new Vector3(0.95f, 0.84f, 0.70f);
_mfx.DirectionalLight0.SpecularColor = new Vector3(0.22f, 0.2f, 0.18f);
_mfx.DirectionalLight1.Enabled = true; // kühles Gegenlicht
_mfx.DirectionalLight1.Direction = Vector3.Normalize(new Vector3(-0.7f, 0.1f, 0.7f));
_mfx.DirectionalLight1.DiffuseColor = new Vector3(0.22f, 0.27f, 0.36f);
_mfx.DirectionalLight2.Enabled = false;
_mfx.SpecularPower = 24;
}
/// Figuren ohne eigenes Modell: eine ähnliche vorhandene (in eigener Teamfarbe), bis es eines gibt.
static System.Collections.Generic.IEnumerable<string> Fallbacks(string art)
{
if (art.StartsWith("hero_") && art.LastIndexOf('_') is int u && u > 5) yield return art[..u] + "_1"; // Vorlage 1 der Klasse
if (art.StartsWith("champ_")) { yield return "champ_doctore"; yield break; }
switch (art)
{
case "foe_recruit": yield return "foe_slave"; break;
case "foe_provocator" or "foe_crupellarius" or "foe_praetorian" or "foe_eques":
yield return "foe_hoplomachus"; break;
case "foe_dimachaerus" or "foe_essedarius" or "foe_laquearius" or "foe_sagittarius":
yield return "foe_brawler"; break;
}
yield return "foe_hoplomachus";
}
Model3D.Clip Clip3(string name) => _model!.Find(name) ?? _model!.Clips[0];
/// Clip und Zeit zum Zustand der Kampflogik.
void UpdateModel(DuelFighter f, float dt, float realDt)
{
var m = _model!;
double K(double total) => total > 0 ? Math.Clamp(f.StateTime / total, 0, 1) : 1;
string name; float t; bool loop = false;
var atk = Clip3(f.Heavy ? "slash2" : "slash");
float impact = m.ImpactTime(atk), lead = MathF.Min(0.12f, impact);
switch (f.State)
{
case DuelState.Windup:
name = atk.Name; t = (float)K(f.Heavy ? Duel.HEAVY_WINDUP : f.Windup) * (impact - lead); _mFree = false; break;
case DuelState.Strike:
name = atk.Name; t = impact - lead + (float)K(f.StrikeTime) * lead; break;
case DuelState.Recover:
name = atk.Name; t = impact + (float)K(f.RecoverTime) * (atk.Length - impact) * 0.5f; _mFree = true; break;
case DuelState.Block or DuelState.Wall:
name = "block"; t = (float)f.StateTime * 1.5f; _mFree = false; break;
case DuelState.Hit:
name = "impact"; t = (float)f.StateTime * 1.4f; _mFree = true; break;
case DuelState.Stunned:
name = "impact2"; t = (float)f.StateTime * 0.6f; loop = true; _mFree = false; break;
case DuelState.Dodge:
name = "crouchblock"; t = (float)K(0.32) * Clip3("crouchblock").Length; _mFree = false; break;
case DuelState.Down:
name = "death"; t = (float)f.StateTime; _mFree = false; break;
case DuelState.Victory:
name = "victory"; t = (float)f.StateTime; _mFree = false; break;
case DuelState.Leap:
{
// Sprungangriff: der Hieb des Clips fällt auf den Treffer der Kampflogik
var leap = Clip3("attack");
float li = m.ImpactTime(leap), st = (float)f.StateTime, hit = (float)Duel.LEAP_HIT;
name = leap.Name;
t = st < hit ? st / hit * li : li + (st - hit);
_mFree = true; break;
}
case DuelState.Super:
{
// Aufladen, dann drei Hiebe; jeder Clip trifft genau zu seinem Zeitpunkt
float st = (float)f.StateTime;
if (st < Duel.SUPER_CHARGE) { name = "powerup"; t = st * 1.6f; _mFree = false; break; }
string[] combo = { "slash", "slash3", "attack2" };
int k = 0;
while (k < combo.Length - 1 && st > Duel.SUPER_HITS[k] + 0.08) k++;
var c = Clip3(combo[k]);
name = c.Name;
t = MathF.Max(0, m.ImpactTime(c) + (st - (float)Duel.SUPER_HITS[k]) * 1.2f);
_mFree = true; break;
}
default:
{
float vx = dt > 0 ? (X - _lastX) / dt : 0;
bool moving = MathF.Abs(vx) > 40;
// nach Schlag/Treffer den Clip auslaufen lassen, außer man bewegt sich
if (_mFree && !moving && _mTime < Clip3(_mClip).Length)
{
name = _mClip; t = _mTime + dt * 1.4f; break;
}
_mFree = false;
if (moving)
{
name = "walk"; loop = true;
float dir = MathF.Sign(vx) * Facing; // rückwärts gehen: Clip rückwärts
t = (_mClip == "walk" ? _mTime : 0) + dt * 1.25f * dir;
}
else { name = "idle"; loop = true; t = (_mClip == "idle" ? _mTime : 0) + dt; }
break;
}
}
if (name != _mClip) { m.BeginBlend(); _mBlend = 0; _mClip = name; }
_mBlend = MathF.Min(1, _mBlend + realDt / 0.12f);
_mTime = t;
m.Pose(Clip3(name), t, loop, _mBlend, rootY: f.State == DuelState.Leap ? 0.5f : 1);
}
Matrix ModelWorld(float grow)
{
float s = Stage.FigH / 180f * (1 + grow);
float yaw = Facing * MathHelper.ToRadians(72); // zum Gegner, leicht zum Betrachter gedreht
return _fit * Matrix.CreateRotationY(yaw)
* Matrix.CreateScale(s * (1 - _sq * 0.04f), -s * (1 + _sq * 0.06f), s) // y nach unten
* Matrix.CreateRotationZ(_lean * Facing)
* Matrix.CreateTranslation(X + _off * Facing * 0.35f * Stage.Scale, Stage.FloorY, 0);
}
void DrawModel(GraphicsDevice gd, BasicEffect scene, Color aura, float grow)
{
var fx = _mfx!;
var vp = gd.Viewport;
fx.View = scene.View;
fx.Projection = Matrix.CreateOrthographicOffCenter(0, vp.Width, vp.Height, 0, -100000, 100000);
fx.World = ModelWorld(grow);
if (aura.A > 0)
{
fx.LightingEnabled = false;
fx.DiffuseColor = aura.ToVector3() * (aura.A / 255f);
fx.EmissiveColor = Vector3.Zero;
_model!.Draw(gd, fx, aura: true);
fx.LightingEnabled = true;
fx.DiffuseColor = Vector3.One;
}
else
{
fx.EmissiveColor = Color.White.ToVector3() * (_flash * 0.55f) + _tintColor.ToVector3() * (_tint * 0.5f);
_model!.Draw(gd, fx);
}
gd.DepthStencilState = DepthStencilState.None;
gd.BlendState = BlendState.AlphaBlend;
}
}
}

363
Mono/Arena/FighterView.cs Normal file
View File

@@ -0,0 +1,363 @@
using System;
using System.Collections.Generic;
using GladiatorIdle.Gfx;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Clip = GladiatorIdle.Gfx.ClipCache.Clip;
namespace GladiatorIdle.Arena
{
internal static class Stage
{
/// Größe der Kämpfer (1 = früher 560 px hoch); Abstände im Kampf: <see cref="Duel.SCALE"/>.
public const float Scale = (float)Duel.SCALE;
public const float FloorY = 890, FigH = 560 * Scale;
/// Sprites: 768er-Leinwand, Füße bei y = 742, Kopf bei ~26 (716 px Figur).
public const float Canvas = 768, Feet = 742, Body = 716;
}
/// <summary>
/// Darstellung eines Duell-Kämpfers: Pose je Zustand (weich überblendet) auf einem Gitter,
/// das auf der GPU verformt wird — Atmen, Ausholen (Stauchen), Schlag (Strecken, Vorstoß),
/// Treffer (Rückstoß, Wackeln, weißer Blitz), Lehnen beim Laufen. Füße bleiben am Boden.
/// </summary>
internal sealed partial class FighterView
{
const int NX = 6, NY = 14;
const float BLEND = 0.08f;
readonly string _art;
readonly Dictionary<string, Texture2D?> _poses = new();
readonly VertexPositionColorTexture[] _verts = new VertexPositionColorTexture[(NX + 1) * (NY + 1)];
static readonly short[] Indices = BuildIndices();
Texture2D? _cur, _prev;
string _poseKey = "";
float _blend = 1;
DuelState _state = (DuelState)(-1);
double _t;
float _phase;
// Federn: Strecken/Stauchen, Lehnen, Versatz entlang der Blickrichtung, Wackeln
float _sq, _sqV, _lean, _leanV, _off, _offV, _wob;
float _flash, _tint;
Color _tintColor = Color.Red;
float _lastX, _stepDust;
public float X { get; private set; }
public int Facing { get; private set; } = 1;
public Vector2 Chest => new(X + _off * Facing * Stage.Scale, Stage.FloorY - Stage.FigH * 0.58f);
public Vector2 Front => new(X + (150 + _off) * Facing * Stage.Scale, Stage.FloorY - Stage.FigH * 0.55f);
readonly int _color;
/// <param name="color">Teamfarbe (Index in <see cref="Appearance.Colors"/>), −1 = Bild unverändert.</param>
/// <param name="modelColor">Teamfarbe der 3D-Figur (−1: wie <paramref name="color"/>).</param>
public FighterView(string art, float phase, int color = -1, int modelColor = -1)
{
_art = art;
_phase = phase;
_color = color;
InitModel(modelColor >= 0 ? modelColor : color);
}
Texture2D? Pose(string key)
{
if (!_poses.TryGetValue(key, out var t))
{
t = Assets.Sprite(key == "" ? _art : _art + "_" + key);
if (t != null && _color >= 0) t = Assets.Paint(t, _color);
_poses[key] = t;
}
return t;
}
/// Erste vorhandene Pose aus der Liste (sonst das Grundbild).
string Pick(params string[] keys)
{
foreach (var k in keys) if (Pose(k) != null) return k;
return "";
}
// ── Video-Clips (Wan): Bildfolgen je Aktion, auf die Zustände der Kampflogik gelegt ──
Clip? _clip;
string? _clipName, _lastClipName;
float _clipPos;
bool _freePlay; // Clip läuft nach Ende des Zustands weiter (Erholung nach Schlag/Treffer)
const float FPS = 16;
/// Clip aus dem gemeinsamen Zwischenspeicher (null, solange er im Hintergrund lädt).
Clip? GetClip(string action) => ClipCache.Get(_art, action, _color);
/// Vorab laden (Duell-Beginn), damit es mitten im Kampf nicht ruckelt.
public void Preload()
{
if (_model != null) return;
foreach (var a in new[] { "idle", "walk", "attack", "heavy", "block", "hit", "dodge", "victory", "ko" }) GetClip(a);
}
/// Bild des passenden Clips zum Zustand (null = Posen verwenden).
Texture2D? ClipFrame(DuelFighter f, float dt)
{
string name; float pos;
double K(double total) => total > 0 ? Math.Clamp(f.StateTime / total, 0, 1) : 1;
bool heavy = f.Heavy && GetClip("heavy") != null;
Clip? atk = GetClip(heavy ? "heavy" : "attack");
switch (f.State)
{
case DuelState.Windup when atk != null:
name = heavy ? "heavy" : "attack";
pos = (float)(K(heavy ? Duel.HEAVY_WINDUP : f.Windup) * (atk.Impact - 3));
_freePlay = false; break;
case DuelState.Strike when atk != null:
name = heavy ? "heavy" : "attack";
pos = atk.Impact - 3 + (float)K(f.StrikeTime) * 3; break;
case DuelState.Recover when atk != null:
name = heavy ? "heavy" : "attack";
pos = atk.Impact + (float)K(f.RecoverTime) * (atk.Last - atk.Impact) * 0.55f;
_freePlay = true; break;
case DuelState.Block or DuelState.Wall when GetClip("block") is Clip b:
name = "block"; pos = MathF.Min(b.Last, (float)f.StateTime * FPS * 3); _freePlay = false; break;
case DuelState.Hit when GetClip("hit") is Clip h:
name = "hit"; pos = (float)K(0.25) * h.Impact; _freePlay = true; break;
case DuelState.Dodge when GetClip("dodge") is Clip d:
name = "dodge"; pos = (float)K(0.32) * d.Last; _freePlay = false; break;
case DuelState.Down when GetClip("ko") is Clip ko:
name = "ko"; pos = MathF.Min(ko.Last, (float)f.StateTime * FPS); break;
case DuelState.Victory when GetClip("victory") is Clip v:
name = "victory"; pos = MathF.Min(v.Last, (float)f.StateTime * FPS); break;
case DuelState.Ready:
{
float vx = dt > 0 ? (X - _lastX) / dt : 0;
bool moving = MathF.Abs(vx) > 40;
// nach Schlag/Treffer: Clip zu Ende spielen, außer man bewegt sich
if (_freePlay && _clip != null && !moving && _clipPos < _clip.Last)
{
_clipPos += dt * FPS * 1.6f;
return _clip.Frames[(int)MathF.Min(_clip.Last, _clipPos)];
}
_freePlay = false;
if (moving && GetClip("walk") is Clip w)
{
name = "walk";
float dir = MathF.Sign(vx) * Facing; // rückwärts gehen: Clip rückwärts
pos = _clipName == "walk" ? _clipPos + dt * FPS * 1.3f * dir : 0;
pos = ((pos % w.Last) + w.Last) % w.Last;
break;
}
if (GetClip("idle") is Clip idle)
{
name = "idle";
pos = _clipName == "idle" ? (_clipPos + dt * FPS) % idle.Last : 0;
break;
}
_clip = null; _clipName = null; return null;
}
default:
_clip = null; _clipName = null; _freePlay = false; return null;
}
_clip = GetClip(name); _clipName = name; _clipPos = pos;
return _clip!.Frames[Math.Clamp((int)pos, 0, _clip.Last)];
}
static short[] BuildIndices()
{
var idx = new List<short>();
for (int j = 0; j < NY; j++)
for (int i = 0; i < NX; i++)
{
short a = (short)(j * (NX + 1) + i), b = (short)(a + 1), c = (short)(a + NX + 1), d = (short)(c + 1);
idx.AddRange(new[] { a, b, c, b, d, c });
}
return idx.ToArray();
}
// ── Anstöße von außen (Ereignisse) ──────────────────────────
public void Hurt(bool crit)
{
_flash = crit ? 1f : 0.85f;
_tint = 0.55f; _tintColor = new Color(255, 80, 60);
_offV -= crit ? 900 : 600;
_sqV -= crit ? 2.6f : 1.8f;
_wob = crit ? 1f : 0.7f;
}
public void Blocked() { _offV -= 320; _sqV -= 1.0f; _flash = 0.35f; }
public void Parried() { _flash = 1f; _tint = 0.5f; _tintColor = new Color(160, 210, 255); _sqV += 1.5f; }
public void Heal() { _tint = 0.7f; _tintColor = new Color(120, 255, 140); _sqV += 1.2f; }
// ── Takt ────────────────────────────────────────────────────
/// Zustand übernehmen; liefert true bei einem Fußtritt (Staub).
public bool Update(float dt, float realDt, DuelFighter f, float displayX, bool calm)
{
_t += dt;
X = displayX;
Facing = f.Facing;
if (f.State != _state) Enter(f);
_state = f.State;
string key = f.State switch
{
DuelState.Windup => Pick("windup"),
DuelState.Strike => Pick("attack"),
DuelState.Recover => f.StateTime < f.RecoverTime * 0.35 ? Pick("attack") : Pick("recover", ""),
DuelState.Block or DuelState.Wall => Pick("block"),
DuelState.Dodge => Pick("dodge", ""),
DuelState.Hit => Pick("hit"),
DuelState.Stunned => Pick("stagger", "hit"),
DuelState.Down => Pick("ko", "hit"),
DuelState.Victory => Pick("victory"),
DuelState.Leap => Pick("attack"),
DuelState.Super => f.StateTime < Duel.SUPER_CHARGE ? Pick("windup") : Pick("attack"),
_ => Math.Sin(_t * 0.9 + _phase) > 0.55 ? Pick("idle2", "") : ""
};
var clipFrame = _model != null ? null : ClipFrame(f, dt);
if (_model != null) UpdateModel(f, dt, realDt);
else if (clipFrame != null)
{
// Video-Clip: neues Bild ohne Überblendung, nur beim Wechsel des Clips weich
if (_clipName != _lastClipName) { _prev = _cur; _blend = _prev == null ? 1 : 0; _lastClipName = _clipName; }
_cur = clipFrame; _poseKey = "";
}
else
{
if (_lastClipName != null) { _prev = _cur; _blend = 0; _lastClipName = null; _poseKey = "-"; }
if (key != _poseKey) { _prev = _cur; _cur = Pose(key); _poseKey = key; _blend = _prev == null ? 1 : 0; }
}
_cur ??= Pose("");
_blend = MathF.Min(1, _blend + realDt / BLEND); // in Echtzeit, auch im Trefferstopp
// Federn
Spring(ref _sq, ref _sqV, 0, 260, 14, dt);
Spring(ref _off, ref _offV, 0, 140, 16, dt);
float vx = dt > 0 ? (X - _lastX) / dt : 0;
float leanTarget = f.State == DuelState.Ready ? MathHelper.Clamp(vx * Facing / 440f, -1, 1) * 0.07f : 0;
if (f.State == DuelState.Windup) leanTarget = -0.06f;
if (f.State == DuelState.Strike) leanTarget = 0.09f;
if (f.State == DuelState.Stunned) leanTarget = 0.05f * MathF.Sin((float)_t * 6);
Spring(ref _lean, ref _leanV, leanTarget, 180, 18, dt);
// Blitz und Färbung in Echtzeit (auch während Trefferstopp und Zeitlupe)
_wob = MathF.Max(0, _wob - dt * 3.5f);
_flash = MathF.Max(0, _flash - realDt * 7);
_tint = MathF.Max(0, _tint - realDt * 2.5f);
if (calm) { _sq *= 0.3f; _wob = 0; }
bool step = false;
if (MathF.Abs(vx) > 60 && f.State == DuelState.Ready)
{
_stepDust -= dt;
if (_stepDust <= 0) { _stepDust = 0.22f; step = true; }
}
_lastX = X;
return step;
}
void Enter(DuelFighter f)
{
switch (f.State)
{
case DuelState.Windup: _sqV -= f.Heavy ? 2.2f : 1.2f; _offV -= 200; break; // Ausholen: zusammenziehen
case DuelState.Strike: _sqV += f.Heavy ? 3.5f : 2.4f; _offV += f.Heavy ? 1300 : 900; break; // Vorstoß
case DuelState.Leap: _sqV -= 1.8f; break;
case DuelState.Super: _sqV -= 2.0f; break;
case DuelState.Dodge: _sqV -= 1.5f; break;
case DuelState.Victory: _sqV += 2f; break;
case DuelState.Down: _sqV -= 2.5f; break;
}
}
static void Spring(ref float x, ref float v, float target, float k, float c, float dt)
{
v += (-(x - target) * k - v * c) * dt;
x += v * dt;
}
// ── Zeichnen ────────────────────────────────────────────────
/// Bodenschatten (SpriteBatch, Kamera-Matrix).
public void DrawShadow(SpriteBatch sb)
{
float w = 270 * Stage.Scale * (1 + _sq * 0.4f);
Draw.Glow(sb, new Vector2(X + _off * Facing * 0.5f * Stage.Scale, Stage.FloorY + 4), new Vector2(w, 58 * Stage.Scale), Color.Black * 0.55f);
}
/// Leuchten hinter der Figur (Silhouette, leicht vergrößert): angekündigter Schlag, Schildwall.
public void DrawAura(GraphicsDevice gd, BasicEffect fx, Color c, float grow)
{
if (_model != null) { if (c.A > 0) DrawModel(gd, fx, c, grow); return; }
if (_cur == null || c.A == 0) return;
Quad(gd, fx, Assets.White(_cur), 1 + grow, c, 0);
}
public void DrawBody(GraphicsDevice gd, BasicEffect fx, DuelFighter f, bool calm)
{
if (_model != null) { DrawModel(gd, fx, Color.Transparent, 0); return; }
if (_cur == null) return;
float alpha = f.State == DuelState.Down ? MathF.Max(0.55f, 1 - (float)f.StateTime * 0.3f) : 1f;
// Ausweichen: Nachbilder
if (f.State == DuelState.Dodge && !calm)
for (int k = 1; k <= 2; k++)
{
Quad(gd, fx, _cur, 1, Color.White * (0.22f / k), -Facing * 70 * k);
}
if (_prev != null && _blend < 1)
{
Quad(gd, fx, _prev, 1, Color.White * (alpha * (1 - _blend)), 0);
}
// neue Pose sofort voll deckend; nur die alte blendet darunter aus (sonst scheint
// die Figur beim Wechsel durch)
Quad(gd, fx, _cur, 1, Color.White * alpha, 0);
if (_tint > 0) { Quad(gd, fx, Assets.White(_cur), 1, _tintColor * (_tint * 0.5f), 0); }
if (_flash > 0) { Quad(gd, fx, Assets.White(_cur), 1, Color.White * (_flash * 0.55f), 0); }
}
/// Gitter aufbauen: Füße fest am Boden, Verformung wächst mit der Höhe.
void Quad(GraphicsDevice gd, BasicEffect fx, Texture2D tex, float scale, Color color, float shiftX)
{
// Clip-Bilder sind auf den Bewegungsbereich zugeschnitten: Lage in der vollen Leinwand
if (ClipCache.CropOf(tex) is (Vector4 crop, float aspect))
Build(scale, color, shiftX, Stage.Canvas * aspect, crop);
else
Build(scale, color, shiftX, Stage.Canvas * tex.Width / tex.Height, new Vector4(0, 0, 1, 1));
Mesh(gd, fx, tex);
}
void Build(float scale, Color color, float shiftX, float canvasW, Vector4 crop)
{
float s = Stage.FigH / Stage.Body * scale;
float breathe = _clip != null ? 0 : 0.012f * MathF.Sin((float)_t * 2.3f + _phase);
float sy = 1 + _sq * 0.10f + breathe, sx = 1 - _sq * 0.06f - breathe * 0.5f;
float baseX = X + (_off * Facing * Stage.Scale) * (_clip != null ? 0.35f : 1) + shiftX * Stage.Scale;
for (int j = 0; j <= NY; j++)
{
float v = (float)j / NY, cv = crop.Y + v * crop.W;
float py = (cv * Stage.Canvas - Stage.Feet) * s; // < 0 über den Füßen
float h = MathHelper.Clamp(-py / (Stage.Body * s), 0, 1.1f); // 0 Füße … 1 Kopf
float lean = _lean * h * Stage.FigH * Facing;
float wob = _wob * 22 * MathF.Sin(h * 5.5f - (float)_t * 38) * h;
for (int i = 0; i <= NX; i++)
{
float u = (float)i / NX, cu = crop.X + u * crop.Z;
float px = (cu - 0.5f) * canvasW * s * sx * Facing;
var pos = new Vector3(baseX + px + lean + wob, Stage.FloorY + py * sy, 0);
_verts[j * (NX + 1) + i] = new VertexPositionColorTexture(pos, color, new Vector2(u, v));
}
}
}
void Mesh(GraphicsDevice gd, BasicEffect fx, Texture2D tex)
{
fx.Texture = tex;
foreach (var pass in fx.CurrentTechnique.Passes)
{
pass.Apply();
gd.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, _verts, 0, _verts.Length, Indices, 0, Indices.Length / 3);
}
}
}
}

169
Mono/Arena/HubScene.Gear.cs Normal file
View File

@@ -0,0 +1,169 @@
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
{
/// Ausrüstung: Inventar mit Detailkarte (anlegen, verkaufen), Händler und Schmied.
internal sealed partial class HubScene
{
long? _sel; // gewähltes Stück (Inventar oder angelegt)
double _sellAllArmed; // "Alle verkaufen": zweiter Klick innerhalb von 4 s
Item? Selected => _sel is long id ? _game.Inventory.FirstOrDefault(i => i.Id == id) ?? _game.Equipped.FirstOrDefault(i => i?.Id == id) : null;
bool SelectedEquipped => _sel is long id && _game.Equipped.Any(i => i?.Id == id);
// ── Kachel und Texte ────────────────────────────────────────
void ItemTile(SpriteBatch sb, RectangleF r, Item? it, bool selected)
{
D.Rect(sb, r, new Color(24, 18, 12) * (it == null ? 0.6f : 0.95f));
var col = it == null ? D.Border : RarityColor(it.Rarity);
if (it != null && Assets.Sprite(it.Def.Icon) is Texture2D icon)
sb.Draw(icon, r.Center, null, Color.White, 0, new Vector2(icon.Width / 2f, icon.Height / 2f), r.Width * 0.82f / icon.Width, SpriteEffects.None, 0);
if (it != null && it.Level > 0)
D.Text(sb, Assets.SansBold, 14, it.Level.ToString(NumberFormat.Culture), new Vector2(r.Right - 6, r.Bottom - 12), Color.White, Align.Right);
D.Frame(sb, r, selected ? Color.White : col, selected ? 3 : 2);
}
/// Hauptwirkung in einer Zeile (Schaden ×…, Leben ×…, Block …), so wie im Slot.
string ItemMain(Item it)
{
var d = it.Def;
double lv = it.EffLevel(_game.SlotLevels[(int)it.Slot]);
var parts = new List<string>();
if (d.Slot == ItemSlot.Shield) parts.Add(string.Format(L.t("item.stat.block"), NumberFormat.Percent(0.5 * lv / (lv + 8))));
if (d.DmgK > 0) parts.Add(string.Format(L.t("item.stat.damage"), NumberFormat.Mult(Math.Pow(Items.LEVEL_GROWTH, lv * d.DmgK))));
if (d.HpK > 0) parts.Add(string.Format(L.t("item.stat.health"), NumberFormat.Mult(Math.Pow(Items.LEVEL_GROWTH, lv * d.HpK))));
return string.Join(" · ", parts); // i18n-ok
}
static IEnumerable<string> ItemAffixes(Item it) => it.Affixes.Select(a => a.Kind == Affix.Agility
? string.Format(L.t("affix.agility"), a.Value.ToString("0.#", NumberFormat.Culture))
: string.Format(L.t("affix." + a.Kind.ToString().ToLowerInvariant()), NumberFormat.Percent(a.Value)));
/// Unterschied in der Kampfkraft, wenn das Stück angelegt würde.
(string, Color) PowerDelta(Item it)
{
double now = _game.Power(), with = _game.PowerWith(it), d = with / now - 1;
if (Math.Abs(d) < 0.005) return (L.t("item.same"), D.Dim);
string pct = (d > 0 ? "+" : "−") + NumberFormat.Percent(Math.Abs(d)); // i18n-ok
return (string.Format(L.t("item.power"), pct), d > 0 ? D.Green : D.Red);
}
// ── Inventar und Detailkarte (Gladiator-Schublade, rechts) ──
void DrawInventory(SpriteBatch sb, RectangleF area)
{
const int COLS = 5;
const float CELL = 76, GAP = 8;
D.Text(sb, Assets.SansBold, 20, string.Format(L.t("char.inventory"), _game.Inventory.Count, Items.INVENTORY),
new Vector2(area.X, area.Y), D.Sand);
// Alle verkaufen (mit Sicherheits-Klick)
_sellAllArmed = Math.Max(0, _sellAllArmed - 1 / 60.0);
bool armed = _sellAllArmed > 0;
string sellText = armed ? string.Format(L.t("char.sellall.confirm"), _game.Inventory.Count)
: string.Format(L.t("char.sellall"), NumberFormat.Format(_game.InventoryValue));
if (_ui.Button(sb, new RectangleF(area.X + 170, area.Y - 18, 250, 36), sellText, _game.Inventory.Count > 0,
selected: armed, size: armed ? 13 : 15, accent: armed ? D.Red : null))
{
if (!armed) _sellAllArmed = 4;
else
{
double got = _game.SellAll();
_sellAllArmed = 0;
if (_sel is long id && !_game.Equipped.Any(i => i?.Id == id)) _sel = null;
if (got > 0) SoundManager.PlayCoins();
}
}
for (int i = 0; i < Items.INVENTORY; i++)
{
var r = new RectangleF(area.X + i % COLS * (CELL + GAP), area.Y + 26 + i / COLS * (CELL + GAP), CELL, CELL);
var it = i < _game.Inventory.Count ? _game.Inventory[i] : null;
ItemTile(sb, r, it, it != null && _sel == it.Id);
if (it != null && (_ui.Hover(r) || false) && _ui.Hit(r)) _sel = it.Id;
}
// Detailkarte
var card = new RectangleF(area.X, area.Y + 26 + 6 * (CELL + GAP) + 10, COLS * (CELL + GAP) - GAP, area.Bottom - (area.Y + 26 + 6 * (CELL + GAP) + 10));
Ui.Panel(sb, card, D.Border, 0.9f);
var sel = Selected;
if (sel == null)
{
D.Text(sb, Assets.Sans, 18, L.t("char.pick"), card.Center, D.Dim, Align.Center);
return;
}
float x = card.X + 16, y = card.Y + 22;
D.Text(sb, Assets.SansBold, 22, ItemName(sel), new Vector2(x, y), RarityColor(sel.Rarity));
D.Text(sb, Assets.Sans, 16, L.t("rarity." + sel.Rarity.ToString().ToLowerInvariant()) + " · " + L.t("slot." + sel.Slot.ToString().ToLowerInvariant()),
new Vector2(x, y + 26), D.Dim); // i18n-ok
D.Text(sb, Assets.Sans, 17, ItemMain(sel), new Vector2(x, y + 54), D.Sand);
float ay = y + 80;
foreach (var a in ItemAffixes(sel)) { D.Text(sb, Assets.Sans, 16, a, new Vector2(x, ay), D.Blue); ay += 22; }
if (SelectedEquipped)
{
D.Text(sb, Assets.SansBold, 17, L.t("char.equipped"), new Vector2(card.Right - 16, y), D.Green, Align.Right);
return;
}
var (delta, dc) = PowerDelta(sel);
D.Text(sb, Assets.SansBold, 17, delta, new Vector2(card.Right - 16, y), dc, Align.Right);
float by = card.Bottom - 54, bw = (card.Width - 44) / 2;
if (_ui.Button(sb, new RectangleF(card.X + 16, by, bw, 42), L.t("char.equip"), size: 18, accent: D.Green))
if (_game.Equip(sel.Id)) SoundManager.PlayBlock();
if (_ui.Button(sb, new RectangleF(card.X + 28 + bw, by, bw, 42), string.Format(L.t("char.sell"), NumberFormat.Format(Items.SellValue(sel))), size: 16))
if (_game.Sell(sel.Id)) { SoundManager.PlayCoins(); _sel = null; }
}
// ── Forum: Händler (links) und Schmied (rechts) ─────────────
void DrawForum(SpriteBatch sb, RectangleF r)
{
float x = r.X + 30, y = r.Y + 40, w = 700;
D.Text(sb, Assets.Serif, 30, L.t("forum.tab.merchant"), new Vector2(x, y), D.Gold);
D.Text(sb, Assets.Sans, 16, string.Format(L.t("merchant.refresh"), NumberFormat.Duration(_game.MerchantRefreshIn)),
new Vector2(x + w, y), D.Dim, Align.Right);
D.Text(sb, Assets.Sans, 16, string.Format(L.t("merchant.bag"), _game.Inventory.Count, Items.INVENTORY), new Vector2(x + w, y + 24), D.Dim, Align.Right);
float ry = y + 50;
foreach (var it in _game.Merchant.ToList())
{
var row = new RectangleF(x, ry, w, 96);
D.Rect(sb, row, new Color(30, 22, 15) * 0.9f);
D.Frame(sb, row, RarityColor(it.Rarity), 2);
ItemTile(sb, new RectangleF(row.X + 10, row.Y + 10, 76, 76), it, false);
D.Text(sb, Assets.SansBold, 20, ItemName(it), new Vector2(row.X + 100, row.Y + 22), RarityColor(it.Rarity));
D.Text(sb, Assets.Sans, 15, ItemMain(it), new Vector2(row.X + 100, row.Y + 48), D.Sand);
string aff = string.Join(" · ", ItemAffixes(it)); // i18n-ok
if (aff.Length > 0) D.Text(sb, Assets.Sans, 14, aff, new Vector2(row.X + 100, row.Y + 72), D.Blue);
var (delta, dc) = PowerDelta(it);
D.Text(sb, Assets.SansBold, 15, delta, new Vector2(row.Right - 200, row.Y + 22), dc, Align.Right);
double price = Items.Value(it);
long id = it.Id;
if (_ui.Button(sb, new RectangleF(row.Right - 180, row.Y + 24, 166, 48), NumberFormat.Format(price),
_game.Gold >= price && _game.Inventory.Count < Items.INVENTORY, size: 19))
if (_game.BuyFromMerchant(id)) { SoundManager.PlayPurchase(); _sel = id; }
ry += 104;
}
// Schmied: Ausrüstungsplätze verstärken (wirkt auf jedes Stück im Platz)
float fx = x + w + 50, fw = r.Right - 30 - fx;
D.Text(sb, Assets.Serif, 30, L.t("forum.tab.forge"), new Vector2(fx, y), D.Gold);
for (int i = 0; i < 5; i++)
{
var slot = (ItemSlot)i;
var row = new RectangleF(fx, y + 50 + i * 104, fw, 96);
D.Rect(sb, row, new Color(30, 22, 15) * 0.9f);
D.Frame(sb, row, D.Border, 2);
ItemTile(sb, new RectangleF(row.X + 10, row.Y + 10, 76, 76), _game.Equipped[i], false);
D.Text(sb, Assets.SansBold, 20, L.t("slot." + slot.ToString().ToLowerInvariant()), new Vector2(row.X + 100, row.Y + 30), Color.White);
D.Text(sb, Assets.Sans, 16, string.Format(L.t("forge.level"), _game.SlotLevels[i]), new Vector2(row.X + 100, row.Y + 60), D.Sand);
double cost = _game.UpgradeSlotCost(slot);
if (_ui.Button(sb, new RectangleF(row.Right - 180, row.Y + 24, 166, 48), NumberFormat.Format(cost), _game.Gold >= cost, size: 19))
if (_game.UpgradeSlot(slot)) SoundManager.PlayLevelUp();
}
}
}
}

View File

@@ -0,0 +1,97 @@
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 + 40;
D.Text(sb, Assets.Serif, 30, L.t("char.skills"), new Vector2(x, y), D.Gold);
D.Text(sb, Assets.SansBold, 22, string.Format(L.t("char.skillpoints"), _game.SkillPoints),
new Vector2(x + 300, 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 + 60, rowH = 142;
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;
}
}
}
}

401
Mono/Arena/HubScene.cs Normal file
View File

@@ -0,0 +1,401 @@
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>
/// Arena zwischen den Kämpfen: der eigene Gladiator in der Arena, oben Stufe, Denare und Ruhm,
/// rechts die Gegner zur Wahl (leichter / ebenbürtig / stärker / Champion), unten Schubladen
/// für Gladiator und Ludus. Training und Einnahmen laufen weiter.
/// </summary>
internal sealed partial class HubScene
{
enum Drawer { None, Gladiator, Ludus, Forum, Skills }
readonly GameState _game;
readonly Ui _ui = new();
readonly Particles _fx = new();
readonly Crowd _crowd = new(11);
readonly FighterView _hero;
readonly DuelFighter _dummy = new() { IsPlayer = true, X = 0, Facing = 1, MaxHp = 1, Hp = 1 };
Texture2D? _backdrop;
string? _loopName;
int _arenaShown = -1;
double _t;
Drawer _drawer;
float _drawerK; // 0 zu, 1 offen (gleitet)
// Meldung nach dem Kampf
string[] _toast = Array.Empty<string>();
Color _toastColor;
double _toastAge = 99;
/// Gewählter Gegner (Kampf beginnt) — von außen abgeholt.
public Offer? Chosen { get; set; }
public HubScene(GameState game)
{
_game = game;
string hero = Art.Hero(game.Class, game.Look.Preset);
_hero = Assets.Has(hero) ? new FighterView(hero, 0.5f, game.Look.Color) : new FighterView(Art.Fighter(game.Class), 0.5f);
_hero.Preload();
_fx.Calm = AppSettings.ReduceMotion;
SoundManager.StartAmbient("music_ludus");
}
public void ShowResult(string[] lines, Color color)
{
_toast = lines; _toastColor = color; _toastAge = 0;
_crowd.Excite(color == D.Gold ? 0.8f : 0.1f);
}
void EnsureArena()
{
if (_arenaShown == _game.Arena) return;
_arenaShown = _game.Arena;
string art = Art.Arena(ArenaDef.All[_game.Arena]);
_backdrop = Assets.Sprite(art, "jpg");
_loopName = AppSettings.ReduceMotion ? null : art;
}
// ── Takt ────────────────────────────────────────────────────
public void Update(float dt, Input input, Matrix ui)
{
_t += dt;
_toastAge += dt;
_ui.Begin(input, ui);
_game.Tick(dt); // Training, Einnahmen, Erholung
_hero.Update(dt, dt, _dummy, 0, AppSettings.ReduceMotion);
_crowd.Update(dt);
_fx.Motes(AppSettings.ReduceMotion ? 0 : 50, Camera.W, Camera.H);
_fx.Update(dt);
float target = _drawer == Drawer.None ? 0 : 1;
_drawerK += (target - _drawerK) * (1 - MathF.Exp(-dt * 14));
if (input.Pressed(Microsoft.Xna.Framework.Input.Keys.Escape) && _drawer != Drawer.None) { _drawer = Drawer.None; input.PrevKeys = input.Keys; }
}
public bool DrawerOpen => _drawer != Drawer.None;
/// Testlauf: Schublade öffnen (0 zu, 1 Gladiator, 2 Ludus), sofort ganz offen.
public void DevOpen(int d)
{
_drawer = (Drawer)d; _drawerK = d == 0 ? 0 : 1;
if (d == 1 && _game.Inventory.Count > 0) _sel = _game.Inventory[0].Id;
}
// ── Zeichnen ────────────────────────────────────────────────
public void Draw(GraphicsDevice gd, SpriteBatch sb, BasicEffect fx, float scale, Vector2 offset)
{
EnsureArena();
D.UiScale = scale;
var ui = Matrix.CreateScale(scale) * Matrix.CreateTranslation(offset.X, offset.Y, 0);
// Arena im Hintergrund
sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, ui);
var loop = _loopName != null ? ClipCache.Video(_loopName) : null; // Standbild, bis der Film geladen ist
var bg = loop != null ? loop[PingPong(_t * 8, loop.Length)] : _backdrop;
if (bg != null)
{
float k = 1.12f * MathF.Max(Camera.W / bg.Width, Camera.H / bg.Height);
sb.Draw(bg, new Vector2(Camera.W / 2, Camera.H / 2), null, new Color(0.55f, 0.51f, 0.47f), 0,
new Vector2(bg.Width / 2f, bg.Height / 2f), k, SpriteEffects.None, 0);
}
D.Glow(sb, new Vector2(-200, Camera.H / 2), new Vector2(900, 2000), Color.Black * 0.7f);
D.Glow(sb, new Vector2(Camera.W + 200, Camera.H / 2), new Vector2(900, 2000), Color.Black * 0.6f);
D.Rect(sb, new RectangleF(0, 0, Camera.W, 120), Color.Black * 0.45f);
sb.End();
// Gladiator (links, in der Arena), Licht, Schatten
var view = Matrix.CreateTranslation(0, -Stage.FloorY, 0) * Matrix.CreateScale(1.1f) * Matrix.CreateTranslation(520, 930, 0) * ui;
sb.Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.LinearClamp, null, null, null, view);
D.Glow(sb, new Vector2(0, Stage.FloorY - 300), new Vector2(1000, 1100), new Color(255, 190, 120) * 0.14f);
D.Glow(sb, new Vector2(0, Stage.FloorY + 6), new Vector2(760, 130), new Color(255, 180, 110) * 0.22f);
sb.End();
sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, view);
_hero.DrawShadow(sb);
sb.End();
fx.View = view;
fx.Projection = Matrix.CreateOrthographicOffCenter(0, gd.Viewport.Width, gd.Viewport.Height, 0, 0, 1);
gd.BlendState = BlendState.AlphaBlend; gd.SamplerStates[0] = SamplerState.LinearClamp;
gd.RasterizerState = RasterizerState.CullNone; gd.DepthStencilState = DepthStencilState.None;
_hero.DrawBody(gd, fx, _dummy, AppSettings.ReduceMotion);
sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, ui * Matrix.Identity);
_crowd.Draw(sb, AppSettings.ReduceMotion);
sb.End();
sb.Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.LinearClamp, null, null, null, ui);
_fx.DrawAdd(sb);
sb.End();
sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, ui);
DrawTopBar(sb);
if (_drawerK < 0.98f) DrawOffers(sb);
DrawDrawerButtons(sb);
DrawToast(sb);
if (_drawerK > 0.01f) DrawDrawer(sb);
sb.End();
}
static int PingPong(double t, int n)
{
int period = 2 * (n - 1), i = (int)t % period;
return i < n ? i : period - i;
}
// ── Kopfleiste ──────────────────────────────────────────────
void DrawTopBar(SpriteBatch sb)
{
float x = 40;
if (Assets.Sprite(_game.Look.EmblemArt) is Texture2D em)
{
sb.Draw(em, new Vector2(x + 34, 60), null, Color.White, 0, new Vector2(em.Width / 2f, em.Height / 2f), 70f / em.Width, SpriteEffects.None, 0);
x += 80;
}
D.Text(sb, Assets.Serif, 32, $"{_game.Name} · {L.t(_game.ClassDef.Key)}", new Vector2(x, 42), D.Gold);
D.Text(sb, Assets.SansBold, 20, string.Format(L.t("char.level"), _game.CharLevel), new Vector2(x, 84), D.Sand);
D.Bar(sb, new RectangleF(x + 110, 74, 300, 20), (float)(_game.CharXp / _game.CharXpToNext), (float)(_game.CharXp / _game.CharXpToNext), D.Blue);
// Denare
float gx = 860;
if (Assets.Sprite("icon_denarius") is Texture2D coin)
sb.Draw(coin, new Vector2(gx, 60), null, Color.White, 0, new Vector2(coin.Width / 2f, coin.Height / 2f), 52f / coin.Width, SpriteEffects.None, 0);
D.Text(sb, Assets.SansBold, 30, NumberFormat.Format(_game.Gold), new Vector2(gx + 36, 52), Color.White);
if (_game.GoldPerSec > 0)
D.Text(sb, Assets.Sans, 17, string.Format(L.t("res.persec"), NumberFormat.Small(_game.GoldPerSec)), new Vector2(gx + 36, 86), D.Sand);
// Arena, Rang, Ruhm bis zum Champion
float rx = Camera.W - 40;
D.Text(sb, Assets.Serif, 28, L.t(ArenaDef.All[_game.Arena].Key), new Vector2(rx, 36), D.Gold, Align.Right);
D.Text(sb, Assets.Sans, 18, string.Format(L.t("arena.rank"), _game.Rank + 1, Balance.RANKS_PER_ARENA), new Vector2(rx - 440, 76), D.Sand);
D.Bar(sb, new RectangleF(rx - 300, 68, 300, 18), (float)(_game.FameRun / _game.FameRequired), (float)(_game.FameRun / _game.FameRequired), D.Gold);
D.Text(sb, Assets.Sans, 15, string.Format(L.t("arena.fame"), NumberFormat.Format(_game.FameRun), NumberFormat.Format(_game.FameRequired)),
new Vector2(rx - 150, 100), D.Dim, Align.Center);
}
// ── Gegner zur Wahl ─────────────────────────────────────────
void DrawOffers(SpriteBatch sb)
{
var offers = _game.Offers();
float w = offers.Count > 3 ? 220 : 270, gap = 20;
float total = offers.Count * w + (offers.Count - 1) * gap, x0 = Camera.W - 60 - total, y = 170, h = 650;
bool canFight = _game.CanFight;
for (int i = 0; i < offers.Count; i++)
{
var o = offers[i];
var r = new RectangleF(x0 + i * (w + gap), y, w, h);
bool champ = o.Kind == OfferKind.Champion, hover = canFight && _ui.Hover(r);
var accent = champ ? D.Gold : o.Kind == OfferKind.Hard ? D.Red : o.Kind == OfferKind.Easy ? D.Green : D.Sand;
Ui.Panel(sb, r, hover ? accent : champ ? D.Gold : D.Border, 0.84f);
if (champ) D.Glow(sb, r.Center, new Vector2(w * 1.6f, h * 1.2f), D.Gold * (0.08f + 0.04f * MathF.Sin((float)_t * 3)));
D.Text(sb, Assets.SansBold, 18, L.t(o.Key).ToUpperInvariant(), new Vector2(r.Center.X, r.Y + 24), accent, Align.Center);
// Gegner
string art = o.Enemy.Art ?? Art.Enemy(o.Enemy.NameKey);
if (Assets.Sprite(art) is Texture2D t)
{
float k = 300f / t.Height;
sb.Draw(t, new Vector2(r.Center.X, r.Y + 350), null, Color.White, 0, new Vector2(t.Width / 2f, Stage.Feet), k * 1.0f, SpriteEffects.FlipHorizontally, 0);
}
D.Text(sb, Assets.Serif, 24, o.Enemy.Name, new Vector2(r.Center.X, r.Y + 372), Color.White, Align.Center);
// Aussichten nach Kampfkraft
double ratio = _game.DuelRatio(o.Enemy);
var (odds, oc) = ratio >= 1.3 ? ("hub.odds.easy", D.Green) : ratio >= 0.85 ? ("hub.odds.even", D.Gold) : ("hub.odds.hard", D.Red);
D.Text(sb, Assets.SansBold, 17, L.t(odds), new Vector2(r.Center.X, r.Y + 404), oc, Align.Center);
// Lohn
var (gold, fame, xp) = _game.RewardPreview(o);
float ly = r.Y + 440;
Line(sb, r, ly, L.t("res.gold"), "+" + NumberFormat.Format(gold));
Line(sb, r, ly + 26, L.t("res.fame"), "+" + NumberFormat.Format(fame));
Line(sb, r, ly + 52, "XP", "+" + NumberFormat.Format(xp)); // i18n-ok
// Knöpfe
bool auto = _game.CanAutoWin(o);
var fb = new RectangleF(r.X + 16, r.Bottom - (auto ? 112 : 62), r.Width - 32, 48);
if (_ui.Button(sb, fb, L.t(champ ? "arena.challenge" : "hub.fight"), canFight, selected: champ, size: champ ? 18 : 22, accent: accent))
Chosen = o;
if (auto && _ui.Button(sb, new RectangleF(r.X + 16, r.Bottom - 58, r.Width - 32, 42), L.t("hub.auto"), canFight, size: 17))
{
var before = Snapshot();
_game.AutoWin(o);
ShowResult(ResultLines(before, true), D.Gold);
SoundManager.PlayCoins();
}
}
if (!canFight && _game.Recovery > 0)
{
var r = new RectangleF(x0, y + h / 2 - 50, total, 100);
D.Rect(sb, r, Color.Black * 0.7f);
D.Text(sb, Assets.Serif, 34, string.Format(L.t("arena.recover"), NumberFormat.Duration(_game.Recovery)), r.Center, D.Red, Align.Center);
}
}
static void Line(SpriteBatch sb, RectangleF r, float y, string label, string value)
{
D.Text(sb, Assets.Sans, 17, label, new Vector2(r.X + 20, y), D.Dim);
D.Text(sb, Assets.SansBold, 18, value, new Vector2(r.Right - 20, y), D.Sand, Align.Right);
}
// ── Ergebnis-Meldung ────────────────────────────────────────
/// Stand vor einem Kampf (für die Meldung danach).
public (double Gold, double Fame, double Xp, int Level, int Items) Snapshot() =>
(_game.Gold, _game.FameRun, _game.CharXp, _game.CharLevel, _game.Inventory.Count);
public string[] ResultLines((double Gold, double Fame, double Xp, int Level, int Items) before, bool won)
{
if (!won) return new[] { L.t("duel.lose"), L.t("hub.lost") };
var lines = new List<string>
{
L.t("duel.win"),
string.Format(L.t("hub.won"), NumberFormat.Format(_game.Gold - before.Gold), NumberFormat.Format(_game.FameRun - before.Fame))
};
if (_game.CharLevel > before.Level) lines.Add(string.Format(L.t("ludus.levelup"), _game.CharLevel));
if (_game.Inventory.Count > before.Items && _game.Inventory.Count > 0)
lines.Add(string.Format(L.t("hub.loot"), ItemName(_game.Inventory[^1])));
return lines.ToArray();
}
void DrawToast(SpriteBatch sb)
{
if (_toastAge > 4.5 || _toast.Length == 0 || _drawerK > 0.05f) return;
float a = (float)Math.Clamp(Math.Min(_toastAge * 4, (4.5 - _toastAge) * 2), 0, 1);
float pop = 1 + 0.25f * MathF.Max(0, 1 - (float)_toastAge * 5);
var c = new Vector2(520, 220);
D.Glow(sb, c + new Vector2(0, 40), new Vector2(900, 320), Color.Black * (0.6f * a));
D.Text(sb, Assets.Serif, 64, _toast[0], c, _toastColor * a, Align.Center, pop);
for (int i = 1; i < _toast.Length; i++)
D.Text(sb, Assets.SansBold, 24, _toast[i], c + new Vector2(0, 40 + i * 34), Color.White * a, Align.Center);
}
// ── Schubladen ──────────────────────────────────────────────
void DrawDrawerButtons(SpriteBatch sb)
{
float y = Camera.H - 92;
string gl = _game.AttrPoints > 0 ? $"{L.t("ludus.gladiator")} ({_game.AttrPoints})" : L.t("ludus.gladiator");
if (_ui.Button(sb, new RectangleF(40, y, 230, 60), gl, selected: _drawer == Drawer.Gladiator, size: 22,
accent: _game.AttrPoints > 0 ? D.Gold : null))
_drawer = _drawer == Drawer.Gladiator ? Drawer.None : Drawer.Gladiator;
if (_ui.Button(sb, new RectangleF(286, y, 230, 60), L.t("main.ludus"), selected: _drawer == Drawer.Ludus, size: 22))
_drawer = _drawer == Drawer.Ludus ? Drawer.None : Drawer.Ludus;
if (_ui.Button(sb, new RectangleF(532, y, 230, 60), L.t("main.shop"), selected: _drawer == Drawer.Forum, size: 22))
_drawer = _drawer == Drawer.Forum ? Drawer.None : Drawer.Forum;
int sp = _game.LearnablePoints;
string sk = sp > 0 ? $"{L.t("char.skills")} ({sp})" : L.t("char.skills");
if (_ui.Button(sb, new RectangleF(778, y, 230, 60), sk, selected: _drawer == Drawer.Skills, size: 22, accent: sp > 0 ? D.Gold : null))
_drawer = _drawer == Drawer.Skills ? Drawer.None : Drawer.Skills;
}
void DrawDrawer(SpriteBatch sb)
{
float w = _drawer == Drawer.Ludus ? 820 : 1300, x = -w + (w + 40) * Ease(_drawerK);
var r = new RectangleF(x, 140, w, Camera.H - 260);
Ui.Panel(sb, r, D.Gold, 0.94f);
if (_drawer == Drawer.Gladiator) DrawGladiator(sb, r);
else if (_drawer == Drawer.Ludus) DrawLudus(sb, r);
else if (_drawer == Drawer.Forum) DrawForum(sb, r);
else if (_drawer == Drawer.Skills) DrawSkills(sb, r);
}
static float Ease(float k) => 1 - (1 - k) * (1 - k);
void DrawGladiator(SpriteBatch sb, RectangleF r)
{
float x = r.X + 30, y = r.Y + 40;
D.Text(sb, Assets.Serif, 30, $"{_game.Name} · {L.t(_game.ClassDef.Key)}", new Vector2(x, y), D.Gold);
D.Text(sb, Assets.SansBold, 20, string.Format(L.t("char.power"), NumberFormat.Format(_game.Power())), new Vector2(x + 700, y), D.Sand, Align.Right);
// Werte mit Attributpunkten
y += 50;
D.Text(sb, Assets.SansBold, 20, string.Format(L.t("char.points"), _game.AttrPoints), new Vector2(x, y), _game.AttrPoints > 0 ? D.Gold : D.Dim);
for (int i = 0; i < 4; i++)
{
var s = (Stat)i;
float ry = y + 44 + i * 44;
D.Text(sb, Assets.Sans, 21, L.t(TextKeys.Of(s)), new Vector2(x, ry), D.Sand);
D.Text(sb, Assets.SansBold, 22, _game.Level(s).ToString(NumberFormat.Culture), new Vector2(x + 300, ry), Color.White, Align.Right);
if (_ui.Button(sb, new RectangleF(x + 320, ry - 17, 44, 34), "+", _game.AttrPoints > 0, size: 22)) // i18n-ok
_game.SpendPoint(s);
}
// Kampfwerte
var c = _game.PlayerCombat();
float cx = x + 420;
Stat2(sb, cx, y + 44, L.t("ludus.hp"), NumberFormat.Format(c.MaxHp));
Stat2(sb, cx, y + 88, L.t("ludus.damage"), NumberFormat.Format(c.Damage));
Stat2(sb, cx, y + 132, L.t("ludus.crit"), NumberFormat.Percent(c.Crit));
// Ausrüstung
y += 240;
if (_ui.Button(sb, new RectangleF(x + 480, y - 22, 220, 44), L.t("char.equipbest"), size: 18))
{
if (_game.EquipBest() > 0) SoundManager.PlayPurchase();
}
for (int i = 0; i < 5; i++)
{
var slot = (ItemSlot)i;
var it = _game.Equipped[i];
float ry = y + 40 + i * 74;
var row = new RectangleF(x, ry, 700, 66);
D.Rect(sb, row, new Color(30, 22, 15) * 0.9f);
D.Frame(sb, row, it == null ? D.Border : RarityColor(it.Rarity), 2);
if (it != null && Assets.Sprite(it.Def.Icon) is Texture2D icon)
sb.Draw(icon, new Vector2(row.X + 36, row.Center.Y), null, Color.White, 0, new Vector2(icon.Width / 2f, icon.Height / 2f), 56f / icon.Width, SpriteEffects.None, 0);
D.Text(sb, Assets.Sans, 16, L.t("slot." + slot.ToString().ToLowerInvariant()), new Vector2(row.X + 76, row.Y + 18), D.Dim);
D.Text(sb, Assets.SansBold, 20, it == null ? "–" : ItemName(it), new Vector2(row.X + 76, row.Y + 44), it == null ? D.Dim : RarityColor(it.Rarity)); // i18n-ok
if (it != null && _sel == it.Id) D.Frame(sb, row, Color.White, 3);
if (it != null && _ui.Hit(row)) _sel = it.Id;
}
DrawInventory(sb, new RectangleF(r.X + 790, r.Y + 30, 430, r.Height - 60));
}
static void Stat2(SpriteBatch sb, float x, float y, string label, string value)
{
D.Text(sb, Assets.Sans, 19, label, new Vector2(x, y), D.Dim);
D.Text(sb, Assets.SansBold, 21, value, new Vector2(x + 320, y), Color.White, Align.Right);
}
void DrawLudus(SpriteBatch sb, RectangleF r)
{
float x = r.X + 30, y = r.Y + 40;
D.Text(sb, Assets.Serif, 30, L.t("main.ludus"), new Vector2(x, y), D.Gold);
y += 40;
foreach (var u in UpgradeDef.All)
{
var row = new RectangleF(x, y, r.Width - 60, 84);
D.Rect(sb, row, new Color(30, 22, 15) * 0.9f);
D.Frame(sb, row, D.Border, 2);
if (Assets.Sprite(Art.Upgrade(u)) is Texture2D icon)
sb.Draw(icon, new Vector2(row.X + 42, row.Center.Y), null, Color.White, 0, new Vector2(icon.Width / 2f, icon.Height / 2f), 64f / icon.Width, SpriteEffects.None, 0);
int level = _game.UpgradeLevel(u.Id);
D.Text(sb, Assets.SansBold, 21, L.t(u.Key), new Vector2(row.X + 86, row.Y + 24), Color.White);
D.Text(sb, Assets.Sans, 17, string.Format(L.t("ludus.level"), level), new Vector2(row.X + 86, row.Y + 56), D.Sand);
string desc = u.Stat is Stat s ? string.Format(L.t("upgrade.trainer.desc"), L.t(TextKeys.Of(s))) : L.t(u.Key + ".desc");
D.Text(sb, Assets.Sans, 15, desc.Length > 52 ? desc[..50] + "…" : desc, new Vector2(row.X + 200, row.Y + 56), D.Dim); // i18n-ok
double cost = _game.UpgradeCost(u.Id);
if (_ui.Button(sb, new RectangleF(row.Right - 200, row.Y + 16, 184, 52), NumberFormat.Format(cost), _game.Gold >= cost, size: 20))
if (_game.Buy(u.Id)) SoundManager.PlayPurchase();
y += 92;
}
}
public static string ItemName(Item it) => L.t(it.Def.Key) + (it.Level > 0 ? $" +{it.Level}" : ""); // i18n-ok
static Color RarityColor(Rarity r) => r switch
{
Rarity.Good => new Color(110, 200, 90), Rarity.Rare => new Color(90, 160, 240),
Rarity.Epic => new Color(185, 110, 235), Rarity.Legendary => new Color(250, 160, 40),
_ => new Color(190, 175, 150)
};
}
}

186
Mono/Arena/IntroScene.cs Normal file
View File

@@ -0,0 +1,186 @@
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
{
/// <summary>
/// Intro als kurzer Film: Schwarz mit Glut → erster Satz → fünf Kapitel (Wan-Clips mit
/// Kamerafahrt, Kinobalken, Untertitel, Erzählstimme) → Titel mit Schlusssatz → "Weiter".
/// Die Kapitellänge richtet sich nach den gesprochenen Sätzen. Überspringen jederzeit.
/// </summary>
internal sealed class IntroScene
{
public static readonly string[] Scenes = { "intro_village", "intro_chains", "intro_market", "intro_ludus", "intro_colosseum" };
static bool Voiced => SoundManager.Enabled && AppSettings.Narration;
static float Longest(params string[] keys) => Voiced ? keys.Max(k => SoundManager.VoiceSeconds(k)) : 0f;
const float LINE1_AT = 1.2f, FADE_OUT = 0.6f;
readonly float _lineLen, _storyAt, _chapter, _storyEnd, _titleAt, _promptAt, _autoClose;
readonly (float At, string Key)[] _voice;
readonly Ui _ui = new();
readonly Particles _fx = new();
readonly Texture2D? _finale = Assets.Sprite("intro_colosseum", "jpg");
float _t, _closeAt = -1;
int _voicePlayed;
public bool Done { get; private set; }
public IntroScene()
{
_lineLen = Math.Max(4.5f, 0.2f + SoundManager.VoiceDelay(0) + Longest("intro.line1") + 1.2f);
_storyAt = LINE1_AT + _lineLen;
_chapter = Math.Max(6.0f, 0.4f + SoundManager.VoiceDelay(0)
+ Longest(Enumerable.Range(1, Scenes.Length).Select(i => $"intro.story.{i}").ToArray()) + 1.4f);
_storyEnd = _storyAt + Scenes.Length * _chapter;
_titleAt = _storyEnd + 0.3f;
_promptAt = _titleAt + Math.Max(4f, Longest("intro.line2") + 2.2f);
_autoClose = _promptAt + 12f;
_voice = Enumerable.Range(0, Scenes.Length)
.Select(i => (_storyAt + i * _chapter + 0.4f, $"intro.story.{i + 1}"))
.Prepend((LINE1_AT + 0.1f, "intro.line1"))
.Append((_titleAt + 1.2f, "intro.line2"))
.ToArray();
SoundManager.PreloadVoice(_voice.Select(v => v.Key));
foreach (var s in Scenes) ClipCache.Video(s);
SoundManager.PlayMusic("music_intro", loop: false);
}
/// Testläufe: Zeitpunkte zum Aufnehmen (erster Satz, Mitte jedes Kapitels, Titel).
public float[] CaptureTimes() =>
new[] { LINE1_AT + 2f }.Concat(Enumerable.Range(0, Scenes.Length).Select(i => _storyAt + (i + 0.55f) * _chapter)).Append(_promptAt + 0.5f).ToArray();
public float Time { get => _t; set => _t = value; }
void Close()
{
SoundManager.StopVoice();
if (_closeAt < 0) _closeAt = _t;
}
public void Update(float dt, Input input, Matrix ui)
{
_t += dt;
_ui.Begin(input, ui);
while (_closeAt < 0 && _voicePlayed < _voice.Length && _t >= _voice[_voicePlayed].At)
SoundManager.PlayVoice(_voice[_voicePlayed++].Key);
if (input.Pressed(Microsoft.Xna.Framework.Input.Keys.Escape) || input.Pressed(Microsoft.Xna.Framework.Input.Keys.Enter)
|| input.Pressed(Microsoft.Xna.Framework.Input.Keys.Space)) Close();
if (_closeAt < 0 && _t >= _autoClose) Close();
if (_closeAt >= 0 && _t - _closeAt >= FADE_OUT) Done = true;
_fx.Motes(AppSettings.ReduceMotion ? 0 : 60, Camera.W, Camera.H);
_fx.Update(dt);
}
// ── Zeichnen ────────────────────────────────────────────────
public void Draw(SpriteBatch sb, float scale, Vector2 offset)
{
D.UiScale = scale;
var ui = Matrix.CreateScale(scale) * Matrix.CreateTranslation(offset.X, offset.Y, 0);
sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, ui);
if (_t < _storyAt) DrawLine(sb, L.t("intro.line1"), (_t - LINE1_AT) / _lineLen);
else if (_t < _storyEnd) DrawStory(sb);
else DrawFinale(sb);
sb.End();
if (_t < _storyAt || _t >= _storyEnd)
{
sb.Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.LinearClamp, null, null, null, ui);
_fx.DrawAdd(sb);
sb.End();
}
sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, ui);
DrawSkip(sb);
if (_closeAt >= 0) D.Rect(sb, new RectangleF(0, 0, Camera.W, Camera.H), Color.Black * Clamp01((_t - _closeAt) / FADE_OUT));
sb.End();
}
static void DrawLine(SpriteBatch sb, string text, float p)
{
if (p <= 0 || p >= 1) return;
float a = EaseOut(Clamp01(p < 0.2f ? p / 0.2f : p > 0.8f ? (1 - p) / 0.2f : 1));
D.Text(sb, Assets.Serif, 50, text, new Vector2(Camera.W / 2, Camera.H * 0.45f - p * 20), new Color(240, 222, 186) * a, Align.Center);
}
void DrawStory(SpriteBatch sb)
{
float local = _t - _storyAt;
int idx = Math.Min(Scenes.Length - 1, (int)(local / _chapter));
float p = (local - idx * _chapter) / _chapter;
// Clip "cover" auf 110 %, langsame Kamerafahrt abwechselnd nach links/rechts
var frames = ClipCache.Video(Scenes[idx]);
var tex = frames != null ? frames[Math.Min(frames.Length - 1, (int)(p * (frames.Length - 1)))] : Assets.Sprite(Scenes[idx], "jpg");
if (tex != null)
{
float k = 1.1f * MathF.Max(Camera.W / tex.Width, Camera.H / tex.Height);
float e = EaseInOut(p), over = tex.Width * k - Camera.W;
float x = -over * (idx % 2 == 0 ? e : 1 - e);
sb.Draw(tex, new Vector2(x, (Camera.H - tex.Height * k) / 2), null, Color.White, 0, Vector2.Zero, k, SpriteEffects.None, 0);
}
// Kinobalken, Abblende zwischen den Kapiteln
float barIn = Clamp01(local / 0.6f) * Clamp01((_storyEnd - _t) / 0.6f);
float bar = Camera.H * 0.11f * EaseOut(barIn);
D.Rect(sb, new RectangleF(0, 0, Camera.W, bar), Color.Black);
D.Rect(sb, new RectangleF(0, Camera.H - bar, Camera.W, bar), Color.Black);
float dip = p < 0.1f ? 1 - p / 0.1f : p > 0.92f ? (p - 0.92f) / 0.08f : 0f;
if (dip > 0) D.Rect(sb, new RectangleF(0, 0, Camera.W, Camera.H), Color.Black * Clamp01(dip));
// Kapitel und Satz im unteren Drittel
float ta = Clamp01((p - 0.1f) / 0.12f) * Clamp01((0.92f - p) / 0.08f);
if (ta <= 0) return;
D.Glow(sb, new Vector2(Camera.W / 2, Camera.H * 0.78f), new Vector2(Camera.W * 1.6f, Camera.H * 0.6f), Color.Black * (0.75f * ta));
D.Text(sb, Assets.Serif, 26, $"{idx + 1} / {Scenes.Length} · {L.t($"intro.chapter.{idx + 1}").ToUpperInvariant()}", // i18n-ok
new Vector2(Camera.W / 2, Camera.H * 0.665f), D.Gold * ta, Align.Center);
DrawCentered(sb, L.t($"intro.story.{idx + 1}"), Camera.H * 0.745f, 42, new Color(245, 236, 214) * ta);
}
/// Satz zentriert, bei Bedarf auf zwei Zeilen umbrochen.
static void DrawCentered(SpriteBatch sb, string text, float y, float px, Color c)
{
float max = Camera.W * 0.8f;
if (D.Measure(Assets.Serif, px, text).X <= max) { D.Text(sb, Assets.Serif, px, text, new Vector2(Camera.W / 2, y), c, Align.Center); return; }
var words = text.Split(' ');
int split = words.Length / 2;
for (int i = 1; i < words.Length; i++)
if (D.Measure(Assets.Serif, px, string.Join(' ', words[..i])).X > max * 0.55f) { split = i; break; }
D.Text(sb, Assets.Serif, px, string.Join(' ', words[..split]), new Vector2(Camera.W / 2, y - px * 0.6f), c, Align.Center);
D.Text(sb, Assets.Serif, px, string.Join(' ', words[split..]), new Vector2(Camera.W / 2, y + px * 0.6f), c, Align.Center);
}
void DrawFinale(SpriteBatch sb)
{
float bg = Clamp01((_t - _storyEnd) / 1.2f);
if (_finale != null)
{
float k = 1.08f * MathF.Max(Camera.W / _finale.Width, Camera.H / _finale.Height);
sb.Draw(_finale, new Vector2(Camera.W / 2, Camera.H / 2), null, new Color(0.5f, 0.47f, 0.43f) * bg, 0,
new Vector2(_finale.Width / 2f, _finale.Height / 2f), k, SpriteEffects.None, 0);
}
float p = Clamp01((_t - _titleAt) / 1.0f);
if (p <= 0) return;
float e = EaseOut(p);
D.Glow(sb, new Vector2(Camera.W / 2, Camera.H * 0.36f), new Vector2(1600, 420), D.Gold * (0.12f * e));
D.Text(sb, Assets.Serif, 130, L.t("app.title").ToUpperInvariant(), new Vector2(Camera.W / 2, Camera.H * 0.36f), D.Gold * e, Align.Center, 1.3f - 0.3f * e);
float lp = Clamp01((_t - _titleAt - 1.2f) / 0.8f);
DrawCentered(sb, L.t("intro.line2"), Camera.H * 0.62f, 38, new Color(245, 236, 214) * lp);
}
void DrawSkip(SpriteBatch sb)
{
if (_t < 1f || _closeAt >= 0) return;
bool end = _t >= _promptAt;
var r = new RectangleF(Camera.W - 300, Camera.H - 100, 260, 60);
if (_ui.Button(sb, r, L.t(end ? "intro.continue" : "intro.skip"), selected: end, size: 22)) Close();
}
static float Clamp01(float v) => v < 0 ? 0 : v > 1 ? 1 : v;
static float EaseOut(float v) => 1 - MathF.Pow(1 - v, 3);
static float EaseInOut(float v) => v < 0.5f ? 2 * v * v : 1 - MathF.Pow(-2 * v + 2, 2) / 2;
}
}

92
Mono/Arena/MenuScene.cs Normal file
View File

@@ -0,0 +1,92 @@
using System;
using GladiatorIdle.Gfx;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using D = GladiatorIdle.Gfx.Draw;
namespace GladiatorIdle.Arena
{
/// <summary>
/// Startmenü: Kolosseum im Morgenlicht, Titel, Weiterspielen / Neuer Gladiator (mit zweitem
/// Klick zur Sicherheit, wenn ein Spielstand da ist) / Intro / Einstellungen / Beenden.
/// </summary>
internal sealed class MenuScene
{
public enum Choice { None, Continue, New, Intro, Settings, Quit }
readonly Ui _ui = new();
readonly Particles _fx = new();
readonly Texture2D? _backdrop = Assets.Sprite("intro_colosseum", "jpg");
readonly bool _hasSave;
readonly int _freedoms;
double _t, _armNew;
public Choice Picked { get; set; }
public MenuScene(bool hasSave, int freedoms)
{
_hasSave = hasSave;
_freedoms = freedoms;
SoundManager.StartAmbient("music_menu");
// Intro-Clips schon jetzt im Hintergrund laden
foreach (var s in IntroScene.Scenes) ClipCache.Video(s);
}
public void Update(float dt, Input input, Matrix ui, bool overlay)
{
_t += dt;
_armNew = Math.Max(0, _armNew - dt);
if (!overlay) _ui.Begin(input, ui); else _ui.Click = false;
_fx.Motes(AppSettings.ReduceMotion ? 0 : 70, Camera.W, Camera.H);
_fx.Update(dt);
}
public void Draw(SpriteBatch sb, float scale, Vector2 offset)
{
D.UiScale = scale;
var ui = Matrix.CreateScale(scale) * Matrix.CreateTranslation(offset.X, offset.Y, 0);
sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, ui);
if (_backdrop != null)
{
// langsames Heranfahren
float k = (1.08f + 0.03f * (float)Math.Sin(_t * 0.05)) * MathF.Max(Camera.W / _backdrop.Width, Camera.H / _backdrop.Height);
sb.Draw(_backdrop, new Vector2(Camera.W / 2, Camera.H / 2), null, new Color(0.62f, 0.58f, 0.54f), 0,
new Vector2(_backdrop.Width / 2f, _backdrop.Height / 2f), k, SpriteEffects.None, 0);
}
D.Glow(sb, new Vector2(Camera.W / 2, Camera.H / 2), new Vector2(Camera.W * 0.9f, Camera.H * 1.2f), Color.Black * 0.35f);
D.Glow(sb, new Vector2(-200, Camera.H / 2), new Vector2(900, 2000), Color.Black * 0.8f);
D.Glow(sb, new Vector2(Camera.W + 200, Camera.H / 2), new Vector2(900, 2000), Color.Black * 0.8f);
sb.End();
sb.Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.LinearClamp, null, null, null, ui);
_fx.DrawAdd(sb);
D.Glow(sb, new Vector2(Camera.W / 2, 230), new Vector2(1500, 420), D.Gold * 0.10f);
sb.End();
sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, ui);
float appear = MathHelper.Clamp((float)_t / 0.8f, 0, 1);
D.Text(sb, Assets.Serif, 120, L.t("app.title").ToUpperInvariant(), new Vector2(Camera.W / 2, 220), D.Gold * appear, Align.Center, 1.06f - 0.06f * appear);
D.Text(sb, Assets.Serif, 32, L.t("start.subtitle"), new Vector2(Camera.W / 2, 320), D.Sand * appear, Align.Center);
float w = 520, h = 74, x = (Camera.W - w) / 2, y = 430;
if (_hasSave && _ui.Button(sb, new RectangleF(x, y, w, h), L.t("menu.continue"), selected: true, size: 30)) Picked = Choice.Continue;
if (_hasSave) y += h + 18;
string newText = _armNew > 0 ? L.t("menu.new.confirm") : L.t("menu.new");
if (_ui.Button(sb, new RectangleF(x, y, w, h), newText, selected: !_hasSave, size: _armNew > 0 ? 18 : 28, accent: _armNew > 0 ? D.Red : null))
{
if (!_hasSave || _armNew > 0) Picked = Choice.New;
else _armNew = 4; // zweiter Klick innerhalb von 4 s
}
y += h + 18;
if (_ui.Button(sb, new RectangleF(x, y, w, h), L.t("menu.intro"), size: 26)) Picked = Choice.Intro;
y += h + 18;
if (_ui.Button(sb, new RectangleF(x, y, w, h), L.t("main.settings"), size: 26)) Picked = Choice.Settings;
y += h + 18;
if (_ui.Button(sb, new RectangleF(x, y, w, h), L.t("main.quit"), size: 26)) Picked = Choice.Quit;
if (_freedoms > 0)
D.Text(sb, Assets.Serif, 22, string.Format(L.t("menu.freedoms"), _freedoms), new Vector2(Camera.W / 2, y + h + 50), D.Gold, Align.Center);
D.Text(sb, Assets.Sans, 16, $"{Credits.COPYRIGHT} · {Credits.DISCORD}", new Vector2(Camera.W / 2, Camera.H - 30), D.Dim, Align.Center); // i18n-ok
sb.End();
}
}
}

View File

@@ -0,0 +1,150 @@
using System;
using GladiatorIdle.Gfx;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using D = GladiatorIdle.Gfx.Draw;
namespace GladiatorIdle.Arena
{
/// <summary>
/// Test: ein Gladiator als 3D-Modell (Mixamo-Bewegungen) vor der Arena. Start mit --model3d.
/// Pfeile/1–9: Bewegung, Leertaste: anhalten, Maus ziehen: drehen, Rad: Abstand,
/// V: Ansicht (vorn / schräg / Duell-Seite), T: Teamfarbe, Esc: beenden.
/// </summary>
internal sealed class ModelTestScene
{
public readonly Model3D? Model;
readonly BasicEffect _fx;
readonly Texture2D? _backdrop;
public int ClipIndex;
public float Time, Yaw, Distance = 520;
public bool Paused;
public int Color = -1;
float _blend = 1;
int _lastX = -1;
int _prevWheel;
static readonly float[] Views = { 0, MathHelper.ToRadians(35), MathHelper.ToRadians(90) };
int _view;
Matrix? _fit; // Modell in Zentimeter, Füße auf dem Boden (aus der ersten Haltung)
public ModelTestScene(GraphicsDevice gd)
{
// --model=<name>: andere Figur ansehen (Standard: hero_murmillo_1)
string name = Array.Find(Environment.GetCommandLineArgs(), x => x.StartsWith("--model="))?[8..] ?? "hero_murmillo_1";
Model = Model3D.Load(gd, name);
Model?.AddSword();
Model?.AddShield();
_backdrop = Assets.Sprite("arena_colosseum", "jpg");
_fx = new BasicEffect(gd) { VertexColorEnabled = true, LightingEnabled = true, PreferPerPixelLighting = true };
_fx.AmbientLightColor = new Vector3(0.42f, 0.38f, 0.36f);
_fx.DirectionalLight0.Enabled = true;
_fx.DirectionalLight0.Direction = Vector3.Normalize(new Vector3(-0.4f, -0.7f, -0.6f));
_fx.DirectionalLight0.DiffuseColor = new Vector3(0.95f, 0.85f, 0.72f);
_fx.DirectionalLight0.SpecularColor = new Vector3(0.25f, 0.22f, 0.2f);
_fx.DirectionalLight1.Enabled = true; // kühles Gegenlicht von hinten links
_fx.DirectionalLight1.Direction = Vector3.Normalize(new Vector3(0.7f, -0.2f, 0.7f));
_fx.DirectionalLight1.DiffuseColor = new Vector3(0.25f, 0.3f, 0.4f);
_fx.DirectionalLight2.Enabled = false;
_fx.SpecularPower = 24;
Yaw = Views[1];
_view = 1;
}
public Model3D.Clip? Clip => Model != null && Model.Clips.Count > 0 ? Model.Clips[ClipIndex % Model.Clips.Count] : null;
public void Play(int index)
{
if (Model == null || Model.Clips.Count == 0) return;
ClipIndex = (index % Model.Clips.Count + Model.Clips.Count) % Model.Clips.Count;
Time = 0;
Model.BeginBlend();
_blend = 0;
}
public void SetView(int v) { _view = v % Views.Length; Yaw = Views[_view]; }
public void Update(float dt, Input input)
{
if (Model == null) return;
if (input.Pressed(Keys.Right)) Play(ClipIndex + 1);
if (input.Pressed(Keys.Left)) Play(ClipIndex - 1);
for (int k = 0; k < 9; k++) if (input.Pressed(Keys.D1 + k)) Play(k);
if (input.Pressed(Keys.Space)) Paused = !Paused;
if (input.Pressed(Keys.V)) SetView(_view + 1);
if (input.Pressed(Keys.T)) Color = Color + 1 >= Appearance.Colors.Length ? -1 : Color + 1;
// drehen mit gedrückter linker Maustaste, Abstand mit dem Rad
if (input.Mouse.LeftButton == ButtonState.Pressed)
{
if (_lastX >= 0) Yaw += (input.Mouse.X - _lastX) * 0.01f;
_lastX = input.Mouse.X;
}
else _lastX = -1;
int wheel = input.Mouse.ScrollWheelValue;
Distance = MathHelper.Clamp(Distance - (wheel - _prevWheel) * 0.3f, 200, 1200);
_prevWheel = wheel;
if (!Paused) Time += dt;
_blend = Math.Min(1, _blend + dt / 0.15f);
Model.SetColor(Color);
}
public void Draw(GraphicsDevice gd, SpriteBatch sb, float scale, Vector2 offset)
{
var vp = gd.Viewport;
sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp);
if (_backdrop != null)
{
float k = MathF.Max(vp.Width / (float)_backdrop.Width, vp.Height / (float)_backdrop.Height);
sb.Draw(_backdrop, new Vector2(vp.Width / 2f, vp.Height / 2f), null, new Color(0.55f, 0.52f, 0.5f), 0,
new Vector2(_backdrop.Width / 2f, _backdrop.Height / 2f), k, SpriteEffects.None, 0);
}
sb.End();
if (Model == null || Clip is not Model3D.Clip clip)
{
sb.Begin(transformMatrix: Matrix.CreateScale(scale) * Matrix.CreateTranslation(offset.X, offset.Y, 0));
D.Text(sb, Assets.SansBold, 30, L.t("model3d.missing"), new Vector2(Camera.W / 2, Camera.H / 2), Microsoft.Xna.Framework.Color.White, Align.Center);
sb.End();
return;
}
bool loop = clip.Name is "idle" or "walk" or "run" or "blockidle" or "strafe"; // i18n-ok
Model.Pose(clip, Time, loop, _blend);
var target = new Vector3(0, 95, 0);
var view = Matrix.CreateLookAt(target + new Vector3(0, 25, Distance), target, Vector3.Up);
var proj = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(32), vp.AspectRatio, 10, 5000);
if (_fit == null && _blend >= 1)
{
// robuste Grenzen (einzelne Ausreißer-Punkte verschieben sonst Boden und Größe)
float Q(Func<Vector3, float> axis, float q)
{
var a = Array.ConvertAll(Model.Vertices, v => axis(v.Position));
Array.Sort(a);
return a[(int)(q * (a.Length - 1))];
}
float y0 = Q(p => p.Y, 0.002f), y1 = Q(p => p.Y, 0.998f);
float cx = (Q(p => p.X, 0.01f) + Q(p => p.X, 0.99f)) / 2, cz = (Q(p => p.Z, 0.01f) + Q(p => p.Z, 0.99f)) / 2;
_fit = Matrix.CreateTranslation(-cx, -y0, -cz) * Matrix.CreateScale(180 / MathF.Max(1e-3f, y1 - y0));
DevShot.Log($"model3d fit: unit {Model.Unit} feet {y0:0.0} top {y1:0.0}");
}
var world = (_fit ?? Matrix.Identity) * Matrix.CreateRotationY(Yaw);
// Schatten unter den Füßen
var feet = vp.Project(Vector3.Zero, proj, view, world);
var side = vp.Project(new Vector3(60, 0, 0), proj, view, Matrix.Identity);
float w = MathF.Abs(side.X - vp.Project(Vector3.Zero, proj, view, Matrix.Identity).X) * 2.4f;
sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
D.Glow(sb, new Vector2(feet.X, feet.Y), new Vector2(w, w * 0.22f), Microsoft.Xna.Framework.Color.Black * 0.7f);
sb.End();
_fx.World = world; _fx.View = view; _fx.Projection = proj;
Model.Draw(gd, _fx);
sb.Begin(transformMatrix: Matrix.CreateScale(scale) * Matrix.CreateTranslation(offset.X, offset.Y, 0));
string info = $"{ClipIndex + 1}/{Model.Clips.Count} {clip.Name} {Time % MathF.Max(clip.Length, 0.01f):0.00}/{clip.Length:0.00} s"; // i18n-ok
D.Text(sb, Assets.SansBold, 26, info, new Vector2(40, 40), D.Gold);
D.Text(sb, Assets.Sans, 18, L.t("model3d.help"), new Vector2(40, 80), D.Sand);
sb.End();
}
}
}

136
Mono/Arena/Particles.cs Normal file
View File

@@ -0,0 +1,136 @@
using System;
using System.Collections.Generic;
using GladiatorIdle.Gfx;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace GladiatorIdle.Arena
{
internal enum PKind { Spark, Dust, Mote, Ring, Chip }
/// <summary>Funken (gestreckt, additiv), Sand/Staub (weich), Schwebstaub im Licht, Ringe, Splitter.</summary>
internal sealed class Particles
{
struct P
{
public PKind Kind;
public Vector2 Pos, Vel;
public float Age, Life, Size, Grow, Gravity, Drag, Rot, Spin;
public Color Color;
}
readonly List<P> _list = new(2048);
readonly Random _rng = new();
public bool Calm;
float R(float a, float b) => a + (float)_rng.NextDouble() * (b - a);
public void Sparks(Vector2 at, int n, Color c, float dir = 0, float spread = MathF.PI, float speed = 900)
{
if (Calm) n /= 3;
for (int i = 0; i < n; i++)
{
float a = dir + R(-spread, spread), v = R(0.3f, 1f) * speed;
_list.Add(new P { Kind = PKind.Spark, Pos = at, Vel = new Vector2(MathF.Cos(a), MathF.Sin(a)) * v - new Vector2(0, R(100, 300)),
Life = R(0.18f, 0.45f), Size = R(2.5f, 5f), Gravity = 1600, Drag = 2.5f, Color = c });
}
}
public void Dust(Vector2 at, int n, float spread = 60, float rise = 60, float size = 60)
{
if (Calm) n /= 2;
for (int i = 0; i < n; i++)
_list.Add(new P { Kind = PKind.Dust, Pos = at + new Vector2(R(-spread, spread), R(-8, 4)),
Vel = new Vector2(R(-120, 120), -R(10, rise)), Life = R(0.5f, 1.1f), Size = R(0.6f, 1f) * size,
Grow = size * 1.2f, Drag = 2.2f, Color = new Color(150, 120, 85) * 0.55f });
}
public void Chips(Vector2 at, int n, Color c, int facing)
{
if (Calm) n /= 2;
for (int i = 0; i < n; i++)
_list.Add(new P { Kind = PKind.Chip, Pos = at, Vel = new Vector2(facing * R(150, 650), -R(250, 750)), Life = R(0.5f, 0.9f),
Size = R(4, 9), Gravity = 2000, Drag = 0.6f, Rot = R(0, 6), Spin = R(-20, 20), Color = c });
}
public void Ring(Vector2 at, Color c, float size = 420, float life = 0.35f) =>
_list.Add(new P { Kind = PKind.Ring, Pos = at, Life = life, Size = 40, Grow = size / life, Color = c });
/// Schwebstaub im Licht: langsam, flackernd; hält die Anzahl um <paramref name="count"/>.
public void Motes(int count, float w, float h)
{
int have = 0;
foreach (var p in _list) if (p.Kind == PKind.Mote) have++;
for (int i = have; i < count; i++)
_list.Add(new P { Kind = PKind.Mote, Pos = new Vector2(R(-200, w + 200), R(80, h - 120)), Vel = new Vector2(R(-12, 12), R(-14, -4)),
Life = R(5, 11), Size = R(3, 7), Rot = R(0, 6), Color = new Color(255, 215, 150) * 0.5f });
}
public void Update(float dt)
{
for (int i = _list.Count - 1; i >= 0; i--)
{
var p = _list[i];
p.Age += dt;
if (p.Age >= p.Life) { _list[i] = _list[^1]; _list.RemoveAt(_list.Count - 1); continue; }
p.Vel.Y += p.Gravity * dt;
p.Vel *= MathF.Exp(-p.Drag * dt);
p.Pos += p.Vel * dt;
p.Size += p.Grow * dt;
p.Rot += p.Spin * dt;
if (p.Kind == PKind.Chip && p.Pos.Y > Stage.FloorY) { p.Pos.Y = Stage.FloorY; p.Vel.Y *= -0.3f; p.Vel.X *= 0.5f; p.Spin *= 0.5f; }
_list[i] = p;
}
}
/// Weiche Teile (Staub, Schwebstaub, Splitter) mit Alpha-Mischung.
public void DrawSoft(SpriteBatch sb)
{
foreach (var p in _list)
{
float k = p.Age / p.Life;
switch (p.Kind)
{
case PKind.Dust:
Draw.Glow(sb, p.Pos, new Vector2(p.Size * 1.4f, p.Size), p.Color * (1 - k));
break;
case PKind.Chip:
sb.Draw(Assets.Pixel, p.Pos, null, p.Color * MathF.Min(1, (1 - k) * 3), p.Rot, new Vector2(0.5f), new Vector2(p.Size, p.Size * 0.6f), SpriteEffects.None, 0);
break;
}
}
}
/// Leuchtende Teile (Funken, Ringe, Schwebstaub) additiv.
public void DrawAdd(SpriteBatch sb)
{
foreach (var p in _list)
{
float k = p.Age / p.Life;
switch (p.Kind)
{
case PKind.Spark:
float len = MathF.Max(6, p.Vel.Length() * 0.035f);
float rot = MathF.Atan2(p.Vel.Y, p.Vel.X);
sb.Draw(Assets.Pixel, p.Pos, null, p.Color * (1 - k), rot, new Vector2(1, 0.5f), new Vector2(len, p.Size), SpriteEffects.None, 0);
Draw.Glow(sb, p.Pos, new Vector2(p.Size * 6), p.Color * (0.35f * (1 - k)));
break;
case PKind.Ring:
// Ring aus vielen Punkten
int n = 48;
for (int i = 0; i < n; i++)
{
float a = i * MathF.Tau / n;
Draw.Glow(sb, p.Pos + new Vector2(MathF.Cos(a), MathF.Sin(a) * 0.55f) * p.Size, new Vector2(26), p.Color * ((1 - k) * 0.9f));
}
break;
case PKind.Mote:
float tw = 0.5f + 0.5f * MathF.Sin(p.Age * 2.5f + p.Rot);
float fade = MathF.Min(1, MathF.Min(p.Age, p.Life - p.Age));
Draw.Glow(sb, p.Pos, new Vector2(p.Size * 2), p.Color * (tw * fade));
break;
}
}
}
}
}

View File

@@ -0,0 +1,104 @@
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
{
/// <summary>
/// Einstellungen über jedem Bildschirm: Lautstärken (Musik, Effekte, Erzählstimme), Ton an/aus,
/// Vollbild, Sprache, Erzählstimme, Effekte reduzieren. Jede Änderung wird sofort gespeichert.
/// </summary>
internal sealed class SettingsOverlay
{
readonly Ui _ui = new();
readonly Action _toggleFullscreen;
public bool Open { get; set; }
public SettingsOverlay(Action toggleFullscreen) => _toggleFullscreen = toggleFullscreen;
public void Update(Input input, Matrix ui)
{
_ui.Begin(input, ui);
if (input.Pressed(Microsoft.Xna.Framework.Input.Keys.Escape)) { Open = false; input.PrevKeys = input.Keys; }
}
/// Text ohne vorangestelltes Symbol (die Schrift hat keine Emoji).
static string Plain(string s) => new string(s.SkipWhile(c => !char.IsLetter(c)).ToArray());
static void Save()
{
AppSettings.Save();
AppSettings.ApplyVolumes();
}
public void Draw(SpriteBatch sb, float scale, Vector2 offset)
{
var ui = Matrix.CreateScale(scale) * Matrix.CreateTranslation(offset.X, offset.Y, 0);
sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, null, ui);
D.Rect(sb, new RectangleF(0, 0, Camera.W, Camera.H), Color.Black * 0.6f);
var r = new RectangleF(Camera.W / 2 - 420, 100, 840, 880);
Ui.Panel(sb, r, D.Gold, 0.97f);
float x = r.X + 50, y = r.Y + 60, w = r.Width - 100;
D.Text(sb, Assets.Serif, 40, L.t("main.settings").ToUpperInvariant(), new Vector2(r.Center.X, y), D.Gold, Align.Center);
// Audio
y += 70;
D.Text(sb, Assets.SansBold, 18, L.t("settings.sec.audio"), new Vector2(x, y), D.Dim);
y += 40;
Volume(sb, x, y, w, L.t("settings.row.music"), () => AppSettings.MusicVolume, v => AppSettings.MusicVolume = v); y += 56;
Volume(sb, x, y, w, L.t("settings.row.sfx"), () => AppSettings.SfxVolume, v => AppSettings.SfxVolume = v); y += 56;
Volume(sb, x, y, w, L.t("settings.vol.voice"), () => AppSettings.VoiceVolume, v => AppSettings.VoiceVolume = v); y += 56;
Toggle(sb, x, y, w, Plain(L.t(AppSettings.Muted ? "settings.muted" : "settings.sound.on")), !AppSettings.Muted,
() => { AppSettings.Muted = !AppSettings.Muted; if (!AppSettings.Muted) SoundManager.StartAmbient(); });
y += 56;
Toggle(sb, x, y, w, L.t("settings.narration"), AppSettings.Narration, () => AppSettings.Narration = !AppSettings.Narration);
// Anzeige
y += 80;
D.Text(sb, Assets.SansBold, 18, L.t("settings.sec.display"), new Vector2(x, y), D.Dim);
y += 40;
Toggle(sb, x, y, w, L.t("settings.fullscreen"), AppSettings.Fullscreen, _toggleFullscreen);
y += 56;
Toggle(sb, x, y, w, L.t("settings.reducemotion"), AppSettings.ReduceMotion, () => AppSettings.ReduceMotion = !AppSettings.ReduceMotion);
y += 56;
D.Text(sb, Assets.Sans, 22, L.t("settings.row.language"), new Vector2(x, y), D.Sand);
var langs = new[] { (L.Lang.De, "Deutsch"), (L.Lang.En, "English"), (L.Lang.Es, "Español") }; // i18n-ok
for (int i = 0; i < langs.Length; i++)
{
var (lang, name) = langs[i];
if (_ui.Button(sb, new RectangleF(x + w - 3 * 150 - 20 + i * 160, y - 22, 150, 44), name, selected: L.Current == lang, size: 18))
if (L.Current != lang && DevShot.Lang == null) L.Set(lang);
}
if (_ui.Button(sb, new RectangleF(r.Center.X - 160, r.Bottom - 100, 320, 64), L.t("select.back"), selected: true, size: 26))
Open = false;
D.Text(sb, Assets.Sans, 15, $"{Credits.COPYRIGHT} · {Credits.MAIL}", new Vector2(r.Center.X, r.Bottom - 20), D.Dim, Align.Center); // i18n-ok
sb.End();
}
void Volume(SpriteBatch sb, float x, float y, float w, string label, Func<int> get, Action<int> set)
{
D.Text(sb, Assets.Sans, 22, label, new Vector2(x, y), D.Sand);
var steps = AppSettings.VolumeSteps;
for (int i = 0; i < steps.Length; i++)
{
int v = steps[i];
var r = new RectangleF(x + w - steps.Length * 86 + i * 86, y - 20, 78, 40);
if (_ui.Button(sb, r, v.ToString(NumberFormat.Culture), selected: get() == v, size: 17)) { set(v); Save(); SoundManager.PlayClick(); }
}
}
void Toggle(SpriteBatch sb, float x, float y, float w, string label, bool on, Action flip)
{
D.Text(sb, Assets.Sans, 22, label, new Vector2(x, y), D.Sand);
if (_ui.Button(sb, new RectangleF(x + w - 170, y - 20, 170, 40), L.t(on ? "settings.on" : "settings.off"), selected: on, size: 18))
{
flip();
Save();
}
}
}
}