// SPDX-License-Identifier: GPL-3.0-only #pragma once #include "modern/ui/controls.hpp" #include #include namespace bmh::modern_ui { using PostmatchBadge = std::function; inline std::string postmatch_position_label(const std::string &position) { return position == "gk" ? "TW" : position == "def" ? "ABW" : position == "mid" ? "MIT" : "STU"; } inline std::string postmatch_pitch_svg(const std::string &color) { return ""; } inline std::string postmatch_eleven_markup(const Json &eleven, const PostmatchBadge &badge, const std::string &pitch) { const auto text = [](const std::string &s) { return "" + editor::escaped(s) + ""; }; const bool available = eleven.value("available", false) && eleven.contains("rows") && eleven.at("rows").is_array() && eleven.at("rows").size() == 11; std::string out = "
" + pitch + "
"; if (available) { for (const auto &[position, top] : std::array, 4>{ {{"gk", 89}, {"def", 68}, {"mid", 45}, {"fwd", 22}}}) { size_t count = 0; for (const auto &row : eleven.at("rows")) if (row.at("position") == position) ++count; size_t column = 0, index = 0; for (const auto &row : eleven.at("rows")) { const auto n = index++; if (row.at("position") != position) continue; ++column; const auto name = row.at("player").at("name").get(); const auto at = name.find_last_of(' '); out += button_markup( "postmatch-player", "" + badge(row.at("team"), 60) + "" + text(at == name.npos ? name : name.substr(at + 1)) + "", "postmatch-field-player", "id=\"postmatch-nominee-" + std::to_string(n) + "\" data-id=\"" + editor::escaped(row.at("player").at("id").get()) + "\" style=\"left:" + std::to_string(100.0 * column / (count + 1)) + "%;top:" + std::to_string(top) + "%;\" aria-label=\"" + editor::escaped(name + " · " + row.at("team").at("name").get()) + "\""); } } } out += "
"; if (!available) out += "

" + text("Keine Nominierungen aufgezeichnet") + "

" + text("Die feste Liveaufnahme enthält keine Spielernoten oder " "Nominierungen. Es wird keine Elf aus Kaderstärken oder " "vermuteten Ereignisakteuren erfunden.") + "

" + text("Ergebnisse und Bericht zeigen ausschließlich die vorhandene " "Aufzeichnung.") + "

"; else { out += "

" + text(eleven.value("notice", "Explizit gelieferte Nominierungen")) + "

    "; size_t index = 0; for (const auto &row : eleven.at("rows")) { const auto n = index++; const auto id = row.at("player").at("id").get(); out += "
  1. " + text(postmatch_position_label(row.at("position"))) + "" + button_markup( "postmatch-player", editor::escaped(row.at("player").at("name").get()), "postmatch-nominee-name", "id=\"postmatch-nominee-name-" + std::to_string(n) + "\" data-id=\"" + editor::escaped(id) + "\"") + button_markup( "postmatch-club", badge(row.at("team"), 38) + text(row.at("team").at("name")), "postmatch-nominee-club", "data-id=\"" + editor::escaped(row.at("team").at("id").get()) + "\"") + "
  2. "; } out += "
"; } return out + "
"; } inline void fit_postmatch_pitch(Rml::ElementDocument &doc) { auto *holder = doc.GetElementById("postmatch-pitch-holder"), *surface = doc.GetElementById("postmatch-pitch-surface"); if (!holder || !surface) return; const auto size = holder->GetBox().GetSize(Rml::BoxArea::Content); const float height = std::min(size.y, size.x * 1110.f / 740), width = height * 740 / 1110; const auto set = [](Rml::Element *node, Rml::PropertyId id, float value) { const auto *old = node->GetLocalProperty(id); if (!old || old->unit != Rml::Unit::PX || std::abs(old->Get() - value) > .02f) node->SetProperty(id, Rml::Property(value, Rml::Unit::PX)); }; set(surface, Rml::PropertyId::Width, width); set(surface, Rml::PropertyId::Height, height); set(surface, Rml::PropertyId::Left, (size.x - width) / 2); set(surface, Rml::PropertyId::Top, (size.y - height) / 2); if (auto *art = doc.GetElementById("postmatch-pitch-art")) for (auto *node : {art, art->QuerySelector(".image-frame"), art->QuerySelector("img")}) if (node) { set(node, Rml::PropertyId::Width, width); set(node, Rml::PropertyId::Height, height); } } inline std::string postmatch_nominee_detail(const Json &row, const PostmatchBadge &badge) { const auto text = [](const std::string &v) { return "" + editor::escaped(v) + ""; }; return "
" + badge(row.at("team"), 120) + "

" + text(row.at("team").at("name")) + "

Position
" + text(postmatch_position_label(row.at("position"))) + "
Note
" + text(row.at("rating").is_null() ? "—" : row.at("rating").dump()) + "
"; } } // namespace bmh::modern_ui