From a45217c3628527085823f807307739a12b1ba156 Mon Sep 17 00:00:00 2001 From: Codex Date: Sun, 25 Oct 2026 20:10:57 +0100 Subject: [PATCH] Port statistics and the news tablet to the Modern UI (by Codex) --- .github/workflows/modern-ui.yml | 4 +- assets/modern/icons/undo.svg | 2 + assets/modern/modern.rml | 2 +- assets/modern/news.rcss | 90 ++++++ assets/modern/statistics.rcss | 109 +++++++ docs/new_ui/NATIVE_STATUS.md | 19 +- docs/new_ui/README.md | 2 + docs/new_ui/desktop/news/README.md | 74 +++++ docs/new_ui/desktop/statistics/README.md | 68 +++++ docs/new_ui/menu-qa.md | 33 ++ docs/new_ui/qa-findings.md | 13 +- src/modern/ui/CMakeLists.txt | 15 +- src/modern/ui/controls.inc | 11 +- src/modern/ui/demo_news.cpp | 366 +++++++++++++++++++++++ src/modern/ui/demo_news.hpp | 23 ++ src/modern/ui/demo_statistics.cpp | 242 +++++++++++++++ src/modern/ui/demo_statistics.hpp | 13 + src/modern/ui/model.cpp | 15 +- src/modern/ui/model.hpp | 4 + src/modern/ui/news_controls.inc | 301 +++++++++++++++++++ src/modern/ui/news_screens.inc | 236 +++++++++++++++ src/modern/ui/news_state.inc | 22 ++ src/modern/ui/report_pickers.inc | 19 +- src/modern/ui/screens.inc | 11 +- src/modern/ui/statistics_controls.inc | 79 +++++ src/modern/ui/statistics_screens.inc | 186 ++++++++++++ src/modern/ui/statistics_state.inc | 15 + src/modern/ui/view.cpp | 51 +++- tests/modern_control_layout_tests.cpp | 38 ++- tests/modern_news_ui_tests.cpp | 304 +++++++++++++++++++ tests/modern_statistics_ui_tests.cpp | 140 +++++++++ tools/modern_ui/prepare_gui_assets.py | 9 + 32 files changed, 2493 insertions(+), 23 deletions(-) create mode 100644 assets/modern/icons/undo.svg create mode 100644 assets/modern/news.rcss create mode 100644 assets/modern/statistics.rcss create mode 100644 docs/new_ui/desktop/news/README.md create mode 100644 docs/new_ui/desktop/statistics/README.md create mode 100644 src/modern/ui/demo_news.cpp create mode 100644 src/modern/ui/demo_news.hpp create mode 100644 src/modern/ui/demo_statistics.cpp create mode 100644 src/modern/ui/demo_statistics.hpp create mode 100644 src/modern/ui/news_controls.inc create mode 100644 src/modern/ui/news_screens.inc create mode 100644 src/modern/ui/news_state.inc create mode 100644 src/modern/ui/statistics_controls.inc create mode 100644 src/modern/ui/statistics_screens.inc create mode 100644 src/modern/ui/statistics_state.inc create mode 100644 tests/modern_news_ui_tests.cpp create mode 100644 tests/modern_statistics_ui_tests.cpp diff --git a/.github/workflows/modern-ui.yml b/.github/workflows/modern-ui.yml index f2c31b9..8155c8b 100644 --- a/.github/workflows/modern-ui.yml +++ b/.github/workflows/modern-ui.yml @@ -52,9 +52,9 @@ jobs: - name: Configure opt-in UI without external assets run: cmake -S . -B build-ui -G Ninja -DCMAKE_BUILD_TYPE=Release -DOPENBMH_BUILD_MODERN_UI=ON -DOPENBMH_BUILD_EDITOR=OFF -DBMH_DATA= - name: Compile native frontend and synthetic checks - run: cmake --build build-ui --target openbmh_play modern_ui_core_tests modern_ticket_document_tests modern_control_layout_tests modern_reports_tests modern_planning_tests modern_almanac_ui_tests modern_finance_ui_tests modern_environment_ui_tests modern_advertising_ui_tests modern_toto_ui_tests modern_lineup_ui_tests modern_transfer_ui_tests modern_career_reports_tests modern_rankings_tests modern_stadium_ui_tests --parallel 2 + run: cmake --build build-ui --target openbmh_play modern_ui_core_tests modern_ticket_document_tests modern_control_layout_tests modern_reports_tests modern_planning_tests modern_almanac_ui_tests modern_finance_ui_tests modern_environment_ui_tests modern_advertising_ui_tests modern_toto_ui_tests modern_lineup_ui_tests modern_transfer_ui_tests modern_career_reports_tests modern_rankings_tests modern_stadium_ui_tests modern_statistics_ui_tests modern_news_ui_tests --parallel 2 - name: Check controls, fonts, density and draft cancellation - run: ctest --test-dir build-ui -R "^modern_(ui_|ticket_|control_|reports_|planning_|almanac_ui_|finance_ui_|environment_ui_|advertising_ui_|toto_ui_|lineup_ui_|transfer_ui_|career_reports_|rankings_|stadium_ui_)" --output-on-failure --output-junit modern-ui-results.xml + run: ctest --test-dir build-ui -R "^modern_(ui_|ticket_|control_|reports_|planning_|almanac_ui_|finance_ui_|environment_ui_|advertising_ui_|toto_ui_|lineup_ui_|transfer_ui_|career_reports_|rankings_|stadium_ui_|statistics_ui_|news_ui_)" --output-on-failure --output-junit modern-ui-results.xml - name: Upload test report if: always() uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 diff --git a/assets/modern/icons/undo.svg b/assets/modern/icons/undo.svg new file mode 100644 index 0000000..8f2ece7 --- /dev/null +++ b/assets/modern/icons/undo.svg @@ -0,0 +1,2 @@ + + diff --git a/assets/modern/modern.rml b/assets/modern/modern.rml index f31bd18..e0b91d5 100644 --- a/assets/modern/modern.rml +++ b/assets/modern/modern.rml @@ -1,6 +1,6 @@ OpenBMH - +
diff --git a/assets/modern/news.rcss b/assets/modern/news.rcss new file mode 100644 index 0000000..a30f4a4 --- /dev/null +++ b/assets/modern/news.rcss @@ -0,0 +1,90 @@ +/* SPDX-License-Identifier: GPL-3.0-only */ +.window.news-tablet {border:16dp #101821;border-radius:74dp;box-shadow:0dp 50dp 130dp #000a;overflow:hidden;} +.news-tablet>.titlebar {height:118dp;padding-top:14dp;border:0dp;border-radius:54dp 54dp 0dp 0dp;} +.news-tablet>.content {left:58dp;right:58dp;top:150dp;bottom:126dp;} +.news-camera {position:absolute;left:50%;margin-left:-7dp;top:18dp;width:14dp;height:14dp;border:3dp #111c25;border-radius:7dp;background-color:#526b83;z-index:5;} +.news-homebar {position:absolute;left:50%;margin-left:-130dp;bottom:16dp;width:260dp;height:8dp;border-radius:6dp;background-color:var(--muted);opacity:0.5;} +.news-screen-footer {position:absolute;left:58dp;right:58dp;bottom:42dp;height:60dp;display:flex;align-items:center;justify-content:space-between;border-top:2dp var(--border);font-size:24dp;color:var(--muted);} +.news-layout {position:absolute;left:0;right:0;top:0;bottom:0;color:var(--text);} +.news-masthead {position:absolute;left:6dp;right:6dp;top:0;height:180dp;padding-bottom:34dp;display:flex;align-items:center;justify-content:space-between;gap:36dp;} +.news-brand {display:flex;align-items:center;gap:34dp;min-width:0;} +.news-wordmark {padding:8dp 24dp 15dp;border:2dp #ff8c8c25;border-radius:15dp;background-color:#c92736;color:#fff6f4;font-size:86dp;font-weight:bold;font-style:italic;letter-spacing:-5dp;line-height:1;} +.news-brand p {margin-bottom:12dp;color:var(--muted);font-size:22dp;letter-spacing:4dp;} +.news-brand h2 {font-size:48dp;line-height:1.1;font-weight:normal;letter-spacing:-1dp;} +.news-owner {display:flex;align-items:center;gap:24dp;min-width:0;} +.news-owner>div {text-align:right;} +.news-owner strong {font-size:32dp;font-weight:normal;} +.news-owner p {margin-top:14dp;font-size:26dp;color:var(--muted);} +.news-owner>.image-frame {flex-shrink:0;} +.news-navigation {position:absolute;left:0;right:0;top:180dp;height:116dp;display:flex;align-items:center;gap:22dp;padding-bottom:28dp;border-bottom:2dp var(--border);} +.news-tabs {display:flex;align-items:stretch;padding:7dp;border:2dp var(--border);border-radius:17dp;background-color:var(--panel);gap:5dp;flex-shrink:0;} +.news-tabs .news-tab {display:flex;align-items:center;justify-content:center;gap:18dp;min-width:240dp;height:65dp;padding:12dp 22dp;border:0dp;border-radius:11dp;background-color:transparent;color:var(--muted);font-size:30dp;} +.news-tabs .news-tab.active {background-color:var(--selected);color:var(--text);} +.news-tab-count {min-width:40dp;padding:3dp 9dp;border-radius:8dp;background-color:var(--panel);color:var(--text);font-size:23dp;text-align:center;} +.news-search {display:flex;align-items:center;gap:16dp;min-width:0;max-width:760dp;flex:1;margin-left:auto;padding:16dp 22dp;border:2dp var(--border);border-radius:13dp;background-color:var(--input);} +.news-search input {min-width:0;width:100%;margin:0;padding:0;border:0dp;border-radius:0dp;background-color:transparent;color:var(--text);font-size:28dp;line-height:1.4;} +.news-search-symbol {position:relative;width:27dp;height:27dp;flex-shrink:0;margin-right:9dp;border:3dp var(--muted);border-radius:14dp;} +.news-search-symbol>span {position:absolute;left:21dp;top:21dp;width:13dp;height:3dp;transform:rotate(45deg);background-color:var(--muted);} +.news-read-all {display:flex;align-items:center;justify-content:center;gap:16dp;min-height:78dp;padding:14dp 22dp;border:2dp var(--border);border-radius:13dp;background-color:var(--soft);color:var(--text);font-size:27dp;white-space:nowrap;flex-shrink:0;} +.news-read-all .image-frame {flex-shrink:0;} +.news-feed {position:absolute;left:0;right:0;top:296dp;bottom:80dp;overflow-y:auto;overflow-x:hidden;padding-right:20dp;} +.news-message {position:relative;display:flex;align-items:center;gap:32dp;min-height:218dp;padding:28dp 16dp 28dp 18dp;border-bottom:2dp var(--border);} +.news-message.is-unread {background-color:var(--soft);} +.news-unread-dot {position:absolute;left:0;top:50%;margin-top:-5dp;width:10dp;height:10dp;border-radius:5dp;background-color:var(--accent);} +.news-art {display:flex;align-items:center;justify-content:center;flex-shrink:0;border:2dp var(--border);border-radius:28dp;background-color:var(--soft);} +.news-message-copy {flex:1;min-width:0;} +.news-message-meta {display:flex;align-items:center;gap:20dp;margin-bottom:13dp;font-size:24dp;line-height:1.4;color:var(--muted);} +.news-category {padding-left:20dp;border-left:2dp var(--border);} +.news-new {padding:2dp 12dp;border:2dp var(--border);border-radius:7dp;background-color:var(--selected);color:var(--accent);font-size:20dp;} +.news-message-title {display:flex;justify-content:flex-start;align-items:center;max-width:100%;padding:0;margin:0 0 12dp;border:0dp;border-radius:3dp;background-color:transparent;color:var(--text);font-size:35dp;font-weight:normal;line-height:1.3;text-align:left;} +.news-message.is-unread .news-message-title {font-weight:bold;} +.news-message-title:hover {background-color:transparent;color:var(--accent);} +.news-excerpt {max-height:81dp;overflow:hidden;font-size:27dp;line-height:1.5;color:var(--muted);} +.news-row-actions {display:flex;align-items:center;gap:10dp;width:136dp;flex-shrink:0;} +.news-icon-button {display:flex;align-items:center;justify-content:center;width:62dp;height:68dp;padding:10dp;border:0dp;border-radius:10dp;background-color:transparent;color:var(--muted);} +.news-icon-button:hover {background-color:var(--hover);color:var(--text);} +.news-symbol.archive {position:relative;width:29dp;height:26dp;margin-top:7dp;border:2dp var(--muted);border-radius:1dp;} +.news-symbol.archive>.news-archive-lid {position:absolute;left:-5dp;right:-5dp;top:-8dp;height:8dp;border:2dp var(--muted);background-color:var(--menu-top);} +.news-symbol.archive>.news-archive-handle {position:absolute;left:8dp;top:7dp;width:9dp;border-top:2dp var(--muted);} +.news-symbol.restore>.news-archive-handle {left:11dp;top:4dp;width:0;height:13dp;border-left:2dp var(--muted);} + +.news-bottom {position:absolute;left:4dp;right:4dp;bottom:0;height:80dp;display:flex;align-items:center;justify-content:space-between;gap:25dp;padding-top:12dp;} +.news-bottom>p {color:var(--muted);font-size:24dp;line-height:1.4;} +.news-undo {display:flex;align-items:center;justify-content:center;gap:16dp;padding:10dp 20dp;border:2dp var(--border);border-radius:10dp;background-color:var(--soft);color:var(--text);font-size:26dp;} +.news-undo-symbol {font-size:38dp;line-height:1;} +.news-empty {height:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:24dp;text-align:center;color:var(--muted);padding:70dp;} +.news-empty h3 {color:var(--text);font-size:42dp;font-weight:normal;} +.news-empty p {max-width:1300dp;font-size:29dp;line-height:1.6;} +.news-empty-art {position:relative;width:90dp;height:80dp;margin-bottom:10dp;border:3dp var(--muted);border-radius:5dp;} +.news-empty-art>span {position:absolute;left:0;right:0;top:30dp;height:0;border-top:3dp var(--muted);} +.news-detail-layer {position:absolute;left:0;right:0;top:0;bottom:0;z-index:20;} +.news-detail-shade {position:absolute;left:0;right:0;top:0;bottom:0;background-color:#08101980;} +.news-detail-box {position:absolute;left:64dp;right:64dp;top:50%;max-height:1552dp;overflow-y:auto;transform:translate(0,-50%);padding:40dp 52dp;border:2dp var(--border);border-radius:22dp;background-color:#283542f5;box-shadow:0dp 24dp 70dp #0007;font-size:36dp;} +.news-detail-box h2 {font-size:42dp;font-weight:bold;letter-spacing:-0.4dp;text-align:center;line-height:1.2;margin-bottom:35dp;} +.news-detail {padding-top:0;} +.news-detail-meta {display:flex;align-items:center;gap:28dp;margin-bottom:38dp;} +.news-detail-meta>div>p {margin-top:16dp;color:var(--muted);font-size:28dp;} +.news-detail-body {font-size:34dp;line-height:1.7;color:var(--text);} +.news-detail small {display:block;margin-top:34dp;color:var(--muted);font-size:24dp;} +.news-detail-actions {display:flex;align-items:stretch;justify-content:space-evenly;gap:70dp;margin-top:45dp;} +.news-detail-actions button {display:flex;align-items:center;justify-content:center;flex:1;min-width:0;padding:12dp 24dp;border:2dp var(--border);border-radius:12dp;font-size:32dp;} +body.silver .news-message.is-unread {background-color:#42627d05;} + +body.silver .news-detail-box {background-color:#eaf1f7fc;} +body.matchday .news-detail-box {background-color:#2c2c32fc;} +.news-message>.news-art {margin-right:6dp;} +.news-detail-meta>div>p:first-child {margin-top:0;} +/* Gold desktop journal: a quiet source-order preview, independent of tablet filters. */ +.news-widget-heading {position:absolute;left:0;right:0;top:0;height:70dp;display:flex;align-items:center;justify-content:space-between;gap:20dp;padding:22dp 30dp 12dp;border:0dp;border-radius:0dp;background-color:transparent;color:var(--muted);font-size:25dp;line-height:1.2;text-align:left;} +.news-widget-heading:hover {background-color:var(--hover);} +.news-widget-arrow {display:flex;align-items:center;justify-content:center;flex-shrink:0;} +.news-widget-feed {position:absolute;left:0;right:0;top:70dp;bottom:8dp;padding:0 28dp 16dp;display:flex;flex-direction:column;gap:10dp;overflow:hidden;} +.news-widget-row {display:flex;align-items:flex-start;gap:14dp;padding:10dp 0 18dp;border-bottom:1dp var(--border);} +.news-widget-copy {display:flex;flex-direction:column;gap:8dp;min-width:0;flex:1;} +.news-widget-date {font-size:21dp;color:var(--muted);} +.news-widget-title {font-size:25dp;line-height:1.25;font-weight:normal;max-height:62.5dp;overflow:hidden;} +.news-widget-dot {width:10dp;height:10dp;border-radius:5dp;background-color:transparent;flex-shrink:0;margin-top:8dp;} +.news-widget-row.unread .news-widget-dot {background-color:var(--accent);} + +/* The Modern Gold hides the legacy footer below the tablet content. */ +.news-screen-footer {display:none;} diff --git a/assets/modern/statistics.rcss b/assets/modern/statistics.rcss new file mode 100644 index 0000000..19991b5 --- /dev/null +++ b/assets/modern/statistics.rcss @@ -0,0 +1,109 @@ +/* SPDX-License-Identifier: GPL-3.0-only */ +.statistics-native {position:absolute;left:0;top:0;width:2612dp;height:1864dp;color:#d4e0e9;} +.statistics-panel {position:absolute;left:0;top:0;width:2612dp;height:1724dp;border:2dp #c5d9e726;border-radius:18dp;background-color:#12243140;} +.statistics-heading {position:absolute;left:30dp;top:30dp;width:2548dp;height:46dp;line-height:46dp;margin:0;font-size:38dp;font-weight:normal;color:#dce6ee;text-align:center;} +.statistics-winner-note {position:absolute;left:30dp;top:88dp;width:2548dp;height:32dp;margin:0;font-size:25dp;line-height:32dp;text-align:center;color:#99b1c2;} +.statistics-winner-note .statistics-cell-text {display:block;text-align:center;} +.statistics-list {position:absolute;left:30dp;top:114dp;width:2548dp;height:1580dp;overflow-y:auto;overflow-x:hidden;} +.statistics-list.statistics-winners {top:154dp;height:1540dp;} +.statistics-table {width:2548dp;} +.statistics-row {display:flex;align-items:center;width:2548dp;font-size:31dp;color:#d4e0e9;} +.statistics-row.striped {background-color:#e3edf605;} +.statistics-head {font-size:27dp;color:#a8bdcc;border-bottom:2dp #c5d9e72b;} +.statistics-cell {display:flex;align-items:center;justify-content:flex-end;min-width:0;flex-shrink:0;padding:8dp 14dp;overflow:hidden;} +.statistics-cell.statistics-col-0 {justify-content:flex-start;} +.statistics-cell-text {display:block;flex-shrink:0;white-space:nowrap;} +.statistics-cell>.statistics-cell-text {width:100%;text-align:right;} +.statistics-cell.statistics-col-0>.statistics-cell-text {text-align:left;} +.statistics-club {width:100%;max-width:100%;min-width:0;padding:2dp 0;font-size:31dp;color:var(--text);gap:14dp;} +.statistics-club .report-club-name {flex:1;min-width:0;max-width:100%;text-align:left;} +.statistics-club .image-frame {flex-shrink:0;} +.statistics-club.current {color:#b8e1d1;} +.statistics-winners .statistics-club.current {color:var(--text);} +.statistics-club.name-first {justify-content:flex-end;} +.statistics-club.name-first .report-club-name {text-align:right;flex:1;} +.statistics-section-1 .statistics-col-2 {justify-content:flex-start;} +.statistics-player-prefix {display:block;flex-shrink:0;white-space:nowrap;} +.statistics-player-link {display:flex;align-items:center;justify-content:flex-start;min-width:0;max-width:100%;padding:0;border:0;border-radius:0;background-color:transparent;font-size:31dp;color:var(--text);} +.statistics-player-link .statistics-cell-text {text-align:left;} +.statistics-player-link:hover {background-color:transparent;color:#f3f7fa;} +.statistics-player-link:focus-visible {background-color:var(--hover);} +.statistics-winners .statistics-cell {padding:14dp 20dp;justify-content:flex-start;} +.statistics-winners .statistics-cell>.statistics-cell-text {text-align:left;} +.statistics-winners .statistics-head {font-size:29dp;color:#b2c5d3;font-weight:normal;} +.statistics-winners .statistics-col-0 {font-size:29dp;color:#b8ccd9;} +.statistics-winners .statistics-club {gap:20dp;padding:6dp 0;} +.statistics-trophy-heading {display:flex;flex-direction:column;align-items:center;justify-content:center;width:100%;height:170dp;min-width:0;padding:6dp;border:0;border-radius:12dp;background-color:transparent;color:var(--text);font-size:29dp;font-weight:normal;} +.statistics-trophy-heading:hover {background-color:transparent;color:#f3f7fa;} +.statistics-trophy-heading:focus-visible {border:3dp var(--accent);} +.statistics-trophy-heading:disabled {opacity:1;color:var(--text);} +.statistics-trophy-icon {display:block;width:105dp;height:105dp;flex-shrink:0;} +.statistics-trophy-label {display:block;width:100%;height:35dp;line-height:35dp;margin-top:10dp;text-align:center;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;} +.statistics-world-trophy {display:flex;align-items:center;justify-content:flex-start;max-width:100%;min-width:0;height:62dp;padding:0;border:0;background-color:transparent;color:var(--text);font-size:31dp;} +.statistics-world-trophy:disabled {opacity:1;} +.statistics-world-trophy-art {display:block;width:58dp;height:58dp;margin-right:20dp;flex-shrink:0;} +.statistics-finals .statistics-cell {position:relative;} +.statistics-finals .statistics-cell.statistics-col-0 {padding-left:280dp;justify-content:flex-end;} +.statistics-finals .statistics-cell.statistics-col-0>.statistics-cell-text {text-align:right;} +.statistics-finals .statistics-cell.statistics-col-1 {padding-left:8dp;padding-right:8dp;justify-content:center;} +.statistics-finals .statistics-cell.statistics-col-1>.statistics-cell-text {text-align:center;} +.statistics-finals .statistics-cell.statistics-col-2 {padding-right:280dp;justify-content:flex-start;} +.statistics-finals .statistics-cell.statistics-col-2>.statistics-cell-text {text-align:left;} +.statistics-fixture-round {position:absolute;left:28dp;top:0;width:230dp;height:100%;display:flex;align-items:center;justify-content:flex-start;color:#a8bdcc;} +.statistics-fixture-round>span {display:block;max-width:100%;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;} +body.silver .statistics-fixture-round,body.matchday .statistics-fixture-round {color:var(--muted);} +.statistics-empty {margin:0;padding:40dp;font-size:30dp;color:var(--muted);} +.statistics-graph {position:absolute;left:30dp;top:104dp;width:2548dp;height:860dp;padding:22dp;border:2dp #c5d9e726;border-radius:16dp;background-color:#12233070;} +.statistics-series {position:absolute;left:30dp;top:992dp;width:2548dp;height:182dp;} +.statistics-action {border:2dp #d4e0ec29;border-radius:12dp;background-color:transparent;decorator:linear-gradient(180deg,#c1d1e31c,#869eb312);color:#e0e6ec;font-size:30dp;font-weight:normal;} +.statistics-action:hover {decorator:none;background-color:var(--hover);} +.statistics-action:focus-visible {border-color:var(--accent);} +.statistics-series-button {position:absolute;display:flex;align-items:center;justify-content:center;padding:12dp 24dp;} +.statistics-series-dot {display:block;width:18dp;height:18dp;margin-right:18dp;border-radius:9dp;flex-shrink:0;} +.statistics-series-label {display:block;flex-shrink:0;white-space:nowrap;} +.statistics-absolute>.statistics-cell-text {width:100%;text-align:center;} +.statistics-series-button[aria-pressed=false] {color:#92a6b6;} +.statistics-series-button[aria-pressed=false] .statistics-series-dot {opacity:0.35;} +.statistics-absolute {position:absolute;display:flex;align-items:center;justify-content:center;} +.statistics-absolute .statistics-cell-text {display:block;text-align:center;} +.statistics-section-8 .statistics-list {top:190dp;height:1504dp;} +.statistics-minutes .statistics-row {font-size:28dp;} +.statistics-minutes .statistics-cell {justify-content:center;padding:8dp;} +.statistics-minutes .statistics-cell>.statistics-cell-text {text-align:center;} +.statistics-minutes .statistics-cell.statistics-col-0 {justify-content:flex-start;} +.statistics-minutes .statistics-cell.statistics-col-0>.statistics-cell-text {text-align:left;} +.statistics-minutes .statistics-row:not(.statistics-head) .statistics-cell:not(.statistics-col-0) {border:4dp #293c48;background-color:#46606b33;color:#bdd0dc;} +.statistics-minutes .statistics-row:not(.statistics-head) .statistics-cell.good {background-color:#4c91774d;color:#c6ebd9;} +.statistics-minutes .statistics-row:not(.statistics-head) .statistics-cell.bad {background-color:#b65b554d;color:#f2c1b8;} +.statistics-trophy-layer {position:absolute;left:0;top:0;width:100%;height:100%;z-index:200000;overflow:hidden;background-color:var(--panel);color:var(--text);text-align:center;} +.statistics-trophy-backdrop {position:absolute;left:0;top:0;width:100%;height:100%;filter:saturate(0.3) brightness(0.4) blur(5px);pointer-events:none;} +.statistics-trophy-shade {position:absolute;left:0;top:0;width:100%;height:100%;background-color:var(--panel);pointer-events:none;} +.statistics-trophy-large {position:absolute;filter:drop-shadow(#0005 0dp 23.76dp 38.88dp);pointer-events:none;} +#statistics-trophy-title {position:absolute;margin:0;text-align:center;font-weight:normal;letter-spacing:0.02em;color:var(--text);} +.statistics-trophy-winner {position:absolute;display:flex;align-items:center;justify-content:center;color:var(--text);} +.statistics-trophy-winner .image-frame {margin-right:1.2em;flex-shrink:0;} +.statistics-trophy-winner>span {display:block;flex-shrink:0;white-space:nowrap;letter-spacing:-0.025em;} +.statistics-trophy-season {position:absolute;margin:0;text-align:center;color:var(--muted);} +.statistics-trophy-season .statistics-cell-text {display:block;width:100%;text-align:center;} +.statistics-trophy-close {position:absolute;display:flex;align-items:center;justify-content:center;padding:0;border:1px var(--border);background-color:transparent;decorator:linear-gradient(180deg,#daeaf316,#b9d6eb09);color:var(--text);} +.statistics-trophy-close:hover {decorator:none;background-color:var(--hover);} +.statistics-trophy-close:focus-visible {border-color:var(--accent);} +.statistics-trophy-close>span {display:block;} +body.silver .statistics-native,body.matchday .statistics-native,body.silver .statistics-row,body.matchday .statistics-row,body.silver .statistics-heading,body.matchday .statistics-heading,body.silver .statistics-winners .statistics-col-0,body.matchday .statistics-winners .statistics-col-0 {color:var(--text);} +body.silver .statistics-panel,body.matchday .statistics-panel,body.silver .statistics-graph,body.matchday .statistics-graph {border-color:var(--border);background-color:var(--panel);} +body.silver .statistics-head,body.matchday .statistics-head,body.silver .statistics-winners .statistics-head,body.matchday .statistics-winners .statistics-head,body.silver .statistics-winner-note,body.matchday .statistics-winner-note {border-color:var(--border);color:var(--muted);} +body.silver .statistics-row.striped {background-color:#42627d09;} +body.matchday .statistics-row.striped {background-color:#f8e7e00a;} +body.silver .statistics-club,body.matchday .statistics-club,body.silver .statistics-player-link,body.matchday .statistics-player-link {color:var(--text);} +body.silver .statistics-club.current,body.matchday .statistics-club.current {color:var(--accent);} +body.silver .statistics-winners .statistics-club.current,body.matchday .statistics-winners .statistics-club.current {color:var(--text);} +body.silver .statistics-action,body.matchday .statistics-action {border-color:var(--border);color:var(--text);} +body.silver .statistics-action {decorator:linear-gradient(180deg,#ffffffb0,#bfd0e259);} +body.matchday .statistics-action {decorator:linear-gradient(180deg,#e8d6dc12,#a1a0aa0d);} +body.silver .statistics-series-button[aria-pressed=false],body.matchday .statistics-series-button[aria-pressed=false] {color:var(--muted);} +body.silver .statistics-minutes .statistics-row:not(.statistics-head) .statistics-cell:not(.statistics-col-0),body.matchday .statistics-minutes .statistics-row:not(.statistics-head) .statistics-cell:not(.statistics-col-0) {border-color:var(--border);background-color:var(--panel);color:var(--text);} +body.silver .statistics-minutes .statistics-row:not(.statistics-head) .statistics-cell.good,body.matchday .statistics-minutes .statistics-row:not(.statistics-head) .statistics-cell.good {background-color:var(--hover);color:var(--accent);} +body.silver .statistics-minutes .statistics-row:not(.statistics-head) .statistics-cell.bad,body.matchday .statistics-minutes .statistics-row:not(.statistics-head) .statistics-cell.bad {background-color:#b65b554d;color:var(--danger);} + +body.silver .statistics-trophy-close {background-color:transparent;decorator:linear-gradient(180deg,#ffffffb0,#bfd0e259);} +body.silver .statistics-trophy-close:hover {decorator:none;background-color:var(--hover);} diff --git a/docs/new_ui/NATIVE_STATUS.md b/docs/new_ui/NATIVE_STATUS.md index 955b85b..22262af 100644 --- a/docs/new_ui/NATIVE_STATUS.md +++ b/docs/new_ui/NATIVE_STATUS.md @@ -109,13 +109,28 @@ wird ausdrücklich mit `OPENBMH_BUILD_MODERN_UI=ON` gebaut. Eintrittspreis sind umgesetzt. Der Peripherieausbau bleibt ausdrücklich für das angekündigte Redesign zurückgestellt; das Panorama ist nur Ansicht. +- [Statistiken](desktop/statistics/README.md): neun Auswertungen mit + Möglichkeiten, Transferhistorie, sechs Analytics-Kurven, ewigen Tabellen, + sechs WM-Ansichten, Saisonfinanzen, Rekorden, Siegerlisten und Minutenraster. + Nationale Sieger berücksichtigen alle fünf Länder; internationale Titel und + Hallenmasters behalten ihre BMH-Struktur. Pokale öffnen ein Vollbild mit + Vereins-/Ländername und Saison. Alle Filter bleiben lokale Ansichtsparameter. +- [Nachrichten](desktop/news/README.md): Tablet mit zwölf fiktiven Meldungen, + Postfach/Archiv, Suche, Lesen, Sammellesen, Archivierung, Papierkorb und + Rückgängig. Nachrichtenzustände gehören zum separaten UI-Demostand und + überstehen Speichern/Laden. Das Desktop-Widget zeigt zwei oder drei aktuelle + Überschriften und den gemeinsamen Ungelesen-Zähler. + **Anstoß führt keine Aktion aus**, weder per Maus noch per Tastatur. Das gilt auch für die direkte Aktionsschnittstelle des Demoanbieters. ## Noch offen -Die übrigen Desktop-Untermenüs werden in zusammengehörigen Paketen vom -HTML-Mockup übertragen. Für sie erscheinen derzeit keine vereinfachten Ersatzlayouts. +Die verbleibenden Routen und Teilbereiche werden in zusammengehörigen Paketen +vom HTML-Mockup übertragen. Für fehlende Ports erscheinen keine vereinfachten +Ersatzlayouts. Der Katalog zählt jetzt 34 native und drei noch nicht separat +zugeordnete Routen; diese Zahl bestätigt keine vollständige gestalterische +Abnahme aller früheren Teilimplementierungen. Der Einstellungsdialog, die vollständigen Widgetinhalte, Mod-Importkomfort und dauerhafte globale Voreinstellungen sind noch nicht vollständig. Übersetzungen, echte Engine-Anbindung und Plattform-Abnahme diff --git a/docs/new_ui/README.md b/docs/new_ui/README.md index f887cea..e281157 100644 --- a/docs/new_ui/README.md +++ b/docs/new_ui/README.md @@ -39,6 +39,8 @@ Implementierung in der Spiel-Engine. | Fairplay | [Strafpunkte, Karten und Vereinsprofile](desktop/fairplay/README.md) | | Highscore | [Manager-Rangliste und zentrierte Kennzahlen](desktop/highscore/README.md) | | Stadion | [Blöcke A–H, Ausstattung und Stadiondaten ohne Peripherieausbau](desktop/stadium/README.md) | +| Statistiken | [Neun Auswertungen, Siegerlisten, Analytics und Pokalbilder](desktop/statistics/README.md) | +| Nachrichten | [Tablet, Postfach, Archiv, Suche, Rückgängig und Desktopvorschau](desktop/news/README.md) | Jeder Bereich nennt die geprüfte Quelle, bestehende Funktionen und offene Entscheidungen für die Engine-Anbindung. Die Architekturgrundlage bleibt der diff --git a/docs/new_ui/desktop/news/README.md b/docs/new_ui/desktop/news/README.md new file mode 100644 index 0000000..b671279 --- /dev/null +++ b/docs/new_ui/desktop/news/README.md @@ -0,0 +1,74 @@ + +# Nachrichten / Tablet + +Die native RmlUI-Ansicht auf Branch `0.3` überträgt den privaten HTML-Goldstand +vom 25.10.2026 (Referenzrevision `ddd8cab7`; native Ausgangsrevision +`349c416`; `desktop/news-menu.js`, `news-tablet.css`, gemeinsame Menüthemen +und Information-Widget). Die privaten Bilddateien bleiben außerhalb des +Repositorys. Die Implementierung verwendet die gemeinsame 3840×2160-Fläche: +Das Tablet ist 2720×2040 groß; Schrift, Kamera, Rahmen und Homebar sind native +UI-Elemente. Midnight, Silver und Matchday verwenden dieselben Themenvariablen. + +Das Vereinsjournal zeigt Vereinswappen, aktuellen Vereinsnamen und Spieldatum, +die kicker-Wortmarke, Postfach und Archiv mit Gesamtzahlen, Suche, „Alle gelesen“ +und die Zahl der angezeigten ungelesenen Meldungen. Zwölf ausdrücklich fiktive +Meldungen beginnen mit neun Postfach- und drei Archivmeldungen, davon fünf +ungelesen. Die Anfangsdaten entstehen relativ zum aktuellen Spieldatum, auch +über Monats-, Jahres- und Schaltjahresgrenzen hinweg. Gespeicherte Vorlagen +lösen `{{club}}` und `{{manager}}` erst in der Projektion gegen den aktuellen +ersten Manager auf. Ein Managerwechsel behält deshalb keine alten Namen. +Die sechs Kategorien verwenden vorhandene GUI-Bilder für Spielbetrieb, +Verträge, Bargeld, Training und Stadion sowie das Vereinswappen aus dem OBW. +Feste Kategorieillustrationen gehören zur externen GUI-Ressourcensammlung. +Für die Wortmarke stehen passende kursive und fett-kursive Schriftvarianten +zur Verfügung; die mitgelieferten Lato-Varianten ergänzen fehlende Systemfonts. +Rückgängig benutzt ein natives SVG-Symbol statt eines vorausgesetzten +Unicode-Zeichens. Der Tablet-Rahmen bleibt in allen Themes dunkel wie im Gold; +der alte zusätzliche Bildschirmfooter ist ausgeblendet. + +Das Desktop-Widget übernimmt den Gold-Aufbau mit „Postfach · N ungelesen“ +und einem Öffnungspfeil. Es zeigt im kleinen 2×2-Format die ersten zwei, sonst +die ersten drei Postfachmeldungen in Quellreihenfolge: Lesepunkt, Datum und +einen auf zwei Zeilen begrenzten Titel. Aktiver Tablet-Ordner und Suchbegriff +beeinflussen weder Vorschau noch Gesamtzahl. + +Ein Titel öffnet die vollständige Meldung und markiert sie als gelesen. +Zeilenaktionen archivieren, holen eine Meldung ins Postfach zurück oder +verschieben sie in den ausgeblendeten Papierkorb. Archivieren und Zurückholen +markieren die Meldung zusätzlich als gelesen. „Alle gelesen“ betrifft den +gesamten aktuellen Ordner, auch bei aktiver Suche. Die letzte Sammel-, Archiv- +oder Löschaktion kann mit einem kleinen Patch aus ID, Lesestatus und Ordner +zurückgenommen werden. Die Aktion prüft die beobachtete Revision und jeden +betroffenen aktuellen Datensatz. Bei einem Konflikt bleibt der gesamte Zustand +unverändert. Ein bloßes Lesen erzeugt keinen neuen Undo-Eintrag. + +Suche berücksichtigt Titel, Text, Kategorie und deutsches Datum ohne +Beachtung der Großschreibung, einschließlich deutscher Umlaute. Suche und +Ordner sind reine lokale Ansichtsparameter; sie ändern weder Revision noch +Speicherstatus. Die Eingabe aktualisiert nur die Liste und den Zähler und +behält Fokus und Textauswahl bei; die Liste beginnt nach jeder Suche oben. +Ein Ordnerwechsel löscht die Suche und beginnt ebenfalls oben. Leere Ordner und leere Suchergebnisse haben +unterschiedliche Hinweise. Pfeil links/rechts sowie Pos1/Ende wechseln die +Register; Tab bleibt im aktiven Fenster beziehungsweise Detaildialog. Escape +und die rechte Maustaste schließen zuerst den Detaildialog. Rückkehrfokus und +Scrollposition bleiben bei Aktionen erhalten. Schließen verwirft Detaildialog, +Feedback, Scrollposition und Undo; der gewählte Ordner und die Suche bleiben beim +erneuten Öffnen derselben Welt in der laufenden UI-Sitzung erhalten. Anders als +im HTML-Prototyp gelangen diese reinen Ansichtsparameter nicht in einen +Spielcheckpoint; Laden einer Welt beginnt mit dem Postfach ohne Suche. + +Die Grenze zur Quelle liegt in `DataSource`/`DemoSource`: `news` enthält nur +`version` und maximal 100 strikt validierte Meldungen. Ältere Demo-Checkpoints +ohne `news` werden beim Laden ergänzt; vorhandene fehlerhafte Postfächer werden +atomar abgewiesen. Aktionen schreiben ausschließlich diesen Präsentationsblock. +Es gibt weder `GameState`-Zugriffe noch Änderungen an Geld, Kader, Kalender, +Weltkatalog oder Zufallsströmen. Eine spätere Session-Quelle muss echte Meldungen +und deren Zuständigkeit liefern; Ereigniserzeugung und Gameplay bleiben offen. + +`modern_news_ui_tests` verwendet ausschließlich synthetische Kataloge und prüft +Migration, dynamische Identität und Daten, Suche, Zähler, Lesen, Sammellesen, +Archiv/Zurückholen/Löschen, kleine Undo-Patches, Konflikte, strikte Validierung, +Revisionen sowie Save/Load und atomare Ablehnung fehlerhafter Checkpoints. +Visuelle Prüfung und native Eingabereplays erfolgen zusätzlich bei 1280×720 +und 1920×1080 in allen drei Themen; konkrete Ergebnisse stehen im zugehörigen +QA-Protokoll. Diese Tests ersetzen keine Prüfung einer späteren Engine-Quelle. diff --git a/docs/new_ui/desktop/statistics/README.md b/docs/new_ui/desktop/statistics/README.md new file mode 100644 index 0000000..d1eddf5 --- /dev/null +++ b/docs/new_ui/desktop/statistics/README.md @@ -0,0 +1,68 @@ + +# Statistiken + +Referenz: privater HTML-Goldstand `ddd8cab7` vom 25.10.2026, +`desktop/report-menus.js` (`stats`, `winners`, `statsBody`) sowie +`table-window.css`, `trophies.css` und die drei Menüthemen. Die native +Umsetzung verwendet RmlUI im gemeinsamen Fenster mit 2720 × 2040 logischen +Pixeln. Das öffentliche Repository enthält keine Referenzbilder oder +proprietären Datenbestände. + +Der Einstieg zeigt **Sieger → National → Deutschland**. Die Hauptauswahl +enthält Möglichkeiten, Transferhistorie, Analytics, Ewige Tabelle, +WM-Statistiken, Saisonfinanzen, Serien u. Rekorde, Sieger und +Minuten-Statistik. Nationale Sieger zeigen zwölf Saisons und drei Wettbewerbe +für Deutschland, Spanien, Italien, Frankreich oder England. International +bleiben Champions League, Pokalsieger und UEFA-Cup erhalten; Hallenmasters +zeigt Sieger und Finalist. Die Ewige Tabelle übernimmt sämtliche Vereine der +höchsten Liga des gewählten Landes, einschließlich einer zwanzigsten Zeile. + +Analytics zeigt sechs einzeln schaltbare Kurven mit je 24 Punkten. REL./ABS. +wechselt zwischen beiden Darstellungen. Die WM-Auswahl bietet Sieger, +Gruppen, Torschützen, Finalrunde, Tabelle und Historie. Die Minutenansicht +zeigt vier Ereignisse über 18 Fünfminutenintervalle mit den Farbmarkierungen +des Goldstands. Dropdowns verwenden die gemeinsamen nativen Berichtspicker +mit Maus, Pfeiltasten, Pos1/Ende, Eingabe, Escape und Fokuswiederherstellung. +Vereine und Spieler öffnen die vorhandenen Profile. Ein Pokal öffnet sein +Vollbild-Siegerbild vor dem abgedunkelten Stadion, wenn der +Welt- oder GUI-Katalog das passende Bild bereitstellt. Escape, Rechtsklick und Weiter +schließen das Bild und stellen den Fokus auf dem auslösenden Pokal wieder her. + +Alle Zahlen und historischen Ergebnisse sind ausdrücklich fiktive, +deterministische Darstellungsdaten nach dem HTML-Muster. Vereins-, Spieler- +und Länderreferenzen stammen aus dem tatsächlich geöffneten OBW-Katalog. +Managername und Bezugsdatum werden aus dem aktuellen vollständigen Snapshot +gelesen; Saisonvergleiche enden bei der letzten abgeschlossenen Saison. +Fehlende Identitäten erzeugen keine Ersatzvereine oder Ersatzspieler. + +Die Datenquelle bietet ausschließlich `read_statistics(request)`. Filter, +Kurvenschalter, Scrollpositionen und Bilddialoge gehören zum lokalen +Ansichtszustand. Es gibt weder einen Statistik-Schreibbefehl noch einen +Zugriff auf Engine, GameState oder Zufallsströme. Snapshot, gespeicherte +Demo-Daten, Revisionsnummer und Dirty-Flag bleiben bei diesen Lesezugriffen +unverändert. Die vorhandenen [Engine-Statistikabfragen](../../../new_engine/statistik.md) +für Wettbewerbe, Titelträger und Spielerwerte werden damit noch nicht aufgerufen. +Der spätere Session-Adapter muss diese Daten in die Ansicht übersetzen; +weitere Auswertungen benötigen entsprechende Projektionen. + +`modern_statistics_ui_tests` prüft alle neun Bereiche, sämtliche WM-Ansichten, +Land-/Wettbewerbsfilter, die vollständige Zwanzigerliga, stabile Identitäten, +Kurvendaten, ungültige Anfragen, leere Welten und die unveränderliche +Datenquellengrenze. Native Bild- und Interaktionsprüfung wird separat im +privaten QA-Lauf dokumentiert; ein bestandener Projektionstest allein ist +keine visuelle Abnahme. + +Die englische Fußballnation darf die stabile OBW-Kennung `nation:x-eng` +anstelle von `nation:en` führen. Länderwahl, ewige Tabelle und WM-Darstellung +verwenden dieselbe Auflösung; die Titel heißen weiterhin Premier League, +FA Cup und League Cup. Der Katalog und seine IDs werden nicht verändert. +Ein synthetischer Regressionstest deckt diese importierte Kennung und die +vollständige zwanzigste englische Mannschaft ab. + +Die Demo bevorzugt vorhandene logische Weltbilder unter +`asset:comp//trophy`. Die Darstellung akzeptiert außerdem ausdrücklich +gelieferte Asset-Schlüssel und den generischen Weltpokal als Ersatz. Die +abgestimmten GUI-Studien dienen nur als Vorschauersatz, falls die Welt die +entsprechende Demorolle nicht enthält. Der spätere Session-Adapter liefert die +wettbewerbsspezifischen Referenzen der tatsächlichen Historie. Auflösung und +Seitenverhältnis bleiben vom Datensatz bestimmt; das OBW wird nicht bearbeitet. diff --git a/docs/new_ui/menu-qa.md b/docs/new_ui/menu-qa.md index 1e79e40..ec6daeb 100644 --- a/docs/new_ui/menu-qa.md +++ b/docs/new_ui/menu-qa.md @@ -173,3 +173,36 @@ Der Katalog umfasst **32 native und 5 noch offene Routen**, zusätzlich zu bewusst zurückgestellten Teilbereichen wie der Stadionperipherie. Der Stadionabschluss besteht 29 Regressionstests. Die unabhängige native Zusatzprüfung besteht 27/27 Fälle, zusätzlich zu 26 Gold-Browser-Behaviors und dem Abgleich aller 28 GUI-Stufenreferenzen. Korrigiert wurden der innere Facility-Bildbeschnitt, die Kapazitätsbeschriftung und die Home/End-Zuordnung nach Mausfokus. Die funktionalen Nachweise enthalten getrennte ursprüngliche und korrigierte Runtimekohorten sowie echte Speicher-Neustarts. + + +Das Informationspaket ergänzt [Statistiken](desktop/statistics/README.md) und +[Nachrichten](desktop/news/README.md). Der HTML-Goldstand bleibt `ddd8cab7`; +222 Browserprüfungen dokumentieren die Referenzbedienung. Die nativen +Ansichten wurden in allen drei Themes bei 720p und 1080p mit echten +RmlUI-Ereignissen erfasst. 1.770 Zustandsprüfungen bestehen für sämtliche +Statistikbereiche, Länder-/Wettbewerbsfilter, Kurven, Profile und +Nachrichtenaktionen einschließlich Abbruch, Scrollen, Fokus, Undo, +Speichern und vollständigem Prozessneustart. Vierzehn gerichtete Prüfungen +ergänzen die tatsächliche Desktop-Widgetauswahl und eine Ultrawide-Pokalansicht. + +Korrigiert wurden verschwindende intrinsische Flexbeschriftungen bei Analytics, +Spieler-/Vereinsnamen, WM-Jahreszahlen und Pokalsiegern; außerdem die fehlende +fett-kursive Wortmarkenschrift und die stabile englische Länderkennung +`nation:x-eng`. Der vorhandene Control-Test lädt nun auch beide neuen +Produktionsstylesheets und prüft ihre Beschriftungen in drei Themes bei +vier Pixeldichten. Die lokale Meilenstein-Suite besteht **31/31 Tests**. + +Die Abschlusskontrolle umfasst alle 17 tatsächlichen Weltpokalbilder, +deren bytegleichen Bezug zu den freigegebenen Referenzen sowie gezielte +Nachprüfungen der Siegerbeschriftungen, des Tablet-Rahmens, des Undo-Symbols +und des Silver-Buttons. Alle 125 gerichteten Abschlussprüfungen bestehen. +Die unabhängigen Runtimekohorten behalten jeweils ihre tatsächlichen +Binary-/Stylesheet-Hashes. Der aktuelle Katalog umfasst **34 native und drei +noch nicht separat zugeordnete Routen**, zusätzlich zu offenen Teilbereichen +wie Einstellungen, Desktopdetails und zurückgestellter Stadionperipherie. +Die privaten Screenshots, ladbaren UI-Demostände und Eingabeskripte liegen +unter `bmh_4k_ui/docs/qa/information-batch-2026-10-25/`. + +Die 31 lokalen Regressionstests und die Linux-/OpenGL-Bildkontrolle sind keine +Behauptung einer Windows-/macOS-Laufzeitabnahme. Die gemeinsame CI baut die +opt-in Oberfläche und ihre synthetischen Tests zusätzlich auf diesen Plattformen. diff --git a/docs/new_ui/qa-findings.md b/docs/new_ui/qa-findings.md index 628be16..1ddf84c 100644 --- a/docs/new_ui/qa-findings.md +++ b/docs/new_ui/qa-findings.md @@ -33,7 +33,7 @@ gemeinsamen Controländerungen zusätzlich in mehreren Menüs nachgeprüft. Die erste Gesamterfassung enthält 36 Routen, davon zwölf native Aufnahmen und 24 ausstehende Ports. Diese historische Matrix bleibt unverändert. Der anschließend übertragene Kalender bekommt einen eigenen Vergleich; -der aktuelle Runner erfasst 32 native Routen und 5 offene Ports. +der aktuelle Runner erfasst 34 native und drei noch nicht separat zugeordnete Routen. Spätere Meilensteine erfassen denselben Gesamtkatalog erneut. Siehe [QA-Ablauf](menu-qa.md), [Typografie](typography-qa.md) und @@ -80,3 +80,14 @@ Streifenfarben in allen Themes. Highscore und Vereinsgeschichte verwenden linke Vereinsnamen direkt neben den Wappen; die Kennzahlen bleiben zentriert. Kleine Unterschiede der Font-/Ziffernraster bei 720p sind im privaten Bildnachweis dokumentiert, keine verdeckten Geometriefehler. + + +Im Informationspaket behoben: unsichtbare Flextexte in Analytics, +Transferhistorie, WM-Titeln und Siegerbildern, fehlende fett-kursive +Wortmarke und ein nicht vorhandenes Unicode-Undo-Zeichen. England verwendet +seine tatsächliche stabile Weltkennung; beide Länder-Auswahlen und alle +englischen Titel-/Pokalnamen bleiben damit korrekt. Tablet-Rahmen und +Silver-Button übernehmen die Referenzfarben. Pokalbilder werden bevorzugt +aus dem Weltindex geladen; die vorhandenen GUI-Studien bleiben ein +unabhängiger Ersatz. Im geprüften Umfang dieser beiden Menüs besteht nach +den gezielten Schlusskontrollen kein offener P1/P2-Befund. diff --git a/src/modern/ui/CMakeLists.txt b/src/modern/ui/CMakeLists.txt index 4275ea1..3434776 100644 --- a/src/modern/ui/CMakeLists.txt +++ b/src/modern/ui/CMakeLists.txt @@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-3.0-only -add_library(bmh_modern_ui_core STATIC catalog.cpp model.cpp gui_assets.cpp desktop.cpp demo_sports.cpp demo_calendar.cpp demo_reports.cpp demo_almanac.cpp demo_finance.cpp demo_environment.cpp demo_advertising.cpp demo_toto.cpp demo_lineup.cpp demo_transfer.cpp demo_career_reports.cpp demo_rankings.cpp demo_stadium.cpp) +add_library(bmh_modern_ui_core STATIC catalog.cpp model.cpp gui_assets.cpp desktop.cpp demo_sports.cpp demo_calendar.cpp demo_reports.cpp demo_almanac.cpp demo_finance.cpp demo_environment.cpp demo_advertising.cpp demo_toto.cpp demo_lineup.cpp demo_transfer.cpp demo_career_reports.cpp demo_rankings.cpp demo_stadium.cpp demo_statistics.cpp demo_news.cpp) target_include_directories(bmh_modern_ui_core PUBLIC ../..) target_link_libraries(bmh_modern_ui_core PUBLIC bmh_asset_io) add_library(bmh_modern_ui STATIC view.cpp ticket_popover.cpp) @@ -14,7 +14,7 @@ endif() set(modern_assets "${CMAKE_BINARY_DIR}/assets/modern") FetchContent_GetProperties(rmlui) file(MAKE_DIRECTORY "${modern_assets}") -foreach(asset modern.rml theme.rcss ticket.rcss sports.rcss calendar.rcss reports.rcss report_details.rcss report_pickers.rcss indoor.rcss planning.rcss almanac.rcss finance.rcss bank.rcss contracts.rcss amount.rcss environment.rcss advertising.rcss toto.rcss lineup.rcss transfer.rcss career_reports.rcss rankings.rcss stadium.rcss) +foreach(asset modern.rml theme.rcss ticket.rcss sports.rcss calendar.rcss reports.rcss report_details.rcss report_pickers.rcss indoor.rcss planning.rcss almanac.rcss finance.rcss bank.rcss contracts.rcss amount.rcss environment.rcss advertising.rcss toto.rcss lineup.rcss transfer.rcss career_reports.rcss rankings.rcss stadium.rcss statistics.rcss news.rcss) configure_file("${CMAKE_SOURCE_DIR}/assets/modern/${asset}" "${modern_assets}/${asset}" COPYONLY) endforeach() @@ -34,7 +34,7 @@ foreach(icon ${modern_icons}) get_filename_component(icon_name "${icon}" NAME) configure_file("${icon}" "${modern_assets}/icons/${icon_name}" COPYONLY) endforeach() -foreach(weight Regular Bold) +foreach(weight Regular Bold Italic BoldItalic) configure_file("${rmlui_SOURCE_DIR}/Samples/assets/LatoLatin-${weight}.ttf" "${modern_assets}/LatoLatin-${weight}.ttf" COPYONLY) endforeach() @@ -99,3 +99,12 @@ foreach(component environment advertising toto lineup transfer stadium) endif() add_test(NAME modern_${component}_ui_tests COMMAND modern_${component}_ui_tests) endforeach() + +foreach(component statistics news) + add_executable(modern_${component}_ui_tests ../../../tests/modern_${component}_ui_tests.cpp) + target_link_libraries(modern_${component}_ui_tests PRIVATE bmh_modern_ui_core) + if(MSVC) + target_compile_options(modern_${component}_ui_tests PRIVATE /utf-8) + endif() + add_test(NAME modern_${component}_ui_tests COMMAND modern_${component}_ui_tests) +endforeach() diff --git a/src/modern/ui/controls.inc b/src/modern/ui/controls.inc index 810dcb6..b9aff2e 100644 --- a/src/modern/ui/controls.inc +++ b/src/modern/ui/controls.inc @@ -133,7 +133,7 @@ void App::ProcessEvent(Rml::Event &event) try { const auto type = event.GetType(); // Native widgets can emit intermediate selected values while their options // are being constructed. Opening a squad menu must stay read-only. - if (setting_menu_markup_ && (menu_ == "lineup" || menu_ == "transfer") && + if (setting_menu_markup_ && (menu_ == "lineup" || menu_ == "transfer" || menu_ == "news") && (type == "change" || type == "input")) return; if (type == "keydown") keyboard_navigation_ = true; @@ -168,6 +168,7 @@ void App::ProcessEvent(Rml::Event &event) try { if (report_detail_kind_.empty() && stadium_event(event)) return; if (popup_.empty() && contracts_event(event)) return; if (popup_.empty() && (advertising_event(event) || toto_event(event))) return; + if (popup_.empty() && (statistics_event(event) || news_event(event))) return; if (popup_.empty() && (bank_event(event) || finance_event(event))) return; if (!planning_dialog_.empty() && popup_.empty()) { const bool key_event = type == "keydown"; @@ -460,6 +461,7 @@ void App::dispatch(const std::string &action, Rml::Element *target) { target ? target->GetAttribute("data-id", "") : std::string(); if (lineup_action(action, target) || transfer_action(action, target)) return; if (career_report_action(action, target) || rankings_action(action, target)) return; + if (statistics_action(action, target) || dispatch_news(action, target)) return; if (stadium_action(action, target)) return; if (environment_action(action, target) || advertising_action(action, target) || toto_action(action, target)) return; if (amount_action(action, target) || bank_action(action, target) || finance_action(action, target) || contracts_action(action, target)) return; @@ -1074,7 +1076,7 @@ void App::dispatch(const std::string &action, Rml::Element *target) { } static const std::set available = { "tables", "strengths", "camp", "settings", - "save", "load", "training", "tactics", "calendar", "league", "other", "postpone", "friendlies", "indoor", "almanac", "bank", "balance", "contracts", "environment", "advertising", "toto", "lineup", "transfer", "achievements", "scorers", "fairplay", "highscore", "stadium"}; + "save", "load", "training", "tactics", "calendar", "league", "other", "postpone", "friendlies", "indoor", "almanac", "bank", "balance", "contracts", "environment", "advertising", "toto", "lineup", "transfer", "achievements", "scorers", "fairplay", "highscore", "stadium", "statistics", "news"}; if (!available.contains(route)) { message("Diese native Ansicht wird im nächsten Menüpaket übertragen."); return; @@ -1467,6 +1469,11 @@ void App::script() { {"transfer_view", transfer_view_}, {"transfer_dialog", transfer_dialog_}, {"transfer_draft", transfer_draft_}, {"career_view", career_view_}, {"rankings_view", rankings_view_}, {"stadium_view", stadium_view_}, + {"statistics_view", statistics_view_}, {"statistics_trophy", statistics_trophy_}, + {"statistics_scrolls", statistics_scrolls_}, + {"news_view", news_view_}, {"news_dialog", news_dialog_}, + {"news_undo", news_undo_}, {"news_scroll", element("news-feed") ? element("news-feed")->GetScrollTop() : news_scroll_}, + {"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()}, {"source_revision", source_ ? Json(snap().revision) : Json()}, diff --git a/src/modern/ui/demo_news.cpp b/src/modern/ui/demo_news.cpp new file mode 100644 index 0000000..b469c72 --- /dev/null +++ b/src/modern/ui/demo_news.cpp @@ -0,0 +1,366 @@ +// SPDX-License-Identifier: GPL-3.0-only +#include "modern/ui/demo_news.hpp" +#include +#include +#include +#include +#include +#include +#include +#include + +namespace bmh::modern_ui { +namespace { +bool news_keys(const Json &v, std::initializer_list expected) { + return v.is_object() && v.size() == expected.size() && + std::all_of(expected.begin(), expected.end(), + [&](auto *key) { return v.contains(key); }); +} +bool news_text(const Json &v, size_t cap, bool nonempty = false) { + if (!v.is_string()) + return false; + const auto &s = v.get_ref(); + return s.size() <= cap && s.find('\0') == s.npos && + (!nonempty || s.find_first_not_of(" \t\r\n") != s.npos); +} +bool news_id(const Json &v) { + if (!news_text(v, 64, true)) + return false; + const auto &s = v.get_ref(); + return s.find_first_not_of("abcdefghijklmnopqrstuvwxyz0123456789-") == s.npos; +} +bool news_folder(const Json &v, bool trash = true) { + return v == "inbox" || v == "archive" || (trash && v == "trash"); +} +std::optional news_date(const std::string &value) { + using namespace std::chrono; + if (value.size() != 10 || value[4] != '-' || value[7] != '-') + return {}; + for (size_t i = 0; i < value.size(); ++i) + if (i != 4 && i != 7 && (value[i] < '0' || value[i] > '9')) + return {}; + const int y = std::stoi(value.substr(0, 4)), + m = std::stoi(value.substr(5, 2)), + d = std::stoi(value.substr(8, 2)); + const year_month_day date{year{y}, month{unsigned(m)}, day{unsigned(d)}}; + if (y < 1 || y > 9999 || !date.ok()) + return {}; + return sys_days{date}; +} +std::string news_iso(std::chrono::sys_days date) { + const std::chrono::year_month_day d{date}; + std::ostringstream out; + out << std::setfill('0') << std::setw(4) << int(d.year()) << '-' + << std::setw(2) << unsigned(d.month()) << '-' << std::setw(2) + << unsigned(d.day()); + return out.str(); +} +std::string news_category(const std::string &kind) { + if (kind == "club") + return "Verein"; + if (kind == "fixture") + return "Spielbetrieb"; + if (kind == "transfer") + return "Personal"; + if (kind == "finance") + return "Finanzen"; + if (kind == "training") + return "Training"; + if (kind == "stadium") + return "Stadion"; + return {}; +} +std::string news_replace(std::string text, const std::string &key, + const std::string &value) { + size_t at = 0; + while ((at = text.find(key, at)) != text.npos) { + text.replace(at, key.size(), value); + at += value.size(); + } + return text; +} +std::string news_fold(std::string text) { + for (auto &ch : text) + if (static_cast(ch) < 128) + ch = char(std::tolower(static_cast(ch))); + for (const auto &[a, b] : + std::array, 4>{ + {{"Ä", "ä"}, {"Ö", "ö"}, {"Ü", "ü"}, {"ẞ", "ß"}}}) + text = news_replace(std::move(text), a, b); + return text; +} +Json news_pair(const Json &item) { + return {{"read", item.at("read")}, {"folder", item.at("folder")}}; +} +bool news_valid_pair(const Json &v) { + return news_keys(v, {"read", "folder"}) && v.at("read").is_boolean() && + news_folder(v.at("folder")); +} +} // namespace + +std::string news_display_date(const std::string &s) { + return news_date(s) + ? s.substr(8, 2) + "." + s.substr(5, 2) + "." + s.substr(0, 4) + : s; +} +Json demo_news(const Catalog &world, const Json &state) { + const auto value = + state.value("date", world.manifest().value("start_date", std::string())); + const auto today = news_date(value); + if (!today) + throw editor::Error("invalid_news_date"); + struct Fixture { + const char *id; + int ago; + const char *kind, *title, *body; + bool read; + const char *folder; + }; + const std::array fixtures{ + {{"season", 0, "club", "Die neue Saison kann kommen", + "Willkommen zurück, {{manager}}. {{club}} startet in die " + "Saisonvorbereitung. Mannschaft, Verein und Fans blicken voller " + "Vorfreude auf die neue Spielzeit.", + false, "inbox"}, + {"cup", 0, "fixture", "Der Pokal schreibt seine eigenen Geschichten", + "64 Mannschaften, 32 Paarungen und ein gemeinsames Ziel: das Finale. " + "Die erste Runde eröffnet die neue Pokalsaison.", + false, "inbox"}, + {"contract", 1, "transfer", "Vertragsgespräche stehen an", + "Nico Brandt möchte seine Zukunft frühzeitig klären. Die sportliche " + "Leitung plant ein Gespräch mit dem Torwart über seine Rolle im Kader.", + false, "inbox"}, + {"tickets", 1, "finance", "8.320 Dauerkarten für die neue Saison", + "Der Vorverkauf läuft gut: 8.320 Fans haben sich bereits ihren " + "Stammplatz gesichert. Die fiktiven Einnahmen aus dem " + "Dauerkartenverkauf betragen 1.450.000 €.", + false, "inbox"}, + {"camp", 2, "training", "Die Vorbereitung nimmt Fahrt auf", + "Ein Trainingslager bietet Raum für Kondition, Technik und Teamgeist. " + "Das Trainerteam hat erste Ziele für die gemeinsame Vorbereitung " + "zusammengestellt.", + false, "inbox"}, + {"shirt", 3, "finance", "Neue Optionen für die Trikotwerbung", + "Mehrere Unternehmen interessieren sich für eine Partnerschaft mit " + "{{club}}. Die Angebote können in Ruhe geprüft und verglichen werden.", + true, "inbox"}, + {"friendly", 4, "fixture", "Ein erster Härtetest für die Mannschaft", + "Ein Testspiel steht auf dem Vorbereitungsplan. Das Trainerteam möchte " + "möglichst vielen Spielern Einsatzzeit geben.", + true, "inbox"}, + {"pitch", 5, "stadium", "Der Rasen ist bereit für den Saisonstart", + "Die Platzpflege hat die Sommerpause genutzt. Der Rasen präsentiert " + "sich zum Trainingsauftakt in gutem Zustand.", + true, "inbox"}, + {"fans", 6, "club", "Vorfreude auf den Rängen", + "Die Fans von {{club}} stimmen sich auf die neue Saison ein. Zum " + "Trainingsauftakt werden zahlreiche Besucher erwartet.", + true, "inbox"}, + {"review", 7, "fixture", "Die Saison im Rückblick", + "Spannende Spiele, große Gefühle und viele gemeinsame Momente: Eine " + "ereignisreiche Spielzeit liegt hinter dem Verein.", + true, "archive"}, + {"planning", 9, "transfer", "Sommerplanung mit klarem Kurs", + "Die sportliche Leitung hat die Aufgaben für die Sommerpause " + "zusammengestellt. Im Mittelpunkt stehen die Kaderplanung und die " + "Entwicklung junger Spieler.", + true, "archive"}, + {"together", 12, "club", "Gemeinsam in die nächste Spielzeit", + "Vorstand und Trainerteam bedanken sich bei Mannschaft, Mitarbeitern " + "und Fans für ihre Unterstützung.", + true, "archive"}}}; + Json items = Json::array(); + for (const auto &f : fixtures) { + const auto day = *today - std::chrono::days{f.ago}; + if (int(std::chrono::year_month_day{day}.year()) < 1) + throw editor::Error("invalid_news_date"); + items.push_back({{"id", f.id}, + {"date", news_iso(day)}, + {"kind", f.kind}, + {"title", f.title}, + {"body", f.body}, + {"read", f.read}, + {"folder", f.folder}}); + } + return {{"version", 1}, {"items", items}}; +} +bool valid_demo_news(const Json &state) { + try { + const auto &news = state.at("news"); + if (!news_keys(news, {"version", "items"}) || + !news.at("version").is_number_integer() || news.at("version") != 1 || + !news.at("items").is_array() || news.at("items").size() > 100) + return false; + std::set ids; + for (const auto &m : news.at("items")) { + if (!news_keys( + m, {"id", "date", "kind", "title", "body", "read", "folder"}) || + !news_id(m.at("id")) || + !ids.insert(m.at("id").get()).second || + !m.at("date").is_string() || + !news_date(m.at("date").get()) || + !m.at("kind").is_string() || + news_category(m.at("kind").get()).empty() || + !news_text(m.at("title"), 160, true) || + !news_text(m.at("body"), 1200) || !m.at("read").is_boolean() || + !news_folder(m.at("folder"))) + return false; + } + return true; + } catch (const std::exception &) { + return false; + } +} +bool migrate_demo_news(Json &state, const Catalog &world) { + try { + if (!state.is_object()) + return false; + if (state.contains("news")) + return valid_demo_news(state); + auto next = state; + next["news"] = demo_news(world, state); + if (!valid_demo_news(next)) + return false; + state = std::move(next); + return true; + } catch (const std::exception &) { + return false; + } +} +std::string edit_demo_news(Json &state, const Json &action, const Catalog &) { + if (!valid_demo_news(state)) + return "invalid_news_state"; + try { + if (!action.is_object() || !action.contains("kind") || + !action.at("kind").is_string()) + return "invalid_news_action"; + const auto kind = action.at("kind").get(); + auto next = state; + auto &items = next["news"]["items"]; + if (kind == "read-all") { + if (!news_keys(action, {"kind", "folder"}) || + !news_folder(action.at("folder"), false)) + return "invalid_news_action"; + for (auto &item : items) + if (item.at("folder") == action.at("folder")) + item["read"] = true; + } else if (kind == "read" || kind == "move") { + if (!(kind == "read" ? news_keys(action, {"kind", "id"}) + : news_keys(action, {"kind", "id", "folder"})) || + !news_id(action.at("id")) || + (kind == "move" && !news_folder(action.at("folder")))) + return "invalid_news_action"; + auto found = std::find_if(items.begin(), items.end(), [&](const auto &m) { + return m.at("id") == action.at("id"); + }); + if (found == items.end() || found->at("folder") == "trash") + return "news_not_found"; + if (kind == "read") + (*found)["read"] = true; + else { + (*found)["folder"] = action.at("folder"); + if (action.at("folder") != "trash") + (*found)["read"] = true; + } + } else if (kind == "undo") { + if (!news_keys(action, {"kind", "patch"}) || + !action.at("patch").is_array() || action.at("patch").empty() || + action.at("patch").size() > 100) + return "invalid_news_action"; + std::set ids; + for (const auto &p : action.at("patch")) { + if (!news_keys(p, {"id", "before", "after"}) || !news_id(p.at("id")) || + !ids.insert(p.at("id").get()).second || + !news_valid_pair(p.at("before")) || + !news_valid_pair(p.at("after")) || p.at("before") == p.at("after")) + return "invalid_news_action"; + auto found = + std::find_if(items.begin(), items.end(), [&](const auto &m) { + return m.at("id") == p.at("id"); + }); + if (found == items.end() || news_pair(*found) != p.at("after")) + return "news_undo_conflict"; + (*found)["read"] = p.at("before").at("read"); + (*found)["folder"] = p.at("before").at("folder"); + } + } else + return "invalid_news_action"; + if (!valid_demo_news(next)) + return "invalid_news_state"; + state = std::move(next); + return {}; + } catch (const std::exception &) { + return "invalid_news_action"; + } +} +int demo_news_unread(const Json &state) { + if (!valid_demo_news(state)) + return 0; + int count = 0; + for (const auto &m : state.at("news").at("items")) + if (m.at("folder") == "inbox" && !m.at("read").get()) + ++count; + return count; +} +Json demo_news_view(const Catalog &world, const Json &state, + const std::string &folder, const std::string &query) { + if (!valid_demo_news(state) || (folder != "inbox" && folder != "archive") || + query.size() > 120) + return {{"ok", false}, {"error", "invalid_news_view"}}; + 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]; + manager = m.value("name", ""); + club_id = m.value("club", ""); + if (const auto *c = world.find("clubs", club_id)) + club_name = world.name(*c); + } + const auto resolve = [&](const std::string &v) { + return news_replace(news_replace(v, "{{club}}", club_name), "{{manager}}", + manager); + }; + Json shown = Json::array(), counts = {{"inbox", 0}, {"archive", 0}}; + bool can_read = false; + for (auto m : state.at("news").at("items")) { + const auto location = m.at("folder").get(); + if (location == "trash") + continue; + counts[location] = counts.at(location).get() + 1; + if (location != folder) + continue; + if (!m.at("read").get()) + can_read = true; + m["title"] = resolve(m.at("title").get()); + m["body"] = resolve(m.at("body").get()); + m["category"] = news_category(m.at("kind").get()); + m["display_date"] = news_display_date(m.at("date").get()); + const auto haystack = news_fold(m.at("title").get() + " " + + m.at("body").get() + " " + + m.at("category").get() + " " + + m.at("display_date").get()); + if (query.empty() || haystack.find(news_fold(query)) != haystack.npos) + shown.push_back(std::move(m)); + } + std::stable_sort(shown.begin(), shown.end(), + [](const auto &a, const auto &b) { + return a.at("date").template get() > + b.at("date").template get(); + }); + int unread = 0; + for (const auto &m : shown) + if (!m.at("read").get()) + ++unread; + return {{"ok", true}, + {"fictional", true}, + {"items", shown}, + {"counts", counts}, + {"unread", demo_news_unread(state)}, + {"shown_unread", unread}, + {"can_read", can_read}, + {"club", club_id}, + {"club_name", club_name}, + {"manager", manager}, + {"date", news_display_date(state.value("date", std::string()))}}; +} +} // namespace bmh::modern_ui diff --git a/src/modern/ui/demo_news.hpp b/src/modern/ui/demo_news.hpp new file mode 100644 index 0000000..1c4da7d --- /dev/null +++ b/src/modern/ui/demo_news.hpp @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-3.0-only +#pragma once +#include "modern/ui/catalog.hpp" + +namespace bmh::modern_ui { +// Presentation-only journal. Templates remain persisted, then resolve against +// the current snapshot's first manager/club. No catalogue or engine mutation. +Json demo_news(const Catalog &, const Json &full_state); +bool valid_demo_news(const Json &full_state); +bool migrate_demo_news(Json &full_state, const Catalog &); +// read{id}, read-all{folder}, move{id,folder}, undo{patch:[{id,before,after}]}. +// Patches contain only {read,folder}; every expected after-value must match. +// The DataSource owns the outer revision check and atomic publication. +std::string edit_demo_news(Json &full_state, const Json &action, + const Catalog &); +int demo_news_unread(const Json &full_state); +// Read-only projection: counts, unread, shown items, can_read, club, manager, +// date. Query and folder belong to the view and never enter a checkpoint. +Json demo_news_view(const Catalog &, const Json &full_state, + const std::string &folder = "inbox", + const std::string &query = {}); +std::string news_display_date(const std::string &); +} // namespace bmh::modern_ui diff --git a/src/modern/ui/demo_statistics.cpp b/src/modern/ui/demo_statistics.cpp new file mode 100644 index 0000000..39cb992 --- /dev/null +++ b/src/modern/ui/demo_statistics.cpp @@ -0,0 +1,242 @@ +// SPDX-License-Identifier: GPL-3.0-only +#include "modern/ui/demo_statistics.hpp" +#include +#include +#include +#include +#include +#include + +namespace bmh::modern_ui { +namespace { +const std::array sections{"Möglichkeiten","Transferhistorie","Analytics","Ewige Tabelle","WM-Statistiken","Saisonfinanzen","Serien u. Rekorde","Sieger","Minuten-Statistik"}; +const std::array views{"Sieger","Gruppen","Torschützen","Finalrunde","Tabelle","Historie"}; +const std::array curves{"Kontostand","Mannschaftsstärke","Zuschauer","Stimmung","Einnahmen","Ausgaben"}; +const std::array colors{"#e3da6a","#79b5c8","#a9d67b","#e58a66","#ded9bd","#b295cd"}; +const std::array,12> domestic{{{{0,0,1}},{{1,3,1}},{{3,1,3}},{{2,4,1}},{{1,1,4}},{{0,2,0}},{{3,3,1}},{{1,5,1}},{{2,1,2}},{{1,1,0}},{{3,0,3}},{{4,2,1}}}}; +const Json &field(const Json &value,const char *key) { + static const Json missing; + if(value.is_object())if(const auto i=value.find(key);i!=value.end())return *i; + return missing; +} +std::string string(const Json &value,const std::string &fallback="") { + return value.is_string()?value.get():fallback; +} +std::optional season_year(const Json &value) { + if(!value.is_string())return {}; + const auto d=value.get(); + if(d.size()!=10||d[4]!='-'||d[7]!='-')return {}; + for(size_t i=0;i'9'))return {}; + const int y=std::stoi(d.substr(0,4)),m=std::stoi(d.substr(5,2)),day=std::stoi(d.substr(8,2)); + if(!std::chrono::year_month_day{std::chrono::year{y},std::chrono::month{unsigned(m)},std::chrono::day{unsigned(day)}}.ok())return {}; + return y-(m<7?1:0); +} +std::string season(int year) { + auto end=std::to_string((year+1)%100); + return std::to_string(year)+"/"+(end.size()<2?"0":"")+end; +} +Json cell(const std::string &text) {return {{"text",text}};} +Json numeric(int value) {return {{"text",std::to_string(value)},{"value",value}};} +Json club_cell(const Catalog &world,const Json *club) { + if(!club)return cell("—"); + return {{"text",world.name(*club)},{"club",club->at("id")}}; +} +Json nation_cell(const Catalog &world,const Json *nation) { + return nation?Json{{"text",world.name(*nation)},{"nation",nation->at("id")}}:cell("—"); +} +Json player_cell(const Catalog &world,const Json *player) { + return player?Json{{"text",world.name(*player)},{"player",player->at("id")},{"club",player->value("team","")}}:cell("—"); +} +void headings(Json &out,std::initializer_list names) { + for(const auto *name:names)out["columns"].push_back({{"text",name}}); +} +void row(Json &out,Json cells) {out["rows"].push_back({{"cells",std::move(cells)}});} +const Json *country_nation(const Catalog &world, const std::string &code) { + if (const auto *nation = world.find("nations", "nation:" + code)) + return nation; + // England has no ISO alpha-2 country of its own. OBW retains the stable + // imported football-nation identity instead of replacing it with the UK. + if (code == "en") + for (const auto *id : {"nation:x-eng", "nation:eng"}) + if (const auto *nation = world.find("nations", id)) return nation; + return nullptr; +} +std::string statistics_country_code(const Json *nation) { + if (!nation) return {}; + const auto id = nation->value("id", ""); + const auto code = id.starts_with("nation:") ? id.substr(7) : id; + return code == "x-eng" || code == "eng" ? "en" : code; +} +std::vector countries(const Catalog &world) { + std::vector result; + std::set seen; + // Match Gold's fixed domestic ordering; retain actual IDs and captions. + for(const auto *code:{"de","es","it","fr","en"}) + if(const auto *nation=country_nation(world,code);nation&&!world.leagues(nation->at("id").get()).empty()) { + result.push_back(nation);seen.insert(nation->at("id").get()); + } + for(const auto *league:world.leagues()) { + const auto id=league->value("nation",""); + if(const auto *nation=world.find("nations",id);nation&&seen.insert(id).second)result.push_back(nation); + } + return result; +} +std::vector first_league_clubs(const Catalog &world,const Json *nation) { + if(!nation)return {}; + const auto leagues=world.leagues(nation->at("id").get()); + if(leagues.empty())return {}; + // Catalog order is canonical; lower-tier competitions are never mixed in. + const Json *first=leagues.front(); + for(const auto *league:leagues)if(league->value("tier",1)value("tier",1))first=league; + return world.clubs(first->at("id").get()); +} +const Json *at(const std::vector &items,size_t index) { + return items.empty()?nullptr:items[index%items.size()]; +} +} // namespace + +Json demo_statistics(const Catalog &world,const Json &state,const Json &request) { + const auto reject=[](const std::string &error){return Json{{"ok",false},{"fictional",true},{"error",error}};}; + if(!request.is_object())return reject("invalid_statistics_request"); + for(const auto &[key,value]:request.items())if(key!="section"&&key!="category"&&key!="country"&&key!="winner_country"&&key!="absolute"&&key!="curves")return reject("unknown_statistics_filter"); + const auto integer=[&](const char *key,int fallback,int maximum)->std::optional{ + if(!request.contains(key))return fallback; + const auto &v=request.at(key); + if(!v.is_number_integer()||v<0||v>maximum)return {}; + return v.get(); + }; + const auto section=integer("section",7,8),category=integer("category",0,5),country=integer("country",0,5); + if(!section||!category||!country||(*category!=0&&*category!=1&&*category!=5))return reject("invalid_statistics_filter"); + if(request.contains("absolute")&&!request.at("absolute").is_boolean())return reject("invalid_statistics_absolute"); + Json active=Json::array({true,true,true,true,true,true}); + if(request.contains("curves")) { + const auto &value=request.at("curves"); + if(!value.is_array()||value.size()!=6||!std::all_of(value.begin(),value.end(),[](const Json &v){return v.is_boolean();}))return reject("invalid_statistics_curves"); + active=value; + } + const auto nations=countries(world); + const auto winner=request.contains("winner_country")?string(request.at("winner_country")):nations.empty()?"":nations.front()->at("id").get(); + if(request.contains("winner_country")&&(!request.at("winner_country").is_string()||std::none_of(nations.begin(),nations.end(),[&](const Json *n){return n->at("id")==winner;})))return reject("invalid_statistics_country"); + 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; + } + 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); + Json out={{"ok",true},{"fictional",true},{"available",true},{"section",*section},{"category",*category},{"country",*country},{"winner_country",winner},{"absolute",absolute},{"curves",active},{"title",sections[size_t(*section)]},{"season",season(year)},{"previous_season",season(year-1)},{"year",year},{"manager",manager_name},{"club",own?own->at("id"):Json()},{"columns",Json::array()},{"rows",Json::array()},{"countries",Json::array()},{"sections",sections},{"world_views",views},{"series",Json::array()}}; + for(const auto *n:nations)out["countries"].push_back({{"id",n->at("id")},{"name",world.name(*n)}}); + out["eternal_countries"] = Json::array(); + const std::array eternal_codes{"de", "es", "en", "fr", "it"}; + for (size_t i = 0; i < eternal_codes.size(); ++i) + if (const auto *n = country_nation(world, eternal_codes[i])) + out["eternal_countries"].push_back({{"value", i}, {"nation", n->at("id")}, {"name", world.name(*n)}}); + out["eternal_countries"].push_back({{"value", 5}, {"name", "Absolut"}}); + auto own_league=own?world.clubs(own->value("competition","")):std::vector{}; + if(own&&own_league.empty())own_league.push_back(own); + if(!own&& !nations.empty())own_league=first_league_clubs(world,nations.front()); + // Gold uses one German/own-league cohort for possibilities and records. + const auto clubs=own_league; + const auto players=own?world.squad(own->at("id").get()):std::vector{}; + if(*section==0) { + headings(out,{"Verein","Meisterschaft","Pokal","Europapokal"}); + for(size_t i=0;i ns; + for(const auto *code:{"de","es","fr","it","en","nl","pt","be"})if(const auto *n=country_nation(world,code))ns.push_back(n); + for(const auto &n:world.rows("nations"))if(ns.size()<8&&std::find(ns.begin(),ns.end(),&n)==ns.end())ns.push_back(&n); + if(*country==0||*country==5) { + headings(out,{"WM / EM","Sieger","Finalist","Finale"}); + for(size_t i=0;iat("id");tournament["season"]=std::to_string(year-1-int(i)*2); + row(out,Json::array({tournament,nation_cell(world,ns[i]),nation_cell(world,at(ns,i+1)),cell(std::to_string(i%3+1)+":"+std::to_string(i%2))})); + } + } else if(*country==1) { + headings(out,{"Gruppe","Mannschaft","Spiele","Punkte"}); + for(size_t i=0;i rounds{"Finale","Halbfinale","Halbfinale","Viertelfinale"}; + for(size_t i=0;i names{"Ungeschlagen","Siege in Folge","Heimsiege","Auswärtssiege","Tore in einer Saison","Höchster Sieg","Längste Torserie","Meiste Zuschauer"}; + for(size_t i=0;i titles,trophies; + if(*category==0) { + if(code=="es"){titles={"Primera División","Copa del Rey","Supercopa"};trophies={"es-la-liga","es-copa-del-rey",""};} + else if(code=="en"){titles={"Premier League","FA Cup","League Cup"};trophies={"en-premier-league","en-fa-cup",""};} + else if(code=="fr"){titles={"Ligue 1","Coupe de France","Trophée des Champions"};trophies={"fr-ligue-1","fr-coupe-de-france",""};} + else if(code=="it"){titles={"Serie A","Coppa Italia","Supercoppa"};trophies={"it-serie-a","it-coppa-italia",""};} + else {titles={"Meisterschaft","DFB-Pokal","Supercup"};trophies={"championship","dfb-cup","supercup"};} + out["note"]=(nation?world.name(*nation):"—")+" · Titelträger im Saisonvergleich"; + } else if(*category==1){titles={"Champions League","Pokalsieger","UEFA-Cup"};trophies={"champions-league","cup-winners","uefa-cup"};out["note"]="Europäische Titelträger im Saisonvergleich";} + else {titles={"Sieger","Finalist"};trophies={"indoor-masters",""};out["note"]="Hallenmasters · Sieger und Finalisten";} + headings(out,{"Saison"}); + std::vector international; + const std::array preferred{"club:es-real-madrid","club:en-manchester-city","club:it-ac-mailand","club:es-fc-barcelona","club:en-liverpool","club:de-bayern-muenchen","club:fr-paris-saint-germain","club:it-inter-mailand","club:de-borussia-dortmund","club:en-chelsea","club:it-juventus-turin","club:es-fc-sevilla"}; + for(const auto *id:preferred)if(const auto *club=world.find("clubs",id))international.push_back(club); + if(international.empty())for(size_t i=0;i<12;++i) { + if(nations.empty())break; + const auto candidates=first_league_clubs(world,nations[i%nations.size()]); + if(const auto *club=at(candidates,i/nations.size()))if(std::find(international.begin(),international.end(),club)==international.end())international.push_back(club); + } + for(size_t col=0;colat("id"):Json(); + } + row(out,std::move(cells)); + } + } else { + headings(out,{"Ereignis"});for(int i=0;i<18;++i)out["columns"].push_back(cell(std::to_string(i*5)+".")); + const std::array names{"Tore","Chancen","Gelb","Rot"}; + if(own)for(int k=0;k<4;++k) { + Json cells=Json::array({cell(names[size_t(k)])}); + for(int i=0;i<18;++i){auto c=numeric((i*3+k)%13);c["tone"]=(i+k)%5==0?"bad":(i+k)%3==0?"good":"";cells.push_back(c);} + row(out,std::move(cells)); + } + } + out["available"]=*section==2?!clubs.empty():!out["rows"].empty(); + return out; +} +} // namespace bmh::modern_ui diff --git a/src/modern/ui/demo_statistics.hpp b/src/modern/ui/demo_statistics.hpp new file mode 100644 index 0000000..afc5792 --- /dev/null +++ b/src/modern/ui/demo_statistics.hpp @@ -0,0 +1,13 @@ +// SPDX-License-Identifier: GPL-3.0-only +#pragma once +#include "modern/ui/catalog.hpp" + +namespace bmh::modern_ui { +// Deterministic, presentation-only statistics. Request: section 0..8 (default +// 7), category 0/1/5, country 0..5, winner_country an actual nation ID, +// absolute boolean and curves an array of six booleans. No state is mutated. +// Table cells carry text and optional actual club/player/nation references. +// Unknown fields, malformed filters and unavailable countries are rejected. +Json demo_statistics(const Catalog &, const Json &full_state, + const Json &request = Json::object()); +} // namespace bmh::modern_ui diff --git a/src/modern/ui/model.cpp b/src/modern/ui/model.cpp index 75ac2bd..f5166b4 100644 --- a/src/modern/ui/model.cpp +++ b/src/modern/ui/model.cpp @@ -11,6 +11,8 @@ #include "modern/ui/demo_lineup.hpp" #include "modern/ui/demo_transfer.hpp" #include "modern/ui/demo_stadium.hpp" +#include "modern/ui/demo_statistics.hpp" +#include "modern/ui/demo_news.hpp" #include "modern/ui/desktop.hpp" #include #include @@ -99,18 +101,27 @@ DemoSource::DemoSource(std::shared_ptr catalog) throw editor::Error("invalid_demo_squad"); if (!migrate_demo_stadium(state_, *catalog_, club)) throw editor::Error("invalid_demo_stadium"); + if (!migrate_demo_news(state_, *catalog_)) + throw editor::Error("invalid_demo_news"); saved_ = state_; } Snapshot DemoSource::snapshot() const { return {revision_, catalog_, state_}; } Json DemoSource::read_almanac(const Json &request) const { return query_demo_almanac(almanac_, request, state_.at("date")); } +Json DemoSource::read_statistics(const Json &request) const { + return demo_statistics(*catalog_, state_, request); +} ActionResult DemoSource::apply(const Action &action) { if (action.revision != revision_) return {false, revision_, "stale_revision"}; auto next = state_; try { - if (action.kind == "ticket") { + if (action.kind == "news") { + const auto error = edit_demo_news(next, action.value, *catalog_); + if (!error.empty()) + return {false, revision_, error}; + } else if (action.kind == "ticket") { if (!action.value.is_number_integer() || action.value < 0 || action.value > 25) return {false, revision_, "invalid_demo_ticket"}; @@ -289,6 +300,8 @@ Json DemoSource::load(const fs::path &file) { throw editor::Error("invalid_demo_squad"); if (!migrate_demo_stadium(data, *catalog_, club)) throw editor::Error("invalid_demo_stadium"); + if (!migrate_demo_news(data, *catalog_)) + throw editor::Error("invalid_demo_news"); auto next = data; auto desktop = next.value("desktop", Json::object()); if (!migrate_desktop(desktop)) diff --git a/src/modern/ui/model.hpp b/src/modern/ui/model.hpp index d596641..b23ba61 100644 --- a/src/modern/ui/model.hpp +++ b/src/modern/ui/model.hpp @@ -29,6 +29,9 @@ public: virtual Json read_almanac(const Json &) const { return {{"ok", false}, {"error", "almanac_unavailable"}}; } + virtual Json read_statistics(const Json &) const { + return {{"ok", false}, {"error", "statistics_unavailable"}}; + } }; class DemoSource final : public DataSource { public: @@ -36,6 +39,7 @@ public: Snapshot snapshot() const override; ActionResult apply(const Action &) override; Json read_almanac(const Json &) const override; + Json read_statistics(const Json &) const override; void save(const fs::path &, const Json &desktop); Json load(const fs::path &); bool dirty() const { return state_ != saved_; } diff --git a/src/modern/ui/news_controls.inc b/src/modern/ui/news_controls.inc new file mode 100644 index 0000000..9d0ae96 --- /dev/null +++ b/src/modern/ui/news_controls.inc @@ -0,0 +1,301 @@ +// SPDX-License-Identifier: GPL-3.0-only +void App::reset_news(bool preserve_view) { + if (!preserve_view) { + news_view_ = {{"folder", "inbox"}, {"query", ""}, {"feedback", ""}}; + news_world_.reset(); + news_source_ = nullptr; + } else + news_view_["feedback"] = ""; + news_dialog_.clear(); + news_return_focus_.clear(); + news_undo_ = Json(); + news_undo_revision_ = 0; + news_scroll_ = 0; + news_restore_scroll_ = false; +} +void App::news_before_render() { + if (menu_ != "news") { + if (last_rendered_menu_ == "news") + reset_news(true); + return; + } + if (last_rendered_menu_ != "news") + return; + if (auto *feed = element("news-feed")) + news_scroll_ = feed->GetScrollTop(); + news_restore_scroll_ = true; + if (focus_after_render_.empty()) { + if (auto *focused = context_->GetFocusElement(); + focused && (focused->GetId().starts_with("news-") || + focused->GetId() == "window-close")) + focus_after_render_ = focused->GetId(); + } +} +void App::news_after_render() { + if (menu_ != "news") + return; + context_->Update(); + if (news_restore_scroll_) { + if (auto *feed = element("news-feed")) + feed->SetScrollTop(news_scroll_); + news_restore_scroll_ = false; + } + if (!news_dialog_.empty()) { + Rml::ElementList nodes; + doc_->QuerySelectorAll(nodes, "#news-underlay button,#news-underlay " + "input,.news-tablet>.titlebar button"); + for (auto *node : nodes) { + node->SetProperty("pointer-events", "none"); + node->SetProperty("tab-index", "none"); + } + } +} +void App::news_update_feed() { + const auto s = snap(); + const auto data = + demo_news_view(*s.world, s.state, news_view_.value("folder", "inbox"), + news_view_.value("query", "")); + if (!data.value("ok", false)) + return; + if (auto *feed = element("news-feed")) { + feed->SetInnerRML(render_news_feed(data)); + context_->Update(); + feed->SetScrollTop(0); + news_scroll_ = 0; + } + if (auto *feedback = element("news-feedback")) + feedback->SetInnerRML(esc( + std::to_string(data.at("items").size()) + + (data.at("items").size() == 1 ? " Nachricht" : " Nachrichten") + " · " + + std::to_string(data.at("shown_unread").get()) + " ungelesen")); + dirty_ = true; +} +bool App::news_commit(const Json &action, const std::string &feedback, + bool remember) { + const auto before = snap(); + const auto result = source_->apply({before.revision, "news", action}); + if (!result.ok) { + news_view_["feedback"] = + "Änderung nicht gespeichert. Bitte erneut versuchen."; + refresh(); + return false; + } + const auto after = snap(); + if (remember) { + Json patch = Json::array(); + for (const auto &old : before.state.at("news").at("items")) { + const auto &items = after.state.at("news").at("items"); + const auto found = + std::find_if(items.begin(), items.end(), [&](const auto &m) { + return m.at("id") == old.at("id"); + }); + if (found != items.end() && (old.at("read") != found->at("read") || + old.at("folder") != found->at("folder"))) + patch.push_back( + {{"id", old.at("id")}, + {"before", + {{"read", old.at("read")}, {"folder", old.at("folder")}}}, + {"after", + {{"read", found->at("read")}, {"folder", found->at("folder")}}}}); + } + if (!patch.empty()) + news_undo_ = std::move(patch); + } + // An article read can leave a prior undo patch usable. Its compare-before + // guard still rejects a changed record, while the current revision binds UI. + news_undo_revision_ = after.revision; + news_view_["feedback"] = feedback; + refresh(); + return true; +} +bool App::dispatch_news(const std::string &action, Rml::Element *target) { + if (!action.starts_with("news-")) + return false; + if (menu_ != "news" || !popup_.empty() || amount_) + return true; + const auto id = + target ? target->GetAttribute("data-id", "") : std::string(); + if (action == "news-detail-close") { + news_dialog_.clear(); + focus_after_render_ = + news_return_focus_.empty() + ? "news-tab-" + news_view_.value("folder", "inbox") + : news_return_focus_; + news_return_focus_.clear(); + refresh(); + return true; + } + if (!news_dialog_.empty() && action != "news-detail-move") + return true; + if (action == "news-folder") { + if (id != "inbox" && id != "archive") + return true; + news_view_["folder"] = id; + news_view_["query"] = ""; + news_view_["feedback"] = ""; + news_scroll_ = 0; + if (auto *feed = element("news-feed")) + feed->SetScrollTop(0); + focus_after_render_ = "news-tab-" + id; + refresh(); + return true; + } + const auto before = snap(); + if (action == "news-undo") { + if (!news_undo_.is_array() || news_undo_.empty()) + return true; + if (news_world_ != before.world || news_source_ != source_.get() || + news_undo_revision_ != before.revision) { + news_undo_ = Json(); + news_view_["feedback"] = "Die Nachricht wurde inzwischen geändert. " + "Rückgängig ist nicht mehr möglich."; + focus_after_render_ = "news-tab-" + news_view_.value("folder", "inbox"); + refresh(); + return true; + } + if (news_commit({{"kind", "undo"}, {"patch", news_undo_}}, + "Letzte Änderung rückgängig gemacht.", false)) + news_undo_ = Json(); + focus_after_render_ = "news-tab-" + news_view_.value("folder", "inbox"); + return true; + } + if (action == "news-read-all") { + const auto folder = news_view_.value("folder", "inbox"); + news_commit( + {{"kind", "read-all"}, {"folder", folder}}, + "Alle Nachrichten " + + std::string(folder == "inbox" ? "im Postfach" : "im Archiv") + + " als gelesen markiert."); + focus_after_render_ = "news-tab-" + folder; + return true; + } + const auto requested = action == "news-detail-move" ? news_dialog_ : id; + const auto &items = before.state.at("news").at("items"); + const auto found = + std::find_if(items.begin(), items.end(), [&](const auto &m) { + return m.at("id") == requested && m.at("folder") != "trash"; + }); + if (found == items.end()) + return true; + if (action == "news-open") { + if (!found->at("read").get() && + !news_commit({{"kind", "read"}, {"id", requested}}, "", false)) + return true; + news_dialog_ = requested; + news_return_focus_ = "news-read-" + requested; + focus_after_render_ = "news-detail-close"; + refresh(); + return true; + } + if (action == "news-move" || action == "news-delete" || + action == "news-detail-move") { + const auto folder = action == "news-delete" ? "trash" + : found->at("folder") == "archive" ? "inbox" + : "archive"; + const auto feedback = std::string(folder) == "trash" ? "Nachricht gelöscht." + : std::string(folder) == "inbox" + ? "Ins Postfach verschoben." + : "Nachricht archiviert."; + if (news_commit({{"kind", "move"}, {"id", requested}, {"folder", folder}}, + feedback)) { + news_dialog_.clear(); + news_return_focus_.clear(); + focus_after_render_ = "news-tab-" + news_view_.value("folder", "inbox"); + } + return true; + } + return true; +} +bool App::news_event(Rml::Event &event) { + if (menu_ != "news" || !popup_.empty() || amount_) + return false; + const auto type = event.GetType(); + auto *target = event.GetTargetElement(); + const auto key = type == "keydown" + ? Rml::Input::KeyIdentifier( + event.GetParameter("key_identifier", 0)) + : Rml::Input::KI_UNKNOWN; + if (!news_dialog_.empty()) { + if (key == Rml::Input::KI_ESCAPE || + (type == "mouseup" && event.GetParameter("button", 0) == 1)) { + dispatch_news("news-detail-close", nullptr); + event.StopImmediatePropagation(); + return true; + } + bool inside = false; + for (auto *n = target; n && n != doc_; n = n->GetParentNode()) + if (n->GetId() == "news-detail-layer") + inside = true; + if (!inside && (type == "click" || type == "dblclick" || + type == "mousedown" || type == "mouseup" || + (type == "keydown" && key != Rml::Input::KI_TAB))) { + event.StopImmediatePropagation(); + return true; + } + } + if ((type == "input" || type == "change") && target && + target->GetId() == "news-search" && news_dialog_.empty()) { + if (auto *input = dynamic_cast(target)) { + auto query = input->GetValue(); + if (query.size() > 120) + query.resize(120); + news_view_["query"] = query; + news_view_["feedback"] = ""; + news_update_feed(); + } + event.StopImmediatePropagation(); + return true; + } + if (type == "keydown" && news_dialog_.empty() && target && + target->GetId().starts_with("news-tab-") && + (key == Rml::Input::KI_LEFT || key == Rml::Input::KI_RIGHT || + key == Rml::Input::KI_HOME || key == Rml::Input::KI_END)) { + const auto next = key == Rml::Input::KI_HOME ? "inbox" + : key == Rml::Input::KI_END ? "archive" + : news_view_.value("folder", "inbox") == "inbox" + ? "archive" + : "inbox"; + dispatch_news("news-folder", element("news-tab-" + std::string(next))); + event.StopImmediatePropagation(); + return true; + } + if (key == Rml::Input::KI_TAB) { + Rml::ElementList controls; + if (auto *root = element(news_dialog_.empty() ? "news-underlay" + : "news-detail-layer")) + root->QuerySelectorAll(controls, "button,input"); + if (news_dialog_.empty()) + if (auto *close = element("window-close")) + controls.insert(controls.begin(), close); + controls.erase( + std::remove_if(controls.begin(), controls.end(), + [](auto *n) { + return !n->IsVisible(true) || + n->HasAttribute("disabled") || + n->template GetAttribute( + "tabindex", "") == "-1"; + }), + controls.end()); + if (!controls.empty()) { + const bool backwards = event.GetParameter("shift_key", 0) != 0; + const auto it = std::find(controls.begin(), controls.end(), + context_->GetFocusElement()); + const int old = it == controls.end() ? (backwards ? 0 : -1) + : int(it - controls.begin()); + auto *next = + controls[size_t((old + (backwards ? -1 : 1) + int(controls.size())) % + int(controls.size()))]; + next->Focus(true); + for (auto *n = next; n && n != doc_; n = n->GetParentNode()) + if (n->GetId().starts_with("news-row-")) { + n->ScrollIntoView( + Rml::ScrollIntoViewOptions(Rml::ScrollAlignment::Nearest)); + break; + } + } + event.StopImmediatePropagation(); + dirty_ = true; + return true; + } + return false; +} diff --git a/src/modern/ui/news_screens.inc b/src/modern/ui/news_screens.inc new file mode 100644 index 0000000..1bcf806 --- /dev/null +++ b/src/modern/ui/news_screens.inc @@ -0,0 +1,236 @@ +// SPDX-License-Identifier: GPL-3.0-only +std::string App::render_news_art(const Json &message, double size) { + const auto kind = message.at("kind").get(); + std::string art; + if (kind == "club") + art = crest(club(snap()), size * .69); + else { + const auto key = + kind == "fixture" ? "button.league" + : kind == "transfer" ? "button.contracts" + : kind == "finance" + ? (gui_.contains("news.cash") ? "news.cash" : "icon.coins") + : kind == "training" ? "button.training" + : "button.stadium"; + art = img(key, size * .76, size * .76, false, false, 256); + } + return "
" + art + "
"; +} +std::string App::render_news_feed(const Json &data) { + std::string out; + for (const auto &m : data.at("items")) { + const auto id = m.at("id").get(), + name = m.at("title").get(); + const bool unread = !m.at("read").get(), + archived = m.at("folder") == "archive"; + out += "
"; + if (unread) + out += ""; + out += render_news_art(m) + + "
" + + esc(m.at("display_date").get()) + + "" + + esc(m.at("category").get()) + "" + + (unread ? "Neu" : "") + "
"; + out += btn("news-open", esc(name), "news-message-title", + "id=\"news-read-" + id + "\" data-id=\"" + id + + "\" aria-label=\"Nachricht lesen: " + esc(name) + "\""); + out += "

" + esc(m.at("body").get()) + + "

"; + // Native CSS line-art has no private bitmap or SVG dependency. + out += btn( + "news-move", + "", + "news-icon-button", + "id=\"news-move-" + id + "\" data-id=\"" + id + "\" aria-label=\"" + + std::string(archived ? "Ins Postfach verschieben: " + : "Archivieren: ") + + esc(name) + "\" title=\"" + + std::string(archived ? "Ins Postfach verschieben" : "Archivieren") + + "\""); + out += btn("news-delete", glyph("trash", 36), "news-icon-button", + "id=\"news-delete-" + id + "\" data-id=\"" + id + + "\" aria-label=\"Löschen: " + esc(name) + + "\" title=\"Löschen\""); + out += "
"; + } + if (out.empty()) { + const bool query = !news_view_.value("query", "").empty(), + archive = news_view_.value("folder", "inbox") == "archive"; + out = "

" + + std::string(query ? "Keine Nachrichten gefunden" + : archive ? "Dein Archiv ist noch leer" + : "Alles auf dem neuesten Stand") + + "

" + + std::string( + query ? "Versuche einen anderen Suchbegriff." + : archive ? "Archivierte Meldungen bleiben hier zum Nachlesen." + : "Hier erscheinen neue Meldungen aus deinem Verein.") + + "

"; + } + return out; +} +std::string App::render_news_detail(const Json &message) { + const auto name = message.at("title").get(); + return "

" + + esc(name) + + "

" + + render_news_art(message) + "

" + + esc(message.at("category").get()) + "

" + + esc(message.at("display_date").get()) + + "

" + + esc(message.at("body").get()) + + "

Fiktive Meldung für den " + "Oberflächen-Prototyp.
" + + btn("news-detail-close", "Schließen", {}, "id=\"news-detail-close\"") + + btn("news-detail-move", + message.at("folder") == "archive" ? "Ins Postfach" : "Archivieren", + {}, "id=\"news-detail-move\"") + + "
"; +} +std::string App::render_news() { + const auto s = snap(); + if (news_world_ != s.world || news_source_ != source_.get()) { + reset_news(); + news_world_ = s.world; + news_source_ = source_.get(); + } + const auto data = + demo_news_view(*s.world, s.state, news_view_.value("folder", "inbox"), + news_view_.value("query", "")); + if (!data.value("ok", false)) + return window("Nachrichten", + "

Das Nachrichtenpostfach ist nicht verfügbar.

"); + const auto folder = news_view_.value("folder", "inbox"); + std::string content = + "
kicker

DEIN " + "VEREINSJOURNAL

Nachrichten

" + + esc(data.at("club_name").get()) + "

" + + esc(data.at("date").get()) + "

" + + crest(club(s), 88) + "
"; + content += "
"; + for (const auto &f : {std::string("inbox"), std::string("archive")}) + content += + btn("news-folder", + "" + std::string(f == "inbox" ? "Postfach" : "Archiv") + + "" + + std::to_string(data.at("counts").at(f).get()) + "", + std::string("news-tab ") + (folder == f ? "active" : ""), + "id=\"news-tab-" + f + "\" data-id=\"" + f + + "\" role=\"tab\" aria-controls=\"news-feed\" aria-selected=\"" + + (folder == f ? "true" : "false") + "\" tabindex=\"" + + (folder == f ? "0" : "-1") + "\""); + content += "
"; + content += + btn("news-read-all", glyph("check", 36) + "Alle gelesen", + "news-read-all", + "id=\"news-read-all\" " + + std::string(data.at("can_read").get() ? "" : "disabled")); + content += "
" + render_news_feed(data) + + "

"; + const auto feedback = news_view_.value("feedback", ""); + content += esc( + feedback.empty() + ? std::to_string(data.at("items").size()) + + (data.at("items").size() == 1 ? " Nachricht" : " Nachrichten") + + " · " + std::to_string(data.at("shown_unread").get()) + + " ungelesen" + : feedback); + content += + "

" + + btn("news-undo", + glyph("undo", 32) + "Rückgängig", + "news-undo", + "id=\"news-undo\" style=\"display:" + + std::string(news_undo_.is_array() && !news_undo_.empty() + ? "flex" + : "none") + + ";\"") + + "
"; + if (!news_dialog_.empty()) { + const auto all = demo_news_view(*s.world, s.state, folder, ""); + const auto &items = all.at("items"); + const auto found = + std::find_if(items.begin(), items.end(), + [&](const auto &m) { return m.at("id") == news_dialog_; }); + if (found != items.end()) + content += render_news_detail(*found); + else + news_dialog_.clear(); + } + return "
" + + btn("close", "×", "close", + "id=\"window-close\" aria-label=\"Fenster schließen\"") + + "

Nachrichten

" + content + + "
Fiktive " + "Vereinsmeldungen · Modern UI " + "DemoOpenBMH
"; +} + +std::string App::render_news_widget(const Json &object) { + const auto s = snap(); + const auto data = demo_news_view(*s.world, s.state, "inbox", ""); + if (!data.value("ok", false)) + return ""; + const bool small = + object.value("w", 472) <= 472 && object.value("h", 472) <= 472; + const int limit = small ? 2 : 3; + std::string out = + btn("open:news", + "Postfach · " + std::to_string(data.at("unread").get()) + + " ungelesen" + + glyph("arrow-diagonal", 26) + "", + "news-widget-heading", + "id=\"desktop-news-open\" data-interactive=\"true\" " + "aria-label=\"Nachrichten öffnen\""); + out += "
"; + int count = 0; + // Gold's widget uses source order, independently of the open tablet's folder, + // search and sorted list. Resolve templates through the same read projection. + for (const auto &raw : s.state.at("news").at("items")) { + if (raw.at("folder") != "inbox") + continue; + const auto &shown = data.at("items"); + const auto found = + std::find_if(shown.begin(), shown.end(), + [&](const auto &m) { return m.at("id") == raw.at("id"); }); + if (found == shown.end()) + continue; + out += "
at("read").get() ? "" : " unread") + + "\">
" + + esc(found->at("display_date").get()) + + "" + + esc(found->at("title").get()) + "
"; + if (++count == limit) + break; + } + return out + "
"; +} diff --git a/src/modern/ui/news_state.inc b/src/modern/ui/news_state.inc new file mode 100644 index 0000000..116ac3f --- /dev/null +++ b/src/modern/ui/news_state.inc @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-3.0-only +// Included within App: navigation is transient and has no save authority. +Json news_view_ = {{"folder", "inbox"}, {"query", ""}, {"feedback", ""}}; +std::string news_dialog_, news_return_focus_; +Json news_undo_; +uint64_t news_undo_revision_ = 0; +std::shared_ptr news_world_; +const DataSource *news_source_ = nullptr; +float news_scroll_ = 0.f; +bool news_restore_scroll_ = false; +std::string render_news(); +std::string render_news_widget(const Json &); +std::string render_news_feed(const Json &); +std::string render_news_art(const Json &, double size = 150); +std::string render_news_detail(const Json &); +bool dispatch_news(const std::string &, Rml::Element *); +bool news_event(Rml::Event &); +void reset_news(bool preserve_view = false); +void news_before_render(); +void news_after_render(); +void news_update_feed(); +bool news_commit(const Json &, const std::string &, bool remember = true); diff --git a/src/modern/ui/report_pickers.inc b/src/modern/ui/report_pickers.inc index be9575c..772b045 100644 --- a/src/modern/ui/report_pickers.inc +++ b/src/modern/ui/report_pickers.inc @@ -2,11 +2,12 @@ namespace { bool report_picker_menu(const std::string &menu) { return menu == "tables" || menu == "strengths" || menu == "league" || - menu == "other" || menu == "calendar" || menu == "friendlies" || menu == "almanac" || menu == "scorers"; + menu == "other" || menu == "calendar" || menu == "friendlies" || menu == "almanac" || menu == "scorers" || menu == "statistics"; } bool report_picker_kind(const std::string &kind) { return kind == "country" || kind == "league" || kind == "filter" || - kind == "competition" || kind == "year" || kind == "scorer-scope"; + kind == "competition" || kind == "year" || kind == "scorer-scope" || + kind == "stat-section" || kind == "stat-category" || kind == "stat-country" || kind == "winner-country"; } } // namespace @@ -15,6 +16,8 @@ App::report_picker_items(const std::string &kind) const { std::vector> items; if (!world_ || !report_picker_kind(kind)) return items; + if (menu_ == "statistics") + return statistics_picker_items(kind); if (kind == "scorer-scope") { if (menu_ == "scorers") items = {{"0", "Gesamte Liga"}, {"1", "Eigener Verein"}}; @@ -70,6 +73,8 @@ App::report_picker_items(const std::string &kind) const { std::string App::report_picker_value(const std::string &kind) const { if (!world_ || !report_picker_kind(kind)) return {}; + if (menu_ == "statistics") + return statistics_picker_value(kind); if (kind == "year") return std::to_string(almanac_year_); if (menu_ == "scorers") { if (kind == "scorer-scope") return std::to_string(rankings_view_.value("scope", 0)); @@ -104,7 +109,11 @@ std::string App::report_picker(const std::string &kind, double left, const bool open = report_picker_ == kind; const std::string menu_label = kind == "country" ? "Land" : kind == "league" ? "Liga" - : kind == "filter" ? "Spiele" : kind == "year" ? "Kalenderjahr" : kind == "scorer-scope" ? "Bereich" : "Wettbewerb"; + : kind == "filter" ? "Spiele" : kind == "year" ? "Kalenderjahr" : kind == "scorer-scope" ? "Bereich" + : kind == "stat-section" ? "Statistik" + : kind == "stat-category" ? "Wettbewerbsgruppe" + : kind == "winner-country" ? "Land" + : kind == "stat-country" ? "Statistikbereich" : "Wettbewerb"; std::string out = "
" + @@ -198,7 +207,9 @@ bool App::report_picker_action(const std::string &action, Rml::Element *target) ? Json(std::stoi(value)) : Json(value); close_report_picker(false); // Commit even an unchanged country: the Gold resets its first league. - if (kind == "year" && menu_ == "almanac") { + if (menu_ == "statistics") { + statistics_picker_select(kind, value); + } else if (kind == "year" && menu_ == "almanac") { almanac_year_ = std::stoi(value); almanac_day_.clear(); almanac_match_.clear(); diff --git a/src/modern/ui/screens.inc b/src/modern/ui/screens.inc index 06b94c7..441febf 100644 --- a/src/modern/ui/screens.inc +++ b/src/modern/ui/screens.inc @@ -154,9 +154,7 @@ std::string App::widget(const std::string &id, const Json &o) { "style=\"font-size:80dp;padding-top:85dp;\">" + std::to_string(s.state.value("fans", 67)) + " %

"; if (id == "news") - return heading("Nachrichten") + - "

Willkommen zur " - "neuen Saison.

"; + return render_news_widget(o); if (id == "results") return heading("Letzte sechs Spiele") + "
"; } std::string App::render_menu(const std::string &key) { + if (key == "news") + return "
" + render_news() + "
"; std::string body; if (key == "tables" || key == "strengths" || key == "league" || key == "other") body = render_reports(key); @@ -897,6 +897,8 @@ std::string App::render_menu(const std::string &key) { body = render_highscore(); else if (key == "stadium") body = render_stadium(); + else if (key == "statistics") + body = render_statistics(); else if (key == "environment") body = render_environment(); else if (key == "advertising") @@ -933,5 +935,6 @@ std::string App::render_menu(const std::string &key) { if (labels.contains(bank_view_)) heading += " · " + labels.at(bank_view_); } return "
" + - window(heading, body) + "
"; + window(heading, body) + + (key == "statistics" ? render_statistics_trophy() : "") + "
"; } diff --git a/src/modern/ui/statistics_controls.inc b/src/modern/ui/statistics_controls.inc new file mode 100644 index 0000000..3105225 --- /dev/null +++ b/src/modern/ui/statistics_controls.inc @@ -0,0 +1,79 @@ +// SPDX-License-Identifier: GPL-3.0-only +bool App::statistics_picker_select(const std::string &kind,const std::string &value) { + if(menu_!="statistics"||!source_||statistics_trophy_.contains("asset"))return false; + const auto items=statistics_picker_items(kind); + if(std::none_of(items.begin(),items.end(),[&](const auto &item){return item.first==value;}))return false; + statistics_remember_scroll(); + if(kind=="winner-country")statistics_view_["winner_country"]=value; + else { + const auto field=kind=="stat-section"?"section":kind=="stat-category"?"category":"country"; + statistics_view_[field]=std::stoi(value); + } + return true; +} +bool App::statistics_action(const std::string &action,Rml::Element *target) { + if(!action.starts_with("statistics-"))return false; + if(menu_!="statistics"||!source_)return true; + if(action=="statistics-trophy-close") { + if(statistics_trophy_.contains("asset")) { + focus_after_render_=statistics_trophy_.value("return_focus","");statistics_trophy_=Json::object();refresh(); + } + return true; + } + if(!target||statistics_trophy_.contains("asset")||!report_detail_kind_.empty()||!report_picker_.empty())return true; + const auto data=source_->read_statistics(statistics_view_); + if(!data.value("ok",false))return true; + statistics_remember_scroll(); + if(action=="statistics-absolute"&&data.at("section")==2)statistics_view_["absolute"]=!data.at("absolute").get(); + else if(action=="statistics-curve"&&data.at("section")==2) { + const int index=target->GetAttribute("data-index",-1);if(index<0||index>=6)return true; + auto curves=data.at("curves");curves[size_t(index)]=!curves[size_t(index)].get();statistics_view_["curves"]=curves; + } else if(action=="statistics-trophy") { + const int r=target->GetAttribute("data-row",-2),c=target->GetAttribute("data-column",-1); + if(c<0||c>=int(data.at("columns").size()))return true; + Json entry; + if(r==-1&&data.at("section")==7)entry=data.at("columns")[size_t(c)]; + else if(r>=0&&r(); + if(!world_||(!world_->find("clubs",winner)&&!world_->find("nations",winner)))return true; + const std::map captions{{"championship","Deutscher Meister"},{"dfb-cup","DFB-Pokalsieger"},{"supercup","Supercup-Sieger"},{"champions-league","Champions-League-Sieger"},{"cup-winners","Europapokalsieger"},{"uefa-cup","UEFA-Cup-Sieger"},{"world-cup","Weltmeister"},{"european-championship","Europameister"},{"indoor-masters","Hallenmasters-Sieger"},{"en-premier-league","Englischer Meister"},{"en-fa-cup","FA-Cup-Sieger"},{"fr-ligue-1","Französischer Meister"},{"fr-coupe-de-france","Coupe-de-France-Sieger"},{"it-serie-a","Italienischer Meister"},{"it-coppa-italia","Coppa-Italia-Sieger"},{"es-la-liga","Spanischer Meister"},{"es-copa-del-rey","Copa-del-Rey-Sieger"}}; + const auto title=captions.contains(trophy)?captions.at(trophy):entry.value("text","Sieger"); + statistics_trophy_={{"asset",asset},{"title",title},{"winner",winner},{"season",entry.value("season",data.value("previous_season",""))},{"return_focus",target->GetId()}}; + focus_after_render_="statistics-trophy-close"; + } else return true; + if(action!="statistics-trophy")focus_after_render_=target->GetId(); + refresh();return true; +} +bool App::statistics_event(Rml::Event &event) { + if(menu_!="statistics")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(statistics_trophy_.contains("asset")) { + if((keyboard&&key==Rml::Input::KI_ESCAPE)||(type=="mouseup"&&event.GetParameter("button",0)==1)) { + statistics_action("statistics-trophy-close",nullptr);event.StopImmediatePropagation();return true; + } + if(keyboard&&key==Rml::Input::KI_TAB) { + if(auto *close=element("statistics-trophy-close"))close->Focus(true); + event.StopImmediatePropagation();return true; + } + bool inside=false; + for(auto *node=event.GetTargetElement();node&&node!=doc_;node=node->GetParentNode())if(node->GetId()=="statistics-trophy-layer")inside=true; + if(!inside&&(type=="click"||type=="dblclick"||type=="mousedown"||type=="mouseup"||keyboard)) {event.StopImmediatePropagation();return true;} + return false; + } + if(!keyboard||key!=Rml::Input::KI_TAB||!report_detail_kind_.empty()||!report_picker_.empty())return false; + Rml::ElementList controls; + if(auto *canvas=element("canvas"))canvas->QuerySelectorAll(controls,".window button,.window input,.window select"); + std::erase_if(controls,[](auto *node){return !node->IsVisible(true)||node->HasAttribute("disabled");}); + if(!controls.empty()) { + const auto found=std::find(controls.begin(),controls.end(),context_->GetFocusElement()); + const int old=found==controls.end()?-1:int(found-controls.begin()),count=int(controls.size()); + const bool back=event.GetParameter("shift_key",0)!=0; + const int next=old<0?(back?count-1:0):(old+(back?-1:1)+count)%count; + controls[size_t(next)]->Focus(true);controls[size_t(next)]->ScrollIntoView({Rml::ScrollAlignment::Nearest});dirty_=true; + } + event.StopImmediatePropagation();return true; +} diff --git a/src/modern/ui/statistics_screens.inc b/src/modern/ui/statistics_screens.inc new file mode 100644 index 0000000..4f9a150 --- /dev/null +++ b/src/modern/ui/statistics_screens.inc @@ -0,0 +1,186 @@ +// SPDX-License-Identifier: GPL-3.0-only +namespace { +std::string statistics_text(const std::string &text) { + return ""+esc(text)+""; +} +std::string statistics_scroll_key(const Json &data) { + return std::to_string(data.value("section",7))+":"+std::to_string(data.value("category",0))+":"+std::to_string(data.value("country",0))+":"+data.value("winner_country",""); +} +} // namespace + +std::vector> App::statistics_picker_items(const std::string &kind) const { + std::vector> result; + if(!source_)return result; + const auto data=source_->read_statistics(statistics_view_); + if(!data.value("ok",false))return result; + const int section=data.at("section").get(); + if(kind=="stat-section") { + const auto &names=data.at("sections"); + for(size_t i=0;i()); + } else if(kind=="stat-category"&§ion==7)result={{"0","National"},{"1","International"},{"5","Hallenmasters"}}; + else if(kind=="winner-country"&§ion==7&&data.at("category")==0) { + for(const auto &nation:data.at("countries"))result.emplace_back(nation.at("id").get(),nation.at("name").get()); + } else if(kind=="stat-country"&§ion==3) { + for(const auto &nation:data.at("eternal_countries")) + result.emplace_back(std::to_string(nation.at("value").get()),nation.at("name").get()); + } else if(kind=="stat-country"&§ion==4) { + const auto &names=data.at("world_views"); + for(size_t i=0;i()); + } + return result; +} +std::string App::statistics_picker_value(const std::string &kind) const { + if(!source_)return {}; + const auto data=source_->read_statistics(statistics_view_); + if(!data.value("ok",false))return {}; + if(kind=="winner-country")return data.value("winner_country",""); + const auto key=kind=="stat-section"?"section":kind=="stat-category"?"category":"country"; + return std::to_string(data.value(key,0)); +} +void App::statistics_remember_scroll() { + if(auto *list=element("statistics-list")) { + const auto key=list->GetAttribute("data-scroll-key",""); + if(!key.empty())statistics_scrolls_[key]=list->GetScrollTop(); + } +} +void App::statistics_restore_scroll() { + if(menu_!="statistics"||!statistics_restore_pending_)return; + statistics_restore_pending_=false; + if(auto *list=element("statistics-list")) { + const auto key=list->GetAttribute("data-scroll-key",""); + if(const auto i=statistics_scrolls_.find(key);i!=statistics_scrolls_.end()&&i->is_number())list->SetScrollTop(i->get()); + } +} +std::string App::statistics_trophy_asset(const std::string &id) const { + if(id.empty())return {}; + // Competition pictures belong to world content. The deterministic demo uses + // semantic trophy roles; an engine adapter can supply a logical asset key. + // Fixed prototype artwork is only a fallback, never an OBW requirement. + if (world_) { + if (id.starts_with("asset:")) { + if (world_->find("assets", id)) return id; + if (world_->find("assets", "asset:comp/generic/trophy")) + return "asset:comp/generic/trophy"; + return {}; + } + const auto key = "asset:comp/" + id + "/trophy"; + if (world_->find("assets", key)) return key; + } + if(gui_.contains("trophy."+id))return "trophy."+id; + for(const auto &[key,item]:gui_.items().items()) { + if(!item.is_object())continue; + const auto file=item.value("file",""); + const auto base=fs::path(file).filename().string(); + if(base==id+"-v1.png"||base==id+"-v2.png")return key; + } + return {}; +} +std::string App::render_statistics() { + statistics_remember_scroll(); + if(!source_||!world_)return "

Statistiken sind nicht verfügbar.

"; + const auto data=source_->read_statistics(statistics_view_); + if(!data.value("ok",false))return "

Statistiken sind nicht verfügbar.

"; + const int section=data.at("section").get(),category=data.at("category").get(); + const bool winners=section==7,minutes=section==8,finals=section==4&&data.at("country")==3; + std::string out="

"+esc(data.at("title").get())+"

"; + if(winners)out+="

"+statistics_text(data.value("note",""))+"

"; + if(section==2) { + std::string svg=""; + const auto &series=data.at("series"); + for(const auto &curve:series)if(curve.at("active")==true) { + svg+=""; + } + svg+=""; + out+="
"+picture(renderer_.diagram("statistics-analytics",svg,5100),2496,812)+"
"; + for(size_t k=0;k(); + out+=btn("statistics-curve","()+";\">"+esc(curve.at("name").get())+"","statistics-action statistics-series-button", + "id=\"statistics-curve-"+std::to_string(k)+"\" data-index=\""+std::to_string(k)+"\" aria-pressed=\""+(active?"true":"false")+"\" style=\""+rect(double(k%3)*854.666666667,double(k/3)*100,836.666666667,82)+"\""); + } + out+="
"; + } else { + const auto &columns=data.at("columns"),&rows=data.at("rows"); + const size_t count=columns.size(); + const double table_width=2548; + const double first=minutes?table_width*.12:winners?190:table_width*.4; + const double rest=count>1?(table_width-first)/double(count-1):0; + const auto width=[&](size_t column){return finals?(column==1?160:1194):column?rest:first;}; + const bool trophies=winners&&std::any_of(columns.begin(),columns.end(),[](const Json &column){return !column.value("trophy","").empty();}); + const double head_height=trophies?200:winners?78:66; + out+="
"; + for(size_t c=0;c()); + if(column.contains("round"))heading=""+esc(column.at("round").get())+""+heading; + if(!trophy.empty()) { + const auto art=asset.empty()?std::string():""+img(asset,105,105,asset.starts_with("asset:"),false,320)+""; + heading=btn("statistics-trophy",art+""+esc(column.at("text").get())+"","statistics-trophy-heading", + "id=\"statistics-trophy-heading-"+std::to_string(c)+"\" data-column=\""+std::to_string(c)+"\" data-row=\"-1\" aria-label=\""+esc(column.at("text").get()+" · Siegerbild ansehen")+"\" "+(asset.empty()||!column.contains("winner")?"disabled":"")); + } + out+="
"+heading+"
"; + } + out+="
"; + for(size_t r=0;r"; + for(size_t c=0;c"+esc(value.value("prefix",""))+""+btn("player-detail",statistics_text(title),"statistics-player-link","id=\"statistics-player-"+token+"\" data-id=\""+esc(value.at("player").get())+"\" data-club=\""+esc(value.value("club",""))+"\" title=\""+esc(title)+"\""); + } else if(value.contains("club")) { + const auto id=value.at("club").get();const auto *club=world_->find("clubs",id);const bool reverse=section==1&&c==1; + const auto name=""+esc(title)+"",badge=crest(club,42); + content=btn("club-detail",reverse?name+badge:badge+name,"report-club-button statistics-club "+std::string(reverse?"name-first ":"")+(data.at("club")==id?"current":""),"id=\"statistics-club-"+token+"\" data-id=\""+esc(id)+"\" title=\""+esc(title)+"\""); + } else if(value.contains("trophy")) { + const auto asset=statistics_trophy_asset(value.at("trophy").get()); + content=btn("statistics-trophy",(asset.empty()?std::string():""+img(asset,58,58,asset.starts_with("asset:"),false,192)+"")+statistics_text(title),"statistics-world-trophy","id=\"statistics-trophy-row-"+token+"\" data-row=\""+std::to_string(r)+"\" data-column=\""+std::to_string(c)+"\" "+(asset.empty()?"disabled":"")); + } else content=statistics_text(value.value("prefix","")+title); + if(value.contains("round"))content=""+esc(value.at("round").get())+""+content; + out+="
"+content+"
"; + } + out+="
"; + } + if(rows.empty())out+="

"+statistics_text("Keine Statistikdaten für diese Auswahl vorhanden.")+"

"; + out+="
"; + } + out+="
"+render_report_detail(); +} + +std::string App::render_statistics_trophy() { + if(!statistics_trophy_.contains("asset"))return {}; + const auto asset=statistics_trophy_.at("asset").get(); + const bool world_image = asset.starts_with("asset:"); + if(world_image ? (!world_ || !world_->find("assets", asset)) : !gui_.contains(asset))return {}; + const auto winner=statistics_trophy_.value("winner",""); + const auto *club=world_?world_->find("clubs",winner):nullptr; + const auto name=club?world_->name(*club):world_?world_->nation_name(winner):"—"; + const auto viewport=context_->GetDimensions(); + const double w=viewport.x/scale_,h=viewport.y/scale_,stage=std::min(w,h*16/9); + const double art=std::min({h*.61,1200/scale_,w*.82}); + const double heading=std::clamp(h*.022,17/scale_,48/scale_),team=std::clamp(h*.035,25/scale_,76/scale_); + const double season_font=std::clamp(h*.0145,13/scale_,30/scale_),button_font=std::clamp(h*.0165,14/scale_,36/scale_); + const double heading_h=heading*1.25,team_h=team*1.5,season_h=season_font*1.25; + const double button_h=std::max(h*.046,button_font*1.25+h*.018+2/scale_); + const double gap=h*.018,copy_gap=h*.012; + const double total=art+heading_h+team_h+season_h+2*copy_gap+button_h+2*gap+h*.008; + const double top=(h-total)/2,heading_top=top+art+gap,team_top=heading_top+heading_h+copy_gap; + const double season_top=team_top+team_h+copy_gap,button_top=season_top+season_h+gap+h*.008; + return "
"+img("background",w,h,false,true,2048)+"
"+img(asset,art,art,world_image,false,1600)+"

"+esc(statistics_trophy_.value("title","Sieger"))+"

"+(club?crest(club,team_h):"")+""+esc(name)+"

"+statistics_text(statistics_trophy_.value("season",""))+"

"+btn("statistics-trophy-close","Weiter","statistics-trophy-close","id=\"statistics-trophy-close\" style=\""+rect((w-h*.17)/2,button_top,h*.17,button_h)+"font-size:"+scalar(button_font)+"dp;border-radius:"+scalar(h*.011)+"dp;\"")+"
"; +} diff --git a/src/modern/ui/statistics_state.inc b/src/modern/ui/statistics_state.inc new file mode 100644 index 0000000..1ede0f1 --- /dev/null +++ b/src/modern/ui/statistics_state.inc @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-3.0-only + Json statistics_view_ = Json::object(); + Json statistics_trophy_ = Json::object(); + Json statistics_scrolls_ = Json::object(); + bool statistics_restore_pending_ = false; + std::string render_statistics(); + std::vector> statistics_picker_items(const std::string &) const; + std::string statistics_picker_value(const std::string &) const; + bool statistics_picker_select(const std::string &, const std::string &); + bool statistics_action(const std::string &, Rml::Element *); + bool statistics_event(Rml::Event &); + void statistics_remember_scroll(); + void statistics_restore_scroll(); + std::string statistics_trophy_asset(const std::string &) const; + std::string render_statistics_trophy(); diff --git a/src/modern/ui/view.cpp b/src/modern/ui/view.cpp index 226e87f..71fcd66 100644 --- a/src/modern/ui/view.cpp +++ b/src/modern/ui/view.cpp @@ -17,6 +17,8 @@ #include "modern/ui/demo_career_reports.hpp" #include "modern/ui/demo_rankings.hpp" #include "modern/ui/demo_stadium.hpp" +#include "modern/ui/demo_statistics.hpp" +#include "modern/ui/demo_news.hpp" #include "modern/ui/desktop.hpp" #include "modern/ui/gui_assets.hpp" #include "modern/ui/model.hpp" @@ -374,6 +376,8 @@ class App final : public Rml::EventListener { uint64_t stadium_revision_ = 0; std::shared_ptr stadium_world_; const DataSource *stadium_source_ = nullptr; +#include "modern/ui/statistics_state.inc" +#include "modern/ui/news_state.inc" float device_ratio_ = 1.f; Json desktop_ = Json::object(), saved_desktop_ = Json::object(), options_ = Json::object(); @@ -593,6 +597,9 @@ class App final : public Rml::EventListener { transfer_dialog_.clear(); transfer_picker_.clear(); transfer_notice_.clear(); transfer_return_focus_.clear(); transfer_poach_league_.clear(); transfer_poach_club_.clear(); transfer_world_.reset(); transfer_revision_ = 0; career_view_ = Json::object(); rankings_view_ = Json::object(); + statistics_view_ = Json::object(); statistics_trophy_ = Json::object(); + statistics_scrolls_ = Json::object(); + reset_news(); stadium_view_ = Json::object(); stadium_revision_ = 0; stadium_world_.reset(); stadium_source_ = nullptr; advertising_selected_ = -1; advertising_offer_ = 0; advertising_revision_ = 0; advertising_world_.reset(); @@ -836,13 +843,17 @@ class App final : public Rml::EventListener { ticket_->resize(device_ratio_); scale_chalk_shadow(); dirty_ = true; + if (statistics_trophy_.contains("asset")) + needs_render_ = true; } void render() { + news_before_render(); fixture_half_width_ = -1.f; almanac_list_width_ = -1.f; // A window-close save prompt can leave a menu while its local dialog is // open. Never keep that menu's modal/input gate in the destination view. if (menu_ != last_rendered_menu_) { + statistics_trophy_ = Json::object(); planning_dialog_.clear(); career_view_["dialog"] = ""; career_view_["return_focus"] = ""; stadium_view_["dialog"] = ""; stadium_view_["draft"] = Json(); @@ -901,7 +912,9 @@ class App final : public Rml::EventListener { markup += render_menu(menu_); setting_menu_markup_ = true; element("canvas")->SetInnerRML(markup); + element("canvas")->SetProperty("overflow", statistics_trophy_.contains("asset") ? "visible" : "hidden"); setting_menu_markup_ = false; + 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; doc_->QuerySelectorAll(behind, @@ -1058,6 +1071,7 @@ class App final : public Rml::EventListener { } if (menu_ == "transfer") transfer_restore_scroll(); if (menu_ == "scorers" || menu_ == "fairplay") rankings_restore_scroll(); + if (menu_ == "statistics") statistics_restore_scroll(); if (!report_option_to_scroll_.empty()) { if (auto *node = element(report_option_to_scroll_)) node->ScrollIntoView(Rml::ScrollIntoViewOptions(Rml::ScrollAlignment::Nearest)); @@ -1079,7 +1093,7 @@ class App final : public Rml::EventListener { editor::images::encode_png({w, h, std::move(bytes)})); } void load_fonts() { - bool regular = false, bold = false; + bool regular = false, bold = false, italic = false, bold_italic = false; #ifdef _WIN32 const char *base = std::getenv("WINDIR"); if (base) { @@ -1090,6 +1104,12 @@ class App final : public Rml::EventListener { bold = Rml::LoadFontFace(rml::asset_path(folder / "segoeuib.ttf"), "Modern", Rml::Style::FontStyle::Normal, Rml::Style::FontWeight::Bold); + italic = Rml::LoadFontFace(rml::asset_path(folder / "segoeuii.ttf"), + "Modern", Rml::Style::FontStyle::Italic, + Rml::Style::FontWeight::Normal); + bold_italic = Rml::LoadFontFace(rml::asset_path(folder / "segoeuiz.ttf"), + "Modern", Rml::Style::FontStyle::Italic, + Rml::Style::FontWeight::Bold); } #elif defined(__APPLE__) const fs::path system = "/System/Library/Fonts/SFNS.ttf"; @@ -1100,6 +1120,15 @@ class App final : public Rml::EventListener { bold = Rml::LoadFontFace(rml::asset_path(system), "Modern", Rml::Style::FontStyle::Normal, Rml::Style::FontWeight::Bold); + const fs::path slanted = "/System/Library/Fonts/SFNSItalic.ttf"; + if (fs::exists(slanted)) { + italic = Rml::LoadFontFace(rml::asset_path(slanted), "Modern", + Rml::Style::FontStyle::Italic, + Rml::Style::FontWeight::Normal); + bold_italic = Rml::LoadFontFace(rml::asset_path(slanted), "Modern", + Rml::Style::FontStyle::Italic, + Rml::Style::FontWeight::Bold); + } } #else const fs::path fonts = fs::exists("/usr/share/fonts/truetype/liberation2") @@ -1112,6 +1141,12 @@ class App final : public Rml::EventListener { bold = Rml::LoadFontFace( rml::asset_path(fonts / "LiberationSans-Bold.ttf"), "Modern", Rml::Style::FontStyle::Normal, Rml::Style::FontWeight::Bold); + italic = Rml::LoadFontFace( + rml::asset_path(fonts / "LiberationSans-Italic.ttf"), "Modern", + Rml::Style::FontStyle::Italic, Rml::Style::FontWeight::Normal); + bold_italic = Rml::LoadFontFace( + rml::asset_path(fonts / "LiberationSans-BoldItalic.ttf"), "Modern", + Rml::Style::FontStyle::Italic, Rml::Style::FontWeight::Bold); } #endif if (!regular) @@ -1122,6 +1157,14 @@ class App final : public Rml::EventListener { bold = Rml::LoadFontFace(rml::asset_path(assets_ / "LatoLatin-Bold.ttf"), "Modern", Rml::Style::FontStyle::Normal, Rml::Style::FontWeight::Bold); + if (!italic) + italic = Rml::LoadFontFace(rml::asset_path(assets_ / "LatoLatin-Italic.ttf"), + "Modern", Rml::Style::FontStyle::Italic, + Rml::Style::FontWeight::Normal); + if (!bold_italic) + bold_italic = Rml::LoadFontFace( + rml::asset_path(assets_ / "LatoLatin-BoldItalic.ttf"), "Modern", + Rml::Style::FontStyle::Italic, Rml::Style::FontWeight::Bold); std::vector chalk_fonts; #ifdef _WIN32 if (const char *windir = std::getenv("WINDIR")) { @@ -1143,7 +1186,7 @@ class App final : public Rml::EventListener { Rml::Style::FontStyle::Normal, Rml::Style::FontWeight::Normal)) break; - if (!regular || !bold) + if (!regular || !bold || !italic || !bold_italic) throw std::runtime_error( "GUI-Schriften fehlen. Bitte das vollständige Paket entpacken."); } @@ -1334,6 +1377,10 @@ public: #include "modern/ui/rankings_controls.inc" #include "modern/ui/stadium_screens.inc" #include "modern/ui/stadium_controls.inc" +#include "modern/ui/statistics_screens.inc" +#include "modern/ui/statistics_controls.inc" +#include "modern/ui/news_screens.inc" +#include "modern/ui/news_controls.inc" } // namespace bool is_modern_world(const fs::path &file) { try { diff --git a/tests/modern_control_layout_tests.cpp b/tests/modern_control_layout_tests.cpp index fc86992..8c617d9 100644 --- a/tests/modern_control_layout_tests.cpp +++ b/tests/modern_control_layout_tests.cpp @@ -80,6 +80,15 @@ void centered_text(Rml::Element &text_root, Rml::Element &control, text_centers(text_root, p.x + s.x / 2, p.y + s.y / 2, horizontal, lines); require(lines == 1, "A control label disappeared or wrapped"); } +size_t visible_text_lines(Rml::Element &node) { + size_t count = 0; + if (auto *text = dynamic_cast(&node)) + for (const auto &line : text->GetLines()) + if (!line.text.empty() && line.width > 0) ++count; + for (int i = 0; i < node.GetNumChildren(); ++i) + count += visible_text_lines(*node.GetChild(i)); + return count; +} } // namespace int main(int argc, char **argv) try { require(argc == 2, "Pass the Modern asset directory"); @@ -97,10 +106,14 @@ int main(int argc, char **argv) try { Rml::Style::FontStyle::Normal, Rml::Style::FontWeight::Bold), "Bold font missing"); + require(Rml::LoadFontFace((root / "LatoLatin-BoldItalic.ttf").string(), "Modern", + Rml::Style::FontStyle::Italic, + Rml::Style::FontWeight::Bold), + "Bold italic font missing"); std::ostringstream css; for (const auto *name : {"theme.rcss", "ticket.rcss", "sports.rcss", "calendar.rcss", "reports.rcss", "report_details.rcss", - "report_pickers.rcss", "indoor.rcss", "planning.rcss", "almanac.rcss", "finance.rcss", "bank.rcss", "contracts.rcss", "amount.rcss", "environment.rcss", "advertising.rcss", "toto.rcss", "lineup.rcss", "transfer.rcss", "career_reports.rcss", "rankings.rcss", "stadium.rcss"}) { + "report_pickers.rcss", "indoor.rcss", "planning.rcss", "almanac.rcss", "finance.rcss", "bank.rcss", "contracts.rcss", "amount.rcss", "environment.rcss", "advertising.rcss", "toto.rcss", "lineup.rcss", "transfer.rcss", "career_reports.rcss", "rankings.rcss", "stadium.rcss", "statistics.rcss", "news.rcss"}) { std::ifstream input(root / name); require(bool(input), "Production stylesheet missing"); css << input.rdbuf() << '\n'; @@ -138,6 +151,24 @@ int main(int argc, char **argv) try { "id='rich' " "style='position:absolute;left:700dp;top:40dp;width:250dp;height:" "260dp;' "); + content += + "
" + + button_markup("statistics-absolute", "REL.", + "statistics-action statistics-absolute", "style='left:0;top:0;width:100%;height:94dp;'") + "
" + + "
" + + button_markup("player-detail", "Synthetic player", + "statistics-player-link") + "
" + + "
" + + button_markup("statistics-trophy", "WM 2098", + "statistics-world-trophy") + "
" + + "
" + + button_markup("club-detail", "Synthetic source club", + "report-club-button statistics-club name-first") + "
" + + "kicker" + + "
" + + "
Sample winner
" + + button_markup("statistics-curve", "Mannschaftsstärke", + "statistics-action statistics-series-button", "style='left:2700dp;top:580dp;width:836dp;height:82dp;'"); content += "
+#include +#include +#include +#include + +using namespace bmh::modern_ui; +namespace { +void require(bool value,const char *message) {if(!value)throw std::runtime_error(message);} +const std::array nations{"de","es","en","fr","it","nl","pt","be"}; +std::string club(const std::string &country,int index) {return "club:statistics-"+country+"-"+std::to_string(index);} +struct Fixture { + fs::path root;std::shared_ptr world; + explicit Fixture(bool empty=false, bool english_subnation=false) { + root=fs::temp_directory_path()/("openbmh-statistics-ui-"+std::to_string(std::chrono::steady_clock::now().time_since_epoch().count())); + fs::create_directories(root/"world"); + const auto write=[&](const std::string &file,const Json &value){bmh::editor::write_atomic(root/file,value.dump());}; + write("manifest.json",{{"format","openbmh-world"},{"kind","world"},{"format_version","1.1"},{"id","world:synthetic-statistics"},{"start_date","2026-07-01"},{"requires",{"editor:world-v1"}},{"x-editor",{{"profile","editor-world-v1"}}}}); + Json ns=Json::array(),leagues=Json::array(),clubs=Json::array(),players=Json::array(); + if(!empty)for(size_t n=0;n=5)continue; + const auto league="competition:statistics-"+code; + leagues.push_back({{"id",league},{"type","league"},{"nation",nation_id},{"tier",1},{"name","Synthetic league "+code}}); + leagues.push_back({{"id",league+"-lower"},{"type","league"},{"nation",nation_id},{"tier",2},{"name","Synthetic lower league "+code}}); + for(int i=0;i<20;++i) { + const auto id=club(code,i); + clubs.push_back({{"id",id},{"name","Synthetic club "+code+" "+std::to_string(i)},{"competition",league},{"nation",nation_id},{"crest","asset:synthetic-crest"}}); + for(int p=0;p<12;++p)players.push_back({{"id","player:statistics-"+code+"-"+std::to_string(i)+"-"+std::to_string(p)},{"name","Synthetic player "+std::to_string(i*12+p)},{"team",id},{"nation",nation_id},{"positions",{p==0?"gk":"mid"}}}); + } + clubs.push_back({{"id",club(code,20)},{"name","Synthetic lower club"},{"competition",league+"-lower"},{"nation",nation_id}}); + } + write("world/nations.json",{{"items",ns}});write("world/competitions.json",{{"items",leagues}});write("world/clubs.json",{{"items",clubs}});write("world/players.json",{{"items",players}}); + world=Catalog::open(root); + } + ~Fixture(){std::error_code ec;fs::remove_all(root,ec);} +}; +Json state() {return {{"date","2027-07-07"},{"managers",{{{"name","Synthetic manager"},{"club",club("de",4)}}}},{"cash",123456},{"reports",{{"league","competition:statistics-es"},{"filter",4}}}};} +void identities(const Catalog &world,const Json &data) { + for(const auto &r:data.at("rows"))for(const auto &c:r.at("cells")) { + if(c.contains("club"))require(world.find("clubs",c.at("club").get()),"Statistics contains an unknown club identity"); + if(c.contains("player"))require(world.find("players",c.at("player").get()),"Statistics contains an unknown player identity"); + if(c.contains("nation"))require(world.find("nations",c.at("nation").get()),"Statistics contains an unknown nation identity"); + } +} +void projections() { + Fixture f;const auto s=state(),before=s,clubs=f.world->rows("clubs"),players=f.world->rows("players"); + const auto initial=demo_statistics(*f.world,s); + require(initial.at("ok")==true&&initial.at("fictional")==true&&initial.at("section")==7&&initial.at("category")==0&&initial.at("winner_country")=="nation:de","Default must open national German winners"); + require(initial.at("rows").size()==12&&initial.at("columns").size()==4,"National winners lost their three title columns or twelve seasons"); + require(initial.at("rows")[0].at("cells")[0].at("text")=="2026/27"&&initial.at("rows")[11].at("cells")[0].at("text")=="2015/16","Winners must end with last completed season"); + require(initial.at("manager")=="Synthetic manager"&&initial.at("club")==club("de",4),"Statistics has stale own-manager identity"); + const std::array winner_order{"de","es","it","fr","en"}; + for(size_t i=0;i order{"de","es","en","fr","it"}; + require(data.at("rows").size()==20,"Eternal table silently lost twentieth team or mixed lower leagues"); + require(data.at("rows")[0].at("cells")[0].at("club")==club(order[size_t(country)],0),"Eternal country selector uses wrong nation cohort"); + require(data.at("rows")[19].at("cells")[0].at("club")==club(order[size_t(country)],19),"Eternal table truncated final actual club"); + identities(*f.world,data); + } + require(demo_statistics(*f.world,s,{{"section",3},{"country",5}}).at("rows").size()==20,"Absolute eternal table lost own-league cohort"); + for(const auto &nation:initial.at("countries")) { + const auto id=nation.at("id").get();const auto code=id.substr(7); + const auto data=demo_statistics(*f.world,s,{{"winner_country",id}}); + require(data.at("rows")[0].at("cells")[1].at("club")==club(code,0)&&data.at("rows")[0].at("cells")[3].at("club")==club(code,1),"National winners must use selected country's actual clubs"); + require(data.at("columns")[1].at("winner")==data.at("rows")[0].at("cells")[1].at("club"),"Trophy detail winner differs from latest visible winner"); + identities(*f.world,data); + } + const auto international=demo_statistics(*f.world,s,{{"category",1}}),indoor=demo_statistics(*f.world,s,{{"category",5}}); + require(international.at("columns").size()==4&&international.at("columns")[2].at("text")=="Pokalsieger"&&international.at("columns")[3].at("text")=="UEFA-Cup","International competition structure differs from BMH Gold"); + require(indoor.at("columns").size()==3&&indoor.at("rows")[0].at("cells").size()==3&&indoor.at("columns")[1].at("text")=="Sieger"&&indoor.at("columns")[2].at("text")=="Finalist","Indoor winners need exactly two title columns"); + identities(*f.world,international);identities(*f.world,indoor); + for(int view=0;view<6;++view) { + const auto data=demo_statistics(*f.world,s,{{"section",4},{"country",view}});identities(*f.world,data); + const size_t expected=view==0||view==5?6:view==3?4:8; + require(data.at("rows").size()==expected,"A world-statistics subview is missing"); + if(view==3)require(data.at("columns")[0].at("round")=="Runde"&&data.at("rows")[0].at("cells")[0].at("round")=="Finale"&&!data.at("rows")[0].at("cells")[0].contains("prefix"),"World final-round metadata was flattened into the team label"); + } + const auto relative=demo_statistics(*f.world,s,{{"section",2}}),absolute=demo_statistics(*f.world,s,{{"section",2},{"absolute",true},{"curves",{false,true,false,true,false,true}}}); + require(relative.at("series").size()==6&&relative.at("series")[0].at("points").size()==24,"Analytics needs six 24-point curves"); + require(relative.at("series")[0].at("points")!=absolute.at("series")[0].at("points")&&absolute.at("series")[0].at("active")==false&&absolute.at("series")[1].at("active")==true,"Curve toggles or relative/absolute data do not work"); + const auto minutes=demo_statistics(*f.world,s,{{"section",8}}); + require(minutes.at("columns").size()==19&&minutes.at("rows").size()==4&&minutes.at("rows")[0].at("cells")[1].at("tone")=="bad"&&minutes.at("rows")[0].at("cells")[4].at("tone")=="good","Minute grid must retain eighteen intervals and meaningful colors"); + auto changed=s;changed["cash"]=0;changed["reports"]={{"league","elsewhere"}}; + require(demo_statistics(*f.world,changed)==initial,"Statistics depends on unrelated wallet or report filters"); + changed=s;changed["managers"][0]["name"]="Changed manager";changed["managers"][0]["club"]=club("de",7); + require(demo_statistics(*f.world,changed).at("manager")=="Changed manager"&&demo_statistics(*f.world,changed).at("club")==club("de",7),"Statistics retains stale manager after switch"); + changed=s;changed["date"]="2027-06-30"; + require(demo_statistics(*f.world,changed).at("rows")[0].at("cells")[0].at("text")=="2025/26","June date falsely completed current season"); + require(s==before&&f.world->rows("clubs")==clubs&&f.world->rows("players")==players&&demo_statistics(*f.world,s)==initial,"Read projection changed input/catalogue or became nondeterministic"); + // This boundary check also proves all UI filters remain outside saved state. + DemoSource source(f.world);const auto snapshot=source.snapshot();const bool dirty=source.dirty(); + for(int section=0;section<9;++section)require(source.read_statistics({{"section",section}}).at("ok")==true,"Data-source read boundary does not expose statistics"); + require(source.snapshot().revision==snapshot.revision&&source.snapshot().state==snapshot.state&&source.dirty()==dirty,"Statistics reads changed checkpoint state, revision or dirty flag"); +} +void invalid_and_empty() { + Fixture f; + for(const auto &request:std::vector{nullptr,Json::array(),Json{{"section",-1}},Json{{"section",9}},Json{{"section","7"}},Json{{"category",2}},Json{{"country",6}},Json{{"winner_country","nation:missing"}},Json{{"winner_country",0}},Json{{"absolute",1}},Json{{"curves",{true,false}}},Json{{"curves",{true,true,true,true,true,1}}},Json{{"page",1}}})require(demo_statistics(*f.world,state(),request).at("ok")==false,"Malformed statistics filter was accepted"); + Fixture empty(true);for(int section=0;section<9;++section) { + const auto data=demo_statistics(*empty.world,Json::object(),{{"section",section}}); + require(data.at("ok")==true&&data.at("available")==false&&data.at("rows").empty()&&data.at("series").empty()&&data.at("club").is_null(),"Empty world fabricated statistics identities or rows"); + } + for(const auto &s:std::vector{nullptr,Json::array(),Json::object(),Json{{"managers",Json::array()}},Json{{"managers",{{{"club","club:missing"}}}}}}) { + const auto data=demo_statistics(*f.world,s);require(data.at("ok")==true&&data.at("club").is_null(),"Malformed manager snapshot threw or invented own identity"); + } +} +void english_subnation() { + Fixture f(false, true); + const auto initial = demo_statistics(*f.world, state()); + require(initial.at("countries").size() == 5 && initial.at("countries")[4].at("id") == "nation:x-eng", + "Stable England identity disappeared from the country picker"); + require(initial.at("eternal_countries").size() == 6 && initial.at("eternal_countries")[2].at("nation") == "nation:x-eng", + "Eternal table omitted England or changed its Gold index"); + const auto eternal = demo_statistics(*f.world, state(), {{"section",3},{"country",2}}); + require(eternal.at("rows").size() == 20 && eternal.at("rows")[19].at("cells")[0].at("club") == club("en",19), + "England's twentieth club is absent from its eternal table"); + const auto winner = demo_statistics(*f.world, state(), {{"winner_country","nation:x-eng"}}); + require(winner.at("columns")[1].at("text") == "Premier League" && winner.at("columns")[2].at("text") == "FA Cup" && + winner.at("columns")[1].at("trophy") == "en-premier-league", + "England incorrectly uses German title or trophy names"); + const auto world = demo_statistics(*f.world, state(), {{"section",4},{"country",1}}); + require(world.at("rows")[4].at("cells")[1].at("nation") == "nation:x-eng", + "World statistics replaced England with an unrelated country"); + require(!f.world->find("nations","nation:en"), "Projection changed stable nation IDs"); +} +} // namespace +int main()try{projections();invalid_and_empty();english_subnation();std::cout<<"Modern statistics UI checks passed\n";return 0;}catch(const std::exception &error){std::cerr<