Complete Modern game setup and manager selection with staged confirmation (by Codex)
This commit is contained in:
1 parent
a0bb8b47dc
commit
967520190d
18 files changed
+1784
-531
No files matched your search
@@ -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 modern_statistics_ui_tests modern_news_ui_tests modern_settings_ui_tests modern_desktop_ui_tests modern_files_ui_tests modern_mods_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 modern_settings_ui_tests modern_desktop_ui_tests modern_files_ui_tests modern_mods_ui_tests modern_entry_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_|statistics_ui_|news_ui_|settings_ui_|desktop_ui_|files_ui_|mods_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_|settings_ui_|desktop_ui_|files_ui_|mods_ui_|entry_ui_)" --output-on-failure --output-junit modern-ui-results.xml
|
||||
- name: Upload test report
|
||||
if: always()
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-only */
|
||||
/* Gold entry layout, expressed in RmlUI logical desktop units. */
|
||||
body {--entry-focus:#8cc8ff;--entry-selected:#78b9a51f;--entry-accent-border:#a9dccb52;--entry-dialog:#283542f5;}
|
||||
body.silver {--entry-focus:#2b729a;--entry-selected:#a3c3dd54;--entry-accent-border:#356f966e;--entry-dialog:#e7f0f5fc;}
|
||||
body.matchday {--entry-focus:#efb2aa;--entry-selected:#d48c7b26;--entry-accent-border:#e5a19770;--entry-dialog:#272a30fc;}
|
||||
.entry-setup,.entry-manager-underlay {position:absolute;left:0;right:0;top:0;bottom:0;}
|
||||
.entry-setup h2,.entry-manager-underlay h2 {font-weight:normal;}
|
||||
.entry-setup button,.entry-manager-underlay button,.entry-dialog button {flex-shrink:0;}
|
||||
.entry-setup button:focus-visible,.entry-manager-underlay button:focus-visible,.entry-manager-underlay input:focus-visible,.entry-manager-underlay select:focus-visible,.entry-dialog button:focus-visible {border-color:var(--entry-focus);}
|
||||
.entry-setup-heading {position:absolute;left:0;right:0;top:0;height:90dp;display:flex;align-items:baseline;justify-content:space-between;gap:30dp;}
|
||||
.entry-setup-heading h2 {margin:0;font-size:38dp;}
|
||||
.entry-setup-heading p {margin:0;color:var(--muted);font-size:28dp;}
|
||||
.entry-setup-options {position:absolute;left:0;right:0;top:116dp;bottom:342dp;}
|
||||
.entry-setup-option {position:absolute;padding:32dp 26dp;border:2dp var(--border);border-radius:18dp;background-color:var(--panel);display:flex;flex-direction:column;justify-content:center;gap:24dp;}
|
||||
.entry-setup-option>h2 {margin:0;text-align:center;font-size:38dp;letter-spacing:0.6dp;flex-shrink:0;}
|
||||
.entry-setup-stepper {position:relative;display:flex;align-items:center;justify-content:space-between;gap:18dp;flex:1;min-height:0;width:100%;}
|
||||
.entry-setup-stepper button {width:94dp;height:124dp;min-width:0;padding:0;font-size:72dp;font-weight:normal;line-height:1;border-radius:16dp;}
|
||||
.entry-setup-stepper button:disabled {opacity:0.25;}
|
||||
.entry-setup-value {display:flex;flex-direction:column;align-items:center;justify-content:center;gap:6dp;min-width:0;min-height:0;flex:1;}
|
||||
.entry-setup-value>strong {display:block;height:190dp;font-size:174dp;line-height:1;font-weight:normal;flex-shrink:0;}
|
||||
.entry-setup-value>.entry-setup-duration {font-size:210dp;line-height:0.8;color:var(--accent);}
|
||||
.entry-setup-value>.entry-setup-mode {letter-spacing:14dp;padding-left:14dp;color:#dfcb91;}
|
||||
.entry-setup-value>span {display:block;font-size:32dp;color:var(--muted);flex-shrink:0;}
|
||||
.entry-setup-balls {position:relative;height:194dp;flex-shrink:0;}
|
||||
.entry-setup-people {display:flex;align-items:center;justify-content:center;gap:18dp;height:190dp;flex-shrink:0;}
|
||||
.entry-setup-people>.image-frame {flex-shrink:0;}
|
||||
.entry-setup-competitions {position:absolute;left:0;right:0;bottom:126dp;height:190dp;}
|
||||
.entry-setup-competition {position:absolute;top:0;width:1293dp;height:126dp;display:flex;align-items:center;justify-content:center;gap:24dp;font-size:32dp;}
|
||||
.entry-setup-competition[data-id=league] {left:0;}
|
||||
.entry-setup-competition[data-id=world] {right:0;}
|
||||
.entry-setup-competition>.image-frame {flex-shrink:0;}
|
||||
.entry-setup-competition>span {display:flex;align-items:center;gap:28dp;flex-shrink:0;}
|
||||
.entry-setup-competition strong {display:block;font-weight:normal;}
|
||||
.entry-setup-competition small {display:block;font-size:25dp;color:var(--muted);}
|
||||
.entry-setup-competition.selected {background-color:var(--entry-selected);border-color:var(--entry-accent-border);color:var(--accent);}
|
||||
.entry-setup-competition:disabled {opacity:0.6;}
|
||||
.entry-setup-competitions>p {position:absolute;left:0;right:0;top:142dp;margin:0;text-align:center;font-size:25dp;color:var(--muted);}
|
||||
.entry-setup-actions {position:absolute;left:0;right:0;bottom:0;height:100dp;display:flex;align-items:center;justify-content:space-between;gap:28dp;}
|
||||
.entry-setup-actions>p {margin:0;font-size:26dp;color:var(--muted);}
|
||||
.entry-setup-actions>div {display:flex;gap:22dp;flex-shrink:0;}
|
||||
.entry-setup-actions button {height:92dp;min-width:270dp;font-size:31dp;}
|
||||
.entry-setup-actions .primary {background-color:var(--entry-selected);border-color:var(--entry-accent-border);color:var(--accent);}
|
||||
|
||||
.entry-manager-layout {position:absolute;left:0;right:0;top:0;bottom:132dp;}
|
||||
.entry-manager-step {position:absolute;left:0;right:0;top:0;height:40dp;display:flex;align-items:baseline;justify-content:space-between;gap:24dp;}
|
||||
.entry-manager-step>span {display:block;font-size:34dp;flex-shrink:0;}
|
||||
.entry-manager-step>p {margin:0;font-size:28dp;color:var(--muted);}
|
||||
.entry-manager-step button {height:64dp;font-size:27dp;padding:0 28dp;}
|
||||
.entry-manager-fields {position:absolute;left:0;right:0;top:64dp;bottom:0;}
|
||||
.entry-manager-layout.is-add .entry-manager-fields {top:88dp;}
|
||||
.entry-manager-identity {position:absolute;left:0;right:0;top:0;height:330dp;}
|
||||
.entry-manager-person-card,.entry-manager-club-card,.entry-manager-portrait-section,.entry-manager-roster {position:absolute;border:2dp var(--border);border-radius:18dp;background-color:var(--panel);min-width:0;min-height:0;}
|
||||
.entry-manager-person-card {left:0;top:0;width:1292dp;height:330dp;padding:32dp;}
|
||||
.entry-manager-person-copy {position:absolute;left:32dp;right:238dp;top:32dp;}
|
||||
.entry-manager-person-copy>label {display:block;margin:0 0 20dp;font-size:28dp;}
|
||||
#manager-name {width:100%;height:86dp;padding:14dp 20dp;font-size:38dp;line-height:1.2;}
|
||||
.entry-manager-person-copy>p {margin:20dp 0;font-size:26dp;line-height:1.4;color:var(--muted);}
|
||||
.entry-manager-profile-tag {display:block;font-size:26dp;color:var(--accent);}
|
||||
.entry-manager-face {display:block;width:174dp;height:232dp;border:2dp var(--border);border-radius:12dp;overflow:hidden;background-color:var(--panel);flex-shrink:0;}
|
||||
.entry-manager-face>.image-frame {position:absolute;left:0;top:0;flex-shrink:0;}
|
||||
.entry-manager-person-card>.entry-manager-face {position:absolute;right:32dp;top:47dp;}
|
||||
.entry-manager-club-card {right:0;top:0;width:1292dp;height:330dp;padding:28dp 30dp;}
|
||||
.entry-manager-club-card>h2,.entry-manager-options h2 {margin:0 0 20dp;font-size:28dp;}
|
||||
.entry-manager-club-button {width:100%;height:222dp;display:flex;align-items:center;justify-content:flex-start;gap:28dp;padding:0;border:0dp;background-color:transparent;text-align:left;}
|
||||
.entry-manager-club-button:hover {background-color:var(--hover);}
|
||||
.entry-manager-club-crest {display:flex;align-items:center;justify-content:center;width:176dp;height:176dp;flex-shrink:0;border:2dp var(--border);border-radius:18dp;background-color:#e8eef2;}
|
||||
.entry-manager-club-crest>.image-frame {flex-shrink:0;}
|
||||
.entry-manager-club-button>span {display:flex;flex-direction:column;gap:18dp;flex:1;min-width:0;}
|
||||
.entry-manager-club-button strong {display:block;font-size:38dp;font-weight:normal;line-height:1.15;}
|
||||
.entry-manager-club-button small {display:block;font-size:26dp;line-height:1.3;color:var(--muted);}
|
||||
.entry-manager-club-button em {display:block;font-style:normal;font-size:28dp;color:var(--accent);}
|
||||
.entry-manager-club-button em>span {padding-left:8dp;font-size:34dp;}
|
||||
.entry-manager-options {position:absolute;left:0;right:0;top:358dp;height:144dp;}
|
||||
.entry-manager-options>section {position:absolute;top:0;width:1292dp;}
|
||||
.entry-manager-options>section:first-child {left:0;}
|
||||
.entry-manager-options>section:last-child {right:0;}
|
||||
.entry-manager-options>section>div {display:flex;gap:20dp;}
|
||||
.entry-manager-options select {width:100%;min-width:0;height:88dp;font-size:30dp;}
|
||||
.entry-manager-options>section>div>select {flex:1;}
|
||||
.entry-manager-fields.is-full .entry-manager-identity,.entry-manager-fields.is-full .entry-manager-options {opacity:0.5;}
|
||||
.entry-manager-choices {position:absolute;left:0;right:0;top:530dp;bottom:0;}
|
||||
.entry-manager-portrait-section {left:0;top:0;bottom:0;width:1984dp;padding:26dp;}
|
||||
.entry-manager-portrait-section>header {position:absolute;left:26dp;right:26dp;top:26dp;height:64dp;display:flex;align-items:baseline;justify-content:space-between;gap:16dp;}
|
||||
.entry-manager-portrait-section h2,.entry-manager-roster h2 {margin:0;font-size:28dp;}
|
||||
.entry-manager-portrait-styles {display:flex;gap:4dp;padding:4dp;border:2dp var(--border);border-radius:12dp;background-color:var(--panel);flex-shrink:0;}
|
||||
.entry-manager-portrait-styles button {height:54dp;min-width:0;padding:0 20dp;border:0dp;border-radius:8dp;background-color:transparent;font-size:25dp;}
|
||||
.entry-manager-portrait-styles button[aria-pressed=true] {background-color:var(--entry-selected);color:var(--accent);}
|
||||
.entry-manager-portraits {position:absolute;left:26dp;right:26dp;top:112dp;bottom:26dp;}
|
||||
.entry-manager-portrait {display:flex;flex-direction:column;align-items:center;justify-content:center;gap:16dp;min-width:0;min-height:0;padding:14dp 8dp;border:2dp var(--border);border-radius:14dp;background-color:var(--soft);}
|
||||
.entry-manager-portrait>.entry-manager-face {position:relative;flex-shrink:0;}
|
||||
.entry-manager-portrait.selected {border-color:var(--entry-accent-border);background-color:var(--entry-selected);color:var(--accent);}
|
||||
.entry-manager-portrait-caption {display:block;font-size:24dp;white-space:nowrap;flex-shrink:0;}
|
||||
.entry-manager-portrait[tabindex="-1"] {tab-index:none;}
|
||||
.entry-manager-portrait[tabindex="0"] {tab-index:auto;}
|
||||
.entry-manager-portrait:disabled {opacity:0.4;}
|
||||
.entry-manager-roster {right:0;top:0;bottom:0;width:600dp;padding:28dp;}
|
||||
.entry-manager-roster>header {display:flex;align-items:baseline;justify-content:space-between;gap:16dp;}
|
||||
.entry-manager-roster>header>span {display:block;font-size:24dp;color:var(--muted);flex-shrink:0;}
|
||||
.entry-manager-roster-list {position:absolute;left:28dp;right:28dp;top:88dp;bottom:82dp;overflow-y:auto;overflow-x:hidden;}
|
||||
.entry-manager-roster-row {display:flex;align-items:center;gap:20dp;min-height:120dp;margin-bottom:24dp;}
|
||||
.entry-manager-roster-row>.entry-manager-face {position:relative;width:90dp;height:120dp;border-radius:10dp;}
|
||||
.entry-manager-roster-row>div:last-child {display:flex;flex-direction:column;gap:10dp;min-width:0;flex:1;}
|
||||
.entry-manager-roster-row small {display:block;font-size:23dp;color:var(--muted);}
|
||||
.entry-manager-roster-row strong {display:block;font-size:29dp;font-weight:normal;}
|
||||
.entry-manager-roster-row>div>span {display:block;font-size:24dp;line-height:1.3;}
|
||||
.entry-manager-roster>p {position:absolute;left:28dp;right:28dp;bottom:28dp;margin:0;font-size:24dp;color:var(--muted);}
|
||||
.entry-manager-actions {position:absolute;left:0;right:0;bottom:0;min-height:96dp;display:flex;align-items:center;justify-content:space-between;gap:32dp;}
|
||||
.entry-manager-actions>p {margin:0;max-width:1450dp;font-size:26dp;line-height:1.4;color:var(--muted);}
|
||||
.entry-manager-actions>div {display:flex;gap:20dp;flex-shrink:0;}
|
||||
.entry-manager-actions button {height:92dp;padding:0 36dp;font-size:30dp;}
|
||||
.entry-manager-actions .primary {background-color:var(--entry-selected);border-color:var(--entry-accent-border);color:var(--accent);}
|
||||
|
||||
.entry-club-picker {position:absolute;left:0;right:0;top:0;bottom:0;}
|
||||
.entry-club-picker>header {position:absolute;left:0;right:0;top:0;height:90dp;display:flex;align-items:center;justify-content:space-between;gap:24dp;}
|
||||
.entry-club-picker h2 {margin:0;font-size:38dp;}
|
||||
.entry-club-picker header p {margin:14dp 0 0;font-size:28dp;color:var(--muted);}
|
||||
.entry-club-filters {position:absolute;left:0;right:0;top:118dp;height:88dp;display:flex;align-items:center;gap:28dp;}
|
||||
.entry-club-filters>div {display:flex;gap:20dp;flex:1;min-width:0;}
|
||||
.entry-club-filters select {min-width:0;height:88dp;font-size:30dp;flex:1;}
|
||||
.entry-club-filters>label {display:block;width:620dp;flex-shrink:0;}
|
||||
#manager-club-search {width:100%;height:88dp;padding:16dp 24dp;font-size:30dp;}
|
||||
.entry-club-results {position:absolute;left:0;right:0;top:234dp;bottom:0;}
|
||||
.entry-club-count {margin:0;font-size:26dp;color:var(--muted);}
|
||||
.entry-club-grid {position:absolute;left:0;right:0;top:51dp;bottom:0;overflow-y:auto;overflow-x:hidden;}
|
||||
.entry-club-grid-content {position:relative;width:100%;}
|
||||
.entry-club-choice {display:flex;flex-direction:column;align-items:center;justify-content:center;gap:16dp;min-width:0;padding:20dp;border:2dp var(--border);border-radius:16dp;background-color:var(--panel);}
|
||||
.entry-club-choice.selected {border-color:var(--entry-accent-border);background-color:var(--entry-selected);}
|
||||
.entry-club-crest {display:flex;align-items:center;justify-content:center;width:120dp;height:120dp;border-radius:12dp;background-color:#e8eef2;flex-shrink:0;}
|
||||
.entry-club-crest>.image-frame {flex-shrink:0;}
|
||||
.entry-club-choice>strong {display:block;font-size:30dp;font-weight:normal;text-align:center;line-height:1.2;flex-shrink:0;}
|
||||
.entry-club-choice>small {display:block;font-size:23dp;text-align:center;color:var(--muted);flex-shrink:0;}
|
||||
.entry-club-choice:disabled {opacity:0.35;}
|
||||
.entry-club-lock {position:absolute;right:18dp;top:18dp;}
|
||||
.entry-no-clubs {margin:80dp 0;text-align:center;font-size:34dp;color:var(--muted);}
|
||||
|
||||
.entry-manager-underlay[aria-hidden=true] {pointer-events:none;}
|
||||
.entry-dialog-layer {position:absolute;left:-52dp;right:-52dp;top:-40dp;bottom:-24dp;z-index:35;display:flex;align-items:center;justify-content:center;padding:70dp;background-color:#08101980;}
|
||||
.entry-dialog {width:1700dp;max-height:1800dp;padding:40dp 52dp;border:2dp var(--border);border-radius:22dp;background-color:var(--entry-dialog);overflow-y:auto;overflow-x:hidden;box-shadow:0dp 24dp 70dp #0007;}
|
||||
.entry-dialog>h2 {margin:0;font-size:42dp;font-weight:bold;color:var(--text);}
|
||||
.entry-dialog>p {margin:36dp 0;font-size:36dp;line-height:1.5;}
|
||||
.entry-confirm-identity {display:flex;align-items:center;gap:40dp;margin:48dp 0;}
|
||||
.entry-confirm-crest {display:flex;align-items:center;justify-content:center;width:200dp;height:200dp;border-radius:18dp;background-color:#e8eef2;flex-shrink:0;}
|
||||
.entry-confirm-crest>.image-frame {flex-shrink:0;}
|
||||
.entry-confirm-copy {display:flex;flex-direction:column;gap:22dp;flex:1;min-width:0;}
|
||||
.entry-confirm-copy>strong {display:block;font-size:46dp;font-weight:normal;}
|
||||
.entry-confirm-copy>span {display:block;font-size:36dp;}
|
||||
.entry-confirm-copy>small {display:block;font-size:28dp;line-height:1.4;color:var(--muted);}
|
||||
.entry-confirm-identity>.entry-manager-face {position:relative;width:150dp;height:200dp;}
|
||||
.entry-dialog>footer {display:flex;justify-content:space-evenly;gap:70dp;margin-top:45dp;}
|
||||
.entry-dialog>footer button {flex:1;height:90dp;font-size:32dp;}
|
||||
.entry-success-dialog {width:1500dp;}
|
||||
|
||||
/* Use the owned SVG check mark instead of a platform-dependent font glyph. */
|
||||
.entry-choice-status,.entry-manager-portrait-caption {display:flex;align-items:center;justify-content:center;gap:8dp;}
|
||||
.entry-choice-status>.image-frame,.entry-manager-portrait-caption>.image-frame {flex-shrink:0;}
|
||||
.entry-confirm-dialog>h2 {text-align:center;}
|
||||
|
||||
.entry-choice-status>span,.entry-manager-portrait-caption>span {display:block;}
|
||||
@@ -1,6 +1,6 @@
|
||||
<rml>
|
||||
<head><title>OpenBMH</title><link type="text/rcss" href="theme.rcss"/><link type="text/rcss" href="ticket.rcss"/><link type="text/rcss" href="sports.rcss"/><link type="text/rcss" href="calendar.rcss"/><link type="text/rcss" href="reports.rcss"/><link type="text/rcss" href="report_details.rcss"/><link type="text/rcss" href="report_pickers.rcss"/><link type="text/rcss" href="indoor.rcss"/><link type="text/rcss" href="planning.rcss"/><link type="text/rcss" href="almanac.rcss"/><link type="text/rcss" href="finance.rcss"/>
|
||||
<link type="text/rcss" href="bank.rcss"/><link type="text/rcss" href="contracts.rcss"/><link type="text/rcss" href="amount.rcss"/><link type="text/rcss" href="environment.rcss"/><link type="text/rcss" href="advertising.rcss"/><link type="text/rcss" href="toto.rcss"/><link type="text/rcss" href="lineup.rcss"/><link type="text/rcss" href="transfer.rcss"/><link type="text/rcss" href="career_reports.rcss"/><link type="text/rcss" href="rankings.rcss"/><link type="text/rcss" href="stadium.rcss"/><link type="text/rcss" href="statistics.rcss"/><link type="text/rcss" href="news.rcss"/><link type="text/rcss" href="settings.rcss"/><link type="text/rcss" href="widgets.rcss"/><link type="text/rcss" href="files.rcss"/><link type="text/rcss" href="front.rcss"/></head>
|
||||
<link type="text/rcss" href="bank.rcss"/><link type="text/rcss" href="contracts.rcss"/><link type="text/rcss" href="amount.rcss"/><link type="text/rcss" href="environment.rcss"/><link type="text/rcss" href="advertising.rcss"/><link type="text/rcss" href="toto.rcss"/><link type="text/rcss" href="lineup.rcss"/><link type="text/rcss" href="transfer.rcss"/><link type="text/rcss" href="career_reports.rcss"/><link type="text/rcss" href="rankings.rcss"/><link type="text/rcss" href="stadium.rcss"/><link type="text/rcss" href="statistics.rcss"/><link type="text/rcss" href="news.rcss"/><link type="text/rcss" href="settings.rcss"/><link type="text/rcss" href="widgets.rcss"/><link type="text/rcss" href="files.rcss"/><link type="text/rcss" href="front.rcss"/><link type="text/rcss" href="entry.rcss"/></head>
|
||||
<body class="midnight">
|
||||
<div id="background"></div>
|
||||
<div id="canvas"></div>
|
||||
|
||||
@@ -17,8 +17,11 @@ wird ausdrücklich mit `OPENBMH_BUILD_MODERN_UI=ON` gebaut.
|
||||
- [Hauptmenü und Mod-Verwaltung](main-menu/README.md): zwei Tabs, Paketdetails,
|
||||
explizite dauerhaft gespeicherte Aktivierung und bestätigte Dateioperationen.
|
||||
Import von Originalordner, OBW/ZIP und Exportordner mit Prüfung/Namensentwurf,
|
||||
asynchroner Übernahme und getrennten Nutzerdaten. Grundeinstellungen mit vier großen Auswahlfeldern;
|
||||
Manager-/Vereinswahl mit Foto- und Illustrationsporträts. Ausländische
|
||||
asynchroner Übernahme und getrennten Nutzerdaten. [Spieleinstieg](main-menu/entry/README.md) mit vier großen Auswahlfeldern,
|
||||
separatem Entwurf bis zum letzten Ja, suchbarer Vereinswahl, zwölf
|
||||
Foto-/Illustrationsporträts und Identitätsbestätigung. Weitere Mitspieler
|
||||
lassen sich mit derselben Ansicht ergänzen; vier belegte Plätze bleiben
|
||||
sichtbar und gesperrt. Ausländische
|
||||
Vereine bleiben sichtbar und sind für Manager gesperrt.
|
||||
- Drei Teilnehmerseiten, automatische Demo-Auslosung mit Pause/Überspringen
|
||||
und Übersicht; in dieser Folge gibt es keinen Schließen-Knopf.
|
||||
|
||||
@@ -14,6 +14,7 @@ Implementierung in der Spiel-Engine.
|
||||
| QA-Befunde | [Offene Abweichungen zur HTML-Referenz](qa-findings.md) |
|
||||
| Ressourcen | [GUI-Assets, Weltbilder und spätere Paketbereinigung](assets.md) |
|
||||
| Hauptmenü & Mods | [Bibliothek, Import und explizite Aktivierung](main-menu/README.md) |
|
||||
| Spieleinstieg | [Grundeinstellungen, Managerwahl und Bestätigung](main-menu/entry/README.md) |
|
||||
| Desktop | [Statusleiste, Gestaltung und Fenster](desktop/README.md) |
|
||||
| Widgets | [17 Typen, 48 Größen, Raster, Fixierung und Arbeitsanordnung](desktop/widgets/README.md) |
|
||||
| Dateiverwaltung | [Spielstände und Desktopansichten mit Vorschauen](desktop/save-load/README.md) |
|
||||
|
||||
@@ -189,3 +189,8 @@ zugeordneten Runtime 132 Prüfungen in neun Prozessen (darunter zwei Neustarts).
|
||||
Die neue Kompatibilitäts-/Coverkohorte wird getrennt dokumentiert. Native
|
||||
Bild- und Bedienungstests laufen unter Linux/OpenGL; die Plattform-CI baut
|
||||
und prüft synthetisch, ersetzt aber keine Windows-/macOS-Spielabnahme.
|
||||
|
||||
## Spieleinstieg
|
||||
|
||||
Grundeinstellungen, Managerwahl, Entwürfe und Bestätigungen sind im
|
||||
[separaten Einstiegsvertrag](entry/README.md) beschrieben.
|
||||
@@ -0,0 +1,56 @@
|
||||
# Spieleinstieg und Managerwahl
|
||||
|
||||
Die native Modern-UI-Demo auf `0.3` übernimmt Grundeinstellungen, Managerwahl
|
||||
und Bestätigung aus dem privaten HTML-Mockup, Referenzstand `97c19979`.
|
||||
Die POC-Daten bleiben Präsentationsdaten. Es entsteht keine Engine-Karriere;
|
||||
Anstoß bleibt ohne Aktion. Saisonvorbereitung und deren fortsetzbare Speicherung
|
||||
bilden einen eigenen Folgeschritt.
|
||||
|
||||
## Ablauf und Datenvertrag
|
||||
|
||||
„Neues Spiel“ öffnet zuerst vier gleich große Grundeinstellungen: Dauer,
|
||||
Schwierigkeit, Mitspieler und Modus. Die Grenzen und Wettbewerbsabhängigkeiten
|
||||
entsprechen dem HTML-Mockup. Ein eigener Katalogverweis versorgt die
|
||||
Managerauswahl; die laufende DemoSource, Revision und Arbeitsansicht werden
|
||||
beim Öffnen oder Abbrechen nicht ersetzt.
|
||||
|
||||
Die Bestätigung zeigt Name, Vereinswappen, Verein, Liga, gewählte Stärke und
|
||||
Porträt. Nein/Escape kehren zur Auswahl zurück. Erst das Ja des letzten
|
||||
Managers validiert Grundeinstellungen und alle Manager gemeinsam und
|
||||
veröffentlicht die neue DemoSource. Ein fehlgeschlagener Start verwirft die
|
||||
bisherige Partie nicht. Bereits bestätigte Manager eines neuen Spiels sind
|
||||
bis dahin ausschließlich Entwürfe.
|
||||
|
||||
„Neuer Spieler“ auf dem Desktop ergänzt die vorhandene Partie mit derselben
|
||||
Bestätigung, ohne die Grundeinstellungen zu ändern. Vier belegte Plätze
|
||||
zeigen die vollständige, gesperrte Ansicht. Die Aktion „Neues Spiel“ beginnt
|
||||
einen getrennten Entwurf. Porträts und Vereine können pro Partie nur einmal
|
||||
vergeben werden; die Wahl Foto/Illustration bleibt pro Manager erhalten.
|
||||
|
||||
## Bedienung und bewusste Grenzen
|
||||
|
||||
- Der Vereinspicker zeigt fünf Spalten, eine Suche innerhalb der Liga,
|
||||
Trefferzahl und einen Leerzustand. Länder-/Ligawechsel aktualisieren die
|
||||
zulässige Auswahl. Ausländische Vereine sind in dieser nativen Phase
|
||||
sichtbar, aber gesperrt, wie vom Nutzer für `0.3` festgelegt.
|
||||
- Namen werden getrimmt, auf höchstens 24 Unicode-Codepoints begrenzt und auf
|
||||
gültiges UTF-8 sowie Steuerzeichen geprüft. Weiter reagiert bereits bei der
|
||||
Eingabe; Enter im Namensfeld öffnet die Bestätigung.
|
||||
- Die Porträts bilden eine Radiogruppe mit einem Tabstopp. Pfeile, Home und End
|
||||
wechseln die Auswahl; vergebene Bilder werden übersprungen.
|
||||
- Modale Bestätigung und Erfolgsmeldung halten den Tastaturfokus im Dialog.
|
||||
Escape schließt nur die aktuelle Bestätigung beziehungsweise Auswahlstufe.
|
||||
|
||||
Der UI-Demozustand bleibt im separaten JSON-Checkpointformat. `entry_view` im
|
||||
QA-Snapshot beschreibt den nicht übernommenen Entwurf zusätzlich zur weiterhin
|
||||
unveränderten `demo`. Diese Diagnose ist kein Engine-Spielstandformat.
|
||||
|
||||
## Prüfung
|
||||
|
||||
Synthetische Modelltests prüfen die gemeinsame Übernahme, veraltete Revisionen,
|
||||
ungültige Kombinationen, Namensnormalisierung und das Erhalten bestehender
|
||||
Manager beim Hinzufügen. Private Vorher-/Nachher-Bilder, Originaleingaben und
|
||||
UI-Checkpoints werden im privaten QA-Verzeichnis
|
||||
`docs/qa/entry-flow-batch-2026-10-26` geführt. Tatsächliche Laufresultate und
|
||||
verbleibende Abweichungen stehen im dortigen Bericht; Quellvergleich allein
|
||||
wird nicht als Laufabnahme ausgewiesen.
|
||||
@@ -259,3 +259,21 @@ zusätzlich vom vorhandenen 0.2-Launcher erkannt. Die Schriftprobe kontrolliert
|
||||
auch den Hauptmenütext und Modnamen bei vier Dichten in drei Themes.
|
||||
Ein schmaler Streifen rechts vom Cover wurde im finalen Link durch korrekte
|
||||
Coverbreite geschlossen; frühere Kohorten behalten ihre tatsächlichen Bilder.
|
||||
|
||||
|
||||
## Grundeinstellungen und Managerwahl · 26. Oktober 2026
|
||||
|
||||
Das [Managerpaket](main-menu/entry/README.md) ergänzt getrennte Entwürfe,
|
||||
suchbare Vereinswahl, Identitätsbestätigung und Add-/Full-Ansichten. Der
|
||||
unabhängige Vergleich erfasst drei Themes und zwei Auflösungen mit realen
|
||||
Maus-/Tastatureingaben. Ausländische Vereine bleiben bewusst gesperrt.
|
||||
Ein gerichteter zusätzlicher Bedienlauf prüft das Abbrechen nach dem ersten
|
||||
bereits bestätigten Entwurfsmanager gegen die unveränderte laufende Quelle,
|
||||
Revision, Dirty-Marke, Arbeitsansicht und UI-Präferenzen. Ein weiterer Lauf
|
||||
startet über die installierte Mod ohne zuvor geladene DemoSource.
|
||||
|
||||
Die neue synthetische Testsuite `modern_entry_ui_tests` prüft den atomaren
|
||||
Start und die gemeinsame Managervalidierung. Private Quellen, Screenshots
|
||||
und UI-Checkpoints liegen unter `docs/qa/entry-flow-batch-2026-10-26` im
|
||||
Mockup-Repository. Die vorhandene Saisonvorbereitung wird nur durchlaufen;
|
||||
eine neue Engine-Auslosung oder Matchabnahme wird nicht behauptet.
|
||||
@@ -1,6 +1,6 @@
|
||||
# Offene native UI-Befunde
|
||||
|
||||
Stand: 25. Oktober 2026. Diese Liste betrifft die ausdrücklich aktivierte,
|
||||
Stand: 26. Oktober 2026. Diese Liste betrifft die ausdrücklich aktivierte,
|
||||
noch unfertige Modern-Vorschau. Sie ist keine Abnahme der kompletten UI.
|
||||
Verbindliche Quelle ist das private HTML-Mockup; echte Rendererbilder und
|
||||
Bedienungsnachweise bleiben im privaten QA-Paket.
|
||||
@@ -122,3 +122,17 @@ weiter erkannt. Frontfarben folgen in allen Desktopthemes dem dunklen Gold;
|
||||
fast opaker Importdialog und nicht schrumpfender Downloadsbutton beheben die
|
||||
geprüften Farb-/Textabweichungen. Das Hauptmenü zeigt den Fokus-/Hoverpfeil und
|
||||
die korrekten Text-/Fenstermaße.
|
||||
|
||||
|
||||
Im Managerpaket behoben: vorzeitiges Ersetzen der laufenden Partie beim Öffnen
|
||||
von Neues Spiel, fehlender Liga-/Vereinsabgleich, fehlende Suche und Leeranzeige,
|
||||
generische statt vollständiger Bestätigung sowie die vereinfachten Add-/Full-
|
||||
Ansichten. Bestätigte Manager bleiben bis zum letzten Ja ein Entwurf. Die
|
||||
Porträts haben Radiotastaturbedienung und erhalten ihren individuellen Stil.
|
||||
Picker-Zurück und Escape aus offenen/geschlossenen Selects behalten die
|
||||
korrekte Auswahl beziehungsweise kehren zum bisherigen Desktop zurück.
|
||||
Sichtbefunde zu Auswahlglyphen, Bestätigungstitel und letzter Full-Identität
|
||||
wurden im dedizierten Vergleich nachgeprüft. Die oben vermerkte Übertragung
|
||||
des HTML-Popup-Unterbaus für Manager-Selects bleibt gesondert offen.
|
||||
Die Saisonvorbereitung bleibt im bisherigen Demoablauf; ihre fortsetzbare
|
||||
Phasen-/Ziehstandspeicherung und weitere Goldangleichung sind noch offen.
|
||||
@@ -26,7 +26,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 statistics.rcss news.rcss settings.rcss widgets.rcss files.rcss front.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 settings.rcss widgets.rcss files.rcss front.rcss entry.rcss)
|
||||
configure_file("${CMAKE_SOURCE_DIR}/assets/modern/${asset}" "${modern_assets}/${asset}" COPYONLY)
|
||||
endforeach()
|
||||
|
||||
@@ -112,7 +112,7 @@ foreach(component environment advertising toto lineup transfer stadium)
|
||||
add_test(NAME modern_${component}_ui_tests COMMAND modern_${component}_ui_tests)
|
||||
endforeach()
|
||||
|
||||
foreach(component statistics news settings desktop files)
|
||||
foreach(component statistics news settings desktop files entry)
|
||||
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)
|
||||
|
||||
+12
-175
@@ -127,6 +127,8 @@ void App::ProcessEvent(Rml::Event &event) try {
|
||||
// are being constructed. Opening a squad menu must stay read-only.
|
||||
if (setting_menu_markup_ && (menu_ == "lineup" || menu_ == "transfer" || menu_ == "news" || menu_ == "settings" || menu_=="widgets" || menu_=="save" || menu_=="load" || menu_=="view-save" || menu_=="view-load") &&
|
||||
(type == "change" || type == "input")) return;
|
||||
if (setting_menu_markup_ && (scene_ == "manager" || scene_ == "newgame") &&
|
||||
(type == "change" || type == "input")) return;
|
||||
if (type == "keydown")
|
||||
keyboard_navigation_ = true;
|
||||
else if (type == "mousedown")
|
||||
@@ -146,10 +148,11 @@ void App::ProcessEvent(Rml::Event &event) try {
|
||||
if (n->GetId() == "native-ticket-layer")
|
||||
return;
|
||||
if(front_event(event))return;
|
||||
if (entry_event(event)) return;
|
||||
if (amount_event(event)) return;
|
||||
if (popup_.empty() && settings_event(event)) return;
|
||||
if (popup_.empty() && (files_event(event) || widget_event(event))) return;
|
||||
if ((menu_ == "lineup" || menu_ == "transfer") && (type == "change" || type == "input")) {
|
||||
if ((menu_ == "lineup" || menu_ == "transfer" || scene_ == "manager") && (type == "change" || type == "input")) {
|
||||
if (auto *select = dynamic_cast<Rml::ElementFormControlSelect *>(event.GetTargetElement());
|
||||
select && select->IsSelectBoxVisible()) {
|
||||
pending_selects_.insert(select->GetId());
|
||||
@@ -399,6 +402,7 @@ void App::ProcessEvent(Rml::Event &event) try {
|
||||
[this](auto *n) {
|
||||
return !n->IsVisible(true) ||
|
||||
n->HasAttribute("disabled") ||
|
||||
n->template GetAttribute<int>("tabindex", 0) < 0 ||
|
||||
(menu_ == "scorers" &&
|
||||
n->GetId().starts_with("player-stat-tab-") &&
|
||||
n->template GetAttribute<Rml::String>("aria-selected", "false") != "true");
|
||||
@@ -459,6 +463,7 @@ void App::dispatch(const std::string &action, Rml::Element *target) {
|
||||
const auto id =
|
||||
target ? target->GetAttribute<Rml::String>("data-id", "") : std::string();
|
||||
if(front_action(action,target))return;
|
||||
if (entry_action(action, target)) return;
|
||||
if (settings_action(action,target)) return;
|
||||
if (files_action(action,target) || widget_action(action,target)) return;
|
||||
if (lineup_action(action, target) || transfer_action(action, target)) return;
|
||||
@@ -666,139 +671,7 @@ void App::dispatch(const std::string &action, Rml::Element *target) {
|
||||
"Modern-UI-Paket verwenden.");
|
||||
return;
|
||||
}
|
||||
if (auto *m = mod(active_mod_); m && m->type == "Modern")
|
||||
load_world(m->file);
|
||||
if (!source_) {
|
||||
message("Bitte eine Modern-Mod aktivieren.");
|
||||
return;
|
||||
}
|
||||
scene_ = "newgame";
|
||||
menu_.clear();
|
||||
refresh();
|
||||
return;
|
||||
}
|
||||
if (action == "setup-step") {
|
||||
const auto step = target->GetAttribute<int>("data-step", 0);
|
||||
const int limit = id == "duration" ? 5
|
||||
: id == "difficulty" ? 10
|
||||
: id == "players"
|
||||
? (start_options_.value("league", true) ? 4 : 1)
|
||||
: 3;
|
||||
if (id == "duration" || id == "difficulty" || id == "players" ||
|
||||
id == "mode")
|
||||
start_options_[id] =
|
||||
std::clamp(start_options_.value(id, 1) + step, 1, limit);
|
||||
refresh();
|
||||
return;
|
||||
}
|
||||
if (action == "setup-competition") {
|
||||
if (id == "league" || id == "world") {
|
||||
auto next = start_options_;
|
||||
next[id] = !next.value(id, true);
|
||||
if ((next.value("league", true) || next.value("world", true)) &&
|
||||
(next.value("league", true) || next.value("players", 1) == 1))
|
||||
start_options_ = std::move(next);
|
||||
}
|
||||
refresh();
|
||||
return;
|
||||
}
|
||||
if (action == "setup-next") {
|
||||
managers_draft_ = Json::array();
|
||||
manager_index_ = 0;
|
||||
adding_manager_ = false;
|
||||
manager_picker_ = false;
|
||||
selections_["portrait"] = "0";
|
||||
selections_["manager-name"] = "Alex Berger";
|
||||
scene_ = "manager";
|
||||
refresh();
|
||||
return;
|
||||
}
|
||||
if (action == "manager-clubs") {
|
||||
selections_["manager-name"] = field("manager-name");
|
||||
manager_picker_ = true;
|
||||
refresh();
|
||||
return;
|
||||
}
|
||||
if (action == "manager-clubs-back") {
|
||||
manager_picker_ = false;
|
||||
refresh();
|
||||
return;
|
||||
}
|
||||
if (action == "portrait-style") {
|
||||
selections_["manager-name"] = field("manager-name");
|
||||
selections_["portrait-style"] = id;
|
||||
refresh();
|
||||
return;
|
||||
}
|
||||
if (action == "portrait") {
|
||||
selections_["manager-name"] = field("manager-name");
|
||||
selections_["portrait"] = id;
|
||||
refresh();
|
||||
return;
|
||||
}
|
||||
if (action == "manager-club") {
|
||||
if (!world_->manageable(id))
|
||||
return;
|
||||
selected_club_ = id;
|
||||
country_ = "nation:de";
|
||||
league_ = world_->find("clubs", id)->value("competition", league_);
|
||||
manager_picker_ = false;
|
||||
refresh();
|
||||
return;
|
||||
}
|
||||
if (action == "manager-back") {
|
||||
scene_ = adding_manager_ ? "desktop" : "newgame";
|
||||
refresh();
|
||||
return;
|
||||
}
|
||||
if (action == "manager-next") {
|
||||
const auto name = field("manager-name");
|
||||
if (name.empty() || !world_->manageable(selected_club_)) {
|
||||
message("Bitte einen Namen und einen deutschen Verein wählen.");
|
||||
return;
|
||||
}
|
||||
const Json m = {
|
||||
{"name", name},
|
||||
{"club", selected_club_},
|
||||
{"portrait", selections_["portrait"].empty()
|
||||
? 0
|
||||
: std::stoi(selections_["portrait"])},
|
||||
{"portrait_style",
|
||||
selections_["portrait-style"] == "painted" ? "painted" : "photo"},
|
||||
{"strength_choice", selections_["manager-strength"].empty()
|
||||
? 1
|
||||
: std::stoi(selections_["manager-strength"])}};
|
||||
confirmation("Sind alle Eingaben richtig?", [this, m] {
|
||||
auto candidate = managers_draft_;
|
||||
candidate.push_back(m);
|
||||
if (!adding_manager_ &&
|
||||
manager_index_ + 1 < start_options_.value("players", 1)) {
|
||||
managers_draft_ = candidate;
|
||||
++manager_index_;
|
||||
selections_["manager-name"] = std::array<const char *, 4>{
|
||||
"Alex Berger", "Chris Winter", "Robin Meier",
|
||||
"Jamie Sommer"}[size_t(manager_index_)];
|
||||
for (int p = 0; p < 12; ++p)
|
||||
if (std::none_of(
|
||||
candidate.begin(), candidate.end(),
|
||||
[&](const auto &v) { return v.value("portrait", 0) == p; })) {
|
||||
selections_["portrait"] = std::to_string(p);
|
||||
break;
|
||||
}
|
||||
refresh();
|
||||
return;
|
||||
}
|
||||
if (!apply("managers", candidate))
|
||||
return;
|
||||
managers_draft_ = std::move(candidate);
|
||||
apply("edit", {{"key", "setup"}, {"value", start_options_}});
|
||||
scene_ = adding_manager_ || !start_options_.value("league", true)
|
||||
? "desktop"
|
||||
: "opening";
|
||||
opening_page_ = 0;
|
||||
draw_revealed_ = 0;
|
||||
refresh();
|
||||
});
|
||||
entry_begin();
|
||||
return;
|
||||
}
|
||||
if (action == "opening-play") {
|
||||
@@ -837,28 +710,7 @@ void App::dispatch(const std::string &action, Rml::Element *target) {
|
||||
if (route == "kickoff")
|
||||
return;
|
||||
if (route == "newplayer") {
|
||||
const auto existing = snap().state.at("managers");
|
||||
if (existing.size() >= 4) {
|
||||
message("Alle vier Mitspielerplätze sind belegt.");
|
||||
return;
|
||||
}
|
||||
managers_draft_ = existing;
|
||||
manager_index_ = int(existing.size());
|
||||
adding_manager_ = true;
|
||||
manager_picker_ = false;
|
||||
selections_["manager-name"] = std::array<const char *, 4>{
|
||||
"Alex Berger", "Chris Winter", "Robin Meier",
|
||||
"Jamie Sommer"}[existing.size()];
|
||||
for (int p = 0; p < 12; ++p)
|
||||
if (std::none_of(existing.begin(), existing.end(), [&](const auto &v) {
|
||||
return v.value("portrait", 0) == p;
|
||||
})) {
|
||||
selections_["portrait"] = std::to_string(p);
|
||||
break;
|
||||
}
|
||||
menu_.clear();
|
||||
scene_ = "manager";
|
||||
refresh();
|
||||
entry_add();
|
||||
return;
|
||||
}
|
||||
static const std::set<std::string> available = {
|
||||
@@ -949,6 +801,7 @@ void App::dispatch(const std::string &action, Rml::Element *target) {
|
||||
}
|
||||
}
|
||||
void App::change(Rml::Element *target) {
|
||||
if (entry_change(target)) return;
|
||||
if(front_change(target)||files_change(target) || widget_change(target) || settings_change(target))return;
|
||||
const auto kind = target->GetAttribute<Rml::String>("data-change", "");
|
||||
auto *control = dynamic_cast<Rml::ElementFormControl *>(target);
|
||||
@@ -993,26 +846,10 @@ void App::change(Rml::Element *target) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (kind == "manager-country" && value == country_)
|
||||
return;
|
||||
if (kind == "manager-league" && value == league_)
|
||||
return;
|
||||
if (kind == "manager-country" || kind == "manager-league")
|
||||
focus_after_render_ = target->GetId();
|
||||
if (kind == "manager-country" || kind == "manager-league") {
|
||||
if (!manager_picker_)
|
||||
selections_["manager-name"] = field("manager-name");
|
||||
if (kind == "manager-country") {
|
||||
country_ = value;
|
||||
league_.clear();
|
||||
} else
|
||||
league_ = value;
|
||||
refresh();
|
||||
} else if (kind == "manager-strength") {
|
||||
selections_["manager-strength"] = value;
|
||||
}
|
||||
|
||||
}
|
||||
void App::input(Rml::Element *target) {
|
||||
if (entry_input(target)) return;
|
||||
if(front_change(target)||files_change(target) || widget_change(target) || settings_change(target))return;
|
||||
const auto kind = target->GetAttribute<Rml::String>("data-input", "");
|
||||
auto *control = dynamic_cast<Rml::ElementFormControl *>(target);
|
||||
@@ -1145,7 +982,7 @@ 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_},
|
||||
{"front_view",front_snapshot_view()}, {"files_view",{{"mode",files_mode_},{"selected",files_selected_},{"name",files_name_},{"feedback",files_feedback_}}}, {"widget_view",{{"query",widget_query_},{"notice",widget_notice_}}}, {"ui_preferences",ui_preferences_}, {"settings_draft",settings_draft_}, {"settings_category",settings_category_}, {"settings_query",settings_query_}, {"settings_notice",settings_notice_},
|
||||
{"entry_view", entry_snapshot()}, {"front_view",front_snapshot_view()}, {"files_view",{{"mode",files_mode_},{"selected",files_selected_},{"name",files_name_},{"feedback",files_feedback_}}}, {"widget_view",{{"query",widget_query_},{"notice",widget_notice_}}}, {"ui_preferences",ui_preferences_}, {"settings_draft",settings_draft_}, {"settings_category",settings_category_}, {"settings_query",settings_query_}, {"settings_notice",settings_notice_},
|
||||
{"statistics_view", statistics_view_}, {"statistics_trophy", statistics_trophy_},
|
||||
{"statistics_scrolls", statistics_scrolls_},
|
||||
{"news_view", news_view_}, {"news_dialog", news_dialog_},
|
||||
|
||||
@@ -0,0 +1,537 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
// Setup and manager selection are drafts. The running presentation source is
|
||||
// replaced only after the final affirmative confirmation succeeds.
|
||||
bool App::entry_used_club(const std::string &id) const {
|
||||
return std::any_of(managers_draft_.begin(), managers_draft_.end(),
|
||||
[&](const auto &m) { return m.value("club", "") == id; });
|
||||
}
|
||||
bool App::entry_used_portrait(int id) const {
|
||||
return std::any_of(
|
||||
managers_draft_.begin(), managers_draft_.end(),
|
||||
[&](const auto &m) { return m.value("portrait", 0) == id; });
|
||||
}
|
||||
bool App::entry_name_valid() const {
|
||||
const auto i = selections_.find("manager-name");
|
||||
return i != selections_.end() &&
|
||||
normalized_manager_name(i->second).has_value();
|
||||
}
|
||||
void App::entry_sync_club() {
|
||||
const auto catalog = entry_world();
|
||||
if (!catalog)
|
||||
return;
|
||||
const auto leagues = catalog->leagues(country_);
|
||||
if (std::none_of(leagues.begin(), leagues.end(),
|
||||
[&](auto *l) { return l->value("id", "") == league_; }))
|
||||
league_ = leagues.empty() ? "" : leagues.front()->value("id", "");
|
||||
const auto *current = catalog->find("clubs", selected_club_);
|
||||
if (current && current->value("competition", "") == league_ &&
|
||||
catalog->manageable(selected_club_) && !entry_used_club(selected_club_))
|
||||
return;
|
||||
selected_club_.clear();
|
||||
for (const auto *c : catalog->clubs(league_)) {
|
||||
const auto id = c->value("id", "");
|
||||
if (catalog->manageable(id) && !entry_used_club(id)) {
|
||||
selected_club_ = id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
void App::entry_choose_defaults() {
|
||||
const auto catalog = entry_world();
|
||||
selections_["manager-name"] = std::array<const char *, 4>{
|
||||
"Alex Berger", "Chris Winter", "Robin Meier",
|
||||
"Jamie Sommer"}[size_t(std::min(manager_index_, 3))];
|
||||
for (int p = 0; p < 12; ++p)
|
||||
if (!entry_used_portrait(p)) {
|
||||
selections_["portrait"] = std::to_string(p);
|
||||
break;
|
||||
}
|
||||
// Prefer the selected league, then the first available German club.
|
||||
entry_sync_club();
|
||||
if (selected_club_.empty() && catalog)
|
||||
for (auto *c : catalog->clubs()) {
|
||||
const auto id = c->value("id", "");
|
||||
if (catalog->manageable(id) && !entry_used_club(id)) {
|
||||
selected_club_ = id;
|
||||
country_ = "nation:de";
|
||||
league_ = c->value("competition", "");
|
||||
break;
|
||||
}
|
||||
}
|
||||
manager_picker_ = manager_confirm_ = manager_success_ = false;
|
||||
club_search_.clear();
|
||||
}
|
||||
void App::entry_begin() {
|
||||
auto next = world_;
|
||||
if (auto *m = mod(active_mod_); m && m->type == "Modern")
|
||||
next = Catalog::open(m->file);
|
||||
if (!next) {
|
||||
message("Bitte eine Modern-Mod aktivieren.");
|
||||
return;
|
||||
}
|
||||
const auto clubs = next->clubs();
|
||||
if (std::none_of(clubs.begin(), clubs.end(), [&](auto *c) {
|
||||
return next->manageable(c->value("id", ""));
|
||||
})) {
|
||||
message("Diese Mod enthält keinen spielbaren deutschen Verein.");
|
||||
return;
|
||||
}
|
||||
entry_return_scene_ =
|
||||
scene_ == "desktop" || (scene_ == "manager" && adding_manager_)
|
||||
? "desktop"
|
||||
: "main";
|
||||
entry_catalog_ = std::move(next);
|
||||
renderer_.world(entry_catalog_);
|
||||
start_options_ = {{"duration", 5}, {"difficulty", 3}, {"players", 1},
|
||||
{"mode", 3}, {"league", true}, {"world", true}};
|
||||
adding_manager_ = false;
|
||||
managers_draft_ = Json::array();
|
||||
manager_index_ = 0;
|
||||
manager_picker_ = manager_confirm_ = manager_success_ = false;
|
||||
country_ = "nation:de";
|
||||
league_.clear();
|
||||
entry_choose_defaults();
|
||||
scene_ = "newgame";
|
||||
menu_.clear();
|
||||
focus_after_render_ = "window-close";
|
||||
refresh();
|
||||
}
|
||||
void App::entry_add() {
|
||||
if (!source_)
|
||||
return;
|
||||
entry_catalog_.reset();
|
||||
renderer_.world(world_);
|
||||
entry_source_ = source_.get();
|
||||
entry_revision_ = snap().revision;
|
||||
managers_draft_ = snap().state.at("managers");
|
||||
manager_index_ = int(managers_draft_.size());
|
||||
adding_manager_ = true;
|
||||
country_ = "nation:de";
|
||||
entry_choose_defaults();
|
||||
if (entry_full()) {
|
||||
const auto &last = managers_draft_.back();
|
||||
selections_["manager-name"] = last.at("name").get<std::string>();
|
||||
selections_["portrait"] = std::to_string(last.value("portrait", 0));
|
||||
selections_["portrait-style"] = last.value("portrait_style", "photo");
|
||||
selections_["manager-strength"] =
|
||||
std::to_string(last.value("strength_choice", 1));
|
||||
selected_club_ = last.at("club").get<std::string>();
|
||||
league_ = world_->find("clubs", selected_club_)->value("competition", "");
|
||||
}
|
||||
scene_ = "manager";
|
||||
menu_.clear();
|
||||
focus_after_render_ = entry_full() ? "window-close" : "manager-name";
|
||||
refresh();
|
||||
}
|
||||
void App::entry_cancel() {
|
||||
entry_catalog_.reset();
|
||||
renderer_.world(world_);
|
||||
manager_confirm_ = manager_success_ = manager_picker_ = false;
|
||||
club_search_.clear();
|
||||
scene_ = adding_manager_ ? "desktop" : entry_return_scene_;
|
||||
adding_manager_ = false;
|
||||
managers_draft_ = Json::array();
|
||||
manager_index_ = 0;
|
||||
if (source_) {
|
||||
selected_club_ = manager(snap()).value("club", "");
|
||||
const auto *c = world_->find("clubs", selected_club_);
|
||||
if (c)
|
||||
league_ = c->value("competition", "");
|
||||
country_ = "nation:de";
|
||||
}
|
||||
focus_after_render_ =
|
||||
scene_ == "desktop" ? "object-app-newplayer" : "front-new";
|
||||
refresh();
|
||||
}
|
||||
void App::entry_confirm() {
|
||||
if (!manager_confirm_ || entry_full())
|
||||
return;
|
||||
const auto name = normalized_manager_name(selections_["manager-name"]);
|
||||
const auto catalog = entry_world();
|
||||
const int portrait =
|
||||
selections_["portrait"].empty() ? 0 : std::stoi(selections_["portrait"]);
|
||||
if (!name || !catalog || !catalog->manageable(selected_club_) ||
|
||||
entry_used_club(selected_club_) || portrait < 0 || portrait >= 12 ||
|
||||
entry_used_portrait(portrait))
|
||||
return;
|
||||
auto candidate = managers_draft_;
|
||||
candidate.push_back(
|
||||
{{"name", *name},
|
||||
{"club", selected_club_},
|
||||
{"portrait", portrait},
|
||||
{"portrait_style",
|
||||
selections_["portrait-style"] == "painted" ? "painted" : "photo"},
|
||||
{"strength_choice", selections_["manager-strength"].empty()
|
||||
? 1
|
||||
: std::stoi(selections_["manager-strength"])}});
|
||||
if (!adding_manager_ &&
|
||||
int(candidate.size()) < start_options_.value("players", 1)) {
|
||||
managers_draft_ = std::move(candidate);
|
||||
manager_index_ = int(managers_draft_.size());
|
||||
entry_choose_defaults();
|
||||
focus_after_render_ = "manager-name";
|
||||
refresh();
|
||||
return;
|
||||
}
|
||||
if (adding_manager_) {
|
||||
if (source_.get() != entry_source_) {
|
||||
message(
|
||||
"Die Partie hat sich geändert. Bitte die Managerauswahl neu öffnen.");
|
||||
return;
|
||||
}
|
||||
const auto added = source_->apply({entry_revision_, "managers", candidate});
|
||||
if (!added.ok) {
|
||||
message("Der Mitspieler konnte nicht hinzugefügt werden: " + added.error);
|
||||
return;
|
||||
}
|
||||
managers_draft_ = std::move(candidate);
|
||||
manager_confirm_ = false;
|
||||
manager_success_ = true;
|
||||
focus_after_render_ = "manager-success-close";
|
||||
} else {
|
||||
// Construct and validate before releasing any part of the current session.
|
||||
auto demo = std::make_unique<DemoSource>(catalog);
|
||||
const auto result =
|
||||
demo->apply({demo->snapshot().revision,
|
||||
"start",
|
||||
{{"setup", start_options_}, {"managers", candidate}}});
|
||||
if (!result.ok) {
|
||||
message("Die neue Partie konnte nicht übernommen werden: " +
|
||||
result.error);
|
||||
return;
|
||||
}
|
||||
publish_world(catalog, std::move(demo));
|
||||
saved_desktop_ = Json::object();
|
||||
undo_.clear();
|
||||
undo_themes_.clear();
|
||||
managers_draft_ = std::move(candidate);
|
||||
manager_confirm_ = false;
|
||||
entry_catalog_.reset();
|
||||
scene_ = start_options_.value("league", true) ? "opening" : "desktop";
|
||||
opening_page_ = draw_revealed_ = 0;
|
||||
draw_playing_ = true;
|
||||
draw_at_ = 0;
|
||||
focus_after_render_.clear();
|
||||
}
|
||||
refresh();
|
||||
}
|
||||
bool App::entry_action(const std::string &action, Rml::Element *target) {
|
||||
if ((scene_ != "newgame" && scene_ != "manager") || !popup_.empty())
|
||||
return false;
|
||||
const auto id =
|
||||
target ? target->GetAttribute<Rml::String>("data-id", "") : std::string();
|
||||
if (manager_confirm_) {
|
||||
if (action == "manager-confirm-yes")
|
||||
entry_confirm();
|
||||
else if (action == "manager-confirm-no") {
|
||||
manager_confirm_ = false;
|
||||
focus_after_render_ = "manager-next";
|
||||
refresh();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (manager_success_) {
|
||||
if (action == "manager-success-close" || action == "close")
|
||||
entry_cancel();
|
||||
return true;
|
||||
}
|
||||
if (action == "close") {
|
||||
entry_cancel();
|
||||
return true;
|
||||
}
|
||||
if (action == "setup-step") {
|
||||
const auto step = target->GetAttribute<int>("data-step", 0);
|
||||
const int limit = id == "duration" ? 5
|
||||
: id == "difficulty" ? 10
|
||||
: id == "players"
|
||||
? (start_options_.value("league", true) ? 4 : 1)
|
||||
: 3;
|
||||
if (id == "duration" || id == "difficulty" || id == "players" ||
|
||||
id == "mode")
|
||||
start_options_[id] =
|
||||
std::clamp(start_options_.value(id, 1) + step, 1, limit);
|
||||
const int current = start_options_.value(id, 1);
|
||||
focus_after_render_ = "setup-" + id +
|
||||
((current == limit && step > 0) ? "-minus"
|
||||
: (current == 1 && step < 0) ? "-plus"
|
||||
: step < 0 ? "-minus"
|
||||
: "-plus");
|
||||
} else if (action == "setup-competition") {
|
||||
if (id == "league" || id == "world") {
|
||||
auto next = start_options_;
|
||||
next[id] = !next.value(id, true);
|
||||
if ((next.value("league", true) || next.value("world", true)) &&
|
||||
(next.value("league", true) || next.value("players", 1) == 1))
|
||||
start_options_ = std::move(next);
|
||||
}
|
||||
const bool locked = id == "league"
|
||||
? start_options_.value("league", true) &&
|
||||
(start_options_.value("players", 1) > 1 ||
|
||||
!start_options_.value("world", true))
|
||||
: !start_options_.value("league", true);
|
||||
focus_after_render_ = locked ? "setup-next" : target->GetId();
|
||||
} else if (action == "setup-next") {
|
||||
adding_manager_ = false;
|
||||
managers_draft_ = Json::array();
|
||||
manager_index_ = 0;
|
||||
entry_choose_defaults();
|
||||
scene_ = "manager";
|
||||
focus_after_render_ = "manager-name";
|
||||
} else if (action == "manager-newgame") {
|
||||
entry_begin();
|
||||
return true;
|
||||
} else if (action == "manager-back") {
|
||||
if (adding_manager_)
|
||||
entry_cancel();
|
||||
else {
|
||||
scene_ = "newgame";
|
||||
manager_confirm_ = manager_picker_ = false;
|
||||
focus_after_render_ = "setup-next";
|
||||
refresh();
|
||||
}
|
||||
return true;
|
||||
} else if (action == "manager-clubs") {
|
||||
selections_["manager-name"] = field("manager-name");
|
||||
entry_picker_country_ = country_;
|
||||
entry_picker_league_ = league_;
|
||||
manager_picker_ = true;
|
||||
club_search_.clear();
|
||||
focus_after_render_ = "manager-club-search";
|
||||
} else if (action == "manager-clubs-back") {
|
||||
country_ = entry_picker_country_;
|
||||
league_ = entry_picker_league_;
|
||||
manager_picker_ = false;
|
||||
focus_after_render_ = "manager-clubs";
|
||||
} else if (action == "portrait-style") {
|
||||
selections_["manager-name"] = field("manager-name");
|
||||
if (id == "photo" || id == "painted")
|
||||
selections_["portrait-style"] = id;
|
||||
focus_after_render_ = target->GetId();
|
||||
} else if (action == "portrait") {
|
||||
const int portrait = std::stoi(id);
|
||||
if (entry_full() || portrait < 0 || portrait >= 12 ||
|
||||
entry_used_portrait(portrait))
|
||||
return true;
|
||||
selections_["manager-name"] = field("manager-name");
|
||||
selections_["portrait"] = id;
|
||||
focus_after_render_ = "manager-portrait-" + id;
|
||||
} else if (action == "manager-club") {
|
||||
if (entry_full() || !entry_world()->manageable(id) || entry_used_club(id))
|
||||
return true;
|
||||
selected_club_ = id;
|
||||
country_ = "nation:de";
|
||||
league_ = entry_world()->find("clubs", id)->value("competition", league_);
|
||||
manager_picker_ = false;
|
||||
focus_after_render_ = "manager-clubs";
|
||||
} else if (action == "manager-next") {
|
||||
if (entry_full())
|
||||
return true;
|
||||
selections_["manager-name"] = field("manager-name");
|
||||
if (!entry_name_valid() || !entry_world()->manageable(selected_club_) ||
|
||||
entry_used_club(selected_club_))
|
||||
return true;
|
||||
selections_["manager-name"] =
|
||||
*normalized_manager_name(selections_["manager-name"]);
|
||||
manager_confirm_ = true;
|
||||
focus_after_render_ = "manager-confirm-no";
|
||||
} else
|
||||
return false;
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
bool App::entry_change(Rml::Element *target) {
|
||||
if (scene_ != "manager" || manager_confirm_ || manager_success_)
|
||||
return false;
|
||||
const auto kind = target->GetAttribute<Rml::String>("data-change", "");
|
||||
if (kind != "manager-country" && kind != "manager-league" &&
|
||||
kind != "manager-strength")
|
||||
return false;
|
||||
if (entry_full())
|
||||
return true;
|
||||
const auto value =
|
||||
dynamic_cast<Rml::ElementFormControl *>(target)->GetValue();
|
||||
if (kind == "manager-strength") {
|
||||
selections_[kind] = value;
|
||||
return true;
|
||||
}
|
||||
if (!manager_picker_)
|
||||
selections_["manager-name"] = field("manager-name");
|
||||
if (kind == "manager-country") {
|
||||
if (value == country_)
|
||||
return true;
|
||||
country_ = value;
|
||||
league_.clear();
|
||||
} else {
|
||||
if (value == league_)
|
||||
return true;
|
||||
league_ = value;
|
||||
}
|
||||
club_search_.clear();
|
||||
if (manager_picker_) {
|
||||
const auto leagues = entry_world()->leagues(country_);
|
||||
if (std::none_of(leagues.begin(), leagues.end(),
|
||||
[&](auto *l) { return l->value("id", "") == league_; }))
|
||||
league_ = leagues.empty() ? "" : leagues.front()->value("id", "");
|
||||
} else
|
||||
entry_sync_club();
|
||||
focus_after_render_ = target->GetId();
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
bool App::entry_input(Rml::Element *target) {
|
||||
if (scene_ != "manager" || manager_confirm_ || manager_success_)
|
||||
return false;
|
||||
const auto kind = target->GetAttribute<Rml::String>("data-input", "");
|
||||
if (kind != "manager-name" && kind != "manager-search")
|
||||
return false;
|
||||
if (entry_full())
|
||||
return true;
|
||||
const auto value =
|
||||
dynamic_cast<Rml::ElementFormControl *>(target)->GetValue();
|
||||
if (kind == "manager-name") {
|
||||
selections_["manager-name"] = value;
|
||||
if (auto *next = element("manager-next")) {
|
||||
if (entry_name_valid() && entry_world()->manageable(selected_club_) &&
|
||||
!entry_used_club(selected_club_))
|
||||
next->RemoveAttribute("disabled");
|
||||
else
|
||||
next->SetAttribute("disabled", "");
|
||||
}
|
||||
dirty_ = true;
|
||||
} else {
|
||||
club_search_ = value;
|
||||
focus_after_render_ = "manager-club-search";
|
||||
refresh();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool App::entry_event(Rml::Event &event) {
|
||||
if ((scene_ != "newgame" && scene_ != "manager") || !popup_.empty())
|
||||
return false;
|
||||
const auto type = event.GetType();
|
||||
auto *target = event.GetTargetElement();
|
||||
if (type == "keydown") {
|
||||
const auto key =
|
||||
Rml::Input::KeyIdentifier(event.GetParameter<int>("key_identifier", 0));
|
||||
if (manager_confirm_ || manager_success_) {
|
||||
const auto root = element(manager_confirm_ ? "entry-confirm-layer"
|
||||
: "entry-success-layer");
|
||||
if (key == Rml::Input::KI_ESCAPE) {
|
||||
if (manager_confirm_)
|
||||
entry_action("manager-confirm-no", nullptr);
|
||||
else
|
||||
entry_action("manager-success-close", nullptr);
|
||||
} else if (key == Rml::Input::KI_TAB && root) {
|
||||
Rml::ElementList controls;
|
||||
root->QuerySelectorAll(controls, "button");
|
||||
if (!controls.empty()) {
|
||||
auto i = std::find(controls.begin(), controls.end(),
|
||||
context_->GetFocusElement());
|
||||
const int old = i == controls.end() ? -1 : int(i - controls.begin());
|
||||
const int step = event.GetParameter<int>("shift_key", 0) ? -1 : 1;
|
||||
controls[size_t((old + step + int(controls.size())) %
|
||||
int(controls.size()))]
|
||||
->Focus(true);
|
||||
}
|
||||
} else if (key == Rml::Input::KI_RETURN || key == Rml::Input::KI_SPACE) {
|
||||
for (auto *n = target; n && n != root; n = n->GetParentNode())
|
||||
if (n->GetTagName() == "button") {
|
||||
n->DispatchEvent("click", {});
|
||||
break;
|
||||
}
|
||||
}
|
||||
event.StopImmediatePropagation();
|
||||
return true;
|
||||
}
|
||||
// Leave native selects to the shared select controller, including Escape.
|
||||
for (auto *n = target; n && n != doc_; n = n->GetParentNode())
|
||||
if (auto *select = dynamic_cast<Rml::ElementFormControlSelect *>(n)) {
|
||||
if (key != Rml::Input::KI_ESCAPE || select->IsSelectBoxVisible())
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
if (key == Rml::Input::KI_ESCAPE) {
|
||||
if (scene_ == "manager" && manager_picker_)
|
||||
entry_action("manager-clubs-back", nullptr);
|
||||
else if (scene_ == "manager")
|
||||
entry_action("manager-back", nullptr);
|
||||
else
|
||||
entry_cancel();
|
||||
event.StopImmediatePropagation();
|
||||
return true;
|
||||
}
|
||||
if (scene_ == "newgame" && key == Rml::Input::KI_RETURN) {
|
||||
bool button = false;
|
||||
for (auto *n = target; n && n != doc_; n = n->GetParentNode())
|
||||
if (n->GetTagName() == "button")
|
||||
button = true;
|
||||
if (!button) {
|
||||
entry_action("setup-next", nullptr);
|
||||
event.StopImmediatePropagation();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (target->GetId() == "manager-name" && key == Rml::Input::KI_RETURN) {
|
||||
entry_action("manager-next", nullptr);
|
||||
event.StopImmediatePropagation();
|
||||
return true;
|
||||
}
|
||||
if (target->GetAttribute<Rml::String>("role", "") == "radio" &&
|
||||
(key == Rml::Input::KI_LEFT || key == Rml::Input::KI_RIGHT ||
|
||||
key == Rml::Input::KI_UP || key == Rml::Input::KI_DOWN ||
|
||||
key == Rml::Input::KI_HOME || key == Rml::Input::KI_END)) {
|
||||
int selected = std::stoi(
|
||||
selections_["portrait"].empty() ? "0" : selections_["portrait"]);
|
||||
int next = key == Rml::Input::KI_HOME ? 0
|
||||
: key == Rml::Input::KI_END ? 11
|
||||
: selected;
|
||||
const int step = key == Rml::Input::KI_LEFT || key == Rml::Input::KI_UP ||
|
||||
key == Rml::Input::KI_END
|
||||
? -1
|
||||
: 1;
|
||||
if (key != Rml::Input::KI_HOME && key != Rml::Input::KI_END)
|
||||
next = (next +
|
||||
((key == Rml::Input::KI_UP || key == Rml::Input::KI_DOWN)
|
||||
? step * 6
|
||||
: step) +
|
||||
12) %
|
||||
12;
|
||||
for (int tries = 0; tries < 12 && entry_used_portrait(next); ++tries)
|
||||
next = (next + step + 12) % 12;
|
||||
if (auto *node = element("manager-portrait-" + std::to_string(next)))
|
||||
entry_action("portrait", node);
|
||||
event.StopImmediatePropagation();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (type == "mouseup" && event.GetParameter<int>("button", 0) == 1 &&
|
||||
scene_ == "newgame") {
|
||||
entry_action("setup-next", nullptr);
|
||||
event.StopImmediatePropagation();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Json App::entry_snapshot() const {
|
||||
return {{"setup", start_options_},
|
||||
{"managers", managers_draft_},
|
||||
{"adding", adding_manager_},
|
||||
{"index", manager_index_},
|
||||
{"picker", manager_picker_},
|
||||
{"query", club_search_},
|
||||
{"confirm", manager_confirm_},
|
||||
{"success", manager_success_},
|
||||
{"selected_club", selected_club_},
|
||||
{"country", country_},
|
||||
{"league", league_},
|
||||
{"name_valid", entry_name_valid()},
|
||||
{"return_scene", entry_return_scene_},
|
||||
{"name", selections_.contains("manager-name")
|
||||
? selections_.at("manager-name")
|
||||
: ""},
|
||||
{"portrait",
|
||||
selections_.contains("portrait") ? selections_.at("portrait") : "0"},
|
||||
{"draft_world", entry_catalog_
|
||||
? Json(entry_catalog_->manifest().value("id", ""))
|
||||
: Json()}};
|
||||
}
|
||||
@@ -0,0 +1,399 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
// App rendering only. Lifecycle, validation and input dispatch live in the
|
||||
// owner. Required App API: entry_world() -> shared_ptr<const Catalog>,
|
||||
// entry_name_valid(), entry_used_club(id), entry_used_portrait(index),
|
||||
// entry_full(). Required state: club_search_, manager_confirm_,
|
||||
// manager_success_; existing start_options_, managers_draft_, selections_,
|
||||
// country_, league_, selected_club_, manager_index_, manager_picker_,
|
||||
// adding_manager_ remain the draft contract.
|
||||
std::string App::render_newgame() {
|
||||
const std::array<const char *, 4> keys = {"duration", "difficulty", "players",
|
||||
"mode"};
|
||||
const std::array<const char *, 4> names = {"Spieldauer", "Schwierigkeit",
|
||||
"Mitspieler", "Modus"};
|
||||
const std::array<int, 4> limits = {
|
||||
5, 10, start_options_.value("league", true) ? 4 : 1, 3};
|
||||
std::string body =
|
||||
"<section class=\"entry-setup\"><header class=\"entry-setup-heading\">"
|
||||
"<h2>Grundeinstellungen</h2><p>Zuerst die Partie, dann die Manager.</p>"
|
||||
"</header><div class=\"entry-setup-options\">";
|
||||
for (size_t i = 0; i < keys.size(); ++i) {
|
||||
const std::string key = keys[i];
|
||||
const int value = start_options_.value(key, 1);
|
||||
std::string visual, caption;
|
||||
if (i == 0) {
|
||||
visual = "<strong class=\"entry-setup-duration\">" +
|
||||
std::string(value == 5 ? "∞" : std::to_string(value)) +
|
||||
"</strong>";
|
||||
caption = value == 5 ? "Unbegrenzt" : value == 1 ? "Saison" : "Saisons";
|
||||
} else if (i == 1) {
|
||||
const int columns = std::min(value, 5), rows = value > 5 ? 2 : 1;
|
||||
visual = "<div class=\"entry-setup-balls\" style=\"width:" +
|
||||
std::to_string(columns * 102 - 10) + "dp;\">";
|
||||
for (int n = 0; n < value; ++n)
|
||||
visual += "<div style=\"position:absolute;" +
|
||||
rect((n % columns) * 102,
|
||||
(n / columns) * 102 + (rows == 1 ? 51 : 0), 92, 92) +
|
||||
"\">" + glyph("ball", 92) + "</div>";
|
||||
visual += "</div>";
|
||||
caption = "Spielstärke " + std::to_string(value) + " von 10";
|
||||
} else if (i == 2) {
|
||||
visual = "<div class=\"entry-setup-people\">";
|
||||
for (int n = 0; n < value; ++n)
|
||||
visual += glyph("person", 84);
|
||||
visual += "</div>";
|
||||
caption = std::to_string(value) + " Mitspieler";
|
||||
} else {
|
||||
visual = "<strong class=\"entry-setup-mode\">" +
|
||||
std::string(value == 1 ? "I"
|
||||
: value == 2 ? "II"
|
||||
: "III") +
|
||||
"</strong>";
|
||||
caption = value == 1 ? "Grundfunktionen"
|
||||
: value == 2 ? "Erweiterte Funktionen"
|
||||
: "Alle Funktionen";
|
||||
}
|
||||
body += "<section class=\"entry-setup-option\" style=\"" +
|
||||
rect((i % 2) * 1320, (i / 2) * 719, 1292, 691) +
|
||||
"\" aria-labelledby=\"setup-label-" + key +
|
||||
"\"><h2 id=\"setup-label-" + key + "\">" + names[i] +
|
||||
"</h2><div class=\"entry-setup-stepper\">";
|
||||
body += btn("setup-step", "−", "entry-setup-minus",
|
||||
"id=\"setup-" + key + "-minus\" data-id=\"" + key +
|
||||
"\" data-step=\"-1\" aria-label=\"" + names[i] +
|
||||
" verringern\" " + (value == 1 ? "disabled" : ""));
|
||||
body += "<div id=\"setup-value-" + key +
|
||||
"\" class=\"entry-setup-value\" aria-live=\"polite\">" + visual +
|
||||
"<span>" + caption + "</span></div>";
|
||||
body += btn("setup-step", "+", "entry-setup-plus",
|
||||
"id=\"setup-" + key + "-plus\" data-id=\"" + key +
|
||||
"\" data-step=\"1\" aria-label=\"" + names[i] +
|
||||
" erhöhen\" " + (value == limits[i] ? "disabled" : "")) +
|
||||
"</div></section>";
|
||||
}
|
||||
body += "</div><section class=\"entry-setup-competitions\" "
|
||||
"aria-label=\"Wettbewerbe\">";
|
||||
for (const auto *key : {"league", "world"}) {
|
||||
const bool league = std::string(key) == "league",
|
||||
active = start_options_.value(key, true),
|
||||
locked =
|
||||
league ? active && (start_options_.value("players", 1) > 1 ||
|
||||
!start_options_.value("world", true))
|
||||
: !start_options_.value("league", true);
|
||||
body += btn(
|
||||
"setup-competition",
|
||||
glyph(league ? "pitch" : "world", 70) + "<span><strong>" +
|
||||
std::string(league ? "Ligaspiel" : "WM / EM") + "</strong><small>" +
|
||||
(active ? "Aktiv" : "Aus") + "</small></span>",
|
||||
"entry-setup-competition " + std::string(active ? "selected" : ""),
|
||||
"id=\"setup-competition-" + std::string(key) + "\" data-id=\"" + key +
|
||||
"\" aria-pressed=\"" + (active ? "true" : "false") + "\" " +
|
||||
(locked ? "disabled" : ""));
|
||||
}
|
||||
const std::string hint =
|
||||
start_options_.value("players", 1) > 1
|
||||
? "Bei mehreren Mitspielern bleibt das Ligaspiel aktiv."
|
||||
: !start_options_.value("league", true)
|
||||
? "WM / EM allein ist mit einem Mitspieler möglich."
|
||||
: "Mindestens ein Wettbewerb bleibt aktiv.";
|
||||
body += "<p role=\"status\">" + hint +
|
||||
"</p></section><footer class=\"entry-setup-actions\"><p>Deine "
|
||||
"Auswahl wird beim Spielstart übernommen.</p><div>" +
|
||||
btn("close", "Abbrechen") +
|
||||
btn("setup-next", "Weiter", "primary", "id=\"setup-next\"") +
|
||||
"</div></footer></section>";
|
||||
return window("Neues Spiel", body);
|
||||
}
|
||||
|
||||
std::string App::render_manager() {
|
||||
const auto catalog = entry_world();
|
||||
if (!catalog)
|
||||
return window("Neuer Spieler",
|
||||
"<p>Bitte zuerst eine Modern-Mod aktivieren.</p>");
|
||||
const bool full = entry_full(), modal = manager_confirm_ || manager_success_;
|
||||
const int limit = adding_manager_ ? 4 : start_options_.value("players", 1);
|
||||
const int portrait =
|
||||
selections_["portrait"].empty() ? 0 : std::stoi(selections_["portrait"]);
|
||||
const std::string style =
|
||||
selections_["portrait-style"] == "painted" ? "painted" : "photo";
|
||||
const std::array<const char *, 3> strengths = {
|
||||
"Unteres Drittel", "Mittelfeld", "Oberes Drittel"};
|
||||
const int strength =
|
||||
std::clamp(selections_["manager-strength"].empty()
|
||||
? 1
|
||||
: std::stoi(selections_["manager-strength"]),
|
||||
0, 2);
|
||||
const auto face = [&](int index, const std::string &variant, int width,
|
||||
const std::string &extra = "") {
|
||||
return "<div class=\"entry-manager-face " + extra +
|
||||
"\" role=\"img\" aria-label=\"Fiktives Managerporträt " +
|
||||
std::to_string(index + 1) +
|
||||
(variant == "painted" ? ", Illustration" : ", Foto") + "\">" +
|
||||
img(std::string(variant == "painted" ? "manager-painted."
|
||||
: "manager.") +
|
||||
std::to_string(index),
|
||||
width, width * 4.0 / 3.0, false, true, 350) +
|
||||
"</div>";
|
||||
};
|
||||
const auto club_name = [&](const Json *c) {
|
||||
return c ? catalog->name(*c) : std::string("Kein spielbarer Verein");
|
||||
};
|
||||
const auto league_name = [&](const Json *c) {
|
||||
const auto *l =
|
||||
c ? catalog->find("competitions", c->value("competition", ""))
|
||||
: nullptr;
|
||||
return l ? catalog->name(*l) : std::string();
|
||||
};
|
||||
std::vector<std::pair<std::string, std::string>> countries, choices;
|
||||
std::set<std::string> seen;
|
||||
for (const auto *l : catalog->leagues()) {
|
||||
const auto id = l->value("nation", "");
|
||||
if (seen.insert(id).second)
|
||||
countries.emplace_back(id, catalog->nation_name(id));
|
||||
}
|
||||
const auto leagues = catalog->leagues(country_);
|
||||
for (const auto *l : leagues)
|
||||
choices.emplace_back(l->value("id", ""), catalog->name(*l));
|
||||
const auto choose =
|
||||
[&](const std::string &id,
|
||||
const std::vector<std::pair<std::string, std::string>> &rows,
|
||||
const std::string &value) {
|
||||
auto out = select(id, rows, value, id);
|
||||
if (full)
|
||||
out.insert(out.find('>'), " disabled");
|
||||
return out;
|
||||
};
|
||||
const auto *selected = catalog->find("clubs", selected_club_);
|
||||
std::string content;
|
||||
if (manager_picker_) {
|
||||
const auto query = settings_search_key(club_search_);
|
||||
std::vector<const Json *> clubs;
|
||||
for (const auto *c : catalog->clubs(league_))
|
||||
if (query.empty() || settings_search_key(catalog->name(*c)).find(query) !=
|
||||
std::string::npos)
|
||||
clubs.push_back(c);
|
||||
content =
|
||||
"<section class=\"entry-club-picker\"><header><div><h2>Verein "
|
||||
"auswählen</h2><p>Wähle ein Wappen für deinen neuen "
|
||||
"Manager.</p></div>" +
|
||||
btn("manager-clubs-back", "Zurück", {}, "id=\"manager-clubs-back\"") +
|
||||
"</header><div class=\"entry-club-filters\"><div>" +
|
||||
choose("manager-country", countries, country_) +
|
||||
choose("manager-league", choices, league_) +
|
||||
"</div><label><input type=\"search\" id=\"manager-club-search\" "
|
||||
"data-input=\"manager-search\" maxlength=\"60\" placeholder=\"Verein "
|
||||
"suchen\" aria-label=\"Verein in dieser Liga suchen\" value=\"" +
|
||||
esc(club_search_) +
|
||||
"\"/></label></div><section class=\"entry-club-results\"><p "
|
||||
"class=\"entry-club-count\" role=\"status\">" +
|
||||
std::to_string(clubs.size()) +
|
||||
(clubs.size() == 1 ? " Verein" : " Vereine") +
|
||||
"</p><div class=\"entry-club-grid\" id=\"manager-club-grid\">";
|
||||
const int rows = std::max(1, int((clubs.size() + 4) / 5));
|
||||
const double height = std::max(250.0, (1583.0 - (rows - 1) * 20) / rows);
|
||||
content += "<div class=\"entry-club-grid-content\" style=\"height:" +
|
||||
scalar(rows * (height + 20) - 20 + 8) + "dp;\">";
|
||||
for (size_t i = 0; i < clubs.size(); ++i) {
|
||||
const auto *c = clubs[i];
|
||||
const auto id = c->value("id", "");
|
||||
const bool locked = !catalog->manageable(id), used = entry_used_club(id),
|
||||
chosen = id == selected_club_;
|
||||
const std::string note = locked ? "Nicht spielbar · nur deutsche Vereine"
|
||||
: used ? "Bereits vergeben"
|
||||
: chosen ? "Ausgewählt"
|
||||
: league_name(c);
|
||||
content +=
|
||||
btn("manager-club",
|
||||
"<div class=\"entry-club-crest\">" + crest(c, 120) +
|
||||
"</div><strong>" + esc(club_name(c)) +
|
||||
"</strong><small class=\"entry-choice-status\">" +
|
||||
(chosen && !used && !locked ? glyph("check", 20) : "") +
|
||||
"<span>" + esc(note) + "</span></small>" +
|
||||
(locked ? "<span class=\"entry-club-lock\">" +
|
||||
glyph("lock", 32) + "</span>"
|
||||
: ""),
|
||||
"entry-club-choice " + std::string(chosen ? "selected" : ""),
|
||||
"id=\"manager-team-" + std::to_string(i) + "\" data-id=\"" +
|
||||
esc(id) + "\" aria-pressed=\"" + (chosen ? "true" : "false") +
|
||||
"\" style=\"position:absolute;" +
|
||||
rect(4 + (i % 5) * 521.2, 4 + (i / 5) * (height + 20), 501.2,
|
||||
height) +
|
||||
"\" " + (locked || used || full ? "disabled" : ""));
|
||||
}
|
||||
if (clubs.empty())
|
||||
content += "<p class=\"entry-no-clubs\">Kein Verein mit diesem Namen in "
|
||||
"dieser Liga.</p>";
|
||||
content += "</div></div></section></section>";
|
||||
} else {
|
||||
content =
|
||||
"<section class=\"entry-manager-layout " +
|
||||
std::string(adding_manager_ ? "is-add" : "") +
|
||||
"\"><header class=\"entry-manager-step\"><span>" +
|
||||
(full ? std::string("Vier Mitspieler im Spiel")
|
||||
: "Mitspieler " + std::to_string(manager_index_ + 1) + " von " +
|
||||
std::to_string(limit)) +
|
||||
"</span><p>Dein Name. Dein Verein. Dein Porträt.</p>" +
|
||||
(adding_manager_ ? btn("manager-newgame", "Neues Spiel", {},
|
||||
"id=\"manager-newgame\"")
|
||||
: "") +
|
||||
"</header><div class=\"entry-manager-fields " +
|
||||
std::string(full ? "is-full" : "") +
|
||||
"\"><div class=\"entry-manager-identity\"><section "
|
||||
"class=\"entry-manager-person-card\"><div "
|
||||
"class=\"entry-manager-person-copy\"><label "
|
||||
"for=\"manager-name\">Managername</label><input id=\"manager-name\" "
|
||||
"data-input=\"manager-name\" maxlength=\"24\" value=\"" +
|
||||
esc(selections_["manager-name"]) +
|
||||
"\" aria-describedby=\"manager-name-note\" " +
|
||||
(full ? "disabled" : "") +
|
||||
"/><p id=\"manager-name-note\">So wirst du im Spiel "
|
||||
"angesprochen.</p><span class=\"entry-manager-profile-tag\">Porträt " +
|
||||
std::to_string(portrait + 1) + "</span></div>" +
|
||||
face(portrait, style, 174) +
|
||||
"</section><section class=\"entry-manager-club-card\"><h2>Verein</h2>" +
|
||||
btn("manager-clubs",
|
||||
"<div class=\"entry-manager-club-crest\">" + crest(selected, 176) +
|
||||
"</div><span><strong>" + esc(club_name(selected)) +
|
||||
"</strong><small>" +
|
||||
esc(selected
|
||||
? catalog->nation_name(selected->value("nation", ""))
|
||||
: "") +
|
||||
" · " + esc(league_name(selected)) +
|
||||
"</small><em>Verein wählen <span>›</span></em></span>",
|
||||
"entry-manager-club-button",
|
||||
"id=\"manager-clubs\" aria-label=\"Verein wählen: " +
|
||||
esc(club_name(selected)) + "\" " + (full ? "disabled" : "")) +
|
||||
"</section></div><div "
|
||||
"class=\"entry-manager-options\"><section><h2>Startliga</h2><div>" +
|
||||
choose("manager-country", countries, country_) +
|
||||
choose("manager-league", choices, league_) +
|
||||
"</div></section><section><h2>Vereinsstärke</h2>" +
|
||||
choose("manager-strength",
|
||||
{{"0", strengths[0]}, {"1", strengths[1]}, {"2", strengths[2]}},
|
||||
std::to_string(strength)) +
|
||||
"</section></div><div class=\"entry-manager-choices\"><section "
|
||||
"class=\"entry-manager-portrait-section\"><header><h2>Managerporträt</"
|
||||
"h2><div class=\"entry-manager-portrait-styles\" role=\"group\" "
|
||||
"aria-label=\"Porträtvariante\">";
|
||||
for (const auto *variant : {"photo", "painted"})
|
||||
content +=
|
||||
btn("portrait-style",
|
||||
std::string(variant) == "photo" ? "Foto" : "Illustration", {},
|
||||
"id=\"manager-style-" + std::string(variant) + "\" data-id=\"" +
|
||||
variant + "\" aria-pressed=\"" +
|
||||
(style == variant ? "true" : "false") + "\" " +
|
||||
(full ? "disabled" : ""));
|
||||
content += "</div></header><div class=\"entry-manager-portraits\" "
|
||||
"role=\"radiogroup\" aria-label=\"Managerporträt\">";
|
||||
const int portrait_height = adding_manager_ ? 482 : 494;
|
||||
for (int i = 0; i < 12; ++i) {
|
||||
const bool used = entry_used_portrait(i), chosen = i == portrait;
|
||||
content +=
|
||||
btn("portrait",
|
||||
face(i, style, 174) +
|
||||
"<span class=\"entry-manager-portrait-caption\">" +
|
||||
(chosen && !used ? glyph("check", 20) : "") + "<span>" +
|
||||
(used ? "Vergeben"
|
||||
: chosen ? "Ausgewählt"
|
||||
: "Porträt " + std::to_string(i + 1)) +
|
||||
"</span></span>",
|
||||
"entry-manager-portrait " + std::string(chosen ? "selected" : ""),
|
||||
"id=\"manager-portrait-" + std::to_string(i) + "\" data-id=\"" +
|
||||
std::to_string(i) + "\" role=\"radio\" aria-checked=\"" +
|
||||
(chosen ? "true" : "false") + "\" aria-label=\"Porträt " +
|
||||
std::to_string(i + 1) + (used ? ", bereits vergeben" : "") +
|
||||
"\" tabindex=\"" + (chosen ? "0" : "-1") +
|
||||
"\" style=\"position:absolute;" +
|
||||
rect((i % 6) * 324, (i / 6) * (portrait_height + 16), 308,
|
||||
portrait_height) +
|
||||
"\" " + (used || full ? "disabled" : ""));
|
||||
}
|
||||
content +=
|
||||
"</div></section><aside class=\"entry-manager-roster\"><header><h2>" +
|
||||
std::string(adding_manager_ ? "Bereits im Spiel"
|
||||
: "Mitspieler dieser Partie") +
|
||||
"</h2><span>" + std::to_string(managers_draft_.size()) + " / " +
|
||||
std::to_string(limit) +
|
||||
"</span></header><div class=\"entry-manager-roster-list\">";
|
||||
for (size_t i = 0; i < managers_draft_.size(); ++i) {
|
||||
const auto &m = managers_draft_[i];
|
||||
const auto *c = catalog->find("clubs", m.value("club", ""));
|
||||
content +=
|
||||
"<div class=\"entry-manager-roster-row\">" +
|
||||
face(m.value("portrait", 0), m.value("portrait_style", style), 90) +
|
||||
"<div><small>Spieler " + std::to_string(i + 1) + "</small><strong>" +
|
||||
esc(m.value("name", "")) + "</strong><span>" + esc(club_name(c)) +
|
||||
"</span></div></div>";
|
||||
}
|
||||
const int remaining = std::max(0, limit - int(managers_draft_.size()));
|
||||
content +=
|
||||
"</div><p>" +
|
||||
(full ? std::string("Alle vier Plätze sind belegt.")
|
||||
: std::to_string(remaining) + (remaining == 1
|
||||
? " weiterer Platz frei"
|
||||
: " weitere Plätze frei")) +
|
||||
"</p></aside></div></div></section><footer "
|
||||
"class=\"entry-manager-actions\"><p id=\"manager-feedback\" "
|
||||
"role=\"status\">" +
|
||||
(full ? std::string("Es können höchstens vier Manager mitspielen.")
|
||||
: adding_manager_
|
||||
? "Mitspieler wird erst nach deiner Bestätigung hinzugefügt."
|
||||
: "Bestätige nacheinander die Mitspieler für deine neue Partie.") +
|
||||
"</p><div>" +
|
||||
btn("manager-back",
|
||||
full ? "Schließen"
|
||||
: adding_manager_ ? "Abbrechen"
|
||||
: "Zurück",
|
||||
{}, "id=\"manager-back\"") +
|
||||
btn("manager-next",
|
||||
adding_manager_ ? "Mitspieler hinzufügen"
|
||||
: manager_index_ + 1 == limit ? "Spiel starten"
|
||||
: "Mitspieler bestätigen",
|
||||
"primary",
|
||||
"id=\"manager-next\" " +
|
||||
std::string(full || !entry_name_valid() || !selected ||
|
||||
!catalog->manageable(selected_club_) ||
|
||||
entry_used_club(selected_club_) ||
|
||||
entry_used_portrait(portrait)
|
||||
? "disabled"
|
||||
: "")) +
|
||||
"</div></footer>";
|
||||
}
|
||||
std::string body =
|
||||
"<div id=\"entry-manager-underlay\" class=\"entry-manager-underlay\" " +
|
||||
std::string(modal ? "aria-hidden=\"true\"" : "") + ">" + content +
|
||||
"</div>";
|
||||
if (manager_confirm_) {
|
||||
body +=
|
||||
"<div id=\"entry-confirm-layer\" class=\"entry-dialog-layer\"><section "
|
||||
"class=\"entry-dialog entry-confirm-dialog\" role=\"dialog\" "
|
||||
"aria-modal=\"true\" aria-labelledby=\"entry-confirm-title\"><h2 "
|
||||
"id=\"entry-confirm-title\">Sind alle Angaben richtig?</h2><div "
|
||||
"class=\"entry-confirm-identity\"><div class=\"entry-confirm-crest\">" +
|
||||
crest(selected, 200) +
|
||||
"</div><div class=\"entry-confirm-copy\"><strong>" +
|
||||
esc(selections_["manager-name"]) + "</strong><span>" +
|
||||
esc(club_name(selected)) + "</span><small>" +
|
||||
esc(league_name(selected)) + " · " + strengths[size_t(strength)] +
|
||||
"</small></div>" + face(portrait, style, 150) + "</div><footer>" +
|
||||
btn("manager-confirm-no", "Nein", {}, "id=\"manager-confirm-no\"") +
|
||||
btn("manager-confirm-yes", "Ja", "primary",
|
||||
"id=\"manager-confirm-yes\"") +
|
||||
"</footer></section></div>";
|
||||
} else if (manager_success_) {
|
||||
const auto &last =
|
||||
managers_draft_.empty() ? Json::object() : managers_draft_.back();
|
||||
const auto *c = catalog->find("clubs", last.value("club", selected_club_));
|
||||
body +=
|
||||
"<div id=\"entry-success-layer\" class=\"entry-dialog-layer\"><section "
|
||||
"class=\"entry-dialog entry-success-dialog\" role=\"dialog\" "
|
||||
"aria-modal=\"true\" aria-labelledby=\"entry-success-title\"><h2 "
|
||||
"id=\"entry-success-title\">Mitspieler hinzugefügt</h2><p>" +
|
||||
esc(last.value("name", selections_["manager-name"])) + " übernimmt " +
|
||||
esc(club_name(c)) + ".</p><footer>" +
|
||||
btn("manager-success-close", "Verstanden", {},
|
||||
"id=\"manager-success-close\"") +
|
||||
"</footer></section></div>";
|
||||
}
|
||||
return window("Neuer Spieler", body);
|
||||
}
|
||||
+211
-58
@@ -1,25 +1,140 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/ui/model.hpp"
|
||||
#include "modern/ui/demo_almanac.hpp"
|
||||
#include "modern/ui/demo_finance.hpp"
|
||||
#include "modern/ui/demo_environment.hpp"
|
||||
#include "modern/ui/demo_advertising.hpp"
|
||||
#include "modern/ui/demo_toto.hpp"
|
||||
#include "modern/ui/demo_almanac.hpp"
|
||||
#include "modern/ui/demo_calendar.hpp"
|
||||
#include "modern/ui/demo_reports.hpp"
|
||||
#include "modern/ui/demo_sports.hpp"
|
||||
#include "modern/ui/demo_environment.hpp"
|
||||
#include "modern/ui/demo_finance.hpp"
|
||||
#include "modern/ui/demo_lineup.hpp"
|
||||
#include "modern/ui/demo_transfer.hpp"
|
||||
#include "modern/ui/demo_news.hpp"
|
||||
#include "modern/ui/demo_reports.hpp"
|
||||
#include "modern/ui/demo_settings.hpp"
|
||||
#include "modern/ui/demo_sports.hpp"
|
||||
#include "modern/ui/demo_stadium.hpp"
|
||||
#include "modern/ui/demo_statistics.hpp"
|
||||
#include "modern/ui/demo_news.hpp"
|
||||
#include "modern/ui/demo_settings.hpp"
|
||||
#include "modern/ui/demo_toto.hpp"
|
||||
#include "modern/ui/demo_transfer.hpp"
|
||||
#include "modern/ui/desktop.hpp"
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
|
||||
namespace bmh::modern_ui {
|
||||
std::optional<std::string> normalized_manager_name(std::string_view raw) {
|
||||
const auto whitespace = [](uint32_t c) {
|
||||
return c == 0x20 || c == 0xa0 || c == 0x1680 ||
|
||||
(c >= 0x2000 && c <= 0x200a) || c == 0x2028 || c == 0x2029 ||
|
||||
c == 0x202f || c == 0x205f || c == 0x3000 || c == 0xfeff;
|
||||
};
|
||||
size_t first = raw.size(), last = 0, count = 0, pending_spaces = 0;
|
||||
for (size_t at = 0; at < raw.size();) {
|
||||
const auto start = at;
|
||||
const auto byte = uint8_t(raw[at++]);
|
||||
uint32_t value = byte;
|
||||
int remaining = 0;
|
||||
if (byte >= 0xc2 && byte <= 0xdf) {
|
||||
value &= 31;
|
||||
remaining = 1;
|
||||
} else if (byte >= 0xe0 && byte <= 0xef) {
|
||||
value &= 15;
|
||||
remaining = 2;
|
||||
} else if (byte >= 0xf0 && byte <= 0xf4) {
|
||||
value &= 7;
|
||||
remaining = 3;
|
||||
} else if (byte >= 128)
|
||||
return {};
|
||||
const auto encoded_length = remaining;
|
||||
while (remaining--) {
|
||||
if (at == raw.size() || (uint8_t(raw[at]) & 0xc0) != 0x80)
|
||||
return {};
|
||||
value = value * 64 + (uint8_t(raw[at++]) & 63);
|
||||
}
|
||||
if ((encoded_length == 1 && value < 0x80) ||
|
||||
(encoded_length == 2 && value < 0x800) ||
|
||||
(encoded_length == 3 && value < 0x10000) || value > 0x10ffff ||
|
||||
(value >= 0xd800 && value <= 0xdfff) || value < 32 ||
|
||||
(value >= 127 && value <= 159))
|
||||
return {};
|
||||
if (whitespace(value)) {
|
||||
if (count)
|
||||
pending_spaces = std::min(size_t(25), pending_spaces + 1);
|
||||
continue;
|
||||
}
|
||||
if (!count)
|
||||
first = start;
|
||||
count += pending_spaces + 1;
|
||||
pending_spaces = 0;
|
||||
if (count > 24)
|
||||
return {};
|
||||
last = at;
|
||||
}
|
||||
if (!count)
|
||||
return {};
|
||||
return std::string(raw.substr(first, last - first));
|
||||
}
|
||||
namespace {
|
||||
bool bounded_integer(const Json &value, int low, int high) {
|
||||
if (!value.is_number_integer())
|
||||
return false;
|
||||
if (value.is_number_unsigned())
|
||||
return value.get<uint64_t>() >= uint64_t(low) &&
|
||||
value.get<uint64_t>() <= uint64_t(high);
|
||||
return value.get<int64_t>() >= low && value.get<int64_t>() <= high;
|
||||
}
|
||||
bool valid_start_setup(const Json &value) {
|
||||
if (!value.is_object() || value.size() != 6)
|
||||
return false;
|
||||
for (const auto &[key, range] :
|
||||
std::vector<std::pair<std::string, std::pair<int, int>>>{
|
||||
{"duration", {1, 5}},
|
||||
{"difficulty", {1, 10}},
|
||||
{"players", {1, 4}},
|
||||
{"mode", {1, 3}}})
|
||||
if (!value.contains(key) ||
|
||||
!bounded_integer(value.at(key), range.first, range.second))
|
||||
return false;
|
||||
if (!value.contains("league") || !value.at("league").is_boolean() ||
|
||||
!value.contains("world") || !value.at("world").is_boolean())
|
||||
return false;
|
||||
const bool league = value.at("league").get<bool>(),
|
||||
world = value.at("world").get<bool>();
|
||||
return (league || world) && (league || value.at("players").get<int>() == 1);
|
||||
}
|
||||
std::string normalized_managers(const Json &raw, const Catalog &world,
|
||||
Json &output) {
|
||||
if (!raw.is_array() || raw.empty() || raw.size() > 4)
|
||||
return "invalid_managers";
|
||||
std::set<std::string> clubs;
|
||||
std::set<int> portraits;
|
||||
output = Json::array();
|
||||
for (const auto &value : raw) {
|
||||
if (!value.is_object() || !value.contains("club") ||
|
||||
!value.at("club").is_string() || !value.contains("name") ||
|
||||
!value.at("name").is_string())
|
||||
return "invalid_manager";
|
||||
const auto club = value.at("club").get<std::string>();
|
||||
if (!world.manageable(club))
|
||||
return "club_locked";
|
||||
const auto name =
|
||||
normalized_manager_name(value.at("name").get<std::string>());
|
||||
const Json portrait = value.value("portrait", Json(0)),
|
||||
strength = value.value("strength_choice", Json(1));
|
||||
const Json style = value.value("portrait_style", Json("photo"));
|
||||
if (!name || !bounded_integer(portrait, 0, 11) ||
|
||||
!bounded_integer(strength, 0, 2) || !style.is_string() ||
|
||||
(style.get<std::string>() != "photo" &&
|
||||
style.get<std::string>() != "painted") ||
|
||||
!clubs.insert(club).second ||
|
||||
!portraits.insert(portrait.get<int>()).second)
|
||||
return "invalid_manager";
|
||||
auto manager = value;
|
||||
manager["name"] = *name;
|
||||
manager["portrait"] = portrait;
|
||||
manager["portrait_style"] = style;
|
||||
manager["strength_choice"] = strength;
|
||||
output.push_back(std::move(manager));
|
||||
}
|
||||
return {};
|
||||
}
|
||||
bool valid_date(const Json &value) {
|
||||
if (!value.is_string())
|
||||
return false;
|
||||
@@ -73,9 +188,11 @@ DemoSource::DemoSource(std::shared_ptr<const Catalog> catalog)
|
||||
{"schema", "openbmh-ui-demo@1"},
|
||||
{"world", catalog_->manifest().value("id", "")},
|
||||
{"date", catalog_->manifest().value("start_date", "2026-07-01")},
|
||||
{"managers",
|
||||
Json::array(
|
||||
{{{"name", "Alex Berger"}, {"club", club}, {"portrait", 0}}})},
|
||||
{"managers", Json::array({{{"name", "Alex Berger"},
|
||||
{"club", club},
|
||||
{"portrait", 0},
|
||||
{"portrait_style", "photo"},
|
||||
{"strength_choice", 1}}})},
|
||||
{"cash", 12450000},
|
||||
{"deposit", 600000},
|
||||
{"debt", 0},
|
||||
@@ -96,9 +213,12 @@ DemoSource::DemoSource(std::shared_ptr<const Catalog> catalog)
|
||||
state_["reports"] = demo_reports(*catalog_);
|
||||
if (!migrate_demo_finance(state_, *catalog_, club))
|
||||
throw editor::Error("invalid_demo_finance");
|
||||
if (!migrate_demo_environment(state_, *catalog_) || !migrate_demo_advertising(state_, *catalog_) || !migrate_demo_toto(state_, *catalog_))
|
||||
if (!migrate_demo_environment(state_, *catalog_) ||
|
||||
!migrate_demo_advertising(state_, *catalog_) ||
|
||||
!migrate_demo_toto(state_, *catalog_))
|
||||
throw editor::Error("invalid_demo_club");
|
||||
if (!migrate_demo_lineup(state_, *catalog_, club) || !migrate_demo_transfer(state_, *catalog_, club))
|
||||
if (!migrate_demo_lineup(state_, *catalog_, club) ||
|
||||
!migrate_demo_transfer(state_, *catalog_, club))
|
||||
throw editor::Error("invalid_demo_squad");
|
||||
if (!migrate_demo_stadium(state_, *catalog_, club))
|
||||
throw editor::Error("invalid_demo_stadium");
|
||||
@@ -122,7 +242,8 @@ ActionResult DemoSource::apply(const Action &action) {
|
||||
try {
|
||||
if (action.kind == "settings") {
|
||||
const auto error = edit_demo_settings(next, action.value);
|
||||
if (!error.empty()) return {false, revision_, error};
|
||||
if (!error.empty())
|
||||
return {false, revision_, error};
|
||||
} else if (action.kind == "news") {
|
||||
const auto error = edit_demo_news(next, action.value, *catalog_);
|
||||
if (!error.empty())
|
||||
@@ -132,25 +253,26 @@ ActionResult DemoSource::apply(const Action &action) {
|
||||
action.value > 25)
|
||||
return {false, revision_, "invalid_demo_ticket"};
|
||||
next["ticket"] = action.value;
|
||||
} else if (action.kind == "managers") {
|
||||
if (!action.value.is_array() || action.value.empty() ||
|
||||
action.value.size() > 4)
|
||||
} else if (action.kind == "managers" || action.kind == "start") {
|
||||
const bool start = action.kind == "start";
|
||||
if (start &&
|
||||
(!action.value.is_object() || !action.value.contains("setup") ||
|
||||
!action.value.contains("managers") ||
|
||||
!valid_start_setup(action.value.at("setup"))))
|
||||
return {false, revision_, "invalid_setup"};
|
||||
const auto &raw = start ? action.value.at("managers") : action.value;
|
||||
if (start &&
|
||||
(!raw.is_array() ||
|
||||
raw.size() !=
|
||||
size_t(action.value.at("setup").at("players").get<int>())))
|
||||
return {false, revision_, "invalid_managers"};
|
||||
std::set<std::string> clubs;
|
||||
std::set<int> portraits;
|
||||
for (const auto &m : action.value) {
|
||||
const auto club = m.at("club").get<std::string>();
|
||||
const auto name = m.at("name").get<std::string>();
|
||||
if (!catalog_->manageable(club))
|
||||
return {false, revision_, "club_locked"};
|
||||
const auto portrait = m.value("portrait", 0);
|
||||
if (name.find_first_not_of(" \t\r\n") == name.npos ||
|
||||
name.size() > 160 || portrait < 0 || portrait > 11 ||
|
||||
!clubs.insert(club).second || !portraits.insert(portrait).second)
|
||||
return {false, revision_, "invalid_manager"};
|
||||
}
|
||||
next["managers"] = action.value;
|
||||
const auto first = action.value.at(0).at("club").get<std::string>();
|
||||
Json managers;
|
||||
const auto error = normalized_managers(raw, *catalog_, managers);
|
||||
if (!error.empty())
|
||||
return {false, revision_, error};
|
||||
next["managers"] = std::move(managers);
|
||||
const auto first =
|
||||
next.at("managers").at(0).at("club").get<std::string>();
|
||||
if (next.at("training").at("club") != first) {
|
||||
next["training"] = demo_training(*catalog_, first);
|
||||
next["tactics"] = demo_tactics();
|
||||
@@ -159,26 +281,48 @@ ActionResult DemoSource::apply(const Action &action) {
|
||||
next["transfer"] = demo_transfer(*catalog_, first);
|
||||
next["stadium"] = demo_stadium(*catalog_, first);
|
||||
next["calendar"] = demo_calendar(*catalog_, next.at("date"), first);
|
||||
const auto error = edit_demo_reports(next["reports"],
|
||||
{{"kind", "league"}, {"value", next["calendar"]["league"]}}, *catalog_);
|
||||
if (!error.empty()) return {false, revision_, error};
|
||||
const auto error = edit_demo_reports(
|
||||
next["reports"],
|
||||
{{"kind", "league"}, {"value", next["calendar"]["league"]}},
|
||||
*catalog_);
|
||||
if (!error.empty())
|
||||
return {false, revision_, error};
|
||||
}
|
||||
} else if (action.kind == "environment" || action.kind == "advertising" || action.kind == "toto") {
|
||||
const auto error = action.kind == "environment" ? edit_demo_environment(next, action.value, *catalog_)
|
||||
: action.kind == "advertising" ? edit_demo_advertising(next, action.value, *catalog_)
|
||||
: edit_demo_toto(next, action.value, *catalog_);
|
||||
if (!error.empty()) return {false, revision_, error};
|
||||
if (start) {
|
||||
next["edits"]["setup"] = action.value.at("setup");
|
||||
next["opening"] = action.value.at("setup").at("league").get<bool>()
|
||||
? "pending"
|
||||
: "complete";
|
||||
next["opening_created"] = false;
|
||||
}
|
||||
} else if (action.kind == "environment" || action.kind == "advertising" ||
|
||||
action.kind == "toto") {
|
||||
const auto error =
|
||||
action.kind == "environment"
|
||||
? edit_demo_environment(next, action.value, *catalog_)
|
||||
: action.kind == "advertising"
|
||||
? edit_demo_advertising(next, action.value, *catalog_)
|
||||
: edit_demo_toto(next, action.value, *catalog_);
|
||||
if (!error.empty())
|
||||
return {false, revision_, error};
|
||||
} else if (action.kind == "lineup" || action.kind == "transfer") {
|
||||
const auto club = next["managers"][0]["club"].get<std::string>();
|
||||
const auto error = action.kind == "lineup" ? edit_demo_lineup(next, action.value, *catalog_, club)
|
||||
: edit_demo_transfer(next, action.value, *catalog_, club);
|
||||
if (!error.empty()) return {false, revision_, error};
|
||||
const auto error =
|
||||
action.kind == "lineup"
|
||||
? edit_demo_lineup(next, action.value, *catalog_, club)
|
||||
: edit_demo_transfer(next, action.value, *catalog_, club);
|
||||
if (!error.empty())
|
||||
return {false, revision_, error};
|
||||
} else if (action.kind == "stadium") {
|
||||
const auto error = edit_demo_stadium(next, action.value, *catalog_, next["managers"][0]["club"]);
|
||||
if (!error.empty()) return {false, revision_, error};
|
||||
const auto error = edit_demo_stadium(next, action.value, *catalog_,
|
||||
next["managers"][0]["club"]);
|
||||
if (!error.empty())
|
||||
return {false, revision_, error};
|
||||
} else if (action.kind == "finance") {
|
||||
const auto error = edit_demo_finance(next, action.value, *catalog_, next["managers"][0]["club"]);
|
||||
if (!error.empty()) return {false, revision_, error};
|
||||
const auto error = edit_demo_finance(next, action.value, *catalog_,
|
||||
next["managers"][0]["club"]);
|
||||
if (!error.empty())
|
||||
return {false, revision_, error};
|
||||
} else if (action.kind == "training") {
|
||||
const auto error = edit_demo_training(next["training"], action.value);
|
||||
if (!error.empty())
|
||||
@@ -188,19 +332,22 @@ ActionResult DemoSource::apply(const Action &action) {
|
||||
if (!error.empty())
|
||||
return {false, revision_, error};
|
||||
} else if (action.kind == "calendar") {
|
||||
const auto error = edit_demo_calendar(next["calendar"], action.value,
|
||||
*catalog_, next["managers"][0]["club"]);
|
||||
const auto error =
|
||||
edit_demo_calendar(next["calendar"], action.value, *catalog_,
|
||||
next["managers"][0]["club"]);
|
||||
if (!error.empty())
|
||||
return {false, revision_, error};
|
||||
if (action.value.value("kind", "") == "league") {
|
||||
const auto report_error = edit_demo_reports(next["reports"],
|
||||
{{"kind", "league"}, {"value", next["calendar"]["league"]}}, *catalog_);
|
||||
const auto report_error = edit_demo_reports(
|
||||
next["reports"],
|
||||
{{"kind", "league"}, {"value", next["calendar"]["league"]}},
|
||||
*catalog_);
|
||||
if (!report_error.empty())
|
||||
return {false, revision_, report_error};
|
||||
}
|
||||
} else if (action.kind == "reports") {
|
||||
const auto error = edit_demo_reports(next["reports"], action.value,
|
||||
*catalog_);
|
||||
const auto error =
|
||||
edit_demo_reports(next["reports"], action.value, *catalog_);
|
||||
if (!error.empty())
|
||||
return {false, revision_, error};
|
||||
next["calendar"]["league"] = next["reports"]["league"];
|
||||
@@ -253,7 +400,8 @@ Json DemoSource::load(const fs::path &file) {
|
||||
return load_data(Json::parse(editor::read_file(file)));
|
||||
}
|
||||
bool DemoSource::mark_saved(uint64_t expected_revision) {
|
||||
if (revision_ != expected_revision) return false;
|
||||
if (revision_ != expected_revision)
|
||||
return false;
|
||||
saved_ = state_;
|
||||
return true;
|
||||
}
|
||||
@@ -265,6 +413,7 @@ Json DemoSource::load_data(Json data) {
|
||||
const auto result = validation.apply({0, "managers", data.at("managers")});
|
||||
if (!result.ok)
|
||||
throw editor::Error(result.error);
|
||||
data["managers"] = validation.snapshot().state.at("managers");
|
||||
const auto club = data.at("managers").at(0).at("club").get<std::string>();
|
||||
if (!data.contains("training"))
|
||||
data["training"] = demo_training(*catalog_, club);
|
||||
@@ -289,7 +438,8 @@ Json DemoSource::load_data(Json data) {
|
||||
throw editor::Error("invalid_demo_calendar");
|
||||
if (!data.contains("reports")) {
|
||||
data["reports"] = demo_reports(*catalog_);
|
||||
const auto error = edit_demo_reports(data["reports"],
|
||||
const auto error = edit_demo_reports(
|
||||
data["reports"],
|
||||
{{"kind", "league"}, {"value", data["calendar"]["league"]}}, *catalog_);
|
||||
if (!error.empty())
|
||||
throw editor::Error(error);
|
||||
@@ -308,9 +458,12 @@ Json DemoSource::load_data(Json data) {
|
||||
throw editor::Error("invalid_focus");
|
||||
if (!migrate_demo_finance(data, *catalog_, club))
|
||||
throw editor::Error("invalid_demo_finance");
|
||||
if (!migrate_demo_environment(data, *catalog_) || !migrate_demo_advertising(data, *catalog_) || !migrate_demo_toto(data, *catalog_))
|
||||
if (!migrate_demo_environment(data, *catalog_) ||
|
||||
!migrate_demo_advertising(data, *catalog_) ||
|
||||
!migrate_demo_toto(data, *catalog_))
|
||||
throw editor::Error("invalid_demo_club");
|
||||
if (!migrate_demo_lineup(data, *catalog_, club) || !migrate_demo_transfer(data, *catalog_, club))
|
||||
if (!migrate_demo_lineup(data, *catalog_, club) ||
|
||||
!migrate_demo_transfer(data, *catalog_, club))
|
||||
throw editor::Error("invalid_demo_squad");
|
||||
if (!migrate_demo_stadium(data, *catalog_, club))
|
||||
throw editor::Error("invalid_demo_stadium");
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
#include "modern/ui/catalog.hpp"
|
||||
#include <optional>
|
||||
#include <string_view>
|
||||
|
||||
namespace bmh::modern_ui {
|
||||
// Shared UI/model boundary: valid UTF-8, trimmed Unicode whitespace, no control
|
||||
// characters, at most 24 codepoints. Invalid input has no normalized value.
|
||||
std::optional<std::string> normalized_manager_name(std::string_view);
|
||||
struct Snapshot {
|
||||
uint64_t revision = 0;
|
||||
std::shared_ptr<const Catalog> world;
|
||||
@@ -37,6 +42,8 @@ class DemoSource final : public DataSource {
|
||||
public:
|
||||
explicit DemoSource(std::shared_ptr<const Catalog>);
|
||||
Snapshot snapshot() const override;
|
||||
// "start" publishes {setup,managers} together; setup is kept in edits.setup
|
||||
// for checkpoint compatibility. It creates presentation state only.
|
||||
ActionResult apply(const Action &) override;
|
||||
Json read_almanac(const Json &) const override;
|
||||
Json read_statistics(const Json &) const override;
|
||||
|
||||
@@ -72,294 +72,6 @@ std::string App::render_desktop() {
|
||||
}
|
||||
return out + "</div>";
|
||||
}
|
||||
std::string App::render_newgame() {
|
||||
std::string body = "<h2>Grundeinstellungen</h2><p class=\"small\" "
|
||||
"style=\"position:absolute;right:0;top:10dp;\">Zuerst die "
|
||||
"Partie, dann die Manager.</p>";
|
||||
const std::array<const char *, 4> keys = {"duration", "difficulty", "players",
|
||||
"mode"};
|
||||
const std::array<const char *, 4> names = {"Spieldauer", "Schwierigkeit",
|
||||
"Mitspieler", "Modus"};
|
||||
const std::array<int, 4> limits = {
|
||||
5, 10, start_options_.value("league", true) ? 4 : 1, 3};
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
const auto key = std::string(keys[size_t(i)]);
|
||||
const int value = start_options_.value(key, 1), x = (i % 2) * 1320,
|
||||
y = 120 + (i / 2) * 716;
|
||||
std::string symbols, caption;
|
||||
if (i == 0) {
|
||||
symbols = "<strong style=\"font-size:210dp;color:var(--accent);\">" +
|
||||
std::string(value == 5 ? "∞" : std::to_string(value)) +
|
||||
"</strong>";
|
||||
caption = value == 5 ? "Unbegrenzt" : value == 1 ? "Saison" : "Saisons";
|
||||
} else if (i == 1) {
|
||||
symbols = "<div style=\"position:relative;width:500dp;height:200dp;\">";
|
||||
const int cols = std::min(value, 5);
|
||||
for (int n = 0; n < value; ++n)
|
||||
symbols += "<div style=\"position:absolute;" +
|
||||
rect((n % cols) * 100,
|
||||
(n / cols) * 100 + (value <= 5 ? 50 : 0), 92, 92) +
|
||||
"\">" + glyph("ball", 92) + "</div>";
|
||||
symbols += "</div>";
|
||||
caption = "Spielstärke " + std::to_string(value) + " von 10";
|
||||
} else if (i == 2) {
|
||||
symbols =
|
||||
"<div class=\"row\" style=\"height:200dp;justify-content:center;\">";
|
||||
for (int n = 0; n < value; ++n)
|
||||
symbols += glyph("person", 110);
|
||||
symbols += "</div>";
|
||||
caption = std::to_string(value) + " Mitspieler";
|
||||
} else {
|
||||
symbols = "<strong style=\"font-size:174dp;color:#dfcb91;\">" +
|
||||
std::string(value == 1 ? "I"
|
||||
: value == 2 ? "II"
|
||||
: "III") +
|
||||
"</strong>";
|
||||
caption = value == 1 ? "Grundfunktionen"
|
||||
: value == 2 ? "Erweiterte Funktionen"
|
||||
: "Alle Funktionen";
|
||||
}
|
||||
body += "<div class=\"panel\" style=\"position:absolute;" +
|
||||
rect(x, y, 1288, 688) +
|
||||
"padding:40dp 30dp;\"><h2 class=\"center\">" + names[size_t(i)] +
|
||||
"</h2><div class=\"row\" "
|
||||
"style=\"position:absolute;left:30dp;right:30dp;top:190dp;justify-"
|
||||
"content:space-between;\">";
|
||||
body +=
|
||||
btn("setup-step", "−", {},
|
||||
"data-id=\"" + key +
|
||||
"\" data-step=\"-1\" "
|
||||
"style=\"width:94dp;height:124dp;padding:0;font-size:72dp;\" " +
|
||||
(value == 1 ? "disabled" : ""));
|
||||
body += "<div class=\"column center\" "
|
||||
"style=\"width:800dp;align-items:center;gap:20dp;\">" +
|
||||
symbols + "<p>" + caption + "</p></div>";
|
||||
body +=
|
||||
btn("setup-step", "+", {},
|
||||
"data-id=\"" + key +
|
||||
"\" data-step=\"1\" "
|
||||
"style=\"width:94dp;height:124dp;padding:0;font-size:72dp;\" " +
|
||||
(value == limits[size_t(i)] ? "disabled" : "")) +
|
||||
"</div></div>";
|
||||
}
|
||||
body += "<div class=\"row\" "
|
||||
"style=\"position:absolute;left:0;right:0;bottom:205dp;\">";
|
||||
for (const auto *key : {"league", "world"}) {
|
||||
const bool league = std::string(key) == "league",
|
||||
active = start_options_.value(key, true),
|
||||
locked = active &&
|
||||
(league ? (start_options_.value("players", 1) > 1 ||
|
||||
!start_options_.value("world", true))
|
||||
: !start_options_.value("league", true));
|
||||
body +=
|
||||
btn("setup-competition",
|
||||
glyph(league ? "pitch" : "world", 70) + "<span>" +
|
||||
(league ? "Ligaspiel" : "WM / EM") + " " +
|
||||
(active ? "Aktiv" : "Aus") + "</span>",
|
||||
active ? "primary row" : "row",
|
||||
"data-id=\"" + std::string(key) +
|
||||
"\" style=\"flex:1;height:126dp;justify-content:center;\" " +
|
||||
(locked ? "disabled" : ""));
|
||||
}
|
||||
body += "</div><p class=\"small center\" "
|
||||
"style=\"position:absolute;left:0;right:0;bottom:155dp;\">Mindestens "
|
||||
"ein Wettbewerb bleibt aktiv.</p><div class=\"bottom-controls\">" +
|
||||
btn("close", "Abbrechen") + btn("setup-next", "Weiter", "primary") +
|
||||
"</div>";
|
||||
return window("Neues Spiel", body);
|
||||
}
|
||||
std::string App::render_manager() {
|
||||
const int limit = adding_manager_ ? 4 : start_options_.value("players", 1);
|
||||
const auto used_club = [&](const std::string &id) {
|
||||
return std::any_of(
|
||||
managers_draft_.begin(), managers_draft_.end(),
|
||||
[&](const auto &m) { return m.value("club", "") == id; });
|
||||
};
|
||||
const auto used_portrait = [&](int id) {
|
||||
return std::any_of(
|
||||
managers_draft_.begin(), managers_draft_.end(),
|
||||
[&](const auto &m) { return m.value("portrait", 0) == id; });
|
||||
};
|
||||
const int portrait =
|
||||
selections_["portrait"].empty() ? 0 : std::stoi(selections_["portrait"]);
|
||||
const auto style = selections_["portrait-style"] == "painted"
|
||||
? "manager-painted."
|
||||
: "manager.";
|
||||
if (!world_->manageable(selected_club_) || used_club(selected_club_))
|
||||
for (auto *c : world_->clubs())
|
||||
if (world_->manageable(c->value("id", "")) &&
|
||||
!used_club(c->value("id", ""))) {
|
||||
selected_club_ = c->value("id", "");
|
||||
break;
|
||||
}
|
||||
std::string body;
|
||||
std::vector<std::pair<std::string, std::string>> countries;
|
||||
std::set<std::string> seen;
|
||||
for (auto *r : world_->leagues()) {
|
||||
const auto id = r->value("nation", "");
|
||||
if (seen.insert(id).second)
|
||||
countries.emplace_back(id, world_->nation_name(id));
|
||||
}
|
||||
auto leagues = world_->leagues(country_);
|
||||
if (std::none_of(leagues.begin(), leagues.end(),
|
||||
[&](auto *r) { return r->value("id", "") == league_; }))
|
||||
league_ = leagues.empty() ? "" : leagues.front()->value("id", "");
|
||||
std::vector<std::pair<std::string, std::string>> choices;
|
||||
for (auto *r : leagues)
|
||||
choices.emplace_back(r->value("id", ""), world_->name(*r));
|
||||
if (manager_picker_) {
|
||||
body =
|
||||
"<div class=\"row\" "
|
||||
"style=\"justify-content:space-between;\"><h2>Verein auswählen</h2>" +
|
||||
btn("manager-clubs-back", "Zurück") +
|
||||
"</div><div class=\"toolbar\" style=\"margin-top:35dp;\">" +
|
||||
select("manager-country", countries, country_, "manager-country") +
|
||||
select("manager-league", choices, league_, "manager-league") +
|
||||
"</div><div class=\"list\" "
|
||||
"style=\"position:absolute;left:0;right:0;top:240dp;bottom:0;\">";
|
||||
const auto clubs = world_->clubs(league_);
|
||||
for (size_t i = 0; i < clubs.size(); ++i) {
|
||||
const auto *c = clubs[i];
|
||||
const auto id = c->value("id", "");
|
||||
const bool locked = !world_->manageable(id), used = used_club(id);
|
||||
const auto x = (i % 4) * 650, y = (i / 4) * 340;
|
||||
body +=
|
||||
"<button data-action=\"manager-club\" data-id=\"" + esc(id) +
|
||||
"\" class=\"choice " +
|
||||
(locked ? "locked"
|
||||
: id == selected_club_ ? "selected"
|
||||
: "") +
|
||||
"\" style=\"position:absolute;" + rect(x, y, 618, 310) +
|
||||
"padding:25dp;\" " + (locked || used ? "disabled" : "") +
|
||||
"><div class=\"center\">" + crest(c, 150) +
|
||||
"</div><p style=\"font-size:30dp;margin-top:15dp;\">" +
|
||||
esc(world_->name(*c)) + "</p>" +
|
||||
(locked ? "<div style=\"position:absolute;right:24dp;top:24dp;\">" +
|
||||
glyph("lock", 40) + "</div>"
|
||||
: "") +
|
||||
"<p class=\"small\" style=\"margin-top:12dp;\">" +
|
||||
(locked ? "Nicht spielbar"
|
||||
: used ? "Bereits vergeben"
|
||||
: id == selected_club_
|
||||
? "Ausgewählt"
|
||||
: esc(world_->name(*world_->find("competitions", league_)))) +
|
||||
"</p></button>";
|
||||
}
|
||||
return window("Neuer Spieler", body + "</div>");
|
||||
}
|
||||
const auto *c = world_->find("clubs", selected_club_);
|
||||
body = "<h2>Mitspieler " + std::to_string(manager_index_ + 1) + " von " +
|
||||
std::to_string(limit) +
|
||||
"</h2><p class=\"small\" "
|
||||
"style=\"position:absolute;right:0;top:10dp;\">Dein Name. Dein "
|
||||
"Verein. Dein Porträt.</p>";
|
||||
body +=
|
||||
"<div class=\"panel\" style=\"position:absolute;" +
|
||||
rect(0, 90, 1288, 330) +
|
||||
"padding:32dp;\"><div "
|
||||
"style=\"position:absolute;left:32dp;top:32dp;width:970dp;\"><label "
|
||||
"class=\"small\">Managername</label><input id=\"manager-name\" "
|
||||
"maxlength=\"24\" value=\"" +
|
||||
esc(selections_["manager-name"]) +
|
||||
"\" style=\"width:100%;font-size:38dp;height:86dp;margin-top:20dp;\"/><p "
|
||||
"class=\"small\" style=\"margin-top:20dp;\">So wirst du im Spiel "
|
||||
"angesprochen.</p><p class=\"small accent\" "
|
||||
"style=\"margin-top:16dp;\">Porträt " +
|
||||
std::to_string(portrait + 1) +
|
||||
"</p></div><div "
|
||||
"style=\"position:absolute;right:32dp;top:45dp;border-radius:12dp;"
|
||||
"overflow:hidden;\">" +
|
||||
img(style + std::to_string(portrait), 174, 232, false, true, 320) +
|
||||
"</div></div>";
|
||||
body += "<div class=\"panel\" style=\"position:absolute;" +
|
||||
rect(1320, 90, 1288, 330) +
|
||||
"padding:30dp;\"><p class=\"small\">Verein</p>" +
|
||||
btn("manager-clubs",
|
||||
crest(c, 176) +
|
||||
"<div class=\"column\" style=\"gap:20dp;\"><strong "
|
||||
"style=\"font-size:38dp;\">" +
|
||||
esc(c ? world_->name(*c) : "") +
|
||||
"</strong><small class=\"small\">" +
|
||||
esc(c ? world_->name(*world_->find(
|
||||
"competitions", c->value("competition", "")))
|
||||
: "") +
|
||||
"</small><span class=\"accent\">Verein wählen ›</span></div>",
|
||||
"row",
|
||||
"style=\"margin-top:10dp;width:100%;height:230dp;background-"
|
||||
"color:transparent;border-width:0;padding:0;text-align:left;\"") +
|
||||
"</div>";
|
||||
body +=
|
||||
"<div style=\"position:absolute;" + rect(0, 460, 1288, 170) +
|
||||
"\"><h3>Startliga</h3><div class=\"row\" style=\"margin-top:20dp;\">" +
|
||||
select("manager-country", countries, country_, "manager-country") +
|
||||
select("manager-league", choices, league_, "manager-league") +
|
||||
"</div></div><div style=\"position:absolute;" +
|
||||
rect(1320, 460, 1288, 170) +
|
||||
"\"><h3>Vereinsstärke</h3><div style=\"margin-top:20dp;\">" +
|
||||
select("manager-strength",
|
||||
{{"0", "Unteres Drittel"},
|
||||
{"1", "Mittelfeld"},
|
||||
{"2", "Oberes Drittel"}},
|
||||
selections_["manager-strength"].empty()
|
||||
? "1"
|
||||
: selections_["manager-strength"],
|
||||
"manager-strength") +
|
||||
"</div></div>";
|
||||
body += "<div class=\"panel\" "
|
||||
"style=\"position:absolute;left:0;top:670dp;width:1978dp;bottom:"
|
||||
"145dp;padding:26dp;\"><h3>Managerporträt</h3><div class=\"row\" "
|
||||
"style=\"position:absolute;right:26dp;top:16dp;\">" +
|
||||
btn("portrait-style", "Foto",
|
||||
selections_["portrait-style"] != "painted" ? "primary" : "",
|
||||
"data-id=\"photo\"") +
|
||||
btn("portrait-style", "Illustration",
|
||||
selections_["portrait-style"] == "painted" ? "primary" : "",
|
||||
"data-id=\"painted\"") +
|
||||
"</div>";
|
||||
for (int i = 0; i < 12; ++i) {
|
||||
const int x = 26 + (i % 6) * 320, y = 100 + (i / 6) * 440;
|
||||
const bool used = used_portrait(i);
|
||||
body += "<button data-action=\"portrait\" data-id=\"" + std::to_string(i) +
|
||||
"\" class=\"choice " + (i == portrait ? "selected" : "") +
|
||||
"\" style=\"position:absolute;" + rect(x, y, 300, 412) +
|
||||
"padding:18dp 30dp;\" " + (used ? "disabled" : "") + ">" +
|
||||
img(style + std::to_string(i), 230, 306, false, true, 350) +
|
||||
"<p style=\"font-size:24dp;margin-top:18dp;\">" +
|
||||
(used ? "Vergeben"
|
||||
: i == portrait ? "Ausgewählt"
|
||||
: "Porträt " + std::to_string(i + 1)) +
|
||||
"</p></button>";
|
||||
}
|
||||
body += "</div><div class=\"panel\" "
|
||||
"style=\"position:absolute;left:2010dp;right:0;top:670dp;bottom:"
|
||||
"145dp;padding:28dp;\"><h3>Mitspieler dieser Partie</h3>";
|
||||
for (size_t i = 0; i < managers_draft_.size(); ++i) {
|
||||
const auto &m = managers_draft_[i];
|
||||
body += "<div class=\"row\" style=\"margin-top:40dp;\">" +
|
||||
img("manager." + std::to_string(m.value("portrait", 0)), 90, 120,
|
||||
false, true, 180) +
|
||||
"<div><small class=\"small\">Spieler " + std::to_string(i + 1) +
|
||||
"</small><p style=\"margin-top:10dp;\">" +
|
||||
esc(m.value("name", "")) + "</p><small class=\"small\">" +
|
||||
esc(world_->name(*world_->find("clubs", m.value("club", "")))) +
|
||||
"</small></div></div>";
|
||||
}
|
||||
body += "<p class=\"small\" "
|
||||
"style=\"position:absolute;left:28dp;right:28dp;bottom:28dp;\">" +
|
||||
std::to_string(limit - int(managers_draft_.size())) +
|
||||
" weitere Plätze frei</p></div><div class=\"bottom-controls\">" +
|
||||
btn("manager-back", adding_manager_ ? "Abbrechen" : "Zurück") +
|
||||
btn("manager-next",
|
||||
adding_manager_ ? "Mitspieler hinzufügen"
|
||||
: manager_index_ + 1 == limit ? "Spiel starten"
|
||||
: "Mitspieler bestätigen",
|
||||
"primary",
|
||||
world_->manageable(selected_club_) && manager_index_ < limit
|
||||
? ""
|
||||
: "disabled") +
|
||||
"</div>";
|
||||
return window("Neuer Spieler", body);
|
||||
}
|
||||
std::string App::render_opening() {
|
||||
const std::array<const char *, 3> names = {"UEFA-Cup", "Champions League",
|
||||
"Europapokal der Pokalsieger"};
|
||||
|
||||
+37
-2
@@ -401,6 +401,12 @@ class App final : public Rml::EventListener {
|
||||
Json managers_draft_ = Json::array(),
|
||||
start_options_ = {{"duration", 5}, {"difficulty", 3}, {"players", 1},
|
||||
{"mode", 3}, {"league", true}, {"world", true}};
|
||||
std::shared_ptr<const Catalog> entry_catalog_;
|
||||
const DataSource *entry_source_ = nullptr;
|
||||
uint64_t entry_revision_ = 0;
|
||||
std::string club_search_, entry_return_scene_ = "main",
|
||||
entry_picker_country_, entry_picker_league_;
|
||||
bool manager_confirm_ = false, manager_success_ = false;
|
||||
int manager_index_ = 0;
|
||||
bool manager_picker_ = false, adding_manager_ = false;
|
||||
struct Drag {
|
||||
@@ -584,10 +590,14 @@ class App final : public Rml::EventListener {
|
||||
return nullptr;
|
||||
}
|
||||
void load_world(const fs::path &file) {
|
||||
reset_settings();
|
||||
reset_files();
|
||||
auto next = Catalog::open(file);
|
||||
auto demo = std::make_unique<DemoSource>(next);
|
||||
publish_world(std::move(next), std::move(demo));
|
||||
}
|
||||
void publish_world(std::shared_ptr<const Catalog> next,
|
||||
std::unique_ptr<DemoSource> demo) {
|
||||
reset_settings();
|
||||
reset_files();
|
||||
ticket_.reset();
|
||||
renderer_.world(next);
|
||||
world_ = std::move(next);
|
||||
@@ -725,6 +735,24 @@ class App final : public Rml::EventListener {
|
||||
void render_context();
|
||||
void context_menu(const std::string &id, int x, int y);
|
||||
void drag_event(Rml::Event &);
|
||||
std::shared_ptr<const Catalog> entry_world() const {
|
||||
return entry_catalog_ ? entry_catalog_ : world_;
|
||||
}
|
||||
bool entry_name_valid() const;
|
||||
bool entry_used_club(const std::string &) const;
|
||||
bool entry_used_portrait(int) const;
|
||||
bool entry_full() const { return adding_manager_ && managers_draft_.size() >= 4; }
|
||||
void entry_begin();
|
||||
void entry_add();
|
||||
void entry_cancel();
|
||||
void entry_choose_defaults();
|
||||
void entry_sync_club();
|
||||
void entry_confirm();
|
||||
bool entry_action(const std::string &, Rml::Element *);
|
||||
bool entry_change(Rml::Element *);
|
||||
bool entry_input(Rml::Element *);
|
||||
bool entry_event(Rml::Event &);
|
||||
Json entry_snapshot() const;
|
||||
std::string render_newgame();
|
||||
std::string render_manager();
|
||||
std::string render_opening();
|
||||
@@ -853,6 +881,11 @@ class App final : public Rml::EventListener {
|
||||
element("canvas")->SetInnerRML(markup);
|
||||
element("canvas")->SetProperty("overflow", statistics_trophy_.contains("asset") ? "visible" : "hidden");
|
||||
setting_menu_markup_ = false;
|
||||
if (manager_confirm_ || manager_success_) {
|
||||
Rml::ElementList behind;
|
||||
doc_->QuerySelectorAll(behind, "#entry-manager-underlay button,#entry-manager-underlay input,#entry-manager-underlay select,.window>.titlebar button");
|
||||
for (auto *node : behind) node->SetProperty("pointer-events", "none");
|
||||
}
|
||||
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;
|
||||
@@ -1300,6 +1333,8 @@ public:
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
#include "modern/ui/entry_controls.inc"
|
||||
#include "modern/ui/entry_screens.inc"
|
||||
#include "modern/ui/controls.inc"
|
||||
#include "modern/ui/widgets_screens.inc"
|
||||
#include "modern/ui/widgets_controls.inc"
|
||||
|
||||
@@ -0,0 +1,318 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/ui/desktop.hpp"
|
||||
#include "modern/ui/model.hpp"
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
using namespace bmh::modern_ui;
|
||||
namespace {
|
||||
void require(bool yes, const char *message) {
|
||||
if (!yes)
|
||||
throw std::runtime_error(message);
|
||||
}
|
||||
struct Fixture {
|
||||
fs::path root;
|
||||
std::shared_ptr<const Catalog> world;
|
||||
Fixture()
|
||||
: root(fs::temp_directory_path() /
|
||||
bmh::editor::new_id("openbmh-entry-test-")) {
|
||||
fs::create_directories(root / "world");
|
||||
const auto write = [&](const char *path, const Json &data) {
|
||||
bmh::editor::write_atomic(root / path, data.dump());
|
||||
};
|
||||
write("manifest.json", {{"format", "openbmh-world"},
|
||||
{"kind", "world"},
|
||||
{"format_version", "1.1"},
|
||||
{"id", "world:synthetic-entry"},
|
||||
{"start_date", "2032-07-01"},
|
||||
{"requires", {"editor:world-v1"}},
|
||||
{"x-editor", {{"profile", "editor-world-v1"}}}});
|
||||
write("world/nations.json",
|
||||
{{"items",
|
||||
{{{"id", "nation:de"}, {"name", "Synthetic Germany"}},
|
||||
{{"id", "nation:es"}, {"name", "Synthetic Spain"}}}}});
|
||||
write("world/competitions.json", {{"items",
|
||||
{{{"id", "competition:de"},
|
||||
{"name", "Synthetic DE"},
|
||||
{"nation", "nation:de"},
|
||||
{"type", "league"}},
|
||||
{{"id", "competition:es"},
|
||||
{"name", "Synthetic ES"},
|
||||
{"nation", "nation:es"},
|
||||
{"type", "league"}}}}});
|
||||
Json clubs = Json::array();
|
||||
for (int index = 0; index < 5; ++index)
|
||||
clubs.push_back({{"id", "club:entry-" + std::to_string(index)},
|
||||
{"name", "Synthetic club " + std::to_string(index)},
|
||||
{"nation", "nation:de"},
|
||||
{"competition", "competition:de"}});
|
||||
clubs.push_back({{"id", "club:foreign"},
|
||||
{"name", "Foreign club"},
|
||||
{"nation", "nation:es"},
|
||||
{"competition", "competition:es"}});
|
||||
write("world/clubs.json", {{"items", clubs}});
|
||||
write("world/players.json", {{"items", Json::array()}});
|
||||
world = Catalog::open(root);
|
||||
}
|
||||
~Fixture() {
|
||||
std::error_code error;
|
||||
fs::remove_all(root, error);
|
||||
}
|
||||
};
|
||||
Json setup(int players = 2, bool league = true, bool world = true) {
|
||||
return {{"duration", 5}, {"difficulty", 3}, {"players", players},
|
||||
{"mode", 3}, {"league", league}, {"world", world}};
|
||||
}
|
||||
Json manager(int index, const std::string &name = {}) {
|
||||
return {{"name", name.empty() ? "Manager " + std::to_string(index) : name},
|
||||
{"club", "club:entry-" + std::to_string(index)},
|
||||
{"portrait", index},
|
||||
{"portrait_style", index % 2 ? "painted" : "photo"},
|
||||
{"strength_choice", index % 3}};
|
||||
}
|
||||
Json start(int players = 2) {
|
||||
Json managers = Json::array();
|
||||
for (int index = 0; index < players; ++index)
|
||||
managers.push_back(manager(index));
|
||||
return {{"setup", setup(players)}, {"managers", managers}};
|
||||
}
|
||||
void rejected(DemoSource &source, const std::string &kind, const Json &value,
|
||||
uint64_t revision) {
|
||||
const auto before = source.snapshot();
|
||||
const bool dirty = source.dirty();
|
||||
const auto result = source.apply({revision, kind, value});
|
||||
require(!result.ok && result.revision == before.revision,
|
||||
"Invalid/stale entry action accepted or returned wrong revision");
|
||||
require(source.snapshot().state == before.state &&
|
||||
source.snapshot().revision == before.revision &&
|
||||
source.dirty() == dirty,
|
||||
"Rejected entry action changed state, revision or clean marker");
|
||||
}
|
||||
void names() {
|
||||
require(normalized_manager_name(" Änne Öster ") == "Änne Öster",
|
||||
"Manager name not trimmed");
|
||||
require(normalized_manager_name("\xc2\xa0"
|
||||
"Robin"
|
||||
"\xe3\x80\x80") == "Robin",
|
||||
"Unicode edge whitespace not trimmed");
|
||||
require(normalized_manager_name("Alex Berger") == "Alex Berger",
|
||||
"Internal whitespace was changed");
|
||||
std::string umlauts, emoji;
|
||||
for (int index = 0; index < 24; ++index) {
|
||||
umlauts += "Ä";
|
||||
emoji += "\xf0\x9f\x98\x80";
|
||||
}
|
||||
require(normalized_manager_name(umlauts) == umlauts &&
|
||||
normalized_manager_name(emoji) == emoji,
|
||||
"24 Unicode codepoints were counted as UTF8 bytes/UTF16 units");
|
||||
require(!normalized_manager_name(umlauts + "Ä") &&
|
||||
!normalized_manager_name(emoji + "x"),
|
||||
"25 codepoints accepted");
|
||||
require(!normalized_manager_name("") && !normalized_manager_name(" ") &&
|
||||
!normalized_manager_name("Name\n") &&
|
||||
!normalized_manager_name("\tName") &&
|
||||
!normalized_manager_name(std::string("N\0ame", 5)) &&
|
||||
!normalized_manager_name("Name\xc2\x85"),
|
||||
"Empty/control manager name accepted");
|
||||
require(!normalized_manager_name("\xc0\xaf") &&
|
||||
!normalized_manager_name("\xed\xa0\x80") &&
|
||||
!normalized_manager_name("\xf4\x90\x80\x80") &&
|
||||
!normalized_manager_name("\xe2\x82"),
|
||||
"Malformed UTF8 manager name accepted");
|
||||
}
|
||||
void transactions(const Fixture &fixture) {
|
||||
DemoSource source(fixture.world);
|
||||
const auto base = source.snapshot();
|
||||
auto valid = start();
|
||||
valid["managers"][0]["name"] = " Alex Öster ";
|
||||
const auto committed = source.apply({base.revision, "start", valid});
|
||||
const auto current = source.snapshot();
|
||||
require(committed.ok && committed.revision == base.revision + 1 &&
|
||||
current.revision == committed.revision && source.dirty(),
|
||||
"Start did not atomically publish exactly one dirty revision");
|
||||
require(current.state.at("edits").at("setup") == valid.at("setup") &&
|
||||
current.state.at("managers").size() == 2 &&
|
||||
current.state.at("managers")[0].at("name") == "Alex Öster" &&
|
||||
current.state.at("managers")[1].at("portrait_style") ==
|
||||
"painted" &&
|
||||
current.state.at("managers")[1].at("strength_choice") == 1,
|
||||
"Start lost setup, normalized name, style or strength");
|
||||
require(current.state.at("opening") == "pending" &&
|
||||
current.state.at("opening_created") == false,
|
||||
"League start did not stage presentation opening");
|
||||
for (const auto *field :
|
||||
{"cash", "deposit", "debt", "date", "ticket", "preferences"})
|
||||
require(current.state.at(field) == base.state.at(field),
|
||||
"Presentation start changed unrelated career/global values");
|
||||
rejected(source, "start", valid, base.revision);
|
||||
require(source.mark_saved(current.revision) && !source.dirty(),
|
||||
"Cannot checkpoint accepted start");
|
||||
auto bad = valid;
|
||||
bad["setup"]["players"] = 3;
|
||||
rejected(source, "start", bad, current.revision);
|
||||
require(!source.dirty(), "Rejected start dirtied a clean source");
|
||||
auto world_only = start(1);
|
||||
world_only["setup"] = setup(1, false, true);
|
||||
require(
|
||||
source.apply({current.revision, "start", world_only}).ok &&
|
||||
source.snapshot().state.at("opening") == "complete" &&
|
||||
source.snapshot().state.at("opening_created") == false,
|
||||
"World-only single-manager start incorrectly opens league presentation");
|
||||
}
|
||||
void invalid(const Fixture &fixture) {
|
||||
DemoSource source(fixture.world);
|
||||
const auto valid = start();
|
||||
std::vector<Json> bad_values = {Json(), Json::array(), Json::object()};
|
||||
for (const auto &[field, values] :
|
||||
std::vector<std::pair<std::string, std::vector<Json>>>{
|
||||
{"duration", {0, 6, 2.5, true}},
|
||||
{"difficulty", {0, 11, "3"}},
|
||||
{"players", {0, 5, 2.0}},
|
||||
{"mode", {0, 4, false}}})
|
||||
for (const auto &value : values) {
|
||||
auto bad = valid;
|
||||
bad["setup"][field] = value;
|
||||
bad_values.push_back(bad);
|
||||
}
|
||||
for (const auto *field :
|
||||
{"duration", "difficulty", "players", "mode", "league", "world"}) {
|
||||
auto bad = valid;
|
||||
bad["setup"].erase(field);
|
||||
bad_values.push_back(bad);
|
||||
}
|
||||
auto bad = valid;
|
||||
bad["setup"]["league"] = 1;
|
||||
bad_values.push_back(bad);
|
||||
bad = valid;
|
||||
bad["setup"]["world"] = "true";
|
||||
bad_values.push_back(bad);
|
||||
bad = valid;
|
||||
bad["setup"]["league"] = false;
|
||||
bad["setup"]["world"] = false;
|
||||
bad_values.push_back(bad);
|
||||
bad = valid;
|
||||
bad["setup"]["league"] = false;
|
||||
bad_values.push_back(bad);
|
||||
bad = valid;
|
||||
bad["managers"].push_back(manager(2));
|
||||
bad_values.push_back(bad);
|
||||
bad = valid;
|
||||
bad["managers"] = Json::array();
|
||||
bad_values.push_back(bad);
|
||||
for (const auto &value : bad_values)
|
||||
rejected(source, "start", value, source.snapshot().revision);
|
||||
for (const auto &[field, values] :
|
||||
std::vector<std::pair<std::string, std::vector<Json>>>{
|
||||
{"name", {"", " ", "Name\n", std::string(25, 'x'), 17}},
|
||||
{"club", {"club:foreign", "club:missing", 1}},
|
||||
{"portrait", {-1, 12, 1.5, true}},
|
||||
{"portrait_style", {"", "drawing", 1}},
|
||||
{"strength_choice", {-1, 3, 1.5, false}}})
|
||||
for (const auto &value : values) {
|
||||
auto request = valid;
|
||||
request["managers"][1][field] = value;
|
||||
rejected(source, "start", request, source.snapshot().revision);
|
||||
rejected(source, "managers", request.at("managers"),
|
||||
source.snapshot().revision);
|
||||
}
|
||||
for (const auto *field : {"club", "portrait"}) {
|
||||
auto request = valid;
|
||||
request["managers"][1][field] = request["managers"][0][field];
|
||||
rejected(source, "start", request, source.snapshot().revision);
|
||||
rejected(source, "managers", request.at("managers"),
|
||||
source.snapshot().revision);
|
||||
}
|
||||
require(source.snapshot().revision == 0 && !source.dirty(),
|
||||
"Invalid entries accumulated hidden revisions");
|
||||
}
|
||||
void additional_managers(const Fixture &fixture) {
|
||||
DemoSource source(fixture.world);
|
||||
auto baseline = source.snapshot();
|
||||
auto values = baseline.state.at("managers");
|
||||
auto second = manager(1, " Chris Winter ");
|
||||
second["synthetic_extra"] = "retained";
|
||||
values.push_back(second);
|
||||
require(source.apply({baseline.revision, "managers", values}).ok,
|
||||
"Adding valid second manager failed");
|
||||
auto after = source.snapshot();
|
||||
require(after.state.at("managers")[0] == baseline.state.at("managers")[0] &&
|
||||
after.state.at("managers")[1].at("name") == "Chris Winter" &&
|
||||
after.state.at("managers")[1].at("synthetic_extra") == "retained",
|
||||
"Add mutated earlier manager or lost normalized/extra data");
|
||||
auto previous = after.state.at("managers");
|
||||
values = previous;
|
||||
values.push_back(manager(2));
|
||||
require(source.apply({after.revision, "managers", values}).ok,
|
||||
"Adding third manager failed");
|
||||
after = source.snapshot();
|
||||
require(after.state.at("managers")[0] == previous[0] &&
|
||||
after.state.at("managers")[1] == previous[1],
|
||||
"Third manager changed earlier manager choices");
|
||||
values = after.state.at("managers");
|
||||
values.push_back(manager(3));
|
||||
require(source.apply({after.revision, "managers", values}).ok,
|
||||
"Adding fourth manager failed");
|
||||
after = source.snapshot();
|
||||
values = after.state.at("managers");
|
||||
values.push_back(manager(4));
|
||||
rejected(source, "managers", values, after.revision);
|
||||
rejected(source, "managers", after.state.at("managers"), after.revision - 1);
|
||||
for (const auto &[field, value] : baseline.state.items())
|
||||
if (field != "managers")
|
||||
require(after.state.at(field) == value,
|
||||
"Adding managers changed first-club state, setup or presentation "
|
||||
"phase");
|
||||
auto checkpoint = after.state;
|
||||
checkpoint["desktop"] = default_desktop();
|
||||
DemoSource restored(fixture.world);
|
||||
restored.load_data(checkpoint);
|
||||
require(restored.snapshot().state == after.state && !restored.dirty(),
|
||||
"Additional managers' styles/strengths/extras changed across load");
|
||||
auto legacy = checkpoint;
|
||||
for (auto &row : legacy["managers"]) {
|
||||
row.erase("portrait_style");
|
||||
row.erase("strength_choice");
|
||||
}
|
||||
restored.load_data(legacy);
|
||||
const auto migrated = restored.snapshot();
|
||||
for (const auto &row : migrated.state.at("managers"))
|
||||
require(row.at("portrait_style") == "photo" &&
|
||||
row.at("strength_choice") == 1,
|
||||
"Legacy manager defaults missing");
|
||||
}
|
||||
void club_migration(const Fixture &fixture) {
|
||||
DemoSource started(fixture.world), edited(fixture.world);
|
||||
auto rows = Json::array({manager(1), manager(2)});
|
||||
require(edited.apply({0, "managers", rows}).ok,
|
||||
"Reference manager club switch failed");
|
||||
require(
|
||||
started.apply({0, "start", {{"setup", setup()}, {"managers", rows}}}).ok,
|
||||
"Start manager club switch failed");
|
||||
auto reference = edited.snapshot().state, actual = started.snapshot().state;
|
||||
reference["edits"]["setup"] = setup();
|
||||
reference["opening"] = "pending";
|
||||
reference["opening_created"] = false;
|
||||
require(
|
||||
reference == actual,
|
||||
"Start diverges from established club-change presentation migrations");
|
||||
require(actual.at("training").at("club") == "club:entry-1",
|
||||
"Start retained previous club's training");
|
||||
}
|
||||
} // namespace
|
||||
int main() {
|
||||
try {
|
||||
names();
|
||||
Fixture fixture;
|
||||
transactions(fixture);
|
||||
invalid(fixture);
|
||||
additional_managers(fixture);
|
||||
club_migration(fixture);
|
||||
std::cout << "PASS entry model: atomic setup/managers start, UTF8 names, "
|
||||
"constraints, stale/invalid rollback, stable additions and "
|
||||
"shared club migration\n";
|
||||
return 0;
|
||||
} catch (const std::exception &error) {
|
||||
std::cerr << error.what() << '\n';
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user