// SPDX-License-Identifier: GPL-3.0-only // The pages of the notebook: what all of them are built from. A page is 1244 x 720 design // units (1 unit = 2.25 dp) under the heading of the sheet; its blocks are styled in pages.rcss. // The menus that are laid out as a page of the notebook. Every other career menu is still a // sheet of the old format, shown scaled inside the book. bool App::page_native() const { static const std::set native{"achievements", "highscore", "balance", "contracts", "environment", "tables", "league", "other", "strengths", "fairplay", "indoor", "scorers"}; return notebook_page() && native.contains(menu_); } // A length of the page design in dp. std::string App::pg(double units) { return scalar(units * 2.25) + "dp"; } // Inline styles written in design units: every "px" becomes dp. std::string App::pg_css(std::string_view css) { std::string out; for (size_t i = 0; i < css.size();) { const bool starts = (std::isdigit(static_cast(css[i])) || (css[i] == '.' && i + 1 < css.size() && std::isdigit(static_cast(css[i + 1])))) && (i == 0 || !(std::isalnum(static_cast(css[i - 1])) || css[i - 1] == '#' || css[i - 1] == '.')); if (!starts) { out += css[i++]; continue; } size_t end = i; while (end < css.size() && (std::isdigit(static_cast(css[end])) || css[end] == '.')) ++end; if (css.substr(end, 2) == "px") { out += pg(std::stod(std::string(css.substr(i, end - i)))); i = end + 2; } else { out.append(css.substr(i, end - i)); i = end; } } return out; } std::string App::pg_upper(const std::string &text) { return notebook_upper(text); } std::string App::pg_kicker(const std::string &text, const std::string &css) { return "" + esc(pg_upper(text)) + ""; } std::string App::pg_stat(const std::string &label, const std::string &value, const std::string &sub) { return "
" + pg_kicker(label) + "" + value + "" + (sub.empty() ? std::string() : "" + sub + "") + "
"; } std::string App::pg_bar(double percent, const std::string &kind) { return "
"; } std::string App::pg_dots(int on, int of) { std::string out = ""; for (int i = 0; i < of; ++i) out += i < on ? "" : ""; return out + ""; } // The four lines of a team as the page writes them. std::string App::pg_pos(const std::string &code) { const std::string key = code == "TW" || code == "T" ? "TW" : code == "ABW" || code == "A" || code == "AB" ? "ABW" : code == "MIT" || code == "M" || code == "MF" ? "MIT" : code == "STU" || code == "S" || code == "ST" ? "STU" : ""; return "" + esc(key.empty() ? code : key) + ""; } // The last matches as marks: S won, U drawn, N lost, anything else not played. std::string App::pg_form(const std::string &marks) { std::string out = ""; for (const char c : marks) out += c == 'S' || c == 'U' || c == 'N' ? std::string("" + c + "" : std::string(""); return out + ""; } std::string App::pg_status(const std::string &text) { return text.empty() ? std::string() : "" + esc(text) + ""; } std::string App::pg_button(const std::string &action, const std::string &label, const std::string &css, const std::string &attrs) { // "primary" is the page's own filled button, not the one of the old windows std::string classes = css; if (const auto at = classes.find("primary"); at != std::string::npos) classes.replace(at, 7, "pg-go"); return btn(action, label, "pg-btn " + classes, attrs); } // A cell of a table head (a button when the column sorts) and of a row; a width of 0 takes // the room that is left. `align` is "", "r" or "c". std::string App::pg_th(const std::string &label, double width, const std::string &align, const std::string &sort_action, const std::string &attrs, int sorted) { const std::string css = "pg-th " + align + (width > 0 ? "" : " flex"), style = width > 0 ? " style=\"width:" + pg(width) + ";\"" : ""; const std::string text = "" + esc(pg_upper(label)) + "" + (sorted ? std::string(" 0 ? "up" : "down") + "\">" : std::string()); if (sort_action.empty()) return "" + text + ""; return btn(sort_action, "" + text + "", css, attrs + style); } std::string App::pg_td(const std::string &html, double width, const std::string &align, bool cell) { return "
0 ? "" : " flex") + "\"" + (width > 0 ? " style=\"width:" + pg(width) + ";\"" : "") + ">" + html + "
"; } // A dialog: a note on the dimmed book. `actions` are its buttons, right-aligned. std::string App::pg_dialog(const std::string &title, const std::string &sub, const std::string &body, const std::string &actions, double width, const std::string &attrs) { return "
" + (title.empty() ? std::string() : "

" + esc(title) + "

" + (sub.empty() ? std::string() : "" + sub + "") + "
") + body + (actions.empty() ? std::string() : "
" + actions + "
") + "
"; } // A club as a link to its card: crest and name (the name first when `reverse`). std::string App::pg_club(const std::string &id, double size, bool reverse) { const auto *c = world_->find("clubs", id); const auto live = engine_mode_ ? engine_report_team(id) : Json(); if ((engine_mode_ && live.is_null()) || (!engine_mode_ && !c)) return "—"; const auto name = esc(engine_mode_ ? live.at("name").get() : world_->name(*c)); return btn("club-detail", crest(c, size) + "" + name + "", std::string("pg-link") + (reverse ? " reverse" : ""), "id=\"report-club-" + esc(id) + "\" data-id=\"" + esc(id) + "\""); } // The heading of the sheet is written by the book before the page is; the page may have // changed its title or added a hint since. void App::notebook_finish(std::string &markup) { for (const auto &[token, value] : {std::pair{"\x02T\x02", esc(page_title_)}, {"\x02H\x02", page_hint_.empty() ? std::string() : " · " + esc(pg_upper(page_hint_))}}) for (size_t at = markup.find(token); at != std::string::npos; at = markup.find(token, at)) markup.replace(at, token.size(), value); }