Files
Dreierpack-Manager/src/modern/ui/career_screens.inc
T
MichaelandClaude Fable 5.2 592bc28e9c 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>
2026-11-15 23:05:30 +01:00

77 lines
6.7 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
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());
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);
};
// 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 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=\"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>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_rows;
for (const auto &person : c.at("active_managers")) {
const auto *club = world_->find("clubs", person.value("club", ""));
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 += "<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>";
}
return window("Manager", body);
}