Paper windows, a display serif and chalk hand, a symmetric tactics board, the match day as a stage

- Material: menu windows are sheets of paper (warm surface, edge, two sheets beneath,
  serif headings) that slide in once when their menu opens; the desk stays glass.
  Source Serif 4 and Cabin Sketch ship in assets/modern/fonts (SIL OFL, see
  THIRD_PARTY_NOTICES.md); system fonts remain the fallback.
- Tactics board: 320 x 200 units mirrored about its middle - the pitch of the
  attitude on the left, six equal tiles for the play settings on the right with
  their names in chalk, the commitment with a scale across the foot.
- Live match: a 4:3 sheet like the menus (same window zoom) on the darkened stadium.
  One score board per match of a human manager - a full-width card for one match,
  two side by side, a 2 x 2 grid for three or four - with crests, a score plate in
  the clubs' colours (read from the crests), a clock ring, a pressure bar, and a
  time line of goals, cards and injuries. Compact ticker rows with a mark per kind,
  a goal banner on the card, a horizontal speed control, and optional halts at half
  time and when falling behind.
- QA: script command demo-start begins a demo career with 1-4 managers.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
MichaelandClaude Fable 5.2 committed 2026-11-14 16:15:11 +01:00
1 parent 54fef90a5b
commit 9b5d448fb6
21 files changed
+887 -125

No files matched your search

+7
View File
@@ -69,6 +69,13 @@ foreach(icon ${modern_icons})
get_filename_component(icon_name "${icon}" NAME)
configure_file("${icon}" "${modern_assets}/icons/${icon_name}" COPYONLY)
endforeach()
# the display serif and the chalk hand (SIL Open Font License, THIRD_PARTY_NOTICES.md)
file(GLOB modern_fonts CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/assets/modern/fonts/*")
file(MAKE_DIRECTORY "${modern_assets}/fonts")
foreach(font ${modern_fonts})
get_filename_component(font_name "${font}" NAME)
configure_file("${font}" "${modern_assets}/fonts/${font_name}" COPYONLY)
endforeach()
foreach(weight Regular Bold Italic BoldItalic)
configure_file("${rmlui_SOURCE_DIR}/Samples/assets/LatoLatin-${weight}.ttf"
"${modern_assets}/LatoLatin-${weight}.ttf" COPYONLY)
+19
View File
@@ -983,6 +983,25 @@ void App::script() {
frame();
SDL_Delay(5);
}
} else if (type == "demo-start") {
// QA: begin a demo career with `managers` human managers (1-4), each at a club of
// its own, so the match day can be looked at with several matches at once
if (engine_mode_ || !source_) throw editor::Error("demo-start braucht die UI-Demo.");
const int wanted = std::clamp(command.value("managers", 1), 1, 4);
Json managers = Json::array();
const int step = std::max(1, command.value("step", 2));
int skip = 0;
for (const auto *club : world_->clubs()) {
if (int(managers.size()) >= wanted) break;
const auto id = club->value("id", std::string());
if (!world_->manageable(id) || skip++ % step) continue;
managers.push_back({{"name", "Manager " + std::to_string(managers.size() + 1)}, {"club", id}, {"portrait", int(managers.size())},
{"portrait_style", "photo"}, {"strength_choice", 1}});
}
const auto result = source_->apply({source_->snapshot().revision, "start",
{{"setup", {{"duration", 5}, {"difficulty", 3}, {"players", managers.size()}, {"mode", 3}, {"league", true}, {"world", true}}}, {"managers", managers}}});
if (!result.ok) throw editor::Error("demo-start: " + result.error);
scene_ = "desktop"; menu_.clear(); refresh();
} else if (type == "screenshot")
screenshot(editor::path(command.at("path").get<std::string>()));
else if (type == "checkpoint") {
+81 -59
View File
@@ -272,26 +272,33 @@ std::string tactics_diagram(const Json &state, const std::string &theme,
ring(x + w / 2, y + h / 2, h * .14, chalk, .7);
};
out << "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 295 206'>";
// frame and slate; the wiped patches of an often used board
out << "<rect x='4' y='1' width='272' height='159' rx='3' fill='#6b4a2e'/>"
"<rect x='4.8' y='1.8' width='270.4' height='157.4' rx='2.5' fill='none' stroke='#8a6540' stroke-width='.6'/>"
"<rect x='7.5' y='4.5' width='265' height='152' rx='1.2' fill='"
<< slate << "'/><rect x='7.5' y='4.5' width='265' height='152' rx='1.2' fill='none' stroke='#16261f' stroke-opacity='.55' stroke-width='1'/>";
for (int i = 0; i < 9; ++i) {
const double cx = 40 + i * 27 + wobble(12), cy = 30 + (i % 3) * 45 + wobble(14);
out << "<ellipse cx='" << cx << "' cy='" << cy << "' rx='" << 26 + wobble(9) << "' ry='" << 9 + wobble(4)
// The board, 320 x 200 units (the screen draws it at 8dp a unit), mirrored about its
// middle: the pitch of the attitude on the left, six tiles for the play settings on the
// right, the commitment across the foot. The screen writes the names in chalk under them.
out << "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 320 200'>";
out << "<rect x='0' y='0' width='320' height='192' rx='3' fill='#6b4a2e'/>"
"<rect x='1' y='1' width='318' height='190' rx='2.5' fill='none' stroke='#8a6540' stroke-width='.7'/>"
"<rect x='5' y='5' width='310' height='182' rx='1.2' fill='"
<< slate << "'/><rect x='5' y='5' width='310' height='182' rx='1.2' fill='none' stroke='#16261f' stroke-opacity='.55' stroke-width='1'/>";
for (int i = 0; i < 10; ++i) {
const double cx = 34 + i * 28 + wobble(12), cy = 34 + (i % 3) * 52 + wobble(14);
out << "<ellipse cx='" << cx << "' cy='" << cy << "' rx='" << 28 + wobble(9) << "' ry='" << 10 + wobble(4)
<< "' fill='#ffffff' fill-opacity='" << .022 + (i % 2) * .012 << "' transform='rotate(" << -14 + wobble(10) << ' ' << cx << ' ' << cy << ")'/>";
}
// chalk tray with two pieces of chalk
out << "<rect x='96' y='160' width='88' height='3.2' rx='.8' fill='#58391f'/>"
"<rect x='112' y='158.3' width='9' height='1.7' rx='.5' fill='#f1efe2'/>"
"<rect x='127' y='158.5' width='6' height='1.6' rx='.5' fill='#f3d977' transform='rotate(-6 130 159)'/>";
out << "<rect x='116' y='192' width='88' height='3.4' rx='.8' fill='#58391f'/>"
"<rect x='134' y='190.2' width='9' height='1.8' rx='.5' fill='#f1efe2'/>"
"<rect x='150' y='190.4' width='6' height='1.7' rx='.5' fill='#f3d977' transform='rotate(-6 153 191)'/>";
// the line between the halves and the one above the commitment
line(160, 22, 160, 124, chalk, .5, true);
line(20, 134, 300, 134, chalk, .5, true);
// the scale under the commitment slider: one tick a step, longer at the ends and the middle
for (int i = 0; i <= 11; ++i) {
const double x = 22.2 + i * 24.03;
line(x, 157, x, i == 0 || i == 11 ? 164 : i % 5 == 0 ? 162.5 : 160.5, chalk, .7);
}
field(19, 9, 104, 62);
field(19, 82, 104, 62);
field(137, 10, 58, 37);
field(205, 10, 58, 37);
// attitude: the eleven with the way they lean
field(20, 30, 132, 84);
std::array<std::pair<int, int>, 10> formation = {{{5, 1}, {5, 3}, {5, 5}, {5, 7}, {10, 1}, {10, 3}, {10, 5}, {10, 7}, {16, 3}, {16, 5}}};
if (!lineup_points.is_null()) {
if (!lineup_points.is_array() || lineup_points.size() != 11)
@@ -308,52 +315,67 @@ std::string tactics_diagram(const Json &state, const std::string &theme,
}
}
for (const auto &[x, y] : formation) {
const double px = 25 + x / double(depth_max) * 82, py = 16 + y / double(lane_max) * 49;
arrow(px, py, std::array<int, 4>{-16, -7, 7, 16}[size_t(values[0])], 0);
const double px = 30 + x / double(depth_max) * 104, py = 39 + y / double(lane_max) * 66;
arrow(px, py, std::array<int, 4>{-18, -8, 8, 18}[size_t(values[0])], 0);
dot(px, py);
}
for (int k = 0; k < 2; ++k) {
const int x = 137 + k * 68;
dot(x + 12, 27);
dot(x + 25, 20);
dot(x + 25, 37);
dot(x + 43, 28, true);
if (values[size_t(5 + k)] == 0) {
line(x + 3, 12, x + 55, 44, chalk, 1.7);
line(x + 55, 12, x + 3, 44, chalk, 1.7);
// switched off: the name written under the field (set by the screen) is struck out
line(x + 2, 52.6, x + 56, 51.4, chalk, 1.3);
// the six tiles, 40 x 34 each: 1 wing play, 2 through balls, 3 goal kicks / 4 flat or
// high, 5 offside trap, 6 pressing
const auto tile = [](int index) { return std::pair<double, double>{168 + ((index - 1) % 3) * 46.0, index <= 3 ? 30.0 : 80.0}; };
for (int index = 1; index <= 6; ++index) {
const auto [x, y] = tile(index);
if (index != 4) field(x, y, 40, 34);
const int v = values[size_t(index)];
if (index == 1) { // from the middle out to the wing
dot(x + 12, y + 17);
arrow(x + 12, y + 17, 15, -v * 4.2, true);
dot(x + 31, y + 17 - 3.4 * 3, true);
} else if (index == 2) { // a short pass or a ball into the depth
dot(x + 8, y + 22);
dot(x + 15 + v * 4, y + 12);
arrow(x + 8, y + 22, 7 + v * 6.5, -2 - v * 2.2);
} else if (index == 3) { // the goalkeeper's kick
dot(x + 3.5, y + 17);
arrow(x + 3.5, y + 17, 7 + v * 8.5, -v * 2.4, true);
dot(x + 13, y + 26);
} else if (index == 4) { // two players, the ball along the ground or lobbed
for (double px : {x + 7.0, x + 33.0}) {
ring(px, y + 12, 2, chalk, .8);
line(px, y + 14, px - 1.5, y + 21, chalk, .8);
line(px - 1.5, y + 21, px + 3, y + 26, chalk, .8);
line(px - 1.5, y + 21, px - 5, y + 26, chalk, .8);
line(px - .8, y + 17, px - 5, y + 19, chalk, .8);
line(px - .8, y + 17, px + 4, y + 19, chalk, .8);
}
std::vector<std::pair<double, double>> path;
const double x1 = x + 12, x2 = x + 28, base = y + 22, peak = v ? y - 2 : base;
for (int i = 0; i <= 10; ++i) {
const double t = i / 10.0;
path.emplace_back(x1 + (x2 - x1) * t + wobble(.2), (1 - t) * (1 - t) * base + 2 * (1 - t) * t * peak + t * t * base + wobble(.25));
}
stroke(path, chalk, .9, true);
line(x2, base, x2 - 3.2, base - 2.4 - (v ? 2 : 0), chalk, .9);
line(x2, base, x2 - 2.6 + (v ? 2.6 : 0), base + 2.4 - (v ? 5 : 0), chalk, .9);
} else if (index == 5) { // the back line steps up together
for (double py : {y + 8.0, y + 17.0, y + 26.0}) dot(x + 13, py);
line(x + 17.5, y + 3, x + 17.5, y + 31, chalk, .6, true);
dot(x + 24, y + 14, true);
} else { // three close in on the ball
dot(x + 26, y + 17, true);
arrow(x + 12, y + 8, 9, 6);
arrow(x + 10, y + 26, 11, -6);
arrow(x + 36, y + 27, -6, -6.5);
dot(x + 12, y + 8);
dot(x + 10, y + 26);
dot(x + 36, y + 27);
}
}
dot(29, 111);
dot(76, 94);
dot(76, 119);
dot(101, 118);
dot(111, 120, true);
arrow(29, 111, 10 + values[3] * 10, -values[3] * 5, true);
arrow(76, 94, 10 + values[2] * 8, 12 - values[2] * 5);
arrow(76, 119, 10 + values[1] * 8, -8 + values[1] * 4, true);
for (int x : {181, 222}) {
ring(x, 65, 2, chalk, .8);
line(x, 67, x - 2, 74, chalk, .8);
line(x - 2, 74, x + 3, 78, chalk, .8);
line(x - 2, 74, x - 6, 78, chalk, .8);
line(x - 1, 70, x - 6, 72, chalk, .8);
line(x - 1, 70, x + 4, 72, chalk, .8);
}
{
// the ball's way from one to the other: along the ground or lobbed
std::vector<std::pair<double, double>> path;
const double peak = values[4] ? 45 : 72;
for (int i = 0; i <= 10; ++i) {
const double t = i / 10.0;
path.emplace_back((1 - t) * (1 - t) * 188 + 2 * (1 - t) * t * 201 + t * t * 215 + wobble(.2),
(1 - t) * (1 - t) * 72 + 2 * (1 - t) * t * peak + t * t * 72 + wobble(.25));
if (index >= 5 && v == 0) {
// switched off: crossed out, and the name underneath struck through
line(x + 2, y + 2, x + 38, y + 32, chalk, 1.7);
line(x + 38, y + 2, x + 2, y + 32, chalk, 1.7);
line(x - 1, y + 40.4, x + 41, y + 39.4, chalk, 1.2);
}
stroke(path, chalk, .9, true);
const double dy = values[4] ? 2.6 : 0;
line(215, 72, 211.4, 72 - 2.1 - dy, chalk, .9);
line(215, 72, 212.2 + dy, 72 + 2.3 - dy * 1.6, chalk, .9);
}
out << "</svg>";
return out.str();
+2 -2
View File
@@ -13,9 +13,9 @@ bool App::engine_sports_dirty() const {
std::string App::engine_sports_footer() {
const bool training = menu_ == "training";
return "<p id=\"sports-note\" class=\"small muted\" style=\"position:absolute;" +
(training ? rect(0, 1580, 1060, 112) : rect(0, 1514, 2300, 112)) + "\"></p>"
(training ? rect(0, 1580, 1060, 112) : rect(0, 1688, 2616, 60) + "text-align:center;") + "\"></p>"
"<div class=\"row\" style=\"position:absolute;" +
(training ? rect(0, 1720, 1060, 94) : rect(0, 1650, 2300, 94)) + "\">" +
(training ? rect(0, 1720, 1060, 94) : rect(856, 1764, 904, 94)) + "\">" +
btn("sports-reset", "Zurücksetzen", "", "id=\"sports-reset\" style=\"width:440dp;height:94dp;\"") +
btn("sports-apply", "Anwenden", "primary", "id=\"sports-apply\" style=\"width:440dp;height:94dp;\"") + "</div>";
}
+25 -4
View File
@@ -182,6 +182,26 @@ void App::engine_live_poll() {
focus_after_render_ = "live-dialog-apply";
}
} catch (const std::exception &) {}
// the halts the manager asked for: at half time, and when his side falls behind
try {
const auto owner = live_owner();
const auto &match = live_match_by_id(live_.fixture().at("matches"), owner.at("match_id"));
const bool home = match.at("home").at("id") == owner.at("team").at("id");
std::string reason;
for (const auto &e : live_.fixture().at("frames").back().at("events")) {
if (seen.contains(e.at("id").get<std::string>()) || e.at("match_id") != match.at("id")) continue;
const std::string what = e.value("kind", std::string());
if (live_halt_interval_ && what == "interval") reason = "Halbzeit.";
if (live_halt_behind_ && what == "goal" && (e.at("side") == "home") != home) {
const auto &score = e.at("score");
if ((home ? score[0].get<int>() : score[1].get<int>()) < (home ? score[1].get<int>() : score[0].get<int>())) reason = "Rückstand.";
}
}
if (!reason.empty() && live_dialog_.empty() && live_.speed()) {
live_.speed(0);
live_feedback_ = "Angehalten: " + reason;
}
} catch (const std::exception &) {}
}
} else {
live_.speed(0);
@@ -255,9 +275,7 @@ void App::live_set_speed(int value) {
live_feedback_.clear();
live_last_tick_ = SDL_GetTicks64();
if (auto *node = dynamic_cast<Rml::ElementFormControl *>(element("live-speed"))) {
// Native vertical sliders increase downward; the user's logical speed is
// deliberately inverted so the bottom position always means zero/pause.
node->SetValue(std::to_string(4 - value)); node->SetAttribute("aria-valuenow", value);
node->SetValue(std::to_string(value)); node->SetAttribute("aria-valuenow", value);
node->SetAttribute("aria-valuetext", value ? "Wiedergabe Stufe " + std::to_string(value) : "Pause");
}
if (auto *node = element("live-speed-value")) node->SetInnerRML(esc(value ? std::to_string(value) + "×" : "Pause"));
@@ -360,6 +378,9 @@ bool App::live_action(const std::string &action, Rml::Element *target) {
} else if (action == "live-next") {
if (engine_live_running_) { engine_live_elapsed_ = 0; engine_live_send("live.step", {{"minutes", 1}}); return true; }
live_.next(); live_last_tick_ = SDL_GetTicks64();
} else if (action == "live-halt") {
(id == "interval" ? live_halt_interval_ : live_halt_behind_) ^= true;
focus_after_render_ = target->GetId();
} else if (action == "live-pause") {
live_set_speed(live_.speed() ? 0 : 1); return true;
} else if (action == "live-review" && live_.finished()) {
@@ -425,7 +446,7 @@ bool App::live_event(Rml::Event &event) {
if ((type == "change" || type == "input") && speed_control) {
if (setting_menu_markup_) return true;
if (auto *input = dynamic_cast<Rml::ElementFormControl *>(element("live-speed"))) {
try { live_set_speed(4 - std::stoi(input->GetValue())); } catch (const std::exception &) {}
try { live_set_speed(std::stoi(input->GetValue())); } catch (const std::exception &) {}
}
return true;
}
+155 -32
View File
@@ -180,6 +180,8 @@ std::string App::live_dialog_markup(const Json &owner) {
}
std::string App::live_ticker_events(const Json &frame, size_t &shown) {
const auto &fixture = live_.fixture();
const bool recorded = fixture.at("source") == "engine-recording";
const bool several = fixture.at("matches").size() > 1;
shown = 0;
std::string out;
for (auto i = frame.at("events").rbegin(); i != frame.at("events").rend(); ++i) {
@@ -189,11 +191,23 @@ std::string App::live_ticker_events(const Json &frame, size_t &shown) {
if (live_filter_ == "yellow" && kind != "yellow" && kind != "red" && kind != "second_yellow") continue;
if (live_filter_ == "highlights" && kind != "goal" && kind != "chance" && kind != "miss" && kind != "red" && kind != "second_yellow") continue;
const auto &match = live_match_by_id(fixture.at("matches"), event.at("match_id"));
out += "<article class=\"live-event " + std::string(kind == "goal" ? "is-goal" : "") + "\" data-live-event=\"" + esc(event.at("id").get<std::string>()) + "\">" + live_text(std::to_string(event.at("minute").get<int>()) + "′", "live-event-time") + (kind == "kickoff" || kind == "interval" || kind == "fulltime" ? "<div class=\"live-badge\" style=\"width:54dp;height:54dp;\"></div>" : live_badge(match.at(event.at("side").get<std::string>()), 54)) +
"<div class=\"live-event-copy\">" + (fixture.at("source") == "engine-recording" && fixture.at("matches").size() == 1 ? std::string() : live_text(match.at("home").at("name").get<std::string>() + " · " + match.at("away").at("name").get<std::string>(), "live-event-owners")) + "<h3>" + live_text(event.at("headline")) + "</h3><p>" + live_text(event.at("body")) + "</p></div>" + live_text(live_score_text(event.at("score")), "live-event-score") + "</article>";
const bool whistle = kind == "kickoff" || kind == "interval" || kind == "fulltime";
const auto side = event.at("side").get<std::string>();
// one line per report: minute, what happened (a mark by kind), the club, the wording, the score
std::string row = "<article class=\"live-event kind-" + esc(kind) + (kind == "goal" ? " is-goal" : "") + (whistle ? " is-whistle" : "") +
"\" data-live-event=\"" + esc(event.at("id").get<std::string>()) + "\"";
if (kind == "goal") row += " style=\"border-left-color:" + live_colours(match)[side == "away" ? 1 : 0] + ";\"";
row += ">" + live_text(std::to_string(event.at("minute").get<int>()) + "′", "live-event-time") +
"<div class=\"live-event-mark\"><div class=\"mark\"></div></div>" +
(whistle ? "<div class=\"live-badge\" style=\"width:54dp;height:54dp;\"></div>" : live_badge(match.at(side), 54)) +
"<div class=\"live-event-copy\">" +
(several || !recorded ? live_text(match.at("home").at("name").get<std::string>() + " – " + match.at("away").at("name").get<std::string>(), "live-event-owners") : std::string()) +
"<h3>" + live_text(event.at("headline")) + "</h3><p>" + live_text(event.at("body")) + "</p></div>" +
live_text(live_score_text(event.at("score")), "live-event-score") + "</article>";
out += row;
++shown;
}
if (!shown && fixture.at("source") == "engine-recording" && live_filter_ == "all" && frame.at("events").empty()) {
if (!shown && recorded && live_filter_ == "all" && frame.at("events").empty()) {
// before the first report: who starts
for (const auto &match : fixture.at("matches")) {
if (live_coverage_ == "single" && match.at("id") != live_selected_match_) continue;
@@ -212,9 +226,116 @@ std::string App::live_ticker_events(const Json &frame, size_t &shown) {
}
if (!out.empty()) return out;
}
if (!shown) out += "<p class=\"live-note\">" + live_text(fixture.at("source") == "engine-recording" ? "Noch keine Meldungen." : "Für diesen Filter liegt noch keine Demomeldung vor.") + "</p>";
if (!shown) out += "<p class=\"live-note\">" + live_text(recorded ? "Noch keine Meldungen." : "Für diesen Filter liegt noch keine Demomeldung vor.") + "</p>";
return out;
}
std::array<std::string, 2> App::live_colours(const Json &match) {
// from the crests; a club without one, or a national side, plays in slate. Two sides in
// nearly the same colour: the guests change into a dark neutral.
const auto colour = [&](const Json &team) {
std::string value;
if (team.value("role", "club") != "national" && live_world_)
if (const auto *club = live_world_->find("clubs", team.value("id", "")); club && !club->value("crest", "").empty())
value = renderer_.crest_colour(club->value("crest", ""));
return value;
};
std::array<std::string, 2> out{colour(match.at("home")), colour(match.at("away"))};
const auto channel = [](const std::string &c, size_t at) { return std::stoi(c.substr(at, 2), nullptr, 16); };
if (out[0].empty()) out[0] = "#3d5a73";
if (out[1].empty()) out[1] = "#7a4a3a";
int distance = 0;
for (size_t at : {1u, 3u, 5u}) distance += std::abs(channel(out[0], at) - channel(out[1], at));
if (distance < 110) out[1] = "#3a4148";
return out;
}
// One match on the stage: crests, the score plate in the clubs' colours, the clock, who is
// pressing, and the time line with every goal, card and injury so far. `layout` is solo
// (one match), duo (two) or quad (three or four).
std::string App::live_card(const Json &match, const Json &frame, const std::string &layout, size_t index) {
const auto &fixture = live_.fixture();
const bool recorded = fixture.at("source") == "engine-recording";
const auto &value = live_score_by_id(frame, match.at("id"));
const int minute = frame.at("minute"), duration = std::max(1, fixture.value("duration", 90));
const auto colours = live_colours(match);
const bool quad = layout == "quad";
const double crest = layout == "solo" ? 250 : layout == "duo" ? 190 : 110;
const auto id = match.at("id").get<std::string>();
const double tw = layout == "solo" ? 2480 : 1180, th = quad ? 84 : 124, W = tw / th * 100;
// the clock: a ring that fills with the minutes
const double turn = std::clamp(double(minute) / duration, 0.0, 1.0) * 289.03;
const auto ink = "#eef2f5";
const std::string ring = "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><circle cx='50' cy='50' r='46' fill='none' stroke='" + std::string(ink) +
"' stroke-opacity='.16' stroke-width='7'/><circle cx='50' cy='50' r='46' fill='none' stroke='" + (live_.finished() ? std::string(ink) : colours[0]) +
"' stroke-width='7' stroke-linecap='round' stroke-dasharray='" + scalar(turn) + " 400' transform='rotate(-90 50 50)'/></svg>";
// who is pressing: goals and chances of the last ten minutes
int press[2] = {0, 0};
// the time line: grass in bands of fifteen minutes, the home side's marks above, the guests' below
std::string marks, bands;
for (int from = 0; from < duration; from += 15)
bands += "<rect x='" + scalar(from * W / duration) + "' y='30' width='" + scalar(std::min(15, duration - from) * W / duration) +
"' height='40' fill='" + ((from / 15) % 2 ? "#3f7d4e" : "#4a8a58") + "'/>";
for (const auto &event : frame.at("events")) {
if (event.at("match_id") != match.at("id")) continue;
const auto kind = event.value("kind", std::string());
const size_t side = event.value("side", std::string("home")) == "away" ? 1 : 0;
const int at = event.at("minute").get<int>();
if ((kind == "goal" || kind == "chance" || kind == "miss") && at > minute - 10) ++press[side];
const double x = std::clamp(at * W / duration, 12.0, W - 12), y = side ? 86 : 14;
if (kind == "goal")
marks += "<line x1='" + scalar(x) + "' y1='" + scalar(side ? 70 : 30) + "' x2='" + scalar(x) + "' y2='" + scalar(y) + "' stroke='" + colours[side] + "' stroke-width='3'/>"
"<circle cx='" + scalar(x) + "' cy='" + scalar(y) + "' r='11' fill='" + colours[side] + "' stroke='#ffffff' stroke-width='3'/>";
else if (kind == "yellow" || kind == "red" || kind == "second_yellow")
marks += "<rect x='" + scalar(x - 6) + "' y='" + scalar(y - 9) + "' width='12' height='18' rx='2' fill='" + (kind == "yellow" ? "#f2c230" : "#d6453d") + "' stroke='#00000040' stroke-width='1'/>";
else if (kind == "injury")
marks += "<path d='M" + scalar(x - 8) + " " + scalar(y) + "h16M" + scalar(x) + " " + scalar(y - 8) + "v16' stroke='#d6453d' stroke-width='5' stroke-linecap='round'/>";
}
const double now = std::clamp(minute * W / duration, 0.0, W);
const std::string timeline = "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 " + scalar(W) + " 100'><rect x='0' y='30' width='" + scalar(W) + "' height='40' rx='6' fill='#4a8a58'/>" + bands +
"<rect x='" + scalar(now) + "' y='30' width='" + scalar(W - now) + "' height='40' fill='#10161c' fill-opacity='.5'/>"
"<path d='M" + scalar(W / 2) + " 30v40' stroke='#ffffff' stroke-opacity='.75' stroke-width='3'/><circle cx='" + scalar(W / 2) + "' cy='50' r='12' fill='none' stroke='#ffffff' stroke-opacity='.6' stroke-width='2.5'/>"
"<rect x='1.5' y='31.5' width='" + scalar(W - 3) + "' height='37' rx='6' fill='none' stroke='#ffffff' stroke-opacity='.55' stroke-width='3'/>" + marks +
(live_.finished() ? std::string() : "<path d='M" + scalar(now) + " 24v52' stroke='#ffffff' stroke-width='4' stroke-linecap='round'/>") + "</svg>";
const int total = press[0] + press[1];
const double share = total ? 100.0 * press[0] / total : 50;
const auto phase = frame.at("phase").get<std::string>();
const std::string status = live_.finished() ? "Abpfiff" : phase == "interval" ? "Halbzeit" : minute < 1 ? "Anpfiff" : std::to_string(minute) + "′";
std::string names;
for (const auto &owner_id : match.at("owners")) for (const auto &person : fixture.at("owners")) if (person.at("id") == owner_id) { if (!names.empty()) names += " · "; names += person.at("name").get<std::string>(); }
std::string out = "<button data-action=\"live-match\" class=\"live-game " + layout + (match.at("id") == live_selected_match_ ? " active" : "") + "\" data-live-match=\"" + esc(id) + "\" data-id=\"" + esc(id) + "\">";
out += "<div class=\"live-card-top\">" + live_text(recorded ? match.value("competition", std::string("Spieltag")) : std::string("Demospiel"), "live-card-competition") +
live_text(fixture.at("owners").size() > 1 ? names : live_match_info_text(match, fixture.at("surface") == "indoor"), "live-match-info") + "</div>";
out += "<div class=\"live-card-main\"><div class=\"live-side home\">" + live_badge(match.at("home"), crest) + live_text(match.at("home").at("name"), "live-team-name") + "</div>"
"<div class=\"live-centre\">";
if (!quad)
out += "<div class=\"live-clock\">" + picture(renderer_.diagram("live-clock-" + std::to_string(index), ring, 256), 84, 84) + live_text(status, "live-clock-text") + "</div>";
out += "<div class=\"live-plate\"><div class=\"live-plate-half\" style=\"background-color:" + colours[0] + ";\"><span>" + std::to_string(value.at("score")[0].get<int>()) +
"</span></div><div class=\"live-plate-half\" style=\"background-color:" + colours[1] + ";\"><span>" + std::to_string(value.at("score")[1].get<int>()) + "</span></div></div>";
if (quad) out += live_text(status, "live-clock-inline");
else
out += "<div class=\"live-press\" aria-label=\"Druck der letzten zehn Minuten\"><div class=\"live-press-home\" style=\"width:" + scalar(share) + "%;background-color:" + colours[0] +
";\"></div><div class=\"live-press-away\" style=\"background-color:" + colours[1] + ";\"></div></div>";
out += "</div><div class=\"live-side away\">" + live_badge(match.at("away"), crest) + live_text(match.at("away").at("name"), "live-team-name") + "</div></div>";
out += "<div class=\"live-timeline\">" + picture(renderer_.diagram("live-line-" + std::to_string(index), timeline, 2048), tw, th) + "</div>";
// a goal that has just fallen: a banner across this card, once
if (!frame.at("events").empty()) {
const auto &last = frame.at("events").back();
if (last.at("match_id") == match.at("id") && last.value("kind", std::string()) == "goal" && !live_.finished() &&
last.at("minute").get<int>() >= minute - 1) {
// it stays while the minute lasts and slides in only the first time it is drawn
const bool fresh = live_moment_ != last.at("id").get<std::string>();
live_moment_ = last.at("id").get<std::string>();
const size_t side = last.value("side", std::string("home")) == "away" ? 1 : 0;
out += "<div class=\"live-moment" + std::string(fresh ? " fresh" : "") + "\" style=\"background-color:" + colours[side] + ";\">" + live_badge(match.at(side ? "away" : "home"), quad ? 120 : 200) +
"<div><strong>TOR!</strong>" + live_text(last.value("body", std::string()), "live-moment-text") + "</div>" + live_text(live_score_text(last.at("score")), "live-moment-score") + "</div>";
}
}
return out + "</button>";
}
std::string App::render_live() {
if(live_review_) return render_postmatch();
if (!live_.available()) return "";
@@ -225,39 +346,41 @@ std::string App::render_live() {
const auto &fixture = live_.fixture(); const auto frame = live_.frame(); const auto owner = live_owner();
const int minute = frame.at("minute"); const auto phase = frame.at("phase").get<std::string>();
const bool recorded = fixture.at("source") == "engine-recording";
const size_t count = fixture.at("matches").size();
const std::string layout = count == 1 ? "solo" : count == 2 ? "duo" : "quad";
const auto phase_text = live_.finished() ? "Beendet" : phase == "interval" ? "Halbzeit" : live_.speed() ? (recorded ? (phase == "extra_time" ? "Verlängerung" : phase == "shootout" ? "Elfmeterschießen" : "Spiel läuft") : "Aufzeichnung läuft") : (recorded ? "Pausiert" : "Gemeinsam pausiert");
const auto arrow = [&](bool right) { const auto color = theme_ == "silver" ? "#376b84" : theme_ == "matchday" ? "#efb2aa" : "#b5dbd2"; return picture(renderer_.diagram(right ? "live-arrow-right" : "live-arrow-left", "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 20 20\"><path d=\"" + std::string(right ? "M7 4l6 6-6 6" : "M13 4l-6 6 6 6") + "\" fill=\"none\" stroke=\"" + color + "\" stroke-width=\"1.8\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/></svg>", 72), 36, 36); };
std::string out = "<section id=\"live-stage\" class=\"live-stage\" data-source=\"" + std::string(recorded ? "engine-recording" : "ui-demo-fixture") + "\" data-fixture-id=\"" + esc(fixture.at("fixture_id").get<std::string>()) + "\"><header class=\"live-header\"><div>" + (recorded ? std::string() : live_text("SPIELTAG · LIVE-TICKER", "live-eyebrow")) +
"<h1>" + live_text(live_review_ ? "Ergebnisse & Bericht" : fixture.at("role") == "national" ? "Deutschland · Demo-Länderspiel" : fixture.at("surface") == "indoor" ? "Hallenpartien · 40 Minuten" : recorded ? fixture.at("matches").front().value("competition", std::string("Spieltag")) : std::string("Gemeinsamer Spieltag")) + "</h1></div>" + live_text(recorded ? ui_long_date(fixture.value("date", std::string())) : std::string("UI-Demo · vorgegebene Ergebnisse"), "live-demo-tag") + "</header>";
const auto scoreline = [&](const Json &match) {
const auto &value = live_score_by_id(frame, match.at("id"));
return "<div class=\"live-scoreline\">" + live_text(match.at("home").at("name"), "live-team-name home") + live_badge(match.at("home"), 58) + live_text(live_score_text(value.at("score")), "live-score") + live_badge(match.at("away"), 58) + live_text(match.at("away").at("name"), "live-team-name away") + "</div>";
};
out += "<div id=\"live-underlay\" class=\"live-body\"><div class=\"live-left\"><section class=\"live-panel live-overview\"><nav class=\"live-coverage" + std::string(recorded && fixture.at("matches").size() == 1 ? " solo" : "") + "\">";
if (!(recorded && fixture.at("matches").size() == 1))
for (const auto &[id, text] : std::array<std::pair<const char *, const char *>, 3>{{{"all", "Alle Spiele"}, {"single", "Einzelspiel"}, {"conference", "Konferenz"}}})
out += btn("live-coverage", text, live_coverage_ == id ? "selected" : "", "id=\"live-coverage-" + std::string(id) + "\" data-id=\"" + id + "\"");
if (live_coverage_ == "single" && fixture.at("matches").size() > 1) out += btn("live-match-prev", arrow(false), "live-match-arrow", "id=\"live-match-prev\" aria-label=\"Vorherige Tickerpartie\"") + btn("live-match-next", arrow(true), "live-match-arrow", "id=\"live-match-next\" aria-label=\"Nächste Tickerpartie\"");
if (!(recorded && fixture.at("matches").size() == 1)) out += live_text(std::to_string(minute) + ":00", "live-clock");
out += "</nav><div class=\"live-cards " + std::string(fixture.at("matches").size() == 1 || live_coverage_ == "single" ? "single" : "") + "\">";
for (const auto &match : fixture.at("matches")) {
if (live_coverage_ == "single" && match.at("id") != live_selected_match_) continue;
std::string names;
for (const auto &id : match.at("owners")) for (const auto &person : fixture.at("owners")) if (person.at("id") == id) { if (!names.empty()) names += " · "; names += person.at("name").get<std::string>(); }
out += "<button data-action=\"live-match\" class=\"live-game " + std::string(match.at("id") == live_selected_match_ ? "active" : "") + "\" data-live-match=\"" + esc(match.at("id").get<std::string>()) + "\" data-id=\"" + esc(match.at("id").get<std::string>()) + "\">" + (recorded && fixture.at("owners").size() == 1 ? std::string() : live_text(names, "live-owners")) + scoreline(match) + live_text(recorded && fixture.at("matches").size() == 1 ? std::string(phase_text) + (live_.finished() || minute < 1 ? "" : " · " + std::to_string(minute) + ". Minute") : std::to_string(minute) + "′ · " + (match.at("owners").size() > 1 ? std::string("Zwei menschliche Manager") : recorded ? match.value("competition", std::string("Eine menschliche Mannschaft")) : std::string("Eine menschliche Mannschaft")), "live-card-caption") + live_text(live_match_info_text(match, fixture.at("surface") == "indoor"), "live-match-info") + "</button>";
}
out += "</div></section><section class=\"live-panel live-ticker\"><header class=\"live-panel-heading\"><h2>" + live_text(recorded ? "Ticker" : "Gemeinsamer Live-Ticker") + "</h2>" + (recorded && fixture.at("owners").size() == 1 ? std::string() : live_text(live_coverage_ == "single" ? "Gewählte Partie" : "Alle Manager", "live-small")) + "</header><nav class=\"live-filters\">";
// a sheet in the menus' 4:3 format on the darkened stadium: the stage with one card per
// match of a human manager on top, the ticker and the manager's squad below, the controls at the foot
std::string out = "<div class=\"live-backdrop\"></div><section id=\"live-stage\" class=\"live-stage " + layout + "\" data-source=\"" + std::string(recorded ? "engine-recording" : "ui-demo-fixture") + "\" data-fixture-id=\"" + esc(fixture.at("fixture_id").get<std::string>()) + "\">";
out += "<header class=\"live-header\"><h1>" + live_text(fixture.at("role") == "national" ? "Länderspiel" : fixture.at("surface") == "indoor" ? "Hallenturnier" : recorded && count == 1 ? fixture.at("matches").front().value("competition", std::string("Spieltag")) : std::string("Spieltag")) + "</h1>" +
live_text(recorded ? ui_long_date(fixture.value("date", std::string())) : std::string("Demo · vorgegebene Ergebnisse"), "live-demo-tag") + "</header>";
out += "<div id=\"live-underlay\" class=\"live-body\"><div class=\"live-cards " + layout + "\">";
size_t index = 0;
for (const auto &match : fixture.at("matches")) out += live_card(match, frame, layout, index++);
out += "</div><div class=\"live-columns\"><section class=\"live-panel live-ticker\"><header class=\"live-panel-heading\"><h2>" + live_text("Ticker") + "</h2><nav class=\"live-filters\">";
if (count > 1)
for (const auto &[id, text] : std::array<std::pair<const char *, const char *>, 2>{{{"all", "Alle Spiele"}, {"single", "Gewähltes Spiel"}}})
out += btn("live-coverage", text, live_coverage_ == id ? "selected" : "", "id=\"live-coverage-" + std::string(id) + "\" data-id=\"" + id + "\"");
for (const auto &[id, label] : std::array<std::pair<const char *, const char *>, 4>{{{"all", "Alles"}, {"highlights", "Highlights"}, {"goal", "Tore"}, {"yellow", "Karten"}}}) out += btn("live-filter", label, live_filter_ == id ? "selected" : "", "id=\"live-filter-" + std::string(id) + "\" data-id=\"" + id + "\"");
out += "</nav><div id=\"live-ticker\" class=\"live-event-list\" tabindex=\"0\" aria-label=\"Gemeinsamer Ereignisverlauf\">";
out += "</nav></header><div id=\"live-ticker\" class=\"live-event-list\" tabindex=\"0\" aria-label=\"Ereignisverlauf\">";
size_t shown = 0;
out += live_ticker_events(frame, shown);
out += "</div><footer class=\"live-ticker-footer\">" "<span id=\"live-event-count\" class=\"live-small\">" + esc(recorded && !shown ? std::string() : std::to_string(shown) + (live_.fixture().at("source") == "engine-recording" ? (shown == 1 ? " Meldung" : " Meldungen") : " Meldungen · feste Aufzeichnung")) + "</span>" + "<span id=\"live-phase-status\" class=\"live-small\">" + esc(recorded ? std::string() : std::string(phase_text)) + "</span></footer></section></div><aside id=\"live-detail\" class=\"live-detail live-panel\"><header class=\"live-panel-heading\"><div class=\"live-detail-heading\"><h2>" + "<span id=\"live-owner-team\">" + esc(owner.at("team").at("name").get<std::string>()) + "</span></h2><p><span id=\"live-owner-name\">" + esc(owner.at("name").get<std::string>()) + "</span>" + "</p></div><nav class=\"live-team-switch\" aria-label=\"Managerdetails wechseln\">" +
btn("live-owner-prev", arrow(false), "", "id=\"live-owner-prev\" aria-label=\"Vorheriger Manager\" " + std::string(fixture.at("owners").size() == 1 ? "disabled" : "")) + btn("live-owner-next", arrow(true), "", "id=\"live-owner-next\" aria-label=\"Nächster Manager\" " + std::string(fixture.at("owners").size() == 1 ? "disabled" : "")) + "</nav></header><nav class=\"live-tabs\">";
for (const auto &[id, label] : std::array<std::pair<const char *, const char *>, 5>{{{"team", "Team"}, {"tactics", "Taktik"}, {"opponent", recorded ? "Ergebnisse" : "Gegner"}, {"table", "Live-Tabelle"}, {"stats", "Statistik"}}}) out += btn("live-tab", label, live_tab_ == id ? "selected" : "", "id=\"live-tab-" + std::string(id) + "\" data-id=\"" + id + "\" aria-pressed=\"" + (live_tab_ == id ? "true" : "false") + "\"");
out += "</nav><div id=\"live-detail-body\" class=\"live-detail-body\" tabindex=\"0\">" + live_detail(owner, frame) + "</div><footer class=\"live-detail-footer\">" + btn("live-intervene-lineup", "Aufstellung & Wechsel", "", "id=\"live-lineup-edit\" " + std::string(live_.finished() || (recorded && !live_.running()) ? "disabled" : "")) + "</footer></aside></div>";
out += "<div class=\"live-speed\">" + live_text("+") + "<input id=\"live-speed\" type=\"range\" orientation=\"vertical\" min=\"0\" max=\"4\" step=\"1\" value=\"" + std::to_string(4 - live_.speed()) + "\" aria-label=\"Wiedergabegeschwindigkeit; unten Pause\" aria-valuenow=\"" + std::to_string(live_.speed()) + "\" " + (live_.finished() ? "disabled" : "") + "/><span id=\"live-speed-value\" class=\"live-speed-value\">" + esc(live_.finished() ? "Ende" : live_.speed() ? std::to_string(live_.speed()) + "×" : "Pause") + "</span></div>";
out += "<footer class=\"live-bottom\"><div class=\"live-bottom-actions\">" + btn("live-back", live_.running() ? "Zu Ende spielen" : recorded ? "Zum Schreibtisch" : "Zum Desktop", "", "id=\"live-back\"") + btn("live-pause", live_.speed() ? "Pause" : "Abspielen", "", "id=\"live-pause\" " + std::string(live_.finished() ? "disabled" : "")) + "</div><span id=\"live-playback-status\" class=\"live-bottom-note\">" + esc(live_feedback_.empty() ? (recorded ? std::string() : std::string(phase_text) + " · " + std::to_string(minute) + "′ · keine Spielwertänderung") : live_feedback_) + "</span>" +
btn(live_.finished() ? "live-review" : "live-next", live_.finished() ? "Zur Auswertung" : live_.running() ? "Nächste Minute" : "Nächste Meldung", "", "id=\"" + std::string(live_.finished() ? "live-review" : "live-next") + "\"") + "</footer>";
out += "</div><footer class=\"live-ticker-footer\"><span id=\"live-event-count\" class=\"live-small\">" + esc(recorded && !shown ? std::string() : std::to_string(shown) + (recorded ? (shown == 1 ? " Meldung" : " Meldungen") : " Meldungen · feste Aufzeichnung")) + "</span><span id=\"live-phase-status\" class=\"live-small\">" + esc(phase_text) + "</span></footer></section>";
out += "<aside id=\"live-detail\" class=\"live-detail live-panel\"><header class=\"live-panel-heading\"><div class=\"live-detail-heading\"><h2><span id=\"live-owner-team\">" + esc(owner.at("team").at("name").get<std::string>()) + "</span></h2><p><span id=\"live-owner-name\">" + esc(owner.at("name").get<std::string>()) + "</span></p></div>";
if (fixture.at("owners").size() > 1)
out += "<nav class=\"live-team-switch\" aria-label=\"Manager wechseln\">" + btn("live-owner-prev", arrow(false), "", "id=\"live-owner-prev\" aria-label=\"Vorheriger Manager\"") + btn("live-owner-next", arrow(true), "", "id=\"live-owner-next\" aria-label=\"Nächster Manager\"") + "</nav>";
out += "</header><nav class=\"live-tabs\">";
for (const auto &[id, label] : std::array<std::pair<const char *, const char *>, 5>{{{"team", "Team"}, {"tactics", "Taktik"}, {"opponent", recorded ? "Ergebnisse" : "Gegner"}, {"table", "Tabelle"}, {"stats", "Statistik"}}}) out += btn("live-tab", label, live_tab_ == id ? "selected" : "", "id=\"live-tab-" + std::string(id) + "\" data-id=\"" + id + "\" aria-pressed=\"" + (live_tab_ == id ? "true" : "false") + "\"");
out += "</nav><div id=\"live-detail-body\" class=\"live-detail-body\" tabindex=\"0\">" + live_detail(owner, frame) + "</div><footer class=\"live-detail-footer\">" + btn("live-intervene-lineup", "Aufstellung & Wechsel", "", "id=\"live-lineup-edit\" " + std::string(live_.finished() || (recorded && !live_.running()) ? "disabled" : "")) + "</footer></aside></div></div>";
out += "<footer class=\"live-bottom\"><div class=\"live-bottom-actions\">" + btn("live-back", live_.running() ? "Zu Ende spielen" : recorded ? "Zum Schreibtisch" : "Zum Desktop", "", "id=\"live-back\"") + btn("live-pause", live_.speed() ? "Pause" : "Abspielen", "", "id=\"live-pause\" " + std::string(live_.finished() ? "disabled" : "")) + "</div>";
out += "<div class=\"live-speed\">" + live_text("Tempo") + "<input id=\"live-speed\" type=\"range\" min=\"0\" max=\"4\" step=\"1\" value=\"" + std::to_string(live_.speed()) + "\" aria-label=\"Wiedergabegeschwindigkeit; links Pause\" aria-valuenow=\"" + std::to_string(live_.speed()) + "\" " + (live_.finished() ? "disabled" : "") + "/><span id=\"live-speed-value\" class=\"live-speed-value\">" + esc(live_.finished() ? "Ende" : live_.speed() ? std::to_string(live_.speed()) + "×" : "Pause") + "</span></div>";
if (live_.running())
out += "<div class=\"live-halts\">" + btn("live-halt", "Zur Halbzeit anhalten", live_halt_interval_ ? "selected" : "", "id=\"live-halt-interval\" data-id=\"interval\" aria-pressed=\"" + std::string(live_halt_interval_ ? "true" : "false") + "\"") +
btn("live-halt", "Bei Rückstand anhalten", live_halt_behind_ ? "selected" : "", "id=\"live-halt-behind\" data-id=\"behind\" aria-pressed=\"" + std::string(live_halt_behind_ ? "true" : "false") + "\"") + "</div>";
out += "<span id=\"live-playback-status\" class=\"live-bottom-note\">" + esc(live_feedback_.empty() ? (recorded ? std::string() : std::string(phase_text) + " · " + std::to_string(minute) + "′ · keine Spielwertänderung") : live_feedback_) + "</span>" +
btn(live_.finished() ? "live-review" : "live-next", live_.finished() ? "Zur Auswertung" : live_.running() ? "Nächste Minute" : "Nächste Meldung", "primary", "id=\"" + std::string(live_.finished() ? "live-review" : "live-next") + "\"") + "</footer>";
return out + live_dialog_markup(owner) + "</section>";
}
void App::live_after_render() {
+6
View File
@@ -20,6 +20,12 @@
std::string live_detail(const Json &owner, const Json &frame);
std::string live_dialog_markup(const Json &owner);
std::string live_badge(const Json &, double);
// the two club colours of a match (home, away), far enough apart to tell the sides
std::array<std::string, 2> live_colours(const Json &match);
std::string live_card(const Json &match, const Json &frame, const std::string &layout, size_t index);
std::string live_moment_; // the event whose banner was shown last
bool live_halt_interval_ = false, live_halt_behind_ = false;
std::string live_halted_; // the reason of the last automatic halt, cleared when play resumes
Json live_owner() const;
Json live_owner_rows(const Json &) const;
Json live_owner_state(const Json &) const;
+12 -21
View File
@@ -149,31 +149,22 @@ std::string App::render_tactics() {
"Flache / hohe Bälle", "Flügelbild links",
"Flügelbild rechts", "Einsatz"};
const std::array<int, 8> limits = engine_mode_ ? t.at("limits").get<std::array<int, 8>>() : std::array<int, 8>{3, 3, 3, 3, 1, 1, 1, 11};
const std::array<std::array<int, 4>, 7> areas = {{{19, 9, 104, 62},
{61, 108, 50, 34},
{63, 84, 54, 30},
{26, 95, 24, 24},
{168, 53, 71, 34},
{137, 10, 58, 47},
{205, 10, 58, 47}}};
// the board is drawn at 8dp a unit (tactics_diagram: 320 x 200 units); the pitch of the
// attitude and the six tiles are its click areas, each with its name underneath
const auto tile = [](size_t i) { return std::array<int, 2>{168 + int((i - 1) % 3) * 46, i <= 3 ? 30 : 80}; };
std::string body =
"<div class=\"tactics-board\"><div class=\"tactics-surface\"></div>" +
picture(renderer_.diagram("tactics", tactics_diagram(t, theme_, engine_mode_ ? t.at("board").at("points") : snap().state.value("lineup", Json::object()).value("points", Json()), engine_mode_ ? t.at("board").at("depth_max").get<int>() : 18, engine_mode_ ? t.at("board").at("lane_max").get<int>() : 8)), 2300,
1864);
// the two switches by name, in chalk under their fields; the board strikes out one that is off
for (size_t k = 0; k < 2; ++k)
body += "<div class=\"tactic-chalk-name" + std::string(t["values"][5 + k].get<int>() ? "" : " off") + "\" style=\"position:absolute;" +
rect((137 + k * 68) / 295.0 * 2300, 47.5 / 206.0 * 1864 + 67, 58 / 295.0 * 2300, 9 / 206.0 * 1864) + "\"><span>" +
(k ? "PRESSING" : "ABSEITSFALLE") + "</span></div>";
"<div class=\"tactics-board\">" +
picture(renderer_.diagram("tactics", tactics_diagram(t, theme_, engine_mode_ ? t.at("board").at("points") : snap().state.value("lineup", Json::object()).value("points", Json()), engine_mode_ ? t.at("board").at("depth_max").get<int>() : 18, engine_mode_ ? t.at("board").at("lane_max").get<int>() : 8)), 2560, 1600);
static const std::array<const char *, 7> chalk_names{"GRUNDAUSRICHTUNG", "FLÜGELSPIEL", "STEILPÄSSE", "ABSCHLAG", "FLACH / HOCH", "ABSEITSFALLE", "PRESSING"};
for (size_t i = 0; i < 7; ++i) {
const auto a = areas[i];
const std::array<int, 4> a = i ? std::array<int, 4>{tile(i)[0], tile(i)[1], 40, 46} : std::array<int, 4>{20, 30, 132, 96};
const bool off = i >= 5 && t["values"][i].get<int>() == 0;
body += "<div class=\"tactic-chalk-name" + std::string(off ? " off" : "") + "\" style=\"position:absolute;" +
rect((a[0] - 6) * 8, (a[1] + a[3] - 11) * 8, (a[2] + 12) * 8, 80) + "\"><span>" + chalk_names[i] + "</span></div>";
body += btn("tactic-cycle", "", "tactic-hotspot",
"id=\"tactic-cycle-" + std::to_string(i) + "\" data-id=\"" +
std::to_string(i) + "\" aria-label=\"" + esc(names[i]) +
"\" style=\"position:absolute;" +
rect(a[0] / 295.0 * 2300, a[1] / 206.0 * 1864,
a[2] / 295.0 * 2300, a[3] / 206.0 * 1864) +
"z-index:" + std::to_string(8 - i) + ";\"");
"\" style=\"position:absolute;" + rect(a[0] * 8, a[1] * 8, a[2] * 8, a[3] * 8) + "\"");
}
const int effort = t["values"][7].get<int>();
body +=
@@ -184,7 +175,7 @@ std::string App::render_tactics() {
"</span></div><input type=\"range\" id=\"tactic-effort\" "
"data-input=\"tactic-effort\" min=\"" + std::to_string(engine_mode_ ? t.at("minima")[7].get<int>() : 0) + "\" max=\"" + std::to_string(limits[7]) + "\" step=\"1\" value=\"" +
std::to_string(effort) +
"\"/></div><p id=\"tactic-hint\" class=\"tactic-hint\">" +
"\"/><div class=\"tactic-effort-ends\"><span>LOCKER</span><span>VOLLGAS</span></div></div><p id=\"tactic-hint\" class=\"tactic-hint\">" +
(engine_mode_
? "<strong>" + esc(names[size_t(last_tactic_)] + ": " + tactic_value_text(size_t(last_tactic_), t["values"][size_t(last_tactic_)].get<int>(), limits[size_t(last_tactic_)])) + "</strong><span>" + esc(tactic_effect_text(size_t(last_tactic_))) + "</span>"
: esc(names[size_t(last_tactic_)]) + ": " +
+66 -2
View File
@@ -309,6 +309,40 @@ public:
const auto &r = entries_.at(found->second).raster;
return {found->second, r.width, r.height};
}
// A club's colour, read from its crest: the strongest hue among its opaque pixels, dark
// enough to carry white type. Empty when the crest has no colour to speak of.
std::string crest_colour(const std::string &key) {
const auto identity = "crest-colour:" + key;
if (const auto found = keys_.find(identity); found != keys_.end()) return found->second;
std::string colour;
const auto source = image(key, true);
if (!source.token.empty()) {
const auto &raster = entries_.at(source.token).raster;
std::array<double, 12> weight{}, red{}, green{}, blue{};
for (size_t i = 0; i + 3 < raster.pixels.size(); i += 4) {
const int r = raster.pixels[i], g = raster.pixels[i + 1], b = raster.pixels[i + 2], a = raster.pixels[i + 3];
const int high = std::max({r, g, b}), low = std::min({r, g, b});
if (a < 200 || high - low < 60 || high < 70) continue;
double hue = high == r ? double(g - b) / (high - low) : high == g ? 2 + double(b - r) / (high - low) : 4 + double(r - g) / (high - low);
if (hue < 0) hue += 6;
const size_t bucket = size_t(hue * 2) % 12;
const double w = double(high - low) / 255;
weight[bucket] += w; red[bucket] += r * w; green[bucket] += g * w; blue[bucket] += b * w;
}
const size_t best = size_t(std::max_element(weight.begin(), weight.end()) - weight.begin());
if (weight[best] > 40) {
double r = red[best] / weight[best], g = green[best] / weight[best], b = blue[best] / weight[best];
// white type needs a dark ground
const double light = (.299 * r + .587 * g + .114 * b) / 255;
if (light > .46) { const double f = .46 / light; r *= f; g *= f; b *= f; }
char text[8];
std::snprintf(text, sizeof text, "#%02x%02x%02x", int(r), int(g), int(b));
colour = text;
}
}
keys_[identity] = colour;
return colour;
}
Picture crest(const std::string &key, bool light_surface) {
const auto source = image(key, true);
if (!light_surface || source.token.empty()) return source;
@@ -486,6 +520,7 @@ class App final : public Rml::EventListener {
uint64_t opening_due_ = 0;
bool opening_io_blocked_ = false;
int last_tactic_ = 0;
std::string window_shown_ = "\x01"; // the menu whose window is on screen (window())
#include "modern/ui/engine_state.inc"
#include "modern/ui/settings_state.inc"
@@ -573,7 +608,10 @@ class App final : public Rml::EventListener {
}
std::string window(const std::string &heading, const std::string &content,
bool close = true) {
return "<div class=\"window\"><div class=\"titlebar\">" +
// a sheet of paper on two more; it slides in once when its menu opens, not on every redraw
const std::string arriving = window_shown_ == menu_ ? "" : " window-in";
window_shown_ = menu_;
return "<div class=\"sheet-under first" + arriving + "\"></div><div class=\"sheet-under second" + arriving + "\"></div><div class=\"window" + arriving + "\"><div class=\"titlebar\">" +
(close ? btn("close", "<span>×</span>", "close", "id=\"window-close\" aria-label=\"" + std::string(menu_ == "bank" && bank_view_ != "entrance" ? "Zurück zur Bankhalle" : "Fenster schließen") + "\"")
: "<span style=\"width:76dp;\"></span>") +
"<h1>" + esc(heading) + "</h1></div><div class=\"content\">" +
@@ -882,7 +920,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;
const bool wanted = doc_->QuerySelector(".window") != nullptr || doc_->QuerySelector(".live-stage") != nullptr;
if (!wanted) window_shown_ = "\x01";
if (wanted == window_zoom_) return;
window_zoom_ = wanted;
resize();
@@ -1280,6 +1319,30 @@ class App final : public Rml::EventListener {
bold_italic = Rml::LoadFontFace(
rml::asset_path(assets_ / "LatoLatin-BoldItalic.ttf"), "Modern",
Rml::Style::FontStyle::Italic, Rml::Style::FontWeight::Bold);
// The display serif for headings and names, and the chalk hand of the tactics board;
// both ship with the game. Without the files the text falls back to the system fonts below.
const auto own = assets_ / "fonts";
bool display = fs::exists(own / "SourceSerif4-Regular.ttf") &&
Rml::LoadFontFace(rml::asset_path(own / "SourceSerif4-Regular.ttf"), "Display", Rml::Style::FontStyle::Normal, Rml::Style::FontWeight::Normal);
if (display && fs::exists(own / "SourceSerif4-Semibold.ttf"))
Rml::LoadFontFace(rml::asset_path(own / "SourceSerif4-Semibold.ttf"), "Display", Rml::Style::FontStyle::Normal, Rml::Style::FontWeight::Bold);
bool chalk = fs::exists(own / "CabinSketch-Regular.ttf") &&
Rml::LoadFontFace(rml::asset_path(own / "CabinSketch-Regular.ttf"), "Chalk", Rml::Style::FontStyle::Normal, Rml::Style::FontWeight::Normal);
if (chalk && fs::exists(own / "CabinSketch-Bold.ttf"))
Rml::LoadFontFace(rml::asset_path(own / "CabinSketch-Bold.ttf"), "Chalk", Rml::Style::FontStyle::Normal, Rml::Style::FontWeight::Bold);
if (!display) {
std::vector<fs::path> serif;
#ifdef _WIN32
if (const char *windir = std::getenv("WINDIR")) serif = {fs::path(windir) / "Fonts" / "georgia.ttf", fs::path(windir) / "Fonts" / "times.ttf"};
#elif defined(__APPLE__)
serif = {"/System/Library/Fonts/Supplemental/Georgia.ttf", "/System/Library/Fonts/NewYork.ttf", "/System/Library/Fonts/Times.ttc"};
#else
serif = {"/usr/share/fonts/truetype/liberation2/LiberationSerif-Regular.ttf", "/usr/share/fonts/truetype/liberation/LiberationSerif-Regular.ttf"};
#endif
serif.push_back(assets_ / "LatoLatin-Regular.ttf");
for (const auto &font : serif)
if (fs::exists(font) && Rml::LoadFontFace(rml::asset_path(font), "Display", Rml::Style::FontStyle::Normal, Rml::Style::FontWeight::Normal)) break;
}
std::vector<fs::path> chalk_fonts;
#ifdef _WIN32
if (const char *windir = std::getenv("WINDIR")) {
@@ -1296,6 +1359,7 @@ class App final : public Rml::EventListener {
"/usr/share/fonts/truetype/liberation/LiberationSerif-Regular.ttf"};
#endif
chalk_fonts.push_back(assets_ / "LatoLatin-Regular.ttf");
if (!chalk)
for (const auto &font : chalk_fonts)
if (fs::exists(font) && Rml::LoadFontFace(rml::asset_path(font), "Chalk",
Rml::Style::FontStyle::Normal,