Complete Modern game setup and manager selection with staged confirmation (by Codex)

This commit is contained in:
Codex committed 2026-10-26 09:50:22 +01:00
1 parent a0bb8b47dc
commit 967520190d
18 files changed
+1784 -531

No files matched your search

+399
View File
@@ -0,0 +1,399 @@
// 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() {
const std::array<const char *, 4> keys = {"duration", "difficulty", "players",
"mode"};
const std::array<const char *, 4> names = {"Spieldauer", "Schwierigkeit",
"Mitspieler", "Modus"};
const std::array<int, 4> limits = {
5, 10, start_options_.value("league", true) ? 4 : 1, 3};
std::string body =
"<section class=\"entry-setup\"><header class=\"entry-setup-heading\">"
"<h2>Grundeinstellungen</h2><p>Zuerst die Partie, dann die Manager.</p>"
"</header><div class=\"entry-setup-options\">";
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(value, 5), rows = value > 5 ? 2 : 1;
visual = "<div class=\"entry-setup-balls\" style=\"width:" +
std::to_string(columns * 102 - 10) + "dp;\">";
for (int n = 0; n < value; ++n)
visual += "<div style=\"position:absolute;" +
rect((n % columns) * 102,
(n / columns) * 102 + (rows == 1 ? 51 : 0), 92, 92) +
"\">" + glyph("ball", 92) + "</div>";
visual += "</div>";
caption = "Spielstärke " + std::to_string(value) + " von 10";
} else if (i == 2) {
visual = "<div class=\"entry-setup-people\">";
for (int n = 0; n < value; ++n)
visual += glyph("person", 84);
visual += "</div>";
caption = std::to_string(value) + " Mitspieler";
} else {
visual = "<strong class=\"entry-setup-mode\">" +
std::string(value == 1 ? "I"
: value == 2 ? "II"
: "III") +
"</strong>";
caption = value == 1 ? "Grundfunktionen"
: value == 2 ? "Erweiterte Funktionen"
: "Alle Funktionen";
}
body += "<section class=\"entry-setup-option\" style=\"" +
rect((i % 2) * 1320, (i / 2) * 719, 1292, 691) +
"\" aria-labelledby=\"setup-label-" + key +
"\"><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 += "</div><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",
glyph(league ? "pitch" : "world", 70) + "<span><strong>" +
std::string(league ? "Ligaspiel" : "WM / EM") + "</strong><small>" +
(active ? "Aktiv" : "Aus") + "</small></span>",
"entry-setup-competition " + std::string(active ? "selected" : ""),
"id=\"setup-competition-" + std::string(key) + "\" data-id=\"" + key +
"\" aria-pressed=\"" + (active ? "true" : "false") + "\" " +
(locked ? "disabled" : ""));
}
const std::string hint =
start_options_.value("players", 1) > 1
? "Bei mehreren Mitspielern bleibt das Ligaspiel aktiv."
: !start_options_.value("league", true)
? "WM / EM allein ist mit einem Mitspieler möglich."
: "Mindestens ein Wettbewerb bleibt aktiv.";
body += "<p role=\"status\">" + hint +
"</p></section><footer class=\"entry-setup-actions\"><p>Deine "
"Auswahl wird beim Spielstart übernommen.</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 full = entry_full(), modal = manager_confirm_ || manager_success_;
const int limit = adding_manager_ ? 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 c ? catalog->name(*c) : std::string("Kein spielbarer Verein");
};
const auto league_name = [&](const Json *c) {
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);
if (full)
out.insert(out.find('>'), " disabled");
return out;
};
const auto *selected = catalog->find("clubs", selected_club_);
std::string content;
if (manager_picker_) {
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("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" : "") +
"\"><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>Verein</h2>" +
btn("manager-clubs",
"<div class=\"entry-manager-club-crest\">" + 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 ? "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\">" +
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);
}