Files
Dreierpack-Manager/src/modern/ui/sports_screens.inc
T
MichaelandClaude Fable 5.2 c7d23185ec Line-up and training as pages; the friendlies' opponents as tiles
The line-up of the real game is the squad as a grouped table and the eleven as
shirts on a pitch seen from behind the own goal, or the whole squad as shirts.
Training keeps the game's own arrangement and pictures in the page's size and
inks. The opponents of a friendly are tiles in four columns with both crests.
The demo keeps the older line-up sheet.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-15 18:42:07 +01:00

80 lines
7.5 KiB
HTML

// SPDX-License-Identifier: GPL-3.0-only
namespace {
std::string sports_number(const Json &v) { return v.is_number_integer() ? number(v.get<int64_t>()) : "—"; }
}
std::string App::training_balls(const std::string &group, int index, int value,
bool automatic, const std::string &player,
int size, int gap, bool overtraining) {
std::string body =
"<div class=\"training-balls\" style=\"gap:" + std::to_string(gap) +
"dp;\">";
for (int i = 1; i <= 3; ++i)
body += btn(
"training-ball", img("training.ball", size, size, false, false, 128),
std::string("training-ball ") +
(i <= value ? "is-selected" : "is-empty") +
(overtraining && i <= value ? " overtraining" : ""),
"id=\"training-ball-" + group + "-" + std::to_string(index) + "-" +
std::to_string(i) + "\" data-group=\"" + group + "\" data-id=\"" +
std::to_string(index) + "\" data-player=\"" + esc(player) +
"\" data-value=\"" + std::to_string(i) + "\" style=\"width:" +
std::to_string(size) + "dp;height:" + std::to_string(size) +
"dp;\" " + (automatic ? "disabled" : ""));
return body + "</div>";
}
// Training as a page of the notebook, in the game's own arrangement and pictures: the nine
// areas with their marks at the left, under them the pitch with the four kinds of session and
// the automatic switches; at the right every player with his focus and intensity.
std::string App::render_training() {
const auto t = engine_mode_ ? engine_training_draft_ : snap().state.at("training");
const auto &automatic = t.at("autos");
const std::array<const char *, 9> skills = {"Kondition", "Technik", "Eckball", "Freistoß", "Zweikampf", "Pass", "Schuss", "Schnelligkeit", "Teamplay"};
const std::vector<std::pair<std::string, std::string>> focuses = {{"0", "Allgemein"}, {"1", "Eckball"}, {"2", "Freistoß"}, {"3", "Zweikampf"}, {"4", "Pass"}, {"5", "Schuss"}, {"6", "Schnelligkeit"}, {"7", "Teamplay"}};
int skill_total = 0, type_total = 0;
for (size_t i = 2; i < 9; ++i) skill_total += t["areas"][i].get<int>();
for (const auto &v : t["types"]) type_total += v.get<int>();
// the areas
std::string body = "<div class=\"pg-page\"><div class=\"pg-body\"><div class=\"pg-col\" style=\"width:" + pg(470) + ";\"><div class=\"pg-panel pg-col\" style=\"" + pg_css("gap:0px;padding:6px 16px;") + "\">";
for (size_t i = 0; i < 9; ++i)
body += "<div class=\"tr-skill\">" + img("training.skill." + std::to_string(i), 72, 72, false, false, 160) + "<span class=\"pg-grow\" style=\"display:block;font-weight:bold;\">" + skills[i] + "</span>" +
training_balls("area", int(i), t["areas"][i].get<int>(), !engine_mode_ && automatic[i < 2 ? 1 : 2].get<bool>(), {}, 54, 10, !engine_mode_ && i >= 2 && skill_total > 14) + "</div>";
// the pitch with the four kinds of session, the budget and the switches beside it
body += "</div><div class=\"pg-row pg-grow\" style=\"" + pg_css("gap:12px;") + "align-items:stretch;\"><div class=\"tr-pitch\">";
for (int i = 0; i < 10; ++i) body += "<div class=\"tr-stripe\" style=\"left:" + std::to_string(i * 54) + "dp;background-color:" + std::string(i % 2 ? "#b6cf97" : "#a9c489") + ";\"></div>";
body += "<div class=\"tr-line mid\"></div><div class=\"tr-line circle\"></div><div class=\"tr-line box left\"></div><div class=\"tr-line box right\"></div>";
for (int i = 0; i < 4; ++i)
body += "<div class=\"tr-type\" style=\"left:" + std::to_string(26 + (i % 2) * 270) + "dp;top:" + std::to_string(70 + (i / 2) * 170) + "dp;\">" +
training_balls("type", i, t["types"][size_t(i)].get<int>(), !engine_mode_ && automatic[0].get<bool>(), {}, 52, 6) + "</div>";
body += "</div><div class=\"pg-col pg-grow\" style=\"" + pg_css("gap:6px;") + "\"><div class=\"pg-panel\" style=\"" + pg_css("padding:8px 12px;") + "\">" + pg_kicker("Ballbudget") +
"<div class=\"pg-kv\"><span>Arten</span><strong>" + std::to_string(type_total) + " / " + std::to_string(engine_mode_ ? t.at("limits").at("types").get<int>() : 8) + "</strong></div><div class=\"pg-kv\"><span>Kondition/Technik</span><strong>" +
std::to_string(t["areas"][0].get<int>() + t["areas"][1].get<int>()) + " / " + std::to_string(engine_mode_ ? t.at("limits").at("fitnessAndSkill").get<int>() : 4) + "</strong></div><div class=\"pg-kv\"><span>Fertigkeiten</span><strong>" +
std::to_string(skill_total) + " / " + std::to_string(engine_mode_ ? t.at("limits").at("otherAreas").get<int>() : 18) + (!engine_mode_ && skill_total > 14 ? " · hohe Belastung" : "") + "</strong></div></div>";
const std::array<const char *, 4> auto_names = {"AUTO · Arten", "AUTO · Kondition", "AUTO · Fertigkeiten", "AUTO · Spieler"};
for (size_t i = 0; i < 4; ++i)
body += pg_button("training-auto", auto_names[i], std::string("block tr-auto ") + (automatic[i].get<bool>() ? "on" : ""), "id=\"training-auto-" + std::to_string(i) + "\" data-id=\"" + std::to_string(i) + "\" " + (engine_mode_ ? "disabled" : ""));
const bool all_auto = engine_mode_ ? t.at("master_auto").get<bool>() : std::all_of(automatic.begin(), automatic.end(), [](const auto &v) { return v == true; });
body += pg_button("training-auto-all", "Automatisch", std::string("block tr-auto ") + (all_auto ? "on" : ""), "id=\"training-auto-all\" " + std::string(engine_mode_ ? "disabled" : "")) + "</div></div></div>";
// the players
body += "<div class=\"pg-panel pg-col pg-grow\" style=\"" + pg_css("gap:0px;padding:4px 12px;") + "\"><div class=\"pg-t\" role=\"table\"><div class=\"pg-thead\">" + pg_th("Pos.", 56) + pg_th("Spieler", 0) + pg_th("Stärke", 70, "r") + pg_th("Schwerpunkt", 170) +
pg_th("Intensität", 100) + "</div><div id=\"training-roster\" class=\"pg-tbody\">";
std::vector<const Json *> players;
if (engine_mode_) { for (const auto &p : t.at("roster")) players.push_back(&p); }
else players = world_->squad(t.value("club", ""));
for (size_t i = 0; i < players.size(); ++i) {
const auto *p = players[i];
const auto id = p->value("id", "");
const auto &row = t["players"].at(id);
const auto position = p->value("positions", Json::array());
const auto pos = position.empty() ? std::string() : position[0].get<std::string>();
auto selector = select("training-focus-" + std::to_string(i), focuses, std::to_string(row.value("focus", 0)), "training-focus");
selector.insert(selector.find('>'), " data-player=\"" + esc(id) + "\" " + (engine_mode_ || automatic[3] == true ? "disabled" : ""));
body += "<div class=\"pg-tr tr-player\">" + pg_td(pg_pos(pos == "gk" ? "TW" : pos == "def" ? "ABW" : pos == "mid" ? "MIT" : pos == "fwd" ? "STU" : pos), 56, "", true) +
pg_td("<strong title=\"" + esc(world_->name(*p)) + "\">" + esc(world_->name(*p)) + "</strong>", 0) + pg_td("<strong>" + sports_number(p->value("attributes", Json::object()).value("strength", Json())) + "</strong>", 70, "r") +
pg_td(selector, 170, "", true) + pg_td(training_balls("player", int(i), row.value("intensity", 0), !engine_mode_ && automatic[3].get<bool>(), id, 50, 8), 100, "", true) + "</div>";
}
body += "</div></div></div></div><nav class=\"pg-foot\">";
if (engine_mode_) body += pg_button("sports-reset", "Zurücksetzen", "", "id=\"sports-reset\"") + pg_button("sports-apply", "Anwenden", "primary", "id=\"sports-apply\"") + "<span class=\"pg-sp\"></span><span id=\"sports-note\" class=\"pg-status\"></span>";
else body += "<span class=\"pg-sp\"></span>" + pg_status("Jede Änderung gilt sofort.");
return body + "</nav></div>";
}