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

-288
View File
@@ -72,294 +72,6 @@ std::string App::render_desktop() {
}
return out + "</div>";
}
std::string App::render_newgame() {
std::string body = "<h2>Grundeinstellungen</h2><p class=\"small\" "
"style=\"position:absolute;right:0;top:10dp;\">Zuerst die "
"Partie, dann die Manager.</p>";
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};
for (int i = 0; i < 4; ++i) {
const auto key = std::string(keys[size_t(i)]);
const int value = start_options_.value(key, 1), x = (i % 2) * 1320,
y = 120 + (i / 2) * 716;
std::string symbols, caption;
if (i == 0) {
symbols = "<strong style=\"font-size:210dp;color:var(--accent);\">" +
std::string(value == 5 ? "∞" : std::to_string(value)) +
"</strong>";
caption = value == 5 ? "Unbegrenzt" : value == 1 ? "Saison" : "Saisons";
} else if (i == 1) {
symbols = "<div style=\"position:relative;width:500dp;height:200dp;\">";
const int cols = std::min(value, 5);
for (int n = 0; n < value; ++n)
symbols += "<div style=\"position:absolute;" +
rect((n % cols) * 100,
(n / cols) * 100 + (value <= 5 ? 50 : 0), 92, 92) +
"\">" + glyph("ball", 92) + "</div>";
symbols += "</div>";
caption = "Spielstärke " + std::to_string(value) + " von 10";
} else if (i == 2) {
symbols =
"<div class=\"row\" style=\"height:200dp;justify-content:center;\">";
for (int n = 0; n < value; ++n)
symbols += glyph("person", 110);
symbols += "</div>";
caption = std::to_string(value) + " Mitspieler";
} else {
symbols = "<strong style=\"font-size:174dp;color:#dfcb91;\">" +
std::string(value == 1 ? "I"
: value == 2 ? "II"
: "III") +
"</strong>";
caption = value == 1 ? "Grundfunktionen"
: value == 2 ? "Erweiterte Funktionen"
: "Alle Funktionen";
}
body += "<div class=\"panel\" style=\"position:absolute;" +
rect(x, y, 1288, 688) +
"padding:40dp 30dp;\"><h2 class=\"center\">" + names[size_t(i)] +
"</h2><div class=\"row\" "
"style=\"position:absolute;left:30dp;right:30dp;top:190dp;justify-"
"content:space-between;\">";
body +=
btn("setup-step", "−", {},
"data-id=\"" + key +
"\" data-step=\"-1\" "
"style=\"width:94dp;height:124dp;padding:0;font-size:72dp;\" " +
(value == 1 ? "disabled" : ""));
body += "<div class=\"column center\" "
"style=\"width:800dp;align-items:center;gap:20dp;\">" +
symbols + "<p>" + caption + "</p></div>";
body +=
btn("setup-step", "+", {},
"data-id=\"" + key +
"\" data-step=\"1\" "
"style=\"width:94dp;height:124dp;padding:0;font-size:72dp;\" " +
(value == limits[size_t(i)] ? "disabled" : "")) +
"</div></div>";
}
body += "<div class=\"row\" "
"style=\"position:absolute;left:0;right:0;bottom:205dp;\">";
for (const auto *key : {"league", "world"}) {
const bool league = std::string(key) == "league",
active = start_options_.value(key, true),
locked = active &&
(league ? (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>" +
(league ? "Ligaspiel" : "WM / EM") + " &nbsp; " +
(active ? "Aktiv" : "Aus") + "</span>",
active ? "primary row" : "row",
"data-id=\"" + std::string(key) +
"\" style=\"flex:1;height:126dp;justify-content:center;\" " +
(locked ? "disabled" : ""));
}
body += "</div><p class=\"small center\" "
"style=\"position:absolute;left:0;right:0;bottom:155dp;\">Mindestens "
"ein Wettbewerb bleibt aktiv.</p><div class=\"bottom-controls\">" +
btn("close", "Abbrechen") + btn("setup-next", "Weiter", "primary") +
"</div>";
return window("Neues Spiel", body);
}
std::string App::render_manager() {
const int limit = adding_manager_ ? 4 : start_options_.value("players", 1);
const auto used_club = [&](const std::string &id) {
return std::any_of(
managers_draft_.begin(), managers_draft_.end(),
[&](const auto &m) { return m.value("club", "") == id; });
};
const auto used_portrait = [&](int id) {
return std::any_of(
managers_draft_.begin(), managers_draft_.end(),
[&](const auto &m) { return m.value("portrait", 0) == id; });
};
const int portrait =
selections_["portrait"].empty() ? 0 : std::stoi(selections_["portrait"]);
const auto style = selections_["portrait-style"] == "painted"
? "manager-painted."
: "manager.";
if (!world_->manageable(selected_club_) || used_club(selected_club_))
for (auto *c : world_->clubs())
if (world_->manageable(c->value("id", "")) &&
!used_club(c->value("id", ""))) {
selected_club_ = c->value("id", "");
break;
}
std::string body;
std::vector<std::pair<std::string, std::string>> countries;
std::set<std::string> seen;
for (auto *r : world_->leagues()) {
const auto id = r->value("nation", "");
if (seen.insert(id).second)
countries.emplace_back(id, world_->nation_name(id));
}
auto leagues = world_->leagues(country_);
if (std::none_of(leagues.begin(), leagues.end(),
[&](auto *r) { return r->value("id", "") == league_; }))
league_ = leagues.empty() ? "" : leagues.front()->value("id", "");
std::vector<std::pair<std::string, std::string>> choices;
for (auto *r : leagues)
choices.emplace_back(r->value("id", ""), world_->name(*r));
if (manager_picker_) {
body =
"<div class=\"row\" "
"style=\"justify-content:space-between;\"><h2>Verein auswählen</h2>" +
btn("manager-clubs-back", "Zurück") +
"</div><div class=\"toolbar\" style=\"margin-top:35dp;\">" +
select("manager-country", countries, country_, "manager-country") +
select("manager-league", choices, league_, "manager-league") +
"</div><div class=\"list\" "
"style=\"position:absolute;left:0;right:0;top:240dp;bottom:0;\">";
const auto clubs = world_->clubs(league_);
for (size_t i = 0; i < clubs.size(); ++i) {
const auto *c = clubs[i];
const auto id = c->value("id", "");
const bool locked = !world_->manageable(id), used = used_club(id);
const auto x = (i % 4) * 650, y = (i / 4) * 340;
body +=
"<button data-action=\"manager-club\" data-id=\"" + esc(id) +
"\" class=\"choice " +
(locked ? "locked"
: id == selected_club_ ? "selected"
: "") +
"\" style=\"position:absolute;" + rect(x, y, 618, 310) +
"padding:25dp;\" " + (locked || used ? "disabled" : "") +
"><div class=\"center\">" + crest(c, 150) +
"</div><p style=\"font-size:30dp;margin-top:15dp;\">" +
esc(world_->name(*c)) + "</p>" +
(locked ? "<div style=\"position:absolute;right:24dp;top:24dp;\">" +
glyph("lock", 40) + "</div>"
: "") +
"<p class=\"small\" style=\"margin-top:12dp;\">" +
(locked ? "Nicht spielbar"
: used ? "Bereits vergeben"
: id == selected_club_
? "Ausgewählt"
: esc(world_->name(*world_->find("competitions", league_)))) +
"</p></button>";
}
return window("Neuer Spieler", body + "</div>");
}
const auto *c = world_->find("clubs", selected_club_);
body = "<h2>Mitspieler " + std::to_string(manager_index_ + 1) + " von " +
std::to_string(limit) +
"</h2><p class=\"small\" "
"style=\"position:absolute;right:0;top:10dp;\">Dein Name. Dein "
"Verein. Dein Porträt.</p>";
body +=
"<div class=\"panel\" style=\"position:absolute;" +
rect(0, 90, 1288, 330) +
"padding:32dp;\"><div "
"style=\"position:absolute;left:32dp;top:32dp;width:970dp;\"><label "
"class=\"small\">Managername</label><input id=\"manager-name\" "
"maxlength=\"24\" value=\"" +
esc(selections_["manager-name"]) +
"\" style=\"width:100%;font-size:38dp;height:86dp;margin-top:20dp;\"/><p "
"class=\"small\" style=\"margin-top:20dp;\">So wirst du im Spiel "
"angesprochen.</p><p class=\"small accent\" "
"style=\"margin-top:16dp;\">Porträt " +
std::to_string(portrait + 1) +
"</p></div><div "
"style=\"position:absolute;right:32dp;top:45dp;border-radius:12dp;"
"overflow:hidden;\">" +
img(style + std::to_string(portrait), 174, 232, false, true, 320) +
"</div></div>";
body += "<div class=\"panel\" style=\"position:absolute;" +
rect(1320, 90, 1288, 330) +
"padding:30dp;\"><p class=\"small\">Verein</p>" +
btn("manager-clubs",
crest(c, 176) +
"<div class=\"column\" style=\"gap:20dp;\"><strong "
"style=\"font-size:38dp;\">" +
esc(c ? world_->name(*c) : "") +
"</strong><small class=\"small\">" +
esc(c ? world_->name(*world_->find(
"competitions", c->value("competition", "")))
: "") +
"</small><span class=\"accent\">Verein wählen ›</span></div>",
"row",
"style=\"margin-top:10dp;width:100%;height:230dp;background-"
"color:transparent;border-width:0;padding:0;text-align:left;\"") +
"</div>";
body +=
"<div style=\"position:absolute;" + rect(0, 460, 1288, 170) +
"\"><h3>Startliga</h3><div class=\"row\" style=\"margin-top:20dp;\">" +
select("manager-country", countries, country_, "manager-country") +
select("manager-league", choices, league_, "manager-league") +
"</div></div><div style=\"position:absolute;" +
rect(1320, 460, 1288, 170) +
"\"><h3>Vereinsstärke</h3><div style=\"margin-top:20dp;\">" +
select("manager-strength",
{{"0", "Unteres Drittel"},
{"1", "Mittelfeld"},
{"2", "Oberes Drittel"}},
selections_["manager-strength"].empty()
? "1"
: selections_["manager-strength"],
"manager-strength") +
"</div></div>";
body += "<div class=\"panel\" "
"style=\"position:absolute;left:0;top:670dp;width:1978dp;bottom:"
"145dp;padding:26dp;\"><h3>Managerporträt</h3><div class=\"row\" "
"style=\"position:absolute;right:26dp;top:16dp;\">" +
btn("portrait-style", "Foto",
selections_["portrait-style"] != "painted" ? "primary" : "",
"data-id=\"photo\"") +
btn("portrait-style", "Illustration",
selections_["portrait-style"] == "painted" ? "primary" : "",
"data-id=\"painted\"") +
"</div>";
for (int i = 0; i < 12; ++i) {
const int x = 26 + (i % 6) * 320, y = 100 + (i / 6) * 440;
const bool used = used_portrait(i);
body += "<button data-action=\"portrait\" data-id=\"" + std::to_string(i) +
"\" class=\"choice " + (i == portrait ? "selected" : "") +
"\" style=\"position:absolute;" + rect(x, y, 300, 412) +
"padding:18dp 30dp;\" " + (used ? "disabled" : "") + ">" +
img(style + std::to_string(i), 230, 306, false, true, 350) +
"<p style=\"font-size:24dp;margin-top:18dp;\">" +
(used ? "Vergeben"
: i == portrait ? "Ausgewählt"
: "Porträt " + std::to_string(i + 1)) +
"</p></button>";
}
body += "</div><div class=\"panel\" "
"style=\"position:absolute;left:2010dp;right:0;top:670dp;bottom:"
"145dp;padding:28dp;\"><h3>Mitspieler dieser Partie</h3>";
for (size_t i = 0; i < managers_draft_.size(); ++i) {
const auto &m = managers_draft_[i];
body += "<div class=\"row\" style=\"margin-top:40dp;\">" +
img("manager." + std::to_string(m.value("portrait", 0)), 90, 120,
false, true, 180) +
"<div><small class=\"small\">Spieler " + std::to_string(i + 1) +
"</small><p style=\"margin-top:10dp;\">" +
esc(m.value("name", "")) + "</p><small class=\"small\">" +
esc(world_->name(*world_->find("clubs", m.value("club", "")))) +
"</small></div></div>";
}
body += "<p class=\"small\" "
"style=\"position:absolute;left:28dp;right:28dp;bottom:28dp;\">" +
std::to_string(limit - int(managers_draft_.size())) +
" weitere Plätze frei</p></div><div class=\"bottom-controls\">" +
btn("manager-back", adding_manager_ ? "Abbrechen" : "Zurück") +
btn("manager-next",
adding_manager_ ? "Mitspieler hinzufügen"
: manager_index_ + 1 == limit ? "Spiel starten"
: "Mitspieler bestätigen",
"primary",
world_->manageable(selected_club_) && manager_index_ < limit
? ""
: "disabled") +
"</div>";
return window("Neuer Spieler", body);
}
std::string App::render_opening() {
const std::array<const char *, 3> names = {"UEFA-Cup", "Champions League",
"Europapokal der Pokalsieger"};