Files
Dreierpack-Manager/src/modern/ui/engine_widgets.inc
T

69 lines
3.1 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
std::string App::engine_widget_crest(const Json &team, double size) {
const auto *club = world_->find("clubs", team.at("id").get<std::string>());
if (club)
return crest(club, size);
return picture(renderer_.crest(team.value("crestAssetId", std::string()),
theme_ == "silver"),
size, size);
}
std::string App::engine_widget(const std::string &id, const Json &o) {
if (id == "news")
return engine_news_value_.is_object() ? render_news_widget(o)
: std::string();
if (id != "warnings" && id != "competition" && id != "own-summary" &&
id != "opponent-summary")
return {};
const auto data = engine_widgets_projection(engine_data_);
if (id == "warnings")
return widget_warnings(data.at("warnings"), o);
if (id == "own-summary" || id == "opponent-summary") {
const auto &row = data.at(id == "own-summary" ? "own" : "opponent");
if (!row.is_object())
return widget_heading("Platz & Stärke", false) +
"<div class=\"center\">Noch kein Gegner bestätigt.</div>";
const auto *club =
world_->find("clubs", row.at("teamId").get<std::string>());
const auto number = [&](const char *key) {
return row.at(key).is_null() ? std::string("—")
: std::to_string(row.at(key).get<int>());
};
std::string name = club ? world_->name(*club) : "Nationalteam";
if (!club) {
const auto &desk = engine_data_.at("desktop").at("data");
if (desk.at("team").at("id") == row.at("teamId"))
name = engine_text(desk.at("team").at("name"));
else if (data.at("fixture").is_object())
for (const auto *side : {"home", "away"})
if (data.at("fixture").at(side).at("id") == row.at("teamId"))
name = engine_text(data.at("fixture").at(side).at("name"));
}
return widget_heading(name, false) +
"<div "
"class=\"desk-summary\"><div><small>Tabellenplatz</small><strong>" +
number("rank") +
"</strong></div><div><small>Teamstärke</small><strong>" +
number("strength") + "</strong></div></div>";
}
const auto &next = data.at("fixture");
if (!next.is_object())
return widget_heading("Nächste Begegnung", false) +
"<div class=\"desk-fixture center\"><span>Keine bestätigte "
"Begegnung.</span></div>";
const auto &home = next.at("home"), &away = next.at("away");
const auto team = [&](const Json &v) {
return "<div>" +
engine_widget_crest(v, o.at("w").get<int>() <= 472 ? 68 : 80) +
"<span>" + esc(engine_text(v.at("name"))) + "</span></div>";
};
return widget_heading("Nächste Begegnung", false) +
"<div class=\"desk-fixture\">" + team(home) +
"<div class=\"desk-fixture-centre\"><small>" +
esc(engine_text(next.at("competition"))) +
"</small><strong>–</strong><span>" +
(home.at("id") == data.at("own").at("teamId")
? std::string("Heimspiel")
: std::string("Auswärtsspiel")) +
"</span></div>" + team(away) + "</div>";
}