From d085697bb9ffb4bb4cadf346d7e408ffab7f834a Mon Sep 17 00:00:00 2001 From: Codex Date: Tue, 27 Oct 2026 01:55:12 +0100 Subject: [PATCH] Port career setup, manager hub and context-aware native UI (by Codex) --- assets/modern/career.rcss | 3 + assets/modern/entry.rcss | 23 + assets/modern/lineup.rcss | 7 + assets/modern/modern.rml | 2 +- docs/new_ui/assets.md | 16 + docs/new_ui/desktop/lineup/README.md | 18 + docs/new_ui/desktop/manager/README.md | 20 + docs/new_ui/main-menu/entry/README.md | 15 + src/modern/ui/career_controls.inc | 141 +++++ src/modern/ui/career_screens.inc | 111 ++++ src/modern/ui/contracts_screens.inc | 2 +- src/modern/ui/controls.inc | 17 +- src/modern/ui/demo_career_reports.cpp | 7 +- src/modern/ui/demo_career_reports.hpp | 4 +- src/modern/ui/demo_files.cpp | 3 +- src/modern/ui/demo_finance.cpp | 5 +- src/modern/ui/demo_news.cpp | 3 +- src/modern/ui/demo_stadium.cpp | 6 +- src/modern/ui/demo_stadium.hpp | 2 +- src/modern/ui/demo_statistics.cpp | 7 +- src/modern/ui/demo_widgets.cpp | 3 +- src/modern/ui/entry_controls.inc | 8 +- src/modern/ui/entry_opening_controls.inc | 7 + src/modern/ui/entry_screens.inc | 140 +++-- src/modern/ui/environment_screens.inc | 2 +- src/modern/ui/files_screens.inc | 6 +- src/modern/ui/front_screens.inc | 2 +- src/modern/ui/lineup_controls.inc | 553 +++++++++++++------ src/modern/ui/lineup_screens.inc | 654 +++++++++++++++++------ src/modern/ui/model.cpp | 1 + src/modern/ui/reports_screens.inc | 2 +- src/modern/ui/screens.inc | 13 +- src/modern/ui/stadium_screens.inc | 2 +- src/modern/ui/transfer_screens.inc | 2 +- src/modern/ui/view.cpp | 30 +- src/modern/ui/widgets_screens.inc | 4 + tests/modern_career_ui_tests.cpp | 27 + 37 files changed, 1447 insertions(+), 421 deletions(-) create mode 100644 src/modern/ui/career_controls.inc create mode 100644 src/modern/ui/career_screens.inc diff --git a/assets/modern/career.rcss b/assets/modern/career.rcss index fedbada..b8a957b 100644 --- a/assets/modern/career.rcss +++ b/assets/modern/career.rcss @@ -19,3 +19,6 @@ .career-dialog label {display:block;font-size:32dp;margin-bottom:20dp;} .career-dialog select {width:100%;height:100dp;font-size:32dp;} .career-dialog p {font-size:32dp;line-height:1.5;margin:28dp 0;} + +.career-hub h2,.career-caption strong {font-weight:bold;} +.career-hub header nav {max-width:64%;flex-wrap:wrap;} diff --git a/assets/modern/entry.rcss b/assets/modern/entry.rcss index bb3c082..dc518f8 100644 --- a/assets/modern/entry.rcss +++ b/assets/modern/entry.rcss @@ -156,3 +156,26 @@ body.matchday {--entry-focus:#efb2aa;--entry-selected:#d48c7b26;--entry-accent-b .entry-confirm-dialog>h2 {text-align:center;} .entry-choice-status>span,.entry-manager-portrait-caption>span {display:block;} + +/* Club and international cards mirror the approved HTML career setup. */ +.entry-career-setup .entry-setup-option {padding:26dp 22dp;gap:12dp;} +.entry-career-setup .entry-setup-option>h2 {font-size:34dp;} +.entry-career-setup .entry-setup-stepper button {width:90dp;height:112dp;font-size:60dp;} +.entry-career-setup .entry-setup-value>strong {height:140dp;font-size:138dp;} +.entry-career-setup .entry-setup-value>.entry-setup-duration {font-size:160dp;} +.entry-career-setup .entry-setup-value>span {font-size:28dp;white-space:nowrap;} +.entry-career-setup .entry-setup-balls,.entry-career-setup .entry-setup-people {height:140dp;} +.entry-career-setup .entry-setup-people {gap:8dp;} +.entry-career-setup .entry-setup-competitions {left:786dp;right:0;top:104dp;bottom:124dp;height:auto;} +.entry-career-setup .entry-setup-competition {top:0;width:904dp;height:1580dp;display:block;padding:0;overflow:hidden;border:4dp var(--border);border-radius:22dp;background-color:#0b1724;} +.entry-career-setup .entry-setup-competition>.image-frame {position:absolute;left:0;right:0;top:0;bottom:0;} +.entry-career-setup .entry-setup-competition.selected {border-color:var(--accent);} +.entry-career-setup .entry-setup-competition:disabled {opacity:1;} +.entry-career-setup .entry-career-caption {position:absolute;left:0;right:0;bottom:0;display:flex;flex-direction:column;align-items:flex-start;gap:10dp;padding:70dp 26dp 26dp;background-color:#091522ef;color:#f3f7fb;} +.entry-career-caption strong {font-size:34dp;}.entry-career-caption small {font-size:28dp;color:#d4ede7;} +.entry-career-setup .entry-career-check {position:absolute;right:24dp;top:22dp;width:56dp;height:56dp;display:flex;align-items:center;justify-content:center;background-color:#10282be8;border:2dp #a4dfce;border-radius:28dp;} +.entry-career-setup .entry-setup-competitions>p {top:1598dp;} +.entry-manager-fields.is-national .entry-manager-options {display:none;} +.entry-manager-fields.is-national .entry-manager-choices {top:358dp;} + +.entry-career-setup .entry-career-caption strong {font-weight:bold;} diff --git a/assets/modern/lineup.rcss b/assets/modern/lineup.rcss index 84b5c44..7154618 100644 --- a/assets/modern/lineup.rcss +++ b/assets/modern/lineup.rcss @@ -97,3 +97,10 @@ body.matchday .lineup-row.even {background-color:#f9f4ed05;} body.silver .lineup-taker selectbox {background-color:#f3f7fcfc;} body.matchday .lineup-taker selectbox {background-color:#303037fc;} + +.lineup-surface-controls {position:absolute;right:0;top:1156dp;width:650dp;height:70dp;display:flex;gap:12dp;} +.lineup-surface-controls button {flex:1;min-width:0;height:70dp;font-size:25dp;padding:8dp 14dp;} +.lineup-surface-controls .selected {background-color:var(--selected);border-color:var(--accent);color:var(--accent);} + +.pitch-view .lineup-roster-scroll {height:1068dp;} +.team-view .lineup-surface-controls {display:none;} diff --git a/assets/modern/modern.rml b/assets/modern/modern.rml index c96ed32..596c14a 100644 --- a/assets/modern/modern.rml +++ b/assets/modern/modern.rml @@ -1,6 +1,6 @@ OpenBMH - +
diff --git a/docs/new_ui/assets.md b/docs/new_ui/assets.md index 6b7d9e7..c50d667 100644 --- a/docs/new_ui/assets.md +++ b/docs/new_ui/assets.md @@ -89,3 +89,19 @@ dieselbe Grafik unter `assets/modern/icons/almanac.svg` mit und kann sie auch bei einem älteren externen GUI-Paket anzeigen. Ein OBW muss dieses Motiv nicht enthalten. Bestehende Desktopansichten erhalten nur das zusätzliche Icon an einer freien Stelle; vorhandene Objekte werden dabei nicht verschoben. + +## Karrierebilder und Büro-Unterlagen + +Die optionale private GUI-Vorbereitung übernimmt die unveränderten Nutzerbilder +unter `assets/studies/career/` als `career.club`, `career.international` und drei +normierte Ausschnitte `manager.resign`, `manager.search`, `manager.add` desselben +Sheets. Die beiden Hochformatmotive besitzen1086×1448Pixel, das Sheet1448×1086. +Contain-Darstellung und gemessene Ausschnitte erhalten Proportionen und Köpfe; +es wird keine native4K-Auflösung behauptet. `career.national-de/fr` sind eigene +GUI-Flaggensymbole und keine Vereine im Weltkatalog. + +`menu.club-office` und `menu.trophy-office` werden bei vorhandenen freigegebenen +Study-Dateien ebenfalls übernommen; ältere GUI-Bestände behalten ihren bisherigen +Hintergrundfallback. Das Manifest zeichnet Dateiquelle, SHA256 und Ausschnitt auf +und bleibt als `private-reference-assets` gekennzeichnet. Diese Quelländerung +verteilt keine privaten PNGs und ändert weder OBW noch dessen Asset-Index. diff --git a/docs/new_ui/desktop/lineup/README.md b/docs/new_ui/desktop/lineup/README.md index 5eda00a..e212979 100644 --- a/docs/new_ui/desktop/lineup/README.md +++ b/docs/new_ui/desktop/lineup/README.md @@ -21,3 +21,21 @@ Synthetische Providerprüfungen decken leere, kurze und vollständige Kader, die Der unabhängige Vergleich der vorigen Geometrie bestätigt sechs erfolgreiche Rendererfälle und 48 Status-/Readonly-Prüfungen. Alle sechs Grundansichten und die schmalen eigenen Formationen, Anweisungen und Schützenpicker wurden angesehen. In 24 vermessenen Controlzuständen gibt es keinen unerwarteten horizontalen Textüberlauf; die Seitentitel entsprechen den aktuellen HTML-Maßen (Schrift 34, Boxhöhe 39). Der reine Reglernachtest auf der abschließenden Runtime bleibt in den Metadaten von den vorherigen Geometrieaufnahmen getrennt. Die aktuelle Aufteilung mit breiten Namen und ungefähr zwei Dritteln Tabelle ist getrennt unter `docs/qa/lineup-table-focus-2026-10-25/` geprüft. Der gemeinsame Build und alle 26 Regressionstests bestehen. Der unabhängige Vergleich umfasst sechs Theme-/Größenfälle, 96 Status-/Readonly-/Layoutprüfungen und 18 direkte Popup-Bildgrenzen; beide Datenseiten und alle 20 tatsächlichen Namen passen ohne Textüberlauf. Die drei Schützenlisten bleiben selbst bei 720p mit mindestens zwölf physischen Pixeln Reserve innerhalb des Inhalts. Zwei gezielte Bedienläufe mit 20 und 24 Spielern bestätigen vollständigen Kaderzugriff, Profile, Tauschen durch Anklicken und Ziehen, korrekt skalierte Ziehgeister, eigene Formationen, Gewichtungen, Schützenabbruch, Regler und tatsächlich geänderte rote Fläche sowie saubere Checkpoints. Die bisherigen Nachweise bleiben als vorangegangene Geometrien unverändert. + +## Getrennte Hallenvorschau + +Die native Demo kann über die Managerzentrale oder den Umschalter im Spielfeld +zwischen Rasen und Halle wechseln. Rasen erhält elf gleichzeitige Positionen, +die Halle sechs. Die ersten elf bilden den Rotationsplan (ein Torwart und fünf +Paare); weitere tatsächlich vorhandene Weltspieler bleiben als Reserve sichtbar. +Die Kennzeichnung von fünf Partnern ist keine zusätzliche allgemeine +Kader-/Einsatzsperre. Ein beliebiger vorhandener Spieler darf per Tausch einen +Feldplatz übernehmen. Nur die Positionsbearbeitung selbst gilt für die aktuell +sichtbaren sechs beziehungsweise elf Plätze. + +Rasen und Halle behalten getrennte Positionen, Formationen, Aufträge und Schützen. +Das gemeinsame interne Positionsformat bleibt elfgeteilt, während der lesende +Starterzugriff nur die sechs Hallenpositionen projiziert. Eine passende braune +Hallenfläche ersetzt die grüne Rasenfläche. Der Kader bleibt vollständig; +fehlende Spieler werden weder ergänzt noch als Nationalberufung erfunden. +Es werden keine Rotation, Auswechslung oder Spielminute von einer Engine bewegt. diff --git a/docs/new_ui/desktop/manager/README.md b/docs/new_ui/desktop/manager/README.md index 597d747..8111e8b 100644 --- a/docs/new_ui/desktop/manager/README.md +++ b/docs/new_ui/desktop/manager/README.md @@ -60,3 +60,23 @@ aktiveIdentität, Rollen-/Menüsperren, verworfene/stale Aktionen, getrennte Hallenanker, kein siebter Feldspieler, erhaltene Vereinsansichten sowie Checkpoint-/Game-End-Fortsetzung. Native Bild- und Eingabeprüfung folgt nach dem UI-App-Link; dieser Modellmeilenstein behauptet noch keine grafische Abnahme. + +## Nativer UI-Meilenstein + +Manager-Hub mit Nutzerillustrationen, Besitzerwahl und Bestätigung der Abgabe, +deaktivierter Vereinssuche („Später“) und dem bisherigen Neuen-Spieler-Dialog +sind nativ angebunden. Rollen- und Managerauswahl verwenden denselben Kontext +wie Header, Wappen, Aufstellung, Verträge, Stadion, Transferansichten, Statistik +und Save-Metadaten. Personenreihenfolge und gewählte Identität bleiben erhalten. +Eine geöffnete Abgabebestätigung bindet Sourceidentität und Revision; eine +inzwischen gewechselte Partie wird abgewiesen. Nach Game End führen weder +Desktop-Rückkehr noch alte Opening-Fortsetzung in die beendete Partie. + +Die ersten echten Linux-RmlUI-Eingabeläufe bestehen33/33 Prüfungen in zwei normal +beendeten Prozessen: National-only mit gesperrtem zweiten Menschen und komplette +Vier-Personen-Partie einschließlich Rollenwechsel, Hallen-/Rasenankern, +Save/Export, verworfener Abgabe, anderem Besitzer, KI-Vermerk und letztem +Game End mit erneut erreichbarem Neuen Spiel. Zehn betroffene CTest-Gruppen sind +grün. Die gemessenen Binär-/Welt-Hashes liegen in privater QA; das OBW bleibt +unverändert. Drei-Theme-Bildvergleich, Resize-Gegenprobe und Neustarts werden als +separater Folgeschritt dokumentiert; keine Mac-/Windows-Abnahme wird behauptet. diff --git a/docs/new_ui/main-menu/entry/README.md b/docs/new_ui/main-menu/entry/README.md index ba0280c..2d6886f 100644 --- a/docs/new_ui/main-menu/entry/README.md +++ b/docs/new_ui/main-menu/entry/README.md @@ -54,3 +54,18 @@ UI-Checkpoints werden im privaten QA-Verzeichnis `docs/qa/entry-flow-batch-2026-10-26` geführt. Tatsächliche Laufresultate und verbleibende Abweichungen stehen im dortigen Bericht; Quellvergleich allein wird nicht als Laufabnahme ausgewiesen. + +## Nachtpaket: fester Modus und Wettbewerbskarten + +Der native UI-Entwurf entfernt die Moduswahl; gültige ältere UI-JSON-Spielstände +mit Modus1/2 normalisieren auf3. Dauer, Schwierigkeit und1–4 Menschen bleiben. +Vereinsfußball und International sind zwei getrennte Bildkarten mit gedrücktem +Zustand; mindestens eine bleibt aktiv. International allein erlaubt weiterhin +nur einen Menschen und zeigt eine gesperrte Deutschlandkarte, keine wählbare +Vereinskarte. Die Liga-/Stärkeeinstellungen werden dort ausgeblendet. + +Das Büro bleibt hinter frischem Setup, Managerwizard und Saisonvorbereitung; +beim Hinzufügen bleibt der vorhandene Desktop sichtbar und gesperrt. Die neue +Managerzentrale, aktiver Mensch und Rollen stehen im +[Managervertrag](../../desktop/manager/README.md). Die Motive gehören zum +externen GUI-Paket, nicht zum OBW und nicht zum öffentlichen Quellpaket. diff --git a/src/modern/ui/career_controls.inc b/src/modern/ui/career_controls.inc new file mode 100644 index 0000000..ec26752 --- /dev/null +++ b/src/modern/ui/career_controls.inc @@ -0,0 +1,141 @@ +// SPDX-License-Identifier: GPL-3.0-only +bool App::career_action(const std::string &action, Rml::Element *target) { + if (scene_ != "managerhub" || !source_ || !popup_.empty()) + return false; + const auto id = + target ? target->GetAttribute("data-id", "") : ""; + if (action == "career-resign-cancel") { + career_resign_open_ = false; + focus_after_render_ = "career-resign"; + refresh(); + return true; + } + if (action == "career-game-end") { + career_game_end_ = false; + career_resign_open_ = false; + scene_ = "main"; + menu_.clear(); + focus_after_render_ = "front-new"; + refresh(); + return true; + } + if (career_game_end_) + return true; + if (career_resign_open_) { + if (action == "career-resign-confirm") { + const auto value = field("career-resign-owner"); + if (value.empty() || value.size() > 2 || + !std::all_of(value.begin(), value.end(), + [](char c) { return c >= '0' && c <= '9'; })) + return true; + const auto result = + source_.get() == career_resign_source_ + ? source_->apply( + {career_resign_revision_, + "career", + {{"kind", "resign"}, {"portrait", std::stoi(value)}}}) + : ActionResult{false, 0, "changed_session"}; + if (!result.ok) { + career_resign_open_ = false; + refresh(); + message("Die Partie hat sich geändert. Bitte die Managerabgabe erneut " + "öffnen."); + return true; + } + { + career_resign_open_ = false; + career_game_end_ = snap().state.at("career").value("ended", false); + focus_after_render_ = + career_game_end_ ? "career-game-end" : "career-resign"; + refresh(); + } + } + return true; + } + if (action == "close") { + scene_ = + snap().state.at("career").value("ended", false) ? "main" : "desktop"; + focus_after_render_ = "object-app-newplayer"; + refresh(); + return true; + } + if (action == "career-add") { + entry_add(); + return true; + } + if (action == "career-resign") { + career_resign_open_ = true; + career_resign_portrait_ = manager(snap()).value("portrait", 0); + career_resign_revision_ = snap().revision; + career_resign_source_ = source_.get(); + focus_after_render_ = "career-resign-owner"; + refresh(); + return true; + } + if (action == "career-manager" && !id.empty()) { + if (apply("career", + {{"kind", "select_manager"}, {"portrait", std::stoi(id)}})) { + focus_after_render_ = "career-manager-" + id; + refresh(); + } + return true; + } + if (action == "career-role" || action == "career-surface") { + if (apply("career", {{"kind", action == "career-role" ? "role" : "surface"}, + {"value", id}})) { + focus_after_render_ = action + "-" + id; + refresh(); + } + return true; + } + return false; +} +bool App::career_event(Rml::Event &event) { + if (scene_ != "managerhub" || !source_ || !popup_.empty()) + return false; + const auto type = event.GetType(); + const bool keyboard = type == "keydown"; + const auto key = keyboard ? Rml::Input::KeyIdentifier( + event.GetParameter("key_identifier", 0)) + : Rml::Input::KI_UNKNOWN; + if (key == Rml::Input::KI_ESCAPE) { + career_action(career_game_end_ ? "career-game-end" + : career_resign_open_ ? "career-resign-cancel" + : "close", + nullptr); + event.StopImmediatePropagation(); + return true; + } + if (!career_resign_open_ && !career_game_end_) + return false; + auto *target = event.GetTargetElement(); + bool inside = false; + for (auto *n = target; n && n != doc_; n = n->GetParentNode()) + if (n->GetId() == "career-dialog-layer") + inside = true; + if (!inside && (type == "click" || type == "mousedown" || type == "mouseup" || + type == "dblclick")) { + event.StopImmediatePropagation(); + return true; + } + if (key == Rml::Input::KI_TAB) { + Rml::ElementList nodes; + if (auto *layer = element("career-dialog-layer")) + layer->QuerySelectorAll(nodes, "button,select"); + nodes.erase( + std::remove_if(nodes.begin(), nodes.end(), + [](auto *n) { return n->HasAttribute("disabled"); }), + nodes.end()); + if (!nodes.empty()) { + auto i = + std::find(nodes.begin(), nodes.end(), context_->GetFocusElement()); + const int old = i == nodes.end() ? -1 : int(i - nodes.begin()), + step = event.GetParameter("shift_key", 0) ? -1 : 1; + nodes[size_t((old + step + int(nodes.size())) % int(nodes.size()))] + ->Focus(true); + } + event.StopImmediatePropagation(); + return true; + } + return false; +} diff --git a/src/modern/ui/career_screens.inc b/src/modern/ui/career_screens.inc new file mode 100644 index 0000000..2edc113 --- /dev/null +++ b/src/modern/ui/career_screens.inc @@ -0,0 +1,111 @@ +// SPDX-License-Identifier: GPL-3.0-only +std::string App::render_career() { + const auto s = snap(); + const auto c = demo_career_context(s.state, *s.world); + const bool ended = c.at("ended"); + const auto &m = manager(s); + std::string body = + "

" + + esc(ended ? "Karriere beendet" : m.value("name", "")) + "

" + + esc(c.at("current_team").value("name", "")) + " · " + + (c.at("role") == "national" ? "Nationalmannschaft" : "Vereinsmanager") + + "

"; + const auto card = [&](const std::string &action, const std::string &key, + const std::string &title, const std::string ¬e, + const std::string &css, bool disabled) { + return btn( + action, + img(key, css == "career-add" ? 2612 : 1292, 724, false, false, 1600) + + "" + title + + "" + note + "", + "career-card " + css, + "id=\"" + action + "\" " + (disabled ? "disabled" : "")); + }; + body += card("career-resign", "manager.resign", "Aufgeben", + "Dein Amt abgeben", "career-resign", ended) + + card("career-search", "manager.search", "Vereinssuche", "Später", + "career-search", true) + + card("career-add", "manager.add", "Neuer Spieler", + "Weiteren Menschen einrichten", "career-add", ended) + + "
Dein Aufgabenbereich
"; + for (const auto &role : c.at("available_roles")) { + const auto id = role.get(); + body += btn("career-role", id == "club" ? "Verein" : "Nationalmannschaft", + c.at("role") == role ? "selected" : "", + "id=\"career-role-" + id + "\" data-id=\"" + id + + "\" aria-pressed=\"" + + (c.at("role") == role ? "true" : "false") + "\" " + + (ended ? "disabled" : "")); + } + body += "
Aufstellung · Vorschau
"; + for (const auto *surface : {"outdoor", "indoor"}) + body += btn("career-surface", + std::string(surface) == "indoor" ? "Halle · 6 Spieler" + : "Rasen · 11 Spieler", + c.at("surface") == surface ? "selected" : "", + "id=\"career-surface-" + std::string(surface) + + "\" data-id=\"" + surface + "\" aria-pressed=\"" + + (c.at("surface") == surface ? "true" : "false") + "\" " + + (ended || (std::string(surface) == "indoor" && + c.at("role") == "national") + ? "disabled" + : "")); + body += "
"; + if (career_resign_open_ || career_game_end_) { + body = "
" + body + + "

" + + std::string(career_game_end_ ? "Spiel beendet" + : "Manageramt aufgeben?") + + "

"; + if (career_game_end_) + body += "

Der letzte menschliche Mitspieler hat sein Amt abgegeben. " + "Zurück zum Hauptmenü.

" + + btn("career-game-end", "Zum Hauptmenü", {}, + "id=\"career-game-end\"") + + "
"; + else { + std::vector> people; + for (const auto &person : c.at("active_managers")) { + const auto *club = s.world->find("clubs", person.value("club", "")); + people.emplace_back( + std::to_string(person.value("portrait", 0)), + person.value("name", "") + " · " + + (s.state.at("edits").at("setup").value("league", true) + ? (club ? s.world->name(*club) : "") + : "Deutschland")); + } + body += + "" + + select("career-resign-owner", people, + std::to_string(career_resign_portrait_), + "career-resign-owner") + + "

" + + (people.size() == 1 + ? "Du bist der letzte menschliche Mitspieler. Mit deiner " + "Bestätigung endet diese Partie." + : "Die anderen Menschen spielen weiter. Die KI übernimmt den " + "abgegebenen Verein in dieser Karrierevorschau.") + + "

" + + btn("career-resign-cancel", "Abbrechen", {}, + "id=\"career-resign-cancel\"") + + btn("career-resign-confirm", "Amt aufgeben", {}, + "id=\"career-resign-confirm\"") + + "
"; + } + body += "
"; + } + return window("Manager", body); +} diff --git a/src/modern/ui/contracts_screens.inc b/src/modern/ui/contracts_screens.inc index 6f57cc9..e360c2c 100644 --- a/src/modern/ui/contracts_screens.inc +++ b/src/modern/ui/contracts_screens.inc @@ -15,7 +15,7 @@ std::string contracts_text(const Json &value, const std::string &fallback = "— std::string contracts_managed(const Snapshot &snapshot) { const auto &managers = contracts_field(snapshot.state, "managers"); return managers.is_array() && !managers.empty() - ? contracts_text(contracts_field(managers[0], "club"), "") : ""; + ? contracts_text(contracts_field(demo_career_manager(snapshot.state), "club"), "") : ""; } Json contracts_projection(const Snapshot &snapshot) { if (!snapshot.world) return {{"ok", false}}; diff --git a/src/modern/ui/controls.inc b/src/modern/ui/controls.inc index f288c73..13e3412 100644 --- a/src/modern/ui/controls.inc +++ b/src/modern/ui/controls.inc @@ -148,6 +148,7 @@ void App::ProcessEvent(Rml::Event &event) try { if (n->GetId() == "native-ticket-layer") return; if(front_event(event))return; + if (career_event(event)) return; if (entry_event(event)) return; if (opening_event(event)) return; if (amount_event(event)) return; @@ -464,6 +465,7 @@ void App::dispatch(const std::string &action, Rml::Element *target) { const auto id = target ? target->GetAttribute("data-id", "") : std::string(); if(front_action(action,target))return; + if (career_action(action,target)) return; if (entry_action(action, target)) return; if (opening_action(action, target)) return; if (settings_action(action,target)) return; @@ -682,10 +684,11 @@ void App::dispatch(const std::string &action, Rml::Element *target) { } if (action.starts_with("open:")) { const auto route = action.substr(5); + if(source_&&!demo_career_menu_available(snap().state,route)){message(snap().state.at("career").value("ended",false)?"Diese Partie ist beendet. Bitte ein neues Spiel beginnen oder einen Spielstand laden.":"Dieses Vereinsmenü ist für die Nationalmannschaft nicht verfügbar.");return;} if (route == "kickoff") return; if (route == "newplayer") { - entry_add(); + scene_="managerhub";menu_.clear();career_resign_open_=career_game_end_=false;focus_after_render_="career-resign";refresh(); return; } static const std::set available = { @@ -890,7 +893,14 @@ void App::script() { try { const auto command = Json::parse(line); const auto type = command.value("type", std::string()); - if(type=="front-wait"){ + if(type=="window-resize-probe"){ + // QA-only synthetic event: no OS window or mouse coordinate is changed. + int w,h,pw,ph;SDL_GetWindowSize(video_.window,&w,&h);video_.drawable_size(pw,ph); + const auto before=context_->GetDimensions();SDL_Event probe{};probe.type=SDL_WINDOWEVENT;probe.window.windowID=SDL_GetWindowID(video_.window);probe.window.event=SDL_WINDOWEVENT_SIZE_CHANGED;probe.window.data1=std::max(1,w/2);probe.window.data2=std::max(1,h/2);handle_event(probe); + const auto after=context_->GetDimensions();const bool ok=after.x==pw&&after.y==ph; + editor::write_atomic(editor::path(command.at("path").get()),Json{{"qa_only",true},{"logical",{w,h}},{"drawable",{pw,ph}},{"context_before",{before.x,before.y}},{"synthetic_event",{probe.window.data1,probe.window.data2}},{"context_after",{after.x,after.y}},{"passed",ok}}.dump(2)); + if(!ok)throw editor::Error("QA resize probe: context dimensions were overwritten by logical event data."); + }else if(type=="front-wait"){ const auto end=SDL_GetTicks64()+command.value("timeout_ms",uint64_t(300000)); while(front_busy_&&SDL_GetTicks64()snapshot() : Json()}, {"entry_view", entry_snapshot()}, {"front_view",front_snapshot_view()}, {"files_view",{{"mode",files_mode_},{"selected",files_selected_},{"name",files_name_},{"feedback",files_feedback_}}}, {"widget_view",{{"query",widget_query_},{"notice",widget_notice_}}}, {"ui_preferences",ui_preferences_}, {"settings_draft",settings_draft_}, {"settings_category",settings_category_}, {"settings_query",settings_query_}, {"settings_notice",settings_notice_}, + {"select_menu", select_menu_ ? select_menu_->snapshot() : Json()}, {"career_context",source_?demo_career_context(snap().state,*world_):Json()}, {"manager_hub",{{"resign_open",career_resign_open_},{"game_end",career_game_end_},{"owner",field("career-resign-owner")}}}, {"entry_view", entry_snapshot()}, {"front_view",front_snapshot_view()}, {"files_view",{{"mode",files_mode_},{"selected",files_selected_},{"name",files_name_},{"feedback",files_feedback_}}}, {"widget_view",{{"query",widget_query_},{"notice",widget_notice_}}}, {"ui_preferences",ui_preferences_}, {"settings_draft",settings_draft_}, {"settings_category",settings_category_}, {"settings_query",settings_query_}, {"settings_notice",settings_notice_}, {"statistics_view", statistics_view_}, {"statistics_trophy", statistics_trophy_}, {"statistics_scrolls", statistics_scrolls_}, {"news_view", news_view_}, {"news_dialog", news_dialog_}, @@ -977,6 +987,7 @@ void App::script() { {"focus", context_->GetFocusElement() ? context_->GetFocusElement()->GetId() : ""}, {"contracts_view", {{"dialog", contracts_dialog_}, {"player", contracts_player_}, {"tab", contracts_tab_}, {"draft", contract_draft_}}}, {"amount_editor", amount_ ? Json{{"title", amount_->request.title}, {"raw", amount_->raw}, {"review", amount_->review}, {"error", amount_error()}} : Json()}, + {"display_metrics",[&](){int w,h,pw,ph;SDL_GetWindowSize(video_.window,&w,&h);video_.drawable_size(pw,ph);const auto d=context_->GetDimensions();return Json{{"logical",{w,h}},{"drawable",{pw,ph}},{"context",{d.x,d.y}}};}()}, {"source_revision", source_ ? Json(snap().revision) : Json()}, {"game_dirty", source_ && source_->dirty()}, {"desktop_dirty", desktop_ != saved_desktop_}, diff --git a/src/modern/ui/demo_career_reports.cpp b/src/modern/ui/demo_career_reports.cpp index e302c54..f879414 100644 --- a/src/modern/ui/demo_career_reports.cpp +++ b/src/modern/ui/demo_career_reports.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only #include "modern/ui/demo_career_reports.hpp" +#include "modern/ui/demo_career.hpp" #include #include #include @@ -35,9 +36,9 @@ Context context(const Catalog &world,const Json &state) { Context c; const auto &managers=field(state,"managers"); if(managers.is_array()&&!managers.empty()&&managers[0].is_object()) { - c.manager=text(field(managers[0],"name")); - const auto id=text(field(managers[0],"club"),""); - if(!id.empty())if(const auto *club=world.find("clubs",id);club&&club->value("type",std::string("club"))=="club")c.club=id; + c.manager=text(field(demo_career_manager(state),"name")); + const auto id=text(field(demo_career_manager(state),"club"),""); + if(state.value("career",Json::object()).value("role","club")!="national"&&!id.empty())if(const auto *club=world.find("clubs",id);club&&club->value("type",std::string("club"))=="club")c.club=id; } auto reference=field(state,"date"); if(!date(reference))reference=world.manifest().value("start_date",Json()); diff --git a/src/modern/ui/demo_career_reports.hpp b/src/modern/ui/demo_career_reports.hpp index 777dfff..a23a6c0 100644 --- a/src/modern/ui/demo_career_reports.hpp +++ b/src/modern/ui/demo_career_reports.hpp @@ -4,13 +4,13 @@ namespace bmh::modern_ui { // Read-only, deterministic presentation fixtures. FULL demo state supplies only -// the first manager/club and date. No engine, RNG, wallet or catalogue mutation. +// the active manager/club and date. No engine, RNG, wallet or catalogue mutation. // page0..4 moves the eight-season window backwards by one season per page. // {ok,available,fictional,page,club,manager,first_year,last_year,range,charts, // history:[12 newest completed seasons]}; clubs are existing IDs or null. Json demo_achievements(const Catalog &, const Json &full_state, int page = 0); // At most8 distinct existing clubs, managed club first. Fictional manager names -// and totals match the Gold; the first manager name is taken from the snapshot. +// and totals match the Gold; the active manager name is taken from the snapshot. // {ok,available,fictional,club,manager,rows:[{rank,manager,club,points,...}]}. Json demo_highscores(const Catalog &, const Json &full_state); } // namespace bmh::modern_ui diff --git a/src/modern/ui/demo_files.cpp b/src/modern/ui/demo_files.cpp index 2aeb717..cee2e0f 100644 --- a/src/modern/ui/demo_files.cpp +++ b/src/modern/ui/demo_files.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only #include "modern/ui/demo_files.hpp" +#include "modern/ui/demo_career.hpp" #include "modern/ui/desktop.hpp" #include "editor/images.hpp" #include "content/digest.hpp" @@ -343,6 +344,6 @@ Json DemoFiles::career_metadata(const Json &data) { if (data.contains("game_info")) matchday = data.at("game_info").value("matchday", 0); return {{"season", std::to_string(season) + "/" + std::to_string(season + 1).substr(2)}, {"matchday", matchday > 0 ? std::to_string(matchday) + ". Spieltag" : "Vorbereitung"}, - {"date", date}, {"managers", data.at("managers")}}; + {"date", date}, {"managers", data.at("managers")}, {"current_manager",demo_career_manager(data)}, {"role",data.value("career",Json::object()).value("role","club")}, {"ended",data.value("career",Json::object()).value("ended",false)}, {"human_count",data.value("career",Json::object()).value("ended",false)?0:data.at("managers").size()}}; } } // namespace bmh::modern_ui diff --git a/src/modern/ui/demo_finance.cpp b/src/modern/ui/demo_finance.cpp index f6158c1..335d5fb 100644 --- a/src/modern/ui/demo_finance.cpp +++ b/src/modern/ui/demo_finance.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only #include "modern/ui/demo_finance.hpp" +#include "modern/ui/demo_career.hpp" #include #include #include @@ -52,9 +53,9 @@ std::string own(const Catalog &world, const std::string &managed, const Json *st if (!managers.is_array() || managers.empty() || !managers[0].is_object() || !managers[0].contains("club") || !managers[0]["club"].is_string()) throw editor::Error("invalid_finance_manager"); - if (managers[0]["club"].get().empty()) + if (demo_career_manager(*state).value("club", "").empty()) throw editor::Error("invalid_finance_manager"); - return own(world, managers[0]["club"].get()); + return own(world, demo_career_manager(*state).value("club", "")); } for (const auto *club : world.clubs()) if (world.manageable(club->value("id", ""))) return club->value("id", ""); diff --git a/src/modern/ui/demo_news.cpp b/src/modern/ui/demo_news.cpp index b469c72..dbefd70 100644 --- a/src/modern/ui/demo_news.cpp +++ b/src/modern/ui/demo_news.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only #include "modern/ui/demo_news.hpp" +#include "modern/ui/demo_career.hpp" #include #include #include @@ -310,7 +311,7 @@ Json demo_news_view(const Catalog &world, const Json &state, std::string manager, club_id, club_name; if (state.contains("managers") && state.at("managers").is_array() && !state.at("managers").empty()) { - const auto &m = state.at("managers")[0]; + const auto &m = demo_career_manager(state); manager = m.value("name", ""); club_id = m.value("club", ""); if (const auto *c = world.find("clubs", club_id)) diff --git a/src/modern/ui/demo_stadium.cpp b/src/modern/ui/demo_stadium.cpp index 1fa6608..ed9d943 100644 --- a/src/modern/ui/demo_stadium.cpp +++ b/src/modern/ui/demo_stadium.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only #include "modern/ui/demo_stadium.hpp" +#include "modern/ui/demo_career.hpp" #include "modern/ui/demo_finance.hpp" #include #include @@ -48,8 +49,9 @@ std::string owner(const Catalog &world, const Json *state, std::string requested if (requested.empty() && state && state->is_object()) { const auto managers = state->find("managers"); if (managers != state->end() && managers->is_array() && !managers->empty() && (*managers)[0].is_object()) { - const auto club = (*managers)[0].find("club"); - if (club != (*managers)[0].end() && club->is_string()) requested = club->get(); + const auto &active=demo_career_manager(*state); + const auto club = active.find("club"); + if (club != active.end() && club->is_string()) requested = club->get(); } } if (!requested.empty()) { diff --git a/src/modern/ui/demo_stadium.hpp b/src/modern/ui/demo_stadium.hpp index e4013ef..fd76e11 100644 --- a/src/modern/ui/demo_stadium.hpp +++ b/src/modern/ui/demo_stadium.hpp @@ -25,7 +25,7 @@ std::string edit_demo_stadium(Json &state, const Json &action, const Catalog &, // placesCost,seatsCost,roofCost}. All monetary values are raw minor units. // Invalid input/downgrades => ok=false; no-op, pending target or insufficient // budget => ok=true,can_build=false with a precise error and usable quote. -// Explicit club wins; otherwise full state.managers[0].club, then legacy first +// Explicit club wins; otherwise the active full-state manager club, then legacy first // manageable club, or "" for a catalogue without manageable clubs. Json demo_stadium_quote(const Json &state, const Json &request, const Catalog &, const std::string &club = {}); diff --git a/src/modern/ui/demo_statistics.cpp b/src/modern/ui/demo_statistics.cpp index 39cb992..1f2c71b 100644 --- a/src/modern/ui/demo_statistics.cpp +++ b/src/modern/ui/demo_statistics.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only #include "modern/ui/demo_statistics.hpp" +#include "modern/ui/demo_career.hpp" #include #include #include @@ -120,9 +121,9 @@ Json demo_statistics(const Catalog &world,const Json &state,const Json &request) const Json *own=nullptr;std::string manager_name="—"; const auto &managers=field(state,"managers"); if(managers.is_array()&&!managers.empty()) { - own=world.find("clubs",string(field(managers.front(),"club"))); - if(own&&own->value("type","club")!="club")own=nullptr; - const auto name=string(field(managers.front(),"name"));if(!name.empty())manager_name=name; + own=world.find("clubs",string(field(demo_career_manager(state),"club"))); + if(own&&(own->value("type","club")!="club"||state.value("career",Json::object()).value("role","club")=="national"))own=nullptr; + const auto name=string(field(demo_career_manager(state),"name"));if(!name.empty())manager_name=name; } int year=season_year(field(state,"date")).value_or(season_year(world.manifest().value("start_date",Json())).value_or(2027)); const bool absolute=request.value("absolute",false); diff --git a/src/modern/ui/demo_widgets.cpp b/src/modern/ui/demo_widgets.cpp index 11f33a2..c8b7240 100644 --- a/src/modern/ui/demo_widgets.cpp +++ b/src/modern/ui/demo_widgets.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only #include "modern/ui/demo_widgets.hpp" +#include "modern/ui/demo_career.hpp" #include #include #include @@ -27,7 +28,7 @@ const Json &widget_catalogue() { return catalogue; } Json demo_desktop_widgets(const Catalog &world, const Json &state) { - const auto own = state.at("managers")[0].at("club").get(); + const auto own = demo_career_manager(state).value("club", ""); const auto *club = world.find("clubs", own); const auto clubs = world.clubs(club ? club->value("competition", "") : ""); std::string opponent = own; diff --git a/src/modern/ui/entry_controls.inc b/src/modern/ui/entry_controls.inc index 83736c3..31b4888 100644 --- a/src/modern/ui/entry_controls.inc +++ b/src/modern/ui/entry_controls.inc @@ -84,6 +84,8 @@ void App::entry_begin() { bind_world(entry_catalog_); start_options_ = {{"duration", 5}, {"difficulty", 3}, {"players", 1}, {"mode", 3}, {"league", true}, {"world", true}}; + if(source_ && world_ && entry_catalog_->manifest().at("id")==world_->manifest().at("id"))start_options_=snap().state.at("edits").at("setup"); + start_options_["mode"]=3; adding_manager_ = false; managers_draft_ = Json::array(); manager_index_ = 0; @@ -240,14 +242,15 @@ bool App::entry_action(const std::string &action, Rml::Element *target) { return true; } if (action == "setup-step") { + start_options_["mode"]=3; + if(id=="mode")return true; const auto step = target->GetAttribute("data-step", 0); const int limit = id == "duration" ? 5 : id == "difficulty" ? 10 : id == "players" ? (start_options_.value("league", true) ? 4 : 1) : 3; - if (id == "duration" || id == "difficulty" || id == "players" || - id == "mode") + if (id == "duration" || id == "difficulty" || id == "players") start_options_[id] = std::clamp(start_options_.value(id, 1) + step, 1, limit); const int current = start_options_.value(id, 1); @@ -291,6 +294,7 @@ bool App::entry_action(const std::string &action, Rml::Element *target) { } return true; } else if (action == "manager-clubs") { + if(career_national_entry()||entry_full())return true; selections_["manager-name"] = field("manager-name"); entry_picker_country_ = country_; entry_picker_league_ = league_; diff --git a/src/modern/ui/entry_opening_controls.inc b/src/modern/ui/entry_opening_controls.inc index 619f936..8578194 100644 --- a/src/modern/ui/entry_opening_controls.inc +++ b/src/modern/ui/entry_opening_controls.inc @@ -27,6 +27,7 @@ bool App::opening_pending() const { if (!source_) return false; const auto state = snap().state; + if(state.value("career",Json::object()).value("ended",false))return false; const auto &flow = state.at("opening_flow"); return flow.at("created").get() && flow.at("phase") != "done"; } @@ -70,6 +71,7 @@ void App::opening_restore_startup() { auto checkpoint = data.at("state"); checkpoint["desktop"] = data.at("desktop"); const auto layout = demo->load_data(std::move(checkpoint), false); + if(demo->snapshot().state.value("career",Json::object()).value("ended",false))return; const auto flow = demo->snapshot().state.at("opening_flow"); if (!flow.at("created").get() || flow.at("phase") == "done") return; @@ -211,6 +213,11 @@ void App::handle_event(SDL_Event &event) { opening_change("pause"); } resize(); + if(event.window.event==SDL_WINDOWEVENT_SIZE_CHANGED || event.window.event==SDL_WINDOWEVENT_RESIZED || event.window.event==SDL_WINDOWEVENT_DISPLAY_CHANGED){ + // resize() already uses the drawable size. The SDL2 Rml backend would + // replace it with logical event dimensions on SIZE_CHANGED. + dirty_=true;return; + } } int w, h, pw, ph; SDL_GetWindowSize(video_.window, &w, &h); diff --git a/src/modern/ui/entry_screens.inc b/src/modern/ui/entry_screens.inc index fc87699..970a6ab 100644 --- a/src/modern/ui/entry_screens.inc +++ b/src/modern/ui/entry_screens.inc @@ -7,16 +7,17 @@ // country_, league_, selected_club_, manager_index_, manager_picker_, // adding_manager_ remain the draft contract. std::string App::render_newgame() { - const std::array keys = {"duration", "difficulty", "players", - "mode"}; - const std::array names = {"Spieldauer", "Schwierigkeit", - "Mitspieler", "Modus"}; - const std::array limits = { - 5, 10, start_options_.value("league", true) ? 4 : 1, 3}; + start_options_["mode"] = 3; + const std::array keys = {"duration", "difficulty", + "players"}, + names = {"Spieldauer", "Schwierigkeit", + "Mitspieler"}; + const std::array limits = { + 5, 10, start_options_.value("league", true) ? 4 : 1}; std::string body = - "
" - "

Grundeinstellungen

Zuerst die Partie, dann die Manager.

" - "
"; + "

Grundeinstellungen

Deine " + "Karriere · alle Funktionen

"; for (size_t i = 0; i < keys.size(); ++i) { const std::string key = keys[i]; const int value = start_options_.value(key, 1); @@ -27,35 +28,48 @@ std::string App::render_newgame() { ""; caption = value == 5 ? "Unbegrenzt" : value == 1 ? "Saison" : "Saisons"; } else if (i == 1) { - const int columns = std::min(value, 5), rows = value > 5 ? 2 : 1; + const int columns = std::min(5, value); visual = "
"; - for (int n = 0; n < value; ++n) - visual += "
" + glyph("ball", 92) + "
"; + std::to_string(columns * 68 - 6) + "dp;\">"; + for (int j = 0; j < value; ++j) + visual += + "
" + + picture(renderer_.diagram( + "setup-ball", + "", + 128), + 62, 62) + + "
"; visual += "
"; caption = "Spielstärke " + std::to_string(value) + " von 10"; - } else if (i == 2) { + } else { visual = "
"; - for (int n = 0; n < value; ++n) - visual += glyph("person", 84); + for (int j = 0; j < value; ++j) + visual += picture( + renderer_.diagram( + "setup-person", + "", + 192), + 60, 112); visual += "
"; caption = std::to_string(value) + " Mitspieler"; - } else { - visual = "" + - std::string(value == 1 ? "I" - : value == 2 ? "II" - : "III") + - ""; - caption = value == 1 ? "Grundfunktionen" - : value == 2 ? "Erweiterte Funktionen" - : "Alle Funktionen"; } body += "

" + names[i] + "

"; body += btn("setup-step", "−", "entry-setup-minus", @@ -71,8 +85,8 @@ std::string App::render_newgame() { " erhöhen\" " + (value == limits[i] ? "disabled" : "")) + "
"; } - body += "
"; + body += + "
"; for (const auto *key : {"league", "world"}) { const bool league = std::string(key) == "league", active = start_options_.value(key, true), @@ -82,23 +96,28 @@ std::string App::render_newgame() { : !start_options_.value("league", true); body += btn( "setup-competition", - glyph(league ? "pitch" : "world", 70) + "" + - std::string(league ? "Ligaspiel" : "WM / EM") + "" + - (active ? "Aktiv" : "Aus") + "", - "entry-setup-competition " + std::string(active ? "selected" : ""), + img(league ? "career.club" : "career.international", 904, 1580, false, + false, 1600) + + "" + + std::string(league ? "Vereinsfußball" : "International · WM / EM") + + "" + (active ? "Aktiv" : "Auswählen") + + "" + + (active ? glyph("check", 38) : "○") + "", + std::string("entry-setup-competition ") + (active ? "selected" : ""), "id=\"setup-competition-" + std::string(key) + "\" data-id=\"" + key + "\" aria-pressed=\"" + (active ? "true" : "false") + "\" " + (locked ? "disabled" : "")); } - const std::string hint = - start_options_.value("players", 1) > 1 - ? "Bei mehreren Mitspielern bleibt das Ligaspiel aktiv." - : !start_options_.value("league", true) - ? "WM / EM allein ist mit einem Mitspieler möglich." - : "Mindestens ein Wettbewerb bleibt aktiv."; - body += "

" + hint + - "

Deine " - "Auswahl wird beim Spielstart übernommen.

" + + body += "

" + + std::string( + start_options_.value("players", 1) > 1 + ? "Bei mehreren Mitspielern bleibt der Vereinsfußball aktiv." + : !start_options_.value("league", true) + ? "Nationalmannschaft · ein Mitspieler · Deutschland" + : "Mindestens ein Wettbewerb bleibt aktiv.") + + "

Dauer, " + "Schwierigkeit und Mitspielerzahl gelten für deine neue " + "Partie.

" + btn("close", "Abbrechen") + btn("setup-next", "Weiter", "primary", "id=\"setup-next\"") + "
"; @@ -110,8 +129,10 @@ std::string App::render_manager() { if (!catalog) return window("Neuer Spieler", "

Bitte zuerst eine Modern-Mod aktivieren.

"); + const bool national = career_national_entry(); const bool full = entry_full(), modal = manager_confirm_ || manager_success_; - const int limit = adding_manager_ ? 4 : start_options_.value("players", 1); + const int limit = + adding_manager_ ? (national ? 1 : 4) : start_options_.value("players", 1); const int portrait = selections_["portrait"].empty() ? 0 : std::stoi(selections_["portrait"]); const std::string style = @@ -136,9 +157,13 @@ std::string App::render_manager() { ""; }; const auto club_name = [&](const Json *c) { - return c ? catalog->name(*c) : std::string("Kein spielbarer Verein"); + return national ? std::string("Deutschland") + : c ? catalog->name(*c) + : std::string("Kein spielbarer Verein"); }; const auto league_name = [&](const Json *c) { + if (national) + return std::string("Nationalmannschaft"); const auto *l = c ? catalog->find("competitions", c->value("competition", "")) : nullptr; @@ -166,7 +191,7 @@ std::string App::render_manager() { }; const auto *selected = catalog->find("clubs", selected_club_); std::string content; - if (manager_picker_) { + if (manager_picker_ && !national) { const auto query = settings_search_key(club_search_); std::vector clubs; for (const auto *c : catalog->clubs(league_)) @@ -230,7 +255,8 @@ std::string App::render_manager() { "
" + - (full ? std::string("Vier Mitspieler im Spiel") + (full ? std::string(national ? "Nationaltrainer im Spiel" + : "Vier Mitspieler im Spiel") : "Mitspieler " + std::to_string(manager_index_ + 1) + " von " + std::to_string(limit)) + "

Dein Name. Dein Verein. Dein Porträt.

" + @@ -238,7 +264,7 @@ std::string App::render_manager() { "id=\"manager-newgame\"") : "") + "
" + face(portrait, style, 174) + - "

Verein

" + + "

" + + std::string(national ? "Nationalmannschaft" : "Verein") + "

" + btn("manager-clubs", - "
" + crest(selected, 176) + + "
" + + (national + ? img("career.national-de", 176, 176, false, false, 512) + : crest(selected, 176)) + "
" + esc(club_name(selected)) + "" + esc(selected @@ -263,7 +293,8 @@ std::string App::render_manager() { "Verein wählen ›", "entry-manager-club-button", "id=\"manager-clubs\" aria-label=\"Verein wählen: " + - esc(club_name(selected)) + "\" " + (full ? "disabled" : "")) + + esc(club_name(selected)) + "\" " + + (full || national ? "disabled" : "")) + "

Startliga

" + choose("manager-country", countries, country_) + @@ -371,7 +402,8 @@ std::string App::render_manager() { "aria-modal=\"true\" aria-labelledby=\"entry-confirm-title\">

Sind alle Angaben richtig?

" + - crest(selected, 200) + + (national ? img("career.national-de", 200, 200, false, false, 512) + : crest(selected, 200)) + "
" + esc(selections_["manager-name"]) + "" + esc(club_name(selected)) + "" + diff --git a/src/modern/ui/environment_screens.inc b/src/modern/ui/environment_screens.inc index 04e796f..23d2b5b 100644 --- a/src/modern/ui/environment_screens.inc +++ b/src/modern/ui/environment_screens.inc @@ -56,7 +56,7 @@ std::string App::render_environment() { out += "
" + img("art.environment-ball-v1.png", 400, 400, false, false, 640) + "
"; const auto &managers = snapshot.state.at("managers"); - const auto managed = managers.is_array() && !managers.empty() ? managers[0].value("club", "") : ""; + const auto managed = managers.is_array() && !managers.empty() ? demo_career_manager(snapshot.state).value("club", "") : ""; const auto *club = snapshot.world->find("clubs", managed); out += "
name(*club) : "Vereinswappen nicht verfügbar") + "\">" + (club ? img(club->value("crest", ""), 162, 162, true) : "—") + "
"; diff --git a/src/modern/ui/files_screens.inc b/src/modern/ui/files_screens.inc index 6ddc59a..e562d7c 100644 --- a/src/modern/ui/files_screens.inc +++ b/src/modern/ui/files_screens.inc @@ -38,13 +38,13 @@ std::string App::files_details(bool layouts, bool save) { const auto data = fresh ? snap().state : files_entry_->data; const auto meta = DemoFiles::career_metadata(data); const auto &managers = meta.at("managers"); - const Json *own = managers.empty() ? nullptr : world_->find("clubs", managers.at(0).value("club", "")); - out = "
" + crest(own, 108) + "

" + std::string(fresh ? "Aktuelles Spiel" : "Gespeicherter Spielstand") + "

" + esc(fresh ? "Neuer Speicherstand" : files_entry_->name) + "

" + esc(own ? world_->name(*own) : "") + "
"; + const Json *own = managers.empty() ? nullptr : world_->find("clubs", meta.at("current_manager").value("club", "")); + out = "
" + (meta.at("role")=="national"?img("career.national-de",108,108,false,false,256):crest(own,108)) + "

" + std::string(fresh ? "Aktuelles Spiel" : "Gespeicherter Spielstand") + "

" + esc(fresh ? "Neuer Speicherstand" : files_entry_->name) + "

" + esc(meta.at("role")=="national"?"Deutschland":own ? world_->name(*own) : "") + "
"; if (fresh) out += input(); out += "
"; const auto iso_date = meta.at("date").get(); const auto display_date = iso_date.substr(8, 2) + "." + iso_date.substr(5, 2) + "." + iso_date.substr(0, 4); - const std::vector> cells = {{"Saison", meta.at("season")}, {"Spieltag", meta.at("matchday")}, {"Spieldatum", display_date}, {"Spieler", std::to_string(managers.size())}}; + const std::vector> cells = {{"Saison", meta.at("season")}, {"Spieltag", meta.at("matchday")}, {"Spieldatum", display_date}, {"Spieler", std::to_string(meta.at("human_count").get())}}; for (const auto &[label, value] : cells) out += ""; out += "

Mitspieler

"; for (const auto &manager : managers) { diff --git a/src/modern/ui/front_screens.inc b/src/modern/ui/front_screens.inc index 5601984..5888102 100644 --- a/src/modern/ui/front_screens.inc +++ b/src/modern/ui/front_screens.inc @@ -35,7 +35,7 @@ std::string App::main_menu() { {"exit", "Beenden"}}}; for (const auto &[key, title] : actions) { const bool network = std::string(key) == "network", - disabled = scene_ != "main" || network || + disabled = scene_ != "main" || !menu_.empty() || network || (std::string(key) == "new" && !available && !(front_external_override_ && world_)); out += btn(key, diff --git a/src/modern/ui/lineup_controls.inc b/src/modern/ui/lineup_controls.inc index 4601310..6395325 100644 --- a/src/modern/ui/lineup_controls.inc +++ b/src/modern/ui/lineup_controls.inc @@ -1,198 +1,429 @@ // SPDX-License-Identifier: GPL-3.0-only void App::cancel_lineup_drag(bool refresh_view) { - lineup_drag_=Json(); lineup_drag_world_.reset(); lineup_drag_revision_=0; - if (auto *ghost=element("lineup-ghost")) ghost->SetProperty("display","none"); - if (refresh_view) refresh(); + lineup_drag_ = Json(); + lineup_drag_world_.reset(); + lineup_drag_revision_ = 0; + if (auto *ghost = element("lineup-ghost")) + ghost->SetProperty("display", "none"); + if (refresh_view) + refresh(); } -bool App::lineup_action(const std::string &action,Rml::Element *target) { - if (!action.starts_with("lineup-") || menu_!="lineup") return false; - if (!source_ || !target || !popup_.empty() || amount_ || !report_detail_kind_.empty()) return true; - if (lineup_ignore_click_ && action=="lineup-player") {lineup_ignore_click_=false;return true;} - const auto id=target->GetAttribute("data-id",""); - const auto s=snap(); - if (!s.world || !valid_demo_lineup(s.state,*s.world,lineup_managed(s))) return true; - const auto &l=s.state.at("lineup"); - const auto parse_index=[&](int maximum)->int {return id.size()==1 && id[0]>='0' && id[0]<='0'+maximum ? id[0]-'0':-1;}; - const auto commit=[&](const Json &payload,const std::string &focus) { - const auto result=source_->apply({s.revision,"lineup",payload}); - if (!result.ok) {message("Die Aufstellung konnte nicht übernommen werden. Bitte die Ansicht erneut öffnen.");return false;} - focus_after_render_=focus; refresh(); return true; - }; - const auto player_focus=[&](const std::string &p) { - const int slot=lineup_slot(l,p); - return std::string(lineup_pitch_ && slot<11?"lineup-player-":"lineup-name-")+p; - }; - if (action=="lineup-player") { - if (lineup_slot(l,id)<0) return true; - if (lineup_selected_==id) lineup_selected_.clear(); - else if (!lineup_selected_.empty()) { - const auto selected=lineup_selected_; lineup_selected_.clear(); - const int destination=lineup_slot(l,selected); - const auto focus=std::string(lineup_pitch_ && destination<11?"lineup-player-":"lineup-name-")+id; - commit({{"kind","swap"},{"a",selected},{"b",id}},focus); return true; - } else lineup_selected_=id; - focus_after_render_=player_focus(id); refresh(); return true; - } - if (action=="lineup-data") {lineup_data_=1-lineup_data_;focus_after_render_="lineup-data";refresh();return true;} - if (action=="lineup-view") {cancel_lineup_drag(false);lineup_pitch_=!lineup_pitch_;lineup_reset_scroll_=true;focus_after_render_="lineup-view";refresh();return true;} - if (action=="lineup-side") { - if (id=="formations" || id=="orders" || id=="takers") {lineup_side_=id;focus_after_render_="lineup-side-"+id;refresh();} +bool App::lineup_action(const std::string &action, Rml::Element *target) { + if (!action.starts_with("lineup-") || menu_ != "lineup") + return false; + if (!source_ || !target || !popup_.empty() || amount_ || + !report_detail_kind_.empty()) + return true; + if (action == "lineup-surface") { + const auto surface = + target ? target->GetAttribute("data-id", "") : ""; + if (apply("career", {{"kind", "surface"}, {"value", surface}})) { + lineup_selected_.clear(); + focus_after_render_ = "lineup-surface-" + surface; + refresh(); + } + return true; + } + if (lineup_ignore_click_ && action == "lineup-player") { + lineup_ignore_click_ = false; + return true; + } + const auto id = target->GetAttribute("data-id", ""); + const auto s = snap(); + if (!s.world || !valid_demo_lineup(s.state, *s.world, lineup_managed(s))) + return true; + const auto &l = demo_lineup_visible(s.state); + const int field_count = demo_career_field_count(s.state); + const auto parse_index = [&](int maximum) -> int { + return id.size() == 1 && id[0] >= '0' && id[0] <= '0' + maximum + ? id[0] - '0' + : -1; + }; + const auto commit = [&](const Json &payload, const std::string &focus) { + const auto result = source_->apply({s.revision, "lineup", payload}); + if (!result.ok) { + message("Die Aufstellung konnte nicht übernommen werden. Bitte die " + "Ansicht erneut öffnen."); + return false; + } + focus_after_render_ = focus; + refresh(); + return true; + }; + const auto player_focus = [&](const std::string &p) { + const int slot = lineup_slot(l, p); + return std::string(lineup_pitch_ && slot < field_count ? "lineup-player-" + : "lineup-name-") + + p; + }; + if (action == "lineup-player") { + if (lineup_slot(l, id) < 0) + return true; + if (lineup_selected_ == id) + lineup_selected_.clear(); + else if (!lineup_selected_.empty()) { + const auto selected = lineup_selected_; + lineup_selected_.clear(); + const int destination = lineup_slot(l, selected); + const auto focus = std::string(lineup_pitch_ && destination < field_count + ? "lineup-player-" + : "lineup-name-") + + id; + commit({{"kind", "swap"}, {"a", selected}, {"b", id}}, focus); + return true; + } else + lineup_selected_ = id; + focus_after_render_ = player_focus(id); + refresh(); + return true; + } + if (action == "lineup-data") { + lineup_data_ = 1 - lineup_data_; + focus_after_render_ = "lineup-data"; + refresh(); + return true; + } + if (action == "lineup-view") { + cancel_lineup_drag(false); + lineup_pitch_ = !lineup_pitch_; + lineup_reset_scroll_ = true; + focus_after_render_ = "lineup-view"; + refresh(); + return true; + } + if (action == "lineup-side") { + if (id == "formations" || id == "orders" || id == "takers") { + lineup_side_ = id; + focus_after_render_ = "lineup-side-" + id; + refresh(); + } + return true; + } + if (action == "lineup-page") { + const int n = parse_index(1); + if (n >= 0) { + lineup_page_ = n; + focus_after_render_ = n ? "lineup-page-prev" : "lineup-page-next"; + refresh(); + } + return true; + } + if (action == "lineup-formation") { + const int n = parse_index(7); + if (n >= 0) { + lineup_selected_.clear(); + commit({{"kind", "formation"}, {"value", n}}, "lineup-formation-" + id); + } + return true; + } + if (action == "lineup-save") { + const int n = parse_index(3); + if (n >= 0) + commit({{"kind", "custom-save"}, {"index", n}}, "lineup-save-" + id); + return true; + } + if (action == "lineup-weight") { + const int n = parse_index(2); + if (n >= 0) + commit({{"kind", "weight"}, {"index", n}}, "lineup-weight-" + id); + return true; + } + if (action == "lineup-auto") { + commit({{"kind", "takers-auto"}}, "lineup-auto"); return true; } - if (action=="lineup-page") {const int n=parse_index(1);if(n>=0) {lineup_page_=n;focus_after_render_=n?"lineup-page-prev":"lineup-page-next";refresh();}return true;} - if (action=="lineup-formation") {const int n=parse_index(7);if(n>=0) {lineup_selected_.clear();commit({{"kind","formation"},{"value",n}},"lineup-formation-"+id);}return true;} - if (action=="lineup-save") {const int n=parse_index(3);if(n>=0)commit({{"kind","custom-save"},{"index",n}},"lineup-save-"+id);return true;} - if (action=="lineup-weight") {const int n=parse_index(2);if(n>=0)commit({{"kind","weight"},{"index",n}},"lineup-weight-"+id);return true;} - if (action=="lineup-auto") {commit({{"kind","takers-auto"}},"lineup-auto");return true;} return true; } bool App::lineup_event(Rml::Event &event) { - if (menu_!="lineup" || !source_ || !popup_.empty() || amount_ || !report_detail_kind_.empty()) return false; - const auto type=event.GetType(); - auto *target=event.GetTargetElement(); - const auto ancestor=[&](const std::string &attribute)->Rml::Element* { - for(auto *n=target;n && n!=doc_;n=n->GetParentNode()) if(n->HasAttribute(attribute))return n; + if (menu_ != "lineup" || !source_ || !popup_.empty() || amount_ || + !report_detail_kind_.empty()) + return false; + const auto type = event.GetType(); + auto *target = event.GetTargetElement(); + const auto ancestor = [&](const std::string &attribute) -> Rml::Element * { + for (auto *n = target; n && n != doc_; n = n->GetParentNode()) + if (n->HasAttribute(attribute)) + return n; return nullptr; }; - auto *player_node=ancestor("data-squad-player"); - auto *pitch=element("lineup-pitch"); - const auto s=snap(); - if (!s.world || !valid_demo_lineup(s.state,*s.world,lineup_managed(s))) {cancel_lineup_drag(false);return false;} - const auto &l=s.state.at("lineup"); - const auto stop=[&]() {event.StopImmediatePropagation();}; - const auto commit=[&](const Json &payload,uint64_t revision) { - const auto result=source_->apply({revision,"lineup",payload}); - if(!result.ok)message("Die Aufstellung hat sich geändert. Bitte den Spieler erneut auswählen."); + auto *player_node = ancestor("data-squad-player"); + auto *pitch = element("lineup-pitch"); + const auto s = snap(); + if (!s.world || !valid_demo_lineup(s.state, *s.world, lineup_managed(s))) { + cancel_lineup_drag(false); + return false; + } + const auto &l = demo_lineup_visible(s.state); + const int field_count = demo_career_field_count(s.state); + const auto stop = [&]() { event.StopImmediatePropagation(); }; + const auto commit = [&](const Json &payload, uint64_t revision) { + const auto result = source_->apply({revision, "lineup", payload}); + if (!result.ok) + message("Die Aufstellung hat sich geändert. Bitte den Spieler erneut " + "auswählen."); return result.ok; }; - const auto point=[&](float x,float y)->Json { - if(!pitch)return Json(); - const auto origin=pitch->GetAbsoluteOffset(Rml::BoxArea::Border), size=pitch->GetBox().GetSize(Rml::BoxArea::Border); - if(size.x<=0 || size.y<=0)return Json(); - return Json::array({std::clamp(int(std::round(((x-origin.x)/size.x*100-8)/84*18)),0,18),std::clamp(int(std::round(((y-origin.y)/size.y*100-10)/80*8)),0,8)}); + const auto point = [&](float x, float y) -> Json { + if (!pitch) + return Json(); + const auto origin = pitch->GetAbsoluteOffset(Rml::BoxArea::Border), + size = pitch->GetBox().GetSize(Rml::BoxArea::Border); + if (size.x <= 0 || size.y <= 0) + return Json(); + return Json::array( + {std::clamp( + int(std::round(((x - origin.x) / size.x * 100 - 8) / 84 * 18)), 0, + 18), + std::clamp( + int(std::round(((y - origin.y) / size.y * 100 - 10) / 80 * 8)), 0, + 8)}); }; - const auto in_pitch=[&](float x,float y) { - if(!pitch)return false; - const auto origin=pitch->GetAbsoluteOffset(Rml::BoxArea::Border), size=pitch->GetBox().GetSize(Rml::BoxArea::Border); - return x>=origin.x && y>=origin.y && x<=origin.x+size.x && y<=origin.y+size.y; + const auto in_pitch = [&](float x, float y) { + if (!pitch) + return false; + const auto origin = pitch->GetAbsoluteOffset(Rml::BoxArea::Border), + size = pitch->GetBox().GetSize(Rml::BoxArea::Border); + return x >= origin.x && y >= origin.y && x <= origin.x + size.x && + y <= origin.y + size.y; }; - const float mx=event.GetParameter("mouse_x",0),my=event.GetParameter("mouse_y",0); - if(type=="keydown") { - lineup_ignore_click_=false; - const auto key=Rml::Input::KeyIdentifier(event.GetParameter("key_identifier",0)); - if(key==Rml::Input::KI_ESCAPE) { - for(auto *n=target;n && n!=doc_;n=n->GetParentNode()) - if(auto *select=dynamic_cast(n);select && select->IsSelectBoxVisible())return false; - if(!lineup_drag_.is_null()) {cancel_lineup_drag(true);stop();return true;} - if(!lineup_selected_.empty()) {lineup_selected_.clear();refresh();stop();return true;} + const float mx = event.GetParameter("mouse_x", 0), + my = event.GetParameter("mouse_y", 0); + if (type == "keydown") { + lineup_ignore_click_ = false; + const auto key = + Rml::Input::KeyIdentifier(event.GetParameter("key_identifier", 0)); + if (key == Rml::Input::KI_ESCAPE) { + for (auto *n = target; n && n != doc_; n = n->GetParentNode()) + if (auto *select = dynamic_cast(n); + select && select->IsSelectBoxVisible()) + return false; + if (!lineup_drag_.is_null()) { + cancel_lineup_drag(true); + stop(); + return true; + } + if (!lineup_selected_.empty()) { + lineup_selected_.clear(); + refresh(); + stop(); + return true; + } return false; } - if(pitch && player_node && player_node->IsClassSet("lineup-player") && (key==Rml::Input::KI_LEFT || key==Rml::Input::KI_RIGHT || key==Rml::Input::KI_UP || key==Rml::Input::KI_DOWN)) { - const auto id=player_node->GetAttribute("data-squad-player",""); - const int slot=lineup_slot(l,id); - if(slot>=0 && slot<11) { - auto p=l.at("points")[size_t(slot)]; - p[0]=std::clamp(p[0].get()+(key==Rml::Input::KI_RIGHT?1:key==Rml::Input::KI_LEFT?-1:0),0,18); - p[1]=std::clamp(p[1].get()+(key==Rml::Input::KI_DOWN?1:key==Rml::Input::KI_UP?-1:0),0,8); - lineup_selected_=id;commit({{"kind","move"},{"player",id},{"point",p}},s.revision); - focus_after_render_="lineup-player-"+id;refresh();stop();return true; + if (pitch && player_node && player_node->IsClassSet("lineup-player") && + (key == Rml::Input::KI_LEFT || key == Rml::Input::KI_RIGHT || + key == Rml::Input::KI_UP || key == Rml::Input::KI_DOWN)) { + const auto id = + player_node->GetAttribute("data-squad-player", ""); + const int slot = lineup_slot(l, id); + if (slot >= 0 && slot < field_count) { + auto p = l.at("points")[size_t(slot)]; + p[0] = std::clamp(p[0].get() + (key == Rml::Input::KI_RIGHT ? 1 + : key == Rml::Input::KI_LEFT ? -1 + : 0), + 0, 18); + p[1] = std::clamp(p[1].get() + (key == Rml::Input::KI_DOWN ? 1 + : key == Rml::Input::KI_UP ? -1 + : 0), + 0, 8); + lineup_selected_ = id; + commit({{"kind", "move"}, {"player", id}, {"point", p}}, s.revision); + focus_after_render_ = "lineup-player-" + id; + refresh(); + stop(); + return true; } } } - if((type=="change" || type=="input") && target) { - if(auto *control=dynamic_cast(target)) { - if(target->HasAttribute("data-lineup-taker")) { - const auto index=target->GetAttribute("data-lineup-taker",""); - if(index.size()!=1 || index[0]<'0' || index[0]>'2')return true; - const auto value=control->GetValue(); const int i=index[0]-'0'; - if(l.at("takers")[size_t(i)]!=value) {commit({{"kind","taker"},{"index",i},{"player",value}},s.revision);focus_after_render_=target->GetId();refresh();} - stop();return true; - } - if(target->HasAttribute("data-lineup-order")) { - const auto index=target->GetAttribute("data-lineup-order",""); - const auto id=target->GetAttribute("data-player",""); - const auto text=control->GetValue(); - // RmlUI ranges format whole steps as "%f" (for example "22.000000"). - // Accept that complete representation without rounding fractional input. - const auto dot=text.find('.'); - const auto whole=text.substr(0,dot); - const bool whole_fraction=dot==std::string::npos || - (dot+1'3' || whole.empty() || whole.size()>2 || !whole_fraction || std::any_of(whole.begin(),whole.end(),[](char c){return c<'0'||c>'9';}))return true; - const int value=std::stoi(whole),i=index[0]-'0'; - if(value<2 || value>40 || lineup_slot(l,id)<0 || lineup_slot(l,id)>=11)return true; - if(l.at("orders").at(id)[size_t(i)]!=value && commit({{"kind","order"},{"player",id},{"index",i},{"value",value}},s.revision)) { - if(auto *output=element("lineup-order-value-"+index))output->SetInnerRML(std::to_string(value)); - if(auto *zone=element("lineup-zone")) { - const auto now=snap(); - zone->SetInnerRML(picture(renderer_.diagram("lineup-zone",lineup_zone(now.state.at("lineup"),id),lineup_pitch_raster_px),lineup_art_width_dp,lineup_art_height_dp)); - } - dirty_=true; + if ((type == "change" || type == "input") && target) { + if (auto *control = dynamic_cast(target)) { + if (target->HasAttribute("data-lineup-taker")) { + const auto index = + target->GetAttribute("data-lineup-taker", ""); + if (index.size() != 1 || index[0] < '0' || index[0] > '2') + return true; + const auto value = control->GetValue(); + const int i = index[0] - '0'; + if (l.at("takers")[size_t(i)] != value) { + commit({{"kind", "taker"}, {"index", i}, {"player", value}}, + s.revision); + focus_after_render_ = target->GetId(); + refresh(); } - stop();return true; + stop(); + return true; + } + if (target->HasAttribute("data-lineup-order")) { + const auto index = + target->GetAttribute("data-lineup-order", ""); + const auto id = target->GetAttribute("data-player", ""); + const auto text = control->GetValue(); + // RmlUI ranges format whole steps as "%f" (for example "22.000000"). + // Accept that complete representation without rounding fractional + // input. + const auto dot = text.find('.'); + const auto whole = text.substr(0, dot); + const bool whole_fraction = + dot == std::string::npos || + (dot + 1 < text.size() && + std::all_of(text.begin() + dot + 1, text.end(), + [](char c) { return c == '0'; })); + if (index.size() != 1 || index[0] < '0' || index[0] > '3' || + whole.empty() || whole.size() > 2 || !whole_fraction || + std::any_of(whole.begin(), whole.end(), + [](char c) { return c < '0' || c > '9'; })) + return true; + const int value = std::stoi(whole), i = index[0] - '0'; + if (value < 2 || value > 40 || lineup_slot(l, id) < 0 || + lineup_slot(l, id) >= field_count) + return true; + if (l.at("orders").at(id)[size_t(i)] != value && + commit({{"kind", "order"}, + {"player", id}, + {"index", i}, + {"value", value}}, + s.revision)) { + if (auto *output = element("lineup-order-value-" + index)) + output->SetInnerRML(std::to_string(value)); + if (auto *zone = element("lineup-zone")) { + const auto now = snap(); + zone->SetInnerRML( + picture(renderer_.diagram( + "lineup-zone", + lineup_zone(demo_lineup_visible(now.state), id), + lineup_pitch_raster_px), + lineup_art_width_dp, lineup_art_height_dp)); + } + dirty_ = true; + } + stop(); + return true; } } } - if(type=="mousedown" && event.GetParameter("button",0)==0) { - lineup_ignore_click_=false; - if(pitch && player_node) { - const auto id=player_node->GetAttribute("data-squad-player","");const int slot=lineup_slot(l,id); - if(slot>=0) {lineup_drag_={{"player",id},{"club",lineup_managed(s)},{"source_slot",slot},{"start_x",mx},{"start_y",my},{"ghost",point(mx,my)},{"moved",false}};lineup_drag_revision_=s.revision;lineup_drag_world_=s.world;} + if (type == "mousedown" && event.GetParameter("button", 0) == 0) { + lineup_ignore_click_ = false; + if (pitch && player_node) { + const auto id = + player_node->GetAttribute("data-squad-player", ""); + const int slot = lineup_slot(l, id); + if (slot >= 0) { + lineup_drag_ = {{"player", id}, {"club", lineup_managed(s)}, + {"source_slot", slot}, {"start_x", mx}, + {"start_y", my}, {"ghost", point(mx, my)}, + {"moved", false}}; + lineup_drag_revision_ = s.revision; + lineup_drag_world_ = s.world; + } } return false; } - if(type=="mousemove" && lineup_drag_.is_object()) { - if(!lineup_drag_.value("moved",false) && std::hypot(mx-lineup_drag_.at("start_x").get(),my-lineup_drag_.at("start_y").get())<5)return false; - lineup_drag_["moved"]=true; - const auto p=point(mx,my);lineup_drag_["ghost"]=p; - if(p.is_array())if(auto *ghost=element("lineup-ghost")) { - ghost->SetProperty("display","block"); - ghost->SetProperty("left",scalar((8+p[0].get()/18.0*84)*lineup_art_width_dp/100-lineup_player_anchor_x_dp)+"dp"); - ghost->SetProperty("top",scalar((10+p[1].get()/8.0*80)*lineup_art_height_dp/100-lineup_player_anchor_y_dp)+"dp"); - dirty_=true; - } - stop();return true; + if (type == "mousemove" && lineup_drag_.is_object()) { + if (!lineup_drag_.value("moved", false) && + std::hypot(mx - lineup_drag_.at("start_x").get(), + my - lineup_drag_.at("start_y").get()) < 5) + return false; + lineup_drag_["moved"] = true; + const auto p = point(mx, my); + lineup_drag_["ghost"] = p; + if (p.is_array()) + if (auto *ghost = element("lineup-ghost")) { + ghost->SetProperty("display", "block"); + ghost->SetProperty("left", scalar((8 + p[0].get() / 18.0 * 84) * + lineup_art_width_dp / 100 - + lineup_player_anchor_x_dp) + + "dp"); + ghost->SetProperty("top", scalar((10 + p[1].get() / 8.0 * 80) * + lineup_art_height_dp / 100 - + lineup_player_anchor_y_dp) + + "dp"); + dirty_ = true; + } + stop(); + return true; } - if(type=="mouseup" && lineup_drag_.is_object()) { - const auto drag=lineup_drag_; const auto revision=lineup_drag_revision_;const auto world=lineup_drag_world_; - const bool moved=drag.value("moved",false);cancel_lineup_drag(false); - if(!moved)return false; - lineup_ignore_click_=true; - const auto id=drag.at("player").get(); - if(s.world!=world || s.revision!=revision || lineup_managed(s)!=drag.at("club").get() || lineup_slot(l,id)!=drag.at("source_slot").get()) { - message("Die Aufstellung hat sich geändert. Bitte den Spieler erneut auswählen.");stop();return true; + if (type == "mouseup" && lineup_drag_.is_object()) { + const auto drag = lineup_drag_; + const auto revision = lineup_drag_revision_; + const auto world = lineup_drag_world_; + const bool moved = drag.value("moved", false); + cancel_lineup_drag(false); + if (!moved) + return false; + lineup_ignore_click_ = true; + const auto id = drag.at("player").get(); + if (s.world != world || s.revision != revision || + lineup_managed(s) != drag.at("club").get() || + lineup_slot(l, id) != drag.at("source_slot").get()) { + message("Die Aufstellung hat sich geändert. Bitte den Spieler erneut " + "auswählen."); + stop(); + return true; } // Resolve the physical drop target independently of the active mouse // element: Rml may continue dispatching mouseup to the drag origin. std::string drop; - for(auto *n=context_->GetElementAtPoint({mx,my});n && n!=doc_;n=n->GetParentNode()) { - if(n->HasAttribute("data-squad-player")) {drop=n->GetAttribute("data-squad-player","");break;} - } - const int drop_slot=lineup_slot(l,drop); - if(drop_slot>=0 && drop!=id) { - commit({{"kind","swap"},{"a",id},{"b",drop}},revision); - lineup_selected_.clear(); - focus_after_render_=std::string(drop_slot<11?"lineup-player-":"lineup-name-")+id; - } else if(drop_slot<0 && in_pitch(mx,my)) { - const int slot=lineup_slot(l,id); const auto p=point(mx,my); - if(slot<11) {lineup_selected_=id;commit({{"kind","move"},{"player",id},{"point",p}},revision);} - else { - const auto &points=l.at("points");const auto hit=std::find(points.begin(),points.end(),p);const int n=int(hit-points.begin()); - if(nGetElementAtPoint({mx, my}); n && n != doc_; + n = n->GetParentNode()) { + if (n->HasAttribute("data-squad-player")) { + drop = n->GetAttribute("data-squad-player", ""); + break; } - focus_after_render_="lineup-player-"+id; } - refresh();stop();return true; + const int drop_slot = lineup_slot(l, drop); + if (drop_slot >= 0 && drop != id) { + commit({{"kind", "swap"}, {"a", id}, {"b", drop}}, revision); + lineup_selected_.clear(); + focus_after_render_ = + std::string(drop_slot < field_count ? "lineup-player-" + : "lineup-name-") + + id; + } else if (drop_slot < 0 && in_pitch(mx, my)) { + const int slot = lineup_slot(l, id); + const auto p = point(mx, my); + if (slot < field_count) { + lineup_selected_ = id; + commit({{"kind", "move"}, {"player", id}, {"point", p}}, revision); + } else { + const auto &points = l.at("points"); + const auto hit = std::find(points.begin(), points.end(), p); + const int n = int(hit - points.begin()); + if (n < int(std::min(size_t(field_count), l.at("order").size()))) { + commit({{"kind", "swap"}, {"a", id}, {"b", l.at("order")[size_t(n)]}}, + revision); + lineup_selected_.clear(); + } else + lineup_selected_ = id; + } + focus_after_render_ = "lineup-player-" + id; + } + refresh(); + stop(); + return true; } - if(type=="click" && lineup_ignore_click_) {lineup_ignore_click_=false;stop();return true;} - if(type=="click" && pitch && !player_node && !lineup_selected_.empty()) { - bool inside=false;for(auto *n=target;n && n!=doc_;n=n->GetParentNode())if(n==pitch)inside=true; - if(inside) { - const int slot=lineup_slot(l,lineup_selected_); - if(slot>=0 && slot<11) {const auto id=lineup_selected_;commit({{"kind","move"},{"player",id},{"point",point(mx,my)}},s.revision);focus_after_render_="lineup-player-"+id;refresh();} - else message("Einen Ersatzspieler auf einen Spieler der Startelf ziehen oder beide nacheinander anklicken."); - stop();return true; + if (type == "click" && lineup_ignore_click_) { + lineup_ignore_click_ = false; + stop(); + return true; + } + if (type == "click" && pitch && !player_node && !lineup_selected_.empty()) { + bool inside = false; + for (auto *n = target; n && n != doc_; n = n->GetParentNode()) + if (n == pitch) + inside = true; + if (inside) { + const int slot = lineup_slot(l, lineup_selected_); + if (slot >= 0 && slot < field_count) { + const auto id = lineup_selected_; + commit({{"kind", "move"}, {"player", id}, {"point", point(mx, my)}}, + s.revision); + focus_after_render_ = "lineup-player-" + id; + refresh(); + } else + message("Einen Ersatzspieler auf einen Spieler der Startelf ziehen " + "oder beide nacheinander anklicken."); + stop(); + return true; } } return false; diff --git a/src/modern/ui/lineup_screens.inc b/src/modern/ui/lineup_screens.inc index 8a7586b..352e1c6 100644 --- a/src/modern/ui/lineup_screens.inc +++ b/src/modern/ui/lineup_screens.inc @@ -1,222 +1,550 @@ // SPDX-License-Identifier: GPL-3.0-only namespace { -// Shared with lineup_controls.inc: proportional outer pitch and its border-free art box. +// Shared with lineup_controls.inc: proportional outer pitch and its border-free +// art box. constexpr double lineup_roster_height_dp = 1216.0; constexpr double lineup_pitch_top_dp = 1256.0; constexpr double lineup_pitch_height_dp = 608.0; constexpr double lineup_pitch_width_dp = lineup_pitch_height_dp * 196.0 / 117.0; constexpr double lineup_pitch_border_dp = 2.0; -constexpr double lineup_art_width_dp = lineup_pitch_width_dp - 2.0 * lineup_pitch_border_dp; -constexpr double lineup_art_height_dp = lineup_pitch_height_dp - 2.0 * lineup_pitch_border_dp; +constexpr double lineup_art_width_dp = + lineup_pitch_width_dp - 2.0 * lineup_pitch_border_dp; +constexpr double lineup_art_height_dp = + lineup_pitch_height_dp - 2.0 * lineup_pitch_border_dp; constexpr double lineup_player_size_dp = 126.0 * lineup_pitch_width_dp / 1920.0; constexpr double lineup_player_anchor_x_dp = lineup_player_size_dp * 0.5; constexpr double lineup_player_anchor_y_dp = lineup_player_size_dp * 0.61; -constexpr double lineup_controls_width_dp = 2612.0 - lineup_pitch_width_dp - 40.0; -constexpr double lineup_formation_width_dp = (lineup_controls_width_dp - 18.0) / 2.0; +constexpr double lineup_controls_width_dp = + 2612.0 - lineup_pitch_width_dp - 40.0; +constexpr double lineup_formation_width_dp = + (lineup_controls_width_dp - 18.0) / 2.0; constexpr double lineup_tools_width_dp = lineup_controls_width_dp - 16.0; constexpr double lineup_order_width_dp = (lineup_tools_width_dp - 40.0) / 2.0; constexpr double lineup_taker_width_dp = (lineup_tools_width_dp - 36.0) / 3.0; constexpr int lineup_pitch_raster_px = 2048; -// Current demo follows the Classic German/Modern24-slot markers:11 start,6 bench. -// This is not a universal match rule; a future session adapter supplies its DTO status. -// See game/lineup.cpp DispatchLiveOverview and ui/lineup_tests.cpp fixture markers. +// Current demo follows the Classic German/Modern24-slot markers:11 start,6 +// bench. This is not a universal match rule; a future session adapter supplies +// its DTO status. See game/lineup.cpp DispatchLiveOverview and +// ui/lineup_tests.cpp fixture markers. constexpr size_t lineup_start_limit = 11; constexpr size_t lineup_bench_limit = 6; -std::string lineup_status(size_t slot) { - return slot < lineup_start_limit ? "Startelf" : - slot < lineup_start_limit + lineup_bench_limit ? "Ersatzbank" : "—"; +std::string lineup_status(size_t slot, bool indoor = false) { + if (indoor) + return slot < 6 ? "Hallen-Sechs" : slot < 11 ? "Wechselpaar" : "Reserve"; + return slot < lineup_start_limit ? "Startelf" + : slot < lineup_start_limit + lineup_bench_limit ? "Ersatzbank" + : "—"; } std::string lineup_managed(const Snapshot &s) { - const auto m = s.state.value("managers",Json::array()); - return m.is_array() && !m.empty() && m[0].is_object() ? m[0].value("club","") : ""; + return demo_career_manager(s.state).value("club", ""); } std::string lineup_position(const Json &v) { - if (!v.is_string()) return "—"; + if (!v.is_string()) + return "—"; const auto code = v.get(); - return code == "gk" ? "TW" : code == "def" ? "ABW" : code == "mid" ? "MIT" : code == "fwd" ? "STU" : code.empty() ? "—" : code; + return code == "gk" ? "TW" + : code == "def" ? "ABW" + : code == "mid" ? "MIT" + : code == "fwd" ? "STU" + : code.empty() ? "—" + : code; } std::string lineup_value(const Json &v) { - if (!v.is_number()) return "—"; - if (v.is_number_integer()) return number(v.get()); - if (!std::isfinite(v.get())) return "—"; - std::ostringstream out; out << std::setprecision(5) << v.get(); - auto text = out.str(); std::replace(text.begin(),text.end(),'.',','); return text; + if (!v.is_number()) + return "—"; + if (v.is_number_integer()) + return number(v.get()); + if (!std::isfinite(v.get())) + return "—"; + std::ostringstream out; + out << std::setprecision(5) << v.get(); + auto text = out.str(); + std::replace(text.begin(), text.end(), '.', ','); + return text; } int lineup_slot(const Json &l, const std::string &id) { - if (!l.is_object() || !l.contains("order") || !l.at("order").is_array()) return -1; - const auto &a = l.at("order"); const auto p = std::find(a.begin(),a.end(),id); - return p == a.end() ? -1 : int(p-a.begin()); + if (!l.is_object() || !l.contains("order") || !l.at("order").is_array()) + return -1; + const auto &a = l.at("order"); + const auto p = std::find(a.begin(), a.end(), id); + return p == a.end() ? -1 : int(p - a.begin()); } -std::string lineup_svg(const std::string &body, const std::string &box="0 0 120 72") { - return ""+body+""; +std::string lineup_svg(const std::string &body, + const std::string &box = "0 0 120 72") { + return "" + + body + ""; } -std::string lineup_mini(const Json &points, const std::string &theme) { +std::string lineup_mini(const Json &points, const std::string &theme, + size_t limit = 11) { const auto line = theme == "silver" ? "#536f66" : "#c3e8cb"; - std::string body = ""; - if (points.is_array()) for (const auto &p : points) { - const int depth=p[0].get(), lane=p[1].get(); - const auto color = theme == "silver" ? (depth<7?"#85600c":depth<13?"#a46914":"#b44931") : (depth<7?"#ffdc69":depth<13?"#ecac4b":"#f07852"); - body += ""; - } + std::string body = + ""; + if (points.is_array()) + for (size_t i = 0; i < std::min(limit, points.size()); ++i) { + const auto &p = points[i]; + const int depth = p[0].get(), lane = p[1].get(); + const auto color = theme == "silver" ? (depth < 7 ? "#85600c" + : depth < 13 ? "#a46914" + : "#b44931") + : (depth < 7 ? "#ffdc69" + : depth < 13 ? "#ecac4b" + : "#f07852"); + body += ""; + } return lineup_svg(body); } -std::string lineup_field() { +std::string lineup_field(bool indoor = false) { std::string body; - for (int x=0;x<196;x+=15) body += ""; - body += "" - "" - ""; - return lineup_svg(body,"0 0 196 117"); + for (int x = 0; x < 196; x += 15) + body += ""; + body += + "" + "" + ""; + return lineup_svg(body, "0 0 196 117"); } std::string lineup_zone(const Json &l, const std::string &id) { - const int row = lineup_slot(l,id); - if (row<0 || row>=11) return ""; - const auto &point = l.at("points")[size_t(row)], &orders = l.at("orders").at(id); - const double forward=orders[0].get(), width=orders[1].get(), coverage=orders[2].get(); - const double x=(8+point[0].get()/18.0*84)*1.96, y=(10+point[1].get()/8.0*80)*1.17; - double x0=x-(width/2+46-forward), x1=x+width/2+forward+8; - std::string body=""; - for (int n=0;n<=int(coverage/2);++n) { - if (n) { const int bend=(n==8?3:0)+(n==6?2:0)+(n==3?1:0); if (x0lo) for (const auto yy : {std::max(2.0,y-n-1),std::min(114.0,y+n+1)}) - body += ""; + const int row = lineup_slot(l, id); + if (row < 0 || row >= 11) + return ""; + const auto &point = l.at("points")[size_t(row)], + &orders = l.at("orders").at(id); + const double forward = orders[0].get(), width = orders[1].get(), + coverage = orders[2].get(); + const double x = (8 + point[0].get() / 18.0 * 84) * 1.96, + y = (10 + point[1].get() / 8.0 * 80) * 1.17; + double x0 = x - (width / 2 + 46 - forward), x1 = x + width / 2 + forward + 8; + std::string body = ""; + for (int n = 0; n <= int(coverage / 2); ++n) { + if (n) { + const int bend = (n == 8 ? 3 : 0) + (n == 6 ? 2 : 0) + (n == 3 ? 1 : 0); + if (x0 < x1 - (1 + bend) * 2 - 20) { + x0 += 1 + bend; + x1 -= 1 + bend; + } + } + const double lo = std::max(3.0, x0), hi = std::min(192.0, x1); + if (hi > lo) + for (const auto yy : + {std::max(2.0, y - n - 1), std::min(114.0, y + n + 1)}) + body += ""; } - return lineup_svg(body+"","0 0 196 117"); + return lineup_svg(body + "", "0 0 196 117"); } } // namespace std::string App::render_lineup() { - const auto s=snap(); - if (!s.world) return "

Die Aufstellung ist derzeit nicht verfügbar.

"; - const auto projection=demo_lineup_rows(s.state,*s.world,lineup_managed(s)); - if (!projection.value("ok",false)) return "

Die Aufstellung ist derzeit nicht verfügbar.

"; - const auto &l=s.state.at("lineup"), &rows=projection.at("rows"); - if (lineup_slot(l,lineup_selected_)<0) lineup_selected_.clear(); - lineup_data_=lineup_data_==1?1:0; lineup_page_=lineup_page_==1?1:0; - if (lineup_side_!="orders" && lineup_side_!="takers") lineup_side_="formations"; - const auto attr=[](const std::string &key,const std::string &value) {return " "+key+"=\""+esc(value)+"\"";}; - const auto player_attrs=[&](const Json &row,const std::string &prefix) { - const auto id=row.at("id").get(); - return attr("id",prefix+id)+attr("data-id",id)+attr("data-squad-player",id)+ - attr("data-slot",std::to_string(row.at("slot").get()))+attr("aria-pressed",lineup_selected_==id?"true":"false")+ - attr("aria-label",row.at("name").get()+", "+lineup_position(row.at("position"))); + const auto s = snap(); + if (!s.world) + return "

Die Aufstellung ist derzeit nicht " + "verfügbar.

"; + const auto projection = + demo_lineup_rows(s.state, *s.world, lineup_managed(s)); + if (!projection.value("ok", false)) + return "

Die Aufstellung ist derzeit nicht " + "verfügbar.

"; + const auto &l = demo_lineup_visible(s.state), &rows = projection.at("rows"); + const int field_count = demo_career_field_count(s.state); + const bool indoor = field_count == 6; + if (lineup_slot(l, lineup_selected_) < 0) + lineup_selected_.clear(); + lineup_data_ = lineup_data_ == 1 ? 1 : 0; + lineup_page_ = lineup_page_ == 1 ? 1 : 0; + if (lineup_side_ != "orders" && lineup_side_ != "takers") + lineup_side_ = "formations"; + const auto attr = [](const std::string &key, const std::string &value) { + return " " + key + "=\"" + esc(value) + "\""; }; - std::string out="
"; - const std::array,2> headings{{ - {{"Nr.","Name","Pos.","Ko","Te","Fo","Stärke","Status","Land","Mot.","Tore","Ass."}}, - {{"Nr.","Name","Alter","Eck.","Frei.","Zwei.","Pass","Schuss","Schn.","Team","Spiele","Note"}}}}; - for (int c=0;c<12;++c) out+=""+headings[size_t(lineup_data_)][size_t(c)]+""; - out+="
"; - for (const auto &row:rows) { - const auto slot=row.at("slot").get(); const auto id=row.at("id").get(); - out+="
"; - out+=""+(slot<11?std::to_string(slot+1):"–")+""; - out+=btn("lineup-player",esc(row.at("name").get()),"lineup-cell lineup-col-1 lineup-name",player_attrs(row,"lineup-name-")); + const auto player_attrs = [&](const Json &row, const std::string &prefix) { + const auto id = row.at("id").get(); + return attr("id", prefix + id) + attr("data-id", id) + + attr("data-squad-player", id) + + attr("data-slot", std::to_string(row.at("slot").get())) + + attr("aria-pressed", lineup_selected_ == id ? "true" : "false") + + attr("aria-label", row.at("name").get() + ", " + + lineup_position(row.at("position"))); + }; + std::string out = "
"; + const std::array, 2> headings{ + {{{"Nr.", "Name", "Pos.", "Ko", "Te", "Fo", "Stärke", "Status", "Land", + "Mot.", "Tore", "Ass."}}, + {{"Nr.", "Name", "Alter", "Eck.", "Frei.", "Zwei.", "Pass", "Schuss", + "Schn.", "Team", "Spiele", "Note"}}}}; + for (int c = 0; c < 12; ++c) + out += "" + headings[size_t(lineup_data_)][size_t(c)] + + ""; + out += + "
"; + for (const auto &row : rows) { + const auto slot = row.at("slot").get(); + const auto id = row.at("id").get(); + out += "
"; + out += "" + + (slot < field_count ? std::to_string(slot + 1) : "–") + + ""; + out += btn("lineup-player", esc(row.at("name").get()), + "lineup-cell lineup-col-1 lineup-name", + player_attrs(row, "lineup-name-")); std::vector fields; - if (!lineup_data_) fields={lineup_position(row.at("position")),lineup_value(row.at("condition")),lineup_value(row.at("technique")),lineup_value(row.at("form")),lineup_value(row.at("strength")),lineup_status(size_t(slot)),row.at("nation").is_string()?row.at("nation").get():"—",lineup_value(row.at("motivation")),lineup_value(row.at("goals")),lineup_value(row.at("assists"))}; - else for (const auto *key:{"age","corner","free_kick","tackling","passing","shooting","speed","teamplay","games","grade"}) fields.push_back(lineup_value(row.at(key))); - for (size_t f=0;f(); - if (code.starts_with("nation:")) code=code.substr(7); - if (code=="de") value=picture(renderer_.diagram("lineup-flag-de",lineup_svg("","0 0 40 24"),80),40,24); + if (!lineup_data_) + fields = {lineup_position(row.at("position")), + lineup_value(row.at("condition")), + lineup_value(row.at("technique")), + lineup_value(row.at("form")), + lineup_value(row.at("strength")), + lineup_status(size_t(slot), indoor), + row.at("nation").is_string() + ? row.at("nation").get() + : "—", + lineup_value(row.at("motivation")), + lineup_value(row.at("goals")), + lineup_value(row.at("assists"))}; + else + for (const auto *key : + {"age", "corner", "free_kick", "tackling", "passing", "shooting", + "speed", "teamplay", "games", "grade"}) + fields.push_back(lineup_value(row.at(key))); + for (size_t f = 0; f < fields.size(); ++f) { + std::string value = esc(fields[f]); + if (!lineup_data_ && f == 6 && row.at("nation").is_string()) { + auto code = row.at("nation").get(); + if (code.starts_with("nation:")) + code = code.substr(7); + if (code == "de") + value = picture( + renderer_.diagram( + "lineup-flag-de", + lineup_svg("", + "0 0 40 24"), + 80), + 40, 24); else { - const auto flag=ui_nation_flag_svg(code); - if (!flag.empty()) value=picture(renderer_.diagram("lineup-flag-"+code,flag,80),40,24); + const auto flag = ui_nation_flag_svg(code); + if (!flag.empty()) + value = picture(renderer_.diagram("lineup-flag-" + code, flag, 80), + 40, 24); else { // Legacy placeholders are identifiers, not useful country labels. - const bool country_code=code.size()==2 && std::all_of(code.begin(),code.end(),[](unsigned char c){return (c>='a'&&c<='z')||(c>='A'&&c<='Z');}); + const bool country_code = + code.size() == 2 && + std::all_of(code.begin(), code.end(), [](unsigned char c) { + return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); + }); if (country_code) { - std::transform(code.begin(),code.end(),code.begin(),[](unsigned char c){return char(std::toupper(c));}); - value=esc(code); - } else value="—"; + std::transform( + code.begin(), code.end(), code.begin(), + [](unsigned char c) { return char(std::toupper(c)); }); + value = esc(code); + } else + value = "—"; } } } - if (!lineup_data_ && f==5) value=""+value+""; - out+=btn("player-detail",value,"lineup-cell lineup-col-"+std::to_string(f+2)+" lineup-detail", - attr("id","lineup-detail-"+id+"-"+std::to_string(f))+attr("data-id",id)+attr("aria-label",row.at("name").get()+", Spielerinformationen")); + if (!lineup_data_ && f == 5) + value = "" + value + ""; + out += btn("player-detail", value, + "lineup-cell lineup-col-" + std::to_string(f + 2) + + " lineup-detail", + attr("id", "lineup-detail-" + id + "-" + std::to_string(f)) + + attr("data-id", id) + + attr("aria-label", row.at("name").get() + + ", Spielerinformationen")); } - out+="
"; + out += "
"; } - if (rows.empty()) out+="

Für diesen Verein sind keine Spieler überliefert.

"; - out+="
"; - const auto data_btn=[&]() {return btn("lineup-data",lineup_data_?"Daten A":"Daten B","lineup-tab","id=\"lineup-data\"");}; - const auto view_btn=[&]() {return btn("lineup-view",lineup_pitch_?"Team":"Spielfeld","lineup-tab","id=\"lineup-view\"");}; + if (rows.empty()) + out += "

Für diesen Verein sind keine Spieler " + "überliefert.

"; + out += "
"; + const auto data_btn = [&]() { + return btn("lineup-data", lineup_data_ ? "Daten A" : "Daten B", + "lineup-tab", "id=\"lineup-data\""); + }; + const auto view_btn = [&]() { + return btn("lineup-view", lineup_pitch_ ? "Team" : "Spielfeld", + "lineup-tab", "id=\"lineup-view\""); + }; + out += + ""; if (lineup_pitch_) { - out+="
"+picture(renderer_.diagram("lineup-field",lineup_field(),lineup_pitch_raster_px),lineup_art_width_dp,lineup_art_height_dp)+"
"; - if (lineup_side_=="orders" && !lineup_selected_.empty()) { - const auto zone=lineup_zone(l,lineup_selected_); - if (!zone.empty()) out+="
"+picture(renderer_.diagram("lineup-zone",zone,lineup_pitch_raster_px),lineup_art_width_dp,lineup_art_height_dp)+"
"; + out += "
" + + picture(renderer_.diagram("lineup-field", lineup_field(indoor), + lineup_pitch_raster_px), + lineup_art_width_dp, lineup_art_height_dp) + + "
"; + if (lineup_side_ == "orders" && !lineup_selected_.empty()) { + const auto zone = lineup_zone(l, lineup_selected_); + if (!zone.empty()) + out += "
" + + picture(renderer_.diagram("lineup-zone", zone, + lineup_pitch_raster_px), + lineup_art_width_dp, lineup_art_height_dp) + + "
"; } - for (size_t i=0;i(); - const auto x=(8+point[0].get()/18.0*84)*lineup_art_width_dp/100.0-lineup_player_anchor_x_dp; - const auto y=(10+point[1].get()/8.0*80)*lineup_art_height_dp/100.0-lineup_player_anchor_y_dp; - out+=btn("lineup-player",img(selected?"lineup.player.selected":"lineup.player.normal",lineup_player_size_dp,lineup_player_size_dp)+""+std::to_string(i+1)+"","lineup-player",player_attrs(row,"lineup-player-")+attr("style",rect(x,y,lineup_player_size_dp,lineup_player_size_dp))); + for (size_t i = 0; i < std::min(size_t(field_count), rows.size()); ++i) { + const auto &row = rows[i], &point = l.at("points")[i]; + const bool selected = lineup_selected_ == row.at("id").get(); + const auto x = + (8 + point[0].get() / 18.0 * 84) * lineup_art_width_dp / 100.0 - + lineup_player_anchor_x_dp; + const auto y = + (10 + point[1].get() / 8.0 * 80) * lineup_art_height_dp / 100.0 - + lineup_player_anchor_y_dp; + out += + btn("lineup-player", + img(selected ? "lineup.player.selected" : "lineup.player.normal", + lineup_player_size_dp, lineup_player_size_dp) + + "" + std::to_string(i + 1) + + "", + "lineup-player", + player_attrs(row, "lineup-player-") + + attr("style", rect(x, y, lineup_player_size_dp, + lineup_player_size_dp))); } - out+="
"+img("lineup.player.ghost",lineup_player_size_dp,lineup_player_size_dp)+"
"; + out += "
"; } else { - out+="
"+data_btn()+view_btn()+""+std::to_string(std::min(size_t(11),rows.size()))+" Spieler auf dem Feld · "+std::to_string(std::min(lineup_bench_limit,rows.size()>lineup_start_limit?rows.size()-lineup_start_limit:0))+" Ersatzbank · "+std::to_string(rows.size()>lineup_start_limit+lineup_bench_limit?rows.size()-lineup_start_limit-lineup_bench_limit:0)+" weitere Spieler
"; + const auto bench = std::min(indoor ? size_t(5) : lineup_bench_limit, + rows.size() > size_t(field_count) + ? rows.size() - size_t(field_count) + : 0); + const auto reserves = rows.size() > size_t(field_count) + bench + ? rows.size() - size_t(field_count) - bench + : 0; + out += "
" + data_btn() + view_btn() + + "" + + std::to_string(std::min(size_t(field_count), rows.size())) + + " Spieler auf dem Feld · " + std::to_string(bench) + + (indoor ? " Wechselspieler · " : " Ersatzbank · ") + + std::to_string(reserves) + " Reserve
"; } - out+="
"; - return out+render_report_detail(); + out += "
"; + return out + render_report_detail(); } diff --git a/src/modern/ui/model.cpp b/src/modern/ui/model.cpp index 83eb5e0..ce38d0e 100644 --- a/src/modern/ui/model.cpp +++ b/src/modern/ui/model.cpp @@ -244,6 +244,7 @@ Json DemoSource::read_statistics(const Json &request) const { ActionResult DemoSource::apply(const Action &action) { if (action.revision != revision_) return {false, revision_, "stale_revision"}; + if(state_.value("career",Json::object()).value("ended",false)&&action.kind!="start")return {false,revision_,"career_ended"}; auto next = state_; try { if (action.kind == "career") { diff --git a/src/modern/ui/reports_screens.inc b/src/modern/ui/reports_screens.inc index be7c8b7..ef5d5bf 100644 --- a/src/modern/ui/reports_screens.inc +++ b/src/modern/ui/reports_screens.inc @@ -27,7 +27,7 @@ std::string App::report_club_button(const std::string &id, bool name_first) { "\">" + name + ""; return btn("club-detail", name_first ? text + crest(c, 42) : crest(c, 42) + text, std::string("report-club-button ") + (name_first ? "name-first " : "") + - (manager(snap()).value("club", "") == id ? "current" : ""), + (snap().state.at("career").value("role","club")=="club"&&manager(snap()).value("club", "") == id ? "current" : ""), "id=\"report-club-" + esc(id) + "\" data-id=\"" + esc(id) + "\""); } diff --git a/src/modern/ui/screens.inc b/src/modern/ui/screens.inc index 8df67b7..8fd13bc 100644 --- a/src/modern/ui/screens.inc +++ b/src/modern/ui/screens.inc @@ -16,22 +16,23 @@ void App::init_desktop() { std::string App::render_desktop() { init_desktop(); const auto s = snap(); - widget_data_ = demo_desktop_widgets(*world_, s.state); + widget_data_=demo_desktop_widgets(*world_,s.state); + const bool national=s.state.at("career").value("role", "club")=="national"; const auto *c = club(s); std::string out = "
" + btn("desktop-context", - crest(c, 82) + "" + esc(c ? world_->name(*c) : "") + + (national?img("career.national-de",82,82,false,false,256):crest(c,82)) + "" + esc(national?"Deutschland":c ? world_->name(*c) : "") + "" + esc(manager(s).value("name", "")) + "", "identity", "id=\"desktop-identity\"") + "
" + std::string(widget_data_.at("matchday")==0?"Saisonvorbereitung":std::to_string(widget_data_.at("matchday").get())+". Spieltag") + "" + esc(widget_data_.at("season").get()) + - "
Guthaben" + - cash(s.state.value("cash", int64_t(0))) + "
"; + "
"+std::string(national?"Aufgabenbereich":"Guthaben")+"" + + (national?std::string("Nationalmannschaft"):cash(s.state.value("cash", int64_t(0)))) + "
"; if(desktop_.value("grid",true))for(int row=0;row<7;++row)for(int col=0;col<15;++col)out+=""; for (const auto &[id, o] : desktop_["objects"].items()) { - if (!o.value("visible", false)) + if (!o.value("visible", false) || (o.value("widget",false)?!demo_career_widget_available(s.state,id):!demo_career_menu_available(s.state,id.substr(4)))) continue; const auto style = rect(o.value("x", 0), o.value("y", 0), o.value("w", 224), o.value("h", 224)) + "z-index:" + std::to_string(o.value("z", 1)) + ";"; @@ -65,7 +66,7 @@ std::string App::render_desktop() { "style=\"decorator:linear-gradient(140deg," + top + "," + bottom + ");\">" + img("button." + route, 146, 146, false, false, 256) + - "
" + esc(route=="transfer"?"Transfer":title(route)) + "" + + "
" + esc(route=="newplayer"?"Manager":route=="transfer"?"Transfer":title(route)) + "" + (o.value("pinned", true) ? "
" : "") + ""; } diff --git a/src/modern/ui/stadium_screens.inc b/src/modern/ui/stadium_screens.inc index 3ce4233..348a2e8 100644 --- a/src/modern/ui/stadium_screens.inc +++ b/src/modern/ui/stadium_screens.inc @@ -16,7 +16,7 @@ void stadium_view_defaults(Json &v) { } std::string stadium_managed(const Snapshot &s) { const auto &m=stadium_field(s.state,"managers"); - return m.is_array()&&!m.empty()&&stadium_field(m[0],"club").is_string()?m[0].at("club").get():""; + return m.is_array()&&!m.empty()&&stadium_field(m[0],"club").is_string()?demo_career_manager(s.state).value("club",""):""; } std::string stadium_money(const Json &value,const Catalog &world) { return value.is_number_integer()?money(value.get(),world.manifest().value("currency",Json::object())):"—"; diff --git a/src/modern/ui/transfer_screens.inc b/src/modern/ui/transfer_screens.inc index 60fb96a..dc51815 100644 --- a/src/modern/ui/transfer_screens.inc +++ b/src/modern/ui/transfer_screens.inc @@ -35,7 +35,7 @@ std::string transfer_ui_role(const Json &v) { : "—"; } std::string transfer_ui_club(const Snapshot &s) { - return s.state.at("managers")[0].at("club").get(); + return demo_career_manager(s.state).value("club", ""); } Json transfer_ui_find(const Json &rows, const std::string &id) { if (rows.is_array()) diff --git a/src/modern/ui/view.cpp b/src/modern/ui/view.cpp index bf35007..892c15a 100644 --- a/src/modern/ui/view.cpp +++ b/src/modern/ui/view.cpp @@ -15,6 +15,7 @@ #include "modern/ui/demo_opening.hpp" #include "modern/ui/demo_sports.hpp" #include "modern/ui/demo_lineup.hpp" +#include "modern/ui/demo_career.hpp" #include "modern/ui/demo_transfer.hpp" #include "modern/ui/demo_career_reports.hpp" #include "modern/ui/demo_rankings.hpp" @@ -458,7 +459,7 @@ class App final : public Rml::EventListener { } Snapshot snap() const { return source_->snapshot(); } const Json &manager(const Snapshot &s) const { - return s.state.at("managers").at(0); + return demo_career_manager(s.state); } const Json *club(const Snapshot &s) const { return s.world->find("clubs", manager(s).value("club", "")); @@ -761,7 +762,7 @@ class App final : public Rml::EventListener { bool entry_name_valid() const; bool entry_used_club(const std::string &) const; bool entry_used_portrait(int) const; - bool entry_full() const { return adding_manager_ && managers_draft_.size() >= 4; } + bool entry_full() const { return adding_manager_ && managers_draft_.size() >= size_t(career_national_entry()?1:4); } void entry_begin(); void entry_add(); void entry_cancel(); @@ -773,6 +774,14 @@ class App final : public Rml::EventListener { bool entry_input(Rml::Element *); bool entry_event(Rml::Event &); Json entry_snapshot() const; + bool career_resign_open_=false,career_game_end_=false; + int career_resign_portrait_=0; + uint64_t career_resign_revision_=0; + const DataSource *career_resign_source_=nullptr; + bool career_national_entry() const {return adding_manager_?source_&&!snap().state.at("edits").at("setup").value("league",true):!start_options_.value("league",true);} + std::string render_career(); + bool career_action(const std::string &,Rml::Element *); + bool career_event(Rml::Event &); std::string render_newgame(); std::string render_manager(); std::string render_opening(); @@ -856,6 +865,7 @@ class App final : public Rml::EventListener { } void render() { if (select_menu_) select_menu_->before_render(); + if (source_ && scene_=="desktop" && snap().state.value("career",Json::object()).value("ended",false)){scene_="main";menu_.clear();} if (scene_ == "desktop" && !files_capturing_ && opening_pending()) { scene_ = "opening"; menu_.clear(); @@ -919,11 +929,13 @@ class App final : public Rml::EventListener { else if (scene_ == "mods") markup = mods_page(); else if (scene_ == "newgame") - markup = render_newgame(); + markup = main_menu()+"
"+render_newgame()+"
"; else if (scene_ == "manager") - markup = render_manager(); + markup = (adding_manager_?render_desktop():main_menu())+"
"+render_manager()+"
"; + else if (scene_ == "managerhub") + markup = render_desktop()+"
"+render_career()+"
"; else if (scene_ == "opening") - markup = render_opening(); + markup = main_menu()+"
"+render_opening()+"
"; else if (source_) markup = render_desktop(); if (!menu_.empty()) @@ -937,6 +949,10 @@ class App final : public Rml::EventListener { doc_->QuerySelectorAll(behind, "#entry-manager-underlay button,#entry-manager-underlay input,#entry-manager-underlay select,.window>.titlebar button"); for (auto *node : behind) node->SetProperty("pointer-events", "none"); } + if(scene_=="managerhub" || (scene_=="manager"&&adding_manager_)){ + Rml::ElementList background;doc_->QuerySelectorAll(background,".desktop-layer button,.desktop-layer [data-action]"); + for(auto *node:background){node->SetProperty("pointer-events","none");node->SetAttribute("tabindex",-1);} + } news_after_render(); if (!report_detail_kind_.empty() || !planning_dialog_.empty() || !contracts_dialog_.empty() || !toto_dialog_.empty() || !transfer_dialog_.empty() || !career_view_.value("dialog", "").empty() || !stadium_view_.value("dialog", "").empty()) { Rml::ElementList behind; @@ -1303,7 +1319,7 @@ public: active_mod_.clear(); load_world(config_.world); scene_ = config_.scene; - if (scene_ != "main" && scene_ != "mods" && scene_ != "newgame" && scene_ != "manager" && + if (scene_ != "main" && scene_ != "mods" && scene_ != "newgame" && scene_ != "manager" && scene_ != "managerhub" && scene_ != "opening" && scene_ != "desktop") { menu_ = scene_; scene_ = "desktop"; @@ -1386,6 +1402,8 @@ public: } }; #include "modern/ui/entry_controls.inc" +#include "modern/ui/career_screens.inc" +#include "modern/ui/career_controls.inc" #include "modern/ui/entry_screens.inc" #include "modern/ui/entry_opening_controls.inc" #include "modern/ui/entry_opening_screens.inc" diff --git a/src/modern/ui/widgets_screens.inc b/src/modern/ui/widgets_screens.inc index ab0bf0a..7a34807 100644 --- a/src/modern/ui/widgets_screens.inc +++ b/src/modern/ui/widgets_screens.inc @@ -75,6 +75,10 @@ std::string App::widget(const std::string &id, const Json &o) { const auto heading = [&](const std::string &name, bool link = true) { return widget_heading(name, link); }; + if(s.state.at("career").value("role","club")=="national"){ + if(id=="crest"||id=="opponent-crest")return "
"+img(id=="crest"?"career.national-de":"career.national-fr",std::min(w-48,h-138),std::min(w-48,h-138),false,false,768)+"
"+(id=="crest"?std::string("Dein Nationalteam"):"Nächster Gegner")+""+(id=="crest"?std::string("Deutschland"):"Frankreich")+"
"; + if(id=="competition")return heading("Nächste Begegnung")+"
"+img("career.national-de",80,80,false,false,256)+"Deutschland
Fiktives Länderspiel19:00Heim · Samstag
"+img("career.national-fr",80,80,false,false,256)+"Frankreich
"; + } if (id == "calendar") return "
" + esc(widget_data_.at("month").get()) + diff --git a/tests/modern_career_ui_tests.cpp b/tests/modern_career_ui_tests.cpp index 738ba86..01c2a3b 100644 --- a/tests/modern_career_ui_tests.cpp +++ b/tests/modern_career_ui_tests.cpp @@ -1,7 +1,13 @@ // SPDX-License-Identifier: GPL-3.0-only #include "modern/ui/demo_career.hpp" +#include "modern/ui/demo_career_reports.hpp" +#include "modern/ui/demo_files.hpp" +#include "modern/ui/demo_finance.hpp" #include "modern/ui/demo_lineup.hpp" #include "modern/ui/demo_opening.hpp" +#include "modern/ui/demo_stadium.hpp" +#include "modern/ui/demo_statistics.hpp" +#include "modern/ui/demo_widgets.hpp" #include "modern/ui/desktop.hpp" #include "modern/ui/model.hpp" #include @@ -110,6 +116,27 @@ int main() { "manager select"); require(demo_career_manager(source.snapshot().state).at("portrait") == 2, "requested active identity"); + const auto selected_state = source.snapshot().state; + const auto selected_club = + demo_career_manager(selected_state).value("club", ""); + require(demo_desktop_widgets(*f.world, selected_state).at("own") == + selected_club, + "widget projection follows active manager"); + require(demo_contract_rows(selected_state, *f.world).at("ok") == true, + "contracts query accepts active club snapshot"); + require(demo_stadium_view(selected_state, *f.world).at("club") == + selected_club, + "stadium query follows active manager"); + require(demo_statistics(*f.world, selected_state).at("club") == + selected_club, + "statistics own club follows active manager"); + require(demo_highscores(*f.world, selected_state).at("manager") == + demo_career_manager(selected_state).at("name"), + "highscore identity follows active manager"); + require(DemoFiles::career_metadata(selected_state) + .at("current_manager") + .at("portrait") == 2, + "save metadata follows selected snapshot manager"); auto context = demo_career_context(source.snapshot().state, *f.world); require(context.at("active_managers").size() == 4, "four active humans"); require(act({{"kind", "role"}, {"value", "national"}}).ok, "national role");