The manager as a page of the notebook: one picture with three scenes

The scene under the pointer is framed and lit, the others step back, and under
the picture stands what the scene does. The picture is the project's own; the
page is left by any other marker of the book.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
MichaelandClaude Fable 5.2 committed 2026-11-15 23:05:30 +01:00
1 parent 6020fbc30a
commit 592bc28e9c
12 files changed
+128 -142

No files matched your search

+58 -94
View File
@@ -1,110 +1,74 @@
// SPDX-License-Identifier: GPL-3.0-only
namespace {
// The three scenes of the manager's picture: which action each one is, its name, what it
// does, and where it lies on the picture (left, top, width, height in percent).
struct CareerScene { const char *action, *title, *text; double left, top, width, height; };
constexpr std::array<CareerScene, 3> career_scenes{{
{"career-resign", "Aufhören", "Dein Amt abgeben. Der Verein wird danach vom Computer geführt.", 0, 0, 49.3, 52.3},
{"career-search", "Vereinssuche", "Bei einem anderen Verein anheuern – noch nicht verfügbar.", 50.1, 0, 49.9, 52.3},
{"career-add", "Neuer Spieler", "Einen weiteren menschlichen Mitspieler einrichten: Name, Land, Liga und Verein.", 0, 53.2, 100, 46.8}}};
std::string career_hint_markup(const std::string &action) {
for (const auto &scene : career_scenes)
if (action == scene.action) return "<strong>" + esc(scene.title) + "</strong><span>· " + esc(scene.text) + "</span>";
return {};
}
} // namespace
// Optionen > Manager: one picture with three scenes. The pointer lights the scene it is on and
// darkens the others; under the picture stands what the scene does.
std::string App::render_career() {
const auto c = engine_mode_?engine_career_context():demo_career_context(snap().state,*snap().world);
const bool ended = c.at("ended");
const Json m = engine_mode_?engine_manager_value_.at("active"):manager(snap());
std::string body =
"<section class=\"career-hub\"><header><div><h2>" +
esc(ended ? "Karriere beendet" : m.value("name", "")) + "</h2><p>" +
esc(c.at("current_team").value("name", "")) + " · " +
(c.at("role") == "national" ? "Nationalmannschaft" : "Vereinsmanager") +
"</p></div><nav aria-label=\"Aktiver Manager\">";
for (const auto &person : c.at("active_managers"))
body += btn(
"career-manager", esc(person.value("name", "")),
person.value("portrait", 0) == m.value("portrait", 0) ? "selected" : "",
"id=\"career-manager-" + std::to_string(person.value("portrait", 0)) +
"\" data-id=\"" + std::to_string(person.value("portrait", 0)) +
"\" " + (engine_mode_?"disabled ":"") + "aria-pressed=\"" +
(person.value("portrait", 0) == m.value("portrait", 0) ? "true"
: "false") +
"\"");
body += "</nav></header><div class=\"career-cards\">";
const auto card = [&](const std::string &action, const std::string &key,
const std::string &title, const std::string &note,
const std::string &css, bool disabled) {
return btn(
action,
img(key, css == "career-add" ? 2612 : 1292, 724, false, false, 1600) +
"<span class=\"career-caption\"><strong>" + title +
"</strong><small>" + note + "</small></span>",
"career-card " + css,
"id=\"" + action + "\" " + (disabled ? "disabled" : ""));
page_title_ = ended ? "Karriere beendet" : "Manager";
page_hint_ = m.value("name", "") + " · " + c.at("current_team").value("name", "") + " · " + (c.at("role") == "national" ? "Nationalmannschaft" : "Vereinsmanager");
const auto off = [&](const std::string &action) {
if (action == "career-search") return true;
if (action == "career-resign") return ended || (engine_mode_ && engine_manager_value_.at("can_resign") != true);
return ended || (engine_mode_ && engine_manager_value_.at("can_join") != true);
};
body += card("career-resign", "manager.resign", "Aufgeben",
engine_mode_&&engine_manager_value_.at("can_resign")!=true?"Mehrspieler folgt":"Dein Amt abgeben", "career-resign", ended||(engine_mode_&&engine_manager_value_.at("can_resign")!=true)) +
card("career-search", "manager.search", "Vereinssuche", "Später",
"career-search", true) +
card("career-add", "manager.add", "Neuer Spieler",
"Weiteren Menschen einrichten", "career-add", ended||(engine_mode_&&engine_manager_value_.at("can_join")!=true)) +
"</div><footer><section><span>Dein Aufgabenbereich</span><div>";
for (const auto &role : c.at("available_roles")) {
const auto id = role.get<std::string>();
body += btn("career-role", id == "club" ? "Verein" : "Nationalmannschaft",
c.at("role") == role ? "selected" : "",
"id=\"career-role-" + id + "\" data-id=\"" + id +
"\" aria-pressed=\"" +
(c.at("role") == role ? "true" : "false") + "\" " +
(ended||engine_mode_ ? "disabled" : ""));
// 1448 x 1086 on the page: as tall as the page allows
constexpr double frame_h = 1485, frame_w = frame_h * 1448 / 1086;
std::string body = "<section class=\"pg-page mg-page\"><div class=\"mg-stage\"><div class=\"mg-frame\" style=\"width:" + scalar(frame_w) + "dp;height:" + scalar(frame_h) + "dp;\"><div class=\"mg-art\">" +
img("manager.scenes", frame_w, frame_h, false, false, 2048) + "</div>";
for (const auto &scene : career_scenes)
body += "<button data-action=\"" + std::string(scene.action) + "\" class=\"mg-hot" + std::string(!career_hint_.empty() && career_hint_ != scene.action ? " dim" : "") + "\" id=\"" + scene.action + "\" data-hint=\"" + scene.action + "\" aria-label=\"" + esc(std::string(scene.title) + ": " + scene.text) + "\" " +
(off(scene.action) ? "disabled=\"disabled\" aria-disabled=\"true\" " : "") + "style=\"left:" + scalar(scene.left) + "%;top:" + scalar(scene.top) + "%;width:" + scalar(scene.width) + "%;height:" + scalar(scene.height) + "%;\"></button>";
const auto hint = career_hint_markup(career_hint_);
body += "</div></div><div class=\"pg-row mg-foot\">";
// the demo lets one change who plays, as what, and on which ground the line-up is shown
std::string people, tasks;
if (!engine_mode_) {
for (const auto &person : c.at("active_managers")) {
const bool on = person.value("portrait", 0) == m.value("portrait", 0);
people += pg_button("career-manager", esc(person.value("name", "")), on ? "on" : "", "id=\"career-manager-" + std::to_string(person.value("portrait", 0)) + "\" data-id=\"" + std::to_string(person.value("portrait", 0)) + "\" aria-pressed=\"" + (on ? "true" : "false") + "\"");
}
for (const auto &role : c.at("available_roles")) {
const auto id = role.get<std::string>();
tasks += pg_button("career-role", id == "club" ? "Verein" : "Nationalmannschaft", c.at("role") == role ? "on" : "", "id=\"career-role-" + id + "\" data-id=\"" + id + "\" aria-pressed=\"" + (c.at("role") == role ? "true" : "false") + "\" " + (ended ? "disabled=\"disabled\"" : ""));
}
for (const auto *surface : {"outdoor", "indoor"})
tasks += pg_button("career-surface", std::string(surface) == "indoor" ? "Halle" : "Rasen", c.at("surface") == surface ? "on" : "", "id=\"career-surface-" + std::string(surface) + "\" data-id=\"" + surface + "\" aria-pressed=\"" +
(c.at("surface") == surface ? "true" : "false") + "\" " + (ended || (std::string(surface) == "indoor" && c.at("role") == "national") ? "disabled=\"disabled\"" : ""));
}
body += "</div></section><section><span>Aufstellung · Vorschau</span><div>";
for (const auto *surface : {"outdoor", "indoor"}) {
if(engine_mode_&&c.at("surface")!=surface)continue;
body += btn("career-surface",
std::string(surface) == "indoor" ? (engine_mode_?"Halle · Wechselpaare":"Halle · 6 Spieler")
: "Rasen · 11 Spieler",
c.at("surface") == surface ? "selected" : "",
"id=\"career-surface-" + std::string(surface) +
"\" data-id=\"" + surface + "\" aria-pressed=\"" +
(c.at("surface") == surface ? "true" : "false") + "\" " +
(ended || engine_mode_ || (std::string(surface) == "indoor" &&
c.at("role") == "national")
? "disabled"
: ""));
}
body += "</div></section></footer></section>";
body += "<div class=\"mg-side\">" + people + "</div><div class=\"pg-status mg-hint\" id=\"career-hint\" role=\"status\" style=\"visibility:" + std::string(hint.empty() ? "hidden" : "visible") + ";\">" + hint +
"</div><div class=\"mg-side right\">" + tasks + "</div></div></section>";
if (career_resign_open_ || career_game_end_) {
body = "<div id=\"career-underlay\" aria-hidden=\"true\">" + body +
"</div><div id=\"career-dialog-layer\" "
"class=\"entry-dialog-layer\"><section class=\"entry-dialog "
"career-dialog\" role=\"dialog\" aria-modal=\"true\"><h2>" +
std::string(career_game_end_ ? "Spiel beendet"
: "Manageramt aufgeben?") +
"</h2>";
body = "<div id=\"career-underlay\" aria-hidden=\"true\">" + body + "</div><div id=\"career-dialog-layer\" class=\"pg-ov\"><section class=\"pg-dlg\" role=\"dialog\" aria-modal=\"true\" style=\"width:" + pg(480) + ";\"><div><h2>" +
std::string(career_game_end_ ? "Spiel beendet" : "Aufhören?") + "</h2></div>";
if (career_game_end_)
body += "<p>Der letzte menschliche Mitspieler hat sein Amt abgegeben. "
"Zurück zum Hauptmenü.</p><footer>" +
btn("career-game-end", "Zum Hauptmenü", {},
"id=\"career-game-end\"") +
"</footer>";
body += "<p>Es ist kein menschlicher Manager mehr im Amt.</p><nav class=\"pg-dlg-act\">" + pg_button("career-game-end", "Zum Hauptmenü", "primary", "id=\"career-game-end\"") + "</nav>";
else {
std::vector<std::pair<std::string, std::string>> people;
std::vector<std::pair<std::string, std::string>> people_rows;
for (const auto &person : c.at("active_managers")) {
const auto *club = world_->find("clubs", person.value("club", ""));
people.emplace_back(
std::to_string(person.value("portrait", 0)),
person.value("name", "") + " · " +
((engine_mode_?c.at("role")!="national":snap().state.at("edits").at("setup").value("league", true))
? (club ? world_->name(*club) : "")
: "Deutschland"));
people_rows.emplace_back(std::to_string(person.value("portrait", 0)),
person.value("name", "") + " · " + ((engine_mode_ ? c.at("role") != "national" : snap().state.at("edits").at("setup").value("league", true)) ? (club ? world_->name(*club) : "") : "Deutschland"));
}
body +=
"<label for=\"career-resign-owner\">Wer gibt sein Amt ab?</label>" +
select("career-resign-owner", people,
std::to_string(career_resign_portrait_),
"career-resign-owner") +
"<p>" +
(people.size() == 1
? "Du bist der letzte menschliche Mitspieler. Mit deiner "
"Bestätigung endet diese Partie."
: "Die anderen Menschen spielen weiter. Die KI übernimmt den "
"abgegebenen Verein in dieser Karrierevorschau.") +
"</p><footer>" +
btn("career-resign-cancel", "Abbrechen", {},
"id=\"career-resign-cancel\"") +
btn("career-resign-confirm", "Amt aufgeben", {},
"id=\"career-resign-confirm\"") +
"</footer>";
body += "<div class=\"pg-row mg-owner\" style=\"justify-content:space-between;\"><label for=\"career-resign-owner\">Wer gibt sein Amt ab?</label>" + select("career-resign-owner", people_rows, std::to_string(career_resign_portrait_), "career-resign-owner") +
"</div><span class=\"pg-mut\" style=\"display:block;\">" +
(people_rows.size() == 1 ? "Der Verein wird danach vom Computer geführt. Du bist der letzte menschliche Manager: Mit deiner Bestätigung ist das Spiel beendet."
: "Der Verein wird danach vom Computer geführt. Die anderen spielen weiter.") +
"</span><nav class=\"pg-dlg-act\">" + pg_button("career-resign-cancel", "Abbrechen", "", "id=\"career-resign-cancel\"") + pg_button("career-resign-confirm", "Aufhören", "primary", "id=\"career-resign-confirm\"") + "</nav>";
}
body += "</section></div>";
}