Contracts, surroundings and balance sheet as pages of the notebook

Contracts: club and wage bill, the squad as a table, the negotiation as a note on
the dimmed book. Surroundings: six cards with their stars, pictures and costs, the
monthly sum in the page's title. Balance: figures, income against costs, the plan
for the coming year, and the what-if calculation in the notebook's inks.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
MichaelandClaude Fable 5.2 committed 2026-11-15 17:34:15 +01:00
1 parent ac455eabfe
commit 1a1f43ddf7
9 files changed
+204 -454

No files matched your search

+81 -100
View File
@@ -84,15 +84,18 @@ std::string App::render_contracts() {
const auto managed = engine_mode_ ? projection.at("club").get<std::string>() : contracts_managed(snapshot);
const auto *own = snapshot.world ? snapshot.world->find("clubs", managed) : nullptr;
const auto club_name = own ? snapshot.world->name(*own) : std::string("—");
std::string output = "<div id=\"contracts-underlay\" class=\"contracts-overview\">"
"<header class=\"contracts-heading\"><div class=\"contracts-heading-club\"><div class=\"contracts-club-label\">" +
(own ? img(own->value("crest", ""), 58, 58, true) : "") +
"<span>" + esc(club_name) + "</span></div><p>" + std::to_string(count) +
" Spieler · Spieler anklicken, um einen Vertrag zu verhandeln</p></div>"
"<div class=\"contracts-salary-total\"><span>Monatsgehälter</span><span class=\"contracts-total-value money-amount\">" +
(ready ? esc(show_money(contracts_field(projection, "salary_total"))) : "—") +
"</span></div></header><div id=\"contracts-roster-scroll\" class=\"contracts-roster\">"
"<div class=\"contracts-table\" role=\"table\"><div class=\"contracts-row contracts-table-head\" role=\"row\">";
// the page: club and wage bill, the squad as a table, the three sets of columns in the foot
page_hint_ = "Spieler anklicken";
const auto position_tag = [&](const Json &row) {
const auto text = contracts_position(row);
const auto first = text.substr(0, text.find(' '));
return "<span class=\"pg-pos " + esc(first) + "\" style=\"width:auto;padding:0 " + pg(8) + ";\">" + esc(text) + "</span>";
};
std::string output = "<div id=\"contracts-underlay\" class=\"pg-page\"><header class=\"pg-row\" style=\"" + pg_css("gap:14px;") + "\">" +
(own ? img(own->value("crest", ""), 130, 130, true) : "") + "<div class=\"pg-grow\"><h2 class=\"pg-h large\">" + esc(club_name) + "</h2><span class=\"pg-mut\" style=\"display:block;\">" + std::to_string(count) +
" Spieler · Spieler anklicken, um einen Vertrag zu verhandeln</span></div><div style=\"display:flex;flex:none;min-width:" + pg(230) + ";\">" +
pg_stat("Monatsgehälter", "<span class=\"contracts-total-value money-amount\">" + (ready ? esc(show_money(contracts_field(projection, "salary_total"))) : std::string("—")) + "</span>") +
"</div></header><div class=\"pg-panel pg-col pg-grow\" style=\"" + pg_css("gap:0px;padding:6px 12px;") + "\"><div class=\"pg-t\" role=\"table\"><div class=\"pg-thead\" role=\"row\">";
const std::array<std::vector<std::pair<std::string, std::string>>, 3> headings = {{
{{"name", "Spieler"}, {"position", "Pos."}, {"condition", "Kond."},
{"technique", "Technik"}, {"form", "Form"}, {"strength", "Stärke"}, {"age", "Alter"}},
@@ -102,60 +105,48 @@ std::string App::render_contracts() {
{"salary", "Gehalt / Monat"}, {"months", "Vertrag"}, {"insurance", "Versicherung"}}
}};
const auto &columns = headings[size_t(contracts_tab_)];
for (size_t column = 0; column < columns.size(); ++column)
output += "<div class=\"contracts-cell c" + std::to_string(column) +
"\" role=\"columnheader\"><span>" + esc(columns[column].second) + "</span></div>";
output += "</div>";
const auto width = [&](const std::string &key) { return key == "name" ? 0.0 : key == "position" ? 150.0 : key == "salary" ? 200.0 : key == "months" || key == "insurance" ? 170.0 : 120.0; };
for (const auto &[key, label] : columns)
output += pg_th(label, width(key), key == "name" || key == "position" ? "" : "r");
output += "</div><div id=\"contracts-roster-scroll\" class=\"pg-tbody\">";
if (rows.is_array())
for (size_t i = 0; i < rows.size(); ++i) {
const auto &row = rows[i];
const auto id = contracts_text(contracts_field(row, "id"), "");
const auto name = contracts_text(contracts_field(row, "name"));
output += "<div class=\"contracts-row " + std::string(i % 2 == 0 ? "striped " : "") +
(contracts_player_ == id ? "selected" : "") + "\" role=\"row\" data-player=\"" + esc(id) + "\">";
for (size_t column = 0; column < columns.size(); ++column) {
const auto key = columns[column].first;
const auto source = contracts_text(contracts_field(row, "source_label"), "");
output += "<div class=\"contracts-cell c" + std::to_string(column) +
"\" role=\"cell\" title=\"" + esc(key == "salary" ? source : "") + "\">";
if (column == 0)
output += btn("contract-player", "<span class=\"contract-player-rank\">" +
std::to_string(i + 1) + ".</span><span class=\"contract-player-name\" title=\"" +
esc(name) + "\">" + esc(name) + "</span>", "contract-player-button",
"id=\"contract-player-" + esc(id) + "\" data-id=\"" + esc(id) +
"\" aria-haspopup=\"dialog\" aria-pressed=\"" + (contracts_player_ == id ? "true" : "false") + "\"");
output += "<div class=\"pg-tr " + std::string(contracts_player_ == id ? "sel" : "") + "\" role=\"row\" data-player=\"" + esc(id) + "\">";
for (const auto &[key, label] : columns) {
if (key == "name")
output += pg_td(btn("contract-player", "<span class=\"pg-rank pg-mut\" style=\"font-weight:normal;\">" + std::to_string(i + 1) + ".</span><span title=\"" + esc(name) + "\">" + esc(name) + "</span>", "pg-link",
"id=\"contract-player-" + esc(id) + "\" data-id=\"" + esc(id) + "\" aria-haspopup=\"dialog\" aria-pressed=\"" + (contracts_player_ == id ? "true" : "false") + "\""), 0, "", true);
else if (key == "position") output += pg_td(position_tag(row), width(key), "", true);
else {
std::string value;
if (key == "position") value = contracts_position(row);
else if (key == "salary") value = ready ? show_money(contracts_field(row, "salary")) : "—";
else if (key == "months") value = contracts_number(contracts_field(row, "months")) + " Monate";
bool soon = false;
if (key == "salary") value = ready ? show_money(contracts_field(row, "salary")) : "—";
else if (key == "months") { value = contracts_number(contracts_field(row, "months")) + " Monate"; soon = contracts_field(row, "months").is_number_integer() && contracts_field(row, "months").get<int>() <= 9; }
else if (key == "insurance") {
const auto &insurance = contracts_field(row, "insurance");
value = insurance.is_number_integer() ? insurance.get<int>() == 0 ? "Ohne"
: contracts_number(insurance) + " Monate" : "—";
value = insurance.is_number_integer() ? insurance.get<int>() == 0 ? "Ohne" : contracts_number(insurance) + " Monate" : "—";
} else value = contracts_number(contracts_field(row, key.c_str()));
output += "<span class=\"contract-value\">" + esc(value) + "</span>";
output += pg_td(key == "strength" ? "<strong>" + esc(value) + "</strong>" : soon ? "<span class=\"pg-tag accent\" style=\"display:inline-block;\">" + esc(value) + "</span>" : "<span class=\"contract-value\">" + esc(value) + "</span>", width(key), "r");
}
output += "</div>";
}
output += "</div>";
}
output += "</div>";
if (!ready || count == 0)
output += "<p class=\"contracts-empty\">" + std::string(ready
? "Für diesen Verein sind keine Spieler im Katalog vorhanden."
: "Die Vertragsvorschau ist derzeit nicht verfügbar.") + "</p>";
output += "</div><nav class=\"contracts-actions\">";
output += "<div class=\"pg-empty\">" + std::string(ready ? "Für diesen Verein sind keine Spieler im Katalog vorhanden." : "Die Vertragsvorschau ist derzeit nicht verfügbar.") + "</div>";
output += "</div></div></div><nav class=\"pg-foot\"><div class=\"pg-seg\">";
const std::array<const char *, 3> tabs = {"Daten A", "Daten B", "Gehalt"};
for (int tab = 0; tab < 3; ++tab)
output += btn("contracts-tab", "<span>" + std::string(tabs[size_t(tab)]) + "</span>",
"contract-control " + std::string(contracts_tab_ == tab ? "selected" : ""),
"id=\"contracts-tab-" + std::to_string(tab) + "\" data-id=\"" + std::to_string(tab) +
"\" aria-pressed=\"" + (contracts_tab_ == tab ? "true" : "false") + "\"");
output += btn("contracts-bonuses", "<span>Team-Prämien</span>", "contract-control bonuses",
"id=\"contracts-bonuses\" " + std::string(ready && !engine_mode_ ? "" : "disabled")) + "</nav></div>";
output += btn("contracts-tab", "<span>" + std::string(tabs[size_t(tab)]) + "</span>", std::string(tab ? "" : "first ") + (contracts_tab_ == tab ? "on" : ""),
"id=\"contracts-tab-" + std::to_string(tab) + "\" data-id=\"" + std::to_string(tab) + "\" aria-pressed=\"" + (contracts_tab_ == tab ? "true" : "false") + "\"");
output += "</div>" + pg_button("contracts-bonuses", "<span>Team-Prämien</span>", "", "id=\"contracts-bonuses\" " + std::string(ready && !engine_mode_ ? "" : "disabled")) +
"<span class=\"pg-sp\"></span>" + pg_status(engine_mode_ ? (engine_busy_ ? engine_operation_ : !engine_notice_.empty() ? engine_notice_ : std::string("Forderungen ausdrücklich abfragen. Erst das bestätigte Angebot wird verhandelt."))
: std::string("Erst „Angebot machen“ übernimmt Gehalt und Laufzeit.")) + "</nav></div>";
if (contracts_dialog_.empty()) return output;
// the dialogs: a note on the dimmed book
const auto &draft_row = contracts_field(contract_draft_, "row");
const auto player_name = contracts_text(contracts_field(draft_row, "name"));
const auto &world = contracts_world_ ? contracts_world_ : snapshot.world;
@@ -165,11 +156,12 @@ std::string App::render_contracts() {
: contracts_dialog_ == "bonuses" ? "Team-Prämien"
: contracts_text(contracts_field(contract_draft_, "notice_title"), "Vertragsvorschau");
std::string body, actions;
const auto close = [&](const std::string &caption) {
return btn("contract-close", "<span>" + esc(caption) + "</span>", "contract-control",
"id=\"contract-close\"");
double dialog_width = 440;
const auto close = [&](const std::string &caption, bool primary = false) {
return pg_button("contract-close", "<span>" + esc(caption) + "</span>", primary ? "primary" : "", "id=\"contract-close\"");
};
if (offer) {
dialog_width = 660;
const auto &salary = contracts_field(draft_row, "salary");
const auto &proposed = contracts_field(contract_draft_, "salary");
const auto &months = contracts_field(contract_draft_, "months");
@@ -181,76 +173,65 @@ std::string App::render_contracts() {
// Demo asking prices never enter a real negotiation.
const Json demand = engine_mode_ ? (quoted ? engine_quote.at("demands")[size_t(term_index)] : Json()) : salary.is_number_integer()
? Json(((salary.get<int64_t>() / factor * 11 + 5) / 10) * factor) : Json();
body = "<p class=\"contract-player-summary\">" + esc(contracts_position(draft_row)) +
" · Stärke " + esc(contracts_number(contracts_field(draft_row, "strength"))) +
" · " + esc(contracts_number(contracts_field(draft_row, "age"))) + " Jahre</p>"
"<div class=\"contract-scenes\"><div class=\"contract-scene\">" + img("contracts.scene.0", 955, 291.0625) +
"</div><div class=\"contract-scene\">" + img("contracts.scene.1", 955, 291.0625) + "</div></div>"
"<div class=\"contract-amounts\"><div class=\"contract-amount-card\" title=\"" + esc(source) +
"\"><span class=\"contract-amount-label\">Aktuelles Monatsgehalt</span><span class=\"contract-amount-value\">" +
(world ? esc(show_money(salary)) : "—") +
"</span></div><div class=\"contract-amount-card\"><span class=\"contract-amount-label\">" + std::string(engine_mode_ ? "Forderung für die gewählte Laufzeit" : "Fiktive Forderung") + "</span>"
"<span class=\"contract-amount-value\">" + (world ? esc(show_money(demand)) : "—") +
"</span></div></div><div class=\"contract-duration-heading\"><span>Laufzeit</span><span class=\"contract-duration-value\">" +
esc(contracts_number(months)) + " Monate</span></div><nav class=\"contract-duration\" aria-label=\"Vertragslaufzeit\">";
const double scene = (660 - 44 - 10) / 2.0 * 2.25;
body = "<div class=\"pg-row\" style=\"" + pg_css("gap:10px;") + "\"><div class=\"pg-scene\">" + img("contracts.scene.0", scene, scene * 291.0625 / 955) +
"</div><div class=\"pg-scene\">" + img("contracts.scene.1", scene, scene * 291.0625 / 955) + "</div></div>"
"<div class=\"pg-row pg-mut\" style=\"" + pg_css("gap:14px;") + "\">" + position_tag(draft_row) + "<span>" + esc(contracts_number(contracts_field(draft_row, "age"))) + " Jahre</span><span>Stärke " +
esc(contracts_number(contracts_field(draft_row, "strength"))) + "</span><span>Restlaufzeit " + esc(contracts_number(contracts_field(draft_row, "months"))) + " Monate</span></div>"
"<div class=\"pg-row\" style=\"" + pg_css("gap:10px;") + "\" title=\"" + esc(source) + "\">" + pg_stat("Aktuelles Monatsgehalt", world ? esc(show_money(salary)) : std::string("—")) +
pg_stat(engine_mode_ ? "Forderung für die gewählte Laufzeit" : "Fiktive Forderung", world && !demand.is_null() ? esc(show_money(demand)) : std::string("—"), demand.is_null() ? "noch nicht abgefragt" : "") + "</div>"
"<div class=\"pg-row\" style=\"justify-content:space-between;\">" + pg_kicker("Laufzeit · " + contracts_number(months) + " Monate") + "<nav class=\"pg-seg\" aria-label=\"Vertragslaufzeit\">";
for (const int term : {12, 24, 36, 48})
body += btn("contract-term", "<span>" + std::to_string(term / 12) +
(term == 12 ? " Jahr" : " Jahre") + "</span>", "contract-control " +
std::string(months == term ? "selected" : ""), "id=\"contract-term-" + std::to_string(term) +
"\" data-id=\"" + std::to_string(term) + "\" aria-pressed=\"" + (months == term ? "true" : "false") + "\" " + std::string(engine_mode_ && quoted && engine_quote.at("demands")[size_t(term / 12 - 1)].is_null() ? "disabled" : ""));
body += "</nav><div class=\"contract-salary\"><div class=\"contract-salary-label\"><span>Dein Angebot pro Monat</span>"
"<span class=\"contract-salary-hint\">Betrag über die gemeinsame Zahleneingabe ändern</span></div>" +
btn("contract-salary", "<span>" + (world && proposed.is_number_integer()
? esc(engine_mode_ ? money(proposed.get<int64_t>() * 100, {{"code", "EUR"}, {"minor_units", 2}}) : std::to_string(proposed.get<int64_t>())) : "—") + "</span>",
"contract-salary-input amount-trigger", "id=\"contract-salary\" aria-haspopup=\"dialog\" aria-label=\"Angebotenes Monatsgehalt ändern\" " + std::string(engine_mode_ && !quoted ? "disabled" : "")) +
"</div><p class=\"contract-draft-note\">" + std::string(engine_mode_ ? (!contracts_notice_.empty() ? contracts_notice_ : "Forderungen ausdrücklich abfragen. Erst das bestätigte Angebot wird verhandelt.") : "Erst „Angebot machen“ übernimmt Gehalt und Laufzeit.") + "</p>";
body += btn("contract-term", "<span>" + std::to_string(term / 12) + (term == 12 ? " Jahr" : " Jahre") + "</span>", std::string(term == 12 ? "first " : "") + (months == term ? "on" : ""),
"id=\"contract-term-" + std::to_string(term) + "\" data-id=\"" + std::to_string(term) + "\" aria-pressed=\"" + (months == term ? "true" : "false") + "\" " +
std::string(engine_mode_ && quoted && engine_quote.at("demands")[size_t(term / 12 - 1)].is_null() ? "disabled" : ""));
body += "</nav></div><div class=\"pg-row\" style=\"justify-content:space-between;\">" + pg_kicker("Dein Angebot pro Monat") +
pg_button("contract-salary", "<span>" + (world && proposed.is_number_integer()
? esc(engine_mode_ ? money(proposed.get<int64_t>() * 100, {{"code", "EUR"}, {"minor_units", 2}}) : std::to_string(proposed.get<int64_t>())) : std::string("—")) + "</span>",
"amount-trigger", "id=\"contract-salary\" aria-haspopup=\"dialog\" aria-label=\"Angebotenes Monatsgehalt ändern\" " + std::string(engine_mode_ && !quoted ? "disabled" : "")) +
"</div><span class=\"pg-mut\" style=\"display:block;font-size:" + pg(12.5) + ";\">" +
esc(engine_mode_ ? (!contracts_notice_.empty() ? contracts_notice_ : std::string("Forderungen ausdrücklich abfragen. Erst das bestätigte Angebot wird verhandelt.")) : std::string("Erst „Angebot machen“ übernimmt Gehalt und Laufzeit.")) + "</span>";
actions = close("Abbrechen") +
btn("contract-insurance", "<span>" + std::string(engine_mode_ ? "Details" : "Versichern") + "</span>", "contract-control", "id=\"contract-insurance\"") +
(engine_mode_ && !quoted ? btn("contract-quote", "<span>Forderungen abfragen</span>", "contract-control contract-submit", "id=\"contract-quote\" " + std::string(draft_row.value("can_request", false) && engine_quote.is_null() ? "" : "disabled")) :
btn("contract-submit", "<span>Angebot machen</span>", "contract-control contract-submit",
pg_button("contract-insurance", "<span>" + std::string(engine_mode_ ? "Details" : "Versichern") + "</span>", "", "id=\"contract-insurance\"") +
(engine_mode_ && !quoted ? pg_button("contract-quote", "<span>Forderungen abfragen</span>", "primary", "id=\"contract-quote\" " + std::string(draft_row.value("can_request", false) && engine_quote.is_null() ? "" : "disabled")) :
pg_button("contract-submit", "<span>Angebot machen</span>", "primary",
"id=\"contract-submit\" " + std::string(proposed.is_number_integer() && (!engine_mode_ || (!demand.is_null() && engine_quote.value("can_offer", false) && proposed.get<int64_t>() >= 0 && proposed.get<int64_t>() <= engine_quote.at("max_salary").get<int64_t>() / 100)) ? "" : "disabled")));
} else if (engine_mode_ && contracts_dialog_ == "engine-details") {
title = "Versicherung und Prämien · " + player_name;
body = "<p class=\"contract-player-summary\">Versicherung: " + contracts_number(draft_row.at("insurance")) + " Monate · Versicherung und Prämien sind hier schreibgeschützt.</p><div class=\"contract-bonuses\">";
body = "<div class=\"pg-panel\"><div class=\"pg-kv\"><span>Versicherung</span><strong>" + (draft_row.at("insurance").is_number_integer() && draft_row.at("insurance").get<int>() == 0 ? std::string("Ohne") : contracts_number(draft_row.at("insurance")) + " Monate") + "</strong></div>";
const std::array<const char *, 7> labels{"Torprämie", "Punktprämie", "Auflaufprämie", "Meisterprämie", "Prämie Pl. 2–5", "Prämie Pl. 6–10", "Nichtabstiegsprämie"};
for (size_t i = 0; i < labels.size(); ++i) body += "<div class=\"contract-bonus-row\"><span>" + std::string(labels[i]) + "</span><span>Stufe " + contracts_number(draft_row.at("premiums")[i]) + "</span></div>";
body += "</div>"; actions = close("Zurück zur Verhandlung");
for (size_t i = 0; i < labels.size(); ++i) body += "<div class=\"pg-kv\"><span>" + std::string(labels[i]) + "</span><strong>Stufe " + contracts_number(draft_row.at("premiums")[i]) + "</strong></div>";
body += "</div><span class=\"pg-mut\" style=\"display:block;font-size:" + pg(12.5) + ";\">Nur Anzeige. Versicherung und Prämien sind hier nicht veränderbar.</span>";
actions = close("Zurück zur Verhandlung", true);
} else if (insurance) {
dialog_width = 560;
const auto current = contracts_field(draft_row, "insurance");
body = "<p class=\"contract-insurance-prompt\">Wähle die Versicherungsdauer für diesen Spieler.</p>"
"<nav class=\"contract-insurance-options\">";
body = "<p>Wähle die Versicherungsdauer für diesen Spieler.</p><nav class=\"pg-row\" style=\"" + pg_css("gap:10px;") + "\">";
for (const int duration : {0, 12, 24})
body += btn("contract-insure", "<span class=\"contract-insurance-title\">" +
(duration ? std::to_string(duration) + " Monate" : "Ohne") +
"</span><span class=\"contract-insurance-caption\">" +
(duration ? "Versicherungslaufzeit" : "Keine Versicherung") + "</span>",
"contract-control " + std::string(current == duration ? "selected" : ""),
"id=\"contract-insure-" + std::to_string(duration) + "\" data-id=\"" +
std::to_string(duration) + "\" aria-pressed=\"" + (current == duration ? "true" : "false") + "\"");
body += btn("contract-insure", "<span class=\"pg-h\">" + (duration ? std::to_string(duration) + " Monate" : std::string("Ohne")) + "</span><span class=\"pg-mut\">" +
(duration ? "Versicherungslaufzeit" : "Keine Versicherung") + "</span>", "pg-card pg-grow " + std::string(current == duration ? "sel" : ""),
"id=\"contract-insure-" + std::to_string(duration) + "\" data-id=\"" + std::to_string(duration) + "\" aria-pressed=\"" + (current == duration ? "true" : "false") + "\"");
body += "</nav>";
actions = close("Abbrechen");
} else if (contracts_dialog_ == "bonuses") {
body = "<p class=\"contract-player-summary\">Prämienvereinbarung für die gesamte Mannschaft</p>"
"<div class=\"contract-bonuses\">";
dialog_width = 520;
body = "<div class=\"pg-panel pg-col\" style=\"" + pg_css("gap:6px;") + "\">";
const auto &bonuses = contracts_field(contract_draft_, "bonuses");
const std::array<const char *, 7> names = {"Torprämie", "Punktprämie", "Auflaufprämie", "Meisterprämie",
"Prämie Pl. 2–5", "Prämie Pl. 6–10", "Nichtabstiegsprämie"};
const std::array<const char *, 7> names = {"Torprämie", "Punktprämie", "Auflaufprämie", "Meisterprämie", "Prämie Pl. 2–5", "Prämie Pl. 6–10", "Nichtabstiegsprämie"};
for (size_t i = 0; i < names.size(); ++i) {
const Json bonus = bonuses.is_array() && i < bonuses.size() ? bonuses[i] : Json();
body += "<div class=\"contract-bonus-row\"><span>" + esc(contracts_text(contracts_field(bonus, "name"), names[i])) + "</span>" +
btn("contract-bonus", "<span>" + esc(contracts_number(contracts_field(bonus, "value"))) + "</span>",
"contract-control amount-trigger", "id=\"contract-bonus-" + std::to_string(i) + "\" data-id=\"" +
std::to_string(i) + "\" aria-haspopup=\"dialog\"") + "</div>";
body += "<div class=\"pg-row\" style=\"justify-content:space-between;\"><span>" + esc(contracts_text(contracts_field(bonus, "name"), names[i])) + "</span>" +
pg_button("contract-bonus", "<span>" + esc(contracts_number(contracts_field(bonus, "value"))) + "</span>", "amount-trigger",
"id=\"contract-bonus-" + std::to_string(i) + "\" data-id=\"" + std::to_string(i) + "\" aria-haspopup=\"dialog\"") + "</div>";
}
body += "</div>";
actions = close("Zurück");
actions = close("Zurück", true);
} else {
body = "<p class=\"contract-notice-text\">" + esc(contracts_notice_) + "</p>";
actions = close("Verstanden");
body = "<p>" + esc(contracts_notice_) + "</p>";
actions = close("Verstanden", true);
}
return output + "<div id=\"contracts-layer\" class=\"contracts-layer\"><section id=\"contracts-dialog\" "
"class=\"contracts-dialog " + std::string(contracts_dialog_ == "engine-details" ? "contracts-dialog-bonuses " : "") + "contracts-dialog-" + esc(contracts_dialog_) +
"\" role=\"dialog\" aria-modal=\"true\" aria-labelledby=\"contract-dialog-title\">"
"<h2 id=\"contract-dialog-title\">" + esc(title) + "</h2>" + body +
"<nav class=\"contract-dialog-actions\">" + actions + "</nav></section></div>";
// the ids of the layer, the dialog and its title are what the controls and the tests look for
return output + "<div id=\"contracts-layer\" class=\"pg-ov\"><section id=\"contracts-dialog\" class=\"pg-dlg contracts-dialog-" + esc(contracts_dialog_) +
"\" role=\"dialog\" aria-modal=\"true\" aria-labelledby=\"contract-dialog-title\" style=\"width:" + pg(dialog_width) + ";\"><div><h2 id=\"contract-dialog-title\">" + esc(title) + "</h2></div>" + body +
"<nav class=\"pg-dlg-act\">" + actions + "</nav></section></div>";
}
+28 -46
View File
@@ -1,64 +1,46 @@
// SPDX-License-Identifier: GPL-3.0-only
// The club's surroundings: three youth teams and three members of staff, six cards in two
// rows. Each card carries its monthly budget as a row of stars, its picture and its cost.
std::string App::render_environment() {
const auto snapshot = engine_mode_ ? Snapshot{input_revision(), world_, Json::object()} : snap();
if (!snapshot.world) return "<p class=\"environment-unavailable\">Die Umfeldvorschau ist derzeit nicht verfügbar.</p>";
const std::string unavailable = "<div class=\"pg-page\"><div class=\"pg-empty\">Die Umfeldvorschau ist derzeit nicht verfügbar.</div></div>";
if (!snapshot.world) return unavailable;
const auto view = engine_mode_ ? engine_environment_projection(engine_data_) : demo_environment_rows(snapshot.state, *snapshot.world);
if (!view.value("ok", false)) return "<p class=\"environment-unavailable\">Die Umfeldvorschau ist derzeit nicht verfügbar.</p>";
const auto funded = theme_ == "silver" ? "#805b18" : theme_ == "matchday" ? "#e1c68b" : "#e5cd8c";
const auto unfunded = theme_ == "silver" ? "#526779" : theme_ == "matchday" ? "#b7b4b9" : "#6f8595";
if (!view.value("ok", false)) return unavailable;
const auto currency = engine_mode_ ? Json{{"code", "EUR"}, {"minor_units", 2}} : snapshot.world->manifest().value("currency", Json::object());
const auto star = [&](bool active) {
const auto color = active ? funded : unfunded;
const std::string colour = active ? (theme_ == "silver" ? "#b2622d" : theme_ == "matchday" ? "#3f7a3a" : "#e0a25f") : (theme_ == "silver" ? "#c0b6a5" : theme_ == "matchday" ? "#afc09a" : "#525966");
const std::string svg = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"48\" height=\"48\" viewBox=\"0 0 48 48\">"
"<path fill=\"" + std::string(color) + "\" d=\"m24 3 6 13 15 2-11 11 3 15-13-7-13 7 3-15L3 18l15-2Z\"/></svg>";
return picture(renderer_.diagram("environment-star-" + theme_ + (active ? "-funded" : "-unfunded"), svg, 96), 40, 40);
"<path fill=\"" + colour + "\" d=\"m24 3 6 13 15 2-11 11 3 15-13-7-13 7 3-15L3 18l15-2Z\"/></svg>";
return picture(renderer_.diagram("environment-star-" + theme_ + (active ? "-funded" : "-unfunded"), svg, 96), 46, 46);
};
struct Panel { double x, y, w, h, image_h; };
const std::array<Panel, 6> panels{{
{1912,970,600,623.328125,374.78125}, {1056,1060,500,556.40625,307.859375},
{100,970,600,623.328125,374.78125}, {100,160,600,694.375,460.375},
{1056,0,500,612.171875,378.171875}, {1912,160,600,694.375,460.375}}};
std::string out = "<div class=\"environment-ring\" id=\"environment-ring\">";
const auto &rows = view.at("rows");
int64_t total = 0;
for (const auto &row : rows) total += row.at("cost").get<int64_t>();
page_title_ = "Umfeld – " + money(total, currency) + " pro Monat";
// a card is a third of the page wide; its picture takes the height that is left
const double card_width = (2799 - 2 * 31.5) / 3, picture_width = card_width - 2 * 36 - 4, picture_height = 396;
std::string out = "<div class=\"pg-page\" id=\"environment-ring\"><div class=\"env-grid\">";
for (size_t i = 0; i < rows.size(); ++i) {
const auto &row = rows[i];
const auto &panel = panels[i];
const auto name = row.at("name").get<std::string>(), id = row.at("id").get<std::string>();
const auto level = row.at("level").get<int>();
const auto inner = panel.w - 40;
out += "<section class=\"environment-card " + id + "\" style=\"" + rect(panel.x, panel.y, panel.w, panel.h) +
"\" aria-labelledby=\"environment-title-" + std::to_string(i) + "\"><h2 id=\"environment-title-" +
std::to_string(i) + "\">" + esc(name) + "</h2><div class=\"environment-stars\" role=\"group\" aria-label=\"" +
esc(name + " Budget") + "\">";
out += "<section class=\"pg-panel pg-col env-card " + id + "\" style=\"width:" + scalar(card_width) + "dp;\" aria-labelledby=\"environment-title-" + std::to_string(i) +
"\"><div class=\"pg-row\" style=\"justify-content:space-between;\"><h2 class=\"pg-h\" id=\"environment-title-" + std::to_string(i) + "\">" + esc(name) + "</h2>" +
(i < 3 ? "<span class=\"pg-tag sage environment-standing\" title=\"Tabellenplatz der Jugendmannschaft\">Platz " + std::to_string(row.at("rank").get<int>()) + " · " + std::to_string(row.at("league").get<int>()) + ". Liga</span>" : std::string()) +
"</div><div class=\"env-stars\" role=\"group\" aria-label=\"" + esc(name + " Budget") + "\">";
for (int value = 0; value <= 6; ++value) {
const bool selected = value == level;
const auto label = value ? "<span class=\"environment-level-icon\">" + star(value <= level) + "</span>"
: std::string("<span class=\"environment-zero-label\">×</span>");
out += btn("environment-level", label + (selected ? "<span class=\"environment-selection-line\"></span>" : ""),
"environment-level " + std::string(value == 0 ? "zero " : "") + (selected ? "selected" : ""),
"id=\"environment-level-" + std::to_string(i) + "-" + std::to_string(value) +
"\" data-index=\"" + std::to_string(i) + "\" data-id=\"" + std::to_string(value) +
"\" aria-pressed=\"" + (selected ? "true" : "false") + "\" aria-label=\"" +
esc(name + ": " + std::to_string(value) + (value == 1 ? " Stern" : " Sterne")) +
out += btn("environment-level", value ? star(value <= level) : std::string("<span class=\"env-zero\">×</span>"),
"env-level " + std::string(value == 0 ? "zero " : "") + (selected ? "selected" : ""),
"id=\"environment-level-" + std::to_string(i) + "-" + std::to_string(value) + "\" data-index=\"" + std::to_string(i) + "\" data-id=\"" + std::to_string(value) +
"\" aria-pressed=\"" + (selected ? "true" : "false") + "\" aria-label=\"" + esc(name + ": " + std::to_string(value) + (value == 1 ? " Stern" : " Sterne")) +
"\" " + std::string(engine_mode_ && value > row.at("max").get<int>() ? "disabled " : "") + "title=\"" + (value ? std::to_string(value) + (value == 1 ? " Stern" : " Sterne") : "Budget auf null setzen") + "\"");
}
out += "</div><div class=\"environment-picture\" style=\"" + rect(18, 138, inner, panel.image_h) + "\">" +
img("environment." + row.at("image").get<std::string>() + "." + std::to_string(row.at("cell").get<int>()),
inner, panel.image_h, false, false, 1024) +
"</div><div class=\"environment-caption\" style=\"top:" + scalar(152 + panel.image_h) + "dp;height:" +
scalar(i < 3 ? 74.546875 : 60) + "dp;\"><span class=\"environment-cost\" id=\"environment-cost-" + std::to_string(i) +
"\" aria-label=\"" + esc(name + " Monatskosten") + "\">" +
esc(money(row.at("cost").get<int64_t>(), engine_mode_ ? Json{{"code", "EUR"}, {"minor_units", 2}} : snapshot.world->manifest().value("currency", Json::object())) + " / Monat") + "</span>";
if (i < 3)
out += "<span class=\"environment-standing\">" + std::to_string(row.at("rank").get<int>()) + ". / " +
std::to_string(row.at("league").get<int>()) + ". Liga</span>";
out += "</div></section>";
out += "</div><div class=\"env-picture\" style=\"height:" + scalar(picture_height) + "dp;\">" +
img("environment." + row.at("image").get<std::string>() + "." + std::to_string(row.at("cell").get<int>()), picture_width, picture_height, false, true, 1024) +
"</div><div class=\"pg-row\" style=\"justify-content:space-between;\"><span class=\"pg-mut\">Monatskosten</span><strong class=\"pg-num environment-cost\" id=\"environment-cost-" + std::to_string(i) +
"\" aria-label=\"" + esc(name + " Monatskosten") + "\">" + esc(money(row.at("cost").get<int64_t>(), currency) + " / Monat") + "</strong></div></section>";
}
out += "<div class=\"environment-emblem\"><div class=\"environment-ball\">" +
img("art.environment-ball-v1.png", 400, 400, false, false, 640) + "</div>";
const bool demo_manager = !engine_mode_ && snapshot.state.at("managers").is_array() && !snapshot.state.at("managers").empty();
const auto managed = engine_mode_ ? engine_data_.at("desktop").at("meta").at("scope").at("teamId").get<std::string>() : demo_manager ? demo_career_manager(snapshot.state).value("club", "") : "";
const auto *club = snapshot.world->find("clubs", managed);
out += "<div class=\"environment-crest\" aria-label=\"" + esc(club ? snapshot.world->name(*club) : "Vereinswappen nicht verfügbar") + "\">" +
(club ? img(club->value("crest", ""), 162, 162, true) : "<span>—</span>") + "</div></div></div>";
return out;
return out + "</div><nav class=\"pg-foot\">" + pg_status(engine_mode_ && engine_busy_ ? engine_operation_ : engine_mode_ && !engine_notice_.empty() ? engine_notice_ : std::string("Eine Stufe anklicken, um das Monatsbudget zu ändern.")) + "</nav></div>";
}
+45 -47
View File
@@ -1,25 +1,30 @@
// SPDX-License-Identifier: GPL-3.0-only
// The balance sheet as a page of the notebook: the season's sums as figures, income against
// costs as one bar, then every position with its share of its side. "Zukunft" plans the
// coming year's costs; the simulation is a what-if calculation of its own.
std::string App::render_balance() {
const auto rows = balance_rows();
if (!rows.value("ok", false)) throw editor::Error("Die Bilanzdaten sind ungültig.");
std::string out = "<div class=\"balance-native\">";
if (balance_sim_) out += render_balance_simulation();
else if (balance_future_) {
out += "<section class=\"balance-plan\"><h2>Ausgabenplanung</h2><div class=\"balance-plan-rows\">";
std::string out = "<div class=\"pg-page balance-native\">", status;
if (balance_sim_) {
out += render_balance_simulation();
status = "Reine Rechnung – nichts wird gespeichert.";
} else if (balance_future_) {
out += "<div class=\"pg-body\"><section class=\"pg-panel pg-col pg-grow\" style=\"" + pg_css("gap:4px;") + "\"><h2 class=\"pg-h\">Ausgabenplanung</h2><span class=\"pg-mut\" style=\"display:block;margin-bottom:" + pg(6) +
";\">Geplante Ausgaben für die nächsten zwölf Monate. Ein Betrag öffnet das Zahlenfeld.</span><div class=\"pg-tbody\">";
int i = 0;
for (const auto &row : rows.at("plan")) {
const auto name = row.at("name").get<std::string>();
out += "<div class=\"balance-plan-row\"><span>" + esc(name) + "</span>" +
btn("balance-plan", esc(number(row.at("amount").get<int64_t>() / (engine_mode_?100:finance_currency_factor(*world_)))),
"balance-plan-value amount-trigger", "id=\"balance-plan-" + std::to_string(i) +
"\" data-id=\"" + std::to_string(i) + "\" aria-label=\"" + esc(name + " in " + (engine_mode_?"Euro":money_unit() == "€" ? "Euro" : money_unit())) + "\" " + std::string(engine_mode_&&row.at("editable")!=true?"disabled":"")) + "</div>";
out += "<div class=\"pg-tr\" style=\"height:" + pg(44) + ";justify-content:space-between;\"><span style=\"display:block;font-size:" + pg(15) + ";\">" + esc(name) + "</span>" +
pg_button("balance-plan", esc(number(row.at("amount").get<int64_t>() / (engine_mode_?100:finance_currency_factor(*world_)))) + " " + esc(engine_mode_ ? "€" : money_unit()),
"amount-trigger", "id=\"balance-plan-" + std::to_string(i) + "\" data-id=\"" + std::to_string(i) + "\" aria-label=\"" + esc(name + " in " + (engine_mode_?"Euro":money_unit() == "€" ? "Euro" : money_unit())) + "\" " +
std::string(engine_mode_&&row.at("editable")!=true?"disabled":"")) + "</div>";
++i;
}
out += "</div></section><p class=\"balance-plan-total\"><span>Geplante Ausgaben</span><span>" +
esc(balance_cash(rows.at("plan_total").get<int64_t>())) + "</span></p>";
out += "</div></section><div class=\"pg-col\" style=\"width:" + pg(400) + ";\"><div style=\"display:flex;\">" + pg_stat("Geplante Ausgaben", esc(balance_cash(rows.at("plan_total").get<int64_t>())), "Summe für zwölf Monate") +
"</div><div style=\"display:flex;\">" + pg_stat("Kontostand", esc(balance_cash(rows.at("cash").get<int64_t>())), "heute") + "</div></div></div>";
status = "Planung für zwölf Monate.";
} else {
// the season's money at a glance: the sums as numerals, then every position with its
// share of its side as a bar
int64_t sums[2] = {0, 0};
{
int side = 0;
@@ -29,50 +34,43 @@ std::string App::render_balance() {
}
}
const int64_t net = rows.at("balance").get<int64_t>();
const std::array<std::array<std::string, 3>, 5> tiles{{
{balance_cash(sums[0]), "Einnahmen", ""}, {balance_cash(sums[1]), "Ausgaben", ""},
{balance_cash(net), "Saldo der Saison", net < 0 ? "loss" : "gain"},
{balance_cash(rows.at("cash").get<int64_t>()), "Kontostand", ""},
{number(rows.at("attendance_average").get<int64_t>()), "Zuschauerschnitt",
""}}};
for (size_t i = 0; i < tiles.size(); ++i)
out += "<div class=\"balance-tile " + tiles[i][2] + "\" style=\"" + rect(double(i) * 526.4, 0, 506.4, 200) + "\"><strong>" + esc(tiles[i][0]) + "</strong><span>" + tiles[i][1] + "</span></div>";
out += "<div class=\"pg-row\" style=\"" + pg_css("gap:8px;align-items:stretch;") + "\">" + pg_stat("Einnahmen", esc(balance_cash(sums[0]))) + pg_stat("Ausgaben", esc(balance_cash(sums[1]))) +
pg_stat("Saldo der Saison", "<span class=\"" + std::string(net < 0 ? "balance-loss" : "balance-gain") + "\">" + esc(balance_cash(net)) + "</span>") + pg_stat("Kontostand", esc(balance_cash(rows.at("cash").get<int64_t>()))) +
pg_stat("Zuschauerschnitt", esc(number(rows.at("attendance_average").get<int64_t>())), "je Heimspiel") + "</div>";
// income against costs as one bar
const double whole = double(std::max<int64_t>(1, sums[0] + sums[1]));
out += "<div class=\"balance-scale\"><div class=\"in\" style=\"width:" + scalar(sums[0] * 100.0 / whole) + "%;\"><span>Einnahmen " + scalar(std::round(sums[0] * 1000.0 / whole) / 10) +
" %</span></div><div class=\"out\" style=\"width:" + scalar(sums[1] * 100.0 / whole) + "%;\"><span>Ausgaben " + scalar(std::round(sums[1] * 1000.0 / whole) / 10) + " %</span></div></div>";
out += "<div class=\"balance-scale\"><div class=\"in\" style=\"width:" + scalar(sums[0] * 100.0 / whole) + "%;\"><span>Einnahmen " + scalar(std::round(sums[0] * 100.0 / whole)) +
" %</span></div><div class=\"out\" style=\"width:" + scalar(sums[1] * 100.0 / whole) + "%;\"><span>Ausgaben " + scalar(std::round(sums[1] * 100.0 / whole)) + " %</span></div></div><div class=\"pg-body\">";
int index = 0;
for (const auto &kind : {std::string("income"), std::string("costs")}) {
const int64_t sum = std::max<int64_t>(1, sums[index]);
out += "<section class=\"balance-panel " + kind + "\" style=\"left:" + std::to_string(index++ * 1322) +
"dp;\"><h2>" + (kind == "income" ? "Einnahmen" : "Ausgaben") + "</h2><div class=\"balance-table\">";
// the rows share the panel's height
const double row_height = std::min(170.0, 1206.0 / double(std::max<size_t>(1, rows.at(kind).size())));
out += "<section class=\"pg-panel pg-col pg-grow " + kind + "\" style=\"" + pg_css("gap:4px;padding:10px 14px;") + "\"><div class=\"pg-row\" style=\"justify-content:space-between;\"><h2 class=\"pg-h\">" +
(kind == "income" ? "Einnahmen" : "Ausgaben") + "</h2><strong class=\"pg-h\">" + esc(balance_cash(sums[index])) + "</strong></div>";
for (const auto &row : rows.at(kind)) {
const int64_t amount = row.at("amount").get<int64_t>();
const double part = std::clamp(double(std::max<int64_t>(0, amount)) * 100.0 / double(sum), 0.0, 100.0);
out += "<div class=\"balance-row" + std::string(amount ? "" : " none") + "\" style=\"height:" + scalar(row_height) + "dp;\"><span class=\"name\">" + esc(row.at("name").get<std::string>()) +
"</span><div class=\"balance-bar\"><div style=\"width:" + scalar(part) + "%;\"></div></div><span class=\"share\">" + (amount ? scalar(std::round(part)) + " %" : std::string()) +
"</span><span class=\"sum\">" + esc(balance_cash(amount)) + "</span></div>";
out += "<div class=\"pg-row balance-row" + std::string(amount ? "" : " none") + "\" style=\"" + pg_css("gap:10px;min-height:30px;") + "\"><span class=\"pg-grow pg-nowrap\" style=\"display:block;\">" + esc(row.at("name").get<std::string>()) +
"</span><span style=\"display:block;flex:none;width:" + pg(110) + ";\">" + pg_bar(part, kind == "income" ? "sage" : "") + "</span><span class=\"pg-mut pg-r\" style=\"display:block;flex:none;width:" + pg(44) + ";\">" +
scalar(std::round(part)) + " %</span><strong class=\"pg-r\" style=\"display:block;flex:none;width:" + pg(150) + ";\">" + esc(balance_cash(amount)) + "</strong></div>";
}
out += "</div></section>";
out += "</section>";
++index;
}
out += "<p class=\"balance-games\">" + esc(number(rows.at("league_home_games").get<int64_t>()) + " Liga-Heimspiele · " + number(rows.at("other_home_games").get<int64_t>()) +
" sonstige Heimspiele · Eintrittspreis " + balance_cash(rows.at("ticket").get<int64_t>())) + "</p>";
const std::array<std::string, 6> values = {
number(rows.at("league_home_games").get<int64_t>()) + " Liga-Heimspiele",
number(rows.at("other_home_games").get<int64_t>()) + " sonstige Heimspiele",
"Zuschauerschnitt: " + number(rows.at("attendance_average").get<int64_t>()),
"Eintrittspreis: " + balance_cash(rows.at("ticket").get<int64_t>()),
"Kontostand: " + balance_cash(rows.at("cash").get<int64_t>()),
"Saldo: " + balance_cash(rows.at("balance").get<int64_t>())};
for (int i = 0; i < 0; ++i)
out += "<p class=\"balance-summary-item" + std::string(i == 5 ? " balance-net" : "") + (engine_mode_&&(i==4||i==5)?" "+money_classes(rows.at(i==4?"cash":"balance").get<int64_t>()):std::string()) + "\" style=\"" +
rect(26 + (i % 2) * 1310, 1526 + (i / 2) * 68, 1250, 38) + "\">" + esc(values[size_t(i)]) + "</p>";
out += "</div><span class=\"pg-mut\" style=\"display:block;flex:none;\">" + esc(number(rows.at("league_home_games").get<int64_t>()) + " Liga-Heimspiele · " + number(rows.at("other_home_games").get<int64_t>()) +
" sonstige Heimspiele · Eintrittspreis " + balance_cash(rows.at("ticket").get<int64_t>())) + "</span>";
status = "Gebuchte Saisonwerte.";
}
out += btn("balance-sim", balance_sim_ ? "Zurück zur Bilanz" : "Simulation", "balance-sim-button report-reset", "id=\"balance-sim\"");
if (!balance_sim_) out += btn("balance-toggle", "<span>" + std::string(balance_future_ ? "Zukunft" : "Aktuell") +
"</span><span class=\"balance-cycle\" aria-hidden=\"true\"><span class=\"cycle-line cycle-top\"></span><span class=\"cycle-line cycle-bottom\"></span><span class=\"cycle-head cycle-right\"></span><span class=\"cycle-head cycle-left\"></span></span>", "balance-toggle report-reset",
"id=\"balance-toggle\" aria-label=\"Zwischen aktueller Bilanz und Zukunftsplanung wechseln\"");
return out + (engine_mode_?"<p id=\"balance-engine-feedback\" style=\"position:absolute;left:0;right:0;bottom:106dp;font-size:28dp;line-height:28dp;\">"+esc(engine_busy_?engine_operation_:engine_balance_feedback_)+"</p>":"") + "</div>";
// the foot: the two views, the simulation, what the engine last said
out += "<nav class=\"pg-foot\">";
if (!balance_sim_)
// the view that is shown is marked; the other one switches
for (int view = 0; view < 2; ++view) {
const bool shown = (view == 1) == balance_future_;
out += std::string(view ? "" : "<div class=\"pg-seg\">") + btn("balance-toggle", "<span>" + std::string(view ? "Zukunft" : "Aktuell") + "</span>", std::string(view ? "" : "first ") + (shown ? "on" : ""),
shown ? std::string("style=\"pointer-events:none;\" aria-pressed=\"true\"") : std::string("id=\"balance-toggle\" aria-pressed=\"false\" aria-label=\"Zwischen aktueller Bilanz und Zukunftsplanung wechseln\"")) + (view ? "</div>" : "");
}
out += pg_button("balance-sim", balance_sim_ ? "Zurück zur Bilanz" : "Simulation", balance_sim_ ? "primary" : "", "id=\"balance-sim\"") + "<span class=\"pg-sp\"></span>";
if (engine_mode_) out += "<span class=\"pg-status\" id=\"balance-engine-feedback\">" + esc(engine_busy_ ? engine_operation_ : !engine_balance_feedback_.empty() ? engine_balance_feedback_ : status) + "</span>";
else out += pg_status(status);
return out + "</nav></div>";
}
+13 -10
View File
@@ -24,8 +24,10 @@ std::string App::balance_simulation_result() {
{euro(cost_per_match), "Kosten je Heimspiel bisher", ""},
{euro(then), "Ergebnis je Heimspiel", then < 0 ? "loss" : "gain"},
{euro(cash + then * matches), "Kontostand nach " + std::to_string(matches) + " Heimspielen", cash + then * matches < 0 ? "loss" : ""}}};
out += "<div class=\"pg-row\" style=\"" + pg_css("gap:8px;align-items:stretch;") + "\">";
for (size_t i = 0; i < tiles.size(); ++i)
out += "<div class=\"balance-tile " + tiles[i][2] + "\" style=\"" + rect(double(i) * 658, 0, 638, 200) + "\"><strong>" + tiles[i][0] + "</strong><span>" + tiles[i][1] + "</span></div>";
out += pg_stat(tiles[i][1], "<span class=\"" + std::string(tiles[i][2] == "loss" ? "balance-loss" : tiles[i][2] == "gain" ? "balance-gain" : "") + "\">" + tiles[i][0] + "</span>");
out += "</div>";
// the cash after each home match: as booked so far, and with the sliders' values
const double base = cash;
(void)base;
@@ -34,7 +36,7 @@ std::string App::balance_simulation_result() {
const auto px = [&](double match) { return 250 + match * 2290.0 / matches; };
const auto py = [&](double value) { return 760 - (value - floor) / (ceiling - floor) * 720; };
const double zero = 0;
const std::string line = theme_ == "silver" ? "#25617a" : "#9ac7d8", gold = theme_ == "silver" ? "#9a7a3a" : "#d9bd7c", ink = theme_ == "silver" ? "#3d362a" : "#d5dde3",
const std::string line = theme_ == "silver" ? "#8c491a" : theme_ == "matchday" ? "#2f602c" : "#ebb87f", gold = theme_ == "silver" ? "#82796a" : theme_ == "matchday" ? "#6d7f5b" : "#8f95a1", ink = theme_ == "silver" ? "#474238" : theme_ == "matchday" ? "#3a4830" : "#d2d6dc",
faint = theme_ == "silver" ? "#4a433430" : "#dfeaf530";
std::string svg = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 2580 840\"><defs><linearGradient id=\"under\" x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\"><stop offset=\"0\" stop-color=\"" + line +
"\" stop-opacity=\".28\"/><stop offset=\"1\" stop-color=\"" + line + "\" stop-opacity=\".03\"/></linearGradient></defs>";
@@ -46,17 +48,18 @@ std::string App::balance_simulation_result() {
svg += "<line x1=\"250\" y1=\"" + scalar(py(0)) + "\" x2=\"2540\" y2=\"" + scalar(py(0)) + "\" stroke=\"" + ink + "\" stroke-width=\"3\"/>";
for (int match = 0; match <= matches; match += std::max(1, matches / 8))
svg += "<text x=\"" + scalar(px(match)) + "\" y=\"815\" text-anchor=\"middle\" fill=\"" + ink + "\" font-size=\"30\" font-family=\"Arial, Liberation Sans, sans-serif\">" + (match ? std::to_string(match) + "." : std::string("heute")) + "</text>";
const std::string tone = then >= 0 ? "#3f8a63" : "#b24a4f";
const std::string tone = line;
svg += "<polygon points=\"" + scalar(px(0)) + "," + scalar(py(zero)) + " " + scalar(px(matches)) + "," + scalar(py(then * matches)) + " " + scalar(px(matches)) + "," + scalar(py(zero)) +
"\" fill=\"" + tone + "\" fill-opacity=\".22\"/><line x1=\"" + scalar(px(0)) + "\" y1=\"" + scalar(py(zero)) + "\" x2=\"" + scalar(px(matches)) + "\" y2=\"" + scalar(py(now * matches)) + "\" stroke=\"" + gold +
"\" stroke-width=\"6\" stroke-dasharray=\"18 14\"/><line x1=\"" + scalar(px(0)) + "\" y1=\"" + scalar(py(zero)) + "\" x2=\"" + scalar(px(matches)) + "\" y2=\"" + scalar(py(then * matches)) + "\" stroke=\"" + line +
"\" stroke-width=\"9\" stroke-linecap=\"round\"/><circle cx=\"" + scalar(px(matches)) + "\" cy=\"" + scalar(py(then * matches)) + "\" r=\"14\" fill=\"" + line + "\"/></svg>";
out += "<div class=\"balance-sim-graph\">" + picture(renderer_.diagram("balance-simulation", svg, 2580), 2580, 840) + "</div><div class=\"balance-sim-legend\"><span class=\"key sim\"></span><span>Veränderung des Kontostands mit diesen Werten</span>"
"<span class=\"key now\"></span><span>wie bisher (" + euro(ticket) + ", " + number(int64_t(crowd)) + " Zuschauer)</span></div>";
out += "<div class=\"pg-panel pg-col pg-grow\" style=\"" + pg_css("gap:4px;padding:10px 14px;") + "\"><div class=\"pg-row\" style=\"justify-content:space-between;\">" + pg_kicker("Veränderung des Kontostands") +
"<span class=\"pg-legend\"><span class=\"pg-legend-item\"><span class=\"pg-legend-mark\" style=\"height:9dp;background-color:" + line + ";\"></span><span>mit diesen Werten</span></span><span class=\"pg-legend-item\"><span class=\"pg-legend-mark\" style=\"height:9dp;background-color:" +
gold + ";\"></span><span>wie bisher (" + euro(ticket) + ", " + number(int64_t(crowd)) + " Zuschauer)</span></span></span></div><div class=\"balance-sim-graph\">" + picture(renderer_.diagram("balance-simulation-" + theme_, svg, 2580), 2420, 788) + "</div></div>";
const double even = balance_sim_price_ > 0 ? (cost_per_match - other_per_match) / balance_sim_price_ : 0;
out += "<p class=\"balance-sim-reading\">" + std::string(then >= 0 ? "Mit diesen Werten trägt sich jedes Heimspiel. " : "Mit diesen Werten kostet jedes Heimspiel Geld. ") +
out += "<div class=\"pg-surf\" style=\"flex:none;font-size:" + pg(15) + ";line-height:" + pg(21) + ";\">" + std::string(then >= 0 ? "Mit diesen Werten trägt sich jedes Heimspiel. " : "Mit diesen Werten kostet jedes Heimspiel Geld. ") +
(even > 0 ? "Bei " + euro(balance_sim_price_) + " Eintritt deckt ein Schnitt von " + number(int64_t(std::ceil(even))) + " Zuschauern die bisherigen Kosten je Heimspiel." : std::string("Die übrigen Einnahmen decken die Kosten bereits.")) +
" Wie viele Zuschauer bei einem Preis wirklich kommen, entscheidet das Spiel.</p>";
" Wie viele Zuschauer bei einem Preis wirklich kommen, entscheidet das Spiel.</div>";
return out;
}
std::string App::render_balance_simulation() {
@@ -68,14 +71,14 @@ std::string App::render_balance_simulation() {
balance_sim_matches_ = 17;
}
const auto slider = [&](const char *id, const char *label, int min, int max, int step, int value, const std::string &text) {
return "<div class=\"balance-sim-control\"><div class=\"balance-sim-label\"><span>" + std::string(label) + "</span><strong id=\"" + id + "-value\">" + text + "</strong></div><input id=\"" + id +
return "<div class=\"pg-panel pg-grow balance-sim-control\" style=\"" + pg_css("padding:10px 16px;") + "\"><div class=\"pg-row\" style=\"justify-content:space-between;\"><span>" + std::string(label) + "</span><strong class=\"pg-num\" id=\"" + id + "-value\">" + text + "</strong></div><input id=\"" + id +
"\" type=\"range\" min=\"" + std::to_string(min) + "\" max=\"" + std::to_string(max) + "\" step=\"" + std::to_string(step) + "\" value=\"" + std::to_string(value) + "\" aria-label=\"" + label + "\"/></div>";
};
return "<div class=\"balance-sim\"><div class=\"balance-sim-controls\">" +
return "<div class=\"pg-row\" style=\"" + pg_css("gap:8px;") + "\">" +
slider("balance-sim-price", "Eintrittspreis", 5, 60, 1, balance_sim_price_, std::to_string(balance_sim_price_) + " €") +
slider("balance-sim-crowd", "Zuschauerschnitt", 1000, 100000, 500, balance_sim_crowd_, number(balance_sim_crowd_)) +
slider("balance-sim-matches", "Heimspiele voraus", 1, 34, 1, balance_sim_matches_, std::to_string(balance_sim_matches_)) +
"</div><div id=\"balance-sim-out\" class=\"balance-sim-out\">" + balance_simulation_result() + "</div></div>";
"</div><div id=\"balance-sim-out\" class=\"pg-col pg-grow\">" + balance_simulation_result() + "</div>";
}
bool App::balance_simulation_event(Rml::Event &event) {
if (menu_ != "balance" || !balance_sim_ || !popup_.empty()) return false;
+5 -2
View File
@@ -5,7 +5,7 @@
// The menus that are laid out as a page of the notebook. Every other career menu is still a
// sheet of the old format, shown scaled inside the book.
bool App::page_native() const {
static const std::set<std::string> native{"tables", "league", "other", "strengths", "fairplay", "indoor", "scorers"};
static const std::set<std::string> native{"balance", "contracts", "environment", "tables", "league", "other", "strengths", "fairplay", "indoor", "scorers"};
return notebook_page() && native.contains(menu_);
}
@@ -55,7 +55,10 @@ std::string App::pg_form(const std::string &marks) {
}
std::string App::pg_status(const std::string &text) { return text.empty() ? std::string() : "<span class=\"pg-status\">" + esc(text) + "</span>"; }
std::string App::pg_button(const std::string &action, const std::string &label, const std::string &css, const std::string &attrs) {
return btn(action, label, "pg-btn " + css, attrs);
// "primary" is the page's own filled button, not the one of the old windows
std::string classes = css;
if (const auto at = classes.find("primary"); at != std::string::npos) classes.replace(at, 7, "pg-go");
return btn(action, label, "pg-btn " + classes, attrs);
}
// A cell of a table head (a button when the column sorts) and of a row; a width of 0 takes
// the room that is left. `align` is "", "r" or "c".