// 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", "periphery", "environment", "advertising", "investments"}}, {"finance", "Finanzen", {"balance", "bank", "properties", "stocks", "savings", "players", "toto"}}, {"fixtures", "Spielplan", {"calendar", "league", "tables", "other", "friendlies", "postpone", "indoor"}}, {"records", "Statistik", {"statistics", "stat-trend", "stat-winners", "stat-records", "stat-players", "achievements", "almanac", "fairplay", "highscore"}}, {"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"}, {"periphery", "Peripherie"}, {"environment", "Umfeld"}, {"advertising", "Werbung"}, {"investments", "Investitionen"}, {"balance", "Bilanz"}, {"bank", "Bank"}, {"properties", "Immobilien"}, {"stocks", "Aktien"}, {"savings", "Sparbuch"}, {"players", "Spieler"}, {"toto", "Toto"}, {"calendar", "Kalender"}, {"league", "Ligaspiele"}, {"tables", "Tabellen"}, {"other", "Übrige Spiele"}, {"friendlies", "Testspiele"}, {"postpone", "Verlegen"}, {"indoor", "Halle"}, {"statistics", "Analyse"}, {"stat-trend", "Verlauf"}, {"stat-winners", "Sieger"}, {"stat-records", "Rekorde"}, {"stat-players", "Spieler"}, {"achievements", "Erfolge"}, {"almanac", "Almanach"}, {"fairplay", "Fairplay"}, {"highscore", "Highscore"}, {"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(notebook_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 += btn("nb-home", svg("nb-ribbon", 20, 96, "", 200), "nb-ribbon", "id=\"nb-home\" aria-label=\"Zurück ins Hauptmenü\" title=\"Zurück ins Hauptmenü\""); 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(notebook_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; // a marker the book does not show: the pages of the archive in the demo, and the page for // dealings between managers where only one human plays const bool alone = bank_players().size() < 2; const auto hidden = [&](const char *r) { return (!engine_mode_ && std::string_view(r).starts_with("stat-")) || (alone && std::string_view(r) == "players"); }; const auto shown = size_t(std::count_if(section.routes.begin(), section.routes.end(), [&](const char *r) { return !hidden(r); })); for (const char *r : section.routes) { if (hidden(r)) continue; // the statistics are one menu with several pages; the demo has only its first const bool part = std::string_view(r).starts_with("stat-") || std::string_view(r) == "statistics"; // the ground is one menu with two pages: the stadium and what stands around it const bool ground = std::string_view(r) == "stadium" || std::string_view(r) == "periphery"; // so is advertising: the sponsors' contracts, and what the club invests itself const bool commerce = std::string_view(r) == "advertising" || std::string_view(r) == "investments"; const bool here = ground ? menu_ == "stadium" && (stadium_view_.value("view", std::string("inside")) == "panorama") == (std::string_view(r) == "periphery") : !bank_view_of(r).empty() ? menu_ == "bank" && bank_view_ == bank_view_of(r) : commerce ? menu_ == "advertising" && (advertising_page_ == "investments") == (std::string_view(r) == "investments") : part && engine_mode_ ? menu_ == "statistics" && statistics_page_ == r : notebook_menu() == r; if (here) { kicker = std::string(section.label) + " · " + std::to_string(n + 1) + " / " + std::to_string(shown); 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(part ? "statistics" : ground ? "stadium" : commerce ? "advertising" : !bank_view_of(r).empty() ? "bank" : 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 += ""; // the ring a cup left in the lower right corner: only where the page keeps that corner free or covers it // with a panel of its own, never under bare writing or an older sheet // (the transfer market keeps it free; on the home page it shows while no card lies on the last two cells of the bottom row) bool stain = menu_ == "transfer" && page_native(); if (notebook_menu().empty()) { stain = true; const auto &pages = notebook_pages().at("pages"); if (home_page_ >= 0 && home_page_ < int(pages.size())) for (const auto &card : pages[size_t(home_page_)].at("cards")) if (card.at("row").get() + card.at("rows").get() - 1 >= 5 && card.at("col").get() + card.at("cols").get() - 1 >= 7) stain = false; } if (stain) 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(stain ? "nb-lines" : "nb-lines-plain", 1406, 866, lines, 2800) + "
" + svg("nb-corner", 62, 62, "", 200) + "
"; page_title_ = heading; page_hint_.clear(); out += "
" + esc(notebook_upper(kicker)) + "\x02H\x02\x02T\x02
" + head + "
"; // a paper clip at the top edge, a pencil in its loop at the right edge // (the statistics have so many markers that the clip would lie on one of them: it is left off there) if (active != "records") 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 = "" "" "" "" "" "" "" ""; // it lies under the book, turned so that its ball and ring look out at the lower right corner const auto whistle_button = btn(engine_mode_ ? std::string("engine-open") : std::string("open:kickoff"), "" + picture(renderer_.diagram("nb-whistle", "" + whistle + "", 1300), 1012.5, 589.5) + "", "nb-whistle", "id=\"object-app-kickoff\" data-id=\"kickoff\" aria-label=\"Anstoß\"" + std::string(enabled("kickoff") ? "" : " disabled=\"disabled\"")); if (const auto under = out.find("
"); under != std::string::npos) out.insert(under, whistle_button); else out += whistle_button; 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(notebook_menu().empty() ? std::string("statistics") : notebook_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 {}; }