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 <noreply@anthropic.com>
This commit is contained in:
MichaelandClaude Fable 5.2 committed 2026-11-15 20:57:01 +01:00
1 parent 17c6d0a1d3
commit c60b0e9b2c
14 files changed
+1025 -1178

No files matched your search

+49
View File
@@ -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;}
+1 -232
View File
@@ -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. */
+10 -1
View File
@@ -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();
+1 -1
View File
@@ -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");}
+1 -109
View File
@@ -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 = "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 2560 456'><path d='M20 "
"10V436H2540' fill='none' stroke='" +
std::string(theme_ == "silver" ? "#627c8f" : "#7d9aae") +
"' stroke-width='2'/>";
constexpr std::array<const char *, 6> 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 += "<polyline fill='none' stroke='" + std::string(colors[curve]) +
"' stroke-width='4' points='";
for (const auto &point : data.at("history")[curve].at(
stadium_view_.at("relative") == true ? "relative" : "absolute"))
svg += scalar(20. + (point[0].get<double>() - 13.) * 2520. / 298.) + "," +
scalar(20. + (point[1].get<double>() - 18.) * 416. / 83.) + " ";
svg += "'/>";
const auto &points = data.at("history")[curve].at(
stadium_view_.at("relative") == true ? "relative" : "absolute");
if (points.size() == 1)
svg += "<circle cx='" + scalar(20. + (points[0][0].get<double>() - 13.) * 2520. / 298.) +
"' cy='" + scalar(20. + (points[0][1].get<double>() - 18.) * 416. / 83.) +
"' r='3' fill='" + std::string(colors[curve]) + "'/>";
}
svg += "</svg>";
std::string out = "<div class=\"stadium-graph\"><div class=\"stadium-graph-art\">" +
picture(renderer_.diagram("stadium-engine-graph", svg, 5120), 2560, 456) +
"</div></div>";
for (size_t i = 0; i < 6; ++i)
out += btn("stadium-curve",
"<span class=\"stadium-curve-color\" style=\"background-color:" +
std::string(colors[i]) + ";\"></span><span class=\"stadium-curve-label\">" +
esc(data.at("history")[i].value("name", std::string(names[i]))) + "</span>",
"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<const char *, 6> labels{"", "Max. Zuschauer", "Max. Einnahmen (€)",
"Heimspiele", "Ø Zuschauer", "Ges. Einnahmen (€)"};
out += "<div class=\"stadium-data-table\">";
for (size_t row = 0; row < 6; ++row) {
out += "<div class=\"stadium-data-row " +
std::string(row == 0 ? "head"
: row % 2 ? "striped"
: "") +
"\">";
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<std::string>();
if (!other.empty())
value += " · " + other;
}
}
out += "<div class=\"stadium-data-cell " + std::string(col ? "" : "first") + "\"><span>" +
esc(value) + "</span></div>";
}
out += "</div>";
}
out += "</div>";
const int ticket = int(engine_money_minor(data.at("ticketPrice")) / 100);
out += "<p class=\"stadium-required\"><span>Benötigter Zuschauerschnitt bei " +
std::to_string(ticket) + " € Eintritt: </span><span class=\"stadium-required-value\">" +
esc(data.at("requiredAttendanceText").get<std::string>()) +
"</span></p><div class=\"stadium-ticket\"><strong>Eintritt:</strong>";
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 + "</div>";
}
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<Rml::String>("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("<span>" +
esc(hint.empty() ? "Ein Element im Stadionumfeld auswählen." : hint) +
"</span>");
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") {
-1
View File
@@ -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 &);
+7 -4
View File
@@ -14,7 +14,7 @@ const std::vector<NotebookSection> &notebook_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<NotebookSection> &notebook_sections() {
std::string notebook_page_label(const std::string &route) {
static const std::map<std::string, std::string> 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<bool(const std::string &)> &
// 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<bool(const std::string &)> &
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;
}
}
+1 -1
View File
@@ -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<std::string> native{"statistics", "news", "transfer", "training", "almanac", "tactics", "achievements", "highscore", "balance", "contracts", "environment", "tables", "league", "other", "strengths", "fairplay", "indoor", "scorers"};
static const std::set<std::string> 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";
+98 -30
View File
@@ -25,36 +25,111 @@ void App::sync_stadium_draft() {
if(stadium_view_.at("dialog")=="block")if(auto *button=element("stadium-place-number"))button->SetInnerRML("<span class=\"control-label\">"+std::to_string(stadium_view_.at("draft").at("places").get<int64_t>())+"</span>");
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<Rml::String>("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<Rml::String>("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<bool>());
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<float>("mouse_x",0)-stage->GetAbsoluteLeft())/scale_/2.25,my=(event.GetParameter<float>("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<double,3> &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<double,3> 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<float>("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<int>("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<double>(),dy=my-stadium_drag_.at("y").get<double>();
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<Rml::String>("data-tip-name","");state=n->GetAttribute<Rml::String>("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("<strong>"+esc(name)+"</strong><span>"+esc(state)+"</span>");}
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<Rml::String>("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("<span>"+esc(text.empty()?"Ein Element im Stadionumfeld auswählen.":text)+"</span>");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<Rml::String>("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<bool>();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;
}
}
-518
View File
@@ -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 <algorithm>
#include <array>
#include <cmath>
#include <map>
#include <sstream>
#include <string>
#include <vector>
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<Vec> 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<std::vector<Vec>> 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<Face> faces; std::map<std::string, Vec> centres; std::vector<std::pair<std::string, Vec>> anchors; std::string ink = "#3d362a", accent = "#25617a"; };
struct Drawing { std::string svg; std::vector<Part> parts; std::vector<Anchor> 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<std::array<double, 2>, 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<int64_t>(0, places)) / double(std::max<int64_t>(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<std::pair<Vec, Vec>, 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<std::array<const char *, 2>, 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<Vec> 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<Vec> 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<int64_t>());
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<int64_t>(), greatest), most = stand_depth(b.at("max_places").get<int64_t>(), greatest);
const double top = 3 + depth * .58, outer = inner + depth;
deepest = std::max(deepest, inner + most);
const bool seated = b.at("display_seats").get<bool>(), roofed = b.at("display_roof").get<bool>();
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<Vec> 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<int64_t>()), 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<int64_t>(), 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<std::tuple<size_t, double, double, const char *>, 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<const char *, 5> 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<std::array<double, 2>, 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<std::array<double, 2>, 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<Item> 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<size_t>(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<std::string, Part> parts;
Drawing out;
out.svg = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 " + num(width) + " " + num(height) + "\">";
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 += "<path d=\"" + path + "\" fill=\"" + fill + "\" fill-opacity=\"" + (face.fill.empty() ? std::string("1") : num(face.opacity)) + "\"" +
(face.stroke > 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 += "<path d=\"" + d + "\" fill=\"none\" stroke=\"" + (face.fill == "" ? ink : std::string("#ffffff")) + "\" stroke-opacity=\".45\" stroke-width=\"" + num(1.6 * std::sqrt(camera.zoom)) + "\"/>";
}
}
out.svg += "</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
+537
View File
@@ -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 <algorithm>
#include <array>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <string>
#include <vector>
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<Quad> quads;
};
struct Letter { std::string text; Point at; };
struct Scene {
std::string svg;
std::vector<Hot> hots; // sorted from the back to the front
std::vector<Letter> 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<Vec> &all) { std::string out; for (const auto &p : all) out += (out.empty() ? "" : " ") + pt(p); return out; }
inline std::array<int, 3> 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<Vec> &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 "<line x1=\"" + num(p.x) + "\" y1=\"" + num(p.y) + "\" x2=\"" + num(q.x) + "\" y2=\"" + num(q.y) + "\" stroke=\"" + colour + "\" stroke-width=\"" + num(w) + "\" stroke-linecap=\"round\" " + more + "/>";
}
inline const char *edge = "stroke=\"#3a332b\" stroke-opacity=\".55\" stroke-width=\".8\" stroke-linejoin=\"round\"";
inline std::string poly(const std::vector<Vec> &all, const std::string &fill, const std::string &more = edge) { return "<polygon points=\"" + pts(all) + "\" fill=\"" + fill + "\" " + more + "/>"; }
struct Face {
std::vector<Vec> 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<Face> 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<Face> 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<Quad> 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 == '&' ? "&amp;" : c == '<' ? "&lt;" : c == '>' ? "&gt;" : c == '"' ? "&quot;" : 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 "<text transform=\"matrix(.866,.5,0,1," + num(q.x) + "," + num(q.y) + ")\" font-family=\"" + lettering + "\" font-size=\"" + num(size) + "\" fill=\"" + fill + "\">" + xml(text) + "</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 "<text transform=\"matrix(.866,-.5,0,1," + num(q.x) + "," + num(q.y) + ")\" font-family=\"" + lettering + "\" font-size=\"" + num(size) + "\" fill=\"" + fill + "\">" + xml(text) + "</text>";
}
inline std::vector<std::array<double, 2>> hull(std::vector<std::array<double, 2>> 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<std::array<double, 2>> 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<std::array<double, 2>> 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<Vec> 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<std::array<const char *, 3>, 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 "<ellipse cx=\"" + num(q.x - r * .7) + "\" cy=\"" + num(q.y + 1) + "\" rx=\"" + num(r * 1.1) + "\" ry=\"" + num(r * .42) + "\" fill=\"#4a3c2e\" opacity=\".16\"/><rect x=\"" + num(q.x - .9) + "\" y=\"" + num(q.y - r * 1.5) +
"\" width=\"1.8\" height=\"" + num(r * 1.5) + "\" fill=\"#7a5a3a\"/><circle cx=\"" + num(q.x) + "\" cy=\"" + num(q.y - r * 2.1) + "\" r=\"" + num(r) + "\" fill=\"" + g[0] + "\" stroke=\"" + ink +
"\" stroke-opacity=\".5\" stroke-width=\".7\"/><circle cx=\"" + num(q.x + r * .2) + "\" cy=\"" + num(q.y - r * 2.35) + "\" r=\"" + num(r * .72) + "\" fill=\"" + g[1] + "\"/><circle cx=\"" + num(q.x + r * .36) + "\" cy=\"" +
num(q.y - r * 2.6) + "\" r=\"" + num(r * .4) + "\" fill=\"" + g[2] + "\"/>";
}
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<Face> &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 "<line x1=\"" + num(a.x) + "\" y1=\"" + num(a.y) + "\" x2=\"" + num(b.x) + "\" y2=\"" + num(b.y) + "\" stroke=\"#d08a1e\" stroke-width=\"2.4\"/><path d=\"M" + num(a.x - 5) + " " + num(a.y) + "h10\" stroke=\"" + ink +
"\" stroke-width=\"2\"/><path d=\"M" + num(b.x - 16) + " " + num(b.y + 3) + "L" + num(b.x) + " " + num(b.y - 7) + "L" + num(b.x + 46) + " " + num(b.y + 2) + "M" + num(b.x - 16) + " " + num(b.y + 3) + "H" + num(b.x + 46) +
"\" fill=\"none\" stroke=\"#d08a1e\" stroke-width=\"2\"/><rect x=\"" + num(b.x - 18) + "\" y=\"" + num(b.y + 3) + "\" width=\"8\" height=\"6\" fill=\"#7a6a58\"/><path d=\"M" + num(b.x + 34) + " " + num(b.y + 3) + "v20\" stroke=\"" + ink +
"\" stroke-width=\".8\"/><rect x=\"" + num(b.x + 30) + "\" y=\"" + num(b.y + 23) + "\" width=\"8\" height=\"5\" fill=\"#c9b28a\" stroke=\"" + ink + "\" stroke-width=\".6\"/>";
}
// 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<Item> items;
const auto hot = [&](const std::string &id, double depth, std::vector<Quad> 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<Stand> 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<Face> faces, roof; std::vector<Quad> quads; std::string before, after; Vec centre, crane_at; std::vector<Face> 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<const char *, 4> 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<std::array<double, 3>, 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 += "<ellipse cx=\"" + num(q.x) + "\" cy=\"" + num(q.y) + "\" rx=\"" + num(worn[2] * unit * 1.1) + "\" ry=\"" + num(worn[2] * unit * .6) + "\" fill=\"#a58f5c\" opacity=\".6\"/>";
}
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<Vec> 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<double, 4>{16, 24, 32, 42}[size_t(lights)];
for (const auto &at : std::array<std::array<double, 2>, 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 += "<circle cx=\"" + num(top.x + (i - (lamps_across - 1) / 2.) * 3.4) + "\" cy=\"" + num(top.y - head_h + 4.2 + j * 3.5) + "\" r=\"1.5\" fill=\"#fff6c9\" stroke=\"" + ink + "\" stroke-width=\".5\"/>";
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) +
"<rect x=\"" + num(top.x - head_w / 2) + "\" y=\"" + num(top.y - head_h) + "\" width=\"" + num(head_w) + "\" height=\"" + num(head_h) + "\" rx=\"2\" fill=\"#5d5648\" stroke=\"" + ink + "\" stroke-width=\".8\"/>" + 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<double, 4>{9, 13, 17, 22}[size_t(board)], bh = std::array<double, 4>{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<double, 5>{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<Quad>{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")) + "<circle cx=\"" + num(s1.x) + "\" cy=\"" + num(s1.y) + "\" r=\"3\" fill=\"#ffffff\" opacity=\".7\"/><circle cx=\"" + num(s2.x + 3) + "\" cy=\"" + num(s2.y) + "\" r=\"4\" fill=\"#ffffff\" opacity=\".5\"/>");
}
{
const int comfort = grade(5); BoxLook look;
look.top = std::array<const char *, 4>{"#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<const char *, 4>{"#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 = "<circle cx=\"" + num(clock.x) + "\" cy=\"" + num(clock.y) + "\" r=\"3.4\" fill=\"#fbf7ee\" stroke=\"" + std::string(ink) + "\" stroke-width=\".8\"/>";
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<double, 5>{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<const char *, 7> 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")) + "<rect x=\"" + num(q.x - 6) + "\" y=\"" + num(q.y - 6) + "\" width=\"12\" height=\"12\" rx=\"2.5\" fill=\"#2f5f9e\" stroke=\"#ffffff\" stroke-width=\"1.2\"/><text x=\"" + num(q.x) + "\" y=\"" +
num(q.y + 4.2) + "\" text-anchor=\"middle\" font-family=\"" + lettering + "\" font-size=\"11\" fill=\"#ffffff\">P</text>";
}
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<Face> &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<Quad>{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 += "<circle cx=\"" + num(q.x) + "\" cy=\"" + num(q.y) + "\" r=\"5\" fill=\"" + (int(x) % 16 > 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<std::array<double, 2>, 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<const char *, 4> 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 += "<path d=\"M" + num(q.x) + " " + num(q.y) + "v-3.2\" stroke=\"" + coats[size_t(crowd.between(0, 3))] + "\" stroke-width=\"1.5\" stroke-linecap=\"round\"/><circle cx=\"" + num(q.x) + "\" cy=\"" + num(q.y - 4.3) + "\" r=\".9\" fill=\"#e8b88f\"/>";
}
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 = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 " + num(width) + " " + num(height) + "\">" + body + "</svg>";
return scene;
}
} // namespace bmh::modern_ui::stadium_scene
+282 -246
View File
@@ -29,291 +29,327 @@ std::string stadium_feedback(const Json &quote,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 "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 "+scalar(w)+" "+scalar(h)+"\">"+body+"</svg>";
// The colours of the six curves of the stadium's data, in the order of the series.
std::array<std::string,6> 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<std::array<double,2>,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<int64_t>(0,places))/double(std::max<int64_t>(1,greatest));}
std::array<double,2> 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<int64_t>());
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="<rect width=\""+scalar(stadium_plan_w)+"\" height=\""+scalar(stadium_plan_h)+"\" fill=\""+ground+"\"/>";
for(double x=46;x<stadium_plan_w;x+=46)body+="<path d=\"M"+scalar(x)+" 0V"+scalar(stadium_plan_h)+"\" stroke=\""+grid+"\" stroke-width=\"2\"/>";
for(double y=46;y<stadium_plan_h;y+=46)body+="<path d=\"M0 "+scalar(y)+"H"+scalar(stadium_plan_w)+"\" stroke=\""+grid+"\" stroke-width=\"2\"/>";
// the pitch inside its track
body+="<ellipse cx=\""+scalar(stadium_plan_w/2)+"\" cy=\""+scalar(stadium_plan_h/2)+"\" rx=\""+scalar(stadium_plan_rx+40)+"\" ry=\""+scalar(stadium_plan_ry+40)+"\" fill=\""+(paper?"#e7dcc0":"#27323c")+"\" stroke=\""+ink+"\" stroke-width=\"3\"/>";
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+="<rect x=\""+scalar(px+stripe*pw/10)+"\" y=\""+scalar(py)+"\" width=\""+scalar(pw/10)+"\" height=\""+scalar(ph)+"\" fill=\""+(stripe%2?"#4f9a5c":"#57a765")+"\"/>";
body+="<g fill=\"none\" stroke=\"#f4f7ef\" stroke-width=\"4\"><rect x=\""+scalar(px)+"\" y=\""+scalar(py)+"\" width=\""+scalar(pw)+"\" height=\""+scalar(ph)+"\"/><path d=\"M"+scalar(px+pw/2)+" "+scalar(py)+"V"+scalar(py+ph)+"\"/><circle cx=\""+scalar(px+pw/2)+"\" cy=\""+scalar(py+ph/2)+"\" r=\"46\"/>"
"<rect x=\""+scalar(px)+"\" y=\""+scalar(py+ph/2-80)+"\" width=\"74\" height=\"160\"/><rect x=\""+scalar(px+pw-74)+"\" y=\""+scalar(py+ph/2-80)+"\" width=\"74\" height=\"160\"/></g>";
for(size_t i=0;i<8&&i<blocks.size();++i) {
const auto &b=blocks[i];const double from=stadium_plan_spans[i][0]+1.4,to=stadium_plan_spans[i][1]-1.4;
const double inner=48,built=inner+stadium_plan_depth(b.at("display_places").get<int64_t>(),greatest),most=inner+stadium_plan_depth(b.at("max_places").get<int64_t>(),greatest);
const bool seats=b.at("display_seats").get<bool>(),roofed=b.at("display_roof").get<bool>(),building=b.at("building").get<bool>();
// how far the stand may grow
body+="<path d=\""+ring(from,to,inner,most)+"\" fill=\"none\" stroke=\""+ink+"\" stroke-opacity=\".4\" stroke-width=\"3\" stroke-dasharray=\"14 10\"/>";
body+="<path d=\""+ring(from,to,inner,built)+"\" fill=\""+(seats?club_colour:terrace)+"\" stroke=\""+ink+"\" stroke-width=\"4\" stroke-linejoin=\"round\"/>";
// rows of seats run along the stand, the steps of a terrace across it
if(seats)for(double depth=inner+22;depth<built-8;depth+=22){std::string d;for(double a=from+1;a<=to-1+.01;a+=2.5){const auto p=stadium_plan_point(a,depth);d+=(d.empty()?"M":"L")+scalar(p[0])+" "+scalar(p[1]);}body+="<path d=\""+d+"\" fill=\"none\" stroke=\"#ffffff\" stroke-opacity=\".42\" stroke-width=\"3\"/>";}
else for(double a=from+4;a<to-1;a+=5){const auto p=stadium_plan_point(a,inner+6),q=stadium_plan_point(a,built-6);body+="<path d=\"M"+scalar(p[0])+" "+scalar(p[1])+"L"+scalar(q[0])+" "+scalar(q[1])+"\" stroke=\""+ink+"\" stroke-opacity=\".3\" stroke-width=\"3\"/>";}
if(roofed) {
const double edge=built-(built-inner)*.42;
body+="<path d=\""+ring(from,to,edge,built+10)+"\" fill=\""+roof+"\" fill-opacity=\".9\" stroke=\""+ink+"\" stroke-width=\"4\" stroke-linejoin=\"round\"/>";
for(double a=from+5;a<to-1;a+=10){const auto p=stadium_plan_point(a,edge),q=stadium_plan_point(a,built+10);body+="<path d=\"M"+scalar(p[0])+" "+scalar(p[1])+"L"+scalar(q[0])+" "+scalar(q[1])+"\" stroke=\"#ffffff\" stroke-opacity=\".35\" stroke-width=\"3\"/>";}
}
if(building) {
const double target=inner+stadium_plan_depth(b.at("job").value("places",b.at("display_places").get<int64_t>()),greatest);
body+="<path d=\""+ring(from,to,inner,std::max(built,target))+"\" fill=\""+gold+"\" fill-opacity=\".18\" stroke=\""+gold+"\" stroke-width=\"7\" stroke-dasharray=\"22 12\"/>";
// 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<std::pair<std::string,std::vector<std::array<double,2>>>> &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="<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 "+scalar(w)+" "+scalar(h)+"\"><path d=\"M"+scalar(left)+" "+scalar(top)+"V"+scalar(h-bottom)+"H"+scalar(w-right)+"\" fill=\"none\" stroke=\""+rule+"\" stroke-opacity=\".45\" stroke-width=\"3\"/>";
for(const double part:{.25,.5,.75})svg+="<path d=\"M"+scalar(left)+" "+scalar(top+(h-top-bottom)*part)+"H"+scalar(w-right)+"\" fill=\"none\" stroke=\""+rule+"\" stroke-opacity=\".16\" stroke-width=\"2\" stroke-dasharray=\"10 12\"/>";
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+="<circle cx=\""+scalar(x)+"\" cy=\""+scalar(y)+"\" r=\"7\" fill=\""+colour+"\"/>";
}
if(points.size()>1)svg+="<polyline fill=\"none\" stroke=\""+colour+"\" stroke-width=\"5.5\" stroke-linejoin=\"round\" stroke-linecap=\"round\" points=\""+line+"\"/>";
svg+=dots;
}
return stadium_svg(body,stadium_plan_w,stadium_plan_h);
return svg+"</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("<path d=\""+std::string(path)+"\" fill=\"none\" stroke=\""+color+"\" stroke-width=\"1.7\" stroke-linecap=\"round\" stroke-linejoin=\"round\" opacity=\""+(built?"1":".32")+"\"/>",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<const char*,4> tones{"#cfc7b6","#d9a05e","#c8733c","#8c491a"};
std::string svg="<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 120 70\"><rect width=\"120\" height=\"70\" rx=\"12\" fill=\"#eaf0dc\"/>";
for(int i=0;i<=std::clamp(level,0,3);++i)svg+="<rect x=\""+scalar(22+i*20)+"\" y=\""+scalar(44-i*9)+"\" width=\"16\" height=\""+scalar(14+i*9)+"\" rx=\"2\" fill=\""+tones[size_t(i)]+"\" stroke=\"#3a332b\" stroke-width=\"1\"/>";
return svg+"<path d=\"M10 58h100\" stroke=\"#3a332b\" stroke-width=\"1.2\"/></svg>";
}
std::string stadium_graph_svg(const Json &curves,bool relative,const std::string &theme) {
constexpr std::array<const char*,6> colors{"#8fbaa6","#8cacc9","#adb7c1","#cf9088","#c5b384","#729aae"};
std::array<std::array<double,24>,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<double,6> 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="<path d=\"M50 20V590H3570\" fill=\"none\" stroke=\""+divider+"\" stroke-width=\"2\"/>";
for(double x:{.25,.5,.75})svg+="<path d=\"M55 "+scalar(570-x*530)+"H3570\" fill=\"none\" stroke=\""+divider+"\" stroke-width=\"2\" stroke-dasharray=\"12 16\"/>";
for(size_t k=0;k<6;++k)if(curves[k].get<bool>()) {
const double scale=relative?*std::max_element(values[k].begin(),values[k].end()):maximum;
svg+="<polyline fill=\"none\" stroke=\""+std::string(colors[k])+"\" stroke-width=\"6\" points=\"";
for(size_t i=0;i<24;++i)svg+=scalar(70+i*3460.0/23)+","+scalar(570-values[k][i]/scale*530)+" ";
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 "<div class=\"pg-kv\"><span>"+key+"</span><strong"+(id.empty()?std::string():" id=\""+id+"\"")+">"+value+"</strong></div>";
}
} // 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<double,3> 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<double,3> &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<bool>();
const auto overview=stadium_overview(future);const auto club=overview.value("club",std::string());
if(!overview.value("ok",false))return "<p class=\"stadium-empty\">Die Stadionvorschau ist derzeit nicht verfügbar.</p>";
const auto overview=stadium_overview(future);
if(!overview.value("ok",false))return "<div class=\"pg-page\"><div class=\"pg-empty\"><span>Die Stadionvorschau ist derzeit nicht verfügbar.</span></div></div>";
if(engine_mode_)engine_stadium_value_=overview;
const auto view=stadium_view_.at("view").get<std::string>();
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+="<text x=\""+scalar(w*(x+rw/2))+"\" y=\""+scalar(dy+natural_h*(y+rh/2))+"\" dominant-baseline=\"central\" text-anchor=\"middle\" font-family=\"monospace\" font-size=\"33\" letter-spacing=\"4\" fill=\""+color+"\">2 : 1</text>";
}
if(((i==2||i==3)&&level<2)||(i==5&&level==1)) {
const std::string color=theme_=="silver"?"#a23f45":theme_=="matchday"?"#f0a6a7":"#df8c80";
body+="<g transform=\"translate("+scalar((w-100)/2)+" "+scalar(dy+(natural_h-100)/2)+")\"><path d=\"M14 14L86 86M86 14L14 86\" stroke=\""+color+"\" stroke-width=\"9\" fill=\"none\"/></g>";
}
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<n;++k)body+="<g transform=\"translate("+scalar((w-(n*52+(n-1)*8))/2+k*60)+" "+scalar(dy+(natural_h-52)/2)+") scale("+scalar(52.0/48)+")\"><path d=\"m24 3 6 13 15 2-11 11 3 15-13-7-13 7 3-15L3 18l15-2Z\" fill=\""+color+"\"/></g>";
}
if(body.empty())return std::string();
return "<span class=\"stadium-art-overlay\" style=\""+rect(0,0,w,viewport_h)+"\">"+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)+"</span>";
const bool outer=view=="panorama";
const auto ground=overview.at("name").get<std::string>();
page_title_=outer?"Peripherie – "+ground:ground+" – "+number(overview.at("capacity").get<int64_t>())+" 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<std::string>()+" · "+row.at("name").get<std::string>():row.at("name").get<std::string>();
};
std::string out="<div class=\"stadium-screen"+std::string()+"\" id=\"stadium-underlay\">";
out+="<header class=\"stadium-heading\"><div class=\"stadium-heading-copy\"><h2>"+esc(overview.at("name").get<std::string>())+"</h2><p>"+(view=="inside"?"Stadion · ein Bauteil anklicken":view=="panorama"?"Umfeld · ein Gebäude anklicken":"Stadiondaten")+"</p></div><div class=\"stadium-summary\"><div><span>"+(future?"Geplante Kapazität":"Verfügbare Kapazität")+std::string("</span><strong>")+number(overview.at("capacity").get<int64_t>())+" <small>Plätze</small></strong></div><div><span>"+std::string(engine_mode_?"Vereinskasse":"Ausbaubudget")+"</span><strong class=\""+std::string(engine_mode_?money_classes(overview.at("budget").get<int64_t>()):"")+"\">"+esc(stadium_cash(overview.at("budget")))+"</strong></div></div></header>";
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+="<div class=\"stadium-model\" id=\"stadium-model\"><div id=\"stadium-model-art\">"+picture(renderer_.diagram("stadium-model",drawing.svg,3580),mw,mh)+"</div>";
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<std::string>();
if(id.starts_with("facility:"))return overview.at("facilities")[index].at("name").get<std::string>();
return overview.at("periphery")[index].at("name").get<std::string>();
};
// 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<bool>();
state=number(b.at("display_places").get<int64_t>())+" von "+number(b.at("max_places").get<int64_t>())+" Plätzen · "+(b.at("display_seats").get<bool>()?"Sitzplätze":"Stehplätze")+(b.at("display_roof").get<bool>()?" · Dach":"");
} else if(id.starts_with("facility:")) {
const auto &f=overview.at("facilities")[index];busy=f.at("building").get<bool>();
state=f.at("display_label").get<std::string>();
} else {
const auto &p=overview.at("periphery")[index];busy=p.at("building").get<bool>();
const int level=p.at("level").get<int>(),most=p.at("max_level").get<int>();
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 "<span class=\"stadium-tip\" style=\"left:"+scalar(left)+"dp;top:"+scalar(top)+"dp;\"><strong>"+esc(name_of(id))+"</strong><span>"+esc(state)+"</span></span>";
};
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<std::string,int> 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.x<reach||anchor.y<reach||anchor.x>mw-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<bool>();};
// 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<bool>()?b.at("places").get<int64_t>():b.at("display_places").get<int64_t>();};
// 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<int64_t>())+" Plätzen · "+(row.at("display_seats").get<bool>()?"Sitzplätze":"Stehplätze")+(row.at("display_roof").get<bool>()?" · Dach":"");
else if(id.starts_with("facility:"))state=row.at("display_label").get<std::string>();
else {
const int level=row.value("display_level",row.at("level").get<int>()),most=row.at("max_level").get<int>();
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+="<span class=\"stadium-model-tag"+std::string(letter?" letter":"")+(part.id==stadium_focus_?" chosen":"")+"\" style=\"left:"+scalar(part.cx)+"dp;top:"+scalar(part.cy+(letter?0:reach*.62))+"dp;\"><span>"+esc(letter?overview.at("blocks")[size_t(std::stoul(part.id.substr(6)))].at("letter").get<std::string>():name_of(part.id))+"</span></span>";
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="<section class=\"pg-page\" id=\"stadium-underlay\"><div class=\"sd-stage\" id=\"stadium-stage\"><button data-action=\"stadium-pick\" class=\"sd-ground\" id=\"stadium-model-ground\" tabindex=\"-1\" aria-label=\"Stadionmodell\"></button>"
"<div class=\"sd-world\" id=\"stadium-world\" style=\""+stadium_cam_style(cam)+"\"><div id=\"stadium-model-art\">"+picture(renderer_.diagram("stadium-scene",scene.svg,4096),2799,1512)+"</div>";
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+="<button data-action=\"stadium-focus\" class=\"sd-hot"+std::string(part.id==stadium_focus_?" sel":"")+(part.id==stadium_hover_?" hover":"")+"\" id=\"stadium-part-"+token+"\" data-id=\""+esc(part.id)+"\" data-tip-name=\""+esc(name)+"\" data-tip-state=\""+esc(state)+"\" aria-label=\""+esc(name+": "+state)+"\">";
if(part.id==stadium_hover_)tip="<strong>"+esc(name)+"</strong><span>"+esc(state)+"</span>";
for(size_t q=0;q<part.quads.size();++q) {
// a face of the model is a parallelogram on the picture: a square laid onto it
const auto a=stadium_scene::project(part.quads[q].a),b=stadium_scene::project(part.quads[q].b),d=stadium_scene::project(part.quads[q].d);
out+="<span class=\"sd-q\""+(q?std::string():" id=\"stadium-face-"+token+"\"")+" style=\"left:"+pg(a.x)+";top:"+pg(a.y)+";transform:matrix("+scalar((b.x-a.x)*.0225)+","+scalar((b.y-a.y)*.0225)+","+scalar((d.x-a.x)*.0225)+","+scalar((d.y-a.y)*.0225)+",0,0);\"></span>";
}
out+="</button>";
}
if(!outer)for(const auto &letter:scene.letters)out+="<span class=\"sd-letter\" style=\"left:"+pg(letter.at.x-9.5)+";top:"+pg(letter.at.y-9.5)+";\">"+esc(letter.text)+"</span>";
out+="</div>";
// the equipment by name, for what is small on the model
if(!outer) {
out+="<div class=\"sd-chips\">";
for(size_t i=0;i<overview.at("facilities").size();++i) {
const auto &f=overview.at("facilities")[i];const auto id="facility:"+std::to_string(i);
out+=pg_button("stadium-focus","<span>"+esc(f.at("name").get<std::string>())+"</span><span class=\"pg-mut\">· "+esc(f.at("display_label").get<std::string>())+(working(f)?" · im Bau":"")+"</span>",std::string("sd-chip")+(stadium_focus_==id?" on":""),"id=\"stadium-chip-"+std::to_string(i)+"\" data-id=\""+id+"\"");
}
out+="</div>";
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 "<div class=\"bank-fact\"><span>"+k+"</span><strong>"+v+"</strong></div>";};
if(stadium_focus_.starts_with("block:")) {
const auto &b=overview.at("blocks")[index];busy=b.at("building").get<bool>();action="stadium-block";
const int64_t places=b.at("display_places").get<int64_t>(),most=b.at("max_places").get<int64_t>();
facts=fact("Plätze",number(places)+" von "+number(most))+"<div class=\"bank-part-track\"><div style=\"width:"+scalar(std::clamp(places*100.0/double(std::max<int64_t>(1,most)),0.0,100.0))+"%;\"></div></div>"+
fact("Sitzplätze",b.at("display_seats").get<bool>()?"ja":"nein, Stehplätze")+fact("Dach",b.at("display_roof").get<bool>()?"ja":"nein");
if(busy)facts+=fact("Im Bau",number(b.at("job").at("places").get<int64_t>())+" Plätze · noch "+std::to_string(b.at("job").at("weeks").get<int>())+" Wochen");
full=places>=most&&b.at("display_seats").get<bool>()&&b.at("display_roof").get<bool>();
} else if(stadium_focus_.starts_with("facility:")) {
const auto &f=overview.at("facilities")[index];busy=f.at("building").get<bool>();action="stadium-facility";
facts=fact("Zustand",esc(f.at("display_label").get<std::string>()));
if(busy)facts+=fact("Im Bau","noch "+std::to_string(f.at("job").at("weeks").get<int>())+" 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<bool>();action="stadium-periphery";
const int level=p.at("level").get<int>(),most=p.at("max_level").get<int>();
facts=fact("Ausbaustufe",std::to_string(level)+" von "+std::to_string(most));
std::string pips="<div class=\"stadium-card-pips\">";for(int k=0;k<most;++k)pips+=k<level?"<div class=\"pip on\"></div>":"<div class=\"pip\"></div>";
facts+=pips+"</div>";
if(busy)facts+=fact("Im Bau","noch "+std::to_string(p.at("job").at("weeks").get<int>())+" 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+="<aside class=\"stadium-card\" id=\"stadium-card\" style=\"left:"+scalar(chosen_x>mw/2?32.0:mw-32-800)+"dp;\"><h3>"+esc(name_of(stadium_focus_))+"</h3>"+facts+
"<p class=\"stadium-card-note\">"+std::string(busy?"Hier wird gebaut.":full?"Hier ist alles ausgebaut.":"Preis und Bauzeit nennt das Angebot der Baufirma.")+"</p>"+
btn(action,label,"primary stadium-card-build","id=\"stadium-card-build\" data-id=\""+std::to_string(index)+"\" "+(busy||full?"disabled=\"disabled\"":""))+
btn("stadium-focus","Zurück","stadium-card-back","id=\"stadium-card-back\" data-id=\"\"")+"</aside>";
}
} 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<bool>(),theme_);
out+="<div class=\"stadium-graph\"><div class=\"stadium-graph-art\">"+picture(renderer_.diagram("stadium-graph",graph,7200),2560,456)+"</div></div>";
constexpr std::array<const char*,6> 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","<span class=\"stadium-curve-color\" style=\"background-color:"+std::string(colors[i])+";\"></span><span class=\"stadium-curve-label\">"+names[i]+"</span>","stadium-curve","id=\"stadium-curve-"+std::to_string(i)+"\" data-id=\""+std::to_string(i)+"\" aria-pressed=\""+(stadium_view_.at("curves")[i].get<bool>()?"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>()==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<std::string> 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<std::array<std::string,4>,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+="<div class=\"stadium-data-table\">";
for(size_t i=0;i<6;++i){out+="<div class=\"stadium-data-row "+std::string(i==0?"head":i%2?"striped":"")+"\">";for(size_t k=0;k<4;++k)out+="<div class=\"stadium-data-cell "+std::string(k?"":"first")+"\"><span>"+esc(rows[i][k])+"</span></div>";out+="</div>";}out+="</div>";
const int ticket=snapshot.state.at("ticket").get<int>();
out+="<p class=\"stadium-required\"><span>Benötigter Zuschauerschnitt bei "+esc(cash(ticket))+" Eintritt: </span><span class=\"stadium-required-value\">"+(ticket?number((94000+ticket-1)/ticket):"–")+"</span></p><div class=\"stadium-ticket\"><strong>Eintritt:</strong>";
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+="</div>";
}
}
out+="<nav class=\"stadium-nav\">";
if(view=="panorama") {
out+=btn("stadium-back","Zum Stadion","stadium-nav-button half","id=\"stadium-back\"");
out+=btn("stadium-future","Zukunft","stadium-nav-button half","id=\"stadium-future\" aria-pressed=\""+std::string(future?"true":"false")+"\"");
if(!stadium_focus_.empty()) {
// the part's card: what stands there today, and the way to the offer
const auto &row=row_of(stadium_focus_);const auto index=index_of(stadium_focus_);
const bool busy=row.at("building").get<bool>();bool full=false;
std::string body,action,verb="Ausbauen",kind;
if(stadium_focus_.starts_with("block:")) {
kind="Tribüne";action="stadium-block";
const int64_t places=places_of(row),most=row.at("max_places").get<int64_t>();
body=stadium_kv("Plätze",number(places)+" von "+number(most))+pg_bar(places*100.0/double(std::max<int64_t>(1,most)),"accent")+stadium_kv("Sitzplätze",row.at("display_seats").get<bool>()?"ja":"nein · Stehplätze")+stadium_kv("Dach",row.at("display_roof").get<bool>()?"ja":"nein");
full=row.at("places").get<int64_t>()>=most&&row.at("seats").get<bool>()&&row.at("roof").get<bool>();
} else if(stadium_focus_.starts_with("facility:")) {
kind="Ausstattung";action="stadium-facility";
const bool condition=index>=4;const int level=row.value("display_level",row.at("level").get<int>()),most=row.at("max_level").get<int>();
body=stadium_kv(condition?"Zustand":"Ausbaustufe",esc(row.at("display_label").get<std::string>()))+"<div class=\"pg-row\" style=\"justify-content:space-between;\"><span class=\"pg-mut\">"+(condition?std::string():"Stufe "+std::to_string(level)+" von "+std::to_string(most))+"</span>"+pg_dots(level,most)+"</div>";
if(condition)verb="Erneuern";
full=row.value("available",true)!=true||row.at("level").get<int>()>=most;
} else {
kind="Peripherie";action="stadium-periphery";
const int level=row.value("display_level",row.at("level").get<int>()),most=row.at("max_level").get<int>();
static constexpr std::array<const char*,4> links{"Straße","Bushaltestelle","Tram","Bahnhof"};
std::string reach;
for(int i=0;i<level&&i<4;++i)reach+=(i?", ":"")+std::string(links[size_t(i)]);
body=stadium_kv("Ausbaustufe",level<=0?"noch nicht gebaut":most>1?std::to_string(level)+" von "+std::to_string(most):"gebaut")+(index==0&&!reach.empty()?stadium_kv("Anbindung",reach):std::string())+"<div class=\"pg-row\" style=\"justify-content:flex-end;\">"+pg_dots(level,most)+"</div>";
full=row.at("level").get<int>()>=most;
}
std::string job;
if(busy) {
const auto &work=row.at("job");
job="<span class=\"pg-tag accent\" style=\"align-self:flex-start;\">Im Bau"+(stadium_focus_.starts_with("block:")?" auf "+number(work.at("places").get<int64_t>())+" Plätze":std::string())+" · noch "+std::to_string(work.at("weeks").get<int>())+(stadium_focus_.starts_with("periphery:")&&engine_mode_?" Tage":" Wochen")+"</span>";
}
out+="<aside class=\"pg-panel pg-col sd-card\" id=\"stadium-card\"><div>"+pg_kicker(kind)+"<h3 class=\"pg-h\" style=\"font-size:"+pg(22)+";line-height:"+pg(27)+";\">"+esc(name_of(stadium_focus_))+"</h3></div>"+body+job+
"<span class=\"pg-mut\" style=\"display:block;font-size:"+pg(12.5)+";\">"+std::string(busy?"Hier wird gebaut.":full?"Hier ist alles ausgebaut.":"Preis und Bauzeit nennt das Angebot der Baufirma.")+"</span><div class=\"pg-row\" style=\"justify-content:flex-end;"+pg_css("gap:8px;")+"\">"+
pg_button("stadium-focus","Zurück","","id=\"stadium-card-back\" data-id=\"\"")+pg_button(action,verb,"primary","id=\"stadium-card-build\" data-id=\""+std::to_string(index)+"\" "+(busy||full?"disabled=\"disabled\"":""))+"</div></aside>";
}
else if(view=="data")out+=btn("stadium-back","Zurück zum Stadion","stadium-nav-button wide","id=\"stadium-back\"");
stadium_tip_=tip.empty()?std::string():stadium_tip_;
out+="<div class=\"sd-tip\" id=\"stadium-tip\""+(tip.empty()?std::string():" style=\"display:block;left:"+pg(stadium_tip_at_[0])+";top:"+pg(stadium_tip_at_[1])+";\"")+">"+tip+"</div></div><nav class=\"pg-foot\" aria-label=\"Ansicht des Stadions\">";
if(outer)out+=pg_button("stadium-future","Zukunft",future?"on":"","id=\"stadium-future\" aria-pressed=\""+std::string(future?"true":"false")+"\"");
else {
out+=btn("stadium-view",view=="inside"?"Zum Umfeld":"Zum Stadion","stadium-nav-button","id=\"stadium-view\"");
out+=view=="inside"?btn("stadium-future",std::string("Ausbau: ")+(future?"Zukunft":"Aktuell"),"stadium-nav-button","id=\"stadium-future\" aria-pressed=\""+std::string(future?"true":"false")+"\""):"<button class=\"stadium-nav-button control-button\" disabled=\"disabled\"><span class=\"control-label\">Peripherie bauen</span></button>";
out+=btn("stadium-data","Stadion-Daten","stadium-nav-button","id=\"stadium-data\"");
out+="<span class=\"pg-mut\">Ausbau:</span><div class=\"pg-seg\">";
for(int i=0;i<2;++i) {
const bool on=bool(i)==future;
out+=btn("stadium-future","<span>"+std::string(i?"Zukunft":"Aktuell")+"</span>",std::string(i?"":"first ")+(on?"on":""),on?std::string("style=\"pointer-events:none;\" aria-pressed=\"true\""):std::string("id=\"stadium-future\" aria-pressed=\"false\""));
}
out+="</div>"+pg_button("stadium-data","Stadion-Daten","","id=\"stadium-data\"");
}
return out+"</nav></div>"+render_stadium_dialog();
out+=pg_button("stadium-reset","Ansicht zurücksetzen","","id=\"stadium-reset\"")+"<span class=\"pg-sp\"></span>"+pg_status("Mausrad zoomt · Ziehen verschiebt die Ansicht");
return out+"</nav></section>"+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<bool>();
std::array<std::string,6> names{"Zuschauer","Eintritt","Stadionwert","Zus. Stadion-Einnahmen","Einnahmen","Stadionkosten"};
std::vector<std::pair<std::string,std::vector<std::array<double,2>>>> series;
std::vector<std::array<std::string,4>> 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<std::array<double,2>> 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<double>()-13.)/298.,(point[1].get<double>()-18.)/83.});
series.emplace_back(colours[i],std::move(points));
}
static constexpr std::array<const char*,5> 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<std::string,4> 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>();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]+="<span class=\"pg-mut sd-sub\">"+esc(day)+"</span>";
if(row<=1)if(const auto other=data.at("table")[source+1][col].get<std::string>();!other.empty())cells[col+1]+="<span class=\"pg-mut sd-sub\">"+esc(other)+"</span>";
}
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<std::string>();
} else {
// the demo's invented season
std::array<std::array<double,24>,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<double,6> 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<std::array<double,2>> 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<std::string> 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+"<span class=\"pg-mut sd-sub\">"+esc(others.size()>other?others[other]:"—")+"</span>";};
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<int>();low=0;high=25;
needed=ticket?number((94000+ticket-1)/ticket):"–";
}
const auto unit=engine_mode_?std::string("€"):money_unit();
std::string out="<section class=\"pg-page\" id=\"stadium-underlay\"><div class=\"pg-row pg-grow\" style=\"align-items:stretch;\"><div class=\"pg-col pg-grow\"><div class=\"pg-panel pg-col pg-grow\" style=\""+pg_css("gap:8px;")+"\"><div class=\"pg-row\" style=\"flex-wrap:wrap;"+pg_css("gap:6px;")+"\">";
for(size_t i=0;i<6;++i)
out+=pg_button("stadium-curve","<span class=\"sd-mark\" style=\"background-color:"+colours[i]+";\"></span><span>"+esc(names[i])+"</span>",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+="<span class=\"pg-sp\"></span><div class=\"pg-seg\">";
for(int i=0;i<2;++i)out+=btn("stadium-scale","<span>"+std::string(i?"Relativ":"Absolut")+"</span>",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+="</div></div>"+(series.empty()?std::string("<div class=\"pg-empty\"><span>Keine Kurve eingeblendet.</span></div>"):"<div class=\"sd-chart\" role=\"img\" aria-label=\"Stadiondaten der Heimspiele\">"+picture(renderer_.diagram("stadium-chart-"+theme_,stadium_chart_svg(series,theme_),2700),1800,1030)+"</div>")+"</div>";
// the ticket price: a button for every price the game allows
out+="<div class=\"pg-panel\"><div class=\"pg-row\" style=\"margin-bottom:"+pg(8)+";"+pg_css("gap:10px;")+"\">"+pg_kicker("Eintritt:")+"<strong class=\"pg-h\">"+std::to_string(ticket)+" "+esc(unit)+"</strong><span class=\"pg-mut\" id=\"stadium-required\">Benötigter Zuschauerschnitt bei "+std::to_string(ticket)+" "+esc(unit)+" Eintritt: <strong>"+esc(needed)+"</strong></span></div><div class=\"sd-prices\">";
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+="</div></div></div><div class=\"pg-panel sd-table\" role=\"table\"><div class=\"sd-row head\" role=\"row\"><span class=\"sd-cell first\"></span>";
for(const auto *competition:{"Liga","DFB-Pokal","Europapokal"})out+="<span class=\"sd-cell\" role=\"columnheader\">"+esc(pg_upper(competition))+"</span>";
out+="</div>";
for(const auto &row:rows) {
out+="<div class=\"sd-row\" role=\"row\"><span class=\"sd-cell first\" role=\"rowheader\">"+esc(row[0])+"</span>";
for(size_t col=1;col<4;++col)out+="<div class=\"sd-cell\" role=\"cell\"><span>"+row[col]+"</span></div>";
out+="</div>";
}
out+="</div></div><nav class=\"pg-foot\">"+pg_button("stadium-back","Zurück zum Stadion","","id=\"stadium-back\"")+"<span class=\"pg-sp\"></span>"+pg_status("Ein Preisknopf ändert den Eintritt nach Rückfrage.");
return out+"</nav></section>";
}
// 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<int>();
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<int>();
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 "<div class=\"stadium-modal\" id=\"stadium-modal\"><section class=\"stadium-draft\" id=\"stadium-draft\" role=\"dialog\" style=\""+rect(226,650,2160,480)+"\"><h2>"+esc(row.at("name").get<std::string>())+" ausbauen</h2><p>"+esc(engine_busy_?"Angebot wird geladen …":stadium_view_.value("feedback",std::string("Kein gültiges Angebot verfügbar.")))+"</p><nav class=\"stadium-draft-actions\" style=\"top:300dp;\">"+btn("stadium-cancel","Abbrechen","stadium-dialog-action","id=\"stadium-cancel\"")+"</nav></section></div>";
const bool renew=!block&&!periphery&&index>=4;
const auto title=block?"Block "+row.at("letter").get<std::string>()+" ausbauen":row.at("name").get<std::string>()+(renew?" erneuern":" ausbauen");
const auto open=[&](double width){return "<div class=\"pg-ov\" id=\"stadium-modal\"><section class=\"pg-dlg\" id=\"stadium-draft\" role=\"dialog\" aria-modal=\"true\" aria-labelledby=\"stadium-draft-title\" style=\"width:"+pg(width)+";\"><div><h2 id=\"stadium-draft-title\">"+esc(title)+"</h2></div>";};
if(engine_mode_&&!q.value("ok",false))
return open(480)+"<p>"+esc(engine_busy_?"Angebot wird geladen …":stadium_view_.value("feedback",std::string("Kein gültiges Angebot verfügbar.")))+"</p><nav class=\"pg-dlg-act\">"+pg_button("stadium-cancel","Abbrechen","","id=\"stadium-cancel\"")+"</nav></section></div>";
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<bool>();
std::string out=open(block||periphery?480:560);
if(periphery) {
const int level=d.at("level").get<int>();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<std::string>())));
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<std::string>();const auto &meta=config.at("assets").at(asset);const double height=800.0*meta.at("height").get<double>()/meta.at("width").get<double>();
preview="<span class=\"stadium-periphery-preview\" style=\""+rect(680,174,800,height)+"\">"+img("stadium.scene."+asset,800,height,false,false,1600)+"</span>";
const auto asset=binding.at("asset").get<std::string>();const auto &meta=config.at("assets").at(asset);const double tall=std::min(260.0,400.0*meta.at("height").get<double>()/meta.at("width").get<double>());
preview="<span class=\"sd-preview\" style=\"width:400dp;height:"+scalar(tall)+"dp;\">"+img("stadium.scene."+asset,400,tall,false,false,1200)+"</span>";
} catch(const std::exception &) {}
const auto title=row.at("name").get<std::string>();
return "<div class=\"stadium-modal\" id=\"stadium-modal\"><section class=\"stadium-draft\" id=\"stadium-draft\" role=\"dialog\" aria-modal=\"true\" aria-labelledby=\"stadium-draft-title\" style=\""+rect(226,377,2160,1110)+"\"><h2 id=\"stadium-draft-title\">"+esc(title)+" ausbauen</h2><div class=\"stadium-draft-summary\"><span>"+(row.at("level")==0?"Neubau":"Erweiterung")+" · Stufe "+std::to_string(level)+"</span><span>Bauzeit: "+std::to_string(q.value("weeks",0))+" Wochen</span></div>"+preview+"<div class=\"stadium-draft-total\" style=\"top:758dp;\"><span>Gesamtbetrag:</span><span id=\"stadium-quote-total\">"+esc(stadium_cash(stadium_field(q,"cost")))+"</span></div><p id=\"stadium-draft-feedback\" style=\"top:850dp;\">"+esc(stadium_offer_feedback(q,false))+"</p><nav class=\"stadium-draft-actions\" style=\"top:946dp;\">"+btn("stadium-build","Bauen","stadium-dialog-action primary","id=\"stadium-build\" "+std::string(q.value("can_build",false)?"":"disabled=\"disabled\""))+btn("stadium-cancel","Abbrechen","stadium-dialog-action","id=\"stadium-cancel\"")+"</nav></section></div>";
}
struct Option {int level;Picture art;double height;};std::vector<Option> options;double option_h=0;
if(!block)for(int level=row.at("level").get<int>()+1;level<=row.at("max_level").get<int>();++level){if(engine_mode_&&std::none_of(q.at("options").begin(),q.at("options").end(),[&](const auto &option){return option.at("level")==level;}))continue;const auto a=renderer_.image("stadium.facility."+std::to_string(index)+".level."+std::to_string(level),false,2048);const double h=a.width?592.0*a.height/a.width:325;options.push_back({level,a,h});option_h=std::max(option_h,h+159);}
const double height=block?982.5:option_h+499,total_top=block?687.5:option_h+204,feedback_top=block?776.5:option_h+293,actions_top=block?854.5:option_h+371;
const auto title=block?"Block "+row.at("letter").get<std::string>()+" · "+row.at("name").get<std::string>():row.at("name").get<std::string>();
std::string out="<div class=\"stadium-modal\" id=\"stadium-modal\"><section class=\"stadium-draft\" id=\"stadium-draft\" role=\"dialog\" aria-modal=\"true\" aria-labelledby=\"stadium-draft-title\" style=\""+rect(226,(1864-height)/2,2160,height)+"\"><h2 id=\"stadium-draft-title\">"+esc(title)+" ausbauen</h2><div class=\"stadium-draft-summary\"><span>"+std::string(engine_mode_?"Vereinskasse: ":"POC-Budget: ")+esc(stadium_cash(overview.at("budget")))+"</span><span>Bauzeit: "+std::to_string(q.value("weeks",row.at("weeks").get<int>()))+" Wochen</span></div>";
if(block) {
out+="<section class=\"stadium-place-field\"><strong>Block "+row.at("letter").get<std::string>()+"</strong><p>Aktuell: "+number(row.at("places").get<int64_t>())+" Plätze</p><span class=\"stadium-place-label\"><span>Neue Gesamtplätze</span></span>"+btn("stadium-places-editor",std::to_string(d.at("places").get<int64_t>()),"stadium-place-number amount-trigger","id=\"stadium-place-number\"")+"<input type=\"range\" id=\"stadium-place-range\" min=\""+std::to_string(row.at("places").get<int>())+"\" max=\""+std::to_string(row.at("max_places").get<int>())+"\" step=\"1000\" value=\""+std::to_string(d.at("places").get<int>())+"\" aria-label=\"Neue Gesamtplätze\"/></section><div class=\"stadium-features\">";
if(preview.empty())preview="<span class=\"sd-preview\">"+picture(renderer_.diagram("stadium-stage-"+std::to_string(row.at("level").get<int>()),stadium_stage_svg(row.at("level").get<int>()),480),270,157.5)+"</span>";
static constexpr std::array<const char*,4> links{"Straße","Bushaltestelle","Tram","Bahnhof"};
out+="<div class=\"pg-row\" style=\""+pg_css("gap:16px;")+"\">"+preview+"<div class=\"pg-grow\">"+stadium_kv("Art",row.at("level")==0?"Neubau":"Erweiterung · Stufe "+std::to_string(level))+(index==0&&level>=1&&level<=4?stadium_kv("Neu",links[size_t(level-1)]):std::string())+weeks+cash+"</div></div>";
} else if(block) {
const auto places=d.at("places").get<int64_t>(),now=row.at("places").get<int64_t>(),most=row.at("max_places").get<int64_t>();
out+="<div>"+cash+weeks+stadium_kv("Aktuell",number(now)+" Plätze")+"</div><div class=\"pg-panel pg-col\" style=\""+pg_css("gap:10px;")+"\"><div class=\"pg-row\" style=\"justify-content:space-between;\">"+pg_kicker("Neue Gesamtplätze")+
pg_button("stadium-places-editor",number(places),"sd-number amount-trigger","id=\"stadium-place-number\"")+"</div><input type=\"range\" class=\"sd-range\" id=\"stadium-place-range\" min=\""+std::to_string(now)+"\" max=\""+std::to_string(most)+"\" step=\"1000\" value=\""+std::to_string(places)+"\" aria-label=\"Neue Gesamtplätze\"/>"+
"<div class=\"pg-row pg-mut\" style=\"justify-content:space-between;font-size:"+pg(12)+";\"><span>"+number(now)+"</span><span>Ausbaugrenze "+number(most)+"</span></div><div class=\"pg-row\" style=\""+pg_css("gap:22px;")+"\">";
const std::array<const char*,2> features{"seats","roof"},labels{"Sitzplätze","Überdachung"};
for(size_t i=0;i<2;++i){const bool built=row.at(features[i]).get<bool>();const bool checked=d.at(features[i]).get<bool>();out+="<label class=\"stadium-feature-row\"><input type=\"checkbox\" id=\"stadium-feature-"+std::string(features[i])+"\" data-stadium-feature=\""+features[i]+"\" "+(checked?"checked=\"checked\" ":"")+(built?"disabled=\"disabled\" ":"")+"/><span class=\"stadium-feature-image\" id=\"stadium-feature-image-"+std::string(features[i])+"\">"+picture(renderer_.diagram("stadium-feature-"+std::string(features[i])+(checked?"-built-":"-empty-")+theme_,stadium_feature_svg(features[i],checked,theme_),232),116,116)+"</span><span>"+labels[i]+"</span></label>";}
out+="</div><dl class=\"stadium-costs\">";
for(size_t i=0;i<2;++i)
out+="<label class=\"sd-check\"><input type=\"checkbox\" id=\"stadium-feature-"+std::string(features[i])+"\" data-stadium-feature=\""+features[i]+"\" "+(d.at(features[i]).get<bool>()?"checked=\"checked\" ":"")+(row.at(features[i]).get<bool>()?"disabled=\"disabled\" ":"")+"/><span>"+labels[i]+"</span></label>";
out+="</div></div><div>";
const std::array<const char*,3> keys{"placesCost","seatsCost","roofCost"},names{"Neue Plätze","Sitzplätze","Überdachung"};
for(size_t i=0;i<3;++i)out+="<div class=\"stadium-cost-row\" style=\"top:"+scalar(i*51.5)+"dp;\"><dt>"+std::string(names[i])+"</dt><dd id=\"stadium-cost-"+keys[i]+"\">"+esc(stadium_cash(stadium_field(q,keys[i])))+"</dd></div>";
out+="</dl>";
for(size_t i=0;i<3;++i)out+=stadium_kv(names[i],esc(stadium_cash(stadium_field(q,keys[i]))),"stadium-cost-"+std::string(keys[i]));
out+="</div>";
} else {
const double total=options.size()*640+(options.size()-1)*28,left=52+(2052-total)/2;
for(size_t i=0;i<options.size();++i) {
const auto &o=options[i];const bool selected=d.at("level")==o.level;const double group_offset=(option_h-o.height-159)/2;
// Facility options share the same source cells; overlays are rendered at the natural art size.
std::string art=picture(o.art,592,o.height);
if(index==1) {
const double x=o.level==1?.28:o.level==3?.13:o.level==4?.12:.10,y=o.level==3?.24:o.level==4?.63:.30,rw=o.level==1?.40:o.level==3?.72:o.level==4?.74:.60,rh=o.level==1?.28:o.level==3?.24:o.level==4?.18:.45;
const std::string color=o.level==2?"#ff593e":theme_=="silver"?(o.level==4?"#233443":"#805b18"):theme_=="matchday"?(o.level==4?"#efeded":"#e1c68b"):o.level==3?"#dfdc67":"#d9e8ef";
const auto svg=stadium_svg("<text x=\"50%\" y=\"50%\" text-anchor=\"middle\" dominant-baseline=\"central\" font-family=\"monospace\" font-size=\"33\" letter-spacing=\"4\" fill=\""+color+"\">2 : 1</text>",592*rw,o.height*rh);
art+="<span class=\"stadium-art-overlay\" style=\""+rect(592*x,o.height*y,592*rw,o.height*rh)+"\">"+picture(renderer_.diagram("stadium-option-score-"+std::to_string(o.level)+"-"+theme_,svg,1536),592*rw,o.height*rh)+"</span>";
}
if(index==5){const std::string color=theme_=="silver"?"#805b18":theme_=="matchday"?"#e1c68b":"#e0c99b";const auto svg=stadium_svg("<path d=\"m24 3 6 13 15 2-11 11 3 15-13-7-13 7 3-15L3 18l15-2Z\" fill=\""+color+"\"/>",48,48);const int n=o.level-1;for(int j=0;j<n;++j)art+="<span class=\"stadium-art-overlay\" style=\""+rect((592-(n*52+(n-1)*8))/2+j*60,(o.height-52)/2,52,52)+"\">"+picture(renderer_.diagram("stadium-option-star-"+theme_,svg,104),52,52)+"</span>";}
out+=btn("stadium-option","<span class=\"stadium-option-art\" style=\"height:"+scalar(o.height)+"dp;top:"+scalar(22+group_offset)+"dp;\">"+art+"</span><strong style=\"top:"+scalar(22+o.height+20+group_offset)+"dp;\">"+esc(row.at("levels")[size_t(o.level)].get<std::string>())+"</strong><span class=\"stadium-option-price\" style=\"top:"+scalar(22+o.height+20+37+20+group_offset)+"dp;\">"+esc(stadium_cash(engine_mode_?[&]()->Json{for(const auto &option:q.at("options"))if(option.at("level")==o.level)return option.at("cost");return Json();}():Json(int64_t(o.level-row.at("level").get<int>())*row.at("rate").get<int64_t>())))+"</span>","stadium-option","id=\"stadium-option-"+std::to_string(o.level)+"\" data-id=\""+std::to_string(o.level)+"\" aria-pressed=\""+(selected?"true":"false")+"\" style=\""+rect(left+i*668,174,640,option_h)+"\"");
// one card for every stage that can be ordered
struct Option {int level;Json cost;};std::vector<Option> options;
for(int level=row.at("level").get<int>()+1;level<=row.at("max_level").get<int>();++level) {
Json cost;
if(engine_mode_) {
const auto found=std::find_if(q.at("options").begin(),q.at("options").end(),[&](const auto &option){return option.at("level")==level;});
if(found==q.at("options").end())continue;
cost=found->at("cost");
} else cost=int64_t(level-row.at("level").get<int>())*row.at("rate").get<int64_t>();
options.push_back({level,cost});
}
out+="<div>"+cash+weeks+"</div><div class=\"pg-row\" style=\"align-items:stretch;"+pg_css("gap:8px;")+"\">";
const double room=std::min(200.0,(516-8.0*double(std::max<size_t>(1,options.size())-1))/double(std::max<size_t>(1,options.size()))-30);
for(const auto &option:options) {
const bool chosen=d.at("level")==option.level;
// the game's own picture of the stage where the graphics pack has one
const auto art=renderer_.image("stadium.facility."+std::to_string(index)+".level."+std::to_string(option.level),false,1024);
const double wide=room*2.25,tall=art.width>1?std::min(wide*.62,wide*art.height/art.width):wide*70/120;
out+=btn("stadium-option","<span class=\"sd-option-art\" style=\"width:"+scalar(wide)+"dp;height:"+scalar(tall)+"dp;\">"+(art.width>1?picture(art,wide,tall):picture(renderer_.diagram("stadium-stage-"+std::to_string(option.level-1),stadium_stage_svg(option.level-1),480),wide,tall))+"</span><strong class=\"pg-h\" style=\"font-size:"+pg(16)+";\">"+
esc(row.at("levels")[size_t(option.level)].get<std::string>())+"</strong><span class=\"pg-mut\">"+esc(stadium_cash(option.cost))+"</span>",std::string("pg-card sd-option")+(chosen?" sel":""),"id=\"stadium-option-"+std::to_string(option.level)+"\" data-id=\""+std::to_string(option.level)+"\" aria-pressed=\""+(chosen?"true":"false")+"\"");
}
out+="</div>";
}
const auto custom=stadium_view_.at("feedback").get<std::string>();const auto feedback=custom.empty()?stadium_offer_feedback(q,stadium_view_.at("invalid_places").get<bool>()):custom;
out+="<div class=\"stadium-draft-total\" style=\"top:"+scalar(total_top)+"dp;\"><span>Gesamtbetrag:</span><span id=\"stadium-quote-total\">"+esc(stadium_cash(stadium_field(q,"cost")))+"</span></div><p id=\"stadium-draft-feedback\" style=\"top:"+scalar(feedback_top)+"dp;\">"+esc(feedback)+"</p><nav class=\"stadium-draft-actions\" style=\"top:"+scalar(actions_top)+"dp;\">"+btn("stadium-build","Bauen","stadium-dialog-action primary","id=\"stadium-build\" "+std::string(!q.value("can_build",false)||stadium_view_.at("invalid_places").get<bool>()?"disabled=\"disabled\"":""))+btn("stadium-cancel","Abbrechen","stadium-dialog-action","id=\"stadium-cancel\"")+"</nav></section></div>";
const auto custom=stadium_view_.at("feedback").get<std::string>();const auto feedback=custom.empty()?stadium_offer_feedback(q,invalid):custom;
out+="<div class=\"pg-panel pg-row\" style=\"justify-content:space-between;\">"+pg_kicker("Gesamtbetrag:")+"<strong class=\"pg-big\" id=\"stadium-quote-total\">"+esc(stadium_cash(stadium_field(q,"cost")))+"</strong></div><span class=\"pg-status sd-feedback\" id=\"stadium-draft-feedback\" role=\"status\">"+esc(feedback)+"</span><nav class=\"pg-dlg-act\">"+
pg_button("stadium-cancel","Abbrechen","","id=\"stadium-cancel\"")+pg_button("stadium-build","Bauen","primary","id=\"stadium-build\" "+std::string(!q.value("can_build",false)||invalid?"disabled=\"disabled\"":""))+"</nav></section></div>";
return out;
}
+14 -8
View File
@@ -39,7 +39,7 @@
#include "modern/ui/settings_presentation.hpp"
#include "modern/ui/ui_preferences.hpp"
#include "modern/ui/desktop.hpp"
#include "modern/ui/stadium_model.hpp"
#include "modern/ui/stadium_scene.hpp"
#include "modern/ui/demo_widgets.hpp"
#include "modern/ui/demo_files.hpp"
#include "modern/ui/gui_assets.hpp"
@@ -507,11 +507,18 @@ class App final : public Rml::EventListener {
// the stadium's card model: what the camera looks at ("" the whole ground, "stadium", or a
// part such as "block:3"), and its flight from one focus to the next
std::string stadium_focus_;
stadium3d::Camera stadium_camera_, stadium_camera_from_, stadium_camera_to_;
bool stadium_flying_ = false;
uint64_t stadium_flight_start_ = 0;
// how each view of the model is looked at: zoom and the place of the picture's corner
std::map<std::string, std::array<double, 3>> stadium_cams_;
Json stadium_drag_; // the pointer while the view is dragged
bool stadium_dragged_ = false; // the next click only ends a drag
std::string stadium_tip_, stadium_hover_; // what the pointer is on
std::array<double, 2> stadium_tip_at_{}; // where its name is shown, in units of the page
std::vector<stadium_scene::Hot> stadium_hots_; // the parts of the view that is shown
std::array<double, 3> stadium_cam(bool outer);
std::string stadium_cam_style(const std::array<double, 3> &cam);
bool stadium_stage_event(Rml::Event &);
std::string render_stadium_data();
bool stadium_focus_action(const std::string &, Rml::Element *);
void stadium_camera_tick();
uint64_t stadium_revision_ = 0;
std::shared_ptr<const Catalog> stadium_world_;
const DataSource *stadium_source_ = nullptr;
@@ -797,7 +804,7 @@ class App final : public Rml::EventListener {
statistics_view_ = Json::object(); statistics_trophy_ = Json::object();
statistics_scrolls_ = Json::object();
reset_news();
stadium_view_ = Json::object(); stadium_revision_ = 0; stadium_focus_.clear(); stadium_flying_ = false;
stadium_view_ = Json::object(); stadium_revision_ = 0; stadium_focus_.clear(); stadium_drag_ = Json();
stadium_world_.reset(); stadium_source_ = nullptr;
advertising_selected_ = -1; advertising_offer_ = 0; advertising_revision_ = 0; advertising_world_.reset();
toto_column_ = 0; toto_dialog_.clear();
@@ -1326,7 +1333,6 @@ class App final : public Rml::EventListener {
void frame() {
engine_create_poll();
engine_files_poll();
stadium_camera_tick();
if (engine_mode_) { engine_frame(); return; }
front_poll();
flush_selects();
@@ -1589,7 +1595,7 @@ public:
doc_->AddEventListener(event, &select_capture_, true);
for (const char *event :
{"click", "dblclick", "change", "input", "keydown", "blur", "mousedown",
"mouseup", "mousemove", "contextmenu", "focus"})
"mouseup", "mousemove", "contextmenu", "focus", "mousescroll"})
doc_->AddEventListener(event, this, Rml::String(event) == "keydown" ||
Rml::String(event) == "blur" || Rml::String(event) == "focus");
try {
+24 -27
View File
@@ -4,7 +4,7 @@
#include "modern/ui/demo_reports.hpp"
#include "modern/ui/demo_finance.hpp"
#include "modern/ui/desktop.hpp"
#include "modern/ui/stadium_model.hpp"
#include "modern/ui/stadium_scene.hpp"
#include "modern/ui/gui_assets.hpp"
#include "modern/ui/model.hpp"
#include "modern/ui/crest_contrast.hpp"
@@ -544,34 +544,31 @@ int main(int argc, char **argv) try {
{
Json overview = {{"blocks", Json::array()}, {"facilities", Json::array()}, {"periphery", Json::array()}};
for (int i = 0; i < 8; ++i)
overview["blocks"].push_back({{"letter", std::string(1, char('A' + i))}, {"display_places", 3000 + 1000 * i}, {"max_places", 18000},
{"display_seats", i % 2 == 0}, {"display_roof", i == 3}, {"building", i == 5}, {"job", {{"places", 9000}, {"weeks", 12}}}});
for (int i = 0; i < 8; ++i) overview["facilities"].push_back({{"name", "Anlage"}, {"display_level", 2}, {"building", false}});
for (int i = 0; i < 14; ++i) overview["periphery"].push_back({{"name", "Haus"}, {"level", i % 3}, {"max_level", 3}, {"building", false}});
const auto scene = stadium3d::build(overview, "#aa2233", true);
require(scene.centres.contains("block:7") && scene.centres.contains("facility:0") && !scene.centres.contains("periphery:0"),
"The stadium's view should offer stands and facilities only");
const auto inside = stadium3d::fixed_camera(false);
const auto whole = stadium3d::draw(scene, inside, 2612, 1600);
const auto again = stadium3d::draw(stadium3d::build(overview, "#aa2233", true), inside, 2612, 1600);
require(whole.svg == again.svg && whole.svg.size() > 4000, "Stadium model is not drawn the same way twice");
require(std::count_if(whole.anchors.begin(), whole.anchors.end(), [](const auto &a) { return a.id == "facility:0"; }) == 4,
"Each floodlight mast should choose the floodlights");
for (const auto &part : whole.parts)
if (part.id.starts_with("block:"))
require(part.cx > 100 && part.cx < 2512 && part.cy > 100 && part.cy < 1500, "A stand lies outside the fixed camera's picture");
// the surroundings: every object is a part of its own, and every level draws more
const auto around = stadium3d::build(overview, "#aa2233", true, 1);
require(around.centres.size() == 14 && around.centres.contains("periphery:13") && !around.centres.contains("block:0"),
"The surroundings should offer their fourteen objects only");
overview["blocks"].push_back({{"letter", std::string(1, char('A' + i))}, {"places", 3000 + 1000 * i}, {"display_places", i == 5 ? 0 : 3000 + 1000 * i}, {"max_places", i % 2 ? 6000 : 18000},
{"display_seats", i % 2 == 0}, {"display_roof", i == 2}, {"building", i == 5}, {"job", {{"places", 9000}, {"weeks", 12}}}});
for (int i = 0; i < 8; ++i) overview["facilities"].push_back({{"name", "Anlage"}, {"level", 2}, {"display_level", 2}, {"max_level", 4}, {"building", false}});
for (int i = 0; i < 14; ++i) overview["periphery"].push_back({{"name", "Haus"}, {"level", 0}, {"max_level", i == 0 ? 4 : 1}, {"building", false}});
const auto scene = stadium_scene::build(overview, false, "ARENA");
require(scene.svg == stadium_scene::build(overview, false, "ARENA").svg && scene.svg.size() > 20000 && scene.svg.ends_with("</svg>"), "Stadium model is not drawn the same way twice");
const auto part = [&](const std::string &id) { return std::find_if(scene.hots.begin(), scene.hots.end(), [&](const auto &h) { return h.id == id; }); };
for (int i = 0; i < 8; ++i) require(part("block:" + std::to_string(i)) != scene.hots.end() && part("facility:" + std::to_string(i)) != scene.hots.end(), "A stand or a facility cannot be chosen on the model");
for (int i = 0; i < 14; ++i) require(part("periphery:" + std::to_string(i)) != scene.hots.end(), "An object of the surroundings cannot be chosen on the model");
require(part("facility:0")->quads.size() == 4, "Each floodlight mast should choose the floodlights");
require(scene.letters.size() == 8 && scene.letters[0].text == "A", "The stands should carry their letters");
// every face one can choose lies on the picture
for (const auto &hot : scene.hots)
for (const auto &quad : hot.quads)
for (const auto &corner : {quad.a, quad.b, quad.d}) {
const auto p = stadium_scene::project(corner);
require(p.x > 0 && p.x < stadium_scene::width && p.y > 0 && p.y < stadium_scene::height, "A part of the stadium lies outside the picture");
}
// what is built shows more than an empty plot, and a finished stand more than a building site
auto grown = overview;
grown["periphery"][0]["level"] = 4;
grown["periphery"][4]["level"] = 3;
require(stadium3d::build(grown, "#aa2233", true, 1).faces.size() > around.faces.size() + 20,
"Higher levels of road and parking should show more");
const auto outside = stadium3d::draw(around, stadium3d::fixed_camera(true), 2612, 1600);
for (const auto &anchor : outside.anchors)
require(anchor.x > 40 && anchor.x < 2572 && anchor.y > 40 && anchor.y < 1560, "An object of the surroundings lies outside the picture");
grown["periphery"][4]["level"] = 1;
grown["periphery"][3]["level"] = 1;
require(stadium_scene::build(grown, false, "ARENA").svg.size() > scene.svg.size() + 4000, "Built surroundings should show more than their plots");
require(scene.svg.find("#d08a1e") != std::string::npos && stadium_scene::build(overview, true, "ARENA").svg.find("#d08a1e") == std::string::npos, "A crane should stand only where building is going on today");
}
auto corrupt = layout;
corrupt["objects"]["calendar"]["x"] = 999999;