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>
69 lines
2.6 KiB
C#
69 lines
2.6 KiB
C#
using System;
|
|
using FontStashSharp;
|
|
using GladiatorIdle.Arena;
|
|
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using Microsoft.Xna.Framework.Input;
|
|
using D = GladiatorIdle.Gfx.Draw;
|
|
|
|
namespace GladiatorIdle.Gfx
|
|
{
|
|
/// <summary>
|
|
/// Einfache Oberfläche im Sofort-Modus (Design-Pixel): jedes Bild werden Knöpfe gezeichnet und
|
|
/// gleichzeitig geprüft, ob sie geklickt wurden. Maus in Design-Pixel umgerechnet.
|
|
/// </summary>
|
|
internal sealed class Ui
|
|
{
|
|
public Vector2 Mouse;
|
|
public bool Click;
|
|
public bool Hovering { get; private set; }
|
|
Matrix _inverse;
|
|
|
|
public void Begin(Input input, Matrix ui)
|
|
{
|
|
_inverse = Matrix.Invert(ui);
|
|
Mouse = Vector2.Transform(new Vector2(input.Mouse.X, input.Mouse.Y), _inverse);
|
|
Click = input.LeftClick;
|
|
Hovering = false;
|
|
}
|
|
|
|
public bool Hover(RectangleF r)
|
|
{
|
|
bool h = r.Contains(Mouse);
|
|
if (h) Hovering = true;
|
|
return h;
|
|
}
|
|
|
|
/// Klick auf die Fläche (einmal je Klick).
|
|
public bool Hit(RectangleF r)
|
|
{
|
|
if (!Click || !r.Contains(Mouse)) return false;
|
|
Click = false;
|
|
SoundManager.PlayClick();
|
|
return true;
|
|
}
|
|
|
|
/// Dunkle Tafel mit Bronzerand.
|
|
public static void Panel(SpriteBatch sb, RectangleF r, Color? border = null, float alpha = 0.86f)
|
|
{
|
|
D.Rect(sb, r, new Color(18, 13, 9) * alpha);
|
|
D.Frame(sb, r, border ?? D.Border, 2);
|
|
D.Frame(sb, new RectangleF(r.X + 4, r.Y + 4, r.Width - 8, r.Height - 8), Color.Black * 0.35f, 1);
|
|
}
|
|
|
|
/// Knopf mit Text; liefert true beim Klick.
|
|
public bool Button(SpriteBatch sb, RectangleF r, string text, bool enabled = true, bool selected = false,
|
|
float size = 24, Color? accent = null)
|
|
{
|
|
bool hover = enabled && Hover(r);
|
|
var a = accent ?? D.Gold;
|
|
var fill = !enabled ? new Color(24, 20, 16) : selected ? a * 0.32f : hover ? new Color(70, 52, 32) : new Color(38, 28, 19);
|
|
D.Rect(sb, r, fill * 0.95f);
|
|
D.Rect(sb, new RectangleF(r.X + 2, r.Y + 2, r.Width - 4, (r.Height - 4) * 0.45f), Color.White * (hover ? 0.08f : 0.04f));
|
|
D.Frame(sb, r, !enabled ? new Color(60, 48, 36) : selected || hover ? a : D.Border, selected ? 3 : 2);
|
|
D.Text(sb, Assets.SansBold, size, text, r.Center, !enabled ? D.Dim : selected ? Color.White : D.Sand, Align.Center);
|
|
return enabled && Hit(r);
|
|
}
|
|
}
|
|
}
|