// SPDX-License-Identifier: GPL-3.0-only
// The line-up as a page of the notebook (the real game): the squad as a table at the left,
// grouped into starting eleven, bench and the rest; at the right the pitch seen from behind
// the own goal with the eleven as shirts, or the whole squad as shirts. Two players are
// clicked to swap them; any other cell of a row opens the player's card.
std::string App::render_lineup_page() {
const auto projection = engine_lineup_projection(engine_data_);
if (!projection.value("ok", false)) return "
";
for (const auto &column : columns) out += pg_th(column.label, column.width, column.align);
out += "
";
int group = -1;
for (const auto &row : rows) {
const auto slot = row.at("slot").get();
const auto id = row.at("id").get();
const int part = slot < field_count ? 0 : row.value("role", std::string()) == "bench" ? 1 : 2;
if (part != group) {
group = part;
out += "
";
if (lineup_pitch_) {
std::string stripes;
for (int band = 0; band < 8; ++band)
stripes += "";
const auto field = "";
out += "
" +
picture(renderer_.diagram(std::string("lineup-page-field") + (indoor ? "-indoor" : ""), field, 900), side_width, pitch_height, true);
const double depth_max = l.value("depth_max", 18), lane_max = l.value("lane_max", 8);
for (size_t i = 0; i < std::min(size_t(field_count), rows.size()); ++i) {
const auto &row = rows[i], &point = l.at("points")[i];
if (point.is_null()) continue;
// the own goal is at the bottom: depth runs up the pitch, the lanes from left to right
const bool paired = row.at("pair_number").is_number_integer();
const double x = (14 + point[1].get() / lane_max * 72) / 100 * side_width + (paired ? (row.at("pair_member") == 0 ? -0.62 : 0.62) * shirt_size : 0);
const double y = (87 - point[0].get() / depth_max * 76) / 100 * pitch_height;
out += shirt(row, i, "position:absolute;left:" + scalar(x - 110) + "dp;top:" + scalar(y - 70) + "dp;");
}
out += "
";
} else {
out += "
";
for (int part = 0; part < 3; ++part) {
std::string shirts;
for (size_t i = 0; i < rows.size(); ++i) {
const int slot = rows[i].at("slot").get();
if ((slot < field_count ? 0 : rows[i].value("role", std::string()) == "bench" ? 1 : 2) == part) shirts += shirt(rows[i], size_t(slot), "");
}
if (!shirts.empty()) out += pg_kicker(part == 0 ? (indoor ? "Aufgebot" : "Startelf") : part == 1 ? "Ersatzbank" : "Reserve") + "
" + shirts + "
";
}
out += "
";
}
const bool takers = lineup_side_ == "takers" && projection.at("set_pieces").is_object();
if (takers) {
// who takes the set pieces: one of the three is chosen, the next click on a player names him
out += "
Standardschützen" +
pg_button("lineup-piece-auto", "Alle dem Co-Trainer", "", "id=\"lineup-piece-auto\"") + "
";
for (const auto &[key, label] : std::array, 3>{{{"freeKick", "Freistoß"}, {"penalty", "Elfmeter"}, {"corner", "Eckball"}}}) {
const auto &taker = projection.at("set_pieces").at(key);
std::string name = "Co-Trainer";
if (taker.is_string()) for (const auto &row : rows) if (row.at("id") == taker) name = last_name(row.at("name").get());
const bool chosen = lineup_piece_ == key;
out += btn("lineup-piece", "" + pg_upper(label) + "" + esc(name) + "", std::string("pg-card lp-piece") + (chosen ? " sel" : ""),
attr("id", std::string("lineup-piece-") + key) + attr("data-id", key) + attr("aria-pressed", chosen ? "true" : "false"));
}
out += "
Eine der drei Karten wählen, dann den Schützen in der Liste oder auf dem Feld anklicken. Möglich ist, wer aufgestellt ist oder auf der Bank sitzt.
";
} else {
out += "
Aufstellung"
"ab 85ab 70"
"darunter
Zwei Spieler zum Tauschen anklicken."
"Der Tausch wird erst nach Bestätigung übernommen.";
if (indoor) {
out += "
" + pg_kicker("Halle · Wechselpaare", "width:100%;");
for (const auto &pair : projection.at("pairs")) {
std::string names;
for (const auto &id : pair.at("playerIds"))
for (const auto &row : rows) if (row.at("id") == id) names += (names.empty() ? "" : " / ") + last_name(row.at("name").get());
out += "P" + std::to_string(pair.at("number").get()) + " · " + esc(names) + "";
}
if (projection.at("pairs").empty()) out += "Keine Wechselpaare bestätigt.";
out += "
";
}
out += "
";
}
// --- the foot ---
const auto pair_of = [&](const char *action, const char *id, const std::string &first, const std::string &second, bool second_on) {
std::string seg = "
";
for (int i = 0; i < 2; ++i) {
const bool on = (i == 1) == second_on;
seg += btn(action, "" + (i ? second : first) + "", std::string(i ? "" : "first ") + (on ? "on" : ""), on ? std::string("style=\"pointer-events:none;\" aria-pressed=\"true\"") : "id=\"" + std::string(id) + "\" aria-pressed=\"false\"");
}
return seg + "
";
};
std::string status = engine_busy_ ? engine_operation_ : engine_notice_;
if (!lineup_selected_.empty())
for (const auto &row : rows) if (row.at("id") == lineup_selected_) status = row.at("name").get() + " markiert · zweiten Spieler wählen.";
if (lineup_side_ == "takers" && projection.at("set_pieces").is_object() && !engine_busy_) status = "Schützen: Karte wählen, dann Spieler anklicken.";
if (status.empty()) status = "Kein Spieler markiert.";
out += "";
return out + engine_player_profile(projection);
}