Bilanz > Zukunft shows the expected income and the result of the plan beside the planned costs. A match report in the inbox carries the crests of both clubs. The line-up's rows begin with the player's photo. The stadium's curves name their lowest, highest and latest figure. The friendly plan states the place in the table and the games played of every league club, and the opponent's tile shows them. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
165 lines
16 KiB
C++
165 lines
16 KiB
C++
// SPDX-License-Identifier: GPL-3.0-only
|
|
namespace {std::string news_body_markup(const std::string &text){auto value=esc(text);size_t at=0;while((at=value.find('\n',at))!=std::string::npos){value.replace(at,1,"<br/>");at+=5;}return value;}}
|
|
// The picture of a message: the crest of the club it is about, the flag for the national side,
|
|
// else one of four drawn signs: a letter, the doctor's case, a coin, a newspaper.
|
|
std::string App::render_news_art(const Json &message, double size) {
|
|
const auto kind = message.at("kind").get<std::string>();
|
|
const auto sign = [&](const char *name, const std::string &body) {
|
|
return picture(renderer_.diagram(std::string("news-sign-") + name, "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 48 48\">" + body + "</svg>", 192), size * .95, size * .95);
|
|
};
|
|
const auto has = [&](std::initializer_list<const char *> words) {
|
|
const auto text = message.value("title", std::string()) + " " + message.value("body", std::string());
|
|
return std::any_of(words.begin(), words.end(), [&](const char *word) { return text.find(word) != std::string::npos; });
|
|
};
|
|
static const std::string letter = "<path d=\"M6 12h36v24H6z\" fill=\"#fbf7ee\" stroke=\"#3a332b\" stroke-width=\"2\"/><path d=\"M6 12l18 14 18-14\" fill=\"none\" stroke=\"#3a332b\" stroke-width=\"2\"/>";
|
|
static const std::string doctor = "<rect x=\"8\" y=\"12\" width=\"32\" height=\"26\" rx=\"5\" fill=\"#fbf7ee\" stroke=\"#3a332b\" stroke-width=\"2\"/><path d=\"M24 17v16M16 25h16\" stroke=\"#c8402f\" stroke-width=\"5\"/>";
|
|
static const std::string coin = "<circle cx=\"24\" cy=\"24\" r=\"16\" fill=\"#f1cf7a\" stroke=\"#a8782e\" stroke-width=\"2.5\"/><path d=\"M30.5 18.5a8 8 0 1 0 0 11M15.5 22h10M15.5 26h10\" fill=\"none\" stroke=\"#6b4a12\" stroke-width=\"2.6\" stroke-linecap=\"round\"/>";
|
|
static const std::string paper = "<rect x=\"7\" y=\"9\" width=\"34\" height=\"30\" rx=\"2\" fill=\"#fbf7ee\" stroke=\"#3a332b\" stroke-width=\"2\"/><path d=\"M12 16h24M12 22h10M12 27h10M12 32h10\" stroke=\"#3a332b\" stroke-width=\"2\"/><rect x=\"26\" y=\"21\" width=\"10\" height=\"12\" fill=\"#c0b6a5\"/>";
|
|
std::string art;
|
|
if (kind == "national" || (message.contains("scope") && message.at("scope").value("kind", "") == "national"))
|
|
art = picture(renderer_.diagram("news-national-flag", ui_nation_flag_svg("de"), 176), size * .69, size * .46);
|
|
else if (kind == "club" || kind == "career")
|
|
art = crest(world_->find("clubs", message.value("scope", Json::object()).value("id", std::string())), size * .69);
|
|
// a report of a match shows both clubs: the one the report is about and its opponent
|
|
if (kind == "fixture" && message.contains("scope") && message.contains("article")) {
|
|
const auto &article = message.at("article");
|
|
const Json *data = article.is_object() && article.contains("event") && article.at("event").is_object() && article.at("event").contains("data") ? &article.at("event").at("data") : nullptr;
|
|
const auto *own = world_->find("clubs", message.at("scope").value("id", std::string()));
|
|
const auto *other = data && data->is_object() && data->contains("opponent") && data->at("opponent").is_object() ? world_->find("clubs", data->at("opponent").value("id", std::string())) : nullptr;
|
|
if (own && other) art = "<span class=\"news-art-pair\">" + crest(own, size * .46) + crest(other, size * .46) + "</span>";
|
|
}
|
|
if (art.empty()) {
|
|
// what a letter is about decides its sign: an injury, money, a report of a match
|
|
if (has({"verletz", "Verletz", "fällt", "Arzt", "Prellung", "prellung", "Zerrung", "riss"})) art = sign("doctor", doctor);
|
|
else if (kind == "finance" || has({"€", "Prämie", "prämie", "Werbe", "Sponsor", "Zinsen", "Kredit"})) art = sign("coin", coin);
|
|
else if (kind == "fixture" || message.value("category", std::string()) == "Bericht") art = sign("paper", paper);
|
|
else art = sign("letter", letter);
|
|
}
|
|
return "<div class=\"news-art news-art-" + esc(kind) + "\" style=\"width:" + scalar(size) + "dp;height:" + scalar(size) + "dp;\">" + art + "</div>";
|
|
}
|
|
// The messages of a folder as rows of the page: a dot while unread, the sender's picture, date
|
|
// and kind, the headline as a link, a line of the text, and the two things one does with a
|
|
// message. The controls replace this list alone while the player types a search.
|
|
std::string App::render_news_feed(const Json &data) {
|
|
const std::string ink = theme_ == "midnight" ? "#d2d6dc" : theme_ == "matchday" ? "#3a4830" : "#474238";
|
|
const auto icon = [&](const char *name, const char *path) {
|
|
return picture(renderer_.diagram(std::string("news-icon-") + name + "-" + theme_, "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 20 20\"><path d=\"" + std::string(path) + "\" fill=\"none\" stroke=\"" + ink +
|
|
"\" stroke-width=\"1.6\" stroke-linejoin=\"round\"/></svg>", 72), 36, 36);
|
|
};
|
|
std::string out;
|
|
for (const auto &m : data.at("items")) {
|
|
const auto id = m.at("id").get<std::string>(), name = m.at("title").get<std::string>();
|
|
const bool unread = m.at("read").is_boolean() && !m.at("read").get<bool>(), archived = m.at("folder") == "archive" || (engine_mode_ && m.at("folder") == "trash");
|
|
const auto category = m.at("category").get<std::string>();
|
|
out += "<div id=\"news-row-" + id + "\" class=\"nw-row" + std::string(unread ? " is-unread" : "") + "\"><span class=\"nw-dot\"></span><span class=\"nw-art\">" + render_news_art(m, 100) + "</span><div class=\"nw-copy\"><div class=\"pg-row pg-mut\" style=\"" +
|
|
pg_css("gap:8px;font-size:12px;") + "\"><span>" + esc(m.at("display_date").get<std::string>()) + "</span><span class=\"pg-tag" + std::string(category == "Bericht" ? " sage" : "") + "\">" + esc(category) + "</span>" +
|
|
(unread ? "<span class=\"pg-tag accent\">Neu</span>" : "") + (data.value("fictional", false) ? "<span class=\"pg-tag\">Demo</span>" : "") + "</div>" +
|
|
btn("news-open", "<span>" + esc(name) + "</span>", "pg-link nw-title", "id=\"news-read-" + id + "\" data-id=\"" + id + "\" aria-label=\"Nachricht lesen: " + esc(name) + "\"") +
|
|
// a one-line message is its own headline; the excerpt would only repeat it
|
|
(m.at("body").get<std::string>() == name ? std::string() : "<span class=\"pg-mut pg-nowrap nw-excerpt\">" + esc(m.at("body").get<std::string>()) + "</span>") + "</div><div class=\"pg-row\" style=\"" + pg_css("gap:4px;") + "flex:none;\">" +
|
|
pg_button("news-move", icon(archived ? "restore" : "archive", archived ? "M3 10l4-4v3h10v2H7v3z" : "M3 4h14v4H3zM4 8v8h12V8M8 11h4"), "round",
|
|
"id=\"news-move-" + id + "\" data-id=\"" + id + "\" aria-label=\"" + std::string(archived ? "Ins Postfach verschieben: " : "Archivieren: ") + esc(name) + "\" title=\"" + std::string(archived ? "Ins Postfach verschieben" : "Archivieren") + "\" " +
|
|
std::string(engine_mode_ && m.value("mutable", false) == false ? "disabled" : "")) +
|
|
pg_button("news-delete", icon("trash", "M4 6h12M8 6V4h4v2M6 6l1 10h6l1-10"), "round",
|
|
"id=\"news-delete-" + id + "\" data-id=\"" + id + "\" aria-label=\"Löschen: " + esc(name) + "\" title=\"Löschen\" " + std::string(engine_mode_ && (m.value("mutable", false) == false || m.at("folder") == "trash") ? "disabled" : "")) +
|
|
"</div></div>";
|
|
}
|
|
if (out.empty()) {
|
|
const bool query = !news_view_.value("query", "").empty(), archive = news_view_.value("folder", "inbox") == "archive";
|
|
out = "<div class=\"pg-empty\"><strong class=\"pg-h\" style=\"font-size:" + pg(20) + ";\">" + std::string(query ? "Keine Nachrichten gefunden" : archive ? "Dein Archiv ist noch leer" : "Alles auf dem neuesten Stand") + "</strong><span style=\"display:block;\">" +
|
|
std::string(query ? "Versuche einen anderen Suchbegriff." : archive ? "Archivierte Meldungen bleiben hier zum Nachlesen." : "Hier erscheinen neue Meldungen für dein Team.") + "</span></div>";
|
|
}
|
|
return out;
|
|
}
|
|
std::string App::render_news_detail(const Json &message) {
|
|
const auto name = message.at("title").get<std::string>(), category = message.at("category").get<std::string>();
|
|
const bool archived = message.at("folder") == "archive" || (engine_mode_ && message.at("folder") == "trash");
|
|
return "<div id=\"news-detail-layer\" class=\"pg-ov\"><div class=\"pg-dlg\" role=\"dialog\" aria-modal=\"true\" aria-labelledby=\"news-detail-title\" style=\"width:" + pg(640) + ";\"><div><h2 id=\"news-detail-title\">" + esc(name) +
|
|
"</h2></div><div class=\"pg-row\" style=\"" + pg_css("gap:14px;") + "\"><span class=\"nw-art large\">" + render_news_art(message, 144) + "</span><div><span class=\"pg-tag" + std::string(category == "Bericht" ? " sage" : "") + "\" style=\"display:inline-block;\">" +
|
|
esc(category) + "</span><span class=\"pg-mut\" style=\"display:block;margin-top:" + pg(4) + ";\">" + esc(message.at("display_date").get<std::string>()) + "</span></div></div><p class=\"nw-body\">" +
|
|
(engine_mode_ ? news_body_markup(message.at("body").get<std::string>()) : esc(message.at("body").get<std::string>())) + "</p><span class=\"pg-mut\" style=\"display:block;font-size:" + pg(12.5) + ";\">" +
|
|
std::string(engine_mode_ ? (message.value("source", std::string()) == "mail" ? "Aus dem Spielpostfach" : "Bericht aus dem Almanach") : "Fiktive Meldung für den Oberflächen-Prototyp.") + "</span><div class=\"pg-dlg-act\">" +
|
|
pg_button("news-detail-move", archived ? "Ins Postfach" : "Archivieren", "", "id=\"news-detail-move\" " + std::string(engine_mode_ && message.value("mutable", false) == false ? "disabled" : "")) +
|
|
pg_button("news-detail-close", "Schließen", "primary", "id=\"news-detail-close\"") + "</div></div></div>";
|
|
}
|
|
// The inbox as a page of the notebook: whose it is, the folders as tabs, the search, the
|
|
// messages, and at the foot what there is and the way back from the last move.
|
|
std::string App::render_news() {
|
|
const auto s = engine_mode_?Snapshot{}:snap();
|
|
if (!engine_mode_ && (news_world_ != s.world || news_source_ != source_.get())) {
|
|
reset_news();
|
|
news_world_ = s.world;
|
|
news_source_ = source_.get();
|
|
}
|
|
const auto data = news_data(news_view_.value("folder","inbox"),news_view_.value("query",""));
|
|
if (!data.value("ok", false)) return window("Nachrichten", "<div class=\"pg-page\"><div class=\"pg-empty\">Das Nachrichtenpostfach ist nicht verfügbar.</div></div>");
|
|
const auto folder = news_view_.value("folder", "inbox");
|
|
std::string content = "<div id=\"news-underlay\" class=\"pg-page\"><div class=\"pg-row\" style=\"" + pg_css("gap:12px;") + "\">" +
|
|
(data.value("scope", Json::object()).value("kind", std::string()) == "national" ? picture(renderer_.diagram("news-header-national", ui_nation_flag_svg("de"), 176), 104, 70)
|
|
: crest(world_->find("clubs", data.value("club", std::string())), 104)) +
|
|
"<div class=\"pg-grow\"><strong class=\"pg-h\" style=\"font-size:" + pg(20) + ";\">" + esc(data.at("club_name").get<std::string>()) + "</strong><span class=\"pg-mut\" style=\"display:block;\">" + esc(data.at("date").get<std::string>()) +
|
|
"</span></div><div class=\"pg-tabs\" role=\"tablist\" aria-label=\"Postfach und Archiv\">";
|
|
for (const auto &f : (engine_mode_ ? std::vector<std::string>{"inbox", "archive", "trash"} : std::vector<std::string>{"inbox", "archive"}))
|
|
content += btn("news-folder", "<span>" + std::string(f == "inbox" ? "Postfach" : f == "archive" ? "Archiv" : "Papierkorb") + " · " + std::to_string(data.at("counts").at(f).get<int>()) + "</span>", folder == f ? "on" : "",
|
|
"id=\"news-tab-" + f + "\" data-id=\"" + f + "\" role=\"tab\" aria-controls=\"news-feed\" aria-selected=\"" + (folder == f ? "true" : "false") + "\" tabindex=\"" + (folder == f ? "0" : "-1") + "\"");
|
|
content += "</div></div><div class=\"pg-row\"><input id=\"news-search\" class=\"nw-search\" maxlength=\"120\" type=\"text\" aria-label=\"Nachrichten durchsuchen\" placeholder=\"Nachrichten durchsuchen\" value=\"" + esc(news_view_.value("query", "")) + "\"/>" +
|
|
pg_button("news-read-all", "<span>Alle gelesen</span>", "", "id=\"news-read-all\" " + std::string(data.at("can_read").get<bool>() ? "" : "disabled")) +
|
|
"</div><div class=\"pg-panel pg-col pg-grow\" style=\"" + pg_css("gap:0px;padding:4px 10px;") + "\"><div id=\"news-feed\" class=\"pg-tbody\" role=\"tabpanel\" aria-labelledby=\"news-tab-" + folder + "\">" + render_news_feed(data) +
|
|
"</div></div><nav class=\"pg-foot\"><span class=\"pg-status\" id=\"news-feedback\" role=\"status\">";
|
|
const auto feedback = news_view_.value("feedback", "");
|
|
content += esc(feedback.empty() ? std::to_string(data.at("items").size()) + (data.at("items").size() == 1 ? " Nachricht" : " Nachrichten") + " · " + std::to_string(data.at("shown_unread").get<int>()) + " ungelesen" : feedback);
|
|
if (data.value("unbound_count", size_t(0)))
|
|
content += esc(" · " + std::to_string(data.at("unbound_count").get<size_t>()) + (data.at("unbound_count").get<size_t>() == 1 ? " Altbestand ohne Besitzerbeleg unverändert erhalten" : " Altbestände ohne Besitzerbeleg unverändert erhalten"));
|
|
content += "</span>" + pg_button("news-undo", "<span>Rückgängig</span>", "", "id=\"news-undo\" style=\"display:" + std::string((engine_mode_ ? engine_news_undo_.is_object() : news_undo_.is_array() && !news_undo_.empty()) ? "flex" : "none") + ";\"") + "</nav></div>";
|
|
if (!news_dialog_.empty()) {
|
|
const auto all = news_data(folder,"");
|
|
const auto &items = all.at("items");
|
|
const auto found = std::find_if(items.begin(), items.end(), [&](const auto &m) { return m.at("id") == news_dialog_; });
|
|
if (found != items.end()) content += render_news_detail(*found);
|
|
else news_dialog_.clear();
|
|
}
|
|
return window("Nachrichten", content);
|
|
}
|
|
std::string App::render_news_widget(const Json &object) {
|
|
const auto data = news_data("inbox", "");
|
|
const auto raw_items = engine_mode_ ? engine_news_value_.at("items")
|
|
: snap().state.at("news").at("items");
|
|
if (!data.value("ok", false))
|
|
return "";
|
|
const bool compact_preview =
|
|
object.value("w", 472) <= 472 && object.value("h", 472) <= 472;
|
|
const int limit = compact_preview ? 2 : 3;
|
|
std::string out =
|
|
btn(engine_mode_ ? "engine-open" : "open:news",
|
|
"<span>Postfach · " + std::to_string(data.at(engine_mode_ ? "shown_unread" : "unread").get<int>()) +
|
|
" ungelesen</span><span class=\"news-widget-arrow\">" +
|
|
glyph("arrow-diagonal", 26) + "</span>",
|
|
"news-widget-heading",
|
|
"id=\"desktop-news-open\" data-id=\"news\" data-interactive=\"true\" "
|
|
"aria-label=\"Nachrichten öffnen\"");
|
|
out += "<div class=\"news-widget-feed\">";
|
|
int count = 0;
|
|
// Gold's widget uses source order, independently of the open tablet's folder,
|
|
// search and sorted list. Resolve templates through the same read projection.
|
|
for (const auto &raw : raw_items) {
|
|
if (raw.at("folder") != "inbox")
|
|
continue;
|
|
const auto &shown = data.at("items");
|
|
const auto found =
|
|
std::find_if(shown.begin(), shown.end(),
|
|
[&](const auto &m) { return m.at("id") == raw.at("id"); });
|
|
if (found == shown.end())
|
|
continue;
|
|
out += "<div class=\"news-widget-row" +
|
|
std::string(found->at("read") == false ? " unread" : "") +
|
|
"\"><span class=\"news-widget-dot\"></span><div "
|
|
"class=\"news-widget-copy\"><span class=\"news-widget-date\">" +
|
|
esc(found->at("display_date").get<std::string>()) +
|
|
"</span><span class=\"news-widget-title\">" +
|
|
esc(found->at("title").get<std::string>()) + "</span></div></div>";
|
|
if (++count == limit)
|
|
break;
|
|
}
|
|
return out + "</div>";
|
|
}
|