// SPDX-License-Identifier: GPL-3.0-only namespace { std::string sports_number(const Json &v) { return v.is_number_integer() ? number(v.get()) : "—"; } } 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 = "
"; 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 + "
"; } // 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 skills = {"Kondition", "Technik", "Eckball", "Freistoß", "Zweikampf", "Pass", "Schuss", "Schnelligkeit", "Teamplay"}; const std::vector> 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(); for (const auto &v : t["types"]) type_total += v.get(); // the areas std::string body = "
"; for (size_t i = 0; i < 9; ++i) body += "
" + img("training.skill." + std::to_string(i), 72, 72, false, false, 160) + "" + skills[i] + "" + training_balls("area", int(i), t["areas"][i].get(), !engine_mode_ && automatic[i < 2 ? 1 : 2].get(), {}, 54, 10, !engine_mode_ && i >= 2 && skill_total > 14) + "
"; // the pitch with the four kinds of session, the budget and the switches beside it body += "
"; for (int i = 0; i < 10; ++i) body += "
"; body += "
"; for (int i = 0; i < 4; ++i) body += "
" + training_balls("type", i, t["types"][size_t(i)].get(), !engine_mode_ && automatic[0].get(), {}, 52, 6) + "
"; body += "
" + pg_kicker("Ballbudget") + "
Arten" + std::to_string(type_total) + " / " + std::to_string(engine_mode_ ? t.at("limits").at("types").get() : 8) + "
Kondition/Technik" + std::to_string(t["areas"][0].get() + t["areas"][1].get()) + " / " + std::to_string(engine_mode_ ? t.at("limits").at("fitnessAndSkill").get() : 4) + "
Fertigkeiten" + std::to_string(skill_total) + " / " + std::to_string(engine_mode_ ? t.at("limits").at("otherAreas").get() : 18) + (!engine_mode_ && skill_total > 14 ? " · hohe Belastung" : "") + "
"; const std::array 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() ? "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() : 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" : "")) + "
"; // the players body += "
" + pg_th("Pos.", 56) + pg_th("Spieler", 0) + pg_th("Stärke", 70, "r") + pg_th("Schwerpunkt", 170) + pg_th("Intensität", 100) + "
"; std::vector 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(); 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 += "
" + pg_td(pg_pos(pos == "gk" ? "TW" : pos == "def" ? "ABW" : pos == "mid" ? "MIT" : pos == "fwd" ? "STU" : pos), 56, "", true) + pg_td("name(*p)) + "\">" + esc(world_->name(*p)) + "", 0) + pg_td("" + sports_number(p->value("attributes", Json::object()).value("strength", Json())) + "", 70, "r") + pg_td(selector, 170, "", true) + pg_td(training_balls("player", int(i), row.value("intensity", 0), !engine_mode_ && automatic[3].get(), id, 50, 8), 100, "", true) + "
"; } body += "
"; }