>{{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änderspiel 19:00 Heim · 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") +
"
";
if (id == "account")
return heading("Vereinskasse") +
"Guthaben ()) + "\">" +
cash(s.state.at("cash")) +
"
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)) : "") +
"
Freundschaftsspiel"
"small>19:00 Heim · "
"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") + "" +
(wide ? ""
: "3 Siege · 2 Unentschieden · 1 "
"Niederlage
");
}
if (id == "duels")
return heading("Direkter Vergleich") + "" +
crest(own, 75) +
"2 Siege
1"
"strong>Unentschieden
" +
crest(opponent, 75) +
"3 Siege
";
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 +
"
";
}
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 += "" + std::to_string(cols) + " × " +
std::to_string(rows) + " ";
}
}
auto preview_markup = widget(id, preview);
for (size_t at = 0;
(at = preview_markup.find("" +
esc(d.at("group").get()) + " " +
esc(d.at("label").get()) + " " +
esc(d.at("description").get()) +
"
" + dimensions + " " +
btn("widget-add",
(present ? glyph("check", 28) : "") + "" +
(present ? "Auf dem Desktop" : "Hinzufügen") + " ",
"widget-add-button",
"data-id=\"" + id + "\" " + (present ? "disabled" : "")) +
"
";
++index;
}
return index
? "" + out + "
"
: "Keine Widgets gefunden.
";
}
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 Nacht Auf 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 {};
}