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

433 lines
22 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
// App rendering only. Lifecycle, validation and input dispatch live in the
// owner. Required App API: entry_world() -> shared_ptr<const Catalog>,
// entry_name_valid(), entry_used_club(id), entry_used_portrait(index),
// entry_full(). Required state: club_search_, manager_confirm_,
// manager_success_; existing start_options_, managers_draft_, selections_,
// country_, league_, selected_club_, manager_index_, manager_picker_,
// adding_manager_ remain the draft contract.
std::string App::render_newgame() {
start_options_["mode"] = 3;
const std::array<const char *, 3> keys = {"duration", "difficulty",
"players"},
names = {"Spieldauer", "Schwierigkeit",
"Mitspieler"};
const std::array<int, 3> limits = {
5, 10, start_options_.value("league", true) ? 4 : 1};
std::string body =
"<section class=\"entry-setup entry-career-setup\"><header "
"class=\"entry-setup-heading\"><h2>Grundeinstellungen</h2><p>Deine "
"Karriere · alle Funktionen</p></header>";
for (size_t i = 0; i < keys.size(); ++i) {
const std::string key = keys[i];
const int value = start_options_.value(key, 1);
std::string visual, caption;
if (i == 0) {
visual = "<strong class=\"entry-setup-duration\">" +
std::string(value == 5 ? "∞" : std::to_string(value)) +
"</strong>";
caption = value == 5 ? "Unbegrenzt" : value == 1 ? "Saison" : "Saisons";
} else if (i == 1) {
const int columns = std::min(5, value);
visual = "<div class=\"entry-setup-balls\" style=\"width:" +
std::to_string(columns * 68 - 6) + "dp;\">";
for (int j = 0; j < value; ++j)
visual +=
"<div style=\"position:absolute;" +
rect((j % columns) * 68, (j / columns) * 68 + (value <= 5 ? 35 : 0),
62, 62) +
"\">" +
picture(renderer_.diagram(
"setup-ball",
"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 "
"0 48 48\"><circle cx=\"24\" cy=\"24\" r=\"21\" "
"fill=\"#e0e8e6\" stroke=\"#526771\" "
"stroke-width=\"2.6\"/><path d=\"m24 14 10 7-4 "
"12H18l-4-12ZM24 3v11M4 18l10 3M11 41l7-8M37 "
"41l-7-8M44 18l-10 3\" fill=\"#445966\" "
"stroke=\"#526771\" stroke-width=\"2.6\"/></svg>",
128),
62, 62) +
"</div>";
visual += "</div>";
caption = "Spielstärke " + std::to_string(value) + " von 10";
} else {
visual = "<div class=\"entry-setup-people\">";
for (int j = 0; j < value; ++j)
visual += picture(
renderer_.diagram(
"setup-person",
"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 48 "
"64\"><circle cx=\"24\" cy=\"12\" r=\"9\" fill=\"#9fcbbf\" "
"stroke=\"#a9d8ca\" stroke-width=\"4\"/><path d=\"M8 "
"58V39c0-10 6-15 16-15s16 5 16 15v19M16 58V39M32 58V39\" "
"fill=\"none\" stroke=\"#a9d8ca\" stroke-width=\"4\" "
"stroke-linecap=\"round\"/></svg>",
192),
60, 112);
visual += "</div>";
caption = std::to_string(value) + " Mitspieler";
}
body += "<section class=\"entry-setup-option\" style=\"" +
rect(0, 104 + i * (530.6667 + 22), 760, 530.6667) +
"\"><h2 id=\"setup-label-" + key + "\">" + names[i] +
"</h2><div class=\"entry-setup-stepper\">";
body += btn("setup-step", "−", "entry-setup-minus",
"id=\"setup-" + key + "-minus\" data-id=\"" + key +
"\" data-step=\"-1\" aria-label=\"" + names[i] +
" verringern\" " + (value == 1 ? "disabled" : ""));
body += "<div id=\"setup-value-" + key +
"\" class=\"entry-setup-value\" aria-live=\"polite\">" + visual +
"<span>" + caption + "</span></div>";
body += btn("setup-step", "+", "entry-setup-plus",
"id=\"setup-" + key + "-plus\" data-id=\"" + key +
"\" data-step=\"1\" aria-label=\"" + names[i] +
" erhöhen\" " + (value == limits[i] ? "disabled" : "")) +
"</div></section>";
}
body +=
"<section class=\"entry-setup-competitions\" aria-label=\"Wettbewerbe\">";
for (const auto *key : {"league", "world"}) {
const bool league = std::string(key) == "league",
active = start_options_.value(key, true),
locked =
league ? active && (start_options_.value("players", 1) > 1 ||
!start_options_.value("world", true))
: !start_options_.value("league", true);
body += btn(
"setup-competition",
img(league ? "career.club" : "career.international", 904, 1580, false,
false, 1600) +
"<span class=\"entry-career-caption\"><strong>" +
std::string(league ? "Vereinsfußball" : "International · WM / EM") +
"</strong><small>" + (active ? "Aktiv" : "Auswählen") +
"</small></span><span class=\"entry-career-check\">" +
(active ? glyph("check", 38) : "<span>○</span>") + "</span>",
std::string("entry-setup-competition ") + (active ? "selected" : ""),
"id=\"setup-competition-" + std::string(key) + "\" data-id=\"" + key +
"\" aria-pressed=\"" + (active ? "true" : "false") + "\" " +
(locked ? "disabled" : ""));
}
body += "<p role=\"status\">" +
std::string(
start_options_.value("players", 1) > 1
? "Bei mehreren Mitspielern bleibt der Vereinsfußball aktiv."
: !start_options_.value("league", true)
? "Nationalmannschaft · ein Mitspieler · Deutschland"
: "Mindestens ein Wettbewerb bleibt aktiv.") +
"</p></section><footer class=\"entry-setup-actions\"><p>Dauer, "
"Schwierigkeit und Mitspielerzahl gelten für deine neue "
"Partie.</p><div>" +
btn("close", "Abbrechen") +
btn("setup-next", "Weiter", "primary", "id=\"setup-next\"") +
"</div></footer></section>";
return window("Neues Spiel", body);
}
std::string App::render_manager() {
const auto catalog = entry_world();
if (!catalog)
return window("Neuer Spieler",
"<p>Bitte zuerst eine Modern-Mod aktivieren.</p>");
const bool national = career_national_entry();
const bool full = entry_full(), modal = manager_confirm_ || manager_success_;
const int limit =
adding_manager_ ? (national ? 1 : 4) : start_options_.value("players", 1);
const int portrait =
selections_["portrait"].empty() ? 0 : std::stoi(selections_["portrait"]);
const std::string style =
selections_["portrait-style"] == "painted" ? "painted" : "photo";
const std::array<const char *, 3> strengths = {
"Unteres Drittel", "Mittelfeld", "Oberes Drittel"};
const int strength =
std::clamp(selections_["manager-strength"].empty()
? 1
: std::stoi(selections_["manager-strength"]),
0, 2);
const auto face = [&](int index, const std::string &variant, int width,
const std::string &extra = "") {
return "<div class=\"entry-manager-face " + extra +
"\" role=\"img\" aria-label=\"Fiktives Managerporträt " +
std::to_string(index + 1) +
(variant == "painted" ? ", Illustration" : ", Foto") + "\">" +
img(std::string(variant == "painted" ? "manager-painted."
: "manager.") +
std::to_string(index),
width, width * 4.0 / 3.0, false, true, 350) +
"</div>";
};
const auto club_name = [&](const Json *c) {
return national ? std::string("Deutschland")
: c ? catalog->name(*c)
: std::string("Kein spielbarer Verein");
};
const auto league_name = [&](const Json *c) {
if (national)
return std::string("Nationalmannschaft");
const auto *l =
c ? catalog->find("competitions", c->value("competition", ""))
: nullptr;
return l ? catalog->name(*l) : std::string();
};
std::vector<std::pair<std::string, std::string>> countries, choices;
std::set<std::string> seen;
for (const auto *l : catalog->leagues()) {
const auto id = l->value("nation", "");
if (seen.insert(id).second)
countries.emplace_back(id, catalog->nation_name(id));
}
const auto leagues = catalog->leagues(country_);
for (const auto *l : leagues)
choices.emplace_back(l->value("id", ""), catalog->name(*l));
const auto choose =
[&](const std::string &id,
const std::vector<std::pair<std::string, std::string>> &rows,
const std::string &value) {
auto out = select(id, rows, value, id);
out.insert(out.find('>'), " data-select-style=\"league\"");
if (full)
out.insert(out.find('>'), " disabled");
return out;
};
const auto *selected = catalog->find("clubs", selected_club_);
std::string content;
if (manager_picker_ && !national) {
const auto query = settings_search_key(club_search_);
std::vector<const Json *> clubs;
for (const auto *c : catalog->clubs(league_))
if (query.empty() || settings_search_key(catalog->name(*c)).find(query) !=
std::string::npos)
clubs.push_back(c);
content =
"<section class=\"entry-club-picker\"><header><div><h2>Verein "
"auswählen</h2><p>Wähle ein Wappen für deinen neuen "
"Manager.</p></div>" +
btn("manager-clubs-back", "Zurück", {}, "id=\"manager-clubs-back\"") +
"</header><div class=\"entry-club-filters\"><div>" +
choose("manager-country", countries, country_) +
choose("manager-league", choices, league_) +
"</div><label><input type=\"search\" id=\"manager-club-search\" "
"data-input=\"manager-search\" maxlength=\"60\" placeholder=\"Verein "
"suchen\" aria-label=\"Verein in dieser Liga suchen\" value=\"" +
esc(club_search_) +
"\"/></label></div><section class=\"entry-club-results\"><p "
"class=\"entry-club-count\" role=\"status\">" +
std::to_string(clubs.size()) +
(clubs.size() == 1 ? " Verein" : " Vereine") +
"</p><div class=\"entry-club-grid\" id=\"manager-club-grid\">";
const int rows = std::max(1, int((clubs.size() + 4) / 5));
const double height = std::max(250.0, (1583.0 - (rows - 1) * 20) / rows);
content += "<div class=\"entry-club-grid-content\" style=\"height:" +
scalar(rows * (height + 20) - 20 + 8) + "dp;\">";
for (size_t i = 0; i < clubs.size(); ++i) {
const auto *c = clubs[i];
const auto id = c->value("id", "");
const bool locked = !catalog->manageable(id), used = entry_used_club(id),
chosen = id == selected_club_;
const std::string note = locked ? "Nicht spielbar · nur deutsche Vereine"
: used ? "Bereits vergeben"
: chosen ? "Ausgewählt"
: league_name(c);
content +=
btn("manager-club",
"<div class=\"entry-club-crest\">" + crest(c, 120) +
"</div><strong>" + esc(club_name(c)) +
"</strong><small class=\"entry-choice-status\">" +
(chosen && !used && !locked ? glyph("check", 20) : "") +
"<span>" + esc(note) + "</span></small>" +
(locked ? "<span class=\"entry-club-lock\">" +
glyph("lock", 32) + "</span>"
: ""),
"entry-club-choice " + std::string(chosen ? "selected" : ""),
"id=\"manager-team-" + std::to_string(i) + "\" data-id=\"" +
esc(id) + "\" aria-pressed=\"" + (chosen ? "true" : "false") +
"\" style=\"position:absolute;" +
rect(4 + (i % 5) * 521.2, 4 + (i / 5) * (height + 20), 501.2,
height) +
"\" " + (locked || used || full ? "disabled" : ""));
}
if (clubs.empty())
content += "<p class=\"entry-no-clubs\">Kein Verein mit diesem Namen in "
"dieser Liga.</p>";
content += "</div></div></section></section>";
} else {
content =
"<section class=\"entry-manager-layout " +
std::string(adding_manager_ ? "is-add" : "") +
"\"><header class=\"entry-manager-step\"><span>" +
(full ? std::string(national ? "Nationaltrainer im Spiel"
: "Vier Mitspieler im Spiel")
: "Mitspieler " + std::to_string(manager_index_ + 1) + " von " +
std::to_string(limit)) +
"</span><p>Dein Name. Dein Verein. Dein Porträt.</p>" +
(adding_manager_ ? btn("manager-newgame", "Neues Spiel", {},
"id=\"manager-newgame\"")
: "") +
"</header><div class=\"entry-manager-fields " +
std::string(full ? "is-full " : "") + (national ? "is-national" : "") +
"\"><div class=\"entry-manager-identity\"><section "
"class=\"entry-manager-person-card\"><div "
"class=\"entry-manager-person-copy\"><label "
"for=\"manager-name\">Managername</label><input id=\"manager-name\" "
"data-input=\"manager-name\" maxlength=\"24\" value=\"" +
esc(selections_["manager-name"]) +
"\" aria-describedby=\"manager-name-note\" " +
(full ? "disabled" : "") +
"/><p id=\"manager-name-note\">So wirst du im Spiel "
"angesprochen.</p><span class=\"entry-manager-profile-tag\">Porträt " +
std::to_string(portrait + 1) + "</span></div>" +
face(portrait, style, 174) +
"</section><section class=\"entry-manager-club-card\"><h2>" +
std::string(national ? "Nationalmannschaft" : "Verein") + "</h2>" +
btn("manager-clubs",
"<div class=\"entry-manager-club-crest\">" +
(national
? img("career.national-de", 176, 176, false, false, 512)
: crest(selected, 176)) +
"</div><span><strong>" + esc(club_name(selected)) +
"</strong><small>" +
esc(selected
? catalog->nation_name(selected->value("nation", ""))
: "") +
" · " + esc(league_name(selected)) +
"</small><em>Verein wählen <span>›</span></em></span>",
"entry-manager-club-button",
"id=\"manager-clubs\" aria-label=\"Verein wählen: " +
esc(club_name(selected)) + "\" " +
(full || national ? "disabled" : "")) +
"</section></div><div "
"class=\"entry-manager-options\"><section><h2>Startliga</h2><div>" +
choose("manager-country", countries, country_) +
choose("manager-league", choices, league_) +
"</div></section><section><h2>Vereinsstärke</h2>" +
choose("manager-strength",
{{"0", strengths[0]}, {"1", strengths[1]}, {"2", strengths[2]}},
std::to_string(strength)) +
"</section></div><div class=\"entry-manager-choices\"><section "
"class=\"entry-manager-portrait-section\"><header><h2>Managerporträt</"
"h2><div class=\"entry-manager-portrait-styles\" role=\"group\" "
"aria-label=\"Porträtvariante\">";
for (const auto *variant : {"photo", "painted"})
content +=
btn("portrait-style",
std::string(variant) == "photo" ? "Foto" : "Illustration", {},
"id=\"manager-style-" + std::string(variant) + "\" data-id=\"" +
variant + "\" aria-pressed=\"" +
(style == variant ? "true" : "false") + "\" " +
(full ? "disabled" : ""));
content += "</div></header><div class=\"entry-manager-portraits\" "
"role=\"radiogroup\" aria-label=\"Managerporträt\">";
const int portrait_height = adding_manager_ ? 482 : 494;
for (int i = 0; i < 12; ++i) {
const bool used = entry_used_portrait(i), chosen = i == portrait;
content +=
btn("portrait",
face(i, style, 174) +
"<span class=\"entry-manager-portrait-caption\">" +
(chosen && !used ? glyph("check", 20) : "") + "<span>" +
(used ? "Vergeben"
: chosen ? "Ausgewählt"
: "Porträt " + std::to_string(i + 1)) +
"</span></span>",
"entry-manager-portrait " + std::string(chosen ? "selected" : ""),
"id=\"manager-portrait-" + std::to_string(i) + "\" data-id=\"" +
std::to_string(i) + "\" role=\"radio\" aria-checked=\"" +
(chosen ? "true" : "false") + "\" aria-label=\"Porträt " +
std::to_string(i + 1) + (used ? ", bereits vergeben" : "") +
"\" tabindex=\"" + (chosen ? "0" : "-1") +
"\" style=\"position:absolute;" +
rect((i % 6) * 324, (i / 6) * (portrait_height + 16), 308,
portrait_height) +
"\" " + (used || full ? "disabled" : ""));
}
content +=
"</div></section><aside class=\"entry-manager-roster\"><header><h2>" +
std::string(adding_manager_ ? "Bereits im Spiel"
: "Mitspieler dieser Partie") +
"</h2><span>" + std::to_string(managers_draft_.size()) + " / " +
std::to_string(limit) +
"</span></header><div class=\"entry-manager-roster-list\">";
for (size_t i = 0; i < managers_draft_.size(); ++i) {
const auto &m = managers_draft_[i];
const auto *c = catalog->find("clubs", m.value("club", ""));
content +=
"<div class=\"entry-manager-roster-row\">" +
face(m.value("portrait", 0), m.value("portrait_style", style), 90) +
"<div><small>Spieler " + std::to_string(i + 1) + "</small><strong>" +
esc(m.value("name", "")) + "</strong><span>" + esc(club_name(c)) +
"</span></div></div>";
}
const int remaining = std::max(0, limit - int(managers_draft_.size()));
content +=
"</div><p>" +
(full ? std::string("Alle vier Plätze sind belegt.")
: std::to_string(remaining) + (remaining == 1
? " weiterer Platz frei"
: " weitere Plätze frei")) +
"</p></aside></div></div></section><footer "
"class=\"entry-manager-actions\"><p id=\"manager-feedback\" "
"role=\"status\">" +
(full ? std::string("Es können höchstens vier Manager mitspielen.")
: adding_manager_
? "Mitspieler wird erst nach deiner Bestätigung hinzugefügt."
: "Bestätige nacheinander die Mitspieler für deine neue Partie.") +
"</p><div>" +
btn("manager-back",
full ? "Schließen"
: adding_manager_ ? "Abbrechen"
: "Zurück",
{}, "id=\"manager-back\"") +
btn("manager-next",
adding_manager_ ? "Mitspieler hinzufügen"
: manager_index_ + 1 == limit ? "Spiel starten"
: "Mitspieler bestätigen",
"primary",
"id=\"manager-next\" " +
std::string(full || !entry_name_valid() || !selected ||
!catalog->manageable(selected_club_) ||
entry_used_club(selected_club_) ||
entry_used_portrait(portrait)
? "disabled"
: "")) +
"</div></footer>";
}
std::string body =
"<div id=\"entry-manager-underlay\" class=\"entry-manager-underlay\" " +
std::string(modal ? "aria-hidden=\"true\"" : "") + ">" + content +
"</div>";
if (manager_confirm_) {
body +=
"<div id=\"entry-confirm-layer\" class=\"entry-dialog-layer\"><section "
"class=\"entry-dialog entry-confirm-dialog\" role=\"dialog\" "
"aria-modal=\"true\" aria-labelledby=\"entry-confirm-title\"><h2 "
"id=\"entry-confirm-title\">Sind alle Angaben richtig?</h2><div "
"class=\"entry-confirm-identity\"><div class=\"entry-confirm-crest\">" +
(national ? img("career.national-de", 200, 200, false, false, 512)
: crest(selected, 200)) +
"</div><div class=\"entry-confirm-copy\"><strong>" +
esc(selections_["manager-name"]) + "</strong><span>" +
esc(club_name(selected)) + "</span><small>" +
esc(league_name(selected)) + " · " + strengths[size_t(strength)] +
"</small></div>" + face(portrait, style, 150) + "</div><footer>" +
btn("manager-confirm-no", "Nein", {}, "id=\"manager-confirm-no\"") +
btn("manager-confirm-yes", "Ja", "primary",
"id=\"manager-confirm-yes\"") +
"</footer></section></div>";
} else if (manager_success_) {
const auto &last =
managers_draft_.empty() ? Json::object() : managers_draft_.back();
const auto *c = catalog->find("clubs", last.value("club", selected_club_));
body +=
"<div id=\"entry-success-layer\" class=\"entry-dialog-layer\"><section "
"class=\"entry-dialog entry-success-dialog\" role=\"dialog\" "
"aria-modal=\"true\" aria-labelledby=\"entry-success-title\"><h2 "
"id=\"entry-success-title\">Mitspieler hinzugefügt</h2><p>" +
esc(last.value("name", selections_["manager-name"])) + " übernimmt " +
esc(club_name(c)) + ".</p><footer>" +
btn("manager-success-close", "Verstanden", {},
"id=\"manager-success-close\"") +
"</footer></section></div>";
}
return window("Neuer Spieler", body);
}