diff --git a/.gitignore b/.gitignore index a8f2bc3..7e399b5 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,6 @@ __pycache__/ .DS_Store /assets/menu/ + +# the user's design mock-up (not part of the distribution) +NewUIMockup/ diff --git a/assets/modern/modern.rml b/assets/modern/modern.rml index b6ac566..2989e74 100644 --- a/assets/modern/modern.rml +++ b/assets/modern/modern.rml @@ -1,6 +1,6 @@ Dreierpack Manager - +
diff --git a/assets/modern/notebook.rcss b/assets/modern/notebook.rcss new file mode 100644 index 0000000..0b52bb8 --- /dev/null +++ b/assets/modern/notebook.rcss @@ -0,0 +1,271 @@ +/* SPDX-License-Identifier: GPL-3.0-only */ +/* The career's notebook: a leather-bound book on a wooden table. Markers at the left choose a + category, markers at the top a page. Lengths follow the design at 2.25 dp per unit; the + book is 1406 x 866 units at (150, 62). A career menu is a sheet of the book (.nb-sheet). */ +.nb-table {position:absolute;left:0;top:0;width:3840dp;overflow:hidden;} +.nb-table-light {position:absolute;left:0;top:0;width:3840dp;decorator:radial-gradient(ellipse at 42% 36%,#f6a06b3d 0%,#f6a06b00 48%,#402310d1 100%);} +.nb-book {position:absolute;left:0;width:3840dp;height:2160dp;} +.nb-cover-shadow {position:absolute;left:336dp;top:140dp;width:3281dp;height:2066dp;border-radius:90dp;background-color:#2e2b2580;} +.nb-cover {position:absolute;left:297dp;top:81dp;width:3281dp;height:2070dp;border-radius:68dp 86dp 77dp 63dp;overflow:hidden;transform:rotate(-0.25deg);} +.nb-cover-tone {position:absolute;left:0;top:0;width:3281dp;height:2070dp;decorator:linear-gradient(105deg,#8c491a70 0%,#64331280 30%,#402310b0 100%);} +.nb-seam {position:absolute;left:20dp;top:20dp;width:3240dp;height:2030dp;} +.nb-ribbon {position:absolute;left:2488dp;top:2002dp;width:45dp;height:216dp;transform:rotate(3deg);} +.nb-stack {position:absolute;border-radius:50dp 58dp 68dp 50dp;} +.nb-stack.s4 {left:349dp;top:160dp;width:3181dp;height:1962dp;background-color:#c0b6a5;transform:rotate(0.35deg);} +.nb-stack.s3 {left:346dp;top:155dp;width:3177dp;height:1960dp;background-color:#dcd3c4;transform:rotate(-0.2deg);} +.nb-stack.s2 {left:344dp;top:151dp;width:3172dp;height:1957dp;background-color:#eee7db;transform:rotate(0.25deg);} +.nb-stack.s1 {left:342dp;top:146dp;width:3170dp;height:1955dp;background-color:#dcd3c4;transform:rotate(-0.1deg);} +.nb-stack.s0 {left:340dp;top:144dp;width:3166dp;height:1951dp;background-color:#eee7db;} +.nb-paper {position:absolute;left:337.5dp;top:139.5dp;width:3163.5dp;height:1948.5dp;border-radius:45dp 58dp 68dp 50dp;overflow:hidden;background-color:#f9f4ed;} +.nb-paper-edge {position:absolute;left:0;top:0;width:3163.5dp;height:1948.5dp;decorator:linear-gradient(100deg,#dcd3c48c 0%,#dcd3c400 6%,#dcd3c400 90%,#dcd3c48c 100%);} +.nb-paper-art {position:absolute;left:0;top:0;width:3163.5dp;height:1948.5dp;opacity:.26;} +.nb-paper-lines {position:absolute;left:0;top:0;width:3163.5dp;height:1948.5dp;} +.nb-corner {position:absolute;left:3030.75dp;top:1815.75dp;width:139.5dp;height:139.5dp;} + +/* markers: a coloured face with a sheen, the name on a label */ +.nb-tab,.nb-tab:hover,.nb-tab:disabled {position:absolute;left:49.5dp;width:369dp;height:156dp;padding:0 0 0 13dp;border:0dp;border-radius:36dp 9dp 9dp 36dp;background-color:transparent;decorator:none;display:flex;align-items:center;justify-content:flex-start;transition:transform 0.2s cubic-out;color:#2e2b25;} +.nb-tab-face {display:block;position:absolute;left:0;top:0;width:369dp;height:156dp;border-radius:34dp 7dp 9dp 38dp;border-bottom:4dp #2e2b2538;decorator:linear-gradient(180deg,#f9f4ed6b 0%,#f9f4ed00 42%,#2e2b2524 100%);} +.nb-tab:hover .nb-tab-face {decorator:linear-gradient(180deg,#f9f4ed99 0%,#f9f4ed26 42%,#2e2b2514 100%);} +.nb-tab-label {display:block;position:relative;padding:7dp 22dp;border-radius:40dp;font-family:Display;font-size:34dp;line-height:44dp;white-space:nowrap;color:#2e2b25;} +.nb-tab.active .nb-tab-label {background-color:#f9f4ed;} +.nb-tab:disabled {opacity:.5;} +.nb-subs {position:absolute;left:589.5dp;top:31.5dp;height:162dp;display:flex;align-items:flex-start;gap:20dp;} +.nb-sub,.nb-sub:hover,.nb-sub:disabled {position:relative;height:162dp;padding:13.5dp 36dp 0 22.5dp;border:0dp;border-radius:36dp 36dp 9dp 9dp;background-color:transparent;decorator:none;display:flex;align-items:flex-start;transition:transform 0.2s cubic-out;color:#2e2b25;} +.nb-sub-face {display:block;position:absolute;left:0;top:0;right:0;bottom:0;border-radius:34dp 38dp 9dp 7dp;decorator:linear-gradient(180deg,#f9f4ed6b 0%,#f9f4ed00 42%,#2e2b2524 100%);} +.nb-sub:hover .nb-sub-face {decorator:linear-gradient(180deg,#f9f4ed99 0%,#f9f4ed26 42%,#2e2b2514 100%);} +.nb-sub:disabled {opacity:.45;} +.nb-sub-number {display:block;position:relative;width:63dp;height:63dp;line-height:63dp;border-radius:32dp;margin-right:20dp;text-align:center;font-family:Display;font-size:36dp;background-color:#f9f4ed;color:#201e1d;} +.nb-sub.active .nb-sub-number {background-color:#c67139;color:#f9f4ed;} +.nb-sub-label {display:block;position:relative;height:63dp;line-height:63dp;font-size:32dp;font-weight:bold;white-space:nowrap;} +.tone-a2 {background-color:#ffe1d0;} .tone-a3 {background-color:#ffc6a5;} .tone-a4 {background-color:#f6a06b;} .tone-a5 {background-color:#d67f48;} +.tone-s2 {background-color:#e1eecc;} .tone-s3 {background-color:#ccdbb2;} .tone-s4 {background-color:#aebf92;} .tone-s5 {background-color:#8fa073;} +.tone-n3 {background-color:#dcd3c4;} + +/* the head of the page */ +.nb-heading {position:absolute;left:558dp;top:212dp;height:150dp;color:#201e1d;} +.nb-heading small {display:block;font-size:25dp;line-height:32dp;font-weight:bold;color:#8c491a;text-transform:uppercase;letter-spacing:3dp;} +.nb-heading strong {display:block;font-family:Display;font-size:90dp;line-height:100dp;font-weight:normal;} +.nb-head {position:absolute;left:1900dp;top:222dp;width:1457dp;height:140dp;color:#201e1d;} +.nb-head-date {display:block;height:56dp;line-height:56dp;text-align:right;font-family:Display;font-size:38dp;} +.nb-head-tags {display:flex;justify-content:flex-end;gap:14dp;margin-top:12dp;} +.nb-tag {display:block;padding:5dp 22dp;border-radius:30dp;font-size:27dp;line-height:40dp;font-weight:bold;white-space:nowrap;background-color:#e1eecc;color:#3d472b;} +.nb-tag.terra {background-color:#ffe1d0;color:#643312;} +.nb-tag.plain {background-color:#eee7db;color:#474238;} + +/* a paper clip, a pencil in its loop, the whistle */ +.nb-clip {position:absolute;left:2677dp;top:85dp;width:68dp;height:162dp;transform:rotate(8deg);pointer-events:none;} +.nb-pencil {position:absolute;left:3595dp;top:589dp;width:36dp;height:968dp;transform:rotate(-1.2deg);pointer-events:none;} +.nb-loop {position:absolute;left:3573dp;top:994dp;width:72dp;height:122dp;border-radius:14dp 22dp 22dp 14dp;decorator:linear-gradient(90deg,#2e2b25 0%,#645c50 55%,#2e2b25 100%);pointer-events:none;} +.nb-whistle,.nb-whistle:hover,.nb-whistle:disabled {position:absolute;left:3523dp;top:1824dp;width:648dp;height:377dp;padding:0;border:0dp;background-color:transparent;decorator:none;display:block;transform-origin:432dp 331dp;transform:rotate(-12deg);transition:transform 0.16s cubic-out;} +.nb-whistle:hover {transform:rotate(-19deg) scale(1.08);} +.nb-whistle:disabled {opacity:.5;} +.nb-whistle-art {display:block;width:648dp;height:377dp;} + +/* a career menu in its old format, as a sheet of the book: the old window, a little smaller */ +.nb-sheet-layer {position:absolute;left:0;width:3840dp;height:2160dp;} +.window.nb-sheet {left:644dp;top:73dp;border:0dp;border-radius:0dp;decorator:none;background-color:transparent;backdrop-filter:none;box-shadow:none;transform-origin:0dp 0dp;transform:scale(0.966);} +.window.nb-sheet.window-in {animation:none;} +.nb-sheet .titlebar {display:none;} +.nb-book.legacy .nb-heading,.nb-book.legacy .nb-head {display:none;} +.menu-layer {pointer-events:none;} +.menu-layer>* {pointer-events:auto;} +.menu-layer>.nb-sheet-layer {pointer-events:none;} +.menu-layer>.nb-sheet-layer>* {pointer-events:auto;} + +/* the home page: cards on a grid of 8 x 5 */ +.nb-home {position:absolute;left:558dp;width:2799dp;height:1620dp;} +.hw {position:absolute;border-radius:68dp;background-color:#ebddc5;border-bottom:3dp #2e2b2524;padding:31dp 36dp;display:flex;flex-direction:column;overflow:hidden;color:#201e1d;} +.hw.flat {padding:25dp 36dp;} +.hw.one {padding:20dp 22dp;align-items:center;} +.hw.link:hover {background-color:#efe3cd;} +.hw-kicker {display:block;flex-shrink:0;height:34dp;line-height:34dp;margin-bottom:16dp;font-size:25dp;font-weight:bold;letter-spacing:2.5dp;text-transform:uppercase;color:#8c491a;white-space:nowrap;overflow:hidden;} +.hw.flat .hw-kicker,.hw.one .hw-kicker {margin-bottom:10dp;} +.hw-big {display:flex;flex-shrink:0;align-items:flex-end;margin-bottom:16dp;} +.hw-big strong {display:block;font-family:Display;font-weight:normal;white-space:nowrap;} +.hw-big span {display:block;margin-left:16dp;font-size:28dp;line-height:36dp;color:#474238;white-space:nowrap;} +.hw-tag {display:block;flex-shrink:0;align-self:flex-start;padding:5dp 22dp;margin-bottom:16dp;border-radius:30dp;font-size:26dp;line-height:38dp;font-weight:bold;white-space:nowrap;background-color:#e1eecc;color:#3d472b;} +.hw-tag.terra {background-color:#ffe1d0;color:#643312;} +.hw-lines {display:block;flex-shrink:0;} +.hw-line {display:flex;justify-content:space-between;height:58dp;line-height:56dp;font-size:29dp;border-bottom:2dp #c0b6a5;} +.hw-line span {display:block;white-space:nowrap;overflow:hidden;} +.hw-line strong {display:block;margin-left:20dp;white-space:nowrap;} +.hw-foot {display:block;flex-shrink:0;margin-top:auto;height:38dp;line-height:38dp;font-size:26dp;color:#474238;white-space:nowrap;overflow:hidden;} +.hw-items {display:block;flex-shrink:0;} +.hw-item {display:block;padding:16dp 29dp;margin-bottom:13dp;border-radius:40dp;background-color:#f9f4ed;} +.hw-item.unread {background-color:#fff2eb;} +.hw-item-top {display:flex;justify-content:space-between;height:38dp;line-height:38dp;} +.hw-item-top strong {display:block;font-size:28dp;white-space:nowrap;} +.hw-item-top small {display:block;font-size:25dp;color:#645c50;white-space:nowrap;} +.hw-item-text {display:block;height:38dp;line-height:38dp;font-size:28dp;color:#474238;white-space:nowrap;overflow:hidden;} +.hw-chips {display:flex;flex-shrink:0;gap:13dp;margin-bottom:14dp;} +.hw-chip {display:block;text-align:center;font-family:Display;font-size:31dp;border-radius:60dp;background-color:#c0b6a5;color:#2e2b25;} +.hw-chip.form-S {background-color:#728157;color:#f9f4ed;} +.hw-chip.form-N {background-color:#8c491a;color:#f9f4ed;} +.hw-lamps {display:flex;flex-wrap:wrap;flex:1;align-content:center;} +.hw-lamp {display:flex;align-items:center;width:50%;height:62dp;} +.hw-lamps.row .hw-lamp {width:20%;justify-content:center;height:70dp;} +.hw-lamp-dot {display:block;flex-shrink:0;border-radius:40dp;border:4dp #f9f4ed;decorator:radial-gradient(circle at 35% 30%,#ccdbb2 0%,#8fa073 55%,#56633f 100%);} +.hw-lamp.alert .hw-lamp-dot {decorator:radial-gradient(circle at 35% 30%,#d67f48 0%,#8c491a 55%,#402310 100%);} +.hw-lamp.unknown .hw-lamp-dot {border-color:#a19786;decorator:radial-gradient(circle at 35% 30%,#eee7db 0%,#c0b6a5 55%,#82796a 100%);} +.hw-lamp-text {display:block;margin-left:20dp;overflow:hidden;} +.hw-lamp-text strong {display:block;height:34dp;line-height:34dp;font-size:27dp;white-space:nowrap;} +.hw-lamp-text small {display:block;height:30dp;line-height:30dp;font-size:24dp;color:#474238;white-space:nowrap;} +.hw-match {display:flex;flex:1;align-items:center;justify-content:space-around;} +.hw-match-side {display:block;width:36%;text-align:center;} +.hw-match-side strong {display:block;margin-top:16dp;font-family:Display;font-weight:normal;font-size:36dp;line-height:42dp;} +.hw-match-crest {display:flex;justify-content:center;} +.hw-match-mid {display:block;text-align:center;} +.hw-match-mid strong {display:block;font-family:Display;font-weight:normal;font-size:76dp;line-height:80dp;} +.hw-match-mid span {display:block;font-size:30dp;font-weight:bold;line-height:40dp;white-space:nowrap;} +.hw-match-mid .hw-tag {align-self:center;display:inline-block;margin:8dp 0 0 0;} +.hw-img {display:flex;flex:1;align-items:center;justify-content:center;overflow:hidden;} +.hw-img-frame {display:block;overflow:hidden;border-radius:54dp;} +.hw-bars {display:flex;flex:1;align-items:flex-end;gap:13dp;min-height:54dp;margin-bottom:12dp;} +.hw-bars span {display:block;flex:1;border-radius:30dp 30dp 13dp 13dp;background-color:#aebf92;} +.hw-bars span.now {background-color:#728157;} +.hw-step {display:flex;flex-shrink:0;align-items:center;margin-bottom:14dp;} +.hw-step span {display:block;flex:1;font-size:28dp;font-weight:bold;} +.hw-step button,.hw-step button:hover {height:64dp;padding:0 28dp;border:0dp;border-radius:32dp;background-color:#f9f4ed;decorator:none;font-family:Display;font-size:38dp;color:#201e1d;} +.hw-step button:hover {background-color:#fff2eb;} +.hw-chart {display:block;position:relative;flex-shrink:0;} +.hw-chart-label {position:absolute;width:0;height:0;} +.hw-chart-label span {display:block;position:absolute;left:-80dp;top:-22dp;width:160dp;height:44dp;line-height:44dp;text-align:center;white-space:nowrap;font-size:25dp;color:#474238;} +.hw-chart-label.now span {font-family:Display;font-size:38dp;color:#201e1d;text-align:left;left:0;} +.hw-empty {display:flex;flex:1;align-items:center;font-size:28dp;line-height:38dp;color:#645c50;} + +/* dark skins: the same book in other materials */ +body.midnight .nb-table-light {decorator:radial-gradient(ellipse at 42% 36%,#7fa3bd24 0%,#7fa3bd00 48%,#05080cd1 100%);} +body.matchday .nb-table-light {decorator:radial-gradient(ellipse at 42% 36%,#c9584f24 0%,#c9584f00 48%,#080506d1 100%);} +body.midnight .nb-cover-tone {decorator:linear-gradient(105deg,#2a3a4a70 0%,#1a242f80 30%,#0b1016b0 100%);} +body.matchday .nb-cover-tone {decorator:linear-gradient(105deg,#5a262c70 0%,#3a171c80 30%,#1a0a0cb0 100%);} +body.midnight .nb-paper {background-color:#2a3440;} body.matchday .nb-paper {background-color:#302a2c;} +body.midnight .nb-paper-edge,body.matchday .nb-paper-edge {decorator:linear-gradient(100deg,#0000004d 0%,#00000000 6%,#00000000 90%,#0000004d 100%);} +body.midnight .nb-stack.s4,body.midnight .nb-stack.s2,body.midnight .nb-stack.s0 {background-color:#1b232c;} body.midnight .nb-stack.s3,body.midnight .nb-stack.s1 {background-color:#222b35;} +body.matchday .nb-stack.s4,body.matchday .nb-stack.s2,body.matchday .nb-stack.s0 {background-color:#211c1e;} body.matchday .nb-stack.s3,body.matchday .nb-stack.s1 {background-color:#282224;} +body.midnight .nb-heading,body.matchday .nb-heading,body.midnight .nb-head,body.matchday .nb-head {color:#e9eef2;} +body.midnight .nb-heading small {color:#9ac7d8;} body.matchday .nb-heading small {color:#e5a197;} +body.midnight .nb-paper-art,body.matchday .nb-paper-art {opacity:.1;} +body.midnight .hw {background-color:#34404d;color:#e9eef2;} body.matchday .hw {background-color:#3a3235;color:#f1e9ea;} +body.midnight .hw-kicker {color:#9ac7d8;} body.matchday .hw-kicker {color:#e5a197;} +body.midnight .hw-big span,body.midnight .hw-foot,body.midnight .hw-item-text,body.midnight .hw-lamp-text small,body.matchday .hw-big span,body.matchday .hw-foot,body.matchday .hw-item-text,body.matchday .hw-lamp-text small {color:#b9c3cc;} +body.midnight .hw-item,body.matchday .hw-item {background-color:#ffffff14;} body.midnight .hw-line,body.matchday .hw-line {border-bottom-color:#ffffff29;} + +/* corrections after the first look */ +.window.nb-sheet {pointer-events:none;} +.window.nb-sheet>* {pointer-events:auto;} +.hw-step button,.hw-step button:hover {white-space:nowrap;flex-shrink:0;display:block;line-height:64dp;} +.hw-kicker,.nb-heading small {text-transform:none;} +.nb-whistle,.nb-whistle:hover,.nb-whistle:disabled {left:3250dp;top:1690dp;width:810dp;height:471dp;transform-origin:540dp 414dp;} +.nb-whistle-art {width:810dp;height:471dp;} +.nb-whistle,.nb-whistle:hover,.nb-whistle:disabled {left:3345dp;top:1735dp;} + +/* --- The cards, second design: paper notes, a dark match card, a tear-off calendar, lamps on a + dashboard, photographs in white frames. --- */ +#engine-status {display:none;} +.nb-paper-art {opacity:.13;} +.nb-sub.add,.nb-sub.add:hover {padding-right:22.5dp;} +.nb-sub.add .nb-sub-number {margin-right:0;} +.hw {background-color:#f4ead6;border:2dp #dccfb6;border-bottom:4dp #cdbfa3;} +.hw.link:hover {background-color:#f8efdd;} +.hw-row {display:flex;flex:1;align-items:center;} +.hw-row-text {display:block;flex:1;margin-left:28dp;overflow:hidden;} +.hw-centre {display:flex;flex-shrink:0;justify-content:center;margin-bottom:12dp;} +.hw-centre.grow {flex:1;align-items:center;} +.hw-spacer {display:block;flex:1;} +.centre {align-self:center;text-align:center;} +.hw-foot.centre {width:100%;} +/* the match card */ +.hw.hero,.hw.hero.link:hover {border:0dp;background-color:#33241a;decorator:linear-gradient(160deg,#553a28 0%,#2b1d15 100%);color:#f9f4ed;} +.hw.hero .hw-kicker {color:#f6a06b;} +.hw.hero .hw-foot,.hw.hero .hw-big span {color:#d9c9b4;} +.hw.hero .hw-empty {color:#d9c9b4;} +.hw-disc {display:flex;flex-shrink:0;align-items:center;justify-content:center;border-radius:200dp;background-color:#f9f4ed;border:6dp #f6a06b66;} +.hw-versus {display:block;width:124dp;height:124dp;line-height:118dp;margin:0 auto 18dp auto;border-radius:62dp;background-color:#c67139;color:#f9f4ed;font-family:Display;font-size:52dp;text-align:center;} +.hw-match-mid .hw-tag {display:block;align-self:center;margin:0;} +.hw.hero .hw-match-side strong {color:#f9f4ed;font-size:40dp;line-height:46dp;} +/* the calendar */ +.hw.cal {padding-top:104dp;} +.hw.flat.cal {padding-top:92dp;} +.hw-cal-band {position:absolute;left:0;top:0;right:0;height:84dp;padding:0 32dp;display:flex;align-items:center;justify-content:space-between;background-color:#c67139;} +.hw.flat .hw-cal-band {height:72dp;} +.hw-cal-month {display:block;color:#f9f4ed;font-size:28dp;font-weight:bold;letter-spacing:5dp;} +.hw-cal-hole {display:block;width:26dp;height:26dp;border-radius:13dp;background-color:#8c491a;} +.hw-cal-week {display:block;font-size:34dp;line-height:42dp;color:#645c50;} +.hw-cal-day {display:block;font-family:Display;font-weight:normal;color:#201e1d;} +/* the ticket on the cash card */ +.hw-ticket,.hw-ticket:hover {display:flex;flex-shrink:0;align-self:flex-start;height:76dp;padding:0;border:3dp #c67139;border-radius:22dp;background-color:#fff7ee;decorator:none;overflow:hidden;} +.hw-ticket:hover {background-color:#ffe1d0;} +.hw-ticket-stub {display:block;height:70dp;line-height:70dp;padding:0 22dp;background-color:#c67139;color:#f9f4ed;font-size:26dp;font-weight:bold;letter-spacing:2dp;} +.hw-ticket-price {display:block;height:70dp;line-height:70dp;padding:0 28dp;font-family:Display;font-size:38dp;color:#201e1d;white-space:nowrap;} +/* the lamps */ +.hw-dash {display:flex;flex-wrap:wrap;flex:1;align-content:center;padding:14dp 28dp;border-radius:44dp;background-color:#2e2b25;} +.hw-dash .hw-lamp {width:50%;height:66dp;} +.hw-dash.row .hw-lamp {width:20%;height:68dp;justify-content:center;} +.hw-dash .hw-lamp-text strong {color:#f9f4ed;} +.hw-dash .hw-lamp-text small {color:#c0b6a5;} +.hw-lamp-dot {border:4dp #ffffff26;decorator:radial-gradient(circle at 35% 30%,#eaf7cf 0%,#9fc46a 50%,#4f6d2c 100%);} +.hw-lamp.alert .hw-lamp-dot {border-color:#f6a06b99;decorator:radial-gradient(circle at 35% 30%,#ffe0bd 0%,#f08a3c 50%,#a34a12 100%);} +.hw-lamp.unknown .hw-lamp-dot {border-color:#ffffff1a;decorator:radial-gradient(circle at 35% 30%,#82796a 0%,#645c50 55%,#474238 100%);} +/* the inbox */ +.hw-item {display:flex;align-items:center;height:68dp;padding:0 28dp;margin-bottom:12dp;border-radius:34dp;background-color:#fbf6ec;} +.hw-item.unread {background-color:#fff2eb;} +.hw-item-dot {display:block;flex-shrink:0;width:18dp;height:18dp;margin-right:18dp;border-radius:9dp;background-color:#dcd3c4;} +.hw-item.unread .hw-item-dot {background-color:#c67139;} +.hw-item strong {display:block;flex:1;height:40dp;line-height:40dp;font-size:28dp;font-weight:normal;white-space:nowrap;overflow:hidden;} +.hw-item.unread strong {font-weight:bold;} +.hw-item small {display:block;flex-shrink:0;margin-left:20dp;font-size:25dp;color:#645c50;white-space:nowrap;} +/* results, fans, strength, duels */ +.hw-chip-col {display:block;text-align:center;} +.hw-chip-col small {display:block;height:42dp;line-height:42dp;font-size:27dp;font-weight:bold;color:#474238;} +.hw.sage,.hw.sage.link:hover {background-color:#e6efd6;border-color:#c9d8ad;} +.hw-gauge {display:block;position:relative;flex-shrink:0;} +.hw-gauge strong {display:block;position:absolute;left:0;right:0;bottom:0dp;text-align:center;font-family:Display;font-weight:normal;font-size:84dp;line-height:88dp;} +.hw.one .hw-gauge strong {font-size:66dp;line-height:70dp;} +.hw-meter {display:flex;flex-shrink:0;align-items:center;} +.hw-meter span {display:block;margin-right:18dp;font-size:28dp;font-weight:bold;} +.hw-meter-track {display:block;flex:1;height:22dp;border-radius:11dp;background-color:#dcd3c4;overflow:hidden;} +.hw-meter-track div {height:22dp;border-radius:11dp;background-color:#728157;} +.hw-meter-track div.own {background-color:#c67139;} +.hw-meter strong {display:block;margin-left:18dp;font-family:Display;font-weight:normal;font-size:38dp;} +.hw-duels {display:flex;flex:1;align-items:center;justify-content:space-around;} +.hw-duel {display:block;text-align:center;} +.hw-duel strong {display:block;font-family:Display;font-weight:normal;font-size:84dp;line-height:90dp;} +.hw-duel.won strong {color:#56633f;} .hw-duel.lost strong {color:#8c491a;} +.hw-duel small {display:block;font-size:26dp;color:#474238;} +/* photographs */ +.hw.photo,.hw.photo.link:hover {padding:24dp 18dp 8dp 18dp;align-items:center;border:2dp #e2d8c4;border-bottom:5dp #d3c7b0;border-radius:10dp;background-color:#fdfaf3;} +.hw.photo.turn-a {transform:rotate(-2.2deg);} .hw.photo.turn-b {transform:rotate(1.6deg);} .hw.photo.turn-c {transform:rotate(-1.2deg);} +.hw-tape {display:block;position:absolute;left:50%;top:-6dp;width:140dp;height:36dp;margin-left:-70dp;background-color:#e6d49ab8;transform:rotate(-3deg);} +.hw-photo-frame {display:flex;flex-shrink:0;align-items:center;justify-content:center;overflow:hidden;background-color:#eee7db;} +.hw-photo-frame.crest {background-color:#f4efe4;} +.hw-photo-caption {display:block;width:100%;height:44dp;line-height:44dp;margin-top:auto;text-align:center;font-family:Chalk;font-weight:bold;font-size:30dp;color:#474238;white-space:nowrap;overflow:hidden;} +/* the grid while a card moves or a menu is open */ +.hw-cells {display:none;} +.hw-cells.shown {display:block;} +.hw-cell {display:block;position:absolute;border:3dp #c0b6a5;border-radius:58dp;opacity:.55;} +.hw-ghost {display:none;position:absolute;border:5dp #728157;border-radius:68dp;background-color:#f0fae1aa;} +.hw-ghost.shown {display:block;} +.hw-ghost.bad {border-color:#8c491a;background-color:#fff2ebaa;} +.hw-blank {position:absolute;left:0;top:0;width:2799dp;height:1620dp;display:flex;align-items:center;justify-content:center;pointer-events:none;} +.hw-blank span {display:block;padding:20dp 50dp;border-radius:60dp;background-color:#f9f4ed;font-family:Display;font-size:44dp;color:#474238;} +/* menus */ +.hw-menu-back,.hw-menu-back:hover {position:absolute;left:0;top:0;width:3840dp;padding:0;border:0dp;border-radius:0dp;background-color:transparent;decorator:none;z-index:300;} +.hw-menu-back.dim,.hw-menu-back.dim:hover {background-color:#2e2b2566;} +.hw-menu {display:block;position:absolute;width:660dp;padding:22dp;border:3dp #c0b6a5;border-radius:54dp;background-color:#f9f4ed;z-index:310;color:#201e1d;} +.hw-menu-title {display:block;padding:6dp 22dp 14dp 22dp;font-family:Display;font-size:38dp;line-height:48dp;color:#201e1d;} +.hw-menu-item,.hw-menu-item:disabled {display:flex;align-items:center;justify-content:space-between;width:100%;height:72dp;padding:0 22dp;border:0dp;border-radius:28dp;background-color:transparent;decorator:none;font-size:30dp;color:#201e1d;} +.hw-menu-item:hover {background-color:#ffe1d0;decorator:none;border:0dp;} +.hw-menu-item span,.hw-menu-item small {display:block;white-space:nowrap;} +.hw-menu-item small {font-size:26dp;color:#645c50;} +.hw-menu-item.warn {color:#8c491a;} +.hw-menu-item:disabled {opacity:.45;} +.hw-menu-sizes {display:flex;gap:14dp;padding:0 22dp 14dp 22dp;} +.hw-menu-sizes button {height:64dp;padding:0 26dp;border-radius:32dp;font-size:28dp;} +.hw-rename {display:block;position:absolute;left:1470dp;width:900dp;padding:40dp;border:3dp #c0b6a5;border-radius:60dp;background-color:#f9f4ed;z-index:310;color:#201e1d;} +.hw-rename input {display:block;width:820dp;height:84dp;padding:0 26dp;font-size:36dp;border:3dp #c0b6a5;border-radius:42dp;background-color:#ffffff;color:#201e1d;} +.hw-rename-row {display:flex;justify-content:flex-end;gap:16dp;margin-top:26dp;} +.hw-rename-row button {height:76dp;padding:0 36dp;border-radius:38dp;font-size:30dp;} +.hw-match-side {display:flex;flex-direction:column;align-items:center;width:34%;} +.hw-match-mid {display:flex;flex-direction:column;align-items:center;width:30%;} +.hw-versus {display:flex;align-items:center;justify-content:center;line-height:60dp;margin:0 0 18dp 0;} +.hw-match-mid .hw-versus {display:block;line-height:120dp;font-size:52dp;font-weight:normal;} diff --git a/src/modern/ui/CMakeLists.txt b/src/modern/ui/CMakeLists.txt index ce93e4a..cabe645 100644 --- a/src/modern/ui/CMakeLists.txt +++ b/src/modern/ui/CMakeLists.txt @@ -45,7 +45,7 @@ endif() set(modern_assets "${CMAKE_BINARY_DIR}/assets/modern") FetchContent_GetProperties(rmlui) file(MAKE_DIRECTORY "${modern_assets}") -foreach(asset modern.rml theme.rcss ticket.rcss sports.rcss calendar.rcss reports.rcss report_details.rcss report_pickers.rcss indoor.rcss planning.rcss almanac.rcss finance.rcss bank.rcss contracts.rcss amount.rcss environment.rcss advertising.rcss toto.rcss lineup.rcss live.rcss transfer.rcss career_reports.rcss rankings.rcss stadium.rcss statistics.rcss news.rcss news-catalog.json settings.rcss widgets.rcss files.rcss front.rcss entry.rcss opening.rcss select_menu.rcss career.rcss national.rcss postmatch.rcss) +foreach(asset modern.rml theme.rcss ticket.rcss sports.rcss calendar.rcss reports.rcss report_details.rcss report_pickers.rcss indoor.rcss planning.rcss almanac.rcss finance.rcss bank.rcss contracts.rcss amount.rcss environment.rcss advertising.rcss toto.rcss lineup.rcss live.rcss transfer.rcss career_reports.rcss rankings.rcss stadium.rcss statistics.rcss news.rcss news-catalog.json settings.rcss widgets.rcss files.rcss front.rcss entry.rcss opening.rcss select_menu.rcss career.rcss national.rcss postmatch.rcss notebook.rcss) configure_file("${CMAKE_SOURCE_DIR}/assets/modern/${asset}" "${modern_assets}/${asset}" COPYONLY) endforeach() diff --git a/src/modern/ui/controls.inc b/src/modern/ui/controls.inc index 60251b4..406df25 100644 --- a/src/modern/ui/controls.inc +++ b/src/modern/ui/controls.inc @@ -123,6 +123,7 @@ void App::drag_event(Rml::Event &event) { } void App::ProcessEvent(Rml::Event &event) try { const auto type = event.GetType(); + if (notebook_home_event(event)) return; if (engine_mode_) { engine_event(event); return; } // Native widgets can emit intermediate selected values while their options // are being constructed. Opening a squad menu must stay read-only. diff --git a/src/modern/ui/engine_screens.inc b/src/modern/ui/engine_screens.inc index d51e70b..ae9493c 100644 --- a/src/modern/ui/engine_screens.inc +++ b/src/modern/ui/engine_screens.inc @@ -65,11 +65,18 @@ void App::engine_render() { std::string club_line; if (const auto *club = world_->find("clubs", team.at("id").get()); club && !club->value("crest", "").empty()) if (const auto colour = renderer_.crest_colour(club->value("crest", "")); !colour.empty()) club_line = " style=\"border-bottom:8dp " + colour + ";\""; - out = "
" + engine_widget_crest(team, 82) + - "" + esc(engine_text(team.at("name"))) + "" + esc(engine_text(person.at("name"))) + - "
" + esc(ui_long_date(meta.at("date").get())) + "Saison " + - esc(meta.at("season").at("label").get()) + "
Guthaben" + - esc(engine_price(desk.at("accounts").at("cash"))) + "
"; + std::string next_match; + if (desk.at("nextFixture").is_object()) { + const auto &next = desk.at("nextFixture"); + const bool at_home = next.at("home").at("id") == team.at("id"); + next_match = "Nächstes Spiel: " + esc(engine_text(next.at(at_home ? "away" : "home").at("name"))) + (at_home ? " (H)" : " (A)") + ""; + } + const std::string head = "" + esc(ui_long_date(meta.at("date").get())) + "
" + next_match + "" + + esc(engine_price(desk.at("accounts").at("cash"))) + "
"; + (void)club_line; + // which pages can be opened now, and the widgets of the home page + std::map route_open; + std::string home; bool lineup_available = false; try { (void)engine_lineup_projection(engine_data_); lineup_available = true; } catch (const std::exception &) {} bool training_available = false, tactics_available = false; @@ -95,7 +102,7 @@ void App::engine_render() { try { (void)engine_friendly_plan(engine_data_); friendlies_available = true; } catch (const std::exception &) {} init_desktop(); for (const auto &[id, o] : desktop_.at("objects").items()) { - if (!o.value("visible", false)) continue; + if (!o.value("visible", false) || id == "trash") continue; if (meta.at("scope").at("role") == "national" && (id == "account" || id == "warnings" || id == "fans" || id == "results" || id == "own-curve" || id == "opponent-curve" || id == "comparison-curve")) continue; @@ -132,7 +139,7 @@ void App::engine_render() { for (const auto &[key, span] : definition.at("spans").items()) if (o.at("w") == span[0].get() * 248 - 24 && o.at("h") == span[1].get() * 248 - 24) size = key; const auto route = id == "calendar" || id == "competition" ? std::string("calendar") : std::string(); - out += "
" + body + "
"; } @@ -141,38 +148,81 @@ void App::engine_render() { const bool camp_allowed = desk.at("menuAvailability").at("camps").value("status", "") == "available"; const auto commands = meta.at("scope").value("allowedCommands", Json::array()); const bool supported = (route=="newplayer"&&engine_fresh_&&engine_manager_value_.is_object()) || (route=="settings"&&engine_fresh_&&engine_settings_value_.is_object()) || (route=="indoor"&&engine_fresh_&&engine_indoor_value_.is_object()) || ((route=="tables"||route=="strengths"||route=="league"||route=="other"||route=="scorers"||route=="fairplay")&&engine_fresh_&&meta.at("scope").at("role")=="club") || (route == "almanac" && engine_fresh_) || (route == "friendlies" && friendlies_available && engine_fresh_) || (route == "calendar" && calendar_available && engine_fresh_) || (route == "postpone" && scheduling_available && engine_fresh_) || (route == "contracts" && contracts_available && engine_fresh_) || (route == "environment" && environment_available && engine_fresh_) || (route == "advertising" && advertising_available && engine_fresh_) || (route == "bank" && bank_available && engine_fresh_) || (route == "training" && training_available && engine_fresh_) || (route == "tactics" && tactics_available && engine_fresh_) || (route == "lineup" && lineup_available && engine_fresh_) || (route=="balance"&&engine_fresh_&&engine_data_.at("balance").value("messageType","")=="snapshot") || (route=="news"&&engine_fresh_&&engine_news_value_.is_object()) || (route=="achievements"&&engine_fresh_&&engine_data_.at("achievements").value("messageType","")=="snapshot"&&engine_data_.at("achievements").at("data").at("available")==true) || (route=="transfer"&&engine_fresh_&&engine_transfer_value_.is_object()) || (route=="stadium"&&engine_fresh_&&engine_stadium_value_.is_object()) || (route=="toto"&&engine_fresh_&&engine_toto_value_.is_object()) || (route=="statistics"&&engine_fresh_) || route == "save" || route == "load" || (route == "kickoff" && engine_fresh_ && std::find(commands.begin(), commands.end(), Json("session.advance")) != commands.end()) || (route == "camp" && engine_fresh_ && camp_allowed && std::find(commands.begin(), commands.end(), Json("camp.book")) != commands.end()); - out += desktop_button(id, o, "engine-open", supported && !engine_busy_ && (!engine_manager_value_.is_object() || engine_manager_value_.at("ended")!=true || route=="save" || route=="load" || route=="newplayer")); + route_open[route] = (supported && !engine_busy_ && (!engine_manager_value_.is_object() || engine_manager_value_.at("ended")!=true || route=="save" || route=="load" || route=="newplayer")); } } - out += "
"; - if(menu_=="save"||menu_=="load")out+="
"+window(menu_=="save"?"Spiel speichern":"Spiel laden",render_files(false,menu_=="save"))+"
"; - if(menu_=="scorers")out+="
"+window("Spielerstatistiken",engine_rankings_value_.is_object()?render_scorers():"
"+esc(engine_busy_?"Spielerstatistiken werden geladen …":engine_notice_)+"
")+"
"; - if(menu_=="fairplay")out+="
"+window("Fairplay",engine_fairplay_value_.is_object()?render_fairplay():"
"+esc(engine_busy_?"Fairplay wird geladen …":engine_notice_)+"
")+"
"; - if(menu_=="other")out+="
"+window("Übrige Spiele",engine_other_value_.is_object()?render_reports("other"):"
"+esc(engine_busy_?"Wettbewerbe werden geladen …":engine_other_index_.is_object()?"Keine aktiven Wettbewerbe.":engine_notice_)+"
")+"
"; + out = notebook_shell([&](const std::string &route) { const auto found = route_open.find(route); return found != route_open.end() && found->second; }, head); + (void)home; + if (menu_.empty()) { + // the home page: the values of its cards + const auto date = meta.at("date").get(); + const int y = std::stoi(date.substr(0, 4)), mo = std::stoi(date.substr(5, 2)), d = std::stoi(date.substr(8, 2)); + const auto ymd = std::chrono::year_month_day{std::chrono::year(y), std::chrono::month(unsigned(mo)), std::chrono::day(unsigned(d))}; + static constexpr std::array months{"Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"}; + static constexpr std::array weekdays{"Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"}; + const bool club_role = meta.at("scope").at("role") == "club"; + Json model = {{"day", d}, {"weekday", ymd.ok() ? weekdays[std::chrono::weekday{std::chrono::sys_days(ymd)}.c_encoding()] : ""}, {"month", std::string(months[size_t(std::clamp(mo, 1, 12) - 1)]) + " " + std::to_string(y)}, + {"note", "Saison " + meta.at("season").at("label").get()}, {"cash", engine_price(desk.at("accounts").at("cash"))}, {"savings", nullptr}, {"ticket", nullptr}, {"ticket_action", "engine-ticket"}, + {"fixture", nullptr}, {"own", {{"name", engine_text(team.at("name"))}, {"team", team}, {"rank", "—"}, {"strength", "—"}}}, {"opponent", nullptr}, {"own_curve", Json::array()}, {"opponent_curve", Json::array()}, + {"results", Json::array()}, {"warnings", Json::array()}, {"fans", nullptr}, {"news", engine_news_value_.is_object() ? notebook_news() : Json(nullptr)}, {"portrait", ""}, + {"manager", engine_text(person.at("name"))}, {"duels", nullptr}}; + const auto savings = bank_available ? engine_data_.at("bank").at("data").at("accounts").at("deposit") : desk.at("accounts").at("savings"); + if (!savings.is_null()) model["savings"] = engine_price(savings); + if (ticket_available) model["ticket"] = engine_price(engine_data_.at("stadium").at("data").at("ticketPrice")); + if (const auto portrait = person.value("portraitGuiKey", std::string()); portrait.starts_with("gui:manager/photo/")) model["portrait"] = "manager." + portrait.substr(18); + else if (portrait.starts_with("gui:manager/painted/")) model["portrait"] = "manager-painted." + portrait.substr(20); + try { + const auto data = engine_widgets_projection(engine_data_); + const auto text = [](const Json &v) { return v.is_null() ? std::string("—") : std::to_string(v.get()); }; + model["own"]["rank"] = text(data.at("own").at("rank")); + model["own"]["strength"] = text(data.at("own").at("strength")); + if (data.at("fixture").is_object()) { + const auto &next = data.at("fixture"); + const bool at_home = next.at("home").at("id") == data.at("own").at("teamId"); + model["fixture"] = {{"home", {{"name", engine_text(next.at("home").at("name"))}, {"team", next.at("home")}}}, {"away", {{"name", engine_text(next.at("away").at("name"))}, {"team", next.at("away")}}}, + {"competition", engine_text(next.at("competition"))}, {"venue", at_home ? "Heimspiel" : "Auswärtsspiel"}}; + if (data.at("opponent").is_object()) { + const auto &other = next.at(at_home ? "away" : "home"); + model["opponent"] = {{"name", engine_text(other.at("name"))}, {"team", other}, {"rank", text(data.at("opponent").at("rank"))}, {"strength", text(data.at("opponent").at("strength"))}}; + } + } + if (club_role) { + if (data.at("rankCurve").is_array()) model["own_curve"] = data.at("rankCurve"); + if (data.at("recent").is_array()) model["results"] = data.at("recent"); + model["warnings"] = notebook_lamps(data.at("warnings")); + } + } catch (const std::exception &) { + } + out += notebook_home(model); + } + if(menu_=="save"||menu_=="load")out+="
"+window(menu_=="save"?"Spiel speichern":"Spiel laden",render_files(false,menu_=="save"))+"
"; + if(menu_=="scorers")out+="
"+window("Spielerstatistiken",engine_rankings_value_.is_object()?render_scorers():"
"+esc(engine_busy_?"Spielerstatistiken werden geladen …":engine_notice_)+"
")+"
"; + if(menu_=="fairplay")out+="
"+window("Fairplay",engine_fairplay_value_.is_object()?render_fairplay():"
"+esc(engine_busy_?"Fairplay wird geladen …":engine_notice_)+"
")+"
"; + if(menu_=="other")out+="
"+window("Übrige Spiele",engine_other_value_.is_object()?render_reports("other"):"
"+esc(engine_busy_?"Wettbewerbe werden geladen …":engine_other_index_.is_object()?"Keine aktiven Wettbewerbe.":engine_notice_)+"
")+"
"; if(menu_=="newplayer")out+="
"+(scene_=="manager"?render_manager():render_career())+"
"; - if(menu_=="settings")out+="
"+window("Einstellungen",render_settings())+"
"; - if(menu_=="indoor")out+="
"+window("Hallentabellen",render_indoor())+"
"; - if(menu_=="balance")out+="
"+window("Bilanz",render_balance())+"
"; + if(menu_=="settings")out+="
"+window("Einstellungen",render_settings())+"
"; + if(menu_=="indoor")out+="
"+window("Hallentabellen",render_indoor())+"
"; + if(menu_=="balance")out+="
"+window("Bilanz",render_balance())+"
"; if(menu_=="news")out+="
"+render_news()+"
"; - if(menu_=="achievements")out+="
"+window("Erfolge",render_achievements())+"
"; - if(menu_=="transfer")out+="
"+window("Transfers",render_transfer())+"
"; - if(menu_=="stadium")out+="
"+window("Stadion",render_stadium())+"
"; - if(menu_=="toto")out+="
"+window("Toto",render_toto())+"
"; - if(menu_=="statistics")out+="
"+window("Statistiken",engine_statistics_value_.is_object()?render_statistics():"
"+esc(engine_busy_?"Statistik wird geladen …":engine_notice_)+"
")+"
"; - if(menu_=="league")out+="
"+window("Ligaspiele",engine_fixtures_value_.is_object()?render_reports("league"):"
"+esc(engine_busy_?"Ligaspiele werden geladen …":engine_notice_)+"
")+"
"; - if(menu_=="tables"||menu_=="strengths")out+="
"+window(menu_=="tables"?"Tabelle":"Stärken",engine_reports_read_.is_object()?render_reports(menu_):"
"+esc(engine_busy_?"Ligabericht wird geladen …":engine_notice_)+"
")+"
"; - if(menu_=="almanac") out+="
"+window("Almanach",engine_almanac_cache_.contains("index")?render_almanac():"
"+esc(engine_busy_?"Spielarchiv wird geladen …":engine_notice_)+"
")+"
"; - if (menu_ == "friendlies") out += "
" + window("Freundschaftsspiel", friendlies_available ? render_friendlies() : "
Freundschaftsplanung ist derzeit nicht verfügbar.
") + "
"; - if (menu_ == "calendar") out += "
" + window("Kalender", calendar_available ? render_calendar() : "
Der Saisonkalender ist derzeit nicht verfügbar.
") + "
"; - if (menu_ == "postpone") out += "
" + window("Verlegen", scheduling_available ? render_postpone() : "
Die Spielverlegung ist derzeit nicht verfügbar.
") + "
"; - if (menu_ == "contracts") out += "
" + window("Verträge", render_contracts()) + "
"; - if (menu_ == "environment") out += "
" + window("Umfeld", render_environment()) + "
"; - if (menu_ == "advertising") out += "
" + window("Werbung", render_advertising()) + "
"; - if (menu_ == "bank") out += "
" + window("Bank", render_bank()) + "
"; - if (menu_ == "training") out += "
" + window("Training", render_training()) + "
"; - if (menu_ == "tactics") out += "
" + window("Taktik", render_tactics()) + "
"; - if (menu_ == "lineup") out += "
" + window("Aufstellung", render_lineup()) + "
"; - if (menu_ == "camp") out += "
" + window("Trainingslager", render_camp()) + "
"; + if(menu_=="achievements")out+="
"+window("Erfolge",render_achievements())+"
"; + if(menu_=="transfer")out+="
"+window("Transfers",render_transfer())+"
"; + if(menu_=="stadium")out+="
"+window("Stadion",render_stadium())+"
"; + if(menu_=="toto")out+="
"+window("Toto",render_toto())+"
"; + if(menu_=="statistics")out+="
"+window("Statistiken",engine_statistics_value_.is_object()?render_statistics():"
"+esc(engine_busy_?"Statistik wird geladen …":engine_notice_)+"
")+"
"; + if(menu_=="league")out+="
"+window("Ligaspiele",engine_fixtures_value_.is_object()?render_reports("league"):"
"+esc(engine_busy_?"Ligaspiele werden geladen …":engine_notice_)+"
")+"
"; + if(menu_=="tables"||menu_=="strengths")out+="
"+window(menu_=="tables"?"Tabelle":"Stärken",engine_reports_read_.is_object()?render_reports(menu_):"
"+esc(engine_busy_?"Ligabericht wird geladen …":engine_notice_)+"
")+"
"; + if(menu_=="almanac") out+="
"+window("Almanach",engine_almanac_cache_.contains("index")?render_almanac():"
"+esc(engine_busy_?"Spielarchiv wird geladen …":engine_notice_)+"
")+"
"; + if (menu_ == "friendlies") out += "
" + window("Freundschaftsspiel", friendlies_available ? render_friendlies() : "
Freundschaftsplanung ist derzeit nicht verfügbar.
") + "
"; + if (menu_ == "calendar") out += "
" + window("Kalender", calendar_available ? render_calendar() : "
Der Saisonkalender ist derzeit nicht verfügbar.
") + "
"; + if (menu_ == "postpone") out += "
" + window("Verlegen", scheduling_available ? render_postpone() : "
Die Spielverlegung ist derzeit nicht verfügbar.
") + "
"; + if (menu_ == "contracts") out += "
" + window("Verträge", render_contracts()) + "
"; + if (menu_ == "environment") out += "
" + window("Umfeld", render_environment()) + "
"; + if (menu_ == "advertising") out += "
" + window("Werbung", render_advertising()) + "
"; + if (menu_ == "bank") out += "
" + window("Bank", render_bank()) + "
"; + if (menu_ == "training") out += "
" + window("Training", render_training()) + "
"; + if (menu_ == "tactics") out += "
" + window("Taktik", render_tactics()) + "
"; + if (menu_ == "lineup") out += "
" + window("Aufstellung", render_lineup()) + "
"; + if (menu_ == "camp") out += "
" + window("Trainingslager", render_camp()) + "
"; } if ((menu_ == "stadium" || menu_ == "bank" || menu_ == "environment" || menu_ == "advertising" || menu_ == "contracts" || menu_ == "calendar" || menu_ == "postpone" || menu_ == "friendlies" || menu_ == "almanac" || menu_=="tables" || menu_=="strengths" || menu_=="league" || menu_=="other" || menu_=="scorers" || menu_=="fairplay") && !amount_ && contracts_dialog_.empty() && planning_dialog_.empty()) out += "
" + esc(engine_busy_ ? engine_operation_ : engine_notice_) + "
"; if ((menu_.empty() || engine_data_.empty()) && !(scene_ == "live" && live_.available())) out += "
" + esc(engine_busy_ ? engine_operation_ : engine_notice_) + "
"; diff --git a/src/modern/ui/notebook.inc b/src/modern/ui/notebook.inc new file mode 100644 index 0000000..93aa0f0 --- /dev/null +++ b/src/modern/ui/notebook.inc @@ -0,0 +1,265 @@ +// SPDX-License-Identifier: GPL-3.0-only +// The career's notebook: a book on a wooden table instead of a desk with windows. Markers +// at the left edge choose a category, markers at the top edge one of its pages, the whistle +// beside the book kicks off. The open page is still `menu_`; the category follows from it. +// Wood, leather and paper are computed once from noise and tinted by the skin. +namespace { +struct NotebookSection { + const char *id, *label; + std::vector routes; +}; +// Every menu of the career belongs to exactly one category (kick-off is the whistle). +const std::vector ¬ebook_sections() { + static const std::vector value = { + {"home", "Hauptseite", {}}, + {"team", "Mannschaft", {"lineup", "tactics", "training", "camp", "strengths", "scorers"}}, + {"transfers", "Transfers", {"transfer", "contracts"}}, + {"club", "Verein", {"stadium", "environment", "advertising"}}, + {"finance", "Finanzen", {"balance", "bank", "toto"}}, + {"fixtures", "Spielplan", {"calendar", "league", "tables", "other", "friendlies", "postpone", "indoor"}}, + {"records", "Statistik", {"statistics", "achievements", "almanac", "fairplay", "highscore"}}, + {"inbox", "Posteingang", {"news"}}, + {"options", "Optionen", {"settings", "save", "load", "newplayer"}}}; + return value; +} +std::string notebook_page_label(const std::string &route) { + static const std::map labels = { + {"lineup", "Aufstellung"}, {"tactics", "Taktik"}, {"training", "Training"}, {"camp", "Trainingslager"}, {"strengths", "Stärken"}, + {"scorers", "Spielerstatistik"}, {"transfer", "Transfermarkt"}, {"contracts", "Verträge"}, {"stadium", "Stadion"}, {"environment", "Umfeld"}, + {"advertising", "Werbung"}, {"balance", "Bilanz"}, {"bank", "Bank"}, {"toto", "Toto"}, {"calendar", "Kalender"}, {"league", "Ligaspiele"}, + {"tables", "Tabellen"}, {"other", "Übrige Spiele"}, {"friendlies", "Testspiele"}, {"postpone", "Verlegen"}, {"indoor", "Halle"}, + {"statistics", "Statistiken"}, {"achievements", "Erfolge"}, {"almanac", "Almanach"}, {"fairplay", "Fairplay"}, {"highscore", "Highscore"}, + {"news", "Nachrichten"}, {"settings", "Einstellungen"}, {"save", "Speichern"}, {"load", "Laden"}, {"newplayer", "Manager"}}; + const auto found = labels.find(route); + return found == labels.end() ? route : found->second; +} +// Value noise in [0,1] with a period, so that a texture can repeat. +double notebook_noise(double x, double y, uint32_t seed) { + const auto corner = [seed](int64_t ix, int64_t iy) { + uint32_t h = uint32_t(ix) * 374761393u + uint32_t(iy) * 668265263u + seed * 2246822519u; + h = (h ^ (h >> 13)) * 1274126177u; + return double((h ^ (h >> 16)) & 0xffffu) / 65535.0; + }; + const double fx = std::floor(x), fy = std::floor(y); + const double tx = x - fx, ty = y - fy, sx = tx * tx * (3 - 2 * tx), sy = ty * ty * (3 - 2 * ty); + const auto ix = int64_t(fx), iy = int64_t(fy); + const double top = corner(ix, iy) + (corner(ix + 1, iy) - corner(ix, iy)) * sx, bottom = corner(ix, iy + 1) + (corner(ix + 1, iy + 1) - corner(ix, iy + 1)) * sx; + return top + (bottom - top) * sy; +} +double notebook_fractal(double x, double y, uint32_t seed, int octaves) { + double sum = 0, weight = 0, scale = 1; + for (int o = 0; o < octaves; ++o, scale *= 2) { + sum += notebook_noise(x * scale, y * scale, seed + uint32_t(o) * 17u) / scale; + weight += 1 / scale; + } + return sum / weight; +} +// Capitals for a title line, German umlauts included (the style sheet's own does not know them). +std::string notebook_upper(std::string text) { + std::string out; + for (size_t i = 0; i < text.size(); ++i) { + const unsigned char c = static_cast(text[i]); + if (c == 0xc3 && i + 1 < text.size()) { + const unsigned char d = static_cast(text[i + 1]); + out += char(c); + out += char(d == 0xa4 || d == 0xb6 || d == 0xbc ? d - 0x20 : d); + ++i; + } else out += char(std::toupper(c)); + } + return out; +} +struct NotebookTone { double r, g, b; }; +NotebookTone notebook_tone(const std::string &hex) { + return {double(std::stoi(hex.substr(1, 2), nullptr, 16)), double(std::stoi(hex.substr(3, 2), nullptr, 16)), double(std::stoi(hex.substr(5, 2), nullptr, 16))}; +} +// kind: 0 wood (boards with a long grain), 1 leather (a fine pebbled grain), 2 paper (fibres and a faint cloud) +editor::images::Raster notebook_texture(int kind, int width, int height, const std::string &dark, const std::string &light) { + editor::images::Raster raster; + raster.width = width; + raster.height = height; + raster.pixels.resize(size_t(width) * size_t(height) * 4); + const auto a = notebook_tone(dark), b = notebook_tone(light); + for (int y = 0; y < height; ++y) + for (int x = 0; x < width; ++x) { + double t = 0.5; + if (kind == 0) { + const int board = y * 9 / height; // nine boards across the table + const double within = double(y * 9 % height) / height; + const double grain = notebook_fractal(x / 420.0 + board * 7.3, y / 5.0, 7u + uint32_t(board), 4); + const double streak = notebook_fractal(x / 900.0, y / 60.0 + board * 3.1, 31u, 3); + t = 0.18 + 0.5 * grain + 0.3 * streak + (board % 2 ? 0.05 : -0.04); + if (within < 0.012 || within > 0.988) t *= 0.35; // the joint between two boards + } else if (kind == 1) { + const double pebble = notebook_fractal(x / 5.0, y / 5.0, 5u, 2), cloud = notebook_fractal(x / 160.0, y / 160.0, 9u, 3); + t = 0.25 + 0.4 * pebble + 0.4 * cloud; + } else { + const double fibre = notebook_fractal(x / 2.2, y / 2.2, 11u, 2), cloud = notebook_fractal(x / 260.0, y / 260.0, 21u, 3); + t = 0.55 + 0.25 * fibre + 0.3 * cloud; + } + t = std::clamp(t, 0.0, 1.0); + const size_t at = (size_t(y) * size_t(width) + size_t(x)) * 4; + raster.pixels[at] = uint8_t(a.r + (b.r - a.r) * t); + raster.pixels[at + 1] = uint8_t(a.g + (b.g - a.g) * t); + raster.pixels[at + 2] = uint8_t(a.b + (b.b - a.b) * t); + raster.pixels[at + 3] = 255; + } + return raster; +} +// The colours of the three materials for a skin: {wood dark, wood light, leather dark, leather light, paper dark, paper light} +std::array notebook_materials(const std::string &theme) { + if (theme == "midnight") return {"#0b1016", "#1d2833", "#131b24", "#2a3a4a", "#232d38", "#2f3b48"}; + if (theme == "matchday") return {"#120c0e", "#2b1a1d", "#2a1216", "#5a262c", "#2a2326", "#383033"}; + return {"#3a1f0e", "#7a4a26", "#4a2710", "#93531f", "#ecdfc8", "#f9f1e2"}; +} +} // namespace + +// Where the 2160 high book lies on a stage that may be taller than that. +double App::notebook_top() const { return std::max(0.0, (desktop_height() - 2160) / 2.0); } + +// The category a page belongs to; the home section when no page is open. +std::string App::notebook_section_of(const std::string &route) const { + for (const auto §ion : notebook_sections()) + for (const char *r : section.routes) + if (route == r) return section.id; + return "home"; +} + +// The book with its markers, after the design's proportions: 1 design unit = 2.25 dp, the +// book 1406 x 866 units at (150, 62). `enabled` tells which pages can be opened now; `head` +// is the markup at the right of the page's head (day, next match, cash). +std::string App::notebook_shell(const std::function &enabled, const std::string &head) { + const auto materials = notebook_materials(theme_); + const auto wood = renderer_.texture("nb-wood", theme_, [&] { return notebook_texture(0, 1280, 720, materials[0], materials[1]); }); + const auto leather = renderer_.texture("nb-leather", theme_, [&] { return notebook_texture(1, 1100, 680, materials[2], materials[3]); }); + const auto paper = renderer_.texture("nb-paper", theme_, [&] { return notebook_texture(2, 1054, 650, materials[4], materials[5]); }); + const bool light = theme_ == "silver"; + const double stage = desktop_height(), top = notebook_top(); + const auto active = notebook_section_of(menu_); + const auto open = [&](const std::string &route, const std::string &label, const std::string &css, const std::string &attrs, bool on) { + return btn(engine_mode_ ? std::string("engine-open") : "open:" + route, label, css, attrs + " data-id=\"" + route + "\"" + (on ? "" : " disabled=\"disabled\"")); + }; + const auto svg = [&](const std::string &slot, double w, double h, const std::string &body, int pixels) { + return picture(renderer_.diagram(slot + "-" + theme_, "" + body + "", pixels), w * 2.25, h * 2.25); + }; + // the skin's inks (the light skin carries the design's terracotta and sage) + const std::string stitch = light ? "#f6a06b" : theme_ == "matchday" ? "#c9584f" : "#7fa3bd", rule = light ? "#e1eecc" : "#ffffff", margin = light ? "#ffc6a5" : theme_ == "matchday" ? "#c9584f" : "#7fa3bd", + ring = light ? "#8c491a" : "#ffffff", ribbon_a = light ? "#b2622d" : stitch, ribbon_b = light ? "#d67f48" : stitch; + std::string out = "
" + picture(wood, 3840, stage, true) + "
"; + // the leather cover with its seam, the ribbon, the stack of sheets + out += "
" + picture(leather, 3281, 2070, true) + "
" + + svg("nb-seam", 1440, 902, "", 2400) + "
"; + out += "
" + svg("nb-ribbon", 20, 96, "", 200) + "
"; + for (int sheet = 4; sheet >= 0; --sheet) out += "
"; + // the categories: markers that stick out at the left edge + static constexpr std::array tones{"a3", "s3", "a2", "s4", "a4", "n3", "s2", "a5", "s5"}; + static constexpr std::array turns{-1.5, 1, -0.5, 2, -2, 0.5, 1.5, -1, 0}; + static constexpr std::array rest{11, 18, 9, 16, 20, 10, 15, 19, 9}; + size_t index = 0; + for (const auto §ion : notebook_sections()) { + const bool here = active == section.id; + std::string first; + for (const char *r : section.routes) + if (first.empty() && enabled(r)) first = r; + const std::string label = "" + std::string(section.label) + ""; + const std::string css = std::string("nb-tab") + (here ? " active" : ""); + const std::string attrs = "id=\"tab-" + std::string(section.id) + "\" aria-pressed=\"" + (here ? "true" : "false") + "\" style=\"top:" + scalar(265.5 + index * 186.0) + "dp;transform:translateX(" + + (here ? std::string("-27") : std::to_string(rest[index % rest.size()])) + "dp) rotate(" + scalar(turns[index % turns.size()]) + "deg);\""; + if (section.routes.empty()) out += btn("close", label, css, attrs); + else if (here) out += open(menu_, label, css, attrs, true); + else out += open(first, label, css, attrs, !first.empty()); + ++index; + } + // the pages of the open category: markers along the top edge + std::string kicker = "Hauptseite · 1 / 1", heading = "Übersicht"; + out += "
"; + static constexpr std::array sub_tones{"s3", "a2", "s2", "a3", "n3", "s4", "a4"}; + static constexpr std::array sub_turns{-1, 1.5, -0.5, 1, -1.5, 0.5, -1}; + static constexpr std::array sub_rest{10, 14, 6, 12, 8, 13, 7}; + for (const auto §ion : notebook_sections()) { + if (active != section.id) continue; + if (section.routes.empty()) { + // the home pages: the player's own, and a marker to add one + const auto &pages = notebook_pages().at("pages"); + for (size_t p = 0; p < pages.size(); ++p) { + const bool here = int(p) == home_page_; + const auto name = pages[p].at("name").get(); + if (here) { + kicker = "Hauptseite · " + std::to_string(p + 1) + " / " + std::to_string(pages.size()); + heading = name; + } + out += btn("home-do", "" + std::to_string(p + 1) + "" + esc(name) + "", + std::string("nb-sub") + (here ? " active" : ""), + "id=\"page-home-" + std::to_string(p) + "\" data-id=\"page:" + std::to_string(p) + "\" data-index=\"" + std::to_string(p) + "\" aria-pressed=\"" + (here ? "true" : "false") + "\" style=\"transform:translateY(" + + (here ? std::string("-13") : std::to_string(sub_rest[p % sub_rest.size()])) + "dp) rotate(" + scalar(sub_turns[p % sub_turns.size()]) + "deg);\""); + } + if (pages.size() < 5) + out += btn("home-do", "+", "nb-sub add", "id=\"page-home-add\" data-id=\"new\" aria-label=\"Neue Seite\" style=\"transform:translateY(16dp) rotate(1deg);\""); + } + size_t n = 0; + for (const char *r : section.routes) { + const bool here = 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); + } + out += open(r, "" + std::to_string(n + 1) + "" + notebook_page_label(r) + "", + 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(r)); + ++n; + } + } + out += "
"; + // the page: paper, the picture of its subject, ruled lines with a margin, two rings left by a cup, a turned corner + std::string lines; + for (double y = 44; y < 850; y += 32) lines += ""; + lines += ""; + lines += ""; + out += "
" + picture(paper, 3163.5, 1948.5, true) + "
"; + if (const auto art = notebook_art(); !art.token.empty()) out += "
" + picture(art, 3163.5, 1948.5, true) + "
"; + out += "
" + svg("nb-lines", 1406, 866, lines, 2800) + "
" + + svg("nb-corner", 62, 62, "", 200) + "
"; + out += "
" + esc(notebook_upper(kicker)) + "" + esc(heading) + "
" + head + "
"; + // a paper clip at the top edge, a pencil in its loop at the right edge + out += "
" + svg("nb-clip", 30, 72, "", 240) + "
"; + out += "
" + svg("nb-pencil", 16, 430, + "" + "" + "" + "" + "", 900) + "
"; + // the whistle beside the book kicks off + const std::string whistle = + "" + "" + "" + "" + "" + "" + "" + ""; + out += btn(engine_mode_ ? std::string("engine-open") : std::string("open:kickoff"), + "" + picture(renderer_.diagram("nb-whistle", "" + whistle + "", 1300), 810, 471) + "", "nb-whistle", + "id=\"object-app-kickoff\" data-id=\"kickoff\" aria-label=\"Anstoß\"" + std::string(enabled("kickoff") ? "" : " disabled=\"disabled\"")); + return out + "
"; +} + +// The picture of the open page's subject (see window_art), for the whole sheet. +Picture App::notebook_art() { + static const std::map motifs{ + {"stadium", "seats"}, {"advertising", "boards"}, {"calendar", "bench"}, {"postpone", "bench"}, {"friendlies", "bench"}, {"camp", "training"}, + {"almanac", "trophies"}, {"achievements", "trophies"}, {"highscore", "trophies"}, {"news", "press"}, {"newplayer", "press"}, {"settings", "press"}, {"environment", "fans"}, {"training", "training"}, + {"lineup", "bench"}, {"tactics", "bench"}, {"contracts", "locker"}, {"transfer", "press"}, + {"tables", "stand"}, {"league", "stand"}, {"other", "stand"}, {"strengths", "stand"}, {"statistics", "kickoff"}, + {"scorers", "kickoff"}, {"fairplay", "kickoff"}}; + const auto found = motifs.find(menu_.empty() ? std::string("statistics") : menu_); + for (const std::string motif : {found == motifs.end() ? std::string("ball") : found->second, std::string("ball")}) { + const auto art = renderer_.image("art.paper-" + motif + ".png", false, 2048); + if (!art.token.empty() && art.width > 0 && art.height > 0) return art; + } + return {}; +} diff --git a/src/modern/ui/notebook_home.inc b/src/modern/ui/notebook_home.inc new file mode 100644 index 0000000..c9134e4 --- /dev/null +++ b/src/modern/ui/notebook_home.inc @@ -0,0 +1,597 @@ +// SPDX-License-Identifier: GPL-3.0-only +// The notebook's home pages: cards on a grid of eight columns and five rows. The player may +// keep up to five pages, name them, and place the cards: drag a card to move it, the right +// mouse button on a card, on the free page or on a page's marker opens its menu. +// A card is made of a few parts (a title line, a large figure, a label, rows, lamps, chips, +// a chart), and every kind of card has a form for each of its sizes. The demo and the +// engine fill the same model, so the cards are drawn in one place. +namespace { +constexpr double home_cell_w = 322.3, home_cell_h = 294.75, home_gap = 31.5, home_left = 558, home_top = 400.5; +constexpr int home_columns = 8, home_rows = 5, home_pages = 5; +struct HomeKind { + const char *type, *label; + std::vector> sizes; // columns x rows + size_t usual; // the size a new card gets +}; +const std::vector &home_kinds() { + static const std::vector value = { + {"calendar", "Kalender", {{2, 1}, {2, 2}}, 1}, + {"account", "Konto & Eintrittspreis", {{2, 1}, {2, 2}}, 0}, + {"competition", "Wettbewerb & Gegner", {{2, 1}, {2, 2}, {4, 2}}, 2}, + {"portrait", "Managerporträt", {{1, 1}, {2, 2}}, 0}, + {"crest", "Vereinswappen", {{1, 1}, {2, 2}}, 0}, + {"opponent-crest", "Gegnerwappen", {{1, 1}, {2, 2}}, 0}, + {"warnings", "Warnlampen", {{2, 1}, {2, 2}, {4, 2}}, 1}, + {"fans", "Fan-Stimmung", {{1, 1}, {2, 1}, {2, 2}}, 2}, + {"own-curve", "Tabellenplatz · eigener Verein", {{1, 1}, {2, 2}, {4, 2}}, 1}, + {"opponent-curve", "Tabellenplatz · Gegner", {{1, 1}, {2, 2}, {4, 2}}, 1}, + {"comparison-curve", "Tabellenplätze · Vergleich", {{2, 2}, {4, 2}, {4, 4}}, 1}, + {"results", "Letzte Spiele", {{2, 1}, {2, 2}, {4, 2}}, 0}, + {"duels", "Direkter Vergleich", {{2, 1}, {2, 2}}, 0}, + {"own-summary", "Platz & Stärke · eigener Verein", {{2, 1}}, 0}, + {"opponent-summary", "Platz & Stärke · Gegner", {{2, 1}}, 0}, + {"news", "Nachrichten", {{2, 2}, {4, 2}, {4, 4}}, 1}}; + return value; +} +const HomeKind *home_kind(const std::string &type) { + for (const auto &kind : home_kinds()) + if (type == kind.type) return &kind; + return nullptr; +} +Json home_default() { + const auto card = [](const char *type, int cols, int rows, int col, int row) { return Json{{"type", type}, {"cols", cols}, {"rows", rows}, {"col", col}, {"row", row}}; }; + return {{"schema", "dreierpack-notebook-home@1"}, + {"pages", Json::array({{{"name", "Übersicht"}, + {"cards", Json::array({card("competition", 4, 2, 1, 1), card("news", 4, 2, 5, 1), card("own-curve", 2, 2, 1, 3), card("results", 2, 2, 3, 3), card("calendar", 2, 2, 5, 3), + card("warnings", 2, 2, 7, 3), card("account", 2, 1, 1, 5), card("own-summary", 2, 1, 3, 5), card("portrait", 1, 1, 5, 5), card("crest", 1, 1, 6, 5), + card("opponent-crest", 1, 1, 7, 5), card("fans", 1, 1, 8, 5)})}}})}}; +} +// Whether a card of cols x rows fits at (col, row) among `cards`, not counting `ignore`. +bool home_fits(const Json &cards, int col, int row, int cols, int rows, const std::string &ignore) { + if (col < 1 || row < 1 || col + cols - 1 > home_columns || row + rows - 1 > home_rows) return false; + for (const auto &other : cards) { + if (other.at("type") == ignore) continue; + const int oc = other.at("col"), orow = other.at("row"), ow = other.at("cols"), oh = other.at("rows"); + if (col < oc + ow && oc < col + cols && row < orow + oh && orow < row + rows) return false; + } + return true; +} +// The first free place for a card of that size, the wished place first. +std::optional> home_free(const Json &cards, int cols, int rows, const std::string &ignore, int wish_col, int wish_row) { + if (cols > home_columns || rows > home_rows) return {}; + const int c = std::clamp(wish_col, 1, home_columns + 1 - cols), r = std::clamp(wish_row, 1, home_rows + 1 - rows); + if (home_fits(cards, c, r, cols, rows, ignore)) return std::pair{c, r}; + for (int row = 1; row + rows - 1 <= home_rows; ++row) + for (int col = 1; col + cols - 1 <= home_columns; ++col) + if (home_fits(cards, col, row, cols, rows, ignore)) return std::pair{col, row}; + return {}; +} +bool home_valid(const Json &home) { + try { + if (home.at("schema") != "dreierpack-notebook-home@1" || !home.at("pages").is_array() || home.at("pages").empty() || home.at("pages").size() > home_pages) return false; + for (const auto &page : home.at("pages")) { + if (!page.at("name").is_string() || !page.at("cards").is_array()) return false; + Json seen = Json::array(); + for (const auto &card : page.at("cards")) { + const auto *kind = home_kind(card.at("type").get()); + if (!kind) return false; + const std::pair size{card.at("cols").get(), card.at("rows").get()}; + if (std::find(kind->sizes.begin(), kind->sizes.end(), size) == kind->sizes.end()) return false; + for (const auto &other : seen) + if (other.at("type") == card.at("type")) return false; + if (!home_fits(seen, card.at("col"), card.at("row"), size.first, size.second, "")) return false; + seen.push_back(card); + } + } + return true; + } catch (const std::exception &) { + return false; + } +} +} // namespace + +// The player's home pages; read once from the user's folder, the usual page otherwise. +Json &App::notebook_pages() { + if (!home_.is_object()) { + home_ = home_default(); + try { + const auto file = user_dir() / "notebook-home.json"; + if (fs::exists(file)) { + const auto stored = Json::parse(editor::read_file(file)); + if (home_valid(stored)) home_ = stored; + } + } catch (const std::exception &) { + } + } + home_page_ = std::clamp(home_page_, 0, int(home_.at("pages").size()) - 1); + return home_; +} +void App::notebook_pages_changed() { + try { + editor::write_atomic(user_dir() / "notebook-home.json", home_.dump(2)); + } catch (const std::exception &) { + } + refresh(); +} + +// The crest of a team of the model: {"id"} of a club, or {"image"} for a picture of the data set. +std::string App::notebook_crest(const Json &team, double size) { + if (team.contains("image")) return img(team.at("image").get(), size, size, false, false, 256); + if (engine_mode_) return engine_widget_crest(team, size); + return crest(world_->find("clubs", team.value("id", std::string())), size); +} + +// A line chart of table places: the first places at the top, a band for the top and one for +// the bottom of the table, a dot per match day, the latest place written beside its dot. +std::string App::notebook_chart(const std::string &slot, const std::vector, std::string>> &series, double w, double h) { + int last_place = 1, most = 8; + for (const auto &[places, colour] : series) { + most = std::max(most, int(places.size())); + for (const int p : places) last_place = std::max(last_place, p); + } + const int bottom = std::max(12, last_place); + const double pad_l = 54, pad_r = 110, top = 22, plot = h - top - 30; + const auto px = [&](int k) { return pad_l + k * (w - pad_l - pad_r) / double(most - 1); }; + const auto py = [&](double place) { return top + (place - 1) / double(bottom - 1) * plot; }; + const bool light = theme_ == "silver"; + std::string svg = ""; + svg += ""; + svg += ""; + svg += ""; + std::string labels; + const auto label = [&](double x, double y, const std::string &text, bool now) { + labels += "" + esc(text) + ""; + }; + for (const int place : {1, (bottom + 1) / 2, bottom}) label(16, py(place), std::to_string(place), false); + bool first = true; + for (const auto &[places, colour] : series) { + if (places.empty()) continue; + std::string path; + for (size_t k = 0; k < places.size(); ++k) path += (k ? "L" : "M") + scalar(px(int(k))) + " " + scalar(py(places[k])); + // the first series stands on a faint area down to the foot of the chart + if (first && places.size() > 1) svg += ""; + first = false; + svg += ""; + for (size_t k = 0; k < places.size(); ++k) { + const bool now = k + 1 == places.size(); + svg += ""; + } + label(px(int(places.size()) - 1) + 30, py(places.back()), std::to_string(places.back()) + ".", true); + } + svg += ""; + return "
" + picture(renderer_.diagram("hw-chart-" + slot + "-" + theme_, svg, int(w * 1.4)), w, h) + labels + "
"; +} + +// The inside of a card, or nothing when the model has no values for it. `look` receives +// extra classes for the card itself (a dark match card, a photograph in a white frame ...). +std::string App::notebook_card(const std::string &type, int cols, int rows, const Json &m, std::string &look) { + const bool one = cols == 1 && rows == 1, flat = rows == 1 && !one, wide = cols >= 4; + const double inner_w = cols * home_cell_w + (cols - 1) * home_gap - (one ? 44 : 72), inner_h = rows * home_cell_h + (rows - 1) * home_gap - 62; + const auto kicker = [](const std::string &text) { return "" + esc(notebook_upper(text)) + ""; }; + const auto big = [](const std::string &text, int size, const std::string &sub = {}) { + return "
" + esc(text) + "" + (sub.empty() ? "" : "" + esc(sub) + "") + "
"; + }; + const auto tag = [](const std::string &text, bool terra = false) { return "" + esc(text) + ""; }; + const auto foot = [](const std::string &text) { return "" + esc(text) + ""; }; + const auto lines = [](const std::vector> &rows_) { + std::string out = "
"; + for (const auto &[a, b] : rows_) out += "
" + esc(a) + "" + esc(b) + "
"; + return out + "
"; + }; + const auto text_of = [&](const char *key) { return m.contains(key) && m.at(key).is_string() ? m.at(key).get() : std::string(); }; + const Json &fixture = m.at("fixture"), &own = m.at("own"), &opponent = m.at("opponent"); + const auto places = [&](const char *key) { + std::vector out; + if (m.contains(key) && m.at(key).is_array()) + for (const auto &p : m.at(key)) + if (p.is_number_integer()) out.push_back(p.get()); + return out; + }; + const bool light = theme_ == "silver"; + const std::string own_ink = light ? "#c67139" : "#e09463", other_ink = light ? "#56633f" : "#aebf92"; + if (type == "competition") { + look = " hero"; + if (!fixture.is_object()) return kicker("Nächstes Spiel") + "
Keine bestätigte Begegnung.
"; + const auto competition = fixture.value("competition", std::string()), venue = fixture.value("venue", std::string()); + const bool home = venue == "Heimspiel"; + const auto &other = fixture.at(home ? "away" : "home"); + const std::string placed = opponent.is_object() ? "Platz " + opponent.value("rank", std::string("—")) + " · Stärke " + opponent.value("strength", std::string("—")) : std::string(); + if (flat) return kicker(competition) + "
" + notebook_crest(other.at("team"), 106) + "
" + big(other.at("name").get(), 46) + tag(venue, !home) + "
"; + if (!wide) + return kicker(competition) + "
" + notebook_crest(other.at("team"), 164) + "
" + big(other.at("name").get(), 50) + tag(venue, !home) + foot(placed); + const auto side = [&](const Json &team) { + return "
" + notebook_crest(team.at("team"), 178) + "
" + esc(team.at("name").get()) + "
"; + }; + return kicker("Nächstes Spiel · " + competition) + "
" + side(fixture.at("home")) + "
vs" + tag(venue, !home) + "
" + side(fixture.at("away")) + "
" + + foot(placed.empty() ? std::string() : "Gegner auf " + placed); + } + if (type == "news") { + if (!m.at("news").is_object()) return {}; + const auto &items = m.at("news").at("items"); + const size_t limit = rows >= 4 ? 12 : 5; + const int unread = m.at("news").value("unread", 0); + std::string out = kicker(unread ? "Nachrichten · " + std::to_string(unread) + " ungelesen" : "Nachrichten") + "
"; + size_t shown = 0; + for (const auto &item : items) { + if (shown++ == limit) break; + const bool fresh = item.value("unread", false); + out += "
" + esc(item.value("title", std::string())) + "" + (wide ? "" + esc(item.value("date", std::string())) + "" : std::string()) + "
"; + } + if (items.empty()) out += "
Das Postfach ist leer.
"; + return out + "
" + (items.size() > limit ? foot(std::to_string(items.size() - limit) + " weitere im Posteingang") : std::string()); + } + if (type == "calendar") { + // a tear-off calendar: the month on a band, the day large beneath it + look = " cal"; + std::string next; + if (fixture.is_object()) { + const bool home = fixture.value("venue", std::string()) == "Heimspiel"; + next = fixture.at(home ? "away" : "home").at("name").get() + (home ? " (H)" : " (A)"); + } + const std::string band = "
" + esc(notebook_upper(text_of("month"))) + "
"; + if (flat) return band + "
" + std::to_string(m.at("day").get()) + "
" + esc(text_of("weekday")) + "" + foot(next.empty() ? text_of("note") : "Nächstes Spiel: " + next) + "
"; + return band + "" + esc(text_of("weekday")) + "" + std::to_string(m.at("day").get()) + "" + + (next.empty() ? std::string() : "
" + tag("Nächstes Spiel: " + next) + "
") + "" + esc(text_of("note")) + ""; + } + if (type == "account") { + const std::string ticket = m.at("ticket").is_string() + ? btn(text_of("ticket_action"), "Eintritt" + esc(text_of("ticket")) + "", "hw-ticket", "id=\"account-ticket\" data-interactive=\"true\" aria-label=\"Eintrittspreis ändern\"") + : std::string(); + if (flat) return kicker("Vereinskasse") + big(text_of("cash"), 54) + ticket; + return kicker("Vereinskasse") + big(text_of("cash"), 62) + lines({{"Sparbuch", m.at("savings").is_string() ? text_of("savings") : "—"}}) + "
" + ticket; + } + if (type == "warnings") { + if (m.at("warnings").empty()) return {}; + // the lamps of a dashboard on a dark panel + int alerts = 0; + for (const auto &lamp : m.at("warnings")) alerts += lamp.at("attention").is_boolean() && lamp.at("attention").get(); + std::string out = kicker(alerts ? "Warnlampen · " + std::to_string(alerts) + (alerts == 1 ? " leuchtet" : " leuchten") : "Warnlampen · alles ruhig") + "
"; + const double dot = flat ? 52 : wide ? 54 : 44; + for (const auto &lamp : m.at("warnings")) { + const auto &attention = lamp.at("attention"); + const bool alert = attention.is_boolean() && attention.get(); + out += "
"; + if (!flat) out += "" + esc(lamp.value(wide ? "name" : "short", lamp.value("name", std::string()))) + "" + (wide ? "" + esc(alert ? lamp.value("note", std::string()) : attention.is_null() ? "nicht bekannt" : "in Ordnung") + "" : std::string()) + ""; + out += "
"; + } + return out + "
"; + } + if (type == "fans") { + if (!m.at("fans").is_number_integer()) return {}; + look = " sage"; + const int value = std::clamp(m.at("fans").get(), 0, 100); + const std::string mood = value >= 80 ? "Euphorisch" : value >= 60 ? "Zuversichtlich" : value >= 40 ? "Abwartend" : "Unzufrieden"; + // a gauge: half a ring, filled as far as the mood goes + const auto gauge = [&](double w) { + const double r = w / 2 - 24, cx = w / 2, cy = r + 24, angle = 3.14159265 * (1 - value / 100.0); + const double ex = cx + r * std::cos(angle), ey = cy - r * std::sin(angle); + const std::string svg = ""; + return "
" + picture(renderer_.diagram("hw-gauge-" + std::to_string(int(w)) + "-" + theme_, svg, int(w * 1.5)), w, cy + 24) + "" + std::to_string(value) + "
"; + }; + if (one) return kicker("Fans") + "
" + gauge(230) + "
"; + if (flat) return kicker("Fan-Stimmung") + "
" + gauge(250) + "
" + tag(mood, value < 40) + foot("von 100 Punkten") + "
"; + return kicker("Fan-Stimmung") + "
" + gauge(std::min(inner_w - 60, 460.0)) + "
" + tag(mood, value < 40) + "
"; + } + if (type == "own-curve" || type == "opponent-curve" || type == "comparison-curve") { + const bool self = type == "own-curve", both = type == "comparison-curve"; + const Json &team = self || both ? own : opponent; + if (!team.is_object()) return {}; + const auto mine = places("own_curve"), theirs = places("opponent_curve"); + if (one) return kicker(self ? "Platz" : "Gegner") + "
" + big(team.value("rank", std::string("—")) + ".", 120) + "
" + esc(self ? "Stärke " + team.value("strength", std::string("—")) : team.value("name", std::string())) + ""; + std::vector, std::string>> series; + if (self || both) series.push_back({mine, own_ink}); + if (!self) series.push_back({theirs, other_ink}); + bool enough = false; + for (const auto &[row, colour] : series) enough = enough || row.size() >= 2; + const std::string title = both ? "Tabellenplätze · Vergleich" : "Tabellenplatz · " + team.value("name", std::string()); + if (!enough) return kicker(title) + "
Die Kurve beginnt nach dem zweiten Spieltag.
"; + return kicker(title) + notebook_chart(type + std::to_string(cols) + std::to_string(rows), series, inner_w, inner_h - 50); + } + if (type == "results") { + const auto &rows_ = m.at("results"); + if (!rows_.is_array() || rows_.empty()) return kicker("Letzte Spiele") + "
Noch kein Spiel gespielt.
"; + int won = 0, drawn = 0, lost = 0; + const size_t count = std::min(rows_.size(), 6); + const double chip = std::min(96.0, (inner_w - (double(count) - 1) * 13) / double(count)); + std::string chips = "
"; + for (size_t i = rows_.size() - count; i < rows_.size(); ++i) { + const auto form = rows_[i].value("form", std::string("U")); + ++(form == "S" ? won : form == "N" ? lost : drawn); + chips += "
" + esc(form) + "" + + esc(rows_[i].value("score", std::string())) + "
"; + } + chips += "
"; + const std::string title = count == 1 ? "Letztes Spiel" : "Letzte " + std::to_string(count) + " Spiele"; + if (flat) return kicker(title) + chips; + const int points = won * 3 + drawn; + return kicker(title) + chips + "
" + lines({{"Siege", std::to_string(won)}, {"Remis", std::to_string(drawn)}, {"Niederlagen", std::to_string(lost)}}) + foot(std::to_string(points) + " von " + std::to_string(count * 3) + " Punkten"); + } + if (type == "portrait" || type == "crest" || type == "opponent-crest") { + // a photograph in a white frame, stuck to the page with a strip of tape + const Json &team = type == "crest" ? own : opponent; + std::string picture_markup, caption; + const double d = one ? 214 : 430; + if (type == "portrait") { + const auto key = text_of("portrait"); + if (key.empty()) return {}; + picture_markup = "
" + img(key, d, d, false, true, 768) + "
"; + caption = text_of("manager"); + } else { + if (!team.is_object()) return {}; + picture_markup = "
" + notebook_crest(team.at("team"), d * .8) + "
"; + caption = team.value("name", std::string()); + } + look = std::string(" photo") + (type == "portrait" ? " turn-a" : type == "crest" ? " turn-b" : " turn-c"); + return "" + picture_markup + "" + esc(caption) + ""; + } + if (type == "own-summary" || type == "opponent-summary") { + const Json &team = type == "own-summary" ? own : opponent; + if (!team.is_object()) return {}; + const auto strength = team.value("strength", std::string("—")); + int value = 0; + try { value = std::stoi(strength); } catch (const std::exception &) {} + return kicker(team.value("name", std::string())) + big("Platz " + team.value("rank", std::string("—")), 58) + "
Stärke
" + esc(strength) + "
"; + } + if (type == "duels") { + if (!m.at("duels").is_object()) return {}; + const auto &d = m.at("duels"); + const auto column = [](int n, const char *name, const char *css) { return "
" + std::to_string(n) + "" + name + "
"; }; + return kicker("Direkter Vergleich") + "
" + column(d.value("won", 0), "Siege", "won") + column(d.value("drawn", 0), "Remis", "") + column(d.value("lost", 0), "Niederlagen", "lost") + "
"; + } + return {}; +} + +// The open home page for the values of `m`: the grid, the cards, and an open menu. +std::string App::notebook_home(const Json &m) { + home_model_ = m; + const auto &page = notebook_pages().at("pages")[size_t(home_page_)]; + const double top = notebook_top() + home_top; + const auto place = [](int col, int row, int cols, int rows) { + return rect((col - 1) * (home_cell_w + home_gap), (row - 1) * (home_cell_h + home_gap), cols * home_cell_w + (cols - 1) * home_gap, rows * home_cell_h + (rows - 1) * home_gap); + }; + std::string out = "
"; + for (int row = 1; row <= home_rows; ++row) + for (int col = 1; col <= home_columns; ++col) out += ""; + out += "
"; + bool any = false; + for (const auto &card : page.at("cards")) { + const auto type = card.at("type").get(); + const int cols = card.at("cols"), rows = card.at("rows"); + std::string look; + const auto body = notebook_card(type, cols, rows, m, look); + if (body.empty()) continue; + any = true; + std::string route; + for (const auto &d : widget_catalogue()) + if (d.at("id") == type) route = d.value("route", std::string()); + const bool one = cols == 1 && rows == 1; + out += "
" + body + "
"; + } + if (!any) out += "
Leere Seite – rechte Maustaste, um Widgets hinzuzufügen
"; + out += "
"; + // the menu of a card, of the free page or of a page's marker + if (home_menu_.is_object()) { + const auto kind = home_menu_.value("kind", std::string()); + std::string title, body; + const auto item = [](const std::string &command, const std::string &label, const std::string ¬e, bool enabled, bool warn = false) { + return btn("home-do", "" + esc(label) + "" + esc(note) + "", std::string("hw-menu-item") + (warn ? " warn" : ""), "data-id=\"" + command + "\"" + (enabled ? "" : " disabled=\"disabled\"")); + }; + const auto &cards = page.at("cards"); + if (kind == "card") { + const auto type = home_menu_.value("type", std::string()); + const auto *definition = home_kind(type); + const auto found = std::find_if(cards.begin(), cards.end(), [&](const Json &c) { return c.at("type") == type; }); + if (definition && found != cards.end()) { + title = definition->label; + body += "
"; + for (const auto &[cols, rows] : definition->sizes) { + const bool current = found->at("cols") == cols && found->at("rows") == rows; + const bool room = current || home_free(cards, cols, rows, type, found->at("col"), found->at("row")).has_value(); + body += btn("home-do", std::to_string(cols) + " × " + std::to_string(rows), current ? "primary" : "", "data-id=\"size:" + std::to_string(cols) + "x" + std::to_string(rows) + "\"" + (room ? "" : " disabled=\"disabled\"")); + } + body += "
" + item("remove", "Widget entfernen", "", true, true); + } + } else if (kind == "grid") { + title = "Widget hinzufügen"; + for (const auto &definition : home_kinds()) { + const bool lying = std::any_of(cards.begin(), cards.end(), [&](const Json &c) { return c.at("type") == definition.type; }); + std::string look; + const auto usual = definition.sizes[definition.usual]; + const bool known = !notebook_card(definition.type, usual.first, usual.second, m, look).empty(); + bool room = false; + for (const auto &[cols, rows] : definition.sizes) room = room || home_free(cards, cols, rows, "", home_menu_.value("col", 1), home_menu_.value("row", 1)).has_value(); + if (!known) continue; + body += item(std::string("add:") + definition.type, definition.label, lying ? "liegt schon" : room ? "" : "kein Platz", !lying && room); + } + body += item("clear", "Alle Widgets entfernen", "", !cards.empty(), true); + if (home_page_ == 0) body += item("reset", "Standard wiederherstellen", "", true); + } else if (kind == "page") { + const int index = home_menu_.value("index", 0); + const auto count = home_.at("pages").size(); + title = home_.at("pages")[size_t(index)].at("name").get(); + body += item("rename", "Umbenennen", "", true) + item("new", "Neue Seite", std::to_string(count) + " / " + std::to_string(home_pages), count < size_t(home_pages)) + item("delete", "Seite löschen", index == 0 ? "Standardseite" : "", index != 0, true); + } + const double x = std::clamp(home_menu_.value("x", 0.0), 20.0, 3840.0 - 700), y = std::clamp(home_menu_.value("y", 0.0), 20.0, desktop_height() - 1500.0); + out += btn("home-do", "", "hw-menu-back", "data-id=\"close\" aria-label=\"Menü schließen\" style=\"height:" + scalar(desktop_height()) + "dp;\"") + "
" + + esc(title) + "" + body + "
"; + } + // naming a page + if (home_rename_ >= 0 && home_rename_ < int(home_.at("pages").size())) { + out += btn("home-do", "", "hw-menu-back dim", "data-id=\"rename-cancel\" aria-label=\"Abbrechen\" style=\"height:" + scalar(desktop_height()) + "dp;\"") + "
Seite benennen()) + "\"/>
" + + btn("home-do", "Abbrechen", "", "data-id=\"rename-cancel\"") + btn("home-do", "Speichern", "primary", "id=\"home-rename-save\" data-id=\"rename-save\"") + "
"; + } + return out; +} + +// One command of a home menu (see notebook_home). +void App::notebook_home_do(const std::string &command) { + auto &pages = notebook_pages().at("pages"); + auto &cards = pages[size_t(home_page_)].at("cards"); + const auto menu = home_menu_; + home_menu_ = nullptr; + const auto type = menu.is_object() ? menu.value("type", std::string()) : std::string(); + const auto card = std::find_if(cards.begin(), cards.end(), [&](const Json &c) { return c.at("type") == type; }); + if (command == "close") { refresh(); return; } + if (command.starts_with("size:") && card != cards.end()) { + const auto cross = command.find('x'); + const int cols = std::stoi(command.substr(5, cross - 5)), rows = std::stoi(command.substr(cross + 1)); + if (const auto at = home_free(cards, cols, rows, type, card->at("col"), card->at("row"))) { + (*card)["cols"] = cols; (*card)["rows"] = rows; (*card)["col"] = at->first; (*card)["row"] = at->second; + } + } else if (command == "remove" && card != cards.end()) cards.erase(card); + else if (command.starts_with("add:")) { + const auto *definition = home_kind(command.substr(4)); + if (definition) { + // the usual size first, then the others from the smallest + auto sizes = definition->sizes; + std::stable_sort(sizes.begin(), sizes.end(), [](const auto &a, const auto &b) { return a.first * a.second < b.first * b.second; }); + sizes.insert(sizes.begin(), definition->sizes[definition->usual]); + for (const auto &[cols, rows] : sizes) + if (const auto at = home_free(cards, cols, rows, "", menu.value("col", 1), menu.value("row", 1))) { + cards.push_back({{"type", definition->type}, {"cols", cols}, {"rows", rows}, {"col", at->first}, {"row", at->second}}); + break; + } + } + } else if (command == "clear") cards = Json::array(); + else if (command == "reset") pages[0] = home_default().at("pages")[0]; + else if (command == "rename") { home_rename_ = menu.value("index", home_page_); focus_after_render_ = "home-rename-input"; refresh(); return; } + else if (command == "new") { + if (pages.size() < size_t(home_pages)) { + pages.push_back({{"name", "Seite " + std::to_string(pages.size() + 1)}, {"cards", Json::array()}}); + home_page_ = int(pages.size()) - 1; + home_rename_ = home_page_; + focus_after_render_ = "home-rename-input"; + } + } else if (command == "delete") { + const int index = menu.value("index", -1); + if (index > 0 && index < int(pages.size())) { pages.erase(pages.begin() + index); home_page_ = 0; } + } else if (command == "rename-cancel") { home_rename_ = -1; refresh(); return; } + else if (command == "rename-save") { + std::string name; + if (auto *input = dynamic_cast(element("home-rename-input"))) name = input->GetValue(); + while (!name.empty() && name.back() == ' ') name.pop_back(); + if (!name.empty() && home_rename_ >= 0 && home_rename_ < int(pages.size())) pages[size_t(home_rename_)]["name"] = name.substr(0, 32); + home_rename_ = -1; + } else if (command.starts_with("page:")) { + home_page_ = std::clamp(std::stoi(command.substr(5)), 0, int(pages.size()) - 1); + refresh(); + return; + } + notebook_pages_changed(); +} + +// The mouse on the home page: menus with the right button, moving a card by dragging it. +// Returns true when the event is used up. +bool App::notebook_home_event(Rml::Event &event) { + if (!(scene_ == "desktop" || scene_ == "engine") || !menu_.empty() || !popup_.empty() || !doc_->QuerySelector("#notebook")) return false; + const auto type = event.GetType(); + auto *target = event.GetTargetElement(); + const auto mouse = [&] { return Rml::Vector2f{(event.GetParameter("mouse_x", 0) - float(canvas_left_)) / float(scale_), (event.GetParameter("mouse_y", 0) - float(canvas_top_)) / float(scale_)}; }; + const auto up = [&](const auto &wanted) -> Rml::Element * { + for (auto *n = target; n && n != doc_; n = n->GetParentNode()) + if (wanted(n)) return n; + return nullptr; + }; + auto *card = up([](Rml::Element *n) { return n->IsClassSet("hw") && n->HasAttribute("data-widget"); }); + const bool right = event.GetParameter("button", 0) == 1; + if (type == "contextmenu") return true; + if (type == "keydown" && event.GetParameter("key_identifier", 0) == Rml::Input::KI_ESCAPE && (home_menu_.is_object() || home_rename_ >= 0)) { + home_menu_ = nullptr; home_rename_ = -1; refresh(); event.StopImmediatePropagation(); + return true; + } + if (type == "keydown" && event.GetParameter("key_identifier", 0) == Rml::Input::KI_RETURN && home_rename_ >= 0) { notebook_home_do("rename-save"); event.StopImmediatePropagation(); return true; } + if (home_rename_ >= 0 && type != "click") return false; + if (type == "mousedown" && right) { + const auto at = mouse(); + auto *marker = up([](Rml::Element *n) { return n->GetId().starts_with("page-home-"); }); + auto *grid = up([](Rml::Element *n) { return n->GetId() == "notebook-home"; }); + if (card) home_menu_ = {{"kind", "card"}, {"type", card->GetAttribute("data-widget", "")}, {"x", at.x}, {"y", at.y}}; + else if (marker) home_menu_ = {{"kind", "page"}, {"index", marker->GetAttribute("data-index", 0)}, {"x", at.x}, {"y", at.y}}; + else if (grid) { + const double gx = at.x - home_left, gy = at.y - (notebook_top() + home_top); + home_menu_ = {{"kind", "grid"}, {"col", std::clamp(int(gx / (home_cell_w + home_gap)) + 1, 1, home_columns)}, {"row", std::clamp(int(gy / (home_cell_h + home_gap)) + 1, 1, home_rows)}, {"x", at.x}, {"y", at.y}}; + } else return false; + refresh(); + return true; + } + if (type == "mousedown" && !right && card && !home_menu_.is_object() && !up([](Rml::Element *n) { return n->GetTagName() == "button" || n->HasAttribute("data-interactive"); })) { + home_drag_ = {{"type", card->GetAttribute("data-widget", "")}, {"x", mouse().x}, {"y", mouse().y}, {"moved", false}}; + return false; + } + if (type == "mousemove" && home_drag_.is_object()) { + const auto at = mouse(); + const double dx = at.x - home_drag_.at("x").get(), dy = at.y - home_drag_.at("y").get(); + if (!home_drag_.at("moved").get() && std::hypot(dx, dy) < 12) return false; + const auto &cards = notebook_pages().at("pages")[size_t(home_page_)].at("cards"); + const auto id = home_drag_.at("type").get(); + const auto found = std::find_if(cards.begin(), cards.end(), [&](const Json &c) { return c.at("type") == id; }); + auto *moving = element("object-" + id); + auto *ghost = element("hw-ghost"); + if (found == cards.end() || !moving || !ghost) { home_drag_ = nullptr; return false; } + const int cols = found->at("cols"), rows = found->at("rows"); + const int col = std::clamp(int(std::lround(found->at("col").get() + dx / (home_cell_w + home_gap))), 1, home_columns + 1 - cols), row = std::clamp(int(std::lround(found->at("row").get() + dy / (home_cell_h + home_gap))), 1, home_rows + 1 - rows); + const bool fits = home_fits(cards, col, row, cols, rows, id); + home_drag_["moved"] = true; home_drag_["col"] = col; home_drag_["row"] = row; home_drag_["fits"] = fits; + moving->SetProperty("transform", "translate(" + scalar(dx) + "dp," + scalar(dy) + "dp) scale(1.03)"); + moving->SetProperty("z-index", "20"); + ghost->SetProperty("left", scalar((col - 1) * (home_cell_w + home_gap)) + "dp"); + ghost->SetProperty("top", scalar((row - 1) * (home_cell_h + home_gap)) + "dp"); + ghost->SetProperty("width", scalar(cols * home_cell_w + (cols - 1) * home_gap) + "dp"); + ghost->SetProperty("height", scalar(rows * home_cell_h + (rows - 1) * home_gap) + "dp"); + ghost->SetClass("shown", true); + ghost->SetClass("bad", !fits); + if (auto *cells = element("hw-cells")) cells->SetClass("shown", true); + dirty_ = true; + return true; + } + if (type == "mouseup" && home_drag_.is_object()) { + const auto drag = home_drag_; + home_drag_ = nullptr; + if (!drag.at("moved").get()) return false; + home_swallow_click_ = true; + if (drag.value("fits", false)) { + for (auto &c : notebook_pages().at("pages")[size_t(home_page_)].at("cards")) + if (c.at("type") == drag.at("type")) { c["col"] = drag.at("col"); c["row"] = drag.at("row"); } + notebook_pages_changed(); + } else refresh(); + return true; + } + if (type == "click") { + if (home_swallow_click_) { home_swallow_click_ = false; return true; } + if (auto *node = up([](Rml::Element *n) { return n->GetAttribute("data-action", "") == "home-do" && !n->HasAttribute("disabled"); })) { + notebook_home_do(node->GetAttribute("data-id", "")); + return true; + } + } + return false; +} + +// The newest messages of the inbox for the news card. +Json App::notebook_news() { + const auto data = news_data("inbox", ""); + if (!data.value("ok", false)) return nullptr; + Json items = Json::array(); + const auto &raw_items = engine_mode_ ? engine_news_value_.at("items") : snap().state.at("news").at("items"); + const auto &shown = data.at("items"); + for (const auto &raw : raw_items) { + if (raw.at("folder") != "inbox") continue; + const auto found = std::find_if(shown.begin(), shown.end(), [&](const auto &m) { return m.at("id") == raw.at("id"); }); + if (found == shown.end()) continue; + items.push_back({{"title", found->at("title")}, {"date", found->at("display_date")}, {"unread", found->at("read") == false}}); + if (items.size() == 13) break; + } + return {{"unread", data.at(engine_mode_ ? "shown_unread" : "unread")}, {"items", items}}; +} + +// The warning lamps with the short names the small cards use. +Json App::notebook_lamps(Json lamps) { + static constexpr std::array names{"Aktien", "Konto", "Werbung", "Training", "Erschöpfung", "Startelf", "Ersatz", "Taktik", "Verträge", "Lizenz"}; + for (size_t i = 0; i < lamps.size() && i < names.size(); ++i) lamps[i]["short"] = names[i]; + return lamps; +} diff --git a/src/modern/ui/screens.inc b/src/modern/ui/screens.inc index a1b0e19..d44879f 100644 --- a/src/modern/ui/screens.inc +++ b/src/modern/ui/screens.inc @@ -46,37 +46,33 @@ std::string App::render_desktop() { widget_data_=demo_desktop_widgets(*world_,s.state); const bool national=s.state.at("career").value("role", "club")=="national"; const auto *c = club(s); - std::string out = - "
" + - btn("desktop-context", - (national?img("career.national-de",82,82,false,false,256):crest(c,82)) + "" + esc(national?"Deutschland":c ? world_->name(*c) : "") + - "" + esc(manager(s).value("name", "")) + - "", - "identity", "id=\"desktop-identity\"") + - "
" + std::string(widget_data_.at("matchday")==0?"Saisonvorbereitung":std::to_string(widget_data_.at("matchday").get())+". Spieltag") + "" + - esc(widget_data_.at("season").get()) + - "
"+std::string(national?"Aufgabenbereich":"Guthaben")+"()) + "\">" + - (national?std::string("Nationalmannschaft"):cash(s.state.value("cash", int64_t(0)))) + "
"; - if(desktop_.value("grid",true))for(int row=0;row<7;++row)for(int col=0;col<15;++col)out+=""; - for (const auto &[id, o] : desktop_["objects"].items()) { - if (!o.value("visible", false) || (o.value("widget",false)?!demo_career_widget_available(s.state,id):!demo_career_menu_available(s.state,id.substr(4)))) - continue; - const auto style = rect(o.value("x", 0), o.value("y", 0), o.value("w", 224), - o.value("h", 224)) + "z-index:" + std::to_string(o.value("z", 1)) + ";"; - if (o.value("widget", false)) { - std::string size="s",route; - for(const auto &d:widget_catalogue())if(d.at("id")==id){route=d.value("route","");for(const auto &[key,span]:d.at("spans").items())if(o.at("w")==span[0].get()*248-24&&o.at("h")==span[1].get()*248-24)size=key;} - out += "
" + - widget(id, o) + - (o.value("pinned", true) ? "
" : "") + - "
"; - } else { - const auto route = id.substr(4); - out += desktop_button(id, o, "open:" + route); - } - } - return out + "
"; + // the head of the page: the club and its manager, the day, the cash + const std::string matchday = widget_data_.at("matchday")==0?"Saisonvorbereitung":std::to_string(widget_data_.at("matchday").get())+". Spieltag"; + const auto *rival = world_->find("clubs", widget_data_.at("opponent").get()); + const std::string own_name = national?"Deutschland":c ? world_->name(*c) : "", rival_name = national?"Frankreich":rival ? world_->name(*rival) : ""; + const std::string head = + "" + esc(widget_data_.at("weekday").get() + ", " + std::to_string(widget_data_.at("day").get()) + ". " + widget_data_.at("month").get()) + "
Nächstes Spiel: " + + esc(rival_name) + " (H)" + esc(national?std::string("Nationalmannschaft"):cash(s.state.value("cash", int64_t(0)))) + "
"; + std::string out = notebook_shell([&](const std::string &route) { return demo_career_menu_available(s.state, route); }, head); + if (!menu_.empty()) return out; + // the home page: the values of its cards + const Json own_team = national ? Json{{"image", "career.national-de"}} : Json{{"id", widget_data_.at("own")}}; + const Json rival_team = national ? Json{{"image", "career.national-fr"}} : Json{{"id", widget_data_.at("opponent")}}; + Json results = Json::array(); + for (size_t i = 0; i < widget_data_.at("form").size(); ++i) results.push_back({{"form", widget_data_.at("form")[i]}, {"score", widget_data_.at("scores")[i]}}); + const Json model = { + {"day", widget_data_.at("day")}, {"weekday", widget_data_.at("weekday")}, {"month", widget_data_.at("month")}, {"note", matchday + " · " + widget_data_.at("season").get()}, + {"cash", national ? Json("—") : Json(cash(s.state.value("cash", int64_t(0))))}, {"savings", national ? Json(nullptr) : Json(cash(s.state.at("deposit")))}, + {"ticket", national ? Json(nullptr) : Json(std::to_string(s.state.at("ticket").get()) + " " + money_unit())}, {"ticket_action", "ticket"}, + {"fixture", {{"home", {{"name", own_name}, {"team", own_team}}}, {"away", {{"name", rival_name}, {"team", rival_team}}}, {"competition", "Freundschaftsspiel"}, {"venue", "Heimspiel"}}}, + {"own", {{"name", own_name}, {"team", own_team}, {"rank", std::to_string(widget_data_.at("own_rank").get())}, {"strength", std::to_string(widget_data_.at("own_strength").get())}}}, + {"opponent", {{"name", rival_name}, {"team", rival_team}, {"rank", std::to_string(widget_data_.at("opponent_rank").get())}, {"strength", std::to_string(widget_data_.at("opponent_strength").get())}}}, + {"own_curve", national ? Json::array() : widget_data_.at("own_curve")}, {"opponent_curve", national ? Json::array() : widget_data_.at("opponent_curve")}, + {"results", national ? Json::array() : results}, {"warnings", notebook_lamps(widget_data_.at("warnings"))}, {"fans", national ? Json(nullptr) : widget_data_.at("fans")}, + {"news", notebook_news()}, + {"portrait", std::string(manager(s).value("portrait_style", std::string("photo")) == "painted" ? "manager-painted." : "manager.") + std::to_string(manager(s).value("portrait", 0))}, + {"manager", manager(s).value("name", "")}, {"duels", national ? Json(nullptr) : Json{{"won", 2}, {"drawn", 1}, {"lost", 3}}}}; + return out + notebook_home(model); } std::string App::render_camp() { const auto index_file = @@ -239,7 +235,7 @@ std::string App::render_menu(const std::string &key) { {"stocks", "Aktien"}, {"credit", "Kredit"}, {"overview", "Finanzübersicht"}}; if (labels.contains(bank_view_)) heading += " · " + labels.at(bank_view_); } - return "
" + + return "
" + window(heading, body) + (key == "statistics" ? render_statistics_trophy() : "") + "
"; } diff --git a/src/modern/ui/view.cpp b/src/modern/ui/view.cpp index 191aeef..4ae2632 100644 --- a/src/modern/ui/view.cpp +++ b/src/modern/ui/view.cpp @@ -199,6 +199,21 @@ public: const auto &r = entries_.at(token).raster; return {token, r.width, r.height}; } + // A picture computed by the program itself; `key` names its variant (e.g. the skin). + Picture texture(const std::string &slot, const std::string &key, const std::function &make) { + const auto token = "modern-texture-" + slot + ".png"; + auto found = entries_.find(token); + if (found == entries_.end() || found->second.key != key) { + if (const auto loaded = loaded_sources_.find(token); loaded != loaded_sources_.end()) { + Rml::ReleaseTexture(loaded->second, this); + loaded_sources_.erase(loaded); + } + auto raster = make(); + entries_[token] = {key, false, raster.width, std::move(raster)}; + } + const auto &r = entries_.at(token).raster; + return {token, r.width, r.height}; + } Picture generated_png(const std::string &slot,const std::string &png){ const auto token="modern-generated-"+slot+".png",digest=content::sha256(png); auto found=entries_.find(token); @@ -639,7 +654,7 @@ class App final : public Rml::EventListener { {"lineup", "bench"}, {"tactics", "bench"}, {"squad", "locker"}, {"contracts", "locker"}, {"transfer", "press"}, {"tables", "stand"}, {"league", "stand"}, {"other", "stand"}, {"strengths", "stand"}, {"statistics", "kickoff"}, {"scorers", "kickoff"}, {"fairplay", "kickoff"}}; - if (theme_ != "silver") return {}; + if (theme_ != "silver" || notebook_page()) return {}; const auto found = motifs.find(menu_); for (const std::string motif : {found == motifs.end() ? std::string("ball") : found->second, std::string("ball")}) { const auto key = "art.paper-" + motif + ".png"; @@ -667,11 +682,15 @@ class App final : public Rml::EventListener { } } catch (const std::exception &) { } - return "
" + + // on a page of the notebook the sheet has no frame of its own and lies where the book lies + const bool page = notebook_page(); + if (page) club_mark.clear(); + return (page ? "
" + : "
") + (close ? btn("close", "×", "close", "id=\"window-close\" aria-label=\"" + std::string(menu_ == "bank" && bank_view_ != "entrance" ? "Zurück zur Bankhalle" : "Fenster schließen") + "\"") : "") + "

" + esc(heading) + "

" + club_mark + "
" + window_art() + "
" + - content + "
" + (amount_ ? render_amount() : "") + "
"; + content + "
" + (amount_ ? render_amount() : "") + "
" + (page ? "
" : ""); } std::string select(const std::string &id, @@ -835,6 +854,28 @@ class App final : public Rml::EventListener { int calendar_month_ = -1, calendar_from_ = 0; std::string calendar_anim_; std::string render_calendar_year(); + // the career's notebook (notebook.inc) + double notebook_top() const; + std::string notebook_section_of(const std::string &route) const; + std::string notebook_shell(const std::function &enabled, const std::string &head); + Picture notebook_art(); + // the home page (notebook_home.inc) + std::string notebook_crest(const Json &team, double size); + std::string notebook_chart(const std::string &slot, const std::vector, std::string>> &series, double w, double h); + std::string notebook_card(const std::string &type, int cols, int rows, const Json &model, std::string &look); + Json ¬ebook_pages(); + void notebook_pages_changed(); + void notebook_home_do(const std::string &command); + bool notebook_home_event(Rml::Event &event); + // the home pages and their cards; an open menu, a page being named, a card being dragged + Json home_, home_menu_, home_drag_, home_model_; + int home_page_ = 0, home_rename_ = -1; + bool home_swallow_click_ = false; + std::string notebook_home(const Json &model); + Json notebook_news(); + static Json notebook_lamps(Json lamps); + // a career menu is a page of the notebook, not a window of its own + bool notebook_page() const { return (scene_ == "desktop" || scene_ == "engine") && !menu_.empty(); } bool calendar_month_action(const std::string &, Rml::Element *); void calendar_open_month(int); Json planning_calendar() const; @@ -983,7 +1024,8 @@ class App final : public Rml::EventListener { } // Called after the stage was rebuilt: zoom in when it now shows a menu window. void sync_window_zoom() { - const bool wanted = doc_->QuerySelector(".window") != nullptr || doc_->QuerySelector(".live-stage") != nullptr; + // a page of the notebook is no window: the book keeps the whole stage + const bool wanted = (doc_->QuerySelector(".window") != nullptr && doc_->QuerySelector(".nb-sheet") == nullptr) || doc_->QuerySelector(".live-stage") != nullptr; if (!wanted) window_shown_ = "\x01"; // the career's desk hangs from the top edge of a taller screen, so its bar is the // screen's bar and the spare height shows the stadium below @@ -1708,6 +1750,8 @@ public: #include "modern/ui/engine_almanac.inc" #include "modern/ui/engine_reports.inc" #include "modern/ui/calendar_year.inc" +#include "modern/ui/notebook.inc" +#include "modern/ui/notebook_home.inc" #include "modern/ui/finance_simulation.inc" #include "modern/ui/statistics_analysis.inc" #include "modern/ui/engine_rankings.inc"