From c60b0e9b2c1ce8f411c310c5ab0313717920aef6 Mon Sep 17 00:00:00 2001 From: Weyoune Date: Sun, 15 Nov 2026 20:57:01 +0100 Subject: [PATCH] The stadium and its surroundings as two pages with a card model on one plate The ground is drawn after the design: eight stands as deep as they have places, the equipment, the fourteen objects around it, trees, cars and people on one base plate. The stage works out itself which part lies under the pointer, the wheel zooms and dragging moves the view. The part's card, the figures and the building firm's offer follow the notes of the other pages. Co-Authored-By: Claude Fable 5.2 --- assets/modern/pages.rcss | 49 +++ assets/modern/stadium.rcss | 233 +------------ src/modern/ui/controls.inc | 11 +- src/modern/ui/engine_controls.inc | 2 +- src/modern/ui/engine_stadium.inc | 110 +----- src/modern/ui/engine_state.inc | 1 - src/modern/ui/notebook.inc | 11 +- src/modern/ui/pages.inc | 2 +- src/modern/ui/stadium_controls.inc | 128 +++++-- src/modern/ui/stadium_model.hpp | 518 ---------------------------- src/modern/ui/stadium_scene.hpp | 537 +++++++++++++++++++++++++++++ src/modern/ui/stadium_screens.inc | 528 +++++++++++++++------------- src/modern/ui/view.cpp | 22 +- tests/modern_ui_core_tests.cpp | 51 ++- 14 files changed, 1025 insertions(+), 1178 deletions(-) delete mode 100644 src/modern/ui/stadium_model.hpp create mode 100644 src/modern/ui/stadium_scene.hpp diff --git a/assets/modern/pages.rcss b/assets/modern/pages.rcss index 542cf6e..a63c3ee 100644 --- a/assets/modern/pages.rcss +++ b/assets/modern/pages.rcss @@ -507,3 +507,52 @@ body .pg-btn.pg-go[disabled] {opacity:1;background-color:var(--p-a3);border-colo .st-td .pg-link {max-width:100%;} .st-text {display:block;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;} .pg-root .pg-dd .report-picker-popup {min-width:560dp;} + +/* --- stadium and surroundings: the model on its stage, the part's card, the figures, the offer --- */ +.sd-stage {position:relative;display:block;flex:1;min-height:0;overflow:hidden;clip:always;border:2dp var(--p-div);border-radius:45dp;background-color:#eef1e1;} +body.midnight .sd-stage,body.matchday .sd-stage {background-color:var(--p-n2);} +.sd-world {position:absolute;display:block;width:2799dp;height:1512dp;transform-origin:left top;pointer-events:none;} +.sd-world img {position:absolute;left:0;top:0;} +.sd-ground,.sd-ground:hover,.sd-ground:focus {position:absolute;left:0;top:0;width:100%;height:100%;display:block;padding:0;border:0dp;background-color:transparent;decorator:none;} +.sd-hot,.sd-hot:hover,.sd-hot:focus {position:absolute;left:0;top:0;width:0dp;height:0dp;min-width:0dp;min-height:0dp;display:block;padding:0;margin:0;border:0dp;background-color:transparent;decorator:none;overflow:visible;pointer-events:none;} +.sd-q {position:absolute;display:block;width:100dp;height:100dp;transform-origin:left top;background-color:transparent;pointer-events:none;} +.sd-hot.hover .sd-q,.sd-hot:focus .sd-q {background-color:#ffffff66;} +.sd-hot.sel .sd-q,.sd-hot.sel.hover .sd-q {background-color:#c8733c66;} +.sd-letter {position:absolute;display:block;pointer-events:none;width:43dp;height:43dp;line-height:39dp;border:2.5dp #3a332b;border-radius:22dp;background-color:#f9f4ed;font-family:Display;font-size:27dp;text-align:center;color:#3a332b;} +.sd-chips {position:absolute;left:32dp;bottom:27dp;display:flex;flex-wrap:wrap;gap:11dp;max-width:1935dp;} +.pg-root .pg-btn.sd-chip {height:52dp;padding:0 22dp;gap:10dp;font-family:Modern;font-size:27dp;font-weight:bold;} +.pg-root .pg-btn.sd-chip .pg-mut {font-weight:normal;} +.sd-card {position:absolute;right:32dp;top:32dp;width:675dp;gap:22dp;} +.sd-card .pg-kv {line-height:50dp;} +.sd-tip {position:absolute;display:none;pointer-events:none;left:0;top:0;padding:9dp 22dp;border-radius:18dp;background-color:#2e2b25;font-size:27dp;line-height:36dp;color:#f9f4ed;white-space:nowrap;} +.sd-tip strong {display:block;font-weight:bold;} +.sd-tip span {display:block;} +/* the figures */ +.sd-chart {display:block;flex:1;min-height:0;overflow:hidden;} +.sd-mark {display:block;width:32dp;height:9dp;margin-right:14dp;border-radius:5dp;} +.pg-root .pg-btn.sd-curve {height:60dp;padding:0 25dp;font-size:28dp;} +.sd-prices {display:flex;gap:7dp;} +.pg-root .pg-btn.sd-price {flex:1;min-width:0;height:62dp;padding:0;font-family:Modern;font-size:27dp;} +.sd-table {width:900dp;flex:none;align-self:flex-start;padding:14dp 27dp;} +.sd-row {display:flex;align-items:center;min-height:86dp;padding:11dp 0;border-top:2dp var(--p-row);font-size:27dp;line-height:34dp;} +.sd-row.head {min-height:60dp;border-top-width:0dp;font-size:24dp;font-weight:bold;letter-spacing:1dp;color:var(--p-n7);} +.sd-cell {display:block;flex:1;min-width:0;overflow:hidden;text-align:right;} +.sd-cell span {display:block;} +.sd-cell.first {flex:none;width:215dp;text-align:left;font-weight:bold;} +.sd-row.head .sd-cell.first {font-weight:normal;} +.sd-sub {font-size:21dp;line-height:27dp;} +/* the building firm's offer */ +.pg-ov .pg-btn.sd-number {height:76dp;font-size:41dp;} +.pg-ov .sd-range {display:block;width:100%;height:54dp;} +.pg-ov .sd-range slidertrack {height:9dp;margin:22dp 0;border-radius:5dp;background-color:var(--p-n3);} +.pg-ov .sd-range sliderbar {width:40dp;height:40dp;margin-top:7dp;border:4dp var(--p-bg);border-radius:20dp;background-color:var(--p-accent);} +.sd-check {display:flex;align-items:center;gap:16dp;} +.sd-check span {display:block;} +.sd-check input {display:block;flex:none;width:40dp;height:40dp;border:2dp var(--p-n5);border-radius:11dp;background-color:var(--p-n1);} +.sd-check input:checked {background-color:var(--p-accent);border-color:var(--p-accent);} +.sd-check input:disabled {opacity:.55;} +.pg-ov .pg-card.sd-option {flex:1;min-width:0;align-items:center;text-align:center;} +.sd-option-art,.sd-preview {display:block;flex:none;overflow:hidden;border-radius:27dp;} +.sd-option .pg-h,.sd-option .pg-mut {display:block;} +.pg-ov .sd-feedback {max-width:none;white-space:normal;height:auto;min-height:60dp;line-height:40dp;padding:10dp 27dp;} +.sd-card .pg-bar {flex:none;} diff --git a/assets/modern/stadium.rcss b/assets/modern/stadium.rcss index 30489c6..8a51e4b 100644 --- a/assets/modern/stadium.rcss +++ b/assets/modern/stadium.rcss @@ -1,232 +1 @@ -/* SPDX-License-Identifier: GPL-3.0-only */ -.stadium-screen {position:absolute;left:0;top:0;width:2612dp;height:1864dp;color:var(--text);} -.stadium-empty {font-size:30dp;padding:40dp;color:var(--muted);} -.stadium-heading {position:absolute;left:0;top:0;width:2612dp;height:106dp;display:flex;align-items:center;justify-content:space-between;color:#d4e2ed;} -.stadium-heading-copy {height:83dp;} -.stadium-heading h2 {font-size:36dp;font-weight:normal;line-height:41dp;height:41dp;margin:0 0 12dp;white-space:nowrap;} -.stadium-heading p {font-size:28dp;color:#91adbf;line-height:30dp;height:30dp;margin:0;} -.stadium-summary {display:flex;align-items:center;} -.stadium-summary>div {display:flex;flex-direction:column;align-items:flex-end;margin-left:65dp;} -.stadium-summary>div>span {display:block;font-size:28dp;color:#91adbf;height:28dp;line-height:28dp;} -.stadium-summary strong {display:block;font-size:38dp;font-weight:normal;color:#b8dfd0;height:44dp;line-height:44dp;margin-top:10dp;white-space:nowrap;} -.stadium-summary small {font-size:28dp;color:#b7cddc;} -.stadium-bowl {position:absolute;left:100dp;top:134dp;width:1430dp;height:992.923588dp;border:2dp #c5d9e726;border-radius:18dp;overflow:hidden;} -.stadium-letter {position:absolute;display:flex;align-items:center;justify-content:center;width:96dp;height:92dp;padding:0;border:2dp #e4b3a06b;border-radius:18dp;background-color:#14222ae6;color:#f0a99b;font-size:58dp;line-height:1;font-weight:bold;} -.stadium-letter .control-label {width:100%;text-align:center;white-space:nowrap;} -.stadium-letter:hover {background-color:#33434ae6;border-color:#f6c6ba;color:#ffdbcf;} -.stadium-letter.building {border-color:#d8b77f;color:#e9cb9b;opacity:.85;} -.stadium-block {position:absolute;display:block;padding:18dp 28dp;border:2dp #c5d9e726;border-radius:14dp;background-color:#12243140;color:#b8d0e0;font-size:28dp;text-align:left;} -.stadium-block:hover {background-color:#c5d9e712;} -.stadium-block:disabled {opacity:.85;border-color:#d8b77f52;background-color:#b6955d0d;} -.stadium-block-copy {position:absolute;left:28dp;width:540dp;height:116dp;} -.stadium-block-copy strong {position:absolute;left:0;top:0;display:block;width:540dp;height:36dp;line-height:36dp;font-size:31dp;font-weight:normal;color:#d7e5ef;white-space:nowrap;} -.stadium-block-copy>span {position:absolute;left:0;top:46dp;display:block;width:540dp;height:32dp;line-height:32dp;white-space:nowrap;} -.stadium-block-copy small {position:absolute;left:0;top:88dp;display:block;width:540dp;height:28dp;line-height:28dp;font-size:28dp;color:#8faabd;white-space:nowrap;} -.stadium-block-icons {position:absolute;right:20dp;top:22dp;display:flex;width:162dp;height:76dp;} -.stadium-block-icons .image-frame {margin-right:10dp;flex-shrink:0;} -.stadium-block-icons .image-frame:last-child {margin-right:0;} -.stadium-facility {position:absolute;display:block;padding:0;border:2dp #c5d9e726;border-radius:14dp;background-color:#12243140;color:#cbdde9;overflow:hidden;} -.stadium-facility:hover {background-color:#c5d9e712;border-color:#c5d9e752;} -.stadium-facility:disabled {opacity:.7;} -.stadium-facility-picture {position:absolute;left:0;top:0;display:block;width:391dp;height:125dp;overflow:hidden;background-color:#10232e60;} -.stadium-facility-art {position:absolute;display:block;} -.stadium-art-overlay {position:absolute;display:block;pointer-events:none;} -.stadium-facility>strong {position:absolute;left:0;top:133dp;display:block;width:391dp;height:31.2dp;line-height:31.2dp;font-size:28dp;font-weight:normal;text-align:center;white-space:nowrap;color:#d3e2ed;} -.stadium-facility-caption {position:absolute;left:0;top:168.2dp;display:block;width:391dp;height:25.3dp;line-height:25.3dp;font-size:25dp;text-align:center;white-space:nowrap;color:#95b7c2;} -.stadium-nav {position:absolute;left:0;top:1772dp;width:2612dp;height:92dp;display:flex;} -.stadium-nav-button {width:856dp;height:92dp;padding:12dp 24dp;margin-right:22dp;font-size:29dp;border:2dp #c5d9e726;border-radius:12dp;background-color:#b6cad510;flex-shrink:0;} -.stadium-nav-button:last-child {margin-right:0;} -.stadium-nav-button.wide {width:2612dp;} -.stadium-nav-button .control-label {width:100%;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;} -.stadium-panorama {position:absolute;left:0;top:134dp;width:2612dp;height:1470.031100478dp;border:2dp #c5d9e726;border-radius:18dp;overflow:hidden;} -.stadium-graph {position:absolute;left:0;top:134dp;width:2612dp;height:500dp;border:2dp #c5d9e726;border-radius:18dp;background-color:#12243140;} -.stadium-graph-art {position:absolute;left:24dp;top:20dp;width:2560dp;height:456dp;pointer-events:none;} -.stadium-curve,.stadium-scale {position:absolute;padding:10dp 20dp 10dp 38dp;height:74dp;border:2dp #c5d9e726;border-radius:12dp;background-color:#b6cad510;font-size:28dp;color:#cbdde9;} -.stadium-curve {display:flex;align-items:center;justify-content:center;} -.stadium-curve[aria-pressed=false] {opacity:.5;} -.stadium-curve[aria-pressed=true],.stadium-scale[aria-pressed=true] {background-color:#b6cad51f;border-color:#c5d9e744;} -.stadium-curve-color {position:absolute;left:12dp;top:16dp;width:6dp;height:34dp;border-radius:3dp;} -.stadium-curve-label {display:block;width:100%;white-space:nowrap;text-align:center;} -.stadium-scale {padding:12dp 24dp;font-size:28dp;} -.stadium-scale .control-label {width:100%;white-space:nowrap;} -.stadium-data-table {position:absolute;left:0;top:875dp;width:2612dp;height:432dp;} -.stadium-data-row {display:flex;align-items:center;width:2612dp;height:72dp;font-size:29dp;color:#d0e0eb;} -.stadium-data-row.head {font-size:28dp;color:#95afc2;border-bottom:2dp #c5d9e72b;} -.stadium-data-row.striped {background-color:#e3edf605;} -.stadium-data-cell {display:flex;align-items:center;justify-content:center;width:661.706667dp;height:72dp;padding:12dp 14dp;flex-shrink:0;min-width:0;} -.stadium-data-cell.first {width:626.88dp;justify-content:flex-start;} -.stadium-data-cell>span {display:block;width:100%;white-space:nowrap;text-align:center;overflow:hidden;text-overflow:ellipsis;} -.stadium-data-cell.first>span {text-align:left;color:#a7c1d3;} -.stadium-required {position:absolute;left:0;top:1335dp;width:2612dp;height:34dp;line-height:34dp;margin:0;display:flex;align-items:center;justify-content:center;font-size:29dp;color:#a1bccc;} -.stadium-required>span {display:block;white-space:nowrap;} -.stadium-required-value {color:#b8dfd0;margin-left:8dp;} -.stadium-ticket {position:absolute;left:0;top:1415dp;width:2612dp;height:80dp;display:flex;align-items:center;font-size:28dp;color:#bed3e1;} -.stadium-ticket>strong {display:block;width:87.14dp;flex-shrink:0;margin-right:20dp;font-size:28dp;font-weight:normal;} -.stadium-ticket-price {width:88.6484615dp;height:66dp;padding:8dp 0;margin-right:8dp;border:2dp #c5d9e726;border-radius:10dp;background-color:#b6cad510;font-size:28dp;color:#bed3e1;flex-shrink:0;} -.stadium-ticket-price:last-child {margin-right:0;} -.stadium-ticket-price .control-label {width:100%;white-space:nowrap;} -.stadium-ticket-price[aria-pressed=true] {background-color:#78b9a52b;border-color:#a9dccb73;color:#c8e8dc;} -.stadium-modal {position:absolute;left:0;top:0;width:2612dp;height:1864dp;background-color:#08101980;z-index:20;} -.stadium-draft {position:absolute;border:2dp #e1ecf429;border-radius:22dp;background-color:#283542f5;color:#d2e2ed;font-size:30dp;overflow:hidden;} -.stadium-draft h2 {position:absolute;left:52dp;top:40dp;width:2052dp;height:45dp;line-height:45dp;font-size:40dp;font-weight:bold;text-align:center;margin:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;color:#e3ecf3;} -.stadium-draft-summary {position:absolute;left:52dp;top:113dp;width:2052dp;height:31dp;line-height:31dp;display:flex;align-items:center;justify-content:space-between;font-size:28dp;color:#9db7ca;} -.stadium-draft-summary>span {display:block;white-space:nowrap;} -.stadium-place-field {position:absolute;left:52dp;top:174dp;width:1233.230769dp;height:307dp;padding:26dp 30dp;border:2dp #c5d9e726;border-radius:14dp;background-color:#12243140;} -.stadium-place-field>strong {position:absolute;left:30dp;top:26dp;font-size:34dp;font-weight:normal;height:39dp;line-height:39dp;} -.stadium-place-field>p {position:absolute;left:30dp;top:83dp;font-size:28dp;height:30dp;line-height:30dp;color:#9db7ca;margin:0;} -.stadium-place-label {position:absolute;left:30dp;top:140dp;display:flex;align-items:center;width:789.230769dp;height:80dp;line-height:80dp;font-size:28dp;white-space:nowrap;} -.stadium-place-number {position:absolute;right:30dp;top:140dp;width:340dp;height:80dp;padding:12dp 20dp;border:2dp #c5d9e738;border-radius:12dp;background-color:#111f2a80;color:#e3ecf5;font-size:34dp;text-align:right;justify-content:flex-end;} -.stadium-place-number .control-label {width:100%;white-space:nowrap;text-align:right;} -#stadium-place-range {position:absolute;left:30dp;top:252dp;width:1169.230769dp;height:18dp;margin:0;padding:0;} -#stadium-place-range slidertrack {height:4dp;margin:7dp 0;} -#stadium-place-range sliderbar {width:18dp;height:18dp;margin:0;border:0;border-radius:9dp;} -.stadium-features {position:absolute;left:1333.230769dp;top:196.5dp;width:770.769231dp;height:262dp;} -.stadium-feature-row {display:flex;align-items:center;width:770.769231dp;height:116dp;margin-bottom:30dp;font-size:32dp;} -.stadium-feature-row>input {width:38dp;height:38dp;flex-shrink:0;margin-right:24dp;} -.stadium-feature-image {display:block;width:116dp;height:116dp;margin-right:24dp;flex-shrink:0;} -.stadium-feature-row>span:last-child {display:block;white-space:nowrap;} -.stadium-costs {position:absolute;left:52dp;top:511dp;width:2052dp;height:146.5dp;margin:0;} -.stadium-cost-row {position:absolute;left:0;width:2052dp;height:43.5dp;} -.stadium-cost-row dt,.stadium-cost-row dd {position:absolute;top:0;height:43.5dp;line-height:43.5dp;width:1022dp;font-size:29dp;margin:0;} -.stadium-cost-row dt {left:0;color:#a9c1d2;} -.stadium-cost-row dd {right:0;text-align:right;color:#d2e4ee;} -.stadium-draft-total {position:absolute;left:52dp;width:2052dp;height:69dp;border-top:2dp #c5d9e726;padding-top:25dp;display:flex;align-items:center;justify-content:space-between;font-size:36dp;} -.stadium-draft-total>span {display:block;white-space:nowrap;} -#stadium-quote-total {color:#b8dfd0;} -#stadium-draft-feedback {position:absolute;left:52dp;width:2052dp;height:48dp;font-size:28dp;line-height:1.4;color:#94afc3;margin:0;} -.stadium-draft-actions {position:absolute;left:52dp;width:2052dp;height:84dp;display:flex;} -.stadium-dialog-action {width:1014dp;height:84dp;padding:12dp 24dp;margin-right:24dp;border:2dp #c5d9e726;border-radius:12dp;font-size:30dp;background-color:#12243140;flex-shrink:0;} -.stadium-dialog-action:last-child {margin-right:0;} -.stadium-dialog-action .control-label {width:100%;white-space:nowrap;} -.stadium-option {position:absolute;padding:22dp;display:block;border:2dp #c5d9e726;border-radius:16dp;background-color:#12243140;overflow:hidden;} -.stadium-option[aria-pressed=true] {background-color:#78b9a51f;border-color:#a9dccb73;} -.stadium-option-art {position:absolute;left:22dp;top:22dp;display:block;width:592dp;overflow:hidden;border-radius:10dp;} -.stadium-option>strong {position:absolute;left:22dp;width:592dp;height:37dp;line-height:37dp;font-size:32dp;font-weight:normal;white-space:nowrap;text-align:center;} -.stadium-option-price {position:absolute;left:22dp;width:592dp;height:34dp;line-height:34dp;font-size:30dp;white-space:nowrap;text-align:center;color:#b8dfd0;} -body.silver .stadium-heading,body.matchday .stadium-heading,body.silver .stadium-block,body.matchday .stadium-block,body.silver .stadium-block-copy strong,body.matchday .stadium-block-copy strong,body.silver .stadium-facility>strong,body.matchday .stadium-facility>strong,body.silver .stadium-summary small,body.matchday .stadium-summary small,body.silver .stadium-data-row,body.matchday .stadium-data-row,body.silver .stadium-data-cell.first>span,body.matchday .stadium-data-cell.first>span {color:var(--text);} -body.silver .stadium-heading p,body.matchday .stadium-heading p,body.silver .stadium-summary>div>span,body.matchday .stadium-summary>div>span,body.silver .stadium-block-copy small,body.matchday .stadium-block-copy small,body.silver .stadium-facility-caption,body.matchday .stadium-facility-caption,body.silver .stadium-required,body.matchday .stadium-required,body.silver .stadium-draft-summary,body.matchday .stadium-draft-summary,body.silver .stadium-place-field>p,body.matchday .stadium-place-field>p,body.silver #stadium-draft-feedback,body.matchday #stadium-draft-feedback {color:var(--muted);} -body.silver .stadium-summary strong,body.matchday .stadium-summary strong,body.silver .stadium-required-value,body.matchday .stadium-required-value,body.silver .stadium-option-price,body.matchday .stadium-option-price,body.silver #stadium-quote-total,body.matchday #stadium-quote-total {color:var(--accent);} -body.silver .stadium-bowl,body.matchday .stadium-bowl,body.silver .stadium-panorama,body.matchday .stadium-panorama,body.silver .stadium-graph,body.matchday .stadium-graph,body.silver .stadium-block,body.matchday .stadium-block,body.silver .stadium-facility,body.matchday .stadium-facility,body.silver .stadium-option,body.matchday .stadium-option,body.silver .stadium-place-field,body.matchday .stadium-place-field {border-color:var(--border);background-color:var(--panel);} -body.silver .stadium-facility-picture,body.matchday .stadium-facility-picture {background-color:var(--panel);} -body.silver .stadium-nav-button,body.matchday .stadium-nav-button,body.silver .stadium-curve,body.matchday .stadium-curve,body.silver .stadium-scale,body.matchday .stadium-scale,body.silver .stadium-ticket-price,body.matchday .stadium-ticket-price,body.silver .stadium-dialog-action,body.matchday .stadium-dialog-action {border-color:var(--border);background-color:var(--soft);color:var(--text);} -body.silver .stadium-nav-button:hover,body.matchday .stadium-nav-button:hover,body.silver .stadium-curve:hover,body.matchday .stadium-curve:hover,body.silver .stadium-scale:hover,body.matchday .stadium-scale:hover {background-color:var(--hover);} -body.silver .stadium-curve[aria-pressed=true],body.matchday .stadium-curve[aria-pressed=true],body.silver .stadium-scale[aria-pressed=true],body.matchday .stadium-scale[aria-pressed=true],body.silver .stadium-ticket-price[aria-pressed=true],body.matchday .stadium-ticket-price[aria-pressed=true],body.silver .stadium-option[aria-pressed=true],body.matchday .stadium-option[aria-pressed=true] {background-color:var(--selected);border-color:var(--accent);} -body.silver .stadium-draft {background-color:#f7f3e9fc;border-color:var(--border);color:var(--text);} -body.matchday .stadium-draft {background-color:#2c2c32fc;border-color:var(--border);color:var(--text);} -body.silver .stadium-draft h2,body.matchday .stadium-draft h2,body.silver .stadium-place-number,body.matchday .stadium-place-number,body.silver .stadium-cost-row dt,body.matchday .stadium-cost-row dt,body.silver .stadium-cost-row dd,body.matchday .stadium-cost-row dd {color:var(--text);} -body.silver .stadium-place-number,body.matchday .stadium-place-number {background-color:var(--input);border-color:var(--border);} -body.silver .stadium-data-row.head,body.matchday .stadium-data-row.head {color:var(--muted);border-color:var(--border);} -body.silver .stadium-data-row.striped {background-color:#6b552a0c;} -body.matchday .stadium-data-row.striped {background-color:#f8e7e00a;} -/* Ordinary Gold buttons retain their gradient; construction previews use separate palettes. */ -.stadium-nav-button,.stadium-scale,.stadium-dialog-action {background-color:transparent;decorator:linear-gradient(180deg,#c1d1e31c,#869eb312);color:#e0e6ec;} -.stadium-nav-button:hover,.stadium-scale:hover,.stadium-dialog-action:hover {decorator:none;background-color:#d0e2f226;} -.stadium-nav-button[aria-pressed=true],.stadium-scale[aria-pressed=true] {decorator:none;background-color:#9cafc240;border-color:#dce9f047;color:#f5f8fc;} -.stadium-dialog-action.primary:not([disabled]) {decorator:none;background-color:#78b9a533;border-color:#a9dccb52;color:#d7efe5;} -.stadium-block[disabled] {opacity:.85;border-color:#d8b77f52;background-color:#b6955d0d;} -.stadium-facility[disabled] {opacity:.7;} -body.silver .stadium-nav-button,body.silver .stadium-scale,body.silver .stadium-dialog-action {decorator:linear-gradient(180deg,#ffffffd8,#e9e1cf99);background-color:transparent;color:var(--text);border-color:var(--border);} -body.matchday .stadium-nav-button,body.matchday .stadium-scale,body.matchday .stadium-dialog-action {decorator:linear-gradient(180deg,#e8d6dc12,#a1a0aa0d);background-color:transparent;color:var(--text);border-color:var(--border);} -body.silver .stadium-nav-button:hover,body.silver .stadium-scale:hover,body.silver .stadium-dialog-action:hover,body.matchday .stadium-nav-button:hover,body.matchday .stadium-scale:hover,body.matchday .stadium-dialog-action:hover {decorator:none;background-color:var(--hover);} -body.silver .stadium-nav-button[aria-pressed=true],body.silver .stadium-scale[aria-pressed=true] {decorator:none;background-color:#e3d3a878;border-color:#8a7a5570;color:#193b52;} -body.matchday .stadium-nav-button[aria-pressed=true],body.matchday .stadium-scale[aria-pressed=true] {decorator:none;background-color:#d48c7b26;border-color:#e5a19770;color:#ffe5de;} -body.silver .stadium-dialog-action.primary:not([disabled]) {decorator:none;background-color:#e3d3a878;border-color:#8a7a5570;color:#25617a;} -body.matchday .stadium-dialog-action.primary:not([disabled]) {decorator:none;background-color:#d48c7b26;border-color:#e5a19770;color:#efb2aa;} -body.silver .stadium-block[disabled],body.matchday .stadium-block[disabled] {opacity:.85;border-color:#d8b77f52;background-color:#b6955d0d;} - -.stadium-place-label>span {display:block;width:100%;white-space:nowrap;} - -.stadium-periphery-scene {position:absolute;left:0;top:67.375dp;width:2612dp;height:1469.25dp;overflow:hidden;} -.stadium-scene-sprite,.stadium-periphery-preview {position:absolute;display:block;pointer-events:none;} -.stadium-periphery-hit,.stadium-periphery-hit:hover,.stadium-periphery-hit:focus,.stadium-periphery-hit:active {position:absolute;display:block;box-sizing:border-box;padding:0;margin:0;border:0;border-radius:0;background-color:transparent;decorator:none;opacity:1;} -.stadium-periphery-hit .control-label {display:none;} -#stadium-interaction-hint {position:absolute;left:0;top:1568.625dp;width:2612dp;height:56dp;line-height:56dp;text-align:center;font-size:29dp;color:var(--muted);margin:0;} -#stadium-interaction-hint>span {display:block;width:100%;white-space:nowrap;} -.stadium-nav-button.half {width:1295dp;} - -.stadium-screen.periphery .stadium-nav {top:1704.625dp;} - -body.midnight .stadium-summary strong.money-amount,body.silver .stadium-summary strong.money-amount,body.matchday .stadium-summary strong.money-amount {color:var(--money);} -body .stadium-summary strong.money-amount.is-negative {color:var(--danger);} - -/* the stadium as a plan drawn from its blocks */ -.stadium-bowl.stadium-plan,body.silver .stadium-bowl.stadium-plan,body.matchday .stadium-bowl.stadium-plan {border:2dp var(--paper-edge);border-radius:8dp;} -.stadium-letter,body.silver .stadium-letter,body.matchday .stadium-letter {width:76dp;height:76dp;border:3dp #3d362a;border-radius:38dp;background-color:#fdfaf2;color:#3d362a;font-family:Display;font-size:44dp;font-weight:bold;decorator:none;} -.stadium-letter:hover,body.silver .stadium-letter:hover {background-color:#ffffff;border-color:#25617a;color:#25617a;} -.stadium-letter.building {border-color:#c9962e;color:#8a6414;opacity:1;} -.stadium-plan-legend {position:absolute;left:24dp;bottom:16dp;height:40dp;display:flex;align-items:center;font-size:24dp;color:#3d362a;} -body.midnight .stadium-plan-legend,body.matchday .stadium-plan-legend {color:#d5dde3;} -.stadium-plan-legend span {display:block;flex-shrink:0;} -.stadium-plan-legend .key {width:34dp;height:22dp;margin:0 10dp 0 26dp;border:2dp #3d362a;border-radius:3dp;} -.stadium-plan-legend .key.seats {margin-left:0;} -.stadium-plan-legend .key.terrace {background-color:#d8cfb9;} -.stadium-plan-legend .key.roof {background-color:#4d5660;} -.stadium-plan-legend .key.most {background-color:transparent;border:2dp #3d362a88;} -.stadium-plan-legend .key.building {background-color:#c9962e40;border-color:#c9962e;} -.stadium-plan-total {position:absolute;right:24dp;top:18dp;width:420dp;text-align:right;color:#3d362a;} -body.midnight .stadium-plan-total,body.matchday .stadium-plan-total {color:#d5dde3;} -.stadium-plan-total strong {display:block;font-family:Display;font-size:64dp;line-height:70dp;font-weight:bold;} -.stadium-plan-total span {display:block;font-size:26dp;line-height:34dp;margin-bottom:8dp;} -.stadium-block-bar {position:absolute;left:28dp;right:220dp;bottom:10dp;height:8dp;border-radius:4dp;background-color:var(--rule);overflow:hidden;display:block;} -.stadium-block-bar span {display:block;height:8dp;border-radius:4dp;background-color:#9a7a3a;} -.stadium-block-copy strong {font-family:Display;font-size:34dp;font-weight:bold;} -.stadium-plan-total {right:auto;left:24dp;top:16dp;text-align:left;width:380dp;} - -/* the card model */ -.stadium-model {position:absolute;left:0;top:134dp;width:1790dp;height:1600dp;border:2dp var(--paper-edge);border-radius:8dp;overflow:hidden;} -#stadium-model-art {position:absolute;left:0;top:0;width:1790dp;height:1600dp;} -.stadium-model-back,.stadium-model-back:hover {position:absolute;padding:0;border:0dp;border-radius:0dp;background-color:transparent;decorator:none;} -.stadium-model-hit {position:absolute;padding:0;border:3dp transparent;border-radius:12dp;background-color:transparent;decorator:none;} -.stadium-model-hit:hover,.stadium-model-hit:focus-visible {border-color:#25617a;background-color:#25617a1c;} -.stadium-model-hit.chosen {border-color:transparent;background-color:transparent;} -.stadium-model-hit.bowl {display:flex;align-items:flex-start;justify-content:center;font-family:Display;font-size:44dp;color:#25617a;border:3dp #25617a55;} -.stadium-model-tag {position:absolute;width:0;height:0;pointer-events:none;} -.stadium-model-tag>span {display:block;position:absolute;left:-150dp;top:-22dp;width:300dp;height:44dp;line-height:44dp;text-align:center;font-size:26dp;color:#3d362a;white-space:nowrap;} -.stadium-model-tag.letter>span {left:-30dp;top:-30dp;width:60dp;height:60dp;line-height:54dp;border:3dp #3d362a;border-radius:30dp;background-color:#fdfaf2;font-family:Display;font-size:38dp;font-weight:bold;} -.stadium-model-path {position:absolute;left:20dp;top:18dp;height:64dp;display:flex;gap:12dp;} -.stadium-model-crumb {height:60dp;padding:0 28dp;border:2dp var(--rule);border-radius:30dp;background-color:#fdfaf2e0;decorator:none;font-size:30dp;color:#3d362a;display:flex;align-items:center;} -.stadium-model-crumb.here {background-color:#9a7a3a;border-color:#9a7a3a;color:#ffffff;} -.stadium-model-crumb span {display:block;} -.stadium-card {position:absolute;left:1822dp;top:134dp;width:790dp;height:1600dp;border:2dp var(--rule);border-radius:10dp;background-color:var(--panel);padding:36dp;} -.stadium-card h3 {display:block;margin:0 0 20dp 0;font-family:Display;font-size:60dp;line-height:72dp;font-weight:bold;} -.stadium-card .bank-fact {height:84dp;font-size:36dp;} -.stadium-card .bank-fact strong {font-size:42dp;} -.stadium-card .bank-part-track {margin:6dp 0 14dp 0;} -.stadium-card-pips {display:flex;gap:12dp;margin:16dp 0;} -.stadium-card-pips .pip {width:44dp;height:44dp;border:3dp var(--rule);border-radius:8dp;} -.stadium-card-pips .pip.on {background-color:#9a7a3a;border-color:#9a7a3a;} -.stadium-card-note {margin:30dp 0;font-size:32dp;line-height:44dp;color:var(--muted);} -.stadium-card-build {display:flex;align-items:center;justify-content:center;width:100%;height:110dp;font-size:42dp;margin-bottom:20dp;} -.stadium-card-back {display:flex;align-items:center;justify-content:center;width:100%;height:84dp;font-size:34dp;} -.stadium-model-tag>span {left:-160dp;top:-20dp;width:320dp;height:40dp;line-height:40dp;} -.stadium-model-hit,.stadium-model-hit:focus-visible {border-radius:40dp;} -.stadium-model-hit:focus-visible {border-color:transparent;background-color:transparent;} -.stadium-model-tag.letter>span {left:-30dp;top:-30dp;width:60dp;height:60dp;line-height:54dp;} -.stadium-model-tag>span {font-size:28dp;font-weight:bold;} - -/* names on the model stand on a framed field; the list of the surroundings */ -.stadium-model-tag>span {left:-170dp;top:-22dp;width:340dp;height:44dp;line-height:44dp;font-size:30dp;font-weight:bold;color:#3d362a;font-effect:outline(3dp #fffbf2);} -.stadium-model-tag.chosen>span {color:#25617a;} -.stadium-model-tag.letter>span {font-effect:none;} -.stadium-list {padding:28dp 32dp;} -.stadium-list h3 {margin-bottom:10dp;} -.stadium-row {display:flex;align-items:center;width:100%;height:98dp;padding:0 16dp;border:0dp;border-bottom:2dp var(--rule);border-radius:0dp;background-color:transparent;decorator:none;font-size:36dp;text-align:left;} -.stadium-row:hover {background-color:var(--hover);} -.stadium-row span {display:block;flex-shrink:0;} -.stadium-row .name {flex:1;} -.stadium-row .job {margin-right:20dp;font-size:28dp;color:#8a6414;} -.stadium-row-pips {display:flex;gap:8dp;} -.stadium-row-pips .pip {width:30dp;height:30dp;border:3dp var(--rule);border-radius:6dp;} -.stadium-row-pips .pip.on {background-color:#9a7a3a;border-color:#9a7a3a;} -.stadium-row .stadium-row-pips {display:flex;} - -/* --- The model fills the window; the pointer names a part, the card lies over the picture. --- */ -.stadium-model,#stadium-model-art {width:2612dp;} -.stadium-model-hit {overflow:visible;} -.stadium-model-hit:hover {z-index:6;} -.stadium-tip {display:none;position:absolute;width:620dp;height:128dp;padding:14dp 24dp;border:3dp #3d362a;border-radius:10dp;background-color:#fffbf2;color:#3d362a;text-align:left;pointer-events:none;} -.stadium-model-hit:hover .stadium-tip {display:block;} -.stadium-tip strong {display:block;font-family:Display;font-size:38dp;line-height:46dp;white-space:nowrap;} -.stadium-tip span {display:block;font-size:30dp;line-height:40dp;white-space:nowrap;} -.stadium-card {top:166dp;width:800dp;height:auto;z-index:8;} -body.silver .stadium-card {background-color:#fffbf2f6;border-color:#3d362a;} +/* The stadium is a page of the notebook now: its styles are the sd-* rules in pages.rcss. */ diff --git a/src/modern/ui/controls.inc b/src/modern/ui/controls.inc index 781341f..d907f70 100644 --- a/src/modern/ui/controls.inc +++ b/src/modern/ui/controls.inc @@ -123,6 +123,11 @@ void App::drag_event(Rml::Event &event) { } void App::ProcessEvent(Rml::Event &event) try { const auto type = event.GetType(); + // the wheel is only listened to for the stadium's model + if (type == "mousescroll") { + if (menu_ == "stadium" && popup_.empty() && !amount_ && stadium_view_.value("dialog", std::string()).empty()) stadium_stage_event(event); + return; + } if (notebook_home_event(event)) return; if (tactics_page_event(event)) return; if (engine_mode_) { engine_event(event); return; } @@ -691,7 +696,10 @@ void App::dispatch(const std::string &action, Rml::Element *target) { return; } if (action.starts_with("open:")) { - const auto route = action.substr(5); + auto route = action.substr(5); + // the surroundings are the second page of the stadium + const bool surroundings = route == "periphery"; + if (surroundings) route = "stadium"; if(source_&&!demo_career_menu_available(snap().state,route)){message(snap().state.at("career").value("ended",false)?"Diese Partie ist beendet. Bitte ein neues Spiel beginnen oder einen Spielstand laden.":"Dieses Vereinsmenü ist für die Nationalmannschaft nicht verfügbar.");return;} if (route == "kickoff") return; @@ -707,6 +715,7 @@ void App::dispatch(const std::string &action, Rml::Element *target) { return; } if (route == "bank") { bank_view_ = "entrance"; bank_hint_.clear(); } + if (route == "stadium") { if (!stadium_view_.is_object()) stadium_view_ = Json::object(); stadium_view_["view"] = surroundings ? "panorama" : "inside"; stadium_focus_.clear(); } menu_ = route; report_picker_.clear(); report_detail_kind_.clear(); diff --git a/src/modern/ui/engine_controls.inc b/src/modern/ui/engine_controls.inc index 31e164e..1c343bf 100644 --- a/src/modern/ui/engine_controls.inc +++ b/src/modern/ui/engine_controls.inc @@ -481,7 +481,7 @@ void App::engine_event(Rml::Event &event) { else if(action=="engine-open"&&id=="news"){menu_=id;news_dialog_.clear();refresh();} else if(action=="engine-open"&&id=="achievements"){menu_=id;career_view_=Json::object();refresh();} else if(action=="engine-open"&&id=="transfer"){menu_=id;transfer_view_=Json::object();transfer_dialog_.clear();engine_transfer_sync();refresh();} - else if(action=="engine-open"&&id=="stadium"){menu_=id;stadium_view_=Json::object();stadium_view_defaults(stadium_view_);engine_stadium_sync();refresh();} + else if(action=="engine-open"&&(id=="stadium"||id=="periphery")){menu_="stadium";stadium_view_=Json::object();stadium_view_defaults(stadium_view_);if(id=="periphery")stadium_view_["view"]="panorama";stadium_focus_.clear();engine_stadium_sync();refresh();} else if(action=="engine-open"&&id=="toto"){menu_=id;engine_toto_sync();refresh();} else if(action=="engine-open"&&(id=="statistics"||id.starts_with("stat-"))){statistics_open(id);} else if(action=="engine-open"&&id=="load"){engine_files_begin("load");} diff --git a/src/modern/ui/engine_stadium.inc b/src/modern/ui/engine_stadium.inc index b4f989a..15118c6 100644 --- a/src/modern/ui/engine_stadium.inc +++ b/src/modern/ui/engine_stadium.inc @@ -127,96 +127,6 @@ void App::engine_stadium_send(const Json &request, const std::string &operation) return EngineReply{link, link->snapshot(), response, nullptr}; }); } -std::string App::engine_stadium_data() { - const auto &data = engine_data_.at("stadium").at("data"); - std::string svg = ""; - constexpr std::array colors{"#8fbaa6", "#8cacc9", "#adb7c1", - "#cf9088", "#c5b384", "#729aae"}, - names{"Zuschauer", "Eintritt", "Stadionwert", "Zus. Stadion-Einnahmen", - "Einnahmen", "Stadionkosten"}; - for (size_t curve = 0; curve < 6; ++curve) - if (stadium_view_.at("curves")[curve] == true) { - svg += ""; - const auto &points = data.at("history")[curve].at( - stadium_view_.at("relative") == true ? "relative" : "absolute"); - if (points.size() == 1) - svg += ""; - } - svg += ""; - std::string out = "
" + - picture(renderer_.diagram("stadium-engine-graph", svg, 5120), 2560, 456) + - "
"; - for (size_t i = 0; i < 6; ++i) - out += btn("stadium-curve", - "" + - esc(data.at("history")[i].value("name", std::string(names[i]))) + "", - "stadium-curve", - "id=\"stadium-curve-" + std::to_string(i) + "\" data-id=\"" + std::to_string(i) + - "\" aria-pressed=\"" + - (stadium_view_.at("curves")[i] == true ? "true" : "false") + "\" style=\"" + - rect((i % 3) * 754.666666667, 660 + (i / 3) * 90, 732.666666667, 74) + "\""); - for (int i = 0; i < 2; ++i) - out += btn("stadium-scale", i ? "Relativ" : "Absolut", "stadium-scale", - "id=\"stadium-scale-" + std::to_string(i) + "\" data-id=\"" + std::to_string(i) + - "\" aria-pressed=\"" + - (stadium_view_.at("relative") == bool(i) ? "true" : "false") + "\" style=\"" + - rect(2282, 660 + i * 90, 330, 74) + "\""); - const std::array labels{"", "Max. Zuschauer", "Max. Einnahmen (€)", - "Heimspiele", "Ø Zuschauer", "Ges. Einnahmen (€)"}; - out += "
"; - for (size_t row = 0; row < 6; ++row) { - out += "
"; - for (size_t col = 0; col < 4; ++col) { - std::string value; - if (!col) - value = labels[row]; - else if (!row) - value = col == 1 ? "Liga" : col == 2 ? "DFB-Pokal" : "Europapokal"; - else { - const size_t source = row == 1 ? 0 : row == 2 ? 2 : row + 1; - value = data.at("table")[source][col - 1]; - if (row <= 2) { - const auto other = data.at("table")[source + 1][col - 1].get(); - if (!other.empty()) - value += " · " + other; - } - } - out += "
" + - esc(value) + "
"; - } - out += "
"; - } - out += "
"; - const int ticket = int(engine_money_minor(data.at("ticketPrice")) / 100); - out += "

Benötigter Zuschauerschnitt bei " + - std::to_string(ticket) + " € Eintritt: " + - esc(data.at("requiredAttendanceText").get()) + - "

Eintritt:"; - const int low = int(engine_money_minor(data.at("ticketPriceRange").at("min")) / 100), - high = int(engine_money_minor(data.at("ticketPriceRange").at("max")) / 100); - for (int price = low; price <= high; ++price) - out += btn( - "stadium-ticket", (price < 10 ? "0" : "") + std::to_string(price), "stadium-ticket-price", - "id=\"stadium-ticket-" + std::to_string(price) + "\" data-id=\"" + std::to_string(price) + - "\" aria-pressed=\"" + (ticket == price ? "true" : "false") + "\""); - return out + "
"; -} bool App::engine_stadium_action(const std::string &action, Rml::Element *target) { if (!action.starts_with("stadium-")) return false; @@ -387,25 +297,7 @@ bool App::engine_stadium_event(Rml::Event &event) { event.StopImmediatePropagation(); return true; } - if (!dialog && stadium_view_.at("view") == "panorama" && - (type == "mousemove" || type == "focus" || type == "blur")) { - std::string hint; - for (auto *n = target; n && n != doc_; n = n->GetParentNode()) - if (n->HasAttribute("data-stadium-hint")) { - hint = n->GetAttribute("data-stadium-hint", ""); - break; - } - if (type == "blur") - hint.clear(); - if (stadium_view_.at("hint") != hint) { - stadium_view_["hint"] = hint; - if (auto *n = element("stadium-interaction-hint")) - n->SetInnerRML("" + - esc(hint.empty() ? "Ein Element im Stadionumfeld auswählen." : hint) + - ""); - dirty_ = true; - } - } + if (!dialog && stadium_stage_event(event)) return true; Rml::Element *range = nullptr; for (auto *n = target; n && n != doc_; n = n->GetParentNode()) if (n->GetId() == "stadium-place-range") { diff --git a/src/modern/ui/engine_state.inc b/src/modern/ui/engine_state.inc index d5d300c..3f2e8de 100644 --- a/src/modern/ui/engine_state.inc +++ b/src/modern/ui/engine_state.inc @@ -120,7 +120,6 @@ Json stadium_quote_value() const; std::string stadium_cash(const Json &) const; std::string stadium_offer_feedback(const Json &,bool) const; - std::string engine_stadium_data(); void engine_stadium_sync(); void engine_stadium_poll(); void engine_stadium_send(const Json &,const std::string &); diff --git a/src/modern/ui/notebook.inc b/src/modern/ui/notebook.inc index f767d1a..7dbfb03 100644 --- a/src/modern/ui/notebook.inc +++ b/src/modern/ui/notebook.inc @@ -14,7 +14,7 @@ const std::vector ¬ebook_sections() { {"home", "Hauptseite", {}}, {"team", "Mannschaft", {"lineup", "tactics", "training", "camp", "strengths", "scorers"}}, {"transfers", "Transfers", {"transfer", "contracts"}}, - {"club", "Verein", {"stadium", "environment", "advertising"}}, + {"club", "Verein", {"stadium", "periphery", "environment", "advertising"}}, {"finance", "Finanzen", {"balance", "bank", "toto"}}, {"fixtures", "Spielplan", {"calendar", "league", "tables", "other", "friendlies", "postpone", "indoor"}}, {"records", "Statistik", {"statistics", "stat-trend", "stat-winners", "stat-records", "stat-players", "achievements", "almanac", "fairplay", "highscore"}}, @@ -25,7 +25,7 @@ const std::vector ¬ebook_sections() { std::string notebook_page_label(const std::string &route) { static const std::map labels = { {"lineup", "Aufstellung"}, {"tactics", "Taktik"}, {"training", "Training"}, {"camp", "Trainingslager"}, {"strengths", "Stärken"}, - {"scorers", "Spielerstatistik"}, {"transfer", "Transfermarkt"}, {"contracts", "Verträge"}, {"stadium", "Stadion"}, {"environment", "Umfeld"}, + {"scorers", "Spielerstatistik"}, {"transfer", "Transfermarkt"}, {"contracts", "Verträge"}, {"stadium", "Stadion"}, {"periphery", "Peripherie"}, {"environment", "Umfeld"}, {"advertising", "Werbung"}, {"balance", "Bilanz"}, {"bank", "Bank"}, {"toto", "Toto"}, {"calendar", "Kalender"}, {"league", "Ligaspiele"}, {"tables", "Tabellen"}, {"other", "Übrige Spiele"}, {"friendlies", "Testspiele"}, {"postpone", "Verlegen"}, {"indoor", "Halle"}, {"statistics", "Analyse"}, {"stat-trend", "Verlauf"}, {"stat-winners", "Sieger"}, {"stat-records", "Rekorde"}, {"stat-players", "Spieler"}, {"achievements", "Erfolge"}, {"almanac", "Almanach"}, {"fairplay", "Fairplay"}, {"highscore", "Highscore"}, @@ -201,7 +201,10 @@ std::string App::notebook_shell(const std::function & // the statistics are one menu with several pages; the demo has only its first const bool part = std::string_view(r).starts_with("stat-") || std::string_view(r) == "statistics"; if (!engine_mode_ && std::string_view(r).starts_with("stat-")) continue; - const bool here = part && engine_mode_ ? menu_ == "statistics" && statistics_page_ == r : menu_ == r; + // the ground is one menu with two pages: the stadium and what stands around it + const bool ground = std::string_view(r) == "stadium" || std::string_view(r) == "periphery"; + const bool here = ground ? menu_ == "stadium" && (stadium_view_.value("view", std::string("inside")) == "panorama") == (std::string_view(r) == "periphery") + : part && engine_mode_ ? menu_ == "statistics" && statistics_page_ == r : menu_ == r; if (here) { kicker = std::string(section.label) + " · " + std::to_string(n + 1) + " / " + std::to_string(section.routes.size()); heading = notebook_page_label(r); @@ -210,7 +213,7 @@ std::string App::notebook_shell(const std::function & std::string("nb-sub") + (here ? " active" : ""), "id=\"page-" + std::string(r) + "\" aria-pressed=\"" + (here ? "true" : "false") + "\" style=\"transform:translateY(" + (here ? std::string("-13") : std::to_string(sub_rest[n % sub_rest.size()])) + "dp) rotate(" + scalar(sub_turns[n % sub_turns.size()]) + "deg);\"", - enabled(part ? "statistics" : r)); + enabled(part ? "statistics" : ground ? "stadium" : r)); ++n; } } diff --git a/src/modern/ui/pages.inc b/src/modern/ui/pages.inc index 092fd86..44563e0 100644 --- a/src/modern/ui/pages.inc +++ b/src/modern/ui/pages.inc @@ -5,7 +5,7 @@ // The menus that are laid out as a page of the notebook. Every other career menu is still a // sheet of the old format, shown scaled inside the book. bool App::page_native() const { - static const std::set native{"statistics", "news", "transfer", "training", "almanac", "tactics", "achievements", "highscore", "balance", "contracts", "environment", "tables", "league", "other", "strengths", "fairplay", "indoor", "scorers"}; + static const std::set native{"stadium", "statistics", "news", "transfer", "training", "almanac", "tactics", "achievements", "highscore", "balance", "contracts", "environment", "tables", "league", "other", "strengths", "fairplay", "indoor", "scorers"}; if (menu_ == "calendar" || menu_ == "postpone" || menu_ == "lineup") return notebook_page() && engine_mode_; // a national coach arranges friendlies on the older sheet if (menu_ == "friendlies") return notebook_page() && engine_mode_ && engine_data_.contains("desktop") && engine_data_.at("desktop").at("meta").at("scope").at("role") == "club"; diff --git a/src/modern/ui/stadium_controls.inc b/src/modern/ui/stadium_controls.inc index 5497ac5..165e349 100644 --- a/src/modern/ui/stadium_controls.inc +++ b/src/modern/ui/stadium_controls.inc @@ -25,36 +25,111 @@ void App::sync_stadium_draft() { if(stadium_view_.at("dialog")=="block")if(auto *button=element("stadium-place-number"))button->SetInnerRML(""+std::to_string(stadium_view_.at("draft").at("places").get())+""); dirty_=true; } -// The camera of the card model: a new focus starts a flight of 0.6 seconds, during which -// only the picture is drawn anew; reduced motion jumps. +// Choosing a part of the model, and laying the view back to where it started. bool App::stadium_focus_action(const std::string &action,Rml::Element *target) { - if(action!="stadium-focus"||!target)return false; - // the camera stands still: a click only chooses the part (the screen drops a part that - // does not belong to its view) - const auto next=std::string(target->GetAttribute("data-id","")); + if(action=="stadium-reset") { + stadium_view_defaults(stadium_view_); + stadium_cams_.erase(stadium_view_.at("view")=="panorama"?"panorama":"inside"); + focus_after_render_="stadium-reset";refresh();return true; + } + if((action!="stadium-focus"&&action!="stadium-pick")||!target)return false; + // the click that ends a drag of the view chooses nothing + if(stadium_dragged_){stadium_dragged_=false;return true;} + // a click on the stage chooses what lies under the pointer, or lets go of the chosen part + const auto next=action=="stadium-pick"?stadium_hover_:std::string(target->GetAttribute("data-id","")); if(next==stadium_focus_)return true; - stadium_flying_=false; stadium_focus_=next; focus_after_render_=next.find(':')!=std::string::npos?"stadium-card-build":""; refresh(); return true; } -void App::stadium_camera_tick() { - if(!stadium_flying_)return; - if(menu_!="stadium"||!world_){stadium_flying_=false;return;} - const double t=std::min(1.0,double(SDL_GetTicks64()-stadium_flight_start_)/600.0); - stadium_camera_=stadium3d::mix(stadium_camera_from_,stadium_camera_to_,t); - if(t>=1){stadium_flying_=false;refresh();return;} - stadium_view_defaults(stadium_view_); - const auto overview=stadium_overview(stadium_view_.at("future").get()); - auto *art=element("stadium-model-art"); - if(!overview.value("ok",false)||!art){stadium_flying_=false;refresh();return;} - std::string seat_colour; - if(const auto *own=world_->find("clubs",overview.value("club",std::string()));own&&!own->value("crest","").empty())seat_colour=renderer_.crest_colour(own->value("crest","")); - if(seat_colour.empty())seat_colour="#3d6f8f"; - const auto drawing=stadium3d::draw(stadium3d::build(overview,seat_colour,theme_=="silver"),stadium_camera_,1790,1600); - art->SetInnerRML(picture(renderer_.diagram("stadium-model",drawing.svg,1790),1790,1600)); +// Looking around on the stage: the wheel zooms towards the pointer, dragging moves the view, +// and the pointer over a part shows what stands there. Only the place of the picture changes; +// nothing is drawn anew. +bool App::stadium_stage_event(Rml::Event &event) { + auto *stage=element("stadium-stage");auto *world=element("stadium-world"); + if(!stage||!world)return false; + const auto type=event.GetType(); + if(type!="mousemove"&&type!="mousedown"&&type!="mouseup"&&type!="mousescroll")return false; + const bool outer=stadium_view_.value("view",std::string())=="panorama"; + // the pointer on the stage, in units of the page + const double mx=(event.GetParameter("mouse_x",0)-stage->GetAbsoluteLeft())/scale_/2.25,my=(event.GetParameter("mouse_y",0)-stage->GetAbsoluteTop())/scale_/2.25; + const bool on_world=event.GetTargetElement()&&event.GetTargetElement()->GetId()=="stadium-model-ground"; + // the part under the pointer: the one in front wins + const auto under=[&](const std::array &cam)->std::string { + if(!on_world)return {}; + const double x=(mx-cam[1])/cam[0],y=(my-cam[2])/cam[0];std::string found; + for(const auto &part:stadium_hots_) + for(const auto &quad:part.quads) { + const auto a=stadium_scene::project(quad.a),b=stadium_scene::project(quad.b),d=stadium_scene::project(quad.d); + const double ux=b.x-a.x,uy=b.y-a.y,vx=d.x-a.x,vy=d.y-a.y,det=ux*vy-uy*vx; + if(std::abs(det)<1e-6)continue; + const double s=((x-a.x)*vy-(y-a.y)*vx)/det,t=(ux*(y-a.y)-uy*(x-a.x))/det; + if(s>=0&&s<=1&&t>=0&&t<=1){found=part.id;break;} + } + return found; + }; + const auto part_element=[&](const std::string &id){return id.empty()?nullptr:element("stadium-part-"+id.substr(0,id.find(':'))+"-"+id.substr(id.find(':')+1));}; + const auto hover=[&](const std::string &id) { + if(id==stadium_hover_)return; + if(auto *old=part_element(stadium_hover_))old->SetClass("hover",false); + if(auto *now=part_element(id))now->SetClass("hover",true); + stadium_hover_=id;dirty_=true; + }; + const auto place=[&](std::array cam) { + constexpr double w=stadium_scene::width,h=stadium_scene::height; + cam[0]=std::clamp(cam[0],.75,3.2); + cam[1]=std::clamp(cam[1],std::min(240.0,w-w*cam[0]-240),std::max(240.0,w-w*cam[0]-240)); + cam[2]=std::clamp(cam[2],std::min(240.0,h-h*cam[0]-240),std::max(240.0,h-h*cam[0]-240)); + stadium_cams_[outer?"panorama":"inside"]=cam; + world->SetProperty("left",pg(cam[1]));world->SetProperty("top",pg(cam[2]));world->SetProperty("transform","scale("+scalar(cam[0])+")"); + dirty_=true; + }; + auto *tip=element("stadium-tip"); + if(type=="mousescroll") { + if(!on_world)return false; + auto cam=stadium_cam(outer); + const double zoom=std::clamp(cam[0]*std::exp(-event.GetParameter("wheel_delta_y",0)*.16),.75,3.2); + cam[1]=mx-(mx-cam[1])*zoom/cam[0];cam[2]=my-(my-cam[2])*zoom/cam[0];cam[0]=zoom; + place(cam); + if(tip)tip->SetProperty("display","none"); + event.StopImmediatePropagation();return true; + } + if(type=="mousedown") { + stadium_dragged_=false;hover(under(stadium_cam(outer))); + if(on_world&&event.GetParameter("button",0)==0)stadium_drag_={{"x",mx},{"y",my},{"moved",false}}; + return false; + } + if(type=="mouseup") { + if(stadium_drag_.is_object()&&stadium_drag_.at("moved")==true)stadium_dragged_=true; + stadium_drag_=Json(); + return false; + } + if(stadium_drag_.is_object()) { + const double dx=mx-stadium_drag_.at("x").get(),dy=my-stadium_drag_.at("y").get(); + if(stadium_drag_.at("moved")!=true&&std::hypot(dx,dy)<5)return false; + auto cam=stadium_cam(outer);cam[1]+=dx;cam[2]+=dy; + stadium_drag_={{"x",mx},{"y",my},{"moved",true}}; + place(cam);hover({}); + if(tip)tip->SetProperty("display","none"); + return true; + } + // what the pointer is on + hover(under(stadium_cam(outer))); + if(!tip)return false; + std::string name,state; + if(auto *n=part_element(stadium_hover_)){name=n->GetAttribute("data-tip-name","");state=n->GetAttribute("data-tip-state","");} + const auto shown=name+"|"+state; + if(name.empty()) { + if(!stadium_tip_.empty()){stadium_tip_.clear();tip->SetProperty("display","none");dirty_=true;} + return false; + } + if(stadium_tip_!=shown){stadium_tip_=shown;tip->SetInnerRML(""+esc(name)+""+esc(state)+"");} + tip->SetProperty("display","block"); + stadium_tip_at_={std::min(mx+16,stadium_scene::width-330),std::max(4.0,my-34)}; + tip->SetProperty("left",pg(stadium_tip_at_[0]));tip->SetProperty("top",pg(stadium_tip_at_[1])); dirty_=true; + return false; } bool App::stadium_action(const std::string &action,Rml::Element *target) { if(engine_mode_)return engine_stadium_action(action,target); @@ -154,13 +229,7 @@ bool App::stadium_event(Rml::Event &event) { else return false; event.StopImmediatePropagation();return true; } - if(!dialog&&stadium_view_.at("view")=="panorama"&&(type=="mousemove"||type=="focus"||type=="blur")) { - const auto hint=[&](Rml::Element *from) {for(auto *n=from;n&&n!=doc_;n=n->GetParentNode())if(n->HasAttribute("data-stadium-hint"))return n->GetAttribute("data-stadium-hint","");return Rml::String();}; - auto text=hint(target); - if(type=="focus"&&text.empty()&&target&&target->GetId()!="stadium-back"&&target->GetId()!="stadium-future"&&target->GetId()!="window-close")return false; - if(type=="blur")text=""; - if(stadium_view_.at("hint")!=text) {stadium_view_["hint"]=text;if(auto *n=element("stadium-interaction-hint"))n->SetInnerRML(""+esc(text.empty()?"Ein Element im Stadionumfeld auswählen.":text)+"");dirty_=true;} - } + if(!dialog&&stadium_stage_event(event))return true; Rml::Element *place_range=nullptr; for(auto *node=target;node&&node!=doc_;node=node->GetParentNode())if(node->GetId()=="stadium-place-range"){place_range=node;break;} if(dialog&&type=="keydown"&&place_range&&stadium_view_.at("dialog")=="block"&&(key==Rml::Input::KI_HOME||key==Rml::Input::KI_END)) { @@ -192,7 +261,6 @@ bool App::stadium_event(Rml::Event &event) { if(target->HasAttribute("data-stadium-feature")) { const auto field=target->GetAttribute("data-stadium-feature","");if(field!="seats"&&field!="roof")return true; stadium_view_["draft"][field]=target->HasAttribute("checked");stadium_view_["feedback"]=""; - if(auto *image=element("stadium-feature-image-"+field)){const bool checked=stadium_view_.at("draft").at(field).get();image->SetInnerRML(picture(renderer_.diagram("stadium-feature-"+field+(checked?"-built-":"-empty-")+theme_,stadium_feature_svg(field,checked,theme_),232),116,116));} sync_stadium_draft();event.StopImmediatePropagation();return true; } } diff --git a/src/modern/ui/stadium_model.hpp b/src/modern/ui/stadium_model.hpp deleted file mode 100644 index 04e90e1..0000000 --- a/src/modern/ui/stadium_model.hpp +++ /dev/null @@ -1,518 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-only -#pragma once -// The stadium and its surroundings as a card model: bodies built from the blocks, -// facilities and periphery of the stadium overview, seen through a camera, sorted by depth -// and drawn as a vector picture. No renderer is involved: the same picture comes out on -// every platform, and the same input always gives the same picture. -// -// World: x east, y north, z up, the centre spot at the origin; lengths roughly in metres. -// Camera: an axonometric view (no perspective) turned by `yaw` around the vertical axis and -// raised by `pitch` above the ground, both in degrees. -#include "modern/ui/catalog.hpp" -#include -#include -#include -#include -#include -#include -#include - -namespace bmh::modern_ui::stadium3d { -struct Vec { double x = 0, y = 0, z = 0; }; -struct Camera { double yaw = 28, pitch = 40, zoom = 1, tx = 0, ty = 0; }; -struct Face { - std::vector points; - std::string fill; // "#rrggbb"; empty for an outline - std::string part; // the selectable part it belongs to, e.g. "block:3" - bool dashed = false, open = false, flat = false; // flat: keep the fill as it is (no shading) - double stroke = 2, opacity = 1; - std::string ink; // stroke colour; empty: the scene's ink - std::vector> lines; // drawn on the face, in its ink at 40 % - double bias = 0; // moves the face towards the viewer in the depth order -}; -struct Part { std::string id; Vec centre; double x0 = 0, y0 = 0, x1 = 0, y1 = 0, cx = 0, cy = 0; bool seen = false; }; -struct Anchor { std::string id; double x = 0, y = 0; }; -// centres: where a part's name stands and the camera flies to; anchors: every spot a click -// may choose the part at (the four masts of the floodlights are four anchors of one part) -struct Scene { std::vector faces; std::map centres; std::vector> anchors; std::string ink = "#3d362a", accent = "#25617a"; }; -struct Drawing { std::string svg; std::vector parts; std::vector anchors; }; - -inline std::string num(double value) { - std::ostringstream out; - out.imbue(std::locale::classic()); - out << std::round(value * 10) / 10; - return out.str(); -} -inline std::string shade(const std::string &colour, double factor) { - if (colour.size() != 7 || colour[0] != '#') return colour; - std::string out = "#"; - for (size_t at = 1; at < 7; at += 2) { - const int value = std::clamp(int(std::lround(std::stoi(colour.substr(at, 2), nullptr, 16) * factor)), 0, 255); - static constexpr char digits[] = "0123456789abcdef"; - out += digits[value / 16]; - out += digits[value % 16]; - } - return out; -} -inline Camera mix(const Camera &a, const Camera &b, double t) { - const double s = t * t * (3 - 2 * t); // ease in and out - double turn = std::fmod(b.yaw - a.yaw, 360.0); - if (turn > 180) turn -= 360; - if (turn < -180) turn += 360; - return {a.yaw + turn * s, a.pitch + (b.pitch - a.pitch) * s, a.zoom + (b.zoom - a.zoom) * s, a.tx + (b.tx - a.tx) * s, a.ty + (b.ty - a.ty) * s}; -} - -// The eight stands lie on a ring around the pitch; angles in degrees, counted from the east -// towards the south (as on the plan: A north-west, B north, ... H west). -constexpr std::array, 8> spans{{{{205, 245}}, {{245, 295}}, {{295, 335}}, {{-25, 25}}, {{25, 65}}, {{65, 115}}, {{115, 155}}, {{155, 205}}}}; -inline Vec ring(double degrees, double offset, double z) { - const double a = degrees * 3.14159265358979 / 180; - return {(74 + offset) * std::cos(a), -(52 + offset) * std::sin(a), z}; -} -inline double stand_depth(int64_t places, int64_t greatest) { return 12 + 44.0 * double(std::max(0, places)) / double(std::max(1, greatest)); } - -inline void box(Scene &scene, const std::string &part, double x, double y, double w, double d, double h, const std::string &fill, bool planned = false, double z = 0) { - const Vec a{x - w / 2, y - d / 2, z}, b{x + w / 2, y - d / 2, z}, c{x + w / 2, y + d / 2, z}, e{x - w / 2, y + d / 2, z}; - if (planned) { // not built: its footprint only - scene.faces.push_back({{a, b, c, e}, "", part, true, false, false, 2.5, .8, "", {}, 2}); - return; - } - const auto up = [&](Vec v) { v.z = z + h; return v; }; - for (const auto &[p, q] : std::array, 4>{{{a, b}, {b, c}, {c, e}, {e, a}}}) - scene.faces.push_back({{p, q, up(q), up(p)}, fill, part}); - scene.faces.push_back({{up(a), up(b), up(c), up(e)}, fill, part}); -} - -// Builds the model. `seats` is the club's colour; `paper` selects the light skin's tones. -inline Scene build(const Json &overview, const std::string &seats, bool paper, int mode = 0) { - Scene scene; - scene.ink = paper ? "#3d362a" : "#d5dde3"; - scene.accent = paper ? "#25617a" : "#9ac7d8"; - const std::string plate = paper ? "#efe4c8" : "#27323c", wall = paper ? "#f6efdc" : "#55616c", terrace = paper ? "#d6ccb4" : "#6a7680", - roof = paper ? "#5a646e" : "#161d24", glass = "#9fc4d6", gold = "#c9962e", lamp = "#f3d778"; - const auto level_of = [](const Json &row) { return row.value("display_level", row.value("level", 0)); }; - const auto building = [](const Json &row) { return row.value("building", false); }; - // the plate everything stands on - // inside, the plate runs beyond the picture; around, it is the plot with its edge - const double px = mode == 1 ? 262 : 900, py = mode == 1 ? 208 : 900; - scene.faces.push_back({{{-px, -py, 0}, {px, -py, 0}, {px, py, 0}, {-px, py, 0}}, plate, "", false, false, true, 3, 1, "", {}, -1000}); - // the pitch: its colour tells the state of the turf (facility 4) - const auto &facilities = overview.value("facilities", Json::array()); - const auto facility = [&](size_t index) -> const Json & { static const Json none = Json::object(); return index < facilities.size() ? facilities[index] : none; }; - const int turf = facilities.size() > 4 ? level_of(facility(4)) : 3; - const std::array, 5> greens{{{"#a39a5c", "#b3a868"}, {"#8f9e58", "#9dab62"}, {"#6fa25c", "#7bae66"}, {"#4f9a5c", "#57a765"}, {"#3f9456", "#49a260"}}}; - const auto &green = greens[size_t(std::clamp(turf, 0, 4))]; - { - std::vector oval; - for (int a = 0; a < 360; a += 10) oval.push_back(ring(a, -4, 0)); - scene.faces.push_back({oval, paper ? "#e2d6b8" : "#323e49", "", false, false, true, 2.5, 1, "", {}, -900}); - for (int stripe = 0; stripe < 10; ++stripe) { - const double x0 = -52.5 + stripe * 10.5; - Face f{{{x0, -34, 0}, {x0 + 10.5, -34, 0}, {x0 + 10.5, 34, 0}, {x0, 34, 0}}, green[size_t(stripe % 2)], "facility:4", false, false, true, 0, 1, "", {}, -800}; - scene.faces.push_back(f); - } - Face lines{{{-52.5, -34, 0}, {52.5, -34, 0}, {52.5, 34, 0}, {-52.5, 34, 0}}, "", "facility:4", false, false, true, 3, 1, "#f4f7ef", {}, -700}; - scene.faces.push_back(lines); - scene.faces.push_back({{{0, -34, 0}, {0, 34, 0}}, "", "", false, true, true, 3, 1, "#f4f7ef", {}, -700}); - std::vector circle; - for (int a = 0; a <= 360; a += 20) circle.push_back({9.15 * std::cos(a * 3.14159265 / 180), 9.15 * std::sin(a * 3.14159265 / 180), 0}); - scene.faces.push_back({circle, "", "", false, true, true, 3, 1, "#f4f7ef", {}, -700}); - for (const double side : {-1.0, 1.0}) - scene.faces.push_back({{{side * 52.5, -20, 0}, {side * 36, -20, 0}, {side * 36, 20, 0}, {side * 52.5, 20, 0}}, "", "", false, true, true, 3, 1, "#f4f7ef", {}, -700}); - // turf heating (facility 2): pipes under the grass show through - if (facilities.size() > 2 && level_of(facility(2)) > 1) - for (double y = -28; y <= 28; y += 8) - scene.faces.push_back({{{-48, y, 0}, {48, y, 0}}, "", "facility:2", true, true, true, 2.5, .7, "#c8553d", {}, -650}); - scene.centres["facility:4"] = {0, 0, 0}; - } - // the stands - const auto &blocks = overview.at("blocks"); - int64_t greatest = 1; - for (const auto &b : blocks) greatest = std::max(greatest, b.at("max_places").get()); - double deepest = 0; - for (size_t i = 0; i < 8 && i < blocks.size(); ++i) { - const auto &b = blocks[i]; - const std::string part = "block:" + std::to_string(i); - const double from = spans[i][0] + 1.6, to = spans[i][1] - 1.6, inner = 5; - const double depth = stand_depth(b.at("display_places").get(), greatest), most = stand_depth(b.at("max_places").get(), greatest); - const double top = 3 + depth * .58, outer = inner + depth; - deepest = std::max(deepest, inner + most); - const bool seated = b.at("display_seats").get(), roofed = b.at("display_roof").get(); - const std::string tread = seated ? seats : terrace; - const int steps = 4; - for (int s = 0; s < steps; ++s) { - const double a0 = from + (to - from) * s / steps, a1 = from + (to - from) * (s + 1) / steps; - Face slope{{ring(a0, inner, 2), ring(a1, inner, 2), ring(a1, outer, top), ring(a0, outer, top)}, tread, part}; - for (int row = 1; row < 5; ++row) { // rows of seats, or the steps of a terrace - const double t = row / 5.0; - slope.lines.push_back({ring(a0, inner + depth * t, 2 + (top - 2) * t), ring(a1, inner + depth * t, 2 + (top - 2) * t)}); - } - scene.faces.push_back(slope); - scene.faces.push_back({{ring(a0, outer, 0), ring(a1, outer, 0), ring(a1, outer, top), ring(a0, outer, top)}, wall, part}); - scene.faces.push_back({{ring(a0, inner, 0), ring(a1, inner, 0), ring(a1, inner, 2), ring(a0, inner, 2)}, wall, part}); - if (roofed) { - const double edge = inner + depth * .45, height = top + 7; - Face slab{{ring(a0, edge, height + 2), ring(a1, edge, height + 2), ring(a1, outer + 3, height), ring(a0, outer + 3, height)}, roof, part}; - slab.bias = 6; - slab.lines.push_back({ring(a0, outer, top), ring(a0, outer + 1, height)}); // a post - scene.faces.push_back(slab); - } - } - for (const double a : {from, to}) - scene.faces.push_back({{ring(a, inner, 0), ring(a, inner, 2), ring(a, outer, top), ring(a, outer, 0)}, wall, part}); - // how far the stand may grow: its footprint as a dashed line - std::vector limit; - for (int s = 0; s <= steps; ++s) limit.push_back(ring(from + (to - from) * s / steps, inner + most, 0)); - limit.push_back(ring(to, outer, 0)); - limit.insert(limit.begin(), ring(from, outer, 0)); - scene.faces.push_back({limit, "", part, true, true, true, 2.5, .55, "", {}, 0}); - if (building(b)) { // a frame of scaffolding at the size being built - const double target = inner + stand_depth(b.at("job").value("places", b.at("display_places").get()), greatest); - const double height = 3 + (target - inner) * .58; - for (int s = 0; s < steps; ++s) { - const double a0 = from + (to - from) * s / steps, a1 = from + (to - from) * (s + 1) / steps; - Face frame{{ring(a0, target + 2, 0), ring(a1, target + 2, 0), ring(a1, target + 2, height + 9), ring(a0, target + 2, height + 9)}, gold, part, true, false, true, 3, .28, gold, {}, 4}; - scene.faces.push_back(frame); - } - } - scene.centres[part] = ring((from + to) / 2, inner + depth / 2, top / 2); - } - // facility 0: four floodlight masts, taller and brighter with every level - if (!facilities.empty()) { - const int level = level_of(facility(0)); - for (const double a : {45.0, 135.0, 225.0, 315.0}) { - const Vec foot = ring(a, deepest + 16, 0); - const double height = 34 + 9 * level; - if (level <= 0) { box(scene, "facility:0", foot.x, foot.y, 8, 8, 1, wall, true); continue; } - scene.faces.push_back({{foot, {foot.x, foot.y, height}}, "", "facility:0", false, true, true, 5, 1, "", {}, 3}); - const double w = 7 + 2 * level, h = 4 + 1.5 * level; - const double nx = -foot.y / std::hypot(foot.x, foot.y), ny = foot.x / std::hypot(foot.x, foot.y); - Face panel{{{foot.x - nx * w, foot.y - ny * w, height - h}, {foot.x + nx * w, foot.y + ny * w, height - h}, {foot.x + nx * w, foot.y + ny * w, height + h}, {foot.x - nx * w, foot.y - ny * w, height + h}}, - lamp, "facility:0", false, false, true, 2.5, 1, "", {}, 5}; - for (int row = 1; row <= level; ++row) panel.lines.push_back({{foot.x - nx * w, foot.y - ny * w, height - h + 2 * h * row / (level + 1)}, {foot.x + nx * w, foot.y + ny * w, height - h + 2 * h * row / (level + 1)}}); - scene.faces.push_back(panel); - scene.anchors.push_back({"facility:0", {foot.x, foot.y, height}}); - } - scene.centres["facility:0"] = ring(45, deepest + 16, 30); - } - // facility 1: the score board behind the east curve - if (facilities.size() > 1) { - const int level = level_of(facility(1)); - const Vec at = ring(0, deepest + 14, 0); - if (level <= 0) box(scene, "facility:1", at.x, at.y, 6, 30, 1, wall, true); - else { - box(scene, "facility:1", at.x, at.y - 12, 2, 2, 14, wall); - box(scene, "facility:1", at.x, at.y + 12, 2, 2, 14, wall); - box(scene, "facility:1", at.x, at.y, 4, 26 + 4 * level, 8 + 3 * level, "#2c3640", false, 14); - } - scene.centres["facility:1"] = {at.x, at.y, 16}; - } - // facility 3: the lounge, a glass box on the south stand - if (facilities.size() > 3 && blocks.size() > 5) { - const int level = level_of(facility(3)) - 1; - const Vec at = ring(90, 5 + stand_depth(blocks[5].at("display_places").get(), greatest) + 9, 0); - if (level <= 0) box(scene, "facility:3", at.x, at.y, 40, 10, 1, wall, true); - else box(scene, "facility:3", at.x, at.y, 34 + 8 * level, 10, 6 + 4 * level, glass); - scene.centres["facility:3"] = {at.x, at.y, 8}; - } - // facilities 2, 5, 6, 7 as small houses beside the ground: boiler, kiosks, workshop, gate - const std::array, 4> houses{{{2, -160, -66, "#c8a58a"}, {5, 140, -92, "#d9c38a"}, {6, -148, 72, "#b9b3a2"}, {7, 160, 82, "#a9b7a0"}}}; - for (const auto &[index, x, y, colour] : houses) { - if (mode == 1) break; - if (index >= facilities.size()) continue; - const std::string part = "facility:" + std::to_string(index); - const int level = level_of(facility(index)) - (index == 2 || index == 5 ? 1 : 0); - if (level <= 0) box(scene, part, x, y, 26, 18, 1, wall, true); - else - for (int n = 0; n < std::min(level, 4); ++n) box(scene, part, x + (n - (std::min(level, 4) - 1) / 2.0) * 20, y, 16, 16, 7 + 2 * level, colour); - scene.centres[part] = {x, y, 6}; - } - // The surroundings (mode 1): every object in its own shape and at its own place, drawn at - // its level. Level 0 is a dashed footprint, a level being built a dashed frame in gold. - if (mode == 1) { - // the surroundings stand on a plot of their own, without the ground: only the plate stays - scene.faces.resize(1); - scene.centres.clear(); - scene.anchors.clear(); - const std::string asphalt = paper ? "#b9b2a4" : "#3c444c", brick = "#c9a58c", plaster = "#efe6cf", tile = "#a8574f", slate = paper ? "#6b747d" : "#20272e", - wood = "#b98d5a", green = "#7fa86b", white = "#f7f4ea"; - const auto &periphery = overview.value("periphery", Json::array()); - const auto flat = [&](const std::string &part, double x, double y, double w, double d, const std::string &fill, double bias = -500) { - scene.faces.push_back({{{x - w / 2, y - d / 2, 0.2}, {x + w / 2, y - d / 2, 0.2}, {x + w / 2, y + d / 2, 0.2}, {x - w / 2, y + d / 2, 0.2}}, fill, part, false, false, true, 2, 1, "", {}, bias}); - }; - const auto stripe = [&](double x0, double y0, double x1, double y1, const std::string &ink, bool dashed = false) { - scene.faces.push_back({{{x0, y0, 0.3}, {x1, y1, 0.3}}, "", "", dashed, true, true, 2.2, 1, ink, {}, -450}); - }; - // a house with a pitched roof; the ridge runs along x - const auto gabled = [&](const std::string &part, double x, double y, double w, double d, double h, double rise, const std::string &walls, const std::string &roofing) { - box(scene, part, x, y, w, d, h, walls); - const Vec a{x - w / 2, y - d / 2, h}, b{x + w / 2, y - d / 2, h}, c{x + w / 2, y + d / 2, h}, e{x - w / 2, y + d / 2, h}, r0{x - w / 2, y, h + rise}, r1{x + w / 2, y, h + rise}; - scene.faces.push_back({{a, b, r1, r0}, roofing, part, false, false, false, 2, 1, "", {}, 3}); - scene.faces.push_back({{e, c, r1, r0}, roofing, part, false, false, false, 2, 1, "", {}, 3}); - scene.faces.push_back({{a, e, r0}, walls, part, false, false, false, 2, 1, "", {}, 3}); - scene.faces.push_back({{b, c, r1}, walls, part, false, false, false, 2, 1, "", {}, 3}); - }; - // windows as lines on the front (the side towards the viewer, lower y) - const auto windows = [&](const std::string &part, double x, double y, double w, double d, double z0, double z1, int count) { - Face glassy{{{x - w / 2 + 2, y - d / 2 - .2, z0}, {x + w / 2 - 2, y - d / 2 - .2, z0}, {x + w / 2 - 2, y - d / 2 - .2, z1}, {x - w / 2 + 2, y - d / 2 - .2, z1}}, glass, part, false, false, true, 1.5, 1, "", {}, 4}; - for (int n = 1; n < count; ++n) glassy.lines.push_back({{x - w / 2 + 2 + (w - 4) * n / count, y - d / 2 - .2, z0}, {x - w / 2 + 2 + (w - 4) * n / count, y - d / 2 - .2, z1}}); - scene.faces.push_back(glassy); - }; - const auto tree = [&](double x, double y) { - scene.faces.push_back({{{x, y, 0}, {x, y, 5}}, "", "", false, true, true, 3, 1, "#6b5335", {}, 2}); - box(scene, "", x, y, 7, 7, 8, green, false, 5); - }; - const auto car = [&](const std::string &part, double x, double y, int tone) { - static constexpr std::array paints{"#c8553d", "#3f6f9f", "#e8e2d2", "#5b6168", "#d9b13b"}; - box(scene, part, x, y, 4.2, 8.5, 2.6, paints[size_t(tone) % paints.size()]); - }; - const auto level_at = [&](size_t i) { return i < periphery.size() ? periphery[i].value("level", 0) : 0; }; - const auto planned = [&](const std::string &part, double x, double y, double w, double d, bool busy) { - box(scene, part, x, y, w, d, 1, wall, true); - if (busy) scene.faces.push_back({{{x - w / 2, y - d / 2, 0}, {x + w / 2, y - d / 2, 0}, {x + w / 2, y - d / 2, 14}, {x - w / 2, y - d / 2, 14}}, gold, part, true, false, true, 3, .25, gold, {}, 4}); - }; - const auto centre = [&](size_t i, double x, double y, double z) { scene.centres["periphery:" + std::to_string(i)] = {x, y, z}; }; - const auto busy_at = [&](size_t i) { return i < periphery.size() && building(periphery[i]); }; - // 0 transport: a road, then a bus stop, a tram line, a station - if (!periphery.empty()) { - const std::string part = "periphery:0"; - const int level = level_at(0); - if (level <= 0) planned(part, 0, -160, 480, 26, busy_at(0)); - else { - flat(part, 0, -160, 524, 24, asphalt); - stripe(-262, -160, 262, -160, white, true); - flat(part, 0, -30, 22, 236, asphalt); // the avenue through the quarter - if (level >= 2) { // bus stop: shelter and two buses - box(scene, part, -70, -141, 30, 5, 7, glass); - box(scene, part, -120, -157, 26, 7, 8, "#d9b13b"); - box(scene, part, 60, -164, 26, 7, 8, "#d9b13b"); - } - if (level >= 3) { // tram: rails and a tram - stripe(-262, -183, 262, -183, slate); - stripe(-262, -187, 262, -187, slate); - box(scene, part, 150, -185, 44, 6, 8, "#c8553d"); - box(scene, part, 110, -176, 60, 4, 1.5, plaster); - } - if (level >= 4) { // station hall - gabled(part, -180, -186, 90, 30, 16, 10, brick, slate); - windows(part, -180, -186, 90, 30, 4, 12, 9); - } - if (busy_at(0)) planned(part, -180, -186, 96, 36, true); - } - centre(0, level >= 4 ? -180 : -70, -160, 6); - } - // 4 parking: a lot per level, with bays and cars - if (periphery.size() > 4) { - const std::string part = "periphery:4"; - const int level = level_at(4), most = std::max(1, periphery[4].value("max_level", 3)); - for (int lot = 0; lot < most; ++lot) { - const double x = -192, y = 132 - lot * 72; - if (lot >= level) { planned(part, x, y, 110, 62, lot == level && busy_at(4)); continue; } - flat(part, x, y, 110, 62, asphalt); - for (int bay = 0; bay <= 10; ++bay) { stripe(x - 50 + bay * 10, y - 28, x - 50 + bay * 10, y - 10, white); stripe(x - 50 + bay * 10, y + 10, x - 50 + bay * 10, y + 28, white); } - for (int bay = 0; bay < 10; ++bay) { - if ((bay * 7 + lot * 3) % 4 != 3) car(part, x - 45 + bay * 10, y - 19, bay + lot); - if ((bay * 5 + lot) % 3 != 0) car(part, x - 45 + bay * 10, y + 19, bay * 2 + lot); - } - } - centre(4, -192, 132, 4); - } - // 2 shopping centre: two wings, a glass front, a roof terrace - if (periphery.size() > 2) { - const std::string part = "periphery:2"; - if (level_at(2) <= 0) planned(part, 150, 130, 130, 70, busy_at(2)); - else { - box(scene, part, 150, 140, 130, 44, 20, plaster); - box(scene, part, 105, 105, 40, 30, 14, brick); - windows(part, 150, 140, 130, 44, 3, 16, 13); - windows(part, 105, 105, 40, 30, 3, 10, 4); - box(scene, part, 180, 140, 30, 16, 5, glass, false, 20); - box(scene, part, 125, 140, 14, 10, 3, slate, false, 20); - for (double x : {167.0, 187.0, 207.0}) tree(x, 103); - } - centre(2, 150, 130, 12); - } - // 1 arcade: a hall with a sign - if (periphery.size() > 1) { - const std::string part = "periphery:1"; - if (level_at(1) <= 0) planned(part, -72, 140, 84, 50, busy_at(1)); - else { - box(scene, part, -72, 140, 84, 46, 15, "#b9a6c9"); - windows(part, -72, 140, 84, 46, 2, 8, 6); - box(scene, part, -72, 119, 46, 3, 7, "#d9b13b", false, 15); - box(scene, part, -47, 150, 16, 16, 4, slate, false, 15); - } - centre(1, -72, 140, 9); - } - // 3 club house: a pitched roof, a terrace, trees - if (periphery.size() > 3) { - const std::string part = "periphery:3"; - if (level_at(3) <= 0) planned(part, 82, 40, 70, 44, busy_at(3)); - else { - gabled(part, 82, 45, 66, 30, 11, 9, plaster, tile); - windows(part, 82, 45, 66, 30, 3, 8, 6); - flat(part, 82, 22, 66, 14, wood, -400); - for (double x : {58.0, 74.0, 90.0, 106.0}) box(scene, part, x, 22, 5, 5, 2.4, white); - tree(38, 39); tree(126, 39); - } - centre(3, 82, 40, 8); - } - // 5 restaurant: a house with an awning and tables - if (periphery.size() > 5) { - const std::string part = "periphery:5"; - if (level_at(5) <= 0) planned(part, 205, 40, 60, 44, busy_at(5)); - else { - gabled(part, 205, 48, 56, 30, 12, 8, brick, slate); - windows(part, 205, 48, 56, 30, 3, 9, 5); - scene.faces.push_back({{{177, 33, 9}, {233, 33, 9}, {233, 22, 6}, {177, 22, 6}}, "#c8553d", part, false, false, false, 2, 1, "", {}, 5}); - for (double x : {185.0, 199.0, 213.0, 227.0}) box(scene, part, x, 16, 5, 5, 2.4, white); - } - centre(5, 205, 40, 8); - } - // 6-9 snack bars: a kiosk with a striped awning - const std::array, 4> kiosks{{{{-72, 62}}, {{-72, -6}}, {{72, -22}}, {{152, -22}}}}; - for (size_t n = 0; n < 4 && 6 + n < periphery.size(); ++n) { - const std::string part = "periphery:" + std::to_string(6 + n); - const double x = kiosks[n][0], y = kiosks[n][1]; - if (level_at(6 + n) <= 0) planned(part, x, y, 26, 20, busy_at(6 + n)); - else { - box(scene, part, x, y, 32, 20, 12, white); - box(scene, part, x, y, 34, 22, 2, tile, false, 12); - Face awning{{{x - 18, y - 10, 11}, {x + 18, y - 10, 11}, {x + 18, y - 21, 7.5}, {x - 18, y - 21, 7.5}}, "#d9b13b", part, false, false, false, 2, 1, "", {}, 5}; - for (int s = 1; s < 8; ++s) awning.lines.push_back({{x - 18 + 36.0 * s / 8, y - 10, 11}, {x - 18 + 36.0 * s / 8, y - 21, 7.5}}); - scene.faces.push_back(awning); - for (double dx : {-22.0, -8.0, 8.0, 22.0}) box(scene, part, x + dx, y - 28, 5, 5, 3.4, wood); // standing tables - box(scene, part, x + 22, y + 4, 5, 5, 5, slate); // bins - } - centre(6 + n, x, y, 5); - } - // 10-13 fan shops: a shop in the club's colour with a flag - const std::array, 4> shops{{{{62, -88}}, {{132, -88}}, {{202, -88}}, {{-72, -84}}}}; - for (size_t n = 0; n < 4 && 10 + n < periphery.size(); ++n) { - const std::string part = "periphery:" + std::to_string(10 + n); - const double x = shops[n][0], y = shops[n][1]; - if (level_at(10 + n) <= 0) planned(part, x, y, 40, 30, busy_at(10 + n)); - else { - box(scene, part, x, y, 48, 30, 13, plaster); - windows(part, x, y, 48, 30, 2, 9, 6); - box(scene, part, x, y, 50, 32, 3, seats, false, 13); - box(scene, part, x - 14, y - 17, 14, 3, 5, seats, false, 9); // the sign over the door - scene.faces.push_back({{{x + 20, y + 10, 16}, {x + 20, y + 10, 34}}, "", part, false, true, true, 3, 1, "", {}, 6}); - scene.faces.push_back({{{x + 20, y + 10, 34}, {x + 33, y + 10, 30.5}, {x + 20, y + 10, 27}}, seats, part, false, false, true, 1.5, 1, "", {}, 7}); - } - centre(10 + n, x, y, 6); - } - // any further object of a data set: a house that grows with its level - for (size_t i = 14; i < periphery.size(); ++i) { - const std::string part = "periphery:" + std::to_string(i); - const double x = -230 + double(i - 14) * 60, y = -100; - if (level_at(i) <= 0) planned(part, x, y, 40, 30, busy_at(i)); - else box(scene, part, x, y, 30 + 6 * level_at(i), 24, 6 + 5 * level_at(i), brick); - centre(i, x, y, 6); - } - for (double x : {-245.0, -18.0, 18.0, 245.0}) tree(x, 190); - for (double y : {-112.0, -56.0, 0.0, 56.0}) { tree(-18, y); tree(18, y); } // the avenue - for (const auto &[id, at] : scene.centres) scene.anchors.push_back({id, at}); - return scene; - } - scene.centres["stadium"] = {0, 0, 0}; - for (const auto &[id, centre] : scene.centres) - if (id != "stadium" && id != "facility:0") scene.anchors.push_back({id, centre}); - return scene; -} - -// Draws the scene. Faces of `highlight` get an accented outline; `parts` lists where every -// selectable part lies in the picture (in its own units, 0..width and 0..height). -inline Drawing draw(const Scene &scene, const Camera &camera, double width, double height, const std::string &highlight = {}) { - const double yaw = camera.yaw * 3.14159265358979 / 180, pitch = camera.pitch * 3.14159265358979 / 180; - const double cs = std::cos(yaw), sn = std::sin(yaw), sp = std::sin(pitch), cp = std::cos(pitch); - const double scale = camera.zoom * height / 620.0; - struct Flat { double x, y, depth; }; - const auto project = [&](const Vec &v) { - const double x = (v.x - camera.tx) * cs - (v.y - camera.ty) * sn, y = (v.x - camera.tx) * sn + (v.y - camera.ty) * cs; - return Flat{width / 2 + x * scale, height / 2 - (y * sp + v.z * cp) * scale, y * cp - v.z * sp}; - }; - struct Item { const Face *face; double depth; }; - std::vector order; - order.reserve(scene.faces.size()); - for (const auto &face : scene.faces) { - double depth = 0; - for (const auto &p : face.points) depth += project(p).depth; - order.push_back({&face, depth / double(std::max(1, face.points.size())) - face.bias}); - } - std::stable_sort(order.begin(), order.end(), [](const Item &a, const Item &b) { return a.depth > b.depth; }); - std::map parts; - Drawing out; - out.svg = ""; - const Vec light{-0.42, -0.5, 0.76}; - for (const auto &item : order) { - const auto &face = *item.face; - std::string path; - for (size_t i = 0; i < face.points.size(); ++i) { - const auto p = project(face.points[i]); - path += (i ? "L" : "M") + num(p.x) + " " + num(p.y); - if (!face.part.empty()) { - auto &part = parts[face.part]; - if (!part.seen) { part.id = face.part; part.x0 = part.x1 = p.x; part.y0 = part.y1 = p.y; part.seen = true; } - part.x0 = std::min(part.x0, p.x); part.x1 = std::max(part.x1, p.x); part.y0 = std::min(part.y0, p.y); part.y1 = std::max(part.y1, p.y); - } - } - if (!face.open) path += "Z"; - std::string fill = "none"; - if (!face.fill.empty()) { - double factor = 1; - if (!face.flat && face.points.size() >= 3) { - const Vec &a = face.points[0], &b = face.points[1], &c = face.points[2]; - Vec n{(b.y - a.y) * (c.z - a.z) - (b.z - a.z) * (c.y - a.y), (b.z - a.z) * (c.x - a.x) - (b.x - a.x) * (c.z - a.z), (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x)}; - const double length = std::sqrt(n.x * n.x + n.y * n.y + n.z * n.z); - if (length > 0) factor = .74 + .26 * std::abs((n.x * light.x + n.y * light.y + n.z * light.z) / length); - } - fill = shade(face.fill, factor); - } - const bool lit = !highlight.empty() && face.part == highlight; - const std::string ink = lit ? scene.accent : face.ink.empty() ? scene.ink : face.ink; - out.svg += " 0 || lit ? " stroke=\"" + ink + "\" stroke-width=\"" + num((lit ? std::max(face.stroke, 2.0) + 2 : face.stroke) * std::sqrt(camera.zoom)) + "\" stroke-linejoin=\"round\" stroke-linecap=\"round\"" : std::string()) + - (face.dashed ? " stroke-dasharray=\"" + num(9 * std::sqrt(camera.zoom)) + " " + num(7 * std::sqrt(camera.zoom)) + "\"" : std::string()) + - (face.fill.empty() && face.opacity < 1 ? " stroke-opacity=\"" + num(face.opacity) + "\"" : std::string()) + "/>"; - for (const auto &line : face.lines) { - std::string d; - for (size_t i = 0; i < line.size(); ++i) { const auto p = project(line[i]); d += (i ? "L" : "M") + num(p.x) + " " + num(p.y); } - out.svg += ""; - } - } - out.svg += ""; - for (auto &[id, part] : parts) { - if (const auto found = scene.centres.find(id); found != scene.centres.end()) { - part.centre = found->second; - const auto p = project(found->second); - part.cx = p.x; part.cy = p.y; - } else { part.cx = (part.x0 + part.x1) / 2; part.cy = (part.y0 + part.y1) / 2; } - out.parts.push_back(part); - } - for (const auto &[id, at] : scene.anchors) { - const auto p = project(at); - out.anchors.push_back({id, p.x, p.y}); - } - return out; -} - -// The camera never moves: one station for the stadium, one for its surroundings. -inline Camera fixed_camera(bool surroundings) { return surroundings ? Camera{22, 42, 1.42, 0, 0} : Camera{28, 44, 2.15, 0, 0}; } - -// Where the camera stands for a focus: "" the whole ground with its surroundings, "stadium" -// the bowl, a part id that part, turned so that it lies in front. -inline Camera camera_for(const Scene &scene, const std::string &focus) { - if (focus.empty()) return {28, 42, 1.32, 0, 0}; - if (focus == "stadium") return {28, 44, 2.0, 0, 0}; - if (focus == "periphery") return {28, 52, 1.15, 0, 0}; - const auto found = scene.centres.find(focus); - if (found == scene.centres.end()) return {28, 44, 2.0, 0, 0}; - const Vec c = found->second; - if (std::hypot(c.x, c.y) < 1) return {28, 50, 3.0, 0, 0}; - // turn the part to the near side, a little off the axis so that its flank shows - const double towards = std::atan2(c.y, c.x) * 180 / 3.14159265358979; - const bool outer = focus.starts_with("periphery:"); - return {-90 - towards + 22, 38, outer ? 2.6 : focus.starts_with("block:") ? 3.0 : 3.2, c.x * .82, c.y * .82}; -} -} // namespace bmh::modern_ui::stadium3d diff --git a/src/modern/ui/stadium_scene.hpp b/src/modern/ui/stadium_scene.hpp new file mode 100644 index 0000000..b128dc9 --- /dev/null +++ b/src/modern/ui/stadium_scene.hpp @@ -0,0 +1,537 @@ +// SPDX-License-Identifier: GPL-3.0-only +#pragma once +// The ground and what stands around it as a model of card on one base plate, seen from a +// fixed oblique angle: eight stands as deep as they have places, the stadium's equipment, +// the fourteen objects of the surroundings, trees, cars and people. The picture is built from +// the stadium overview alone, so the same input always gives the same picture. +// +// World: x to the lower right, y to the lower left, z up; the centre spot is the origin and +// lengths are roughly metres. A point lands on the picture through `project`; the picture is +// 1244 x 672 units. Next to the picture the scene lists, for every part one can choose, the +// faces it shows, as parallelograms in world coordinates. +#include "modern/ui/catalog.hpp" +#include +#include +#include +#include +#include +#include +#include + +namespace bmh::modern_ui::stadium_scene { +struct Vec { double x = 0, y = 0, z = 0; }; +struct Point { double x = 0, y = 0; }; +constexpr double unit = 2.2, origin_x = 622, origin_y = 322, width = 1244, height = 672; +inline Point project(const Vec &p) { return {origin_x + (p.x - p.y) * unit * .866, origin_y + (p.x + p.y) * unit * .5 - p.z * unit * .82}; } +// A parallelogram: a corner and the two corners next to it. +struct Quad { Vec a, b, d; }; +struct Hot { + std::string id; // "block:3", "facility:0", "periphery:12" + double depth = 0; + std::vector quads; +}; +struct Letter { std::string text; Point at; }; +struct Scene { + std::string svg; + std::vector hots; // sorted from the back to the front + std::vector letters; // the stands' letters +}; + +namespace detail { +inline std::string num(double v) { char text[32]; std::snprintf(text, sizeof text, "%.1f", v); return text; } +inline std::string pt(const Vec &p) { const auto q = project(p); return num(q.x) + "," + num(q.y); } +inline std::string pts(const std::vector &all) { std::string out; for (const auto &p : all) out += (out.empty() ? "" : " ") + pt(p); return out; } +inline std::array rgb(const std::string &hex) { return {std::stoi(hex.substr(1, 2), nullptr, 16), std::stoi(hex.substr(3, 2), nullptr, 16), std::stoi(hex.substr(5, 2), nullptr, 16)}; } +inline std::string mix(const std::string &a, const std::string &b, double t) { + const auto x = rgb(a), y = rgb(b); char text[16]; + std::snprintf(text, sizeof text, "#%02x%02x%02x", int(std::lround(x[0] + (y[0] - x[0]) * t)), int(std::lround(x[1] + (y[1] - x[1]) * t)), int(std::lround(x[2] + (y[2] - x[2]) * t))); + return text; +} +// the colour of a face under the model's light: the top brightest, the side to the left darkest +inline std::string lit(const std::vector &f, const std::string &base) { + const Vec u{f[1].x - f[0].x, f[1].y - f[0].y, f[1].z - f[0].z}, v{f[2].x - f[0].x, f[2].y - f[0].y, f[2].z - f[0].z}; + const double nx = std::abs(u.y * v.z - u.z * v.y), ny = std::abs(u.z * v.x - u.x * v.z), nz = std::abs(u.x * v.y - u.y * v.x), sum = nx + ny + nz; + const double bright = sum > 0 ? (nz + nx * .66 + ny * .4) / sum : 1; + return mix(base, "#4a3c2e", (1 - bright) * .55); +} +inline Vec lerp(const Vec &a, const Vec &b, double t) { return {a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t, a.z + (b.z - a.z) * t}; } +inline const char *ink = "#3a332b"; +inline std::string line(const Vec &a, const Vec &b, const std::string &colour, double w = 1, const std::string &more = "") { + const auto p = project(a), q = project(b); + return ""; +} +inline const char *edge = "stroke=\"#3a332b\" stroke-opacity=\".55\" stroke-width=\".8\" stroke-linejoin=\"round\""; +inline std::string poly(const std::vector &all, const std::string &fill, const std::string &more = edge) { return ""; } +struct Face { + std::vector p; + std::string colour, deco; // deco is drawn right after the face + bool raw = false; // keep the colour as it is + std::string more; // its own stroke attributes + double bias = 0; +}; +// faces are painted from the back to the front +inline std::string paint(std::vector faces) { + const auto depth = [](const Face &f) { double sum = 0; for (const auto &p : f.p) sum += p.x + p.y + p.z * .9; return sum / double(f.p.size()) + f.bias; }; + std::stable_sort(faces.begin(), faces.end(), [&](const Face &a, const Face &b) { return depth(a) < depth(b); }); + std::string out; + for (const auto &f : faces) out += poly(f.p, f.raw ? f.colour : lit(f.p, f.colour), f.more.empty() ? edge : f.more) + f.deco; + return out; +} +struct BoxLook { std::string top, side_x, side_y, deco_top, deco_x, deco_y; }; +inline std::vector box(double x0, double y0, double x1, double y1, double z0, double z1, const std::string &c, const BoxLook &o = {}) { + return {{{{x0, y0, z1}, {x1, y0, z1}, {x1, y1, z1}, {x0, y1, z1}}, o.top.empty() ? c : o.top, o.deco_top, false, "", .5}, + {{{x1, y0, z0}, {x1, y1, z0}, {x1, y1, z1}, {x1, y0, z1}}, o.side_x.empty() ? c : o.side_x, o.deco_x}, + {{{x0, y1, z0}, {x1, y1, z0}, {x1, y1, z1}, {x0, y1, z1}}, o.side_y.empty() ? c : o.side_y, o.deco_y}}; +} +inline std::vector box_quads(double x0, double y0, double x1, double y1, double z0, double z1) { + return {{{x0, y0, z1}, {x1, y0, z1}, {x0, y1, z1}}, {{x1, y0, z0}, {x1, y1, z0}, {x1, y0, z1}}, {{x0, y1, z0}, {x1, y1, z0}, {x0, y1, z1}}}; +} +inline Quad ground(double x0, double y0, double x1, double y1) { return {{x0, y0, 0}, {x1, y0, 0}, {x0, y1, 0}}; } +inline const char *pane = "stroke=\"#3a332b\" stroke-opacity=\".5\" stroke-width=\".6\""; +// windows or panels on the face towards +x and on the one towards +y +inline std::string windows_x(double x, double y0, double y1, double z0, double z1, int n, const std::string &colour, double gap = .22) { + std::string out; const double w = (y1 - y0) / n; + for (int i = 0; i < n; ++i) { const double a = y0 + w * (i + gap), b = y0 + w * (i + 1 - gap); out += poly({{x, a, z0}, {x, b, z0}, {x, b, z1}, {x, a, z1}}, colour, pane); } + return out; +} +inline std::string windows_y(double y, double x0, double x1, double z0, double z1, int n, const std::string &colour, double gap = .22) { + std::string out; const double w = (x1 - x0) / n; + for (int i = 0; i < n; ++i) { const double a = x0 + w * (i + gap), b = x0 + w * (i + 1 - gap); out += poly({{a, y, z0}, {b, y, z0}, {b, y, z1}, {a, y, z1}}, colour, pane); } + return out; +} +inline std::string xml(const std::string &text) { + std::string out; + for (const char c : text) out += c == '&' ? "&" : c == '<' ? "<" : c == '>' ? ">" : c == '"' ? """ : std::string(1, c); + return out; +} +inline const char *lettering = "Georgia, 'Times New Roman', 'Liberation Serif', serif"; +// writing on a face towards +y, and on one towards +x +inline std::string sign_y(double x, double y, double z, const std::string &text, double size, const std::string &fill = ink) { + const auto q = project({x, y, z}); + return "" + xml(text) + ""; +} +inline std::string sign_x(double x, double y, double z, const std::string &text, double size, const std::string &fill = ink) { + const auto q = project({x, y, z}); + return "" + xml(text) + ""; +} +inline std::vector> hull(std::vector> all) { + std::sort(all.begin(), all.end()); + const auto cross = [](const auto &o, const auto &a, const auto &b) { return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]); }; + std::vector> lower, upper; + for (const auto &p : all) { while (lower.size() > 1 && cross(lower[lower.size() - 2], lower.back(), p) <= 0) lower.pop_back(); lower.push_back(p); } + for (auto p = all.rbegin(); p != all.rend(); ++p) { while (upper.size() > 1 && cross(upper[upper.size() - 2], upper.back(), *p) <= 0) upper.pop_back(); upper.push_back(*p); } + lower.pop_back(); upper.pop_back(); + lower.insert(lower.end(), upper.begin(), upper.end()); + return lower; +} +// the shadow a body of that height throws on the plate +inline std::string shadow(double x0, double y0, double x1, double y1, double tall) { + const double dx = -tall * .5, dy = tall * .22; + std::vector> all{{x0, y0}, {x1, y0}, {x1, y1}, {x0, y1}}; + for (int i = 0; i < 4; ++i) all.push_back({all[size_t(i)][0] + dx, all[size_t(i)][1] + dy}); + std::vector outline; + for (const auto &p : hull(all)) outline.push_back({p[0], p[1], 0}); + return poly(outline, "#4a3c2e", "fill-opacity=\".16\""); +} +inline std::string tree(double x, double y, double size, int tone) { + static constexpr std::array, 3> greens{{{"#5f7d4a", "#7f9b5c", "#a3ba7c"}, {"#56764f", "#74935f", "#98b183"}, {"#6c8444", "#8ea458", "#b3c47c"}}}; + const auto q = project({x, y, 0}); const double r = 5.2 * size; const auto &g = greens[size_t(tone % 3)]; + return ""; +} +inline std::string car(double x, double y, const std::string &colour, bool along) { + const double l = 4.6, w = 2.3; + auto faces = along ? box(x, y, x + l, y + w, 0, 1.1, colour) : box(x, y, x + w, y + l, 0, 1.1, colour); + const auto cabin = along ? box(x + 1, y + .2, x + l - 1.1, y + w - .2, 1.1, 2, "#dfe9ee") : box(x + .2, y + 1, x + w - .2, y + l - 1.1, 1.1, 2, "#dfe9ee"); + faces.insert(faces.end(), cabin.begin(), cabin.end()); + return paint(faces); +} +// poles and boards in front of the faces that are being built +inline std::string scaffold(const std::vector &faces) { + std::string out; + for (const auto &f : faces) { + if (f.p.size() < 4) continue; + const auto &a = f.p[0], &b = f.p[1], &c = f.p[2], &d = f.p[3]; + for (int i = 0; i <= 6; ++i) out += line(lerp(a, b, i / 6.), lerp(d, c, i / 6.), "#a8782e", 1); + for (int j = 0; j <= 3; ++j) out += line(lerp(a, d, j / 3.), lerp(b, c, j / 3.), "#a8782e", 1); + for (int i = 0; i < 6; i += 2) out += line(lerp(a, b, i / 6.), lerp(d, c, (i + 1) / 6.), "#c79a4e", .7); + } + return out; +} +inline std::string crane(double x, double y, double tall) { + const auto a = project({x, y, 0}), b = project({x, y, tall}); + return ""; +} +// the outline of a plot nothing stands on yet +inline std::string plot(double x0, double y0, double x1, double y1) { + return poly({{x0, y0, 0}, {x1, y0, 0}, {x1, y1, 0}, {x0, y1, 0}}, "none", "stroke=\"#645c50\" stroke-width=\"1.3\" stroke-dasharray=\"5 4\" stroke-linejoin=\"round\""); +} +// a small generator of its own: the scatter of cars, trees and people never changes +struct Random { + uint32_t state; + double next() { state = state * 1664525u + 1013904223u; return double(state >> 8) / 16777216.; } + int between(int lo, int hi) { return lo + int(next() * (hi - lo + 1)); } +}; +} // namespace detail + +// `sign` is written over the gate. With `future`, what is being built stands finished. +inline Scene build(const Json &overview, bool future, const std::string &sign) { + using namespace detail; + Scene scene; + struct Item { double depth; std::string svg; }; + std::vector items; + const auto hot = [&](const std::string &id, double depth, std::vector quads) { + for (auto &h : scene.hots) + if (h.id == id) { h.depth = std::max(h.depth, depth); h.quads.insert(h.quads.end(), quads.begin(), quads.end()); return; } + scene.hots.push_back({id, depth, std::move(quads)}); + }; + static const Json none = Json::object(); + const auto &blocks = overview.contains("blocks") ? overview.at("blocks") : Json::array(); + const auto &facilities = overview.contains("facilities") ? overview.at("facilities") : Json::array(); + const auto &periphery = overview.contains("periphery") ? overview.at("periphery") : Json::array(); + const auto facility = [&](size_t i) -> const Json & { return i < facilities.size() ? facilities[i] : none; }; + const auto around = [&](size_t i) -> const Json & { return i < periphery.size() ? periphery[i] : none; }; + // levels count from 1; the model draws from 0 + const auto grade = [&](size_t i) { const auto &f = facility(i); return std::clamp(f.value("display_level", f.value("level", 1)) - 1, 0, 3); }; + const auto level = [&](size_t i) { const auto &p = around(i); return std::max(0, p.value("display_level", p.value("level", 0))); }; + const auto most = [&](size_t i) { return std::max(1, around(i).value("max_level", 1)); }; + const auto busy = [&](const Json &row) { return !future && row.value("building", false); }; + + // ---- the stands: the four with the most room are the long and short sides ---- + constexpr double G = 40, G2 = 58.5, H0 = 1.6; + struct Stand { size_t index; int place; double places, limit; bool seats, roof, building; }; + std::vector stands; + double even = 0, odd = 0; + for (size_t i = 0; i < 8 && i < blocks.size(); ++i) (i % 2 ? odd : even) += blocks[i].value("max_places", 0.0); + for (size_t i = 0; i < 8 && i < blocks.size(); ++i) { + const auto &b = blocks[i]; + const double shown = b.value("display_places", 0.0), stands_now = b.value("places", shown); + stands.push_back({i, int(even >= odd ? i : (i + 7) % 8), !future && b.value("building", false) ? stands_now : shown, std::max(1.0, b.value("max_places", 1.0)), b.value("display_seats", false), b.value("display_roof", false), busy(b)}); + } + const auto deep = [&](const Stand &s, double places) { return s.place % 2 == 0 ? 8 + places / s.limit * (s.limit > 12000 ? 24 : 20) : 7 + places / s.limit * 15; }; + const auto on_side = [&](int side, double u, double v, double z) -> Vec { return side == 0 ? Vec{u, -G - v, z} : side == 2 ? Vec{u, G + v, z} : side == 1 ? Vec{G2 + v, u, z} : Vec{-G2 - v, u, z}; }; + double depth_west = 8, depth_north = 8; + for (const auto &s : stands) { + const double d = deep(s, s.places), full = deep(s, s.limit), tall = 2.5 + d * .6; + if (s.place == 6) depth_west = d; + if (s.place == 0) depth_north = d; + const std::string id = "block:" + std::to_string(s.index), seat = s.seats ? "#c8733c" : "#cfc7b6", wall = "#efe6d2", row_ink = s.seats ? "#8c491a" : "#8a8274"; + std::vector faces, roof; std::vector quads; std::string before, after; Vec centre, crane_at; std::vector worked; + const int rows = std::max(3, int(std::lround(d / 3))); + if (s.place % 2 == 0) { + const int side = s.place / 2; const double half = side == 0 || side == 2 ? G2 : G; + const auto m = [&](double u, double v, double z) { return on_side(side, u, v, z); }; + const int n = int(std::lround(half / 7.3)); + const Vec in0 = m(-half, 0, H0), in1 = m(half, 0, H0), o0 = m(-half, d, tall), o1 = m(half, d, tall); + std::string deco; + for (int i = 1; i < rows; ++i) deco += line(lerp(in0, o0, double(i) / rows), lerp(in1, o1, double(i) / rows), row_ink, .7, "stroke-opacity=\".7\""); + for (int i = 1; i < n * 2; ++i) deco += line(lerp(in0, in1, i / (n * 2.)), lerp(o0, o1, i / (n * 2.)), s.seats ? "#f3d9c2" : "#f3eee2", i % 2 ? .5 : 1.6); + // the crush barriers of a terrace + if (!s.seats) + for (int i = 0; i < n * 2; ++i) + for (int r = 1; r < rows; r += 2) { + const Vec a = lerp(lerp(in0, in1, (i + .3) / (n * 2.)), lerp(o0, o1, (i + .3) / (n * 2.)), double(r) / rows), c = lerp(lerp(in0, in1, (i + .7) / (n * 2.)), lerp(o0, o1, (i + .7) / (n * 2.)), double(r) / rows); + deco += line({a.x, a.y, a.z + .9}, {c.x, c.y, c.z + .9}, "#6f6a60", .9); + } + std::string back; const Vec b0 = m(-half, d, 0), b1 = m(half, d, 0), t0 = m(-half, d, tall), t1 = m(half, d, tall); + for (int i = 0; i <= n * 2; ++i) back += line(lerp(b0, b1, i / (n * 2.)), lerp(t0, t1, i / (n * 2.)), "#b9ad94", i % 2 ? .6 : 1.3); + back += poly({lerp(b0, t0, .72), lerp(b1, t1, .72), lerp(b1, t1, .9), lerp(b0, t0, .9)}, "#c8733c", "stroke=\"none\""); + for (int i = 1; i < n * 2; i += 2) { + const Vec a = lerp(b0, b1, (i - .28) / (n * 2.)), c = lerp(b0, b1, (i + .28) / (n * 2.)); const double door = std::min(4.5, tall * .4); + back += poly({a, c, {c.x, c.y, door}, {a.x, a.y, door}}, "#6b5a48", "stroke=\"none\""); + } + faces = {{{in0, in1, o1, o0}, seat, deco, true}, {{m(-half, 0, 0), m(half, 0, 0), in1, in0}, wall}, {{m(-half, 0, 0), m(-half, d, 0), o0, in0}, wall}, {{m(half, 0, 0), m(half, d, 0), o1, in1}, wall}, {{b0, b1, t1, t0}, wall, back}}; + quads = {{in0, in1, o0}, {b0, b1, t0}, {m(-half, 0, 0), m(-half, d, 0), in0}, {m(half, 0, 0), m(half, d, 0), in1}}; + worked = {faces[3], faces[4]}; + if (s.roof) { + const Vec r0 = m(-half - 1, d + 1, tall + 5), r1 = m(half + 1, d + 1, tall + 5), r2 = m(half + 1, d * .18, tall + 7.5), r3 = m(-half - 1, d * .18, tall + 7.5); + std::string trusses; + for (int i = 0; i <= n; ++i) { trusses += line(lerp(r0, r1, double(i) / n), lerp(r3, r2, double(i) / n), "#8f8778", 1); trusses += line(lerp(t0, t1, double(i) / n), lerp(r0, r1, double(i) / n), "#8f8778", 1.4); } + trusses += line(lerp(r0, r3, .5), lerp(r1, r2, .5), "#8f8778", .7); + roof.push_back({{r0, r1, r2, r3}, "#fbf7ee", trusses, true, std::string("fill-opacity=\"") + (side == 0 || side == 3 ? ".58" : ".9") + "\" stroke=\"#3a332b\" stroke-opacity=\".6\" stroke-width=\"1\" stroke-linejoin=\"round\""}); + quads.push_back({r0, r1, r3}); + } + centre = m(0, d / 2, 0); crane_at = m(half * .5, d + 6, 0); + // how far the stand may grow + if (!future && s.places < s.limit) + before = poly({m(-half, d, 0), m(half, d, 0), m(half, full, 0), m(-half, full, 0)}, "#ffffff", "fill-opacity=\".18\" stroke=\"#645c50\" stroke-width=\"1.2\" stroke-dasharray=\"5 4\" stroke-linejoin=\"round\""); + } else { + const int sx = s.place == 1 || s.place == 3 ? 1 : -1, sy = s.place == 3 || s.place == 5 ? 1 : -1; + const auto m = [&](double a, double c, double z) -> Vec { return {sx * (G2 + a), sy * (G + c), z}; }; + const Vec inner = m(0, 0, H0), a = m(d, 0, tall), corner = m(d, d, tall), b = m(0, d, tall); + std::string first, second; + for (int i = 1; i < rows; ++i) { + first += line(lerp(inner, a, double(i) / rows), lerp(inner, corner, double(i) / rows), row_ink, .7, "stroke-opacity=\".7\""); + second += line(lerp(inner, corner, double(i) / rows), lerp(inner, b, double(i) / rows), row_ink, .7, "stroke-opacity=\".7\""); + } + const auto band = [&](const Vec &p, const Vec &q) { return poly({{p.x, p.y, tall * .72}, {q.x, q.y, tall * .72}, {q.x, q.y, tall * .9}, {p.x, p.y, tall * .9}}, "#c8733c", "stroke=\"none\""); }; + faces = {{{inner, a, corner}, seat, first, true}, {{inner, corner, b}, mix(seat, "#4a3c2e", .08), second, true}, {{m(d, 0, 0), m(d, d, 0), corner, a}, wall, band(m(d, 0, 0), m(d, d, 0))}, + {{m(0, d, 0), m(d, d, 0), corner, b}, wall, band(m(0, d, 0), m(d, d, 0))}, {{m(0, 0, 0), m(d, 0, 0), a, inner}, wall}, {{m(0, 0, 0), m(0, d, 0), b, inner}, wall}}; + quads = {{m(0, 0, tall * .55), m(d, 0, tall * .55), m(0, d, tall * .55)}, {m(d, 0, 0), m(d, d, 0), a}, {m(0, d, 0), m(d, d, 0), b}}; + worked = {faces[2], faces[3]}; + if (s.roof) { + const Vec peak = m(d * .2, d * .2, tall + 7.5); + roof.push_back({{m(d + 1, 0, tall + 5), m(d + 1, d + 1, tall + 5), m(0, d + 1, tall + 5), peak}, "#fbf7ee", "", true, "fill-opacity=\".75\" stroke=\"#3a332b\" stroke-opacity=\".6\" stroke-width=\"1\" stroke-linejoin=\"round\""}); + quads.push_back({m(0, 0, tall + 6), m(d + 1, 0, tall + 6), m(0, d + 1, tall + 6)}); + } + centre = m(d / 2, d / 2, 0); crane_at = m(d + 5, d + 5, 0); + if (!future && s.places < s.limit) + before = poly({m(d, 0, 0), m(full, 0, 0), m(full, full, 0), m(0, full, 0), m(0, d, 0), m(d, d, 0)}, "#ffffff", "fill-opacity=\".18\" stroke=\"#645c50\" stroke-width=\"1.2\" stroke-dasharray=\"5 4\" stroke-linejoin=\"round\""); + } + if (s.building) after = scaffold(worked) + crane(crane_at.x, crane_at.y, tall + 16); + const double depth = centre.x + centre.y; + if (s.places <= 0) faces.clear(), roof.clear(); + items.push_back({depth, before + paint(faces) + after}); + if (!roof.empty()) items.push_back({depth + 1.2, paint(roof)}); + hot(id, depth, quads); + scene.letters.push_back({blocks[s.index].value("letter", std::string(1, char('A' + s.index))), project({centre.x, centre.y, tall + (s.roof ? 9 : 3)})}); + } + + // ---- the pitch: its green tells the state of the turf, dots the heating under it ---- + { + static constexpr std::array light{"#b8b279", "#a9bd7a", "#93b46a", "#7fae5c"}, dark{"#aba56c", "#9db06e", "#86a95f", "#6f9f50"}; + const int turf = grade(4); + std::string pitch = poly({{-52.5, -34, 0}, {52.5, -34, 0}, {52.5, 34, 0}, {-52.5, 34, 0}}, light[size_t(turf)], "stroke=\"none\""); + for (int i = 0; i < 10; i += 2) pitch += poly({{-52.5 + i * 10.5, -34, 0}, {-42 + i * 10.5, -34, 0}, {-42 + i * 10.5, 34, 0}, {-52.5 + i * 10.5, 34, 0}}, dark[size_t(turf)], "stroke=\"none\""); + if (turf == 0) + for (const auto &worn : std::array, 5>{{{-20, 5, 7}, {14, -12, 5}, {38, 10, 6}, {-40, -18, 4}, {0, 22, 5}}}) { + const auto q = project({worn[0], worn[1], 0}); + pitch += ""; + } + if (facility(2).value("display_level", facility(2).value("level", 1)) >= 2) + for (double y = -30; y <= 30; y += 6) pitch += line({-50, y, 0}, {50, y, 0}, "#d9824a", .8, "stroke-opacity=\".5\" stroke-dasharray=\"1 5\""); + const std::string chalk = "stroke=\"#fdfbf4\" stroke-width=\"1.3\" stroke-linejoin=\"round\""; + std::vector circle; + for (int i = 0; i < 28; ++i) circle.push_back({std::cos(i / 28. * 6.283) * 9.15, std::sin(i / 28. * 6.283) * 9.15, 0}); + pitch += poly({{-50, -31, 0}, {50, -31, 0}, {50, 31, 0}, {-50, 31, 0}}, "none", chalk) + line({0, -31, 0}, {0, 31, 0}, "#fdfbf4", 1.3) + poly(circle, "none", chalk); + for (const double k : {-1.0, 1.0}) { + pitch += poly({{k * 50, -20, 0}, {k * 33.5, -20, 0}, {k * 33.5, 20, 0}, {k * 50, 20, 0}}, "none", chalk) + poly({{k * 50, -9, 0}, {k * 44.5, -9, 0}, {k * 44.5, 9, 0}, {k * 50, 9, 0}}, "none", chalk); + pitch += line({k * 50, -3.7, 0}, {k * 50, -3.7, 2.6}, "#ffffff", 1.4) + line({k * 50, 3.7, 0}, {k * 50, 3.7, 2.6}, "#ffffff", 1.4) + line({k * 50, -3.7, 2.6}, {k * 50, 3.7, 2.6}, "#ffffff", 1.4) + + poly({{k * 50, -3.7, 2.6}, {k * 50, 3.7, 2.6}, {k * 52.3, 3.7, 0}, {k * 52.3, -3.7, 0}}, "#ffffff", "fill-opacity=\".35\" stroke=\"#ffffff\" stroke-width=\".5\""); + } + items.push_back({-9999, pitch}); + hot("facility:4", -9999, {ground(-52.5, -34, 52.5, 34)}); + // the two benches + items.push_back({-30, paint(box(-9, -38.4, -2, -36.4, 0, 2, "#f3ede0")) + paint(box(2, -38.4, 9, -36.4, 0, 2, "#f3ede0"))}); + } + + // ---- the stadium's equipment ---- + { + const int lights = grade(0), lamps_across = lights + 2; const double mast = std::array{16, 24, 32, 42}[size_t(lights)]; + for (const auto &at : std::array, 4>{{{-90, -72}, {90, -72}, {90, 72}, {-90, 72}}}) { + const double x = at[0], y = at[1]; const auto top = project({x, y, mast}); + const double head_w = lamps_across * 3.4 + 3, head_h = (lamps_across - 1) * 3.5 + 5; + std::string lamps; + for (int i = 0; i < lamps_across; ++i) + for (int j = 0; j < lamps_across - 1; ++j) + lamps += ""; + items.push_back({x + y, poly({{x - 1.2, y - 1.2, 0}, {x + 1.2, y - 1.2, 0}, {x + 1.2, y + 1.2, 0}, {x - 1.2, y + 1.2, 0}}, "#bdb4a0") + line({x, y, 0}, {x, y, mast}, "#8f8778", 3) + line({x, y, 0}, {x, y, mast}, "#d9d2c2", 1.2) + + "" + lamps + + (busy(facility(0)) ? crane(x + 5, y + 5, mast + 8) : std::string())}); + hot("facility:0", x + y, {{{x - 3.5, y + 3.5, 0}, {x + 3.5, y - 3.5, 0}, {x - 3.5, y + 3.5, mast + head_h / 2 + 2}}}); + } + // the scoreboard behind the west stand + const int board = grade(1); const double bw = std::array{9, 13, 17, 22}[size_t(board)], bh = std::array{5, 7, 9, 12}[size_t(board)]; + const double bx = -G2 - depth_west - 5, bz = 2.5 + depth_west * .6 + 3; + BoxLook screen; + screen.deco_x = poly({{bx, -bw + 1.2, bz + 1.2}, {bx, bw - 1.2, bz + 1.2}, {bx, bw - 1.2, bz + bh * 1.6 - 1.2}, {bx, -bw + 1.2, bz + bh * 1.6 - 1.2}}, "#2f3a2c", "stroke=\"none\"") + sign_x(bx, bw * .45, bz + bh * .55, "2 : 1", bh * 1.25, "#ffd98a"); + items.push_back({bx - 1, line({bx - 1, -bw + 3, 0}, {bx - 1, -bw + 3, bz}, "#8f8778", 2.2) + line({bx - 1, bw - 3, 0}, {bx - 1, bw - 3, bz}, "#8f8778", 2.2) + paint(box(bx - 2, -bw, bx, bw, bz, bz + bh * 1.6, "#4c463c", screen)) + + (busy(facility(1)) ? crane(bx + 4, bw + 4, bz + bh * 1.6 + 8) : std::string())}); + hot("facility:1", bx - 1, box_quads(bx - 2, -bw, bx, bw, bz, bz + bh * 1.6)); + // the lounge in the main stand; where there is none, its place is only marked + const bool lounge = facility(3).value("max_level", 2) > 2 || facility(3).value("display_level", facility(3).value("level", 1)) >= 2; + const int lounge_size = facility(3).value("max_level", 2) <= 2 ? 2 : grade(3); + const double north_tall = 2.5 + depth_north * .6, vw = std::array{10, 16, 24, 34, 34}[size_t(std::clamp(lounge_size, 0, 4))], vy = -G - depth_north * .62, vz = H0 + (north_tall - H0) * .62; + BoxLook glass; glass.deco_y = windows_y(vy, -vw, vw, vz + .4, vz + 3, int(std::lround(vw / 2.2)), "#bfe0ea", .1); glass.top = "#e9dfc9"; + items.push_back({-G - depth_north / 2 + .6, lounge ? paint(box(-vw, vy - 3.4, vw, vy, vz - .5, vz + 3.6, "#f6f0e2", glass)) + : poly({{-vw, vy, vz - .5}, {vw, vy, vz - .5}, {vw, vy, vz + 3.6}, {-vw, vy, vz + 3.6}}, "#ffffff", "fill-opacity=\".25\" stroke=\"#645c50\" stroke-width=\"1.1\" stroke-dasharray=\"4 3\"")}); + hot("facility:3", -G - depth_north / 2 + .6, box_quads(-vw, vy - 3.4, vw, vy, vz - .5, vz + 3.6)); + // three small houses in the corners of the forecourt: heating, comfort, upkeep + const auto hut = [&](size_t index, bool built, double x0, double y0, double x1, double y1, double tall, const std::string &colour, const BoxLook &look, const std::string &extra) { + items.push_back({(x0 + x1 + y0 + y1) / 2, (built ? shadow(x0, y0, x1, y1, tall) + paint(box(x0, y0, x1, y1, 0, tall, colour, look)) + extra : plot(x0, y0, x1, y1)) + (busy(facility(index)) ? crane(x1 + 3, y1 + 3, tall + 12) : std::string())}); + hot("facility:" + std::to_string(index), (x0 + x1 + y0 + y1) / 2, built ? box_quads(x0, y0, x1, y1, 0, tall) : std::vector{ground(x0, y0, x1, y1)}); + }; + { + BoxLook look; look.top = "#c8733c"; look.deco_y = windows_y(74, 84, 94, 1, 4.2, 2, "#bfe0ea"); + const auto s1 = project({92, 67, 13}), s2 = project({92, 67, 16}); + hut(2, facility(2).value("display_level", facility(2).value("level", 1)) >= 2, 84, 64, 94, 74, 6, "#e9dfc9", look, + paint(box(91, 66, 93, 68, 6, 11, "#b9ad94")) + ""); + } + { + const int comfort = grade(5); BoxLook look; + look.top = std::array{"#b9ad94", "#c9b28a", "#d9a05e", "#c8733c"}[size_t(comfort)]; look.deco_y = windows_y(74, -95, -83, 1, 3.4, 3, "#bfe0ea"); look.deco_x = windows_x(-83, 62, 74, 1, 3.4, 2, "#6b5a48"); + hut(5, true, -95, 62, -83, 74, 4 + comfort, "#f6f0e2", look, sign_y(-94.5, 74, 4.2 + comfort * .2, "WC · Kiosk", 4.2)); + } + { + const int upkeep = grade(6); BoxLook look; look.top = "#8fa073"; look.deco_y = windows_y(-66, 84, 94, .6, 3.8, 2, "#7a6a58", .12); + hut(6, true, 84, -76, 94, -66, 5, std::array{"#c9c0ad", "#ddd3bd", "#ebe2cd", "#f6f0e2"}[size_t(upkeep)], look, + line({95.5, -68, 0}, {94.2, -68, 5}, "#a8782e", 1.2) + line({95.5, -70, 0}, {94.2, -70, 5}, "#a8782e", 1.2) + paint(box(96, -74, 98, -72, 0, 1.6, "#c8733c"))); + } + // safety: the fence along the forecourt and the gate with the ground's name + { + const int safety = grade(7); std::string fence; + for (double x = -96; x < 96; x += 6) + if (std::abs(x + 3) > 12) fence += line({x, 78, 0}, {x, 78, 2 + safety * .5}, "#6f6a60", .9) + line({x, 78, 2 + safety * .5}, {x + 6, 78, 2 + safety * .5}, "#6f6a60", .9); + BoxLook lintel; lintel.deco_y = sign_y(-9.5, 80, 7.5, sign, 4.4, "#fff8ea"); + auto gate = box(-12, 77, -8, 80, 0, 7, "#efe6d2"); const auto right = box(8, 77, 12, 80, 0, 7, "#efe6d2"), over = box(-12, 77, 12, 80, 7, 9.5, "#c8733c", lintel); + gate.insert(gate.end(), right.begin(), right.end()); gate.insert(gate.end(), over.begin(), over.end()); + items.push_back({80, fence + paint(gate) + windows_y(80, -8, 8, 0, 2.6, 4 + safety, "#6f6a60", .35) + + (safety > 1 ? line({14, 79, 0}, {14, 79, 12}, "#8f8778", 1.6) + paint(box(13, 78.4, 15.5, 79.6, 12, 13.2, "#4c463c")) : std::string()) + (busy(facility(7)) ? crane(18, 82, 20) : std::string())}); + hot("facility:7", 80, box_quads(-12, 77, 12, 80, 0, 9.5)); + } + } + + // ---- around the ground ---- + const auto name = [](size_t i) { return "periphery:" + std::to_string(i); }; + const auto works = [&](size_t i, double x, double y, double tall) { return busy(around(i)) ? crane(x, y, tall) : std::string(); }; + { + // roads; from the third stage of the transport links a tram runs along them + const int links = level(0); + std::string road = poly({{-160, 104, 0}, {160, 104, 0}, {160, 122, 0}, {-160, 122, 0}}, "#cfc9bd", "stroke=\"#3a332b\" stroke-opacity=\".35\" stroke-width=\".8\""); + for (double x = -154; x < 156; x += 12) road += line({x, 109, 0}, {x + 6, 109, 0}, "#fbf7ee", 1.1); + road += poly({{112, -128, 0}, {124, -128, 0}, {124, 104, 0}, {112, 104, 0}}, "#cfc9bd", "stroke=\"none\"") + poly({{-6, 82, 0}, {6, 82, 0}, {6, 104, 0}, {-6, 104, 0}}, "#e6dcc6", "stroke=\"none\""); + if (links >= 3) { + road += line({-160, 115, 0}, {160, 115, 0}, "#6f6a60", 1) + line({-160, 117.4, 0}, {160, 117.4, 0}, "#6f6a60", 1); + for (double x = -158; x < 160; x += 5) road += line({x, 114.4, 0}, {x, 118, 0}, "#8a8274", .6); + } + road += car(-70, 105.5, "#c8733c", true) + car(-20, 105.5, "#7a8a5e", true) + car(52, 110.5, "#f3ede0", true) + car(96, 105.5, "#5d7f96", true) + car(115, -60, "#d9b24a", false) + car(115, 30, "#b9ad94", false); + items.push_back({-9000, road}); + hot(name(0), -9000, {ground(-160, 104, 160, 122)}); + if (links >= 2) { + // a bus stop with its bus + auto shelter = box(-124, 98, -108, 101.5, 4.6, 5.2, "#c8733c"); const auto post_a = box(-124, 98, -123.4, 101.5, 0, 4.6, "#d9d2c2"), post_b = box(-108.6, 98, -108, 101.5, 0, 4.6, "#d9d2c2"); + shelter.insert(shelter.end(), post_a.begin(), post_a.end()); shelter.insert(shelter.end(), post_b.begin(), post_b.end()); + BoxLook bus; bus.deco_y = windows_y(109, -100, -84, 2.6, 4.6, 5, "#dfe9ee", .12); + items.push_back({-16, shadow(-124, 98, -108, 101.5, 5) + paint(shelter) + paint(box(-121, 99.4, -111, 100.4, 0, 1.2, "#8a6a4a")) + sign_y(-122, 101.5, 5.4, "H", 5, "#2f6b2f") + paint(box(-100, 105, -84, 109, .8, 5.2, "#d9b24a", bus))}); + hot(name(0), -16, box_quads(-124, 98, -108, 101.5, 0, 5.2)); + } + if (links >= 3) { + BoxLook tram; tram.top = "#f3ede0"; + tram.deco_y = windows_y(117.8, 40, 66, 2.6, 4.8, 8, "#dfe9ee", .12) + poly({{40, 117.8, 1.4}, {66, 117.8, 1.4}, {66, 117.8, 2.2}, {40, 117.8, 2.2}}, "#f6ecd8", "stroke=\"none\""); + items.push_back({176, paint(box(40, 114.6, 66, 117.8, .8, 5.4, "#c8733c", tram)) + line({53, 116.2, 5.4}, {53, 116.2, 8.5}, ink, .8) + line({46, 116.2, 8.5}, {60, 116.2, 8.5}, ink, .8)}); + } + // the station is the last stage; until then its plot is marked + if (links >= 4) { + const auto clock = project({74, 99, 11.6}); + BoxLook hall; hall.top = "#b9ad94"; hall.deco_y = windows_y(99, 44, 104, 2, 7, 10, "#bfe0ea", .18) + sign_y(62, 99, 9.6, "BAHNHOF", 6.5); + BoxLook tower; tower.top = "#c8733c"; tower.deco_y = ""; + auto station = box(44, 86, 104, 99, 0, 9, "#efe6d2", hall); const auto upper = box(68, 84, 80, 99, 9, 14, "#efe6d2", tower); + station.insert(station.end(), upper.begin(), upper.end()); + items.push_back({173, shadow(44, 86, 104, 99, 10) + paint(station) + works(0, 108, 100, 24)}); + hot(name(0), 173, box_quads(44, 86, 104, 99, 0, 9)); + } else if (most(0) >= 4) { + items.push_back({173, plot(44, 86, 104, 99) + works(0, 108, 100, 24)}); + hot(name(0), 173, {ground(44, 86, 104, 99)}); + } + } + { + // the car park grows along the road with every stage + const int stage = level(4) <= 0 ? 0 : std::clamp(int(std::lround(double(level(4)) / most(4) * 4)), 1, 4); + const double half = std::array{0, 14, 24, 36, 46}[size_t(stage)]; + std::string park = (stage < 4 && !future ? plot(128, -46, 156, 46) : std::string()) + (stage ? poly({{128, -half, 0}, {156, -half, 0}, {156, half, 0}, {128, half, 0}}, "#d6d0c4", "stroke=\"#3a332b\" stroke-opacity=\".4\" stroke-width=\".8\"") : std::string()); + Random random{5}; + static constexpr std::array paints{"#c8733c", "#7a8a5e", "#f3ede0", "#5d7f96", "#d9b24a", "#8f8778", "#a8452f"}; + for (double y = -half + 2; y < half - 3; y += 3.6) { + park += line({129, y - .6, 0}, {136, y - .6, 0}, "#fbf7ee", .7) + line({148, y - .6, 0}, {155, y - .6, 0}, "#fbf7ee", .7); + if (random.next() < .7) park += car(130, y, paints[size_t(random.between(0, 6))], true); + if (random.next() < .6) park += car(149.5, y, paints[size_t(random.between(0, 6))], true); + } + if (stage) { + const auto q = project({128.6, 0, 10.5}); + park += paint(box(128, -1.5, 129.2, 1.5, 0, 8, "#8f8778")) + "P"; + } + items.push_back({142, park + works(4, 158, 0, 22)}); + hot(name(4), 142, {ground(128, -46, 156, 46)}); + } + // a house on its plot, or the plot alone + const auto house = [&](size_t index, double x0, double y0, double x1, double y1, double tall, const std::vector &faces, const std::string &extra) { + const bool built = level(index) > 0; const double depth = (x0 + x1 + y0 + y1) / 2; + items.push_back({depth, (built ? shadow(x0, y0, x1, y1, tall) + paint(faces) + extra : plot(x0, y0, x1, y1)) + works(index, x1 + 4, y1 + 4, tall + 14)}); + hot(name(index), depth, built ? box_quads(x0, y0, x1, y1, 0, tall) : std::vector{ground(x0, y0, x1, y1)}); + }; + const auto storeys = [&](size_t index, int tallest) { return level(index) <= 0 ? 0 : most(index) > 1 ? std::clamp(level(index), 1, tallest) : std::min(2, tallest); }; + { + // the club house with its flag + const double z = 5 + storeys(3, 3) * 3.2; + BoxLook look; look.top = "#c8733c"; look.deco_x = windows_x(-116, -34, 10, 1.4, z - 1.2, 7, "#bfe0ea", .2) + sign_x(-116, 6, z + .6, "CLUBHAUS", 6); look.deco_y = windows_y(10, -152, -116, 1.4, z - 1.2, 6, "#bfe0ea", .2); + BoxLook porch; porch.top = "#8fa073"; + auto faces = box(-152, -34, -116, 10, 0, z, "#f1e7d2", look); const auto front = box(-116, -18, -108, -4, 0, 3.4, "#e6dcc6", porch); + faces.insert(faces.end(), front.begin(), front.end()); + house(3, -152, -34, -116, 10, z, faces, line({-140, -20, z}, {-140, -20, z + 9}, ink, .9) + poly({{-140, -20, z + 9}, {-140, -14, z + 7.6}, {-140, -20, z + 6.2}}, "#c8733c") + (busy(around(3)) ? scaffold({faces[1], faces[2]}) : std::string())); + } + { + BoxLook look; look.top = "#f1c94b"; look.side_x = "#6b3a96"; look.side_y = "#6b3a96"; + look.deco_x = windows_x(-120, 34, 66, 1, 5, 5, "#f6d54a", .2) + sign_x(-120, 62, 6.2, "ARCADE", 7, "#ffe9a0"); look.deco_y = windows_y(66, -150, -120, 1, 5, 5, "#f6d54a", .2); + house(1, -150, 34, -120, 66, 9, box(-150, 34, -120, 66, 0, 9, "#5a2d82", look), ""); + } + { + const double z = 7 + storeys(2, 3) * 4; + BoxLook look; look.top = "#d9d2c2"; look.deco_y = windows_y(-92, -46, 44, 1.2, z - 2, 12, "#bfe0ea", .14) + sign_y(-22, -92, z + .8, "EINKAUFSZENTRUM", 7); look.deco_x = windows_x(44, -124, -92, 1.2, z - 2, 4, "#bfe0ea", .14); + BoxLook dome; dome.top = "#dff0f4"; + auto faces = box(-46, -124, 44, -92, 0, z, "#f1e7d2", look); const auto light = box(-10, -116, 14, -100, z, z + 3, "#bfe0ea", dome); + faces.insert(faces.end(), light.begin(), light.end()); + house(2, -46, -124, 44, -92, z, faces, ""); + } + { + BoxLook look; look.top = "#a8452f"; look.deco_y = windows_y(-96, 66, 100, 1.2, 5, 6, "#bfe0ea", .2) + sign_y(72, -96, 7.6, "RESTAURANT", 5.4); look.deco_x = windows_x(100, -122, -96, 1.2, 5, 4, "#bfe0ea", .2); + // tables under parasols in front of it + std::string terrace = paint(box(66, -96, 100, -86, 0, .6, "#d9b98a")); + for (const double x : {70.0, 78.0, 86.0, 94.0}) { + const auto q = project({x, -91, 3}); + terrace += " 7 ? "#c8733c" : "#f6ecd8") + "\" stroke=\"" + ink + "\" stroke-width=\".6\"/>" + line({x, -91, .6}, {x, -91, 3}, ink, .7); + } + house(5, 66, -122, 100, -96, 7, box(66, -122, 100, -96, 0, 7, "#f6f0e2", look), terrace); + } + { + const auto stall = [&](size_t index, double x, double y) { + BoxLook look; look.top = "#c8733c"; + look.deco_y = poly({{x, y + 7, 2.6}, {x + 9, y + 7, 2.6}, {x + 9, y + 9.2, 2.1}, {x, y + 9.2, 2.1}}, "#f6d9a8", "stroke=\"#3a332b\" stroke-width=\".5\"") + windows_y(y + 7, x, x + 9, .8, 2.4, 1, "#6b5a48", .14); + house(index, x, y, x + 9, y + 7, 4, box(x, y, x + 9, y + 7, 0, 4, "#f6ecd8", look), sign_y(x + .6, y + 7, 4.4, "Imbiss", 3.4)); + }; + stall(6, -112, -94); stall(7, 100, -92); stall(8, 96, 84); stall(9, -110, 82); + const auto shop = [&](size_t index, double x, double y) { + BoxLook look; look.top = "#b5562a"; + look.deco_y = windows_y(y + 10, x, x + 16, .8, 3.6, 3, "#bfe0ea", .14) + poly({{x, y + 10, 4}, {x + 16, y + 10, 4}, {x + 16, y + 12.4, 3.3}, {x, y + 12.4, 3.3}}, "#c8733c", "stroke=\"#3a332b\" stroke-width=\".5\""); + look.deco_x = windows_x(x + 16, y, y + 10, .8, 3.6, 2, "#bfe0ea", .14); + house(index, x, y, x + 16, y + 10, 6, box(x, y, x + 16, y + 10, 0, 6, "#f6ecd8", look), sign_y(x + 1.4, y + 10, 6.6, "FAN-SHOP", 3.8)); + }; + shop(10, -84, 84); shop(11, -52, 84); shop(12, 126, -76); shop(13, -136, -72); + } + { + Random random{11}; + static constexpr std::array, 32> trees{{{-156, -120}, {-140, -112}, {-120, -122}, {-96, -116}, {-70, -122}, {58, -110}, {140, -118}, {152, -100}, {150, -84}, {-156, -50}, {-158, 22}, + {-156, 76}, {-140, 90}, {-96, 92}, {-70, 100}, {-30, 98}, {20, 96}, {30, 86}, {118, 96}, {150, 98}, {156, 60}, {-108, -50}, + {-104, 30}, {106, -40}, {104, 50}, {-158, 126}, {-90, 126}, {-10, 126}, {70, 126}, {150, 126}, {-126, 20}, {-112, 56}}}; + for (size_t i = 0; i < trees.size(); ++i) items.push_back({trees[i][0] + trees[i][1], tree(trees[i][0], trees[i][1], .8 + random.next() * .5, int(i))}); + // people on the forecourt + Random crowd{3}; std::string people; + static constexpr std::array coats{"#c8733c", "#3a332b", "#f6ecd8", "#7a8a5e"}; + for (int i = 0; i < 46; ++i) { + const double x = crowd.between(-40, 40) + (i % 3 ? 0 : 50 * (crowd.next() - .5)), y = 84 + crowd.next() * 18 - (i % 4 ? 0 : 4); const auto q = project({x, y, 0}); + people += ""; + } + items.push_back({-8000, people}); + } + + // ---- the base plate of card under it all ---- + std::stable_sort(items.begin(), items.end(), [](const Item &a, const Item &b) { return a.depth < b.depth; }); + std::stable_sort(scene.hots.begin(), scene.hots.end(), [](const Hot &a, const Hot &b) { return a.depth < b.depth; }); + constexpr double X = 160, Y = 128; + std::string body = poly({{-X, Y, -7}, {X, Y, -7}, {X, -Y, -7}, {X + 10, -Y + 6, -7}, {X + 10, Y + 10, -7}, {-X + 6, Y + 10, -7}}, "#2e2b25", "fill-opacity=\".14\""); + body += poly({{X, -Y, 0}, {X, Y, 0}, {X, Y, -7}, {X, -Y, -7}}, "#c9ad80") + poly({{-X, Y, 0}, {X, Y, 0}, {X, Y, -7}, {-X, Y, -7}}, "#b99a6c"); + for (double i = -Y + 3; i < Y; i += 3.2) body += line({X, i, -1.5}, {X, i + 1.6, -5.5}, "#9a7c4e", .6); + for (double i = -X + 3; i < X; i += 3.2) body += line({i, Y, -1.5}, {i + 1.6, Y, -5.5}, "#8a6c40", .6); + body += poly({{-X, -Y, 0}, {X, -Y, 0}, {X, Y, 0}, {-X, Y, 0}}, "#dde6c6", "stroke=\"#3a332b\" stroke-opacity=\".5\" stroke-width=\"1\""); + body += poly({{-98, -80, 0}, {98, -80, 0}, {98, 80, 0}, {-98, 80, 0}}, "#efe7d4", "stroke=\"#3a332b\" stroke-opacity=\".3\" stroke-width=\".8\"") + poly({{-58.5, -40, 0}, {58.5, -40, 0}, {58.5, 40, 0}, {-58.5, 40, 0}}, "#d9c9a4", "stroke=\"none\"") + + poly({{-100, -8, 0}, {-116, -8, 0}, {-116, 4, 0}, {-100, 4, 0}}, "#e6dcc6", "stroke=\"none\""); + for (const auto &item : items) body += item.svg; + scene.svg = "" + body + ""; + return scene; +} +} // namespace bmh::modern_ui::stadium_scene diff --git a/src/modern/ui/stadium_screens.inc b/src/modern/ui/stadium_screens.inc index 39f6760..70300b3 100644 --- a/src/modern/ui/stadium_screens.inc +++ b/src/modern/ui/stadium_screens.inc @@ -29,291 +29,327 @@ std::string stadium_feedback(const Json "e,bool invalid) { if(!quote.value("can_build",false))return "Bitte einen Ausbau auswählen."; return "Fiktiver Bauauftrag; Spielzeit und Desktopkonto bleiben unverändert."; } -std::string stadium_svg(const std::string &body,double w,double h) { - return ""+body+""; +// The colours of the six curves of the stadium's data, in the order of the series. +std::array stadium_curve_colours(const std::string &theme) { + return {"#8c491a","#56633f",theme=="silver"?"#2e2b25":"#d8d2c4","#d08a1e","#2b6f8f","#a8452f"}; } -// The stadium as an architect's plan, drawn from the blocks themselves: each of the eight -// stands is as deep as it has places, its dashed outline shows how far it may grow, seats -// take the club's colour, terraces are hatched, a roof lies over the outer rows, and a -// stand under construction is outlined in gold. Angles in degrees, clockwise from the east. -constexpr std::array,8> stadium_plan_spans{{{{205,245}},{{245,295}},{{295,335}},{{-25,25}},{{25,65}},{{65,115}},{{115,155}},{{155,205}}}}; -constexpr double stadium_plan_w=1426,stadium_plan_h=989,stadium_plan_rx=330,stadium_plan_ry=205; -double stadium_plan_depth(int64_t places,int64_t greatest) {return 50+168.0*double(std::max(0,places))/double(std::max(1,greatest));} -std::array stadium_plan_point(double degrees,double depth) { - const double a=degrees*3.14159265358979/180; - return {stadium_plan_w/2+(stadium_plan_rx+depth)*std::cos(a),stadium_plan_h/2+(stadium_plan_ry+depth)*std::sin(a)}; -} -std::string stadium_plan_svg(const Json &blocks,const std::string &club_colour,const std::string &theme) { - const bool paper=theme=="silver"; - const std::string ground=paper?"#f6efdc":"#1c2630",grid=paper?"#8a7a5522":"#dfeaf514",ink=paper?"#3d362a":"#d5dde3", - terrace=paper?"#d8cfb9":"#4a5661",roof=paper?"#4d5660":"#0f151b",gold="#c9962e"; - int64_t greatest=1;for(const auto &b:blocks)greatest=std::max(greatest,b.at("max_places").get()); - const auto ring=[&](double from,double to,double inner,double outer) { - std::string d; - for(double a=from;a<=to+.01;a+=2.5){const auto p=stadium_plan_point(a,outer);d+=(d.empty()?"M":"L")+scalar(p[0])+" "+scalar(p[1]);} - for(double a=to;a>=from-.01;a-=2.5){const auto p=stadium_plan_point(a,inner);d+="L"+scalar(p[0])+" "+scalar(p[1]);} - return d+"Z"; - }; - std::string body=""; - for(double x=46;x"; - for(double y=46;y"; - // the pitch inside its track - body+=""; - const double pw=500,ph=300,px=(stadium_plan_w-pw)/2,py=(stadium_plan_h-ph)/2; - for(int stripe=0;stripe<10;++stripe)body+=""; - body+="" - ""; - for(size_t i=0;i<8&&i(),greatest),most=inner+stadium_plan_depth(b.at("max_places").get(),greatest); - const bool seats=b.at("display_seats").get(),roofed=b.at("display_roof").get(),building=b.at("building").get(); - // how far the stand may grow - body+=""; - body+=""; - // rows of seats run along the stand, the steps of a terrace across it - if(seats)for(double depth=inner+22;depth";} - else for(double a=from+4;a";} - if(roofed) { - const double edge=built-(built-inner)*.42; - body+=""; - for(double a=from+5;a";} - } - if(building) { - const double target=inner+stadium_plan_depth(b.at("job").value("places",b.at("display_places").get()),greatest); - body+=""; +// The curves of the stadium's data on one sheet: every series is a row of points between 0 +// and 1 (x from the left, y from the top). +std::string stadium_chart_svg(const std::vector>>> &series,const std::string &theme) { + constexpr double w=1800,h=1030,left=24,right=24,top=24,bottom=30; + const std::string rule=theme=="silver"?"#3a332b":"#f0ece2"; + std::string svg=""; + for(const double part:{.25,.5,.75})svg+=""; + for(const auto &[colour,points]:series) { + std::string line,dots; + for(const auto &p:points) { + const double x=left+16+std::clamp(p[0],0.0,1.0)*(w-left-right-32),y=top+12+std::clamp(p[1],0.0,1.0)*(h-top-bottom-24); + line+=scalar(x)+","+scalar(y)+" ";dots+=""; } + if(points.size()>1)svg+=""; + svg+=dots; } - return stadium_svg(body,stadium_plan_w,stadium_plan_h); + return svg+""; } -std::string stadium_feature_svg(const std::string &kind,bool built,const std::string &theme) { - const std::string color=theme=="silver"?"#25617a":theme=="matchday"?"#efb2aa":built?"#b7e0d1":"#a8cbbd"; - const auto path=kind=="seats"?"M7 4h16v13H7zM5 20h22v5H5zM8 25v5M24 25v5M9 9h14":"M2 16 16 4l14 12M6 15v14M26 15v14M10 17h12v12H10"; - return stadium_svg("",32,32); +// A small picture for an offer that has none of its own: one bar more with every stage. +std::string stadium_stage_svg(int level) { + static constexpr std::array tones{"#cfc7b6","#d9a05e","#c8733c","#8c491a"}; + std::string svg=""; + for(int i=0;i<=std::clamp(level,0,3);++i)svg+=""; + return svg+""; } -std::string stadium_graph_svg(const Json &curves,bool relative,const std::string &theme) { - constexpr std::array colors{"#8fbaa6","#8cacc9","#adb7c1","#cf9088","#c5b384","#729aae"}; - std::array,6> values{};double maximum=0; - for(int i=0;i<24;++i) { - const double attendance=std::round(24000+7000*std::sin(i*.7)+i*130); - const std::array row{attendance,double(11+i/8),double(12000000+i*220000),double(18000+i*750),attendance*13,double(70000+i*1500)}; - for(size_t k=0;k<6;++k){values[k][size_t(i)]=row[k];maximum=std::max(maximum,row[k]);} - } - const std::string divider=theme=="silver"?"#6c879c28":theme=="matchday"?"#ead9da16":"#9eb6c44d"; - std::string svg=""; - for(double x:{.25,.5,.75})svg+=""; - for(size_t k=0;k<6;++k)if(curves[k].get()) { - const double scale=relative?*std::max_element(values[k].begin(),values[k].end()):maximum; - svg+=""; - } - return stadium_svg(svg,3600,620); +std::string stadium_kv(const std::string &key,const std::string &value,const std::string &id=std::string()) { + return "
"+key+""+value+"
"; } } // namespace +// How the model lies on the stage: its zoom and where the picture's corner is, in units of the +// page. The stadium's view stands close, the surroundings show the whole plate. +std::array App::stadium_cam(bool outer) { + const auto key=outer?"panorama":"inside"; + if(const auto found=stadium_cams_.find(key);found!=stadium_cams_.end())return found->second; + const double zoom=outer?1.06:1.62; + return {zoom,622-stadium_scene::origin_x*zoom,336-stadium_scene::origin_y*zoom}; +} +std::string App::stadium_cam_style(const std::array &cam) { + return "left:"+pg(cam[1])+";top:"+pg(cam[2])+";transform:scale("+scalar(cam[0])+");"; +} + +// Verein > Stadion and Peripherie: the model of the ground on its stage. The pointer names a +// part, a click lays its card on the picture; from the card the building firm's offer opens. std::string App::render_stadium() { stadium_view_defaults(stadium_view_);if(!world_)return ""; const bool future=stadium_view_.at("future").get(); - const auto overview=stadium_overview(future);const auto club=overview.value("club",std::string()); - if(!overview.value("ok",false))return "

Die Stadionvorschau ist derzeit nicht verfügbar.

"; + const auto overview=stadium_overview(future); + if(!overview.value("ok",false))return "
Die Stadionvorschau ist derzeit nicht verfügbar.
"; if(engine_mode_)engine_stadium_value_=overview; const auto view=stadium_view_.at("view").get(); - const auto feature=[&](const std::string &kind,bool built,double size) {return picture(renderer_.diagram("stadium-feature-"+kind+(built?"-built-":"-empty-")+theme_,stadium_feature_svg(kind,built,theme_),232),size,size);}; - const auto art_overlay=[&](int i,int level,double w,double natural_h) { - // Texture cover handles the base art. This independent125dp SVG viewport - // clips overlays at the same boundary, even for absolutely positioned text. - constexpr double viewport_h=125;const double dy=(viewport_h-natural_h)/2;std::string body; - if(i==1) { - const double x=level==1?.28:level==3?.13:level==4?.12:.10,y=level==3?.24:level==4?.63:.30,rw=level==1?.40:level==3?.72:level==4?.74:.60,rh=level==1?.28:level==3?.24:level==4?.18:.45; - const std::string color=level==2?"#ff593e":theme_=="silver"?(level==4?"#233443":"#805b18"):theme_=="matchday"?(level==4?"#efeded":"#e1c68b"):level==1?"#edc960":level==3?"#dfdc67":"#d9e8ef"; - body+="2 : 1"; - } - if(((i==2||i==3)&&level<2)||(i==5&&level==1)) { - const std::string color=theme_=="silver"?"#a23f45":theme_=="matchday"?"#f0a6a7":"#df8c80"; - body+=""; - } - if(i==5&&level>1) { - const std::string color=theme_=="silver"?"#805b18":theme_=="matchday"?"#e1c68b":"#e0c99b"; - const int n=level-1;for(int k=0;k"; - } - if(body.empty())return std::string(); - return ""+picture(renderer_.diagram("stadium-card-overlay-"+std::to_string(i)+"-"+std::to_string(level)+"-"+theme_,stadium_svg(body,w,viewport_h),1564),w,viewport_h)+""; + const bool outer=view=="panorama"; + const auto ground=overview.at("name").get(); + page_title_=outer?"Peripherie – "+ground:ground+" – "+number(overview.at("capacity").get())+" Plätze"; + page_hint_=view=="data"?"Stadiondaten":std::string(outer?"ein Gebäude anklicken":"ein Bauteil anklicken")+(future?(outer?" · Stand nach Fertigstellung":" · geplante Kapazität"):""); + if(view=="data")return render_stadium_data()+render_stadium_dialog(); + // over the gate stands the first word of the ground's name + auto sign=pg_upper(ground.substr(0,ground.find_first_of(" -"))); + if(sign.empty()||sign.size()>13)sign="STADION"; + const auto scene=stadium_scene::build(overview,future,sign); + if(!stadium_focus_.empty()&&(stadium_focus_.starts_with("periphery:")!=outer||std::none_of(scene.hots.begin(),scene.hots.end(),[&](const auto &h){return h.id==stadium_focus_;})))stadium_focus_.clear(); + const auto index_of=[](const std::string &id){return size_t(std::stoul(id.substr(id.find(':')+1)));}; + const auto row_of=[&](const std::string &id)->const Json & {return overview.at(id.starts_with("block:")?"blocks":id.starts_with("facility:")?"facilities":"periphery")[index_of(id)];}; + const auto name_of=[&](const std::string &id)->std::string { + const auto &row=row_of(id); + return id.starts_with("block:")?"Block "+row.at("letter").get()+" · "+row.at("name").get():row.at("name").get(); }; - std::string out="
"; - out+="

"+esc(overview.at("name").get())+"

"+(view=="inside"?"Stadion · ein Bauteil anklicken":view=="panorama"?"Umfeld · ein Gebäude anklicken":"Stadiondaten")+"

"+(future?"Geplante Kapazität":"Verfügbare Kapazität")+std::string("")+number(overview.at("capacity").get())+" Plätze
"+std::string(engine_mode_?"Vereinskasse":"Ausbaubudget")+"()):"")+"\">"+esc(stadium_cash(overview.at("budget")))+"
"; - if(view=="inside"||view=="panorama") { - // the ground as a card model seen from a fixed camera: the stadium with its stands and - // facilities, or its surroundings; the pointer names a part, a click shows its card - const bool outer=view=="panorama"; - std::string seat_colour; - if(const auto *own=world_->find("clubs",club);own&&!own->value("crest","").empty())seat_colour=renderer_.crest_colour(own->value("crest","")); - if(seat_colour.empty())seat_colour="#3d6f8f"; - const auto scene=stadium3d::build(overview,seat_colour,theme_=="silver",outer?1:0); - if(!stadium_focus_.empty()&&(!scene.centres.contains(stadium_focus_)||stadium_focus_.starts_with("periphery:")!=outer))stadium_focus_.clear(); - constexpr double mw=2612,mh=1600; - const bool part_focus=!stadium_focus_.empty(); - const auto drawing=stadium3d::draw(scene,stadium3d::fixed_camera(outer),mw,mh,stadium_focus_); - out+="
"+picture(renderer_.diagram("stadium-model",drawing.svg,3580),mw,mh)+"
"; - const auto name_of=[&](const std::string &id)->std::string { - const auto index=size_t(std::stoul(id.substr(id.find(':')+1))); - if(id.starts_with("block:"))return "Block "+overview.at("blocks")[index].at("letter").get(); - if(id.starts_with("facility:"))return overview.at("facilities")[index].at("name").get(); - return overview.at("periphery")[index].at("name").get(); - }; - // what the pointer finds on a part: its name and what stands there today - const auto tip_of=[&](const std::string &id,double x,double y,double reach)->std::string { - const auto index=size_t(std::stoul(id.substr(id.find(':')+1))); - std::string state;bool busy=false; - if(id.starts_with("block:")) { - const auto &b=overview.at("blocks")[index];busy=b.at("building").get(); - state=number(b.at("display_places").get())+" von "+number(b.at("max_places").get())+" Plätzen · "+(b.at("display_seats").get()?"Sitzplätze":"Stehplätze")+(b.at("display_roof").get()?" · Dach":""); - } else if(id.starts_with("facility:")) { - const auto &f=overview.at("facilities")[index];busy=f.at("building").get(); - state=f.at("display_label").get(); - } else { - const auto &p=overview.at("periphery")[index];busy=p.at("building").get(); - const int level=p.at("level").get(),most=p.at("max_level").get(); - state=level<=0?"noch nicht gebaut":most>1?"Stufe "+std::to_string(level)+" von "+std::to_string(most):"gebaut"; - } - if(busy)state+=" · im Bau"; - constexpr double tw=620,th=128; - const double left=std::clamp(x-tw/2,12.0,mw-tw-12)-(x-reach),top=y-reach*.8>th+24?-th-12:1.6*reach+56; - return ""+esc(name_of(id))+""+esc(state)+""; - }; - if(part_focus)out+=btn("stadium-focus","","stadium-model-back","id=\"stadium-model-ground\" data-id=\"\" aria-label=\"Auswahl aufheben\" style=\""+rect(0,0,mw,mh)+"\""); - const double reach=outer?74:62; - std::map spots; - // stands last: where spots overlap, the stand is the one that is hit - auto anchors=drawing.anchors; - std::stable_sort(anchors.begin(),anchors.end(),[](const auto &a,const auto &b){return !a.id.starts_with("block:")&&b.id.starts_with("block:");}); - for(const auto &anchor:anchors) { - if(anchor.id==stadium_focus_)continue; - if(anchor.xmw-reach||anchor.y>mh-reach)continue; - const auto name=name_of(anchor.id);const int spot=spots[anchor.id]++; - out+=btn("stadium-focus",tip_of(anchor.id,anchor.x,anchor.y,reach),"stadium-model-hit","id=\"stadium-part-"+esc(anchor.id.substr(0,anchor.id.find(':'))+"-"+anchor.id.substr(anchor.id.find(':')+1))+(spot?"-"+std::to_string(spot):std::string())+"\" data-id=\""+esc(anchor.id)+"\" data-stadium-hint=\""+esc(name)+"\" aria-label=\""+esc(name)+"\" style=\""+rect(anchor.x-reach,anchor.y-reach*.8,2*reach,1.6*reach)+"\""); + const auto working=[&](const Json &row){return !future&&row.at("building").get();}; + // the places a stand has: while it is being built the overview shows none + const auto places_of=[&](const Json &b){return !future&&b.at("building").get()?b.at("places").get():b.at("display_places").get();}; + // what stands there today + const auto state_of=[&](const std::string &id)->std::string { + const auto &row=row_of(id);std::string state; + if(id.starts_with("block:"))state=number(places_of(row))+" von "+number(row.at("max_places").get())+" Plätzen · "+(row.at("display_seats").get()?"Sitzplätze":"Stehplätze")+(row.at("display_roof").get()?" · Dach":""); + else if(id.starts_with("facility:"))state=row.at("display_label").get(); + else { + const int level=row.value("display_level",row.at("level").get()),most=row.at("max_level").get(); + state=level<=0?"noch nicht gebaut":most>1?"Stufe "+std::to_string(level)+" von "+std::to_string(most):"gebaut"; } - for(const auto &part:drawing.parts) { - if(part.cx<60||part.cy<60||part.cx>mw-60||part.cy>mh-60)continue; - const bool letter=part.id.starts_with("block:"); - out+=""+esc(letter?overview.at("blocks")[size_t(std::stoul(part.id.substr(6)))].at("letter").get():name_of(part.id))+""; + return state+(working(row)?" · im Bau":""); + }; + const auto cam=stadium_cam(outer); + // The stage itself takes the pointer: which part lies under it is worked out from the + // scene, because the picture is zoomed and its faces lie askew. The faces in the world only + // show what is under the pointer or chosen; as buttons they serve the keyboard. + std::string out="
" + "
"+picture(renderer_.diagram("stadium-scene",scene.svg,4096),2799,1512)+"
"; + stadium_hots_.clear(); + // what the pointer was on stays marked when the page is drawn anew + if(std::none_of(scene.hots.begin(),scene.hots.end(),[&](const auto &h){return h.id==stadium_hover_&&h.id.starts_with("periphery:")==outer;}))stadium_hover_.clear(); + std::string tip; + for(const auto &part:scene.hots) { + if(part.id.starts_with("periphery:")!=outer)continue; + stadium_hots_.push_back(part); + const auto token=part.id.substr(0,part.id.find(':'))+"-"+part.id.substr(part.id.find(':')+1); + const auto name=name_of(part.id),state=state_of(part.id); + out+=""; + } + if(!outer)for(const auto &letter:scene.letters)out+=""+esc(letter.text)+""; + out+="
"; + // the equipment by name, for what is small on the model + if(!outer) { + out+="
"; + for(size_t i=0;i"+esc(f.at("name").get())+"· "+esc(f.at("display_label").get())+(working(f)?" · im Bau":"")+"",std::string("sd-chip")+(stadium_focus_==id?" on":""),"id=\"stadium-chip-"+std::to_string(i)+"\" data-id=\""+id+"\""); } out+="
"; - if(part_focus) { - // the part's card: what stands there today, and the way to build on - const auto index=size_t(std::stoul(stadium_focus_.substr(stadium_focus_.find(':')+1))); - std::string facts,action,label="Ausbauen";bool busy=false,full=false; - const auto fact=[](const std::string &k,const std::string &v){return "
"+k+""+v+"
";}; - if(stadium_focus_.starts_with("block:")) { - const auto &b=overview.at("blocks")[index];busy=b.at("building").get();action="stadium-block"; - const int64_t places=b.at("display_places").get(),most=b.at("max_places").get(); - facts=fact("Plätze",number(places)+" von "+number(most))+"
(1,most)),0.0,100.0))+"%;\">
"+ - fact("Sitzplätze",b.at("display_seats").get()?"ja":"nein, Stehplätze")+fact("Dach",b.at("display_roof").get()?"ja":"nein"); - if(busy)facts+=fact("Im Bau",number(b.at("job").at("places").get())+" Plätze · noch "+std::to_string(b.at("job").at("weeks").get())+" Wochen"); - full=places>=most&&b.at("display_seats").get()&&b.at("display_roof").get(); - } else if(stadium_focus_.starts_with("facility:")) { - const auto &f=overview.at("facilities")[index];busy=f.at("building").get();action="stadium-facility"; - facts=fact("Zustand",esc(f.at("display_label").get())); - if(busy)facts+=fact("Im Bau","noch "+std::to_string(f.at("job").at("weeks").get())+" Wochen"); - full=f.value("available",true)!=true;label=index>=4?"Erneuern":"Ausbauen"; - } else { - const auto &p=overview.at("periphery")[index];busy=p.at("building").get();action="stadium-periphery"; - const int level=p.at("level").get(),most=p.at("max_level").get(); - facts=fact("Ausbaustufe",std::to_string(level)+" von "+std::to_string(most)); - std::string pips="
";for(int k=0;k
":"
"; - facts+=pips+"
"; - if(busy)facts+=fact("Im Bau","noch "+std::to_string(p.at("job").at("weeks").get())+" Wochen"); - full=level>=most; - } - double chosen_x=0;for(const auto &part:drawing.parts)if(part.id==stadium_focus_)chosen_x=part.cx; - // the card lies over the picture, on the side away from the chosen part - out+=""; - } - } else { - if(engine_mode_)out+=engine_stadium_data(); - else {const auto snapshot=snap(); - const auto graph=stadium_graph_svg(stadium_view_.at("curves"),stadium_view_.at("relative").get(),theme_); - out+="
"+picture(renderer_.diagram("stadium-graph",graph,7200),2560,456)+"
"; - constexpr std::array colors{"#8fbaa6","#8cacc9","#adb7c1","#cf9088","#c5b384","#729aae"},names{"Zuschauer","Eintritt","Stadionwert","Zus. Stadion-Einnahmen","Einnahmen","Stadionkosten"}; - for(size_t i=0;i<6;++i)out+=btn("stadium-curve",""+names[i]+"","stadium-curve","id=\"stadium-curve-"+std::to_string(i)+"\" data-id=\""+std::to_string(i)+"\" aria-pressed=\""+(stadium_view_.at("curves")[i].get()?"true":"false")+"\" style=\""+rect((i%3)*754.666666667,660+(i/3)*90,732.666666667,74)+"\""); - for(int i=0;i<2;++i)out+=btn("stadium-scale",i?"Relativ":"Absolut","stadium-scale","id=\"stadium-scale-"+std::to_string(i)+"\" data-id=\""+std::to_string(i)+"\" aria-pressed=\""+(stadium_view_.at("relative").get()==bool(i)?"true":"false")+"\" style=\""+rect(2282,660+i*90,330,74)+"\""); - const auto factor=finance_currency_factor(*snapshot.world);const auto currency=snapshot.world->manifest().value("currency",Json::object());const auto cash=[&](int64_t n){return money(n*factor,currency);}; - std::vector other_clubs;for(const auto *c:snapshot.world->clubs())if(c->value("id","")!=club&&other_clubs.size()<2&&c->value("type",std::string("club"))=="club")other_clubs.push_back(snapshot.world->name(*c)); - const std::array,6> rows{{{{"","Liga","DFB-Pokal","Europapokal"}},{{"Max. Zuschauer","34.800 · "+(other_clubs.size()>0?other_clubs[0]:"—"),"35.200 · "+(other_clubs.size()>1?other_clubs[1]:"—"),"–"}},{{"Max. Einnahmen",cash(452400),cash(457600),"–"}},{{"Heimspiele","15","3","0"}},{{"Ø Zuschauer","28.450","31.200","–"}},{{"Ges. Einnahmen",cash(5547750),cash(1216800),"–"}}}}; - out+="
"; - for(size_t i=0;i<6;++i){out+="
";for(size_t k=0;k<4;++k)out+="
"+esc(rows[i][k])+"
";out+="
";}out+="
"; - const int ticket=snapshot.state.at("ticket").get(); - out+="

Benötigter Zuschauerschnitt bei "+esc(cash(ticket))+" Eintritt: "+(ticket?number((94000+ticket-1)/ticket):"–")+"

Eintritt:"; - for(int price=0;price<=25;++price)out+=btn("stadium-ticket",(price<10?"0":"")+std::to_string(price),"stadium-ticket-price","id=\"stadium-ticket-"+std::to_string(price)+"\" data-id=\""+std::to_string(price)+"\" aria-pressed=\""+(price==ticket?"true":"false")+"\" aria-label=\"Eintritt "+std::to_string(price)+" "+esc(money_unit())+"\""); - out+="
"; - } } - out+="
"+render_stadium_dialog(); + out+=pg_button("stadium-reset","Ansicht zurücksetzen","","id=\"stadium-reset\"")+""+pg_status("Mausrad zoomt · Ziehen verschiebt die Ansicht"); + return out+""+render_stadium_dialog(); } +// The stadium's figures: six curves over the home games, the ticket price, and the table of +// the three competitions. +std::string App::render_stadium_data() { + const auto colours=stadium_curve_colours(theme_); + const bool relative=stadium_view_.at("relative").get(); + std::array names{"Zuschauer","Eintritt","Stadionwert","Zus. Stadion-Einnahmen","Einnahmen","Stadionkosten"}; + std::vector>>> series; + std::vector> rows; + int ticket=0,low=0,high=25;std::string needed; + const Snapshot snapshot=engine_mode_?Snapshot{}:snap(); + if(engine_mode_) { + const auto &data=engine_data_.at("stadium").at("data"); + for(size_t i=0;i<6;++i) { + names[i]=data.at("history")[i].value("name",names[i]); + if(stadium_view_.at("curves")[i]!=true)continue; + std::vector> points; + // the game's own sheet runs from 13 to 311 across and from 18 to 101 down + for(const auto &point:data.at("history")[i].at(relative?"relative":"absolute"))points.push_back({(point[0].get()-13.)/298.,(point[1].get()-18.)/83.}); + series.emplace_back(colours[i],std::move(points)); + } + static constexpr std::array labels{"Max. Zuschauer","Max. Einnahmen (€)","Heimspiele","Ø Zuschauer","Ges. Einnahmen (€)"}; + for(size_t row=0;row<5;++row) { + const size_t source=row==0?0:row==1?2:row+2; + std::array cells{labels[row],"","",""}; + for(size_t col=0;col<3;++col) { + // a record comes with its day in brackets and its opponent: both go under the figure + auto figure=data.at("table")[source][col].get();std::string day; + if(const auto at=figure.find(" (");row<=1&&at!=std::string::npos){day=figure.substr(at+1);figure.erase(at);} + cells[col+1]=esc(figure); + if(!day.empty())cells[col+1]+=""+esc(day)+""; + if(row<=1)if(const auto other=data.at("table")[source+1][col].get();!other.empty())cells[col+1]+=""+esc(other)+""; + } + rows.push_back(cells); + } + ticket=int(engine_money_minor(data.at("ticketPrice"))/100); + low=int(engine_money_minor(data.at("ticketPriceRange").at("min"))/100);high=int(engine_money_minor(data.at("ticketPriceRange").at("max"))/100); + needed=data.at("requiredAttendanceText").get(); + } else { + // the demo's invented season + std::array,6> values{};double greatest=0; + for(int i=0;i<24;++i) { + const double attendance=std::round(24000+7000*std::sin(i*.7)+i*130); + const std::array row{attendance,double(11+i/8),double(12000000+i*220000),double(18000+i*750),attendance*13,double(70000+i*1500)}; + for(size_t k=0;k<6;++k){values[k][size_t(i)]=row[k];greatest=std::max(greatest,row[k]);} + } + for(size_t k=0;k<6;++k) { + if(stadium_view_.at("curves")[k]!=true)continue; + const double scale=relative?*std::max_element(values[k].begin(),values[k].end()):greatest; + std::vector> points; + for(size_t i=0;i<24;++i)points.push_back({double(i)/23.,1-values[k][i]/scale}); + series.emplace_back(colours[k],std::move(points)); + } + const auto club=stadium_managed(snapshot); + const auto factor=finance_currency_factor(*snapshot.world);const auto currency=snapshot.world->manifest().value("currency",Json::object());const auto cash=[&](int64_t n){return esc(money(n*factor,currency));}; + std::vector others; + for(const auto *c:snapshot.world->clubs())if(c->value("id","")!=club&&others.size()<2&&c->value("type",std::string("club"))=="club")others.push_back(snapshot.world->name(*c)); + const auto with=[&](const std::string &value,size_t other){return value+""+esc(others.size()>other?others[other]:"—")+"";}; + rows={{{"Max. Zuschauer",with("34.800",0),with("35.200",1),"–"}},{{"Max. Einnahmen",cash(452400),cash(457600),"–"}},{{"Heimspiele","15","3","0"}},{{"Ø Zuschauer","28.450","31.200","–"}},{{"Ges. Einnahmen",cash(5547750),cash(1216800),"–"}}}; + ticket=snapshot.state.at("ticket").get();low=0;high=25; + needed=ticket?number((94000+ticket-1)/ticket):"–"; + } + const auto unit=engine_mode_?std::string("€"):money_unit(); + std::string out="
"; + for(size_t i=0;i<6;++i) + out+=pg_button("stadium-curve",""+esc(names[i])+"",std::string("sd-curve")+(stadium_view_.at("curves")[i]==true?" on":""),"id=\"stadium-curve-"+std::to_string(i)+"\" data-id=\""+std::to_string(i)+"\" aria-pressed=\""+(stadium_view_.at("curves")[i]==true?"true":"false")+"\""); + out+="
"; + for(int i=0;i<2;++i)out+=btn("stadium-scale",""+std::string(i?"Relativ":"Absolut")+"",std::string(i?"":"first ")+(relative==bool(i)?"on":""),"id=\"stadium-scale-"+std::to_string(i)+"\" data-id=\""+std::to_string(i)+"\" aria-pressed=\""+(relative==bool(i)?"true":"false")+"\""); + out+="
"+(series.empty()?std::string("
Keine Kurve eingeblendet.
"):"
"+picture(renderer_.diagram("stadium-chart-"+theme_,stadium_chart_svg(series,theme_),2700),1800,1030)+"
")+"
"; + // the ticket price: a button for every price the game allows + out+="
"+pg_kicker("Eintritt:")+""+std::to_string(ticket)+" "+esc(unit)+"Benötigter Zuschauerschnitt bei "+std::to_string(ticket)+" "+esc(unit)+" Eintritt: "+esc(needed)+"
"; + for(int price=low;price<=high;++price) + out+=pg_button("stadium-ticket",std::to_string(price),std::string("sd-price")+(price==ticket?" on":""),"id=\"stadium-ticket-"+std::to_string(price)+"\" data-id=\""+std::to_string(price)+"\" aria-pressed=\""+(price==ticket?"true":"false")+"\" aria-label=\"Eintritt "+std::to_string(price)+" "+esc(unit)+"\""); + out+="
"; + for(const auto *competition:{"Liga","DFB-Pokal","Europapokal"})out+=""+esc(pg_upper(competition))+""; + out+="
"; + for(const auto &row:rows) { + out+="
"+esc(row[0])+""; + for(size_t col=1;col<4;++col)out+="
"+row[col]+"
"; + out+="
"; + } + out+="
"; +} + +// The building firm's offer as a note: what is to be built, what it costs and how long it +// takes; the order is given with "Bauen". std::string App::render_stadium_dialog() { stadium_view_defaults(stadium_view_);if(stadium_view_.at("dialog")=="")return ""; if(!world_||!stadium_view_.at("draft").is_object())return ""; - const auto &d=stadium_view_.at("draft");const bool block=d.at("kind")=="block";const int index=d.at("index").get(); + const auto &d=stadium_view_.at("draft");const bool block=d.at("kind")=="block",periphery=d.at("kind")=="periphery";const int index=d.at("index").get(); const auto overview=stadium_overview(false);if(!overview.value("ok",false))return ""; - const bool periphery=d.at("kind")=="periphery"; const auto &row=overview.at(block?"blocks":periphery?"periphery":"facilities")[size_t(index)];const auto q=stadium_quote_value(); - if(engine_mode_&&!q.value("ok",false))return "

"+esc(row.at("name").get())+" ausbauen

"+esc(engine_busy_?"Angebot wird geladen …":stadium_view_.value("feedback",std::string("Kein gültiges Angebot verfügbar.")))+"

"; + const bool renew=!block&&!periphery&&index>=4; + const auto title=block?"Block "+row.at("letter").get()+" ausbauen":row.at("name").get()+(renew?" erneuern":" ausbauen"); + const auto open=[&](double width){return "

"+esc(title)+"

";}; + if(engine_mode_&&!q.value("ok",false)) + return open(480)+"

"+esc(engine_busy_?"Angebot wird geladen …":stadium_view_.value("feedback",std::string("Kein gültiges Angebot verfügbar.")))+"

"; + const auto cash=stadium_kv(engine_mode_?"Vereinskasse":"POC-Budget",esc(stadium_cash(overview.at("budget")))); + const auto weeks=stadium_kv("Bauzeit",std::to_string(q.value("weeks",row.value("weeks",0)))+" Wochen","stadium-quote-weeks"); + const bool invalid=stadium_view_.at("invalid_places").get(); + std::string out=open(block||periphery?480:560); if(periphery) { const int level=d.at("level").get();std::string preview; + // the game's own picture of the building where the graphics pack has one if(gui_.contains("stadium.scene"))try { const auto config=Json::parse(editor::read_file(gui_.root()/editor::path(gui_.items().at("stadium.scene").at("file").get()))); const auto &profile=config.at("profiles").at("modern"); const auto binding=index==0?profile.at("backgroundOptions")[0].at("variants").at(size_t(level)):profile.at("objects").at(size_t(index)).at("sprites").at("variants").at(index==4?size_t(level-1):0); - const auto asset=binding.at("asset").get();const auto &meta=config.at("assets").at(asset);const double height=800.0*meta.at("height").get()/meta.at("width").get(); - preview=""+img("stadium.scene."+asset,800,height,false,false,1600)+""; + const auto asset=binding.at("asset").get();const auto &meta=config.at("assets").at(asset);const double tall=std::min(260.0,400.0*meta.at("height").get()/meta.at("width").get()); + preview=""+img("stadium.scene."+asset,400,tall,false,false,1200)+""; } catch(const std::exception &) {} - const auto title=row.at("name").get(); - return "

"+esc(title)+" ausbauen

"+(row.at("level")==0?"Neubau":"Erweiterung")+" · Stufe "+std::to_string(level)+"Bauzeit: "+std::to_string(q.value("weeks",0))+" Wochen
"+preview+"
Gesamtbetrag:"+esc(stadium_cash(stadium_field(q,"cost")))+"

"+esc(stadium_offer_feedback(q,false))+"

"; - } - struct Option {int level;Picture art;double height;};std::vector