Files
Dreierpack-Manager/src/modern/ui/lineup_page.inc
T
MichaelandClaude Fable 5.2 92555b9ba0 The takers of free kicks, penalties and corners can be named in the line-up
The read lineup states the three takers (setPieces; null is the assistant's
choice) and the new command lineup.setPiece names one or hands all three
back, through the game's own set_pitch_set_piece_taker_source and
auto_pitch_set_piece_takers_source. In the line-up, Schütze opens the three
cards; a card is chosen and the next click on a player names him.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-16 14:25:04 +01:00

184 lines
16 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 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 "<div class=\"pg-page\"><div class=\"pg-empty\">Die Aufstellung ist derzeit nicht verfügbar.</div></div>";
const auto &l = projection.at("board");
const auto &rows = projection.at("rows");
const int field_count = projection.at("field_count").get<int>();
const bool indoor = projection.at("surface") == "indoor";
if (lineup_slot(l, lineup_selected_) < 0) lineup_selected_.clear();
lineup_data_ = lineup_data_ == 1 ? 1 : 0;
const auto attr = [](const std::string &key, const std::string &value) { return " " + key + "=\"" + esc(value) + "\""; };
const auto player_attrs = [&](const Json &row, const std::string &prefix) {
const auto id = row.at("id").get<std::string>();
return attr("id", prefix + id) + attr("data-id", id) + attr("data-squad-player", id) + attr("data-slot", std::to_string(row.at("slot").get<size_t>())) +
attr("aria-pressed", lineup_selected_ == id ? "true" : "false") + attr("aria-label", row.at("name").get<std::string>() + ", " + lineup_position(row.at("position")));
};
const auto last_name = [](const std::string &name) { const auto at = name.rfind(' '); return at == std::string::npos ? name : name.substr(at + 1); };
const auto flag = [&](const Json &nation) -> std::string {
if (!nation.is_string()) return "—";
auto code = nation.get<std::string>();
if (code.starts_with("nation:")) code = code.substr(7);
const auto svg = code == "de" ? lineup_svg("<path fill=\"#111111\" d=\"M0 0H40V8H0Z\"/><path fill=\"#bc302e\" d=\"M0 8H40V16H0Z\"/><path fill=\"#edc758\" d=\"M0 16H40V24H0Z\"/>", "0 0 40 24") : ui_nation_flag_svg(code);
if (!svg.empty()) return "<span class=\"lp-flag\">" + picture(renderer_.diagram("lineup-flag-" + code, svg, 80), 45, 27) + "</span>";
std::transform(code.begin(), code.end(), code.begin(), [](unsigned char c) { return char(std::toupper(c)); });
return code.size() == 2 ? esc(code) : std::string("—");
};
// --- the table ---
struct Column { const char *label, *key; double width; const char *align; };
const std::vector<Column> columns = lineup_data_ == 0
? std::vector<Column>{{"Nr.", "", 40, "r"}, {"Name", "", 0, ""}, {"Pos.", "position", 60, "c"}, {"Ko", "condition", 42, "c"}, {"Te", "technique", 42, "c"}, {"Fo", "form", 42, "c"}, {"Stärke", "strength", 60, "c"},
{"Status", "status", 104, "c"}, {"Land", "nation", 50, "c"}, {"Sp.", "games", 42, "c"}, {"Tore", "goals", 46, "c"}, {"Vorl.", "assists", 46, "c"}}
: std::vector<Column>{{"Nr.", "", 40, "r"}, {"Name", "", 0, ""}, {"Alter", "age", 54, "c"}, {"Eck.", "corner", 58, "c"}, {"Frei.", "free_kick", 58, "c"}, {"Zwei.", "tackling", 58, "c"}, {"Pass", "passing", 58, "c"},
{"Schuss", "shooting", 58, "c"}, {"Schn.", "speed", 58, "c"}, {"Team", "teamplay", 58, "c"}, {"Spiele", "games", 56, "c"}, {"Note", "grade", 52, "c"}};
std::string out = "<div id=\"lineup-underlay\" class=\"pg-page" + std::string(indoor ? " indoor-lineup" : "") + "\"><div class=\"pg-body\"><div class=\"pg-panel pg-col pg-grow\" style=\"" + pg_css("gap:0px;padding:6px 10px;") +
"\"><div class=\"pg-t\" role=\"table\"><div class=\"pg-thead\" role=\"row\">";
for (const auto &column : columns) out += pg_th(column.label, column.width, column.align);
out += "</div><div id=\"lineup-roster-scroll\" class=\"pg-tbody\" tabindex=\"0\" aria-label=\"Kaderliste, scrollbar\">";
int group = -1;
for (const auto &row : rows) {
const auto slot = row.at("slot").get<int>();
const auto id = row.at("id").get<std::string>();
const int part = slot < field_count ? 0 : row.value("role", std::string()) == "bench" ? 1 : 2;
if (part != group) {
group = part;
out += "<div class=\"pg-tr grp\">" + pg_td(pg_upper(part == 0 ? (indoor ? "Aufgebot" : "Startelf") : part == 1 ? "Ersatzbank" : "Übriger Kader"), 0) + "</div>";
}
out += "<div class=\"pg-tr " + std::string(lineup_selected_ == id ? "sel" : "") + "\" role=\"row\" style=\"height:" + pg(30) + ";\">";
size_t field = 0;
for (const auto &column : columns) {
const std::string key = column.key;
if (std::string(column.label) == "Nr.") { out += pg_td(slot < field_count ? std::to_string(slot + 1) : std::string("–"), column.width, "r"); continue; }
if (std::string(column.label) == "Name") {
auto name = esc(row.at("name").get<std::string>());
if (row.at("pair_number").is_number_integer()) name += "</span><span class=\"pg-tag sage\" style=\"margin-left:" + pg(6) + ";\">P" + std::to_string(row.at("pair_number").get<int>());
// the player's photo heads his name
out += pg_td("<span class=\"lp-face\">" + img("asset:player/" + (id.starts_with("player:") ? id.substr(7) : id) + "/photo", 46, 46 * 4.0 / 3.0, true, true, 128) + "</span>" + btn("lineup-player", "<span>" + name + "</span>", "pg-link", player_attrs(row, "lineup-name-")), 0, "", true);
continue;
}
std::string value;
if (key == "position") value = pg_pos(lineup_position(row.at("position")));
else if (key == "nation") value = flag(row.at("nation"));
else if (key == "status") {
const auto text = row.at("status").get<std::string>();
const bool out_of_action = text.find("erletz") != std::string::npos || text.find("esperr") != std::string::npos;
value = out_of_action ? "<span class=\"pg-tag accent\">" + esc(text) + "</span>" : "<span>" + esc(text) + "</span>";
} else if (key == "strength") value = "<strong>" + esc(lineup_value(row.at(key))) + "</strong>";
else if (lineup_data_ == 1 && key != "age" && key != "games" && key != "grade" && row.at(key).is_number_integer() && row.at(key).get<int>() >= 0 && row.at(key).get<int>() <= 3)
value = pg_dots(row.at(key).get<int>(), 3);
else value = "<span>" + esc(lineup_value(row.at(key))) + "</span>";
out += btn("player-detail", value, std::string("pg-td lp-cell ") + column.align,
attr("id", "lineup-detail-" + id + "-" + std::to_string(field++)) + attr("data-id", id) + attr("aria-label", row.at("name").get<std::string>() + ", Spielerinformationen") + " style=\"width:" + pg(column.width) + ";\"");
}
out += "</div>";
}
if (rows.empty()) out += "<div class=\"pg-empty\">Für diesen Verein sind keine Spieler überliefert.</div>";
out += "</div></div></div>";
// --- the pitch or the squad as shirts ---
std::string shirt_colour;
if (const auto *club = world_->find("clubs", engine_data_.at("desktop").at("meta").at("scope").at("teamId").get<std::string>()); club && !club->value("crest", "").empty())
shirt_colour = renderer_.crest_colour(club->value("crest", ""));
if (shirt_colour.empty()) shirt_colour = "#b2622d";
const double shirt_size = 100;
const auto shirt = [&](const Json &row, size_t index, const std::string &style) {
const auto &condition = row.contains("condition") ? row.at("condition") : Json();
const bool selected = lineup_selected_ == row.at("id").get<std::string>();
const std::string level = condition.is_number_integer() ? (condition.get<int>() >= 85 ? "a" : condition.get<int>() >= 70 ? "b" : "c") : "n";
return btn("lineup-player", "<span class=\"lp-shirt-art\">" + picture(renderer_.diagram("lineup-shirt-" + shirt_colour + (selected ? "-s-" : "-n-") + level, lineup_shirt(shirt_colour, selected, condition), 160), shirt_size, shirt_size) +
"<span class=\"lp-num\">" + (index < size_t(field_count) ? std::to_string(index + 1) : std::string()) + "</span></span><span class=\"lp-name\">" + esc(last_name(row.at("name").get<std::string>())) + "</span>",
std::string("lp-shirt") + (selected ? " sel" : ""), player_attrs(row, "lineup-player-") + (style.empty() ? std::string() : " style=\"" + style + "\""));
};
const double side_width = 900, pitch_height = 1512 - 27 - (indoor ? 420 : 250);
out += "<div class=\"pg-col\" style=\"width:" + scalar(side_width) + "dp;\">";
if (lineup_pitch_) {
std::string stripes;
for (int band = 0; band < 8; ++band)
stripes += "<rect y=\"" + scalar(band * 16.25) + "\" width=\"100\" height=\"16.25\" fill=\"" + (indoor ? (band % 2 ? "#d2ad7a" : "#c79d68") : (band % 2 ? "#b6cf97" : "#a9c489")) + "\"/>";
const auto field = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 100 130\" preserveAspectRatio=\"none\">" + stripes +
"<g fill=\"none\" stroke=\"#fdfbf4\" stroke-width=\".7\"><rect x=\"5\" y=\"5\" width=\"90\" height=\"120\" rx=\"1\"/><path d=\"M5 65h90M30 5v17h40V5M30 125v-17h40v17M41 5v6h18V5M41 125v-6h18v6\"/><ellipse cx=\"50\" cy=\"65\" rx=\"11\" ry=\"9\"/></g></svg>";
out += "<div id=\"lineup-pitch\" class=\"lp-pitch\" role=\"group\" aria-label=\"Spielfeld, Spieler auswählen\" style=\"height:" + scalar(pitch_height) + "dp;\">" +
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<int>() / 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<int>() / depth_max * 76) / 100 * pitch_height;
out += shirt(row, i, "position:absolute;left:" + scalar(x - 110) + "dp;top:" + scalar(y - 70) + "dp;");
}
out += "</div>";
} else {
out += "<div class=\"pg-panel pg-col lp-team\" style=\"height:" + scalar(pitch_height) + "dp;\">";
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<int>();
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") + "<div class=\"lp-team-row\">" + shirts + "</div>";
}
out += "</div>";
}
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 += "<div class=\"pg-panel pg-col pg-grow\" style=\"" + pg_css("gap:6px;padding:10px 14px;") + "\"><div class=\"pg-row\" style=\"justify-content:space-between;\"><strong class=\"pg-h\">Standardschützen</strong>" +
pg_button("lineup-piece-auto", "Alle dem Co-Trainer", "", "id=\"lineup-piece-auto\"") + "</div><div class=\"pg-row\" style=\"align-items:stretch;" + pg_css("gap:8px;") + "\">";
for (const auto &[key, label] : std::array<std::pair<const char *, const char *>, 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<std::string>());
const bool chosen = lineup_piece_ == key;
out += btn("lineup-piece", "<span class=\"pg-k\">" + pg_upper(label) + "</span><strong class=\"pg-nowrap\">" + esc(name) + "</strong>", 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 += "</div><span class=\"pg-mut\" style=\"display:block;font-size:" + pg(12.5) + ";\">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.</span></div></div></div>";
} else {
out += "<div class=\"pg-panel pg-col pg-grow\" style=\"" + pg_css("gap:4px;padding:10px 14px;") + "\"><div class=\"pg-row\" style=\"justify-content:space-between;\"><strong class=\"pg-h\">Aufstellung</strong><span class=\"pg-legend\">"
"<span class=\"pg-legend-item\"><span class=\"pg-legend-mark lp-dot a\"></span><span>ab 85</span></span><span class=\"pg-legend-item\"><span class=\"pg-legend-mark lp-dot b\"></span><span>ab 70</span></span>"
"<span class=\"pg-legend-item\"><span class=\"pg-legend-mark lp-dot c\"></span><span>darunter</span></span></span></div><span style=\"display:block;\">Zwei Spieler zum Tauschen anklicken.</span>"
"<span class=\"pg-mut\" style=\"display:block;font-size:" + pg(12.5) + ";\">Der Tausch wird erst nach Bestätigung übernommen.</span>";
if (indoor) {
out += "<div id=\"lineup-engine-pairs\" class=\"lp-pairs\">" + 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<std::string>());
out += "<span class=\"pg-nowrap lp-pair\"><strong>P" + std::to_string(pair.at("number").get<int>()) + "</strong> · " + esc(names) + "</span>";
}
if (projection.at("pairs").empty()) out += "<span class=\"pg-mut\" style=\"display:block;\">Keine Wechselpaare bestätigt.</span>";
out += "</div>";
}
out += "</div></div></div>";
}
// --- 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 = "<div class=\"pg-seg\">";
for (int i = 0; i < 2; ++i) {
const bool on = (i == 1) == second_on;
seg += btn(action, "<span>" + (i ? second : first) + "</span>", 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 + "</div>";
};
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<std::string>() + " 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 += "<nav class=\"pg-foot\">" + pair_of("lineup-data", "lineup-data", "Daten A", "Daten B", lineup_data_ == 1) + pair_of("lineup-view", "lineup-view", "Spielfeld", "Team", !lineup_pitch_) + "<div class=\"pg-seg\">";
for (const auto &[side, label] : std::array<std::pair<const char *, const char *>, 3>{{{"formations", "Aufst."}, {"orders", "Anweis."}, {"takers", "Schütze"}}})
out += btn("lineup-side", "<span>" + std::string(label) + "</span>", std::string(std::string(side) == "formations" ? "first" : "") + (std::string(side) == "takers" && takers ? " on" : ""),
attr("id", "lineup-side-" + std::string(side)) + attr("data-id", side) + (std::string(side) == "takers" && projection.at("set_pieces").is_object() ? attr("aria-pressed", takers ? "true" : "false") : std::string(" disabled title=\"Im Spiel nicht verfügbar\"")));
out += "</div><span class=\"pg-tag sage\">" + std::string(indoor ? "Halle · 40 Min." : "Rasen · 90 Min.") + "</span><span class=\"pg-sp\"></span>" + pg_status(status) + "</nav></div>";
return out + engine_player_profile(projection);
}