Eine Zeile oben in der Ecke der Leistenseite (380x52): Statuspunkt, ECHTGELD, Satz, darunter was laeuft / die Meldung / die letzte Entscheidung, Zug-Uhr, Hauptknopf, Not-Aus, Ausklappen, Beenden. Doppelklick, der Pfeil oder Strg+Alt+C klappt wieder aus. cockpit.json meldet form "pille" (Kacheln wie am Mac). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
241 lines
11 KiB
C#
241 lines
11 KiB
C#
using Microsoft.UI.Windowing;
|
|
using Microsoft.UI.Xaml;
|
|
using Microsoft.UI.Xaml.Controls;
|
|
using Microsoft.UI.Xaml.Media;
|
|
using Pokerfreak.Cockpit.Kern;
|
|
using Pokerfreak.Cockpit.Seiten;
|
|
using Windows.Graphics;
|
|
using Windows.UI;
|
|
|
|
namespace Pokerfreak.Cockpit;
|
|
|
|
/// <summary>
|
|
/// Das Cockpit-Fenster nach der Leiste der Mac-App (Wurzel.swift `Leiste`): schmal und hoch (440 x 900),
|
|
/// tiefes Glas mit Gluehen (blau in Uebung, rot in Echtgeld, roter Rand bei Echtgeld/Not-Aus), oben
|
|
/// Verbindung/Klon/Laufzeit/Zahnrad, unten die Reiter mit Symbol und Namen. Die Seiten bleiben am Leben.
|
|
/// </summary>
|
|
public sealed partial class MainWindow : Window
|
|
{
|
|
private static readonly (string Tag, string Titel, string Glyph)[] Reiter =
|
|
{
|
|
("cash", "Cash", ""), ("haende", "Hände", ""),
|
|
("statistik", "Statistik", ""), ("protokoll", "Protokoll", ""),
|
|
};
|
|
|
|
private readonly CockpitZustand _z;
|
|
private readonly Dictionary<string, ISeite> _seiten = new();
|
|
private readonly Dictionary<string, (FontIcon Zeichen, TextBlock Text)> _reiterKnoepfe = new();
|
|
private string _tag = "cash";
|
|
|
|
/// <summary>Die Leiste der laufenden App - fuer die Seitenwahl in den Einstellungen.</summary>
|
|
public static Leiste? Leiste { get; private set; }
|
|
private ISeite? _sichtbar;
|
|
private readonly Border _klon = Ui.Abzeichen("Klon", "lila");
|
|
private readonly StackPanel _laufzeit = Ui.Reihe(4);
|
|
private readonly TextBlock _laufzeitText = Ui.Winzig("");
|
|
private readonly Dienst _dienst;
|
|
private readonly Ort _ort;
|
|
private readonly Leiste _leiste;
|
|
private readonly Schale _schale;
|
|
private readonly Pille _pille;
|
|
|
|
public MainWindow(Adresse adresse)
|
|
{
|
|
InitializeComponent();
|
|
ExtendsContentIntoTitleBar = true;
|
|
SetTitleBar(Titelleiste);
|
|
AppWindow.TitleBar.PreferredHeightOption = TitleBarHeightOption.Standard;
|
|
AppWindow.SetIcon("Assets/cockpit.ico");
|
|
|
|
if (AppWindow.Presenter is OverlappedPresenter p) p.IsMaximizable = false;
|
|
|
|
// Windows: den Server selbst hochziehen (mit Tisch-Desktop), den Rahmen fuers Kacheln melden,
|
|
// bei Tisch-Desktop mit hinueber und nur dort andocken, ins Tray minimieren (wie das Rust-Cockpit).
|
|
// Angedockt wie das Mac-Panel: Leiste am Rand, ueber allem (Kern/Leiste.cs).
|
|
_dienst = Dienst.Starten(adresse);
|
|
var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
|
|
_ort = new Ort(hwnd, DispatcherQueue);
|
|
_leiste = new Leiste(AppWindow, hwnd, DispatcherQueue, _ort.Treffpunkt());
|
|
_ort.Lage = () => (_leiste.Seite, _leiste.Mindestbreite, _leiste.Form);
|
|
_ort.AufTischDesktop += _leiste.Platzieren;
|
|
_leiste.Platzieren();
|
|
_schale = new Schale(hwnd, Path.Combine(AppContext.BaseDirectory, "Assets", "cockpit.ico"), "Pokerfreak Cockpit",
|
|
Hervorholen, Close);
|
|
// Minimieren klappt zur Pille (wie Gelb am Mac), statt das Cockpit in die Taskleiste zu legen
|
|
AppWindow.Changed += (_, e) =>
|
|
{
|
|
if (e.DidPresenterChange || e.DidSizeChange)
|
|
if (AppWindow.Presenter is OverlappedPresenter op && op.State == OverlappedPresenterState.Minimized)
|
|
{
|
|
op.Restore();
|
|
FormSetzen(true);
|
|
}
|
|
};
|
|
Closed += (_, _) =>
|
|
{
|
|
_schale.Dispose();
|
|
_leiste.Dispose();
|
|
_ort.Dispose();
|
|
_dienst.Dispose();
|
|
};
|
|
|
|
_z = new CockpitZustand(adresse, DispatcherQueue);
|
|
_pille = new Pille(_z, () => FormSetzen(false), Close);
|
|
PilleFlaeche.Content = _pille;
|
|
_leiste.TischeOffen = () => _z.Ansicht.Kopf.Zahl("tische_offen") is double t ? (int)t : null;
|
|
Leiste = _leiste;
|
|
_leiste.SeiteGeaendert += Zeichnen;
|
|
_seiten["cash"] = new CashSeite(_z);
|
|
_seiten["haende"] = new HaendeSeite(_z);
|
|
_seiten["statistik"] = new StatistikSeite(_z);
|
|
_seiten["protokoll"] = new ProtokollSeite(_z);
|
|
_seiten["einstellungen"] = new EinstellungenSeite(_z);
|
|
_z.EinstellungenGewuenscht += b =>
|
|
{
|
|
((EinstellungenSeite)_seiten["einstellungen"]).BereichSetzen(b);
|
|
Zeigen("einstellungen");
|
|
};
|
|
|
|
for (int i = 0; i < Reiter.Length; i++)
|
|
{
|
|
var (tag, titel, glyph) = Reiter[i];
|
|
var zeichen = Ui.Zeichen(glyph, 15);
|
|
var text = Ui.Text(titel, 10.5);
|
|
text.HorizontalAlignment = HorizontalAlignment.Center;
|
|
var inhalt = Ui.Spalte(2, zeichen, text);
|
|
inhalt.HorizontalAlignment = HorizontalAlignment.Stretch;
|
|
inhalt.Padding = new Thickness(0, 4, 0, 4);
|
|
var knopf = inhalt.Tippen(() => Zeigen(tag), 8, $"{titel} (Strg+{i + 1})");
|
|
Reiterleiste.ColumnDefinitions.Add(new ColumnDefinition());
|
|
Reiterleiste.Children.Add(knopf.Spalte(i));
|
|
_reiterKnoepfe[tag] = (zeichen, text);
|
|
var taste = new Microsoft.UI.Xaml.Input.KeyboardAccelerator
|
|
{
|
|
Key = Windows.System.VirtualKey.Number1 + i,
|
|
Modifiers = Windows.System.VirtualKeyModifiers.Control,
|
|
};
|
|
taste.Invoked += (_, e) => { e.Handled = true; Zeigen(tag); };
|
|
Wurzel.KeyboardAccelerators.Add(taste);
|
|
}
|
|
|
|
_laufzeit.Children.Add(Ui.Zeichen("", 10, "grau"));
|
|
_laufzeit.Children.Add(_laufzeitText);
|
|
// Strg+Alt+C: Leiste <-> Pille (am Mac systemweit ⌃⌥⌘C)
|
|
var form = new Microsoft.UI.Xaml.Input.KeyboardAccelerator
|
|
{
|
|
Key = Windows.System.VirtualKey.C,
|
|
Modifiers = Windows.System.VirtualKeyModifiers.Control | Windows.System.VirtualKeyModifiers.Menu,
|
|
};
|
|
form.Invoked += (_, e) => { e.Handled = true; FormSetzen(!_leiste.Pille); };
|
|
Wurzel.KeyboardAccelerators.Add(form);
|
|
Zahnrad.Click += (_, _) => Zeigen(_tag == "einstellungen" ? "cash" : "einstellungen");
|
|
KopfRechts.Children.Add(_klon);
|
|
KopfRechts.Children.Add(_laufzeit);
|
|
// In der eigenen Titelleiste ist alles Ziehflaeche; das Zahnrad muss Klicks durchlassen
|
|
Zahnrad.Loaded += (_, _) => DurchlassSetzen();
|
|
Zahnrad.SizeChanged += (_, _) => DurchlassSetzen();
|
|
Titelleiste.SizeChanged += (_, _) => DurchlassSetzen();
|
|
Activated += (_, _) => DurchlassSetzen();
|
|
AppWindow.Changed += (_, e) => { if (e.DidSizeChange || e.DidVisibilityChange) DurchlassSetzen(); };
|
|
|
|
_z.Geaendert += Zeichnen;
|
|
Zeigen("cash");
|
|
Closed += (_, _) => _z.Verbindung.Dispose();
|
|
|
|
// Laufende Zeit (Countdown, Dauer) tickt ohne neue Daten weiter
|
|
var takt = DispatcherQueue.CreateTimer();
|
|
takt.Interval = TimeSpan.FromSeconds(1);
|
|
takt.Tick += (_, _) => { if (_leiste.Pille) _pille.Takt(); else _sichtbar?.Takt(); };
|
|
takt.Start();
|
|
}
|
|
|
|
private static double DpiSkala()
|
|
{
|
|
try { return GetDpiForSystem() / 96.0; } catch { return 1.0; }
|
|
}
|
|
|
|
[System.Runtime.InteropServices.DllImport("user32.dll")]
|
|
private static extern uint GetDpiForSystem();
|
|
|
|
/// <summary>Leiste oder Pille zeigen (Cockpit.swift `form`).</summary>
|
|
private void FormSetzen(bool pille)
|
|
{
|
|
if (pille == _leiste.Pille) return;
|
|
var leiste = pille ? Visibility.Collapsed : Visibility.Visible;
|
|
Titelleiste.Visibility = Inhalt.Visibility = Trenner.Visibility = Reiterleiste.Visibility = leiste;
|
|
PilleFlaeche.Visibility = pille ? Visibility.Visible : Visibility.Collapsed;
|
|
_leiste.FormSetzen(pille);
|
|
if (pille) _pille.Zeichnen(); else _sichtbar?.Zeichnen();
|
|
DurchlassSetzen();
|
|
}
|
|
|
|
/// <summary>Das Zahnrad aus der Ziehflaeche der Titelleiste nehmen (sonst schluckt Windows den Klick).
|
|
/// Als Pille ist nichts Ziehflaeche - jeder Knopf darin muss klicken.</summary>
|
|
private void DurchlassSetzen()
|
|
{
|
|
var quelle = Microsoft.UI.Input.InputNonClientPointerSource.GetForWindowId(AppWindow.Id);
|
|
if (_leiste?.Pille == true)
|
|
{
|
|
var g = AppWindow.Size;
|
|
quelle.SetRegionRects(Microsoft.UI.Input.NonClientRegionKind.Passthrough, new[] { new RectInt32(0, 0, g.Width, g.Height) });
|
|
return;
|
|
}
|
|
if (Zahnrad.XamlRoot is not { } wurzel || Zahnrad.ActualWidth <= 0) return;
|
|
var s = wurzel.RasterizationScale;
|
|
var p = Zahnrad.TransformToVisual(null).TransformPoint(new Windows.Foundation.Point(0, 0));
|
|
var r = new RectInt32((int)(p.X * s), (int)(p.Y * s), (int)(Zahnrad.ActualWidth * s), (int)(Zahnrad.ActualHeight * s));
|
|
quelle.SetRegionRects(Microsoft.UI.Input.NonClientRegionKind.Passthrough, new[] { r });
|
|
}
|
|
|
|
private void Zeigen(string tag)
|
|
{
|
|
_tag = tag;
|
|
_sichtbar = _seiten[tag];
|
|
Inhalt.Content = _sichtbar;
|
|
foreach (var (t, (zeichen, text)) in _reiterKnoepfe)
|
|
{
|
|
var pinsel = t == tag ? Ui.Akzent : Ui.Zweit;
|
|
zeichen.Foreground = pinsel;
|
|
text.Foreground = pinsel;
|
|
}
|
|
ZahnradZeichen.Foreground = tag == "einstellungen" ? Ui.Akzent : Ui.Pinsel(null);
|
|
_sichtbar.Zeichnen();
|
|
}
|
|
|
|
private void Zeichnen()
|
|
{
|
|
var k = _z.Ansicht.Kopf;
|
|
VerbindungPunkt.Fill = Ui.Pinsel(_z.Verbunden ? "gruen" : _z.JemalsVerbunden ? "rot" : "grau");
|
|
VerbindungText.Text = _z.Verbunden ? "" : _z.Getrennt;
|
|
ToolTipService.SetToolTip(VerbindungPunkt, $"{_z.Verbindung.Adresse.Host}:{_z.Verbindung.Adresse.Port}");
|
|
_klon.Visibility = k.Wahr("klon") && !Umfang.NurSpiel ? Visibility.Visible : Visibility.Collapsed;
|
|
var lz = k.Zahl("laufzeit_s");
|
|
_laufzeit.Visibility = k.Wahr("laeuft") && lz != null ? Visibility.Visible : Visibility.Collapsed;
|
|
_laufzeitText.Text = lz is double s ? Format.Dauer(s) : "";
|
|
|
|
// Hintergrund: Echtgeld glueht rot, sonst ein Hauch Blau; Rand rot bei Echtgeld und Not-Aus
|
|
bool cash = _z.Wahl.Cash && !_z.Ansicht.Zuschauen;
|
|
GluehenFarbe.Color = cash ? Color.FromArgb(0x47, 0xFF, 0x45, 0x3A) : Color.FromArgb(0x24, 0x0A, 0x84, 0xFF);
|
|
GluehenRand.Color = cash ? Color.FromArgb(0, 0xFF, 0x45, 0x3A) : Color.FromArgb(0, 0x0A, 0x84, 0xFF);
|
|
Wurzel.BorderBrush = _z.NotAus ? Ui.Pinsel("rot") : cash ? Ui.Pinsel("rot", 0.7) : Ui.Weiss(0.10);
|
|
Wurzel.BorderThickness = new Thickness(_z.NotAus || cash ? 1.5 : 0.5);
|
|
if (_leiste.Pille) _pille.Zeichnen(); else _sichtbar?.Zeichnen();
|
|
}
|
|
/// <summary>Aus dem Tray zurueck: zeigen, wiederherstellen, nach vorn.</summary>
|
|
private void Hervorholen()
|
|
{
|
|
AppWindow.Show();
|
|
if (AppWindow.Presenter is OverlappedPresenter op && op.State == OverlappedPresenterState.Minimized) op.Restore();
|
|
if (_leiste.Pille) FormSetzen(false); else _leiste.Platzieren();
|
|
Activate();
|
|
}
|
|
}
|
|
|
|
/// <summary>Ein Reiter: zeichnet sich aus dem Zustand neu; `Takt` jede Sekunde fuer laufende Zeit.</summary>
|
|
public interface ISeite
|
|
{
|
|
void Zeichnen();
|
|
void Takt() { }
|
|
|
|
}
|