diff --git a/assets/modern/modern.rml b/assets/modern/modern.rml index 02057ec..1691492 100644 --- a/assets/modern/modern.rml +++ b/assets/modern/modern.rml @@ -1,5 +1,5 @@ -OpenBMH +OpenBMH
diff --git a/assets/modern/sports.rcss b/assets/modern/sports.rcss new file mode 100644 index 0000000..62ef7a3 --- /dev/null +++ b/assets/modern/sports.rcss @@ -0,0 +1,49 @@ +/* SPDX-License-Identifier: GPL-3.0-only */ +.training-skills {position:absolute;left:0;top:0;width:1060dp;height:1008dp;} +.training-skill {height:112dp;display:flex;align-items:center;gap:14dp;font-size:36dp;} +.training-skill>div,.training-skill>span {flex-shrink:0;} +.training-balls {display:flex;align-items:center;justify-content:flex-start;} +.training-ball {display:flex;align-items:center;justify-content:center;padding:0;border:0dp;background-color:transparent;flex-shrink:0;} +.training-ball:hover,.training-ball:disabled {background-color:transparent;} +.training-ball.is-empty {opacity:.18;filter:grayscale(1);} +.training-ball.overtraining {filter:sepia(1) saturate(9) hue-rotate(310deg);} +.training-pitch {position:absolute;left:0;top:1040dp;width:570dp;height:390dp;border:3dp var(--border);border-radius:12dp;overflow:hidden;box-shadow:0dp 0dp 0dp 3dp #244c38;} +.training-midline {position:absolute;left:50%;top:0;width:2dp;height:100%;background-color:#d5efd2;} +.training-circle {position:absolute;left:50%;top:50%;width:110dp;height:110dp;margin-left:-55dp;margin-top:-55dp;border:3dp #d5efd2;border-radius:55dp;} +.training-box {position:absolute;top:22%;width:19%;height:56%;border:3dp #d5efd2;} +.left-box {left:-4dp;}.right-box {right:-4dp;} +.training-type-cell {position:absolute;width:227dp;height:156dp;display:flex;align-items:center;justify-content:center;} +.training-auto {font-size:32dp;} +.training-auto.auto-players {font-size:29dp;} +.training-budget {position:absolute;left:604dp;top:1338dp;width:440dp;font-size:27dp;line-height:1.5;color:var(--muted);} +.training-roster {position:absolute;left:1120dp;right:0;top:0;bottom:80dp;overflow-y:auto;overflow-x:hidden;} +.training-row {display:flex;align-items:center;height:99dp;border-bottom:2dp var(--border);font-size:34dp;} +.training-row>div {flex-shrink:0;} +.training-header {height:62dp;font-size:31dp;color:var(--muted);border-bottom:2dp var(--border);} +.training-position {font-size:30dp;color:var(--muted);} +.training-name {overflow:hidden;white-space:nowrap;text-overflow:ellipsis;padding-right:10dp;} +.training-row.striped {background-color:var(--soft);} +.training-roster select {width:490dp;height:62dp;padding:10dp 12dp;border:2dp var(--border);border-radius:8dp;font-size:32dp;} +.training-roster select selectbox {width:490dp;max-height:480dp;margin-top:8dp;padding:10dp;border-radius:16dp;} +.training-roster select option {min-height:72dp;padding:10dp 14dp;line-height:1.3;} +.tactics-board {position:absolute;left:76dp;top:0;width:2300dp;height:100%;} +.tactics-surface {position:absolute;left:0;right:0;top:0;bottom:100dp;border:2dp var(--border);border-radius:28dp;decorator:linear-gradient(130deg,#bfd9e40a,#9ecbb809);} +.tactics-board>.image-frame {filter:drop-shadow(0dp 0dp 1dp #e0edbc);} +.tactic-hotspot {padding:0;border:0dp;background-color:transparent;} +.tactic-hotspot:hover,.tactic-hotspot:active {background-color:transparent;} +.tactic-hotspot:focus-visible {border:3dp var(--accent);} +.tactic-effort {position:absolute;left:1021.188dp;top:1021.469dp;width:1012dp;height:316.875dp;color:#d4e6b3;} +body.silver .tactic-effort {color:#536f66;} +.tactic-effort-label {display:flex;align-items:baseline;gap:18dp;font-family:Chalk;font-size:60dp;line-height:1.2;letter-spacing:4dp;font-effect:shadow(2dp 2dp #386824);} +.tactic-effort-marks {font-size:52dp;letter-spacing:1dp;line-height:1.2;} +.tactic-effort input {position:absolute;left:2dp;top:96dp;width:96%;height:20dp;} +.tactic-effort input slidertrack {margin:8dp 0;height:4dp;} +.tactic-effort input sliderprogress {height:4dp;background-color:var(--accent);border-radius:2dp;} +.tactic-effort input sliderbar {width:16dp;height:16dp;margin-top:2dp;border:0dp;border-radius:8dp;background-color:var(--accent);} +.tactic-hint {position:absolute;left:0;right:0;bottom:34dp;height:39dp;text-align:center;font-size:34dp;color:var(--text);} +body.midnight .training-skill {color:#c6d6df;} +body.midnight .training-row {color:#d8e3eb;} +body.midnight .training-header,body.midnight .training-position {color:#9fb2c3;} +body.midnight .training-budget {color:#9fb6c6;} +body.midnight .training-pitch {border-color:#9eb9a5;} +body.midnight .tactic-hint {color:#b8cddc;} diff --git a/docs/new_ui/NATIVE_STATUS.md b/docs/new_ui/NATIVE_STATUS.md index 26b181a..0683267 100644 --- a/docs/new_ui/NATIVE_STATUS.md +++ b/docs/new_ui/NATIVE_STATUS.md @@ -30,6 +30,11 @@ wird ausdrücklich mit `OPENBMH_BUILD_MODERN_UI=ON` gebaut. Ansichten vorhanden; ihr vollständiger Bedienungsabgleich bleibt offen. - Separate UI-Demostände und Desktopansichten. Ansichten speichern zusätzlich einen Screenshot; die Standardansicht kann nicht gelöscht werden. +- [Training](desktop/training/README.md): neun Übungen, vier Arten, Kader mit + Schwerpunkt/Intensität, Automatikgruppen und gemeinsame Automatik. +- [Taktik](desktop/tactics/README.md): sieben interaktive Diagrammflächen, + zyklische Einstellungen und Einsatzregler. Die Grafik aktualisiert sich + unmittelbar und speichert ausschließlich UI-Vorschaueinstellungen. **Anstoß führt keine Aktion aus**, weder per Maus noch per Tastatur. Das gilt auch für die direkte Aktionsschnittstelle des Demoanbieters. @@ -94,6 +99,11 @@ Die [dedizierte Schrift-QA](typography-qa.md) prüft zusätzlich Buttons und Dropdowns gegen das HTML-Mockup, einschließlich tatsächlicher Textmitten, Pixeldichten sowie Escape- und Fokusverhalten. +Die [Menü-QA](menu-qa.md) hält den Gesamtkatalog einschließlich fehlender +Ports nach. Training/Taktik wurden in zwölf tatsächlichen Rendererläufen +mit drei Themes und zwei Auflösungen verglichen. Die native UI und die +synthetischen Kontrolltests bauen in der CI unter Linux, Windows und macOS. + Ein nativer Linux-/OpenGL-Durchlauf mit externem Diamond-Datensatz führt über das Hauptmenü, die Managerwahl und Auslosung zum Desktop, verändert den Eintrittspreis nach Bestätigung, öffnet das Nahost-Lager und prüft Verschieben diff --git a/docs/new_ui/README.md b/docs/new_ui/README.md index 545d407..15d1b72 100644 --- a/docs/new_ui/README.md +++ b/docs/new_ui/README.md @@ -10,10 +10,13 @@ Implementierung in der Spiel-Engine. | Umsetzung | [Abgestimmter Umfang der nativen UI bis zum Anstoß](PLAN.md) | | Nativer Stand | [Unterbau, erster Durchlauf und noch offene Übertragungen](NATIVE_STATUS.md) | | Schrift-QA | [Button-/Dropdown-Ausrichtung und unabhängiger Vergleich](typography-qa.md) | +| Menü-QA | [Wiederholbarer Gesamtkatalog und Meilenstein-Abnahme](menu-qa.md) | | Ressourcen | [GUI-Assets, Weltbilder und spätere Paketbereinigung](assets.md) | | Desktop | [Statusleiste, Gestaltung und Fenster](desktop/README.md) | | Eintrittspreis | [Kompakter Schieberegler im Konto-Widget](desktop/entry-price/README.md) | | Trainingslager | [Alle 18 Angebote, Qualitätswerte und Bedienung](desktop/trainingcamp/README.md) | +| Training | [Übungen, Kader, Intensität und Demo-Automatik](desktop/training/README.md) | +| Taktik | [Interaktive Diagramme und Einsatzregler](desktop/tactics/README.md) | | Transfers | [Ablöse-Kasten und Positionsfilter](desktop/transfers/README.md) | Jeder Bereich nennt die geprüfte Quelle, bestehende Funktionen und offene diff --git a/docs/new_ui/desktop/tactics/README.md b/docs/new_ui/desktop/tactics/README.md new file mode 100644 index 0000000..9593092 --- /dev/null +++ b/docs/new_ui/desktop/tactics/README.md @@ -0,0 +1,50 @@ +# Taktik · native Modern UI + +Stand: 23. Oktober 2026. Quelle: privates HTML-Mockup `bmh_4k_ui`, Revision +`0bf0f2afd2ff8d5dabb96c795db2a5d0abaaf278`, `desktop/squad-menus.js`, +`squad-menus.css` und `table-window.css`. Der Port verwendet dieselbe +Geometrie, Farben und Interaktionsflächen. + +## Darstellung und Bedienung + +Die transparente Tafel liegt im gemeinsamen 4:3-Fenster. Spielfelder, +Spielerpunkte, Pfeile und Kurven entstehen als skalierbares Diagramm mit +erhaltenem Seitenverhältnis. Es gibt keine sichtbaren Hoverkästen; +Tastaturfokus bleibt sichtbar. + +Sieben Flächen wechseln zyklisch Defensiv/offensiv, drei Pass-/Schussbilder, +flache/hohe Bälle und zwei Flügelbilder. Der dezente Regler stellt den +Einsatz von 0 bis 11 ein. Ausrufezeichen und Hinweis aktualisieren sich +während der Bedienung. Die drei Themes verwenden ihre Referenzfarben, +einschließlich der dunklen Linien in Silver. + +Die dynamische Textur verwendet einen festen Cacheplatz. Bei Änderungen wird +die vorherige GPU-Textur freigegeben; wiederholte Klicks legen keine +unbegrenzte Bildsammlung an. Kein zusätzliches Tafelbild im OBW ist nötig. + +## Demo und spätere Anbindung + +`Snapshot.state.tactics.values` enthält acht Vorschaueinstellungen. +Revisionierte `tactics`-Aktionen mit `cycle` oder `effort` gehen ausschließlich +an den Demoanbieter. Die HTML-Startwerte sind `[2, 1, 1, 0, 1, 0, 1, 6]`; +Speichern, Laden und Wiederöffnen erhalten Änderungen. Keine Matchfunktion +wird ausgeführt. + +Die Formation ist derzeit dieselbe feste Vorschau wie im HTML-POC. Sie ist +noch nicht mit einer nativen Aufstellungsansicht verbunden. Der Sessionadapter +liefert später Formation, erlaubte Werte und Wirkungen. Die Kreideschrift +nutzt verfügbare Systemschriften mit Rückfall auf die mitgelieferte UI-Schrift; +geringe Metrikunterschiede zwischen Betriebssystemen sind noch zu prüfen. + +## QA + +Zwölf vollständige Trainings-/Taktikläufe decken drei Themes und zwei +Auflösungen ab. Geprüft: alle sieben Wechsel samt Rückkehr zu Startwerten, +tatsächlich aktualisierte Diagramme, beide Reglerenden, Tastaturbedienung, +Wiederöffnen und Wiederherstellung in einem zweiten Prozess. Zusätzliche +Silver-Aufnahmen prüfen Reglerknopf, Fortschritt und Schatten. + +Linux/OpenGL wurde tatsächlich gerendert. Windows/macOS haben CI-Builds und +synthetische Tests; ihre visuelle Laufzeitabnahme ist damit nicht erledigt. +Kleine Schrift-/Kantenrasterungsunterschiede bleiben protokolliert. +Siehe [wiederholbare Menü-QA](../../menu-qa.md). diff --git a/docs/new_ui/desktop/training/README.md b/docs/new_ui/desktop/training/README.md new file mode 100644 index 0000000..37bfebd --- /dev/null +++ b/docs/new_ui/desktop/training/README.md @@ -0,0 +1,57 @@ +# Training · native Modern UI + +Stand: 23. Oktober 2026. Verbindliche Quelle: privates HTML-Mockup +`bmh_4k_ui`, Revision `0bf0f2afd2ff8d5dabb96c795db2a5d0abaaf278`, +`desktop/squad-menus.js`, `squad-menus.css` und `table-window.css`. +Der native Port liegt in `src/modern/ui/sports_screens.inc`. + +## Darstellung und Bedienung + +- Neun Übungen mit dem unveränderten GUI-Iconatlas und drei Bällen je Zeile: + Kondition, Technik, Eckball, Freistoß, Zweikampf, Pass, Schuss, + Schnelligkeit und Teamplay. +- Vier Trainingsarten auf dem gezeichneten Spielfeld; Automatik für Arten, + Kondition/Technik, Fertigkeiten und Spieler sowie der gemeinsame Schalter. +- Rechts der vollständige OBW-Kader mit Position, Name, Stärke, + Schwerpunkt und Intensität. Lange Namen werden mit Abstand zur Stärke + gekürzt. Die Liste scrollt bei größeren Kadern. +- Ein bereits gewählter Intensitätsball schaltet die Spielerintensität auf + null. Escape verwirft die Schwerpunktwahl; Fokus und Listenposition bleiben + bei Änderungen erhalten. +- Automatik sperrt manuelle Eingaben der jeweiligen Gruppe. Die + Spielerautomatik behält Schwerpunkte bei; der gemeinsame Schalter schaltet + alle vier Gruppen zusammen. + +Der Demoanbieter übernimmt die HTML-Vorschaubudgets 8/4/18 für Arten, +Kondition/Technik und Fertigkeiten. Ab 15 Fertigkeitsbällen zeigt er hohe +Belastung. Überschreitungen werden ohne teilweise Übernahme abgewiesen. +**Dies sind UI-Dummydaten, keine Trainingsregel oder Spielerentwicklung.** + +## Daten und spätere Engine-Anbindung + +`Snapshot.state.training` enthält Vereins-ID, neun Übungswerte, vier +Artenwerte, vier Automatikflags sowie Intensität/Schwerpunkt nach Spieler-ID. +Revisionierte `training`-Aktionen gehen ausschließlich an `DemoSource`. +Der erste Manager bestimmt den angezeigten Kader. Ein Vereinswechsel erzeugt +eine passende neue Vorschau. Ältere UI-Demostände werden beim Laden ergänzt; +echte `.obs`-Spielstände bleiben davon unberührt. + +Der spätere Sessionadapter muss Budgets, Automatik und Wirkungen liefern. +Die Verbindung zur globalen Einstellungsautomatik steht noch aus. +Namen/Positionen/Stärke stammen aus dem schreibgeschützten OBW-Katalog; +Icons und Ballgrafik sind [GUI-Ressourcen](../../assets.md). +Die Referenz hat 16 fiktive Spieler, der geprüfte Diamond-Kader 20. +Diese Datenabweichung wird nicht durch Entfernen von Spielern kaschiert. + +## QA + +Zwölf tatsächliche Trainings-/Taktikläufe decken drei Themes und zwei Größen +(1280 × 720, 1920 × 1080) ab. Geprüft: Budgets, Überlastungsfarbe, +Schwerpunktwahl/Escape, Intensität null, Automatik, echtes Mausrad, +Scroll-/Fokuserhalt, Wiederöffnen und gespeicherte Wiederherstellung. +Die Budgetumbrüche wurden in allen sechs Training-Konfigurationen nachgeprüft. +Synthetische Tests ergänzen atomare Ablehnung, Revisionen und Migration. + +Die gemeinsame Dropdown-Markierungsspalte und geringe Unterschiede der +Kantenglättung bleiben dokumentierte Abweichungen. Screenshots, Eingaben und +passende Demostände: [wiederholbare Menü-QA](../../menu-qa.md). diff --git a/docs/new_ui/menu-qa.md b/docs/new_ui/menu-qa.md new file mode 100644 index 0000000..ace96bb --- /dev/null +++ b/docs/new_ui/menu-qa.md @@ -0,0 +1,51 @@ +# Wiederholbare Menü-QA gegen HTML + +Die HTML-Version ist der verbindliche Gestaltungsstandard. Der Vergleich +begleitet fortlaufend die Portierung bis Anstoß. Eine Bildschirmaufnahme +allein bedeutet keine visuelle Abnahme. + +## Arbeitsweise + +1. Unveränderte HTML-Quelle lesen; Browserbilder, Geometrie, Schrift und + Interaktionszustände aufnehmen. +2. Native Ansicht mit Dummydaten hinter `DataSource` umsetzen. + Datenabweichungen ausdrücklich nennen und das Referenzlayout beibehalten. +3. Dedizierten QA-Agenten den tatsächlichen Renderer gegen HTML prüfen lassen: + drei Themes × 1280 × 720 und 1920 × 1080, einschließlich Buttons, + Dropdowns, langer Texte, Scrollen, Fokus und Abbrechen. +4. Befunde mit Eingabeskript und ladbarem UI-Demostand belegen. Korrekturen + gezielt nachprüfen; vollständige Interaktionsmatrix am Menü-Meilenstein. +5. Gesamtkatalog und offene Befunde fortschreiben. Fehlende Ports bleiben offen. + +Das private Mockup-Repository enthält dafür +`tools/qa/native_mockup_compare.py` mit deutscher Anleitung. +`--scenes all` nimmt jede katalogisierte Ansicht bis Anstoß auf; fehlende +native Ports erhalten weiterhin eine HTML-Aufnahme. Native Fälle enthalten +PNG, DOM, Snapshot, Eingabeskript und ladbaren Demostand. Das Werkzeug ist +ein endlicher QA-Lauf, kein unbeaufsichtigter Dauerprozess. Folgende +Menü-Meilensteine verwenden denselben Katalog erneut. + +Die Matrix trennt technische Aufnahme, Datenabgleich und visuelle Freigabe. +Reviewer, Zeitpunkt und fünf Prüfbereiche werden gespeichert. Unvollständige +Vergleiche bleiben `UNIMPLEMENTED` beziehungsweise `PENDING`. Protokolliert +werden außerdem Binärdatei-, Welt-, GUI- und Demostand-Hashes sowie Referenzrevision. + +## Automatisierte Regression + +`.github/workflows/modern-ui.yml` baut die aktivierte native UI unter Linux, +Windows und macOS. Fensterlose Tests mit synthetischen Daten prüfen unter +anderem Text-/Pfeilmitten, Dropdown-Schriftgrößen, Themes/Pixeldichten und das +Verwerfen von Eingaben. Private Ressourcen werden dort nicht vorausgesetzt. + +CI ergänzt die tatsächlichen Renderer-/HTML-Vergleiche. Ein erfolgreicher +Build bestätigt keine visuelle Abnahme auf dem jeweiligen Betriebssystem. + +## Nachweise + +Private Bilder und passende UI-Demostände liegen im Mockup-Repository unter +`docs/qa/native-rmlui-2026-10-23/`. Sie enthalten Weltinhalte und gehören +deshalb nicht ins öffentliche Quellcode-Repository. Öffentliche Zusammenfassung: + +- [Nativer Stand](NATIVE_STATUS.md) +- [Typografie-Befunde](typography-qa.md) +- [Training](desktop/training/README.md) und [Taktik](desktop/tactics/README.md) diff --git a/src/modern/ui/CMakeLists.txt b/src/modern/ui/CMakeLists.txt index 3e144d7..52eb67d 100644 --- a/src/modern/ui/CMakeLists.txt +++ b/src/modern/ui/CMakeLists.txt @@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-3.0-only -add_library(bmh_modern_ui_core STATIC catalog.cpp model.cpp gui_assets.cpp desktop.cpp) +add_library(bmh_modern_ui_core STATIC catalog.cpp model.cpp gui_assets.cpp desktop.cpp demo_sports.cpp) target_include_directories(bmh_modern_ui_core PUBLIC ../..) target_link_libraries(bmh_modern_ui_core PUBLIC bmh_asset_io) add_library(bmh_modern_ui STATIC view.cpp ticket_popover.cpp) @@ -14,7 +14,7 @@ endif() set(modern_assets "${CMAKE_BINARY_DIR}/assets/modern") FetchContent_GetProperties(rmlui) file(MAKE_DIRECTORY "${modern_assets}") -foreach(asset modern.rml theme.rcss ticket.rcss) +foreach(asset modern.rml theme.rcss ticket.rcss sports.rcss) configure_file("${CMAKE_SOURCE_DIR}/assets/modern/${asset}" "${modern_assets}/${asset}" COPYONLY) endforeach() file(GLOB modern_icons CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/assets/modern/icons/*.svg") diff --git a/src/modern/ui/controls.hpp b/src/modern/ui/controls.hpp index f655f34..762dbf8 100644 --- a/src/modern/ui/controls.hpp +++ b/src/modern/ui/controls.hpp @@ -29,13 +29,13 @@ inline bool center_selects(Rml::ElementDocument &document) { bool changed = false; Rml::ElementList controls; document.QuerySelectorAll(controls, "select"); - const auto set_pixels = [&](Rml::Element *element, const char *name, + const auto set_pixels = [&](Rml::Element *element, Rml::PropertyId name, float value) { const auto *old = element->GetLocalProperty(name); if (old && old->unit == Rml::Unit::PX && std::abs(old->Get() - value) < .02f) return; - element->SetProperty(name, std::to_string(value) + "px"); + element->SetProperty(name, Rml::Property(value, Rml::Unit::PX)); changed = true; }; for (auto *select : controls) { @@ -48,8 +48,8 @@ inline bool center_selects(Rml::ElementDocument &document) { continue; // WidgetDropDown fixes both offsets at the content-box top. A flex // selectvalue loses its text in pinned RmlUI; center its line instead. - set_pixels(caption, "line-height", height); - set_pixels(arrow, "margin-top", + set_pixels(caption, Rml::PropertyId::LineHeight, height); + set_pixels(arrow, Rml::PropertyId::MarginTop, std::max(0.f, (height - arrow->GetBox().GetSize(Rml::BoxArea::Border).y) / 2)); diff --git a/src/modern/ui/controls.inc b/src/modern/ui/controls.inc index 469e4ff..4b57adc 100644 --- a/src/modern/ui/controls.inc +++ b/src/modern/ui/controls.inc @@ -131,6 +131,10 @@ void App::drag_event(Rml::Event &event) { } void App::ProcessEvent(Rml::Event &event) try { const auto type = event.GetType(); + if (type == "keydown") + keyboard_navigation_ = true; + else if (type == "mousedown") + keyboard_navigation_ = false; for (auto *n = event.GetTargetElement(); n && n != doc_; n = n->GetParentNode()) if (n->GetId() == "native-ticket-layer") @@ -267,7 +271,10 @@ void App::ProcessEvent(Rml::Event &event) try { } } if (type == "change") { - change(target); + if (target->HasAttribute("data-input")) + input(target); + else + change(target); return; } if (type == "input") { @@ -879,7 +886,8 @@ void App::dispatch(const std::string &action, Rml::Element *target) { return; } static const std::set available = { - "tables", "strengths", "camp", "settings", "save", "load"}; + "tables", "strengths", "camp", "settings", + "save", "load", "training", "tactics"}; if (!available.contains(route)) { message("Diese native Ansicht wird im nächsten Menüpaket übertragen."); return; @@ -892,6 +900,39 @@ void App::dispatch(const std::string &action, Rml::Element *target) { refresh(); return; } + if (action == "training-auto" || action == "training-auto-all" || + action == "training-ball") { + Json change; + if (action == "training-auto-all") + change = {{"kind", "auto-all"}}; + else if (action == "training-auto") + change = {{"kind", "auto"}, {"index", std::stoi(id)}}; + else { + const auto group = target->GetAttribute("data-group", ""); + change = {{"kind", "ball"}, + {"group", group}, + {"index", std::stoi(id)}, + {"value", target->GetAttribute("data-value", 1)}}; + if (group == "player") + change["player"] = target->GetAttribute("data-player", ""); + } + if (apply("training", change)) { + focus_after_render_ = target->GetId(); + refresh(); + } + return; + } + if (action == "tactic-cycle") { + const int i = std::stoi(id); + if (i < 0 || i > 6) + return; + if (apply("tactics", {{"kind", "cycle"}, {"index", i}})) { + last_tactic_ = i; + focus_after_render_ = "tactic-cycle-" + id; + refresh(); + } + return; + } if (action == "ticket") { if (ticket_) { ticket_->open(target, device_ratio_); @@ -1061,6 +1102,19 @@ void App::change(Rml::Element *target) { pending_selects_.insert(target->GetId()); return; } + if (kind == "training-focus") { + const auto player = target->GetAttribute("data-player", ""); + const int focus = std::stoi(value); + if (snap().state.at("training").at("players").at(player).at("focus") == + focus) + return; + if (apply("training", + {{"kind", "focus"}, {"player", player}, {"value", focus}})) { + focus_after_render_ = target->GetId(); + refresh(); + } + return; + } if ((kind == "manager-country" || kind == "table-country") && value == country_) return; @@ -1097,6 +1151,18 @@ void App::input(Rml::Element *target) { if (!control) return; const auto value = control->GetValue(); + if (kind == "tactic-effort") { + const int value = std::stoi(control->GetValue()); + if (apply("tactics", {{"kind", "effort"}, {"value", value}})) { + last_tactic_ = 7; + element("tactic-effort-value") + ->SetInnerRML(std::string(size_t(value), '!')); + element("tactic-hint") + ->SetInnerRML("Einsatz: " + std::to_string(value) + " / 11"); + dirty_ = true; + } + return; + } if (kind == "sound-volume") { const int n = std::stoi(value); draft_preferences_["volume"] = n; diff --git a/src/modern/ui/demo_sports.cpp b/src/modern/ui/demo_sports.cpp new file mode 100644 index 0000000..4afa9d4 --- /dev/null +++ b/src/modern/ui/demo_sports.cpp @@ -0,0 +1,264 @@ +// SPDX-License-Identifier: GPL-3.0-only +#include "modern/ui/demo_sports.hpp" +#include +#include +#include +#include + +namespace bmh::modern_ui { +namespace { +bool integers(const Json &a, size_t size, int low, int high) { + if (!a.is_array() || a.size() != size) + return false; + return std::all_of(a.begin(), a.end(), [&](const auto &v) { + return v.is_number_integer() && v >= low && v <= high; + }); +} +int sum(const Json &a, size_t begin, size_t end) { + int n = 0; + for (size_t i = begin; i < end; ++i) + n += a.at(i).template get(); + return n; +} +constexpr std::array tactic_limits = {3, 3, 3, 3, 1, 1, 1, 11}; +} // namespace +Json demo_training(const Catalog &world, const std::string &club) { + Json players = Json::object(); + size_t i = 0; + for (auto *player : world.squad(club)) { + players[player->value("id", "")] = {{"intensity", i % 5 == 0 ? 1 : 2}, + {"focus", int(i % 8)}}; + ++i; + } + return {{"club", club}, + {"areas", {2, 2, 1, 1, 2, 2, 2, 2, 3}}, + {"types", {2, 2, 2, 2}}, + {"autos", {false, false, false, false}}, + {"players", players}}; +} +bool valid_demo_training(const Json &value, const Catalog &world, + const std::string &club) { + try { + if (!value.is_object() || value.at("club") != club || + !integers(value.at("areas"), 9, 1, 3) || + !integers(value.at("types"), 4, 1, 3)) + return false; + if (sum(value["types"], 0, 4) > 8 || sum(value["areas"], 0, 2) > 4 || + sum(value["areas"], 2, 9) > 18) + return false; + const auto &autos = value.at("autos"); + if (!autos.is_array() || autos.size() != 4) + return false; + for (const auto &v : autos) + if (!v.is_boolean()) + return false; + const auto &players = value.at("players"); + const auto squad = world.squad(club); + if (!players.is_object() || players.size() != squad.size()) + return false; + for (auto *p : squad) { + const auto &v = players.at(p->value("id", "")); + if (!v.at("intensity").is_number_integer() || v["intensity"] < 0 || + v["intensity"] > 3 || !v.at("focus").is_number_integer() || + v["focus"] < 0 || v["focus"] > 7) + return false; + } + return true; + } catch (const Json::exception &) { + return false; + } +} +std::string edit_demo_training(Json &state, const Json &action) { + for (const auto *key : {"index", "value"}) + if (action.contains(key) && (!action[key].is_number_integer() || + action[key] < 0 || action[key] > 100)) + return "invalid_training_value"; + auto next = state; + const auto kind = action.at("kind").get(); + if (kind == "auto" || kind == "auto-all") { + const int group = kind == "auto-all" ? -1 : action.at("index").get(); + if (group < -1 || group > 3) + return "invalid_training_group"; + const bool enabled = + kind == "auto-all" + ? !std::all_of(next["autos"].begin(), next["autos"].end(), + [](const auto &v) { return v == true; }) + : !next["autos"][size_t(group)].get(); + for (int i = 0; i < 4; ++i) + if (group == -1 || group == i) { + next["autos"][size_t(i)] = enabled; + if (!enabled) + continue; + if (i == 0) + next["types"] = {2, 2, 2, 2}; + if (i == 1) { + next["areas"][0] = 2; + next["areas"][1] = 2; + } + if (i == 2) + for (size_t j = 2; j < 9; ++j) + next["areas"][j] = 2; + if (i == 3) + for (auto &[id, p] : next["players"].items()) { + (void)id; + p["intensity"] = 2; + } + } + } else if (kind == "focus") { + const auto player = action.at("player").get(); + const int value = action.at("value").get(); + if (!next["players"].contains(player) || value < 0 || value > 7) + return "invalid_training_player"; + if (next["autos"][3] == true) + return "training_automatic"; + next["players"][player]["focus"] = value; + } else if (kind == "ball") { + const auto group = action.at("group").get(); + const int value = action.at("value").get(); + if (value < 1 || value > 3) + return "invalid_training_value"; + if (group == "player") { + const auto player = action.at("player").get(); + if (!next["players"].contains(player)) + return "invalid_training_player"; + if (next["autos"][3] == true) + return "training_automatic"; + auto &v = next["players"][player]["intensity"]; + v = v == value ? 0 : value; + } else { + const int index = action.at("index").get(); + const bool area = group == "area"; + if ((!area && group != "type") || index < 0 || index >= (area ? 9 : 4)) + return "invalid_training_group"; + if (next["autos"][size_t(area ? (index < 2 ? 1 : 2) : 0)] == true) + return "training_automatic"; + auto &list = next[area ? "areas" : "types"]; + list[size_t(index)] = value; + if (sum(next["types"], 0, 4) > 8 || sum(next["areas"], 0, 2) > 4 || + sum(next["areas"], 2, 9) > 18) + return "training_preview_budget"; + } + } else + return "unknown_training_action"; + state = std::move(next); + return {}; +} +Json demo_tactics() { return {{"values", {2, 1, 1, 0, 1, 0, 1, 6}}}; } +bool valid_demo_tactics(const Json &value) { + try { + const auto &v = value.at("values"); + if (!integers(v, 8, 0, 11)) + return false; + for (size_t i = 0; i < 8; ++i) + if (v[i] > tactic_limits[i]) + return false; + return true; + } catch (const Json::exception &) { + return false; + } +} +std::string edit_demo_tactics(Json &state, const Json &action) { + for (const auto *key : {"index", "value"}) + if (action.contains(key) && (!action[key].is_number_integer() || + action[key] < 0 || action[key] > 100)) + return "invalid_tactic_value"; + const auto kind = action.at("kind").get(); + const int index = kind == "effort" ? 7 : action.at("index").get(); + if (index < 0 || index > 7) + return "invalid_tactic_index"; + if (kind == "cycle") + state["values"][size_t(index)] = + (state["values"][size_t(index)].get() + 1) % + (tactic_limits[size_t(index)] + 1); + else if (kind == "effort") { + const int v = action.at("value").get(); + if (v < 0 || v > 11) + return "invalid_tactic_value"; + state["values"][7] = v; + } else + return "unknown_tactic_action"; + return {}; +} +std::string tactics_diagram(const Json &state, const std::string &theme) { + const auto values = state.at("values").get>(); + const std::string line = theme == "silver" ? "#536f66" : "#dfe8bf"; + const auto field_line = theme == "silver" ? "#536f66" : "#d7edbf", + man_line = theme == "silver" ? "#536f66" : "#c9e6ae", + curve_line = theme == "silver" ? "#536f66" : "#d4e7ba"; + const std::string defence = theme == "silver" ? "#85600c" : "#ffdd6b"; + std::ostringstream out; + out.imbue(std::locale::classic()); + out << ""; + const auto field = [&](double x, double y, double w, double h) { + out << ""; + }; + const auto dot = [&](double x, double y, bool opponent = false) { + out << ""; + }; + const auto arrow = [&](double x, double y, double dx, double dy, + bool dashed = false) { + out << ""; + }; + field(19, 9, 104, 62); + field(19, 82, 104, 62); + field(137, 10, 58, 37); + field(205, 10, 58, 37); + const std::array, 10> formation = {{{5, 1}, + {5, 3}, + {5, 5}, + {5, 7}, + {10, 1}, + {10, 3}, + {10, 5}, + {10, 7}, + {16, 3}, + {16, 5}}}; + for (const auto &[x, y] : formation) { + const double px = 25 + x / 18.0 * 82, py = 16 + y / 8.0 * 49; + arrow(px, py, std::array{-16, -7, 7, 16}[size_t(values[0])], 0); + dot(px, py); + } + for (int k = 0; k < 2; ++k) { + const int x = 137 + k * 68; + dot(x + 12, 27); + dot(x + 25, 20); + dot(x + 25, 37); + dot(x + 43, 28, true); + if (values[size_t(5 + k)] == 0) + out << ""; + } + dot(29, 111); + dot(76, 94); + dot(76, 119); + dot(101, 118); + dot(111, 120, true); + arrow(29, 111, 10 + values[3] * 10, -values[3] * 5, true); + arrow(76, 94, 10 + values[2] * 8, 12 - values[2] * 5); + arrow(76, 119, 10 + values[1] * 8, -8 + values[1] * 4, true); + for (int x : {181, 222}) + out << ""; + out << ""; + return out.str(); +} +} // namespace bmh::modern_ui diff --git a/src/modern/ui/demo_sports.hpp b/src/modern/ui/demo_sports.hpp new file mode 100644 index 0000000..cceb1c0 --- /dev/null +++ b/src/modern/ui/demo_sports.hpp @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-3.0-only +#pragma once +#include "modern/ui/catalog.hpp" + +namespace bmh::modern_ui { +// UI fixtures from the HTML reference; these never run a training/match rule. +Json demo_training(const Catalog &, const std::string &club); +bool valid_demo_training(const Json &, const Catalog &, + const std::string &club); +std::string edit_demo_training(Json &, const Json &action); +Json demo_tactics(); +bool valid_demo_tactics(const Json &); +std::string edit_demo_tactics(Json &, const Json &action); +std::string tactics_diagram(const Json &, const std::string &theme); +} // namespace bmh::modern_ui diff --git a/src/modern/ui/model.cpp b/src/modern/ui/model.cpp index e964da6..e0e04a9 100644 --- a/src/modern/ui/model.cpp +++ b/src/modern/ui/model.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only #include "modern/ui/model.hpp" +#include "modern/ui/demo_sports.hpp" #include "modern/ui/desktop.hpp" #include #include @@ -73,6 +74,8 @@ DemoSource::DemoSource(std::shared_ptr catalog) {"preferences", {{"theme", "midnight"}, {"volume", 80}, {"effects", true}}}, {"edits", Json::object()}}; + state_["training"] = demo_training(*catalog_, club); + state_["tactics"] = demo_tactics(); saved_ = state_; if (!valid_date(state_.at("date"))) throw editor::Error("invalid_demo_date"); @@ -106,6 +109,19 @@ ActionResult DemoSource::apply(const Action &action) { return {false, revision_, "invalid_manager"}; } next["managers"] = action.value; + const auto first = action.value.at(0).at("club").get(); + if (next.at("training").at("club") != first) { + next["training"] = demo_training(*catalog_, first); + next["tactics"] = demo_tactics(); + } + } else if (action.kind == "training") { + const auto error = edit_demo_training(next["training"], action.value); + if (!error.empty()) + return {false, revision_, error}; + } else if (action.kind == "tactics") { + const auto error = edit_demo_tactics(next["tactics"], action.value); + if (!error.empty()) + return {false, revision_, error}; } else if (action.kind == "camp.select") { if (!camp_id(action.value)) return {false, revision_, "camp_unknown"}; @@ -147,7 +163,7 @@ void DemoSource::save(const fs::path &file, const Json &desktop) { saved_ = state_; } Json DemoSource::load(const fs::path &file) { - const auto data = Json::parse(editor::read_file(file)); + auto data = Json::parse(editor::read_file(file)); if (data.value("schema", "") != "openbmh-ui-demo@1" || data.value("world", "") != catalog_->manifest().value("id", "")) throw editor::Error("wrong_demo_world"); @@ -155,6 +171,14 @@ Json DemoSource::load(const fs::path &file) { const auto result = validation.apply({0, "managers", data.at("managers")}); if (!result.ok) throw editor::Error(result.error); + const auto club = data.at("managers").at(0).at("club").get(); + if (!data.contains("training")) + data["training"] = demo_training(*catalog_, club); + if (!data.contains("tactics")) + data["tactics"] = demo_tactics(); + if (!valid_demo_training(data.at("training"), *catalog_, club) || + !valid_demo_tactics(data.at("tactics"))) + throw editor::Error("invalid_demo_sports"); if (!data.at("ticket").is_number_integer() || data.at("ticket") < 0 || data.at("ticket") > 25) throw editor::Error("invalid_demo_ticket"); diff --git a/src/modern/ui/screens.inc b/src/modern/ui/screens.inc index c054245..bd7ca37 100644 --- a/src/modern/ui/screens.inc +++ b/src/modern/ui/screens.inc @@ -963,6 +963,10 @@ std::string App::render_menu(const std::string &key) { std::string body; if (key == "tables" || key == "strengths") body = render_table(key == "strengths", false); + else if (key == "training") + body = render_training(); + else if (key == "tactics") + body = render_tactics(); else if (key == "camp") body = render_camp(); else if (key == "settings") diff --git a/src/modern/ui/sports_screens.inc b/src/modern/ui/sports_screens.inc new file mode 100644 index 0000000..b3a3f43 --- /dev/null +++ b/src/modern/ui/sports_screens.inc @@ -0,0 +1,181 @@ +// SPDX-License-Identifier: GPL-3.0-only +std::string App::training_balls(const std::string &group, int index, int value, + bool automatic, const std::string &player, + int size, int gap, bool overtraining) { + std::string body = + "
"; + for (int i = 1; i <= 3; ++i) + body += btn( + "training-ball", img("training.ball", size, size, false, false, 128), + std::string("training-ball ") + + (i <= value ? "is-selected" : "is-empty") + + (overtraining && i <= value ? " overtraining" : ""), + "id=\"training-ball-" + group + "-" + std::to_string(index) + "-" + + std::to_string(i) + "\" data-group=\"" + group + "\" data-id=\"" + + std::to_string(index) + "\" data-player=\"" + esc(player) + + "\" data-value=\"" + std::to_string(i) + "\" style=\"width:" + + std::to_string(size) + "dp;height:" + std::to_string(size) + + "dp;\" " + (automatic ? "disabled" : "")); + return body + "
"; +} +std::string App::render_training() { + const auto s = snap(); + const auto &t = s.state.at("training"), &automatic = t.at("autos"); + const std::array skills = { + "Kondition", "Technik", "Eckball", "Freistoß", "Zweikampf", + "Pass", "Schuss", "Schnelligkeit", "Teamplay"}; + const std::vector> focuses = { + {"0", "Allgemein"}, {"1", "Eckball"}, {"2", "Freistoß"}, + {"3", "Zweikampf"}, {"4", "Pass"}, {"5", "Schuss"}, + {"6", "Schnelligkeit"}, {"7", "Teamplay"}}; + int skill_total = 0, type_total = 0; + for (size_t i = 2; i < 9; ++i) + skill_total += t["areas"][i].get(); + for (const auto &v : t["types"]) + type_total += v.get(); + std::string body = "
"; + for (size_t i = 0; i < 9; ++i) + body += + "
" + + img("training.skill." + std::to_string(i), 80, 80, false, false, 160) + + "
" + skills[i] + + ":
" + + training_balls("area", int(i), t["areas"][i].get(), + automatic[i < 2 ? 1 : 2].get(), {}, 56, 10, + i >= 2 && skill_total > 14) + + "
"; + body += "
"; + for (int i = 0; i < 10; ++i) + body += "
"; + body += "
"; + for (int i = 0; i < 4; ++i) + body += "
" + + training_balls("type", i, t["types"][size_t(i)].get(), + automatic[0].get(), {}, 48, 5) + + "
"; + body += "
"; + const std::array auto_names = { + "AUTO · Arten", "AUTO · Kondition", "AUTO · Fertigkeiten", + "AUTO · Spieler"}; + const std::array, 4> auto_boxes = { + {{0, 1456, 570, 76}, + {604, 1040, 440, 76}, + {604, 1136, 440, 76}, + {2312, 1803, 300, 61}}}; + for (size_t i = 0; i < 4; ++i) { + const auto a = auto_boxes[i]; + body += btn( + "training-auto", auto_names[i], + std::string(i == 3 ? "training-auto auto-players " : "training-auto ") + + (automatic[i].get() ? "primary" : ""), + "id=\"training-auto-" + std::to_string(i) + "\" data-id=\"" + + std::to_string(i) + "\" style=\"position:absolute;" + + rect(a[0], a[1], a[2], a[3]) + "\""); + } + const bool all_auto = std::all_of(automatic.begin(), automatic.end(), + [](const auto &v) { return v == true; }); + body += btn("training-auto-all", "Automatisch", + std::string("training-auto ") + (all_auto ? "primary" : ""), + "id=\"training-auto-all\" style=\"position:absolute;" + + rect(604, 1232, 440, 76) + "\""); + body += "

Arten: " + std::to_string(type_total) + + " / 8 Bälle ·
Kondition/Technik: " + + std::to_string(t["areas"][0].get() + t["areas"][1].get()) + + " / 4 ·
Fertigkeiten: " + std::to_string(skill_total) + " / 18" + + (skill_total > 14 ? " · hohe
Belastung" : "") + + "

"; + const std::array headings = {"Pos.", "Spieler", "Stärke", + "Schwerpunkt", "Intensität"}; + const std::array widths = {90, 300, 95, 510, 497}; + for (size_t i = 0; i < 5; ++i) + body += "
" + + headings[i] + "
"; + body += "
"; + const auto players = world_->squad(t.value("club", "")); + for (size_t i = 0; i < players.size(); ++i) { + const auto *p = players[i]; + const auto id = p->value("id", ""); + const auto &row = t["players"].at(id); + const auto position = p->value("positions", Json::array()); + const auto pos = position.empty() ? "" : position[0].get(); + body += + "
" + + std::string(pos == "gk" ? "TW" + : pos == "def" ? "ABW" + : pos == "mid" ? "MIT" + : pos == "fwd" ? "STU" + : pos) + + "
name(*p)) + "\">" + esc(world_->name(*p)) + + "
" + + std::to_string( + p->value("attributes", Json::object()).value("strength", 0)) + + "
"; + auto selector = + select("training-focus-" + std::to_string(i), focuses, + std::to_string(row.value("focus", 0)), "training-focus"); + const auto end = selector.find('>'); + selector.insert(end, " data-player=\"" + esc(id) + "\" " + + (automatic[3] == true ? "disabled" : "")); + body += selector + "
" + + training_balls("player", int(i), row.value("intensity", 0), + automatic[3].get(), id, 50, 9) + + "
"; + } + return body + "
"; +} +std::string App::render_tactics() { + const auto t = snap().state.at("tactics"); + const std::array names = { + "Defensiv / offensiv", "Pass-/Schussbild unten", + "Pass-/Schussbild Mitte", "Pass-/Schussbild links", + "Flache / hohe Bälle", "Flügelbild links", + "Flügelbild rechts", "Einsatz"}; + const std::array limits = {3, 3, 3, 3, 1, 1, 1, 11}; + const std::array, 7> areas = {{{19, 9, 104, 62}, + {61, 108, 50, 34}, + {63, 84, 54, 30}, + {26, 95, 24, 24}, + {168, 53, 71, 34}, + {137, 10, 58, 37}, + {205, 10, 58, 37}}}; + std::string body = + "
" + + picture(renderer_.diagram("tactics", tactics_diagram(t, theme_)), 2300, + 1864); + for (size_t i = 0; i < 7; ++i) { + const auto a = areas[i]; + body += btn("tactic-cycle", "", "tactic-hotspot", + "id=\"tactic-cycle-" + std::to_string(i) + "\" data-id=\"" + + std::to_string(i) + "\" aria-label=\"" + esc(names[i]) + + "\" style=\"position:absolute;" + + rect(a[0] / 295.0 * 2300, a[1] / 206.0 * 1864, + a[2] / 295.0 * 2300, a[3] / 206.0 * 1864) + + "z-index:" + std::to_string(8 - i) + ";\""); + } + const int effort = t["values"][7].get(); + body += + "
EINSATZ" + + std::string(size_t(effort), '!') + + "

" + + esc(names[size_t(last_tactic_)]) + ": " + + std::to_string(t["values"][size_t(last_tactic_)].get()) + " / " + + std::to_string(limits[size_t(last_tactic_)]) + "

"; + return body; +} diff --git a/src/modern/ui/view.cpp b/src/modern/ui/view.cpp index 9c62187..e3cd504 100644 --- a/src/modern/ui/view.cpp +++ b/src/modern/ui/view.cpp @@ -5,6 +5,7 @@ #include "launch/rml_path.hpp" #include "launch/rml_video.hpp" #include "modern/ui/controls.hpp" +#include "modern/ui/demo_sports.hpp" #include "modern/ui/desktop.hpp" #include "modern/ui/gui_assets.hpp" #include "modern/ui/model.hpp" @@ -24,6 +25,7 @@ #include #include #include +#include #include namespace bmh::modern_ui { @@ -129,11 +131,29 @@ class Renderer final : public rml::Renderer { }; std::map entries_; std::map keys_; + std::map loaded_sources_; size_t serial_ = 0; public: Renderer(rml::Video &video, GuiAssets &gui, fs::path assets) : rml::Renderer(video), gui_(gui), assets_(std::move(assets)) {} + Picture diagram(const std::string &slot, const std::string &svg, + int pixels = 2400) { + const auto token = "modern-dynamic-" + slot + ".png", + digest = content::sha256(svg); + auto found = entries_.find(token); + if (found == entries_.end() || found->second.key != digest) { + auto raster = editor::images::decode(svg, ".svg", pixels); + if (const auto loaded = loaded_sources_.find(token); + loaded != loaded_sources_.end()) { + Rml::ReleaseTexture(loaded->second, this); + loaded_sources_.erase(loaded); + } + entries_[token] = {digest, false, pixels, std::move(raster)}; + } + const auto &r = entries_.at(token).raster; + return {token, r.width, r.height}; + } Picture local_image(const fs::path &file, int pixels) { const auto identity = editor::utf8(file) + ":" + @@ -155,6 +175,7 @@ public: Rml::ReleaseTextures(this); entries_.clear(); keys_.clear(); + loaded_sources_.clear(); world_ = std::move(value); } Picture image(const std::string &key, bool world = false, int pixels = 512) { @@ -239,6 +260,7 @@ public: auto found = entries_.find(token); if (found == entries_.end()) return rml::Renderer::LoadTexture(dimensions, source); + loaded_sources_[token] = source; auto pixels = found->second.raster.pixels; for (size_t i = 0; i < pixels.size(); i += 4) for (int c = 0; c < 3; ++c) @@ -278,6 +300,9 @@ class App final : public Rml::EventListener { bool focus_ticket_ = false; std::set pending_selects_; std::string focus_after_render_; + bool keyboard_navigation_ = false; + std::string last_rendered_menu_; + std::optional training_scroll_; float device_ratio_ = 1.f; Json desktop_ = Json::object(), saved_desktop_ = Json::object(), options_ = Json::object(); @@ -305,6 +330,7 @@ class App final : public Rml::EventListener { std::string context_id_; int context_x_ = 0, context_y_ = 0; int opening_page_ = 0, draw_revealed_ = 0; + int last_tactic_ = 0; bool draw_playing_ = true; uint64_t draw_at_ = 0; std::string settings_category_ = "display"; @@ -336,7 +362,10 @@ class App final : public Rml::EventListener { } std::string img(const std::string &key, double w, double h, bool world = false, bool cover = false, int pixels = 512) { - const auto p = renderer_.image(key, world, pixels); + return picture(renderer_.image(key, world, pixels), w, h, cover); + } + std::string picture(const Picture &p, double w, double h, + bool cover = false) { if (p.token.empty()) return "
"; @@ -398,6 +427,14 @@ class App final : public Rml::EventListener { bool apply(const std::string &kind, const Json &value) { const auto r = source_->apply({source_->snapshot().revision, kind, value}); if (!r.ok) { + if (kind == "training" && r.error == "training_preview_budget") { + const int limit = value.value("group", "") == "type" ? 8 + : value.value("index", 0) < 2 ? 4 + : 18; + message("Für diesen Trainingsbereich stehen höchstens " + + std::to_string(limit) + " Bälle zur Verfügung."); + return false; + } message("Die Eingabe konnte nicht übernommen werden: " + r.error); return false; } @@ -559,6 +596,11 @@ class App final : public Rml::EventListener { std::string widget(const std::string &, const Json &); std::string render_table(bool strengths = false, bool indoor = false); std::string render_camp(); + std::string render_training(); + std::string render_tactics(); + std::string training_balls(const std::string &, int, int, bool, + const std::string &player = {}, int size = 56, + int gap = 10, bool overtraining = false); std::string render_settings(); std::string render_save(bool save); std::string render_desktop_tools(const std::string &); @@ -605,6 +647,10 @@ class App final : public Rml::EventListener { dirty_ = true; } void render() { + training_scroll_.reset(); + if (menu_ == "training" && last_rendered_menu_ == "training") + if (auto *roster = element("training-roster")) + training_scroll_ = roster->GetScrollTop(); if (ticket_) ticket_->close(false); context_open_ = false; @@ -638,6 +684,7 @@ class App final : public Rml::EventListener { ? "saturate(0.13) brightness(0.56)" : "saturate(0.34) brightness(0.70)"); needs_render_ = false; + last_rendered_menu_ = menu_; dirty_ = true; if (focus_ticket_) { if (auto *n = element("desktop-ticket")) @@ -646,7 +693,7 @@ class App final : public Rml::EventListener { } if (!focus_after_render_.empty()) { if (auto *node = element(focus_after_render_)) - node->Focus(true); + node->Focus(keyboard_navigation_); focus_after_render_.clear(); } } @@ -691,6 +738,11 @@ class App final : public Rml::EventListener { context_->Update(); if (center_selects(*doc_)) context_->Update(); + if (training_scroll_) { + if (auto *roster = element("training-roster")) + roster->SetScrollTop(*training_scroll_); + training_scroll_.reset(); + } renderer_.Clear(); renderer_.BeginFrame(); context_->Render(); @@ -750,6 +802,27 @@ class App final : public Rml::EventListener { bold = Rml::LoadFontFace(rml::asset_path(assets_ / "LatoLatin-Bold.ttf"), "Modern", Rml::Style::FontStyle::Normal, Rml::Style::FontWeight::Bold); + std::vector chalk_fonts; +#ifdef _WIN32 + if (const char *windir = std::getenv("WINDIR")) { + chalk_fonts.push_back(fs::path(windir) / "Fonts" / "comic.ttf"); + chalk_fonts.push_back(fs::path(windir) / "Fonts" / "times.ttf"); + } +#elif defined(__APPLE__) + chalk_fonts = {"/System/Library/Fonts/Supplemental/Comic Sans MS.ttf", + "/System/Library/Fonts/Supplemental/Apple Chancery.ttf", + "/System/Library/Fonts/Times.ttc"}; +#else + chalk_fonts = { + "/usr/share/fonts/truetype/liberation2/LiberationSerif-Regular.ttf", + "/usr/share/fonts/truetype/liberation/LiberationSerif-Regular.ttf"}; +#endif + chalk_fonts.push_back(assets_ / "LatoLatin-Regular.ttf"); + for (const auto &font : chalk_fonts) + if (fs::exists(font) && Rml::LoadFontFace(rml::asset_path(font), "Chalk", + Rml::Style::FontStyle::Normal, + Rml::Style::FontWeight::Normal)) + break; if (!regular || !bold) throw std::runtime_error( "GUI-Schriften fehlen. Bitte das vollständige Paket entpacken."); @@ -906,6 +979,7 @@ public: #include "modern/ui/controls.inc" #include "modern/ui/desktop_screens.inc" #include "modern/ui/screens.inc" +#include "modern/ui/sports_screens.inc" } // namespace bool is_modern_world(const fs::path &file) { try { diff --git a/tests/modern_ui_core_tests.cpp b/tests/modern_ui_core_tests.cpp index 865d774..de17b93 100644 --- a/tests/modern_ui_core_tests.cpp +++ b/tests/modern_ui_core_tests.cpp @@ -1,4 +1,5 @@ // SPDX-License-Identifier: GPL-3.0-only +#include "modern/ui/demo_sports.hpp" #include "modern/ui/desktop.hpp" #include "modern/ui/gui_assets.hpp" #include "modern/ui/model.hpp" @@ -174,6 +175,93 @@ int main(int argc, char **argv) try { require(rejected && source.snapshot().state == accepted.state && source.snapshot().revision == accepted.revision, "Invalid desktop partially restored demo"); + DemoSource sports(world); + const auto initial_sports = sports.snapshot(); + require(!sports + .apply({0, + "training", + {{"kind", "ball"}, + {"group", "type"}, + {"index", 0}, + {"value", 3}}}) + .ok, + "Training preview budget exceeded"); + require(sports.snapshot().state == initial_sports.state && + sports.snapshot().revision == 0, + "Rejected training mutated demo"); + require(!sports + .apply({0, + "training", + {{"kind", "ball"}, + {"group", "area"}, + {"index", 0}, + {"value", 1.5}}}) + .ok, + "Fractional training value accepted"); + const auto player = world->squad("club:a").front()->value("id", ""); + require(sports + .apply({0, + "training", + {{"kind", "ball"}, + {"group", "player"}, + {"player", player}, + {"value", 1}}}) + .ok, + "Player intensity action failed"); + require(sports.snapshot().state["training"]["players"][player]["intensity"] == + 0, + "Selected intensity must toggle to zero in UI demo"); + require(sports + .apply({1, + "training", + {{"kind", "focus"}, {"player", player}, {"value", 7}}}) + .ok, + "Direct focus selection failed"); + for (int i = 0; i < 4; ++i) + require(sports + .apply({sports.snapshot().revision, + "tactics", + {{"kind", "cycle"}, {"index", 0}}}) + .ok, + "Tactic cycle failed"); + require(sports.snapshot().state["tactics"]["values"][0] == + initial_sports.state["tactics"]["values"][0], + "Tactic cycle did not wrap"); + require( + sports + .apply( + {sports.snapshot().revision, "training", {{"kind", "auto-all"}}}) + .ok, + "Global automatic training failed"); + const auto automated = sports.snapshot(); + require(automated.state["training"]["players"][player]["intensity"] == 2 && + automated.state["training"]["players"][player]["focus"] == 7, + "Automatic training must preserve focuses"); + require(!sports.apply({automated.revision, + "training", + {{"kind", "focus"}, {"player", player}, {"value", 0}}}) + .ok && + sports.snapshot().state == automated.state, + "Automatic player controls accepted manual changes"); + sports.save(root / "sports.ui.json", default_desktop()); + DemoSource restored_sports(world); + restored_sports.load(root / "sports.ui.json"); + require(restored_sports.snapshot().state == sports.snapshot().state, + "Training/tactics were lost on restoration"); + auto legacy = Json::parse(bmh::editor::read_file(root / "sports.ui.json")); + legacy.erase("training"); + legacy.erase("tactics"); + write(root, "legacy-ui.json", legacy); + restored_sports.load(root / "legacy-ui.json"); + require(valid_demo_training(restored_sports.snapshot().state["training"], + *world, "club:a"), + "Older UI checkpoint did not migrate safely"); + for (const auto *theme : {"midnight", "silver", "matchday"}) { + const auto diagram = bmh::editor::images::decode( + tactics_diagram(demo_tactics(), theme), ".svg", 256); + require(diagram.width == 256 && diagram.height > 0, + "Tactic SVG failed to decode"); + } GuiAssets absent(root / "missing-gui"); require(!absent.available(), "World resources were mistaken for GUI resources"); diff --git a/tools/modern_ui/prepare_gui_assets.py b/tools/modern_ui/prepare_gui_assets.py index 7078c29..6aba605 100644 --- a/tools/modern_ui/prepare_gui_assets.py +++ b/tools/modern_ui/prepare_gui_assets.py @@ -55,6 +55,10 @@ def main(): for route, button in zip(routes, buttons, strict=True): add('button.' + route, button['src'].removeprefix('../')) add('button.news', 'assets/vector/desktop-news.svg') + for i in range(9): + add('training.skill.' + str(i), 'assets/studies/submenus/training-icons-v2.png', + [(i % 3) / 3, (i // 3) / 3, 1 / 3, 1 / 3]) + add('training.ball', 'assets/studies/submenus/training-ball-v1.png') for i in range(12): add('manager.' + str(i), 'assets/studies/submenus/manager-portraits-photo-v1.png', [(i % 4) / 4, (i // 4) / 3, 1 / 4, 1 / 3])