// SPDX-License-Identifier: GPL-3.0-only std::string App::widget_heading(const std::string &name, bool link) { return "
" + esc(name) + "" + (link ? glyph("arrow-diagonal", 28) : "") + "
"; } std::string App::widget_curve(const std::string &id, const Json &o, int w, int h) { const bool compare = id == "comparison-curve", square = (w == 720 || h == 968); const int height = square ? 600 : 330, range = height - 76; const auto accent = theme_ == "silver" ? "#235e78" : theme_ == "matchday" ? "#f1a99e" : "#a5e2cf"; const auto other = theme_ == "silver" ? "#a04b30" : theme_ == "matchday" ? "#91cce8" : "#f2b286"; const auto muted = theme_ == "silver" ? "#586d80" : theme_ == "matchday" ? "#b4b5b7" : "#afbfcd"; std::string svg = ""; const auto series = [&](const Json &values, const char *color, bool dash) { std::string path, dots; for (size_t i = 0; i < values.size(); ++i) { const auto x = 32 + i * 936. / (values.size() - 1), y = 38 + (values[i].get() - 1) / 17. * range; path += (i ? "L" : "M") + scalar(x) + " " + scalar(y); dots += ""; } return "" + dots; }; svg += series( widget_data_.at(id == "opponent-curve" ? "opponent_curve" : "own_curve"), accent, false); if (compare) svg += series(widget_data_.at("opponent_curve"), other, true); svg += ""; const int ch = h - (compare ? 180 : 96); std::string out = "
" + picture(renderer_.diagram("widget-" + id + "-" + std::to_string(w) + "-" + std::to_string(h), svg, 1600), w - 42, ch) + "SaisonstartHeute
"; if (compare) out += "
" + esc(world_->name(*world_->find("clubs", widget_data_.at("own")))) + "" + esc(world_->name(*world_->find("clubs", widget_data_.at("opponent")))) + "
"; (void)o; return out; } std::string App::widget_warnings(const Json &rows, const Json &o) { const int w = o.at("w"), h = o.at("h"); const bool wide = h == 224; const std::vector> groups = wide ? std::vector>{{0}, {1}, {2}, {3, 4}, {5, 6}, {7}, {8}, {9}} : std::vector>{{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}}; std::string out = widget_heading("Vereinsstatus", false) + "
"; const int cols = wide ? 8 : 5, cw = (w - (wide ? 56 : 52) - (wide ? 7 * 18 : 4 * 14)) / cols, rh = wide ? h - 76 : (h - 120) / 2; for (size_t i = 0; i < groups.size(); ++i) { std::string label, key; bool attention = false, known = true; for (int n : groups[i]) { const auto &v = rows[size_t(n)]; if (!label.empty()) { label += " & "; key += ","; } label += v.at("name").get(); key += std::to_string(n); attention = attention || v.at("attention") == true; known = known && v.at("attention").is_boolean(); } const auto &v = rows[size_t(groups[i][0])]; out += btn(engine_mode_ ? "engine-widget-warning" : "widget-warning", "" + glyph(v.at("icon"), h == 720 ? 42 : 28) + "" + (wide ? "" : "" + esc(label) + ""), "desk-warning", "data-id=\"" + key + "\" data-interactive=\"true\" title=\"" + esc(label) + "\" aria-label=\"" + esc(label) + ": " + (attention ? "Handlungsbedarf" : known ? "In Ordnung" : "Nicht bekannt") + "\" style=\"left:" + std::to_string((wide ? 28 : 26) + (int(i) % cols) * (cw + (wide ? 18 : 14))) + "dp;top:" + std::to_string(int(i) / cols * (rh + 20)) + "dp;width:" + std::to_string(cw) + "dp;height:" + std::to_string(rh) + "dp;\""); } return out + "
"; } std::string App::widget(const std::string &id, const Json &o) { const auto s = snap(); if (!widget_data_.is_object()) widget_data_ = demo_desktop_widgets(*world_, s.state); const auto *own = world_->find("clubs", widget_data_.at("own")), *opponent = world_->find("clubs", widget_data_.at("opponent")); const int w = o.at("w"), h = o.at("h"); const bool wide = h == 224, compact = w == 472; const auto heading = [&](const std::string &name, bool link = true) { return widget_heading(name, link); }; if(s.state.at("career").value("role","club")=="national"){ if(id=="crest"||id=="opponent-crest")return "
"+img(id=="crest"?"career.national-de":"career.national-fr",std::min(w-48,h-138),std::min(w-48,h-138),false,false,768)+"
"+(id=="crest"?std::string("Dein Nationalteam"):"Nächster Gegner")+""+(id=="crest"?std::string("Deutschland"):"Frankreich")+"
"; if(id=="competition")return heading("Nächste Begegnung")+"
"+img("career.national-de",80,80,false,false,256)+"Deutschland
Fiktives Länderspiel19:00Heim · Samstag
"+img("career.national-fr",80,80,false,false,256)+"Frankreich
"; } if (id == "calendar") return "
" + esc(widget_data_.at("month").get()) + "
" + esc(widget_data_.at("weekday").get()) + "" + std::to_string(widget_data_.at("day").get()) + "" + (widget_data_.at("matchday") == 0 ? "Saisonvorbereitung" : std::to_string(widget_data_.at("matchday").get()) + ". Spieltag") + "
" + glyph("calendar", 30) + "Kalender öffnen" + glyph("arrow-diagonal", 26) + "
"; if (id == "account") return heading("Vereinskasse") + "
Sparbuch" + cash(s.state.at("deposit")) + "
" + btn("ticket", glyph("ticket", 36) + "Eintritt" + std::to_string(s.state.at("ticket").get()) + " " + money_unit() + "   ›", "desk-ticket", "id=\"account-ticket\" data-interactive=\"true\"") + "
"; if (id == "competition") return heading("Nächste Begegnung") + "
" + crest(own, compact ? 68 : 80) + "" + esc(own ? own->value("short_name", world_->name(*own)) : "") + "
Freundschaftsspiel19:00Heim · " "Samstag
" + crest(opponent, compact ? 68 : 80) + "" + esc(opponent ? opponent->value("short_name", world_->name(*opponent)) : "") + "
"; if (id == "portrait") return img(std::string(manager(s).value("portrait_style", std::string("photo")) == "painted" ? "manager-painted." : "manager.") + std::to_string(manager(s).value("portrait", 0)), w, h, false, false, 768) + "
Manager" + esc(manager(s).value("name", "")) + "
"; if (id == "crest" || id == "opponent-crest") { const auto *c = id == "crest" ? own : opponent; return "
" + crest(c, std::min(int((w - 48) * .78), int((h - 138) * .9))) + "
" + (id == "crest" ? std::string("Dein Verein") : "Nächster Gegner") + "" + esc(c ? world_->name(*c) : "") + "
"; } if (id == "warnings") return widget_warnings(widget_data_.at("warnings"), o); if (id == "fans") return heading("Fan-Stimmung") + "
" + glyph("heart", 36) + "
" + std::to_string(widget_data_.at("fans").get()) + " %()) + "%;\">
Zuversichtlich
"; if (id == "news") return render_news_widget(o); if (id == "own-curve" || id == "opponent-curve" || id == "comparison-curve") return heading(id == "comparison-curve" ? "Tabellenplätze" : world_->name(*(id == "own-curve" ? own : opponent))) + widget_curve(id, o, w, h); if (id == "own-summary" || id == "opponent-summary") { bool self = id == "own-summary"; return heading(world_->name(*(self ? own : opponent))) + "
Tabellenplatz" + std::to_string(widget_data_.at(self ? "own_rank" : "opponent_rank") .get()) + ".
Teamstärke" + std::to_string( widget_data_.at(self ? "own_strength" : "opponent_strength") .get()) + "
"; } if (id == "results") { std::string out = heading("Die letzten sechs Spiele") + "
"; for (size_t i = 0; i < 6; ++i) out += "
() + "\" style=\"width:" + scalar(wide ? 50 : w * .08) + "dp;height:" + scalar(wide ? 50 : w * .08) + "dp;font-size:" + scalar(wide ? 26 : w * .04) + "dp;\">" + widget_data_.at("form")[i].get() + "" + widget_data_.at("scores")[i].get() + "
"; return out + "
" + (wide ? "" : "

3 Siege · 2 Unentschieden · 1 " "Niederlage

"); } if (id == "duels") return heading("Direkter Vergleich") + "
" + crest(own, 75) + "2Siege
1Unentschieden
" + crest(opponent, 75) + "3Siege
"; if (id == "trash") return "
" + glyph("trash", 100) + "
Papierkorb"; return {}; } std::string App::desktop_dialog(const std::string &heading, const std::string &body, const std::string &footer, int width, int height) { return "
" + btn("close", "×", "desktop-window-close", "id=\"window-close\" aria-label=\"Schließen\"") + "

" + esc(heading) + "

" + body + "
" + footer + "
"; } std::string App::render_widget_gallery_items() { std::string out; int index = 0; const auto query = settings_search_key(widget_query_); for (const auto &d : widget_catalogue()) { const auto id = d.at("id").get(); if (!query.empty() && settings_search_key(d.at("label").get() + " " + d.at("description").get() + " " + d.at("group").get()) .find(query) == std::string::npos) continue; auto preview = desktop_.at("objects").at(id); const auto span = d.at("spans").at(d.at("size").get()); const int w = span[0].get() * 248 - 24, h = span[1].get() * 248 - 24; preview["w"] = w; preview["h"] = h; const auto factor = std::min(620. / w, 300. / h); std::string dimensions; for (const auto &def : widget_definitions()) if (def.id == id) { auto chosen = widget_choices_.contains(id) ? widget_choices_[id] : std::pair{span[0], span[1]}; for (const auto &[cols, rows] : def.sizes) { const auto key = std::to_string(cols) + "x" + std::to_string(rows); dimensions += ""; } } auto preview_markup = widget(id, preview); for (size_t at = 0; (at = preview_markup.find("
() + "\" style=\"width:" + std::to_string(w) + "dp;height:" + std::to_string(h) + "dp;left:" + scalar((732 - w) / 2.) + "dp;top:" + scalar((320 - h) / 2.) + "dp;transform:scale(" + scalar(factor) + ");\">" + preview_markup + "
" + esc(d.at("group").get()) + "

" + esc(d.at("label").get()) + "

" + esc(d.at("description").get()) + "

" + btn("widget-add", (present ? glyph("check", 28) : "") + "" + (present ? "Auf dem Desktop" : "Hinzufügen") + "", "widget-add-button", "data-id=\"" + id + "\" " + (present ? "disabled" : "")) + "
"; ++index; } return index ? "" : ""; } std::string App::render_widget_dialog(const std::string &key) { init_desktop(); widget_data_ = demo_desktop_widgets(*world_, snap().state); if (key == "widgets") { widget_restore_scroll_ = true; return desktop_dialog( "Widget hinzufügen", "
" + render_widget_gallery_items() + "
", "

" + esc(widget_notice_) + "

" + btn("close", "Fertig")); } if (key == "background") return desktop_dialog( "Hintergrundbild ändern", "

Ein Ort. Dein Spieltag.

" + btn("widget-background", img("background", 1972, 820, false, true, 2000) + "Stadion bei NachtAuf die " "aktuelle Desktopgestaltung abgestimmt" + glyph("check", 48) + "", "background-choice", "aria-pressed=\"true\"") + "

Weitere Hintergründe folgen.

", "

" + esc(widget_notice_) + "

" + btn("close", "Fertig"), 2080, 1680); if (key == "warning") { std::string label, description; bool attention = false; std::istringstream in(widget_warning_); std::string bit; while (std::getline(in, bit, ',')) { const int i = std::stoi(bit); if (i < 0 || i >= 10) continue; const auto &v = widget_data_.at("warnings")[size_t(i)]; if (!label.empty()) label += " & "; label += v.at("name").get(); if (v.at("attention") == true) { attention = true; description += v.at("description").get() + " "; } } return desktop_dialog("Vereinsstatus", "
" + glyph(attention ? "alert" : "check", 80) + "

" + esc(label) + "

" + esc(attention ? description : "Hier ist derzeit alles in Ordnung.") + "

", "

" + btn("close", "Fertig"), 1800, 1000); } if (key == "quit") { const bool dirty = source_->dirty(); return desktop_dialog( "Spiel beenden", "
" + glyph("power", 80) + "

" + std::string(dirty ? "Noch nicht gespeichert" : "Spiel beenden?") + "

" + (dirty ? "Deine Änderungen wurden noch nicht gespeichert. Möchtest " "du vor dem Beenden speichern?" : "Möchtest du das Spiel beenden und zum Hauptmenü " "zurückkehren?") + "

", "

" + btn("desktop-quit-cancel", "Abbrechen") + (dirty ? btn("desktop-quit-discard", "Nicht speichern") + btn("desktop-quit-save", "Speichern", "primary") : btn("desktop-quit-confirm", "Beenden", "primary")), 1800, 1000); } return {}; }