- Live ticker: the paused live state carries both starting elevens; the ticker lists them until the first report. A single match no longer gets an empty strip above the score, repeated status lines are gone, whistles carry no club badge, dates are written out. - Desk: "Die letzten Spiele" and the table place curve are fed by the engine (desktop-widgets read: recent, rankCurve) and belong to the default layout; the own crest widget is bound. - News: the German press templates are rewritten to one plain sentence each (the catalogue accepts a single sentence now); the reference snapshots follow, and the catalogue test can rewrite them with --update. Mailbox texts show world spellings of clubs and players and the euro sign. - Small type raised in advertising, lineup, news, toto, transfer and others; the transfer market column no longer runs under its scrollbar. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
830 lines
42 KiB
C++
830 lines
42 KiB
C++
// SPDX-License-Identifier: GPL-3.0-only
|
||
namespace {
|
||
const Json &transfer_ui_field(const Json &v, const char *key) {
|
||
static const Json empty;
|
||
if (v.is_object()) {
|
||
auto i = v.find(key);
|
||
if (i != v.end())
|
||
return *i;
|
||
}
|
||
return empty;
|
||
}
|
||
std::string transfer_ui_text(const Json &v, const std::string &fallback = "—") {
|
||
return v.is_string() && !v.get_ref<const std::string &>().empty()
|
||
? v.get<std::string>()
|
||
: fallback;
|
||
}
|
||
std::string transfer_ui_number(const Json &v) {
|
||
if (v.is_number_integer())
|
||
return number(v.get<int64_t>());
|
||
if (!v.is_number())
|
||
return "—";
|
||
std::ostringstream s;
|
||
s.imbue(std::locale::classic());
|
||
s << std::setprecision(4) << v.get<double>();
|
||
auto out = s.str();
|
||
std::replace(out.begin(), out.end(), '.', ',');
|
||
return out;
|
||
}
|
||
std::string transfer_ui_role(const Json &v) {
|
||
const auto p = transfer_ui_text(v, "");
|
||
return p == "gk" ? "TW"
|
||
: p == "def" ? "ABW"
|
||
: p == "mid" ? "MIT"
|
||
: p == "fwd" ? "STU"
|
||
: "—";
|
||
}
|
||
std::string transfer_ui_club(const Snapshot &s) {
|
||
return demo_career_manager(s.state).value("club", "");
|
||
}
|
||
Json transfer_ui_find(const Json &rows, const std::string &id) {
|
||
if (rows.is_array())
|
||
for (const auto &r : rows)
|
||
if (r.at("id") == id)
|
||
return r;
|
||
return nullptr;
|
||
}
|
||
const std::array<const char *, 7> transfer_ui_bonuses{
|
||
"Torprämie", "Punktprämie", "Auflaufprämie", "Meisterprämie",
|
||
"Prämie Pl. 2–5", "Prämie Pl. 6–10", "Nichtabstiegsprämie"};
|
||
} // namespace
|
||
|
||
void App::transfer_remember_scroll() {
|
||
if (!transfer_view_.is_object())
|
||
return;
|
||
for (const auto &[id, key] :
|
||
std::array<std::pair<const char *, const char *>, 4>{
|
||
{{"transfer-roster-scroll", "roster_top"},
|
||
{"transfer-market-scroll", "market_top"},
|
||
{"transfer-poach-scroll", "poach_top"},
|
||
{"transfer-orders-scroll", "orders_top"}}})
|
||
if (auto *node = element(id)) {
|
||
transfer_view_[key] = node->GetScrollTop();
|
||
if (std::string(id) == "transfer-roster-scroll")
|
||
transfer_view_["roster_left"] = node->GetScrollLeft();
|
||
}
|
||
if (auto *node = element("transfer-poach-scroll")) {
|
||
const auto key = node->GetAttribute<Rml::String>("data-scope", "");
|
||
if (!key.empty())
|
||
transfer_view_["poach_scrolls"][key] = node->GetScrollTop();
|
||
}
|
||
if (auto *node = element("transfer-dialog-scroll")) {
|
||
const auto kind = node->GetAttribute<Rml::String>("data-dialog", "");
|
||
if (!kind.empty())
|
||
transfer_view_["dialog_scrolls"][kind] = node->GetScrollTop();
|
||
}
|
||
}
|
||
void App::transfer_restore_scroll() {
|
||
if (menu_ != "transfer" || !transfer_view_.is_object() ||
|
||
!transfer_view_.value("restore_scroll", false))
|
||
return;
|
||
transfer_view_["restore_scroll"] = false;
|
||
for (const auto &[id, key] :
|
||
std::array<std::pair<const char *, const char *>, 4>{
|
||
{{"transfer-roster-scroll", "roster_top"},
|
||
{"transfer-market-scroll", "market_top"},
|
||
{"transfer-poach-scroll", "poach_top"},
|
||
{"transfer-orders-scroll", "orders_top"}}})
|
||
if (auto *node = element(id)) {
|
||
const auto &v = transfer_ui_field(transfer_view_, key);
|
||
if (v.is_number())
|
||
node->SetScrollTop(v.get<float>());
|
||
if (std::string(id) == "transfer-roster-scroll" &&
|
||
transfer_view_.contains("roster_left"))
|
||
node->SetScrollLeft(transfer_view_.at("roster_left").get<float>());
|
||
}
|
||
if (auto *node = element("transfer-poach-scroll")) {
|
||
const auto key = node->GetAttribute<Rml::String>("data-scope", "");
|
||
const auto &v = transfer_ui_field(
|
||
transfer_ui_field(transfer_view_, "poach_scrolls"), key.c_str());
|
||
if (v.is_number())
|
||
node->SetScrollTop(v.get<float>());
|
||
}
|
||
if (auto *node = element("transfer-dialog-scroll")) {
|
||
const auto kind = node->GetAttribute<Rml::String>("data-dialog", "");
|
||
const auto &v = transfer_ui_field(
|
||
transfer_ui_field(transfer_view_, "dialog_scrolls"), kind.c_str());
|
||
if (v.is_number())
|
||
node->SetScrollTop(v.get<float>());
|
||
}
|
||
}
|
||
std::string App::render_transfer() {
|
||
transfer_remember_scroll();
|
||
const auto snapshot = engine_mode_ ? Snapshot{} : snap();
|
||
const auto own = engine_mode_ ? engine_data_.at("desktop").at("meta").at("scope").at("teamId").get<std::string>() : transfer_ui_club(snapshot);
|
||
const auto data = transfer_data();
|
||
if (!data.value("ok", false))
|
||
return {};
|
||
if (!transfer_view_.is_object() || !transfer_view_.contains("tab"))
|
||
transfer_view_ = {{"tab", 0},
|
||
{"complete", false},
|
||
{"scope", "active"},
|
||
{"page", 0},
|
||
{"side", "market"},
|
||
{"own", ""},
|
||
{"market", ""},
|
||
{"hover", ""},
|
||
{"query", data.at("query")},
|
||
{"dialog_scrolls", Json::object()}};
|
||
if (transfer_view_.value("applied_query", std::string()) !=
|
||
data.at("query").get<std::string>()) {
|
||
transfer_view_["query"] = data.at("query");
|
||
transfer_view_["applied_query"] = data.at("query");
|
||
}
|
||
const auto &ours = data.at("own"), &pool = data.at("market");
|
||
if (transfer_ui_find(ours, transfer_view_.value("own", std::string()))
|
||
.is_null())
|
||
transfer_view_["own"] = ours.empty() ? Json("") : ours[0].at("id");
|
||
if (transfer_ui_find(pool, transfer_view_.value("market", std::string()))
|
||
.is_null()) {
|
||
transfer_view_["market"] = "";
|
||
for (const auto &r : pool)
|
||
if (r.at("own") == false) {
|
||
transfer_view_["market"] = r.at("id");
|
||
break;
|
||
}
|
||
}
|
||
const bool complete = transfer_view_.value("complete", false),
|
||
b = transfer_view_.value("tab", 0) == 1;
|
||
const int pages = std::max(1, int((pool.size() + 5) / 6)),
|
||
page = std::clamp(transfer_view_.value("page", 0), 0, pages - 1);
|
||
transfer_view_["page"] = page;
|
||
Json chosen =
|
||
transfer_view_.value("side", std::string("market")) == "own"
|
||
? transfer_ui_find(ours, transfer_view_.value("own", std::string()))
|
||
: transfer_ui_find(pool,
|
||
transfer_view_.value("market", std::string()));
|
||
const auto hovered = transfer_view_.value("hover", std::string());
|
||
auto preview = transfer_ui_find(pool, hovered);
|
||
if (preview.is_null())
|
||
preview = chosen;
|
||
const auto listed = [&](const std::string &id) {
|
||
const auto &ls = engine_mode_ ? engine_transfer_value_.at("listed") : snapshot.state.at("transfer").at("listed");
|
||
return std::find(ls.begin(), ls.end(), id) != ls.end();
|
||
};
|
||
const auto trait = [&](const Json &v, bool foot) {
|
||
if (!v.is_number_integer())
|
||
return std::string("<span class=\"transfer-trait\">—</span>");
|
||
const int n = v.get<int>();
|
||
const std::array<const char *, 4> fl{"", "Links", "Beidfüßig", "Rechts"},
|
||
ty{"", "Defensiv", "Ausgeglichen", "Offensiv"};
|
||
const std::string path = n == 2 ? "M16 4L28 16L16 28L4 16Z"
|
||
: foot
|
||
? (n == 1 ? "M28 16H4M4 16L14 6M4 16L14 26"
|
||
: "M4 16H28M28 16L18 6M28 16L18 26")
|
||
: (n == 1 ? "M16 4V28M16 28L6 18M16 28L26 18"
|
||
: "M16 28V4M16 4L6 14M16 4L26 14");
|
||
const auto svg =
|
||
"<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"32\" "
|
||
"height=\"32\"><path d=\"" +
|
||
path + "\" stroke=\"#9db7c9\" fill=\"none\" stroke-width=\"2\"/></svg>";
|
||
return "<span class=\"transfer-trait\" title=\"" +
|
||
std::string(foot ? fl[size_t(n)] : ty[size_t(n)]) + "\">" +
|
||
picture(renderer_.diagram("transfer-trait-" +
|
||
std::to_string(int(foot)) + "-" +
|
||
std::to_string(n),
|
||
svg, 64),
|
||
32, 32) +
|
||
"</span>";
|
||
};
|
||
const auto nation = [&](const Json &r) {
|
||
const auto code = transfer_ui_text(r.at("nation"), "");
|
||
const auto svg = ui_nation_flag_svg(code);
|
||
return "<span class=\"transfer-nation\" title=\"" +
|
||
esc(transfer_ui_text(transfer_ui_field(r, "nation_name"))) + "\">" +
|
||
(svg.empty() ? std::string("—")
|
||
: picture(renderer_.diagram(
|
||
"transfer-flag-" +
|
||
content::sha256(svg).substr(0, 12),
|
||
svg, 120),
|
||
36, 24)) +
|
||
"</span>";
|
||
};
|
||
std::string out =
|
||
"<section class=\"transfer-overview " +
|
||
std::string(complete ? "transfer-complete" : "") +
|
||
"\"><header class=\"transfer-heading\"><h2>Kader und "
|
||
"Transfermarkt</h2>" + (engine_mode_?"<p id=\"transfer-engine-feedback\" style=\"position:absolute;left:0;right:650dp;bottom:0;font-size:28dp;line-height:27dp;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;\">"+esc(engine_busy_?engine_operation_:engine_notice_)+"</p>":"") + "<div><span>Verfügbares Kapital</span><strong class=\"" + money_classes(engine_mode_?engine_transfer_value_.at("cash").get<int64_t>():snapshot.state.at("cash").get<int64_t>()) + "\">" +
|
||
esc(transfer_money((engine_mode_ ? engine_transfer_value_.at("cash").get<int64_t>() : snapshot.state.at("cash").get<int64_t>()))) +
|
||
"</strong></div></header><div class=\"transfer-columns\"><section "
|
||
"class=\"transfer-roster\"><header><h2>Dein Kader</h2><span>" +
|
||
std::to_string(ours.size()) + " Spieler · Daten " + (b ? "B" : "A") +
|
||
"</span></header><div id=\"transfer-roster-scroll\" "
|
||
"class=\"transfer-roster-scroll\"><div class=\"transfer-roster-table " +
|
||
std::string(b ? "data-b" : "data-a") + "\">";
|
||
std::vector<std::string> headers =
|
||
b ? std::vector<std::string>{"Spieler", "Alter", "Ecke",
|
||
"Frei", "Zwei", "Pass",
|
||
"Schuss", "Schnell", "Team"}
|
||
: std::vector<std::string>{"Spieler", "Pos.", "Fuß", "Typ",
|
||
"Kond.", "Tech.", "Form", "Stärke"};
|
||
if (complete) {
|
||
const std::vector<std::string> extras =
|
||
b ? std::vector<std::string>{"Liga", "Pokal", "Europa", "Tore",
|
||
"Vorlagen"}
|
||
: std::vector<std::string>{"Alter", "Land", "Spiele", "Tore",
|
||
"Vorlagen"};
|
||
headers.insert(headers.end(), extras.begin(), extras.end());
|
||
}
|
||
const double namewidth = complete ? 22. : 33.,
|
||
width = (100 - namewidth) / (headers.size() - 1);
|
||
out += "<div class=\"transfer-roster-row head\">";
|
||
for (size_t i = 0; i < headers.size(); ++i)
|
||
out += "<div style=\"width:" + scalar(i ? width : namewidth) +
|
||
"%;\"><span>" + headers[i] + "</span></div>";
|
||
out += "</div>";
|
||
for (size_t i = 0; i < ours.size(); ++i) {
|
||
const auto &r = ours[i];
|
||
const auto id = r.at("id").get<std::string>();
|
||
std::vector<std::string> values;
|
||
if (b) {
|
||
values.push_back(transfer_ui_number(r.at("age")));
|
||
for (const auto &v : r.at("skills"))
|
||
values.push_back(transfer_ui_number(v));
|
||
} else
|
||
values = {transfer_ui_role(r.at("position")),
|
||
trait(r.at("foot"), true),
|
||
trait(r.at("type"), false),
|
||
transfer_ui_number(r.at("condition")),
|
||
transfer_ui_number(r.at("technique")),
|
||
transfer_ui_number(r.at("form")),
|
||
transfer_ui_number(r.at("strength"))};
|
||
if (complete) {
|
||
if (b) {
|
||
for (auto *key :
|
||
{"league_games", "cup_games", "europe_games", "goals", "assists"})
|
||
values.push_back(transfer_ui_number(r.at(key)));
|
||
} else {
|
||
values.push_back(transfer_ui_number(r.at("age")));
|
||
values.push_back(nation(r));
|
||
for (auto *key : {"games", "goals", "assists"})
|
||
values.push_back(transfer_ui_number(r.at(key)));
|
||
}
|
||
}
|
||
out += "<div class=\"transfer-roster-row " +
|
||
std::string(i % 2 == 0 ? "striped " : "") +
|
||
(transfer_view_.value("side", std::string()) == "own" &&
|
||
transfer_view_.at("own") == id
|
||
? "selected"
|
||
: "") +
|
||
"\"><div class=\"transfer-name-cell\" style=\"width:" +
|
||
scalar(namewidth) + "%;\">" +
|
||
btn("transfer-own",
|
||
"<span class=\"transfer-player-rank\">" + std::to_string(i + 1) +
|
||
".</span><span class=\"transfer-player-name\">" +
|
||
esc(r.at("name").get<std::string>()) + "</span>" +
|
||
(listed(id) ? "<span class=\"transfer-list-marker\">●</span>"
|
||
: ""),
|
||
listed(id) ? "transfer-listed" : "",
|
||
"id=\"transfer-own-" + esc(id) + "\" data-player=\"" + esc(id) +
|
||
"\" aria-pressed=\"" +
|
||
(transfer_view_.value("side", std::string()) == "own" &&
|
||
transfer_view_.at("own") == id
|
||
? "true"
|
||
: "false") +
|
||
"\"") +
|
||
"</div>";
|
||
for (const auto &v : values)
|
||
out += "<div style=\"width:" + scalar(width) + "%;\"><span>" + v +
|
||
"</span></div>";
|
||
out += "</div>";
|
||
}
|
||
if (ours.empty())
|
||
out += "<p class=\"transfer-empty\">Keine Kaderspieler vorhanden.</p>";
|
||
out += "</div></div><p class=\"transfer-roster-note\">" +
|
||
std::string(
|
||
complete
|
||
? "Vollständige Kaderdaten"
|
||
: "Spieler links wählen, um zu verkaufen oder zu verleihen") +
|
||
"</p></section>";
|
||
if (!complete) {
|
||
out +=
|
||
"<section id=\"transfer-market-scroll\" class=\"transfer-market\"><div "
|
||
"class=\"transfer-market-content\"><header><h2>Angebote</"
|
||
"h2><span>Kondition · Technik · Form (Stärke)</span></header><div "
|
||
"class=\"transfer-name-search\"><input id=\"transfer-search\" "
|
||
"maxlength=\"40\" value=\"" +
|
||
esc(transfer_view_.value("query",
|
||
data.at("query").get<std::string>())) +
|
||
"\" aria-label=\"Spielername suchen\" placeholder=\"Spielername "
|
||
"suchen\"/>" +
|
||
btn("transfer-search", "Finden", "", "id=\"transfer-find\"") +
|
||
"</div><div id=\"transfer-offers\" class=\"transfer-offers\">";
|
||
for (size_t i = size_t(page) * 6;
|
||
i < std::min(pool.size(), size_t(page + 1) * 6); ++i) {
|
||
const auto &r = pool[i];
|
||
const auto id = r.at("id").get<std::string>();
|
||
const bool mine = r.at("own");
|
||
out += btn(
|
||
mine ? "transfer-own" : "transfer-market",
|
||
"<span class=\"transfer-market-name\">" + nation(r) + "<strong>" +
|
||
esc(r.at("name").get<std::string>()) + "</strong><span>" +
|
||
transfer_ui_role(r.at("position")) + "</span>" +
|
||
trait(r.at("foot"), true) + trait(r.at("type"), false) +
|
||
"</span><span class=\"transfer-market-attributes\"><span>" +
|
||
transfer_ui_number(r.at("condition")) + " · " +
|
||
transfer_ui_number(r.at("technique")) + " · " +
|
||
transfer_ui_number(r.at("form")) + " <strong>(" +
|
||
transfer_ui_number(r.at("strength")) + ")</strong></span><span>" +
|
||
transfer_ui_number(r.at("age")) + " Jahre</span></span>",
|
||
"transfer-market-player " +
|
||
std::string(mine ? "transfer-own-listing " : "") +
|
||
((mine ? transfer_view_.at("own")
|
||
: transfer_view_.at("market")) == id &&
|
||
transfer_view_.value("side", std::string()) ==
|
||
(mine ? "own" : "market")
|
||
? "selected"
|
||
: ""),
|
||
"id=\"transfer-market-" + esc(id) + "\" data-player=\"" + esc(id) +
|
||
"\" data-preview=\"" + esc(id) + "\" aria-pressed=\"" +
|
||
(((mine ? transfer_view_.at("own")
|
||
: transfer_view_.at("market")) == id)
|
||
? "true"
|
||
: "false") +
|
||
"\" style=\"" +
|
||
rect(0, (i - size_t(page) * 6) * 128.7864583, 1062,
|
||
120.7864583) +
|
||
"\"");
|
||
}
|
||
if (pool.empty())
|
||
out +=
|
||
"<p class=\"transfer-empty\">Keine Spieler für diese "
|
||
"Auswahl.<small>Name, Positionen oder Suchprofil ändern.</small></p>";
|
||
out +=
|
||
"</div><div class=\"transfer-market-pages\">" +
|
||
btn("transfer-page", "‹", "",
|
||
"id=\"transfer-page-previous\" data-step=\"-1\" " +
|
||
std::string(page == 0 ? "disabled" : "")) +
|
||
"<span>" +
|
||
(pool.empty()
|
||
? std::string("Keine Angebote")
|
||
: std::to_string(page * 6 + 1) + "–" +
|
||
std::to_string(std::min(pool.size(), size_t(page + 1) * 6)) +
|
||
" von " + std::to_string(pool.size())) +
|
||
"</span>" +
|
||
btn("transfer-page", "›", "",
|
||
"id=\"transfer-page-next\" data-step=\"1\" " +
|
||
std::string(page + 1 >= pages ? "disabled" : "")) +
|
||
"</div><section id=\"transfer-preview\" class=\"transfer-preview\">";
|
||
if (preview.is_object()) {
|
||
const auto *source = world_->find("clubs", preview.at("club"));
|
||
const auto fee = preview.at("fee").is_number_integer() ? preview.at("fee").get<int64_t>() : 0;
|
||
const auto remaining = (engine_mode_ ? engine_transfer_value_.at("cash").get<int64_t>() : snapshot.state.at("cash").get<int64_t>()) +
|
||
(preview.at("own") == true ? fee : -fee);
|
||
out += "<p>" + (source?label(source,32):esc(preview.value("seller_name",std::string("—")))) + "</p><div><section><span>" +
|
||
std::string(preview.at("own") == true ? "Marktwert"
|
||
: "Geforderte Ablöse") +
|
||
"</span><strong>" + esc(preview.at("fee").is_null()?std::string("—"):transfer_money(fee)) +
|
||
"</strong></section><section><span>Restkapital nach " +
|
||
std::string(preview.at("own") == true ? "Verkauf" : "Kauf") +
|
||
"</span><strong class=\"" +
|
||
money_classes(remaining) + "\">" +
|
||
esc(preview.at("fee").is_null()?std::string("—"):transfer_money(remaining)) + "</strong></section></div>";
|
||
} else
|
||
out += "<p>Wähle einen angebotenen Spieler.</p>";
|
||
out += "</section><nav class=\"transfer-filters\">";
|
||
const std::array<const char *, 5> filters{"Alle", "Tor", "ABW", "MIT",
|
||
"STU"};
|
||
for (int i = 0; i < 5; ++i)
|
||
out +=
|
||
btn("transfer-filter", filters[size_t(i)], "",
|
||
"id=\"transfer-filter-" + std::to_string(i) + "\" data-index=\"" +
|
||
std::to_string(i) + "\" aria-pressed=\"" +
|
||
std::string((i == 0 ? data.at("positions") == 15
|
||
: bool(data.at("positions").get<int>() &
|
||
(1 << (i - 1))))
|
||
? "true"
|
||
: "false") +
|
||
"\"");
|
||
out += "</nav>";
|
||
const auto strengths = engine_mode_ ? engine_transfer_value_.at("strengths") : demo_transfer_strengths(
|
||
snapshot.state, *world_, own, demo_lineup_active(snapshot.state));
|
||
const auto scope = transfer_view_.value("scope", std::string("active"));
|
||
out +=
|
||
"<section class=\"transfer-strengths\"><header><nav>" +
|
||
btn("transfer-scope", "Aktive", "",
|
||
"id=\"transfer-scope-active\" data-scope=\"active\" "
|
||
"aria-pressed=\"" +
|
||
std::string(scope == "active" ? "true" : "false") + "\"") +
|
||
btn("transfer-scope", "Team", "",
|
||
"id=\"transfer-scope-team\" data-scope=\"team\" aria-pressed=\"" +
|
||
std::string(scope == "team" ? "true" : "false") + "\"") +
|
||
"</nav><p>Durchschnitt <strong>" +
|
||
transfer_ui_number(
|
||
strengths.at(scope == "team" ? "team_average" : "active_average")) +
|
||
"</strong></p></header><div>";
|
||
for (int i = 0; i < 4; ++i)
|
||
out += "<section><span>" +
|
||
std::string(std::array<const char *, 4>{
|
||
"Tor", "Abwehr", "Mittelfeld", "Sturm"}[size_t(i)]) +
|
||
"</span><strong>" +
|
||
transfer_ui_number(strengths.at(scope)[size_t(i)]) +
|
||
"</strong></section>";
|
||
out += "</div></section><div class=\"transfer-business\"><p>" +
|
||
(chosen.is_object()
|
||
? std::string(chosen.at("own") == true ? "Eigener Spieler: "
|
||
: "Marktspieler: ") +
|
||
esc(chosen.at("name").get<std::string>())
|
||
: "Kein Marktspieler ausgewählt") +
|
||
"</p><div>";
|
||
const bool mine = chosen.is_object() && chosen.at("own") == true;
|
||
const bool pending = engine_mode_ && !mine && chosen.is_object() && chosen.value("bid",Json()).is_object();
|
||
const bool pending_loan = pending && chosen.at("bid").value("loan",false);
|
||
out +=
|
||
btn("transfer-offer",
|
||
mine && listed(chosen.at("id")) ? "Vom Markt nehmen" : "Verkaufen",
|
||
"",
|
||
"id=\"transfer-offer-buy-sell\" data-kind=\"" +
|
||
std::string(mine ? "sell" : "buy") + "\" " +
|
||
std::string(chosen.is_object() && (!engine_mode_ || !mine || !listed(chosen.at("id"))) && (!pending || !pending_loan) ? "" : "disabled")) +
|
||
btn("transfer-offer", "Verleihen", "",
|
||
"id=\"transfer-offer-loan-lend\" data-kind=\"" +
|
||
std::string(mine ? "lend" : "loan") + "\" " +
|
||
std::string(chosen.is_object() && (!engine_mode_ || !mine || !listed(chosen.at("id"))) && (!pending || pending_loan) && (!engine_mode_ || mine || chosen.value("loan_allowed",false)) ? "" : "disabled")) +
|
||
"</div></div></div></section>";
|
||
}
|
||
out += "</div><nav class=\"transfer-actions\">" +
|
||
btn("transfer-data", b ? "Daten A" : "Daten B", "",
|
||
"id=\"transfer-data\"") +
|
||
btn("transfer-all", complete ? "Angebote" : "Komplett", "",
|
||
"id=\"transfer-all\" aria-pressed=\"" +
|
||
std::string(complete ? "true" : "false") + "\"");
|
||
if (!complete)
|
||
out += btn("transfer-criteria", "Spieler suchen", "",
|
||
"id=\"transfer-criteria\"") +
|
||
btn("transfer-suggest", "Vorschlag", "", "id=\"transfer-suggest\"") +
|
||
btn("transfer-poach", "Abwerben", "", "id=\"transfer-poach\" " + std::string(engine_mode_?"disabled title=\"Noch nicht angebunden\"":"")) +
|
||
btn("transfer-orders",
|
||
"Aufträge (" + std::to_string(data.at("orders").size()) + ")",
|
||
"", "id=\"transfer-orders\"");
|
||
transfer_view_["restore_scroll"] = true;
|
||
return out + "</nav></section>" + render_transfer_dialog();
|
||
}
|
||
|
||
std::string App::render_transfer_dialog() {
|
||
if (transfer_dialog_.empty())
|
||
return {};
|
||
const auto snapshot = engine_mode_ ? Snapshot{} : snap();
|
||
const auto actor = engine_mode_ ? engine_data_.at("desktop").at("meta").at("scope").at("teamId").get<std::string>() : transfer_ui_club(snapshot);
|
||
std::string title, body, actions;
|
||
double height = 500;
|
||
const auto button = [&](const char *action, const std::string &caption,
|
||
const std::string &attrs = "") {
|
||
return btn(action, esc(caption), "transfer-dialog-button", attrs);
|
||
};
|
||
const auto close = [&](const std::string &caption = "Abbruch") {
|
||
return button("transfer-close", caption, "id=\"transfer-close\"");
|
||
};
|
||
if (transfer_dialog_ == "offer") {
|
||
height = 1210.5;
|
||
const auto &d = transfer_draft_;
|
||
const auto &r = d.at("row");
|
||
const auto kind = d.at("kind").get<std::string>();
|
||
const bool loan = kind == "loan" || kind == "lend", mine = r.at("own");
|
||
const std::map<std::string, std::string> kinds{{"buy", "Kaufen"},
|
||
{"loan", "Ausleihen"},
|
||
{"sell", "Verkaufen"},
|
||
{"lend", "Verleihen"}};
|
||
title =
|
||
(d.at("poached") == true ? std::string("Abwerben") : kinds.at(kind)) +
|
||
" · " + r.at("name").get<std::string>();
|
||
const auto flag = ui_nation_flag_svg(transfer_ui_text(r.at("nation"), ""));
|
||
const auto flag_image =
|
||
flag.empty()
|
||
? std::string("<span>—</span>")
|
||
: picture(renderer_.diagram("transfer-offer-flag", flag, 180), 60,
|
||
40);
|
||
body = "<section class=\"transfer-offer-layout\"><header><div "
|
||
"class=\"transfer-offer-flag\">" +
|
||
flag_image + "</div><div class=\"transfer-offer-person\"><strong>" +
|
||
esc(r.at("name").get<std::string>()) + "</strong><span>" +
|
||
transfer_ui_role(r.at("position")) + " · " +
|
||
transfer_ui_number(r.at("age")) + " Jahre · Stärke " +
|
||
transfer_ui_number(r.at("strength")) +
|
||
"</span></div><div class=\"transfer-offer-club\">" +
|
||
(world_->find("clubs",r.at("club"))?label(world_->find("clubs",r.at("club")),58):esc(r.value("club_name",std::string("—")))) +
|
||
"</div></header><div class=\"transfer-demands\"><section><span>" +
|
||
std::string(engine_mode_ ? "Ablöseforderung" : loan ? "Fiktive Leihgebühr" : "Ungefährer Marktwert") +
|
||
"</span><strong>" + esc(transfer_money(d.at("demand_fee").get<int64_t>())) +
|
||
"</strong></section><section><span>" +
|
||
std::string(engine_mode_ ? "Gehaltsreferenz / Monat" : mine ? "Aktuelles Monatsgehalt" : "Gehaltswunsch") +
|
||
"</span><strong>" +
|
||
(d.at("demand_salary").is_number_integer()
|
||
? esc(transfer_money(d.at("demand_salary").get<int64_t>()))
|
||
: "—") +
|
||
"</strong></section></div><h3 class=\"transfer-offer-your\">Dein "
|
||
"Angebot</h3><div class=\"transfer-offer-inputs\">";
|
||
for (int i = 0; i < 3; ++i) {
|
||
const auto field = i == 0 ? "fee" : i == 1 ? "salary" : "months";
|
||
const std::string caption = i == 0 ? (loan ? "Leihgebühr" : "Ablöse")
|
||
: i == 1 ? "Monatsgehalt"
|
||
: "Vertragsdauer";
|
||
body += "<div><span>" + caption + "</span>";
|
||
if (i < 2)
|
||
body += btn("transfer-amount",
|
||
esc(std::to_string(d.at(field).get<int64_t>())),
|
||
"transfer-amount-input amount-trigger",
|
||
"id=\"transfer-" + std::string(field) + "\" data-field=\"" +
|
||
field + "\" aria-label=\"" + caption + "\"");
|
||
else {
|
||
body += "<select id=\"transfer-months\" aria-label=\"Vertragsdauer in "
|
||
"Monaten\">";
|
||
for (int months : {12, 24, 36, 48})
|
||
if (!loan || months <= 24)
|
||
body += "<option value=\"" + std::to_string(months) + "\" " +
|
||
std::string(d.at("months") == months ? "selected" : "") +
|
||
">" + std::to_string(months) + " Monate</option>";
|
||
body += "</select>";
|
||
}
|
||
body += "</div>";
|
||
}
|
||
body += "</div><section "
|
||
"class=\"transfer-offer-premiums\"><h3>Mannschaftsprämien für "
|
||
"diesen Vertrag</h3><div>";
|
||
for (int i = 0; i < 7; ++i)
|
||
body +=
|
||
"<div class=\"transfer-premium-row\" style=\"" +
|
||
rect((i % 2) * 1063, 48 + (i / 2) * 82, 1029, 82) + "\"><span>" +
|
||
std::string(transfer_ui_bonuses[size_t(i)]) + "</span>" +
|
||
btn("transfer-bonus", transfer_ui_number(engine_mode_&&i>=3?Json(d.at("bonuses")[size_t(i)].get<int>()*5):d.at("bonuses")[size_t(i)]),
|
||
"amount-trigger",
|
||
"id=\"transfer-bonus-" + std::to_string(i) + "\" data-index=\"" +
|
||
std::to_string(i) + "\"") +
|
||
"</div>";
|
||
body += "</div></section><p class=\"transfer-offer-note\">" +
|
||
std::string(engine_mode_ ? "Die Engine entscheidet nach Bestätigung über dieses Angebot. Die Konditionen werden erst beim Absenden verbindlich." : mine ? "Der Spieler wird zum " +
|
||
std::string(loan ? "Verleihen" : "Verkauf") +
|
||
" auf dem Markt vorgemerkt."
|
||
: "Das Angebot wird vorgemerkt; die Entscheidung "
|
||
"des Spielers folgt später.") +
|
||
"</p></section>";
|
||
actions =
|
||
button("transfer-team-info", "Team-Info", "id=\"transfer-team-info\"") +
|
||
button("transfer-player-info", "Spieler-Info",
|
||
"id=\"transfer-player-info\"") +
|
||
close() +
|
||
button("transfer-submit", "Angebot",
|
||
"id=\"transfer-submit\" " +
|
||
std::string(d.value("can_submit", true) ? "" : "disabled"));
|
||
} else if (transfer_dialog_ == "search") {
|
||
height = 899;
|
||
title = "Spieler suchen";
|
||
const auto &d = transfer_search_draft_;
|
||
body = "<section class=\"transfer-search-editor\"><section "
|
||
"class=\"transfer-search-kind\"><h3>Art</h3><nav>";
|
||
for (int i = 0; i < 4; ++i)
|
||
body += btn(
|
||
"transfer-search-position",
|
||
std::array<const char *, 4>{"Tor", "ABW", "MIT", "STU"}[size_t(i)],
|
||
"",
|
||
"id=\"transfer-search-position-" + std::to_string(i) +
|
||
"\" data-index=\"" + std::to_string(i) + "\" aria-pressed=\"" +
|
||
std::string(d.at("positions").get<int>() & (1 << i) ? "true"
|
||
: "false") +
|
||
"\"");
|
||
body += "</nav></section><section class=\"transfer-search-ranges\">";
|
||
const std::array<std::pair<const char *, const char *>, 4> ranges{
|
||
{{"age_min", "Alter von"},
|
||
{"age_max", "Alter bis"},
|
||
{"strength_min", "Stärke von"},
|
||
{"strength_max", "Stärke bis"}}};
|
||
for (int i = 0; i < 4; ++i) {
|
||
const auto [key, caption] = ranges[size_t(i)];
|
||
body += "<div style=\"" +
|
||
rect((i % 2) * 1068.5, 20 + (i / 2) * 57, 1023.5, 31) +
|
||
"\"><span>" + caption +
|
||
"</span><input type=\"range\" id=\"transfer-range-" + key +
|
||
"\" data-criterion=\"" + key + "\" min=\"" +
|
||
std::to_string(i < 2 ? 16 : 0) + "\" max=\"" +
|
||
std::to_string(i < 2 ? (engine_mode_?47:40) : 100) + "\" step=\"1\" value=\"" +
|
||
transfer_ui_number(d.at(key)) +
|
||
"\"/><output id=\"transfer-range-value-" + key + "\">" +
|
||
transfer_ui_number(d.at(key)) + "</output></div>";
|
||
}
|
||
body += "</section><section class=\"transfer-search-traits\"><h3>Typ · "
|
||
"darauf achten</h3><nav>";
|
||
for (int i = 0; i < 3; ++i)
|
||
body += btn(
|
||
"transfer-search-trait",
|
||
std::array<const char *, 3>{"Kondition", "Technik",
|
||
"Form"}[size_t(i)],
|
||
"",
|
||
"id=\"transfer-search-trait-" + std::to_string(i) +
|
||
"\" data-index=\"" + std::to_string(i) + "\" aria-pressed=\"" +
|
||
std::string(d.at("traits").get<int>() & (1 << i) ? "true"
|
||
: "false") +
|
||
"\"");
|
||
body += "</nav></section><section class=\"transfer-search-space\">";
|
||
for (int i = 0; i < 2; ++i) {
|
||
const auto field = i ? "foot" : "type";
|
||
const std::array<const char *, 4> names =
|
||
i ? std::array<const char *, 4>{"Beliebig", "Links", "Beidfüßig",
|
||
"Rechts"}
|
||
: std::array<const char *, 4>{"Beliebig", "Defensiv",
|
||
"Ausgeglichen", "Offensiv"};
|
||
body += "<div><span>" + std::string(i ? "Spielseite" : "Spielweise") +
|
||
"</span><select id=\"transfer-criterion-" + field +
|
||
"\" data-criterion=\"" + field + "\" aria-label=\"" +
|
||
std::string(i ? "Spielseite" : "Spielweise") + "\">";
|
||
for (int n = 0; n < 4; ++n)
|
||
body += "<option value=\"" + std::to_string(n) + "\" " +
|
||
std::string(d.at(field) == n ? "selected" : "") + ">" +
|
||
names[size_t(n)] + "</option>";
|
||
body += "</select></div>";
|
||
}
|
||
body +=
|
||
"</section><section "
|
||
"class=\"transfer-search-budget\"><span>Preisvorstellung bis</span>" +
|
||
btn("transfer-search-budget",
|
||
esc(std::to_string(d.at("price_max").get<int64_t>())),
|
||
"amount-trigger",
|
||
"id=\"transfer-search-budget\" aria-label=\"Maximale "
|
||
"Ablösesumme\"") +
|
||
"</section></section>";
|
||
actions = close() +
|
||
button("transfer-search-reset", "Zurücksetzen",
|
||
"id=\"transfer-search-reset\"") +
|
||
button("transfer-search-apply", "Suchen",
|
||
"id=\"transfer-search-apply\"");
|
||
} else if (transfer_dialog_ == "player-info") {
|
||
height = 822;
|
||
const auto &r = transfer_draft_.at("row");
|
||
title = r.at("name").get<std::string>();
|
||
body = "<div class=\"transfer-player-info\"><div "
|
||
"class=\"transfer-info-photo\">" +
|
||
(r.at("photo").is_string()
|
||
? img(r.at("photo"), 440, 550, true, true, 650)
|
||
: engine_mode_ ? img("asset:player/generic/photo",440,550,true,false,650) : "<span>—</span>") +
|
||
"</div><div class=\"transfer-info-facts\">";
|
||
const std::vector<std::pair<std::string, std::string>> facts{
|
||
{"Verein", r.at("club_name")},
|
||
{"Position", transfer_ui_role(r.at("position"))},
|
||
{"Alter", transfer_ui_number(r.at("age")) + " Jahre"},
|
||
{"Kondition", transfer_ui_number(r.at("condition"))},
|
||
{"Technik", transfer_ui_number(r.at("technique"))},
|
||
{"Form", transfer_ui_number(r.at("form"))},
|
||
{"Stärke", transfer_ui_number(r.at("strength"))},
|
||
{"Fuß", r.at("foot").is_number_integer()
|
||
? std::array<const char *, 4>{"—", "Links", "Beidfüßig",
|
||
"Rechts"}[size_t(
|
||
r.at("foot").get<int>())]
|
||
: "—"},
|
||
{"Typ", r.at("type").is_number_integer()
|
||
? std::array<const char *,
|
||
4>{"—", "Defensiv", "Ausgeglichen",
|
||
"Offensiv"}[size_t(r.at("type").get<int>())]
|
||
: "—"}};
|
||
for (size_t i = 0; i < facts.size(); ++i)
|
||
body += "<div style=\"" +
|
||
rect((i % 2) * 823.5, (i / 2) * 115, 783.5, 91) + "\"><span>" +
|
||
esc(facts[i].first) + "</span><strong>" + esc(facts[i].second) +
|
||
"</strong></div>";
|
||
body += "</div></div>";
|
||
actions = button("transfer-offer-back", "Zurück zum Angebot",
|
||
"id=\"transfer-offer-back\"");
|
||
} else if (transfer_dialog_ == "team-info") {
|
||
height = 800;
|
||
title = "Team-Info";
|
||
const auto values = engine_mode_ ? engine_transfer_value_.at("strengths") : demo_transfer_strengths(
|
||
snapshot.state, *world_, actor, demo_lineup_active(snapshot.state));
|
||
body = "<div class=\"transfer-team-info\"><h3>" +
|
||
label(world_->find("clubs", actor), 58) +
|
||
"</h3><div class=\"transfer-info-table\"><div "
|
||
"class=\"transfer-info-table-row "
|
||
"head\"><span>Mannschaftsteil</span><span>Aktive</span><span>Team</"
|
||
"span></div>";
|
||
for (int i = 0; i < 4; ++i)
|
||
body +=
|
||
"<div class=\"transfer-info-table-row\"><span>" +
|
||
std::string(std::array<const char *, 4>{"Tor", "Abwehr", "Mittelfeld",
|
||
"Sturm"}[size_t(i)]) +
|
||
"</span><span>" + transfer_ui_number(values.at("active")[size_t(i)]) +
|
||
"</span><span>" + transfer_ui_number(values.at("team")[size_t(i)]) +
|
||
"</span></div>";
|
||
body += "</div></div>";
|
||
actions = button("transfer-offer-back", "Zurück zum Angebot",
|
||
"id=\"transfer-offer-back\"");
|
||
} else if (transfer_dialog_ == "poach-clubs") {
|
||
height = 1141;
|
||
title = "Spieler abwerben";
|
||
const auto leagues = world_->leagues();
|
||
if (transfer_poach_league_.empty() && !leagues.empty())
|
||
transfer_poach_league_ = leagues[0]->at("id").get<std::string>();
|
||
const auto *league = world_->find("competitions", transfer_poach_league_);
|
||
const auto country = league ? league->value("nation", "") : "";
|
||
body = "<section class=\"transfer-poach\"><p>Verein wählen, danach einen "
|
||
"Spieler aus dessen Beispielkader.</p><nav "
|
||
"class=\"transfer-poach-pickers\"><select "
|
||
"id=\"transfer-poach-country\" aria-label=\"Land\">";
|
||
for (const auto &nation : world_->rows("nations")) {
|
||
const auto id = nation.at("id").get<std::string>();
|
||
if (world_->leagues(id).empty())
|
||
continue;
|
||
body += "<option value=\"" + esc(id) + "\" " +
|
||
std::string(country == id ? "selected" : "") + ">" +
|
||
esc(world_->name(nation)) + "</option>";
|
||
}
|
||
body +=
|
||
"</select><select id=\"transfer-poach-league\" aria-label=\"Liga\">";
|
||
for (const auto *l : world_->leagues(country))
|
||
body +=
|
||
"<option value=\"" + esc(l->at("id").get<std::string>()) + "\" " +
|
||
std::string(l->at("id") == transfer_poach_league_ ? "selected" : "") +
|
||
">" + esc(world_->name(*l)) + "</option>";
|
||
body +=
|
||
"</select></nav><div id=\"transfer-poach-scroll\" data-scope=\"clubs-" +
|
||
esc(transfer_poach_league_) + "\" class=\"transfer-poach-clubs\">";
|
||
const auto clubs = world_->clubs(transfer_poach_league_);
|
||
for (size_t i = 0; i < clubs.size(); ++i)
|
||
body += btn(
|
||
"transfer-poach-club", label(clubs[i], 52), "",
|
||
"id=\"transfer-poach-club-" +
|
||
esc(clubs[i]->at("id").get<std::string>()) + "\" data-club=\"" +
|
||
esc(clubs[i]->at("id").get<std::string>()) + "\" style=\"" +
|
||
rect((i % 4) * 527, (i / 4) * 140, 511, 124) + "\" " +
|
||
std::string(clubs[i]->at("id") == actor ? "disabled" : ""));
|
||
body += "</div></section>";
|
||
actions = close();
|
||
} else if (transfer_dialog_ == "poach-roster") {
|
||
height = 1400;
|
||
const auto *club = world_->find("clubs", transfer_poach_club_);
|
||
title = "Abwerben · " + std::string(club ? world_->name(*club) : "—");
|
||
const auto rows = demo_transfer_roster(snapshot.state, *world_, actor,
|
||
transfer_poach_club_);
|
||
body = "<div id=\"transfer-poach-scroll\" data-scope=\"roster-" +
|
||
esc(transfer_poach_club_) +
|
||
"\" class=\"transfer-poach-roster\"><div class=\"transfer-poach-row "
|
||
"head\"><span>Spieler</span><span>Pos.</span><span>Alter</"
|
||
"span><span>Stärke</span><span>Marktwert</span></div>";
|
||
if (rows.value("ok", false))
|
||
for (const auto &r : rows.at("rows"))
|
||
body +=
|
||
"<div class=\"transfer-poach-row\">" +
|
||
btn("transfer-poach-player", esc(r.at("name").get<std::string>()),
|
||
"",
|
||
"id=\"transfer-poach-player-" +
|
||
esc(r.at("id").get<std::string>()) + "\" data-player=\"" +
|
||
esc(r.at("id").get<std::string>()) + "\"") +
|
||
"<span>" + transfer_ui_role(r.at("position")) + "</span><span>" +
|
||
transfer_ui_number(r.at("age")) + "</span><span>" +
|
||
transfer_ui_number(r.at("strength")) + "</span><span>" +
|
||
esc(transfer_money((r.at("fee").get<int64_t>() * 3 + 1) / 2)) +
|
||
"</span></div>";
|
||
body += "</div>";
|
||
actions = button("transfer-poach-back", "Zurück zu Vereinen",
|
||
"id=\"transfer-poach-back\"") +
|
||
close();
|
||
} else if (transfer_dialog_ == "orders") {
|
||
title = "Vorgemerkte Transferaufträge";
|
||
const auto rows =
|
||
transfer_data().at("orders");
|
||
height = rows.empty() ? 430 : std::min(1450., 352. + rows.size() * 74.);
|
||
body = "<div id=\"transfer-orders-scroll\" class=\"transfer-order-list\">";
|
||
if (rows.empty())
|
||
body += "<p>Noch keine Transferaufträge vorgemerkt.</p>";
|
||
else {
|
||
body += "<div class=\"transfer-order-row "
|
||
"head\"><span>Spieler</span><span>Art</span><span>Betrag</"
|
||
"span><span>Laufzeit</span><span></span></div>";
|
||
const std::map<std::string, std::string> kinds{{"buy", "Kaufen"},
|
||
{"loan", "Ausleihen"},
|
||
{"sell", "Verkaufen"},
|
||
{"lend", "Verleihen"}};
|
||
for (size_t i = 0; i < rows.size(); ++i) {
|
||
const auto &o = rows[i];
|
||
body +=
|
||
"<div class=\"transfer-order-row\"><span>" +
|
||
esc(o.at("name").get<std::string>()) + "</span><span>" +
|
||
esc(engine_mode_ ? "Gebot" : o.at("poached") == true ? "Abwerben" : kinds.at(o.at("kind"))) +
|
||
"</span><span>" + esc(transfer_money(o.at("fee").get<int64_t>())) +
|
||
"</span><span>" + std::to_string(o.at("months").get<int>()) +
|
||
" Monate</span>" +
|
||
btn("transfer-order-delete", "×", "",
|
||
"id=\"transfer-order-delete-" + std::to_string(i) +
|
||
"\" data-index=\"" + std::to_string(i) +
|
||
"\" aria-label=\"Auftrag zurücknehmen\" " + std::string(engine_mode_?"disabled title=\"Noch nicht angebunden\"":"")) +
|
||
"</div>";
|
||
}
|
||
}
|
||
body += "</div>";
|
||
actions = close("Zurück");
|
||
} else {
|
||
title = transfer_dialog_ == "booked" ? (engine_mode_ ? "Transferauftrag" : "Auftrag vorgemerkt")
|
||
: "Transferliste voll";
|
||
body = "<p class=\"transfer-notice\">" + esc(transfer_notice_) + "</p>";
|
||
actions = close("Verstanden");
|
||
}
|
||
return "<div id=\"transfer-layer\" class=\"transfer-layer\"><section "
|
||
"id=\"transfer-dialog\" class=\"transfer-dialog " +
|
||
esc(transfer_dialog_) +
|
||
"\" role=\"dialog\" aria-modal=\"true\" "
|
||
"aria-labelledby=\"transfer-dialog-title\" style=\"height:" +
|
||
scalar(height) + "dp;\"><h2 id=\"transfer-dialog-title\">" +
|
||
esc(title) +
|
||
"</h2><div id=\"transfer-dialog-scroll\" "
|
||
"class=\"transfer-dialog-scroll\" data-dialog=\"" +
|
||
esc(transfer_dialog_) + "\">" + body +
|
||
"</div><nav class=\"transfer-dialog-actions\">" + actions +
|
||
"</nav></section></div>";
|
||
}
|