Files
Dreierpack-Manager/src/modern/ui/advertising_screens.inc
T
MichaelandClaude Fable 5.2 e14b2f2374 Advertising with a larger ground and three pictures of 4:3; a note on the investments
The ground with its boards takes the width of the page, shirt, television and
the stadium's name stand beside it under one another, and the forecast is one
line. The investments show how far each budget is used and a pencilled note of
what the figures say.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-15 23:34:32 +01:00

238 lines
25 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 {
// Where the fourteen boards stand around the pitch, in units of the page: five along the far
// side, two at each end, five along the near side, numbered clockwise from the upper left.
struct AdBoard { double x, y, w, h; int turn; }; // turn: 0 flat, 1 right end, -1 left end
constexpr double ad_ground_w = 960, ad_ground_h = 668, ad_board_deep = 66;
AdBoard ad_board(int index) {
constexpr double first = ad_board_deep + 14, gap = 6, long_w = (ad_ground_w - 2 * first - 4 * gap) / 5, step = long_w + gap;
constexpr double end_top = ad_board_deep + 26, end_gap = 20, tall = (ad_ground_h - 2 * end_top - end_gap) / 2;
if (index < 5) return {first + index * step, 0, long_w, ad_board_deep, 0};
if (index < 7) return {ad_ground_w - ad_board_deep, end_top + (index - 5) * (tall + end_gap), ad_board_deep, tall, 1};
if (index < 12) return {first + (11 - index) * step, ad_ground_h - ad_board_deep, long_w, ad_board_deep, 0};
return {0, end_top + (13 - index) * (tall + end_gap), ad_board_deep, tall, -1};
}
// The ground seen from above: the apron with its track, the mown pitch with all its lines,
// goals, benches and corner flags, and around it the frames of the fourteen boards: lit where
// a sponsor has signed, an empty frame where the place is free.
std::string ad_ground_svg(const std::array<bool, 14> &taken, int chosen) {
const auto n = [](double v) { return scalar(std::round(v * 10) / 10); };
constexpr double W = ad_ground_w, H = ad_ground_h, D = ad_board_deep;
const auto frame = [&](double inset, double radius, const std::string &more) {
return "<rect x=\"" + n(D + inset) + "\" y=\"" + n(D + inset) + "\" width=\"" + n(W - 2 * (D + inset)) + "\" height=\"" + n(H - 2 * (D + inset)) + "\" rx=\"" + n(radius) + "\" " + more + "/>";
};
std::string svg = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 " + n(W) + " " + n(H) + "\"><defs><linearGradient id=\"lit\" x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\"><stop offset=\"0\" stop-color=\"#fffaf0\"/><stop offset=\"1\" stop-color=\"#f1e6d0\"/></linearGradient></defs>";
// apron, running track with its lanes, the grass around the pitch
svg += frame(0, 46, "fill=\"#d9c9a4\"") + frame(8, 40, "fill=\"#c98a5e\"");
for (int lane = 0; lane < 4; ++lane) svg += frame(12.5 + lane * 4.6, 36 - lane * 3.4, "fill=\"none\" stroke=\"#f6e3d2\" stroke-opacity=\".55\" stroke-width=\".9\"");
svg += frame(31, 22, "fill=\"#8fb271\"");
// the pitch: thirteen mown stripes
constexpr double px = D + 48, py = D + 46, pw = W - 2 * px, ph = H - 2 * py;
constexpr int stripes = 13;
for (int stripe = 0; stripe < stripes; ++stripe)
svg += "<rect x=\"" + n(px + stripe * pw / stripes) + "\" y=\"" + n(py) + "\" width=\"" + n(pw / stripes + .4) + "\" height=\"" + n(ph) + "\" fill=\"" + (stripe % 2 ? "#a3c182" : "#b2cd92") + "\"/>";
// lengths on the pitch in metres: it is 105 long
const double m = pw / 105, cx = px + pw / 2, cy = py + ph / 2;
svg += "<g fill=\"none\" stroke=\"#fdfbf4\" stroke-width=\"2.4\" stroke-linejoin=\"round\"><rect x=\"" + n(px) + "\" y=\"" + n(py) + "\" width=\"" + n(pw) + "\" height=\"" + n(ph) + "\"/><path d=\"M" + n(cx) + " " + n(py) + "V" + n(py + ph) + "\"/><circle cx=\"" + n(cx) + "\" cy=\"" + n(cy) + "\" r=\"" + n(9.15 * m) + "\"/>";
for (const int side : {-1, 1}) {
const double edge = side < 0 ? px : px + pw;
// penalty area, goal area, the arc at the area, the corner arcs
svg += "<path d=\"M" + n(edge) + " " + n(cy - 20.16 * m) + "h" + n(-side * 16.5 * m) + "v" + n(40.32 * m) + "h" + n(side * 16.5 * m) + "\"/><path d=\"M" + n(edge) + " " + n(cy - 9.16 * m) + "h" + n(-side * 5.5 * m) + "v" + n(18.32 * m) + "h" + n(side * 5.5 * m) + "\"/>";
svg += "<path d=\"M" + n(edge - side * 16.5 * m) + " " + n(cy - 7.3 * m) + "A" + n(9.15 * m) + " " + n(9.15 * m) + " 0 0 " + (side < 0 ? "1" : "0") + " " + n(edge - side * 16.5 * m) + " " + n(cy + 7.3 * m) + "\"/>";
svg += "<path d=\"M" + n(edge) + " " + n(py + 9) + "A9 9 0 0 " + (side < 0 ? "0" : "1") + " " + n(edge - side * 9) + " " + n(py) + "\"/><path d=\"M" + n(edge) + " " + n(py + ph - 9) + "A9 9 0 0 " + (side < 0 ? "1" : "0") + " " + n(edge - side * 9) + " " + n(py + ph) + "\"/>";
}
svg += "</g><g fill=\"#fdfbf4\"><circle cx=\"" + n(cx) + "\" cy=\"" + n(cy) + "\" r=\"3.2\"/><circle cx=\"" + n(px + 11 * m) + "\" cy=\"" + n(cy) + "\" r=\"2.8\"/><circle cx=\"" + n(px + pw - 11 * m) + "\" cy=\"" + n(cy) + "\" r=\"2.8\"/></g>";
for (const int side : {-1, 1}) {
const double edge = side < 0 ? px : px + pw, back = edge + side * 14, half = 3.66 * m + 4;
// the goal with its net, and the flags in the corners
svg += "<path d=\"M" + n(edge) + " " + n(cy - half) + "H" + n(back) + "V" + n(cy + half) + "H" + n(edge) + "\" fill=\"#ffffff\" fill-opacity=\".5\" stroke=\"#fdfbf4\" stroke-width=\"2.2\"/>";
for (int k = 1; k < 6; ++k) svg += "<path d=\"M" + n(edge) + " " + n(cy - half + k * half / 3) + "H" + n(back) + "\" stroke=\"#fdfbf4\" stroke-opacity=\".7\" stroke-width=\".7\"/>";
svg += "<path d=\"M" + n(edge + side * 7) + " " + n(cy - half) + "V" + n(cy + half) + "\" stroke=\"#fdfbf4\" stroke-opacity=\".7\" stroke-width=\".7\"/>";
for (const double flag_y : {py, py + ph})
svg += "<path d=\"M" + n(edge) + " " + n(flag_y) + "v-10\" stroke=\"#3a332b\" stroke-width=\"1.3\"/><path d=\"M" + n(edge) + " " + n(flag_y - 10) + "l" + n(side * -8) + " 3l" + n(side * 8) + " 3z\" fill=\"#c8733c\"/>";
}
// the two benches on the far side with their glass roofs, and the coaches' zones before them
for (const double bench : {cx - 118, cx + 46}) {
svg += "<rect x=\"" + n(bench - 6) + "\" y=\"" + n(py - 4) + "\" width=\"84\" height=\"4\" fill=\"none\" stroke=\"#fdfbf4\" stroke-opacity=\".8\" stroke-width=\"1\" stroke-dasharray=\"4 3\"/>";
svg += "<rect x=\"" + n(bench) + "\" y=\"" + n(py - 17) + "\" width=\"72\" height=\"11\" rx=\"3.5\" fill=\"#f3ede0\" stroke=\"#3a332b\" stroke-opacity=\".5\" stroke-width=\".8\"/><rect x=\"" + n(bench + 3) + "\" y=\"" + n(py - 15) + "\" width=\"66\" height=\"4.5\" rx=\"2\" fill=\"#bfe0ea\"/>";
for (int seat = 0; seat < 8; ++seat) svg += "<circle cx=\"" + n(bench + 8 + seat * 8) + "\" cy=\"" + n(py - 8.6) + "\" r=\"1.5\" fill=\"#8c491a\" fill-opacity=\".6\"/>";
}
// the players' tunnel between the benches
svg += "<rect x=\"" + n(cx - 13) + "\" y=\"" + n(D + 31) + "\" width=\"26\" height=\"" + n(py - D - 31) + "\" fill=\"#e6dcc6\" stroke=\"#3a332b\" stroke-opacity=\".35\" stroke-width=\".8\"/>";
// the boards: a shadow towards the pitch, two feet, the frame
for (int i = 0; i < 14; ++i) {
const auto b = ad_board(i);
const bool on = taken[size_t(i)], here = i == chosen;
const double fx = b.x + 4, fy = b.y + 4, fw = b.w - 8, fh = b.h - 8;
svg += "<rect x=\"" + n(fx + 2) + "\" y=\"" + n(fy + 3) + "\" width=\"" + n(fw) + "\" height=\"" + n(fh) + "\" rx=\"9\" fill=\"#2e2b25\" fill-opacity=\".16\"/>";
if (b.turn == 0)
for (const double foot : {fx + 16, fx + fw - 16}) svg += "<rect x=\"" + n(foot - 2) + "\" y=\"" + n(b.y < 100 ? fy + fh - 2 : fy - 5) + "\" width=\"4\" height=\"7\" fill=\"#6f6a60\"/>";
else
for (const double foot : {fy + 18, fy + fh - 18}) svg += "<rect x=\"" + n(b.turn > 0 ? fx - 5 : fx + fw - 2) + "\" y=\"" + n(foot - 2) + "\" width=\"7\" height=\"4\" fill=\"#6f6a60\"/>";
svg += "<rect x=\"" + n(fx) + "\" y=\"" + n(fy) + "\" width=\"" + n(fw) + "\" height=\"" + n(fh) + "\" rx=\"9\" fill=\"" + (on ? "url(#lit)" : "#e6eed6") + "\" stroke=\"" + (here ? "#8c491a" : on ? "#645c50" : "#7c8a66") + "\" stroke-width=\"" + (here ? "3.2" : "1.6") + "\"" +
(on ? "" : " stroke-dasharray=\"6 4\"") + "/>";
// a sponsor's board carries a stripe in the accent along its outer edge
if (on) svg += b.turn == 0 ? "<rect x=\"" + n(fx + 9) + "\" y=\"" + n(b.y < 100 ? fy + 3 : fy + fh - 6) + "\" width=\"" + n(fw - 18) + "\" height=\"3\" rx=\"1.5\" fill=\"#c8733c\"/>"
: "<rect x=\"" + n(b.turn > 0 ? fx + fw - 6 : fx + 3) + "\" y=\"" + n(fy + 9) + "\" width=\"3\" height=\"" + n(fh - 18) + "\" rx=\"1.5\" fill=\"#c8733c\"/>";
}
return svg + "</svg>";
}
// A sponsor's mark where there is no logo: its initials on a rounded square of a colour of its own.
std::string ad_mark(const std::string &name, double size) {
static constexpr std::array<const char *, 6> colours{"#8c491a", "#56633f", "#2b6f8f", "#a8452f", "#6b5a48", "#3d6f5a"};
unsigned sum = 0;
std::string initials;
bool start = true;
for (size_t i = 0; i < name.size(); ++i) {
const auto c = static_cast<unsigned char>(name[i]);
sum += c;
if (c == ' ' || c == '-' || c == '.') { start = true; continue; }
if (start && initials.size() < 2 && c < 128 && std::isalnum(c)) initials += char(std::toupper(c));
start = false;
}
if (initials.empty()) initials = "·";
return "<span class=\"ad-mark\" style=\"width:" + scalar(size) + "dp;height:" + scalar(size) + "dp;line-height:" + scalar(size) + "dp;font-size:" + scalar(size * .42) + "dp;background-color:" + colours[sum % colours.size()] + ";\">" + esc(initials) + "</span>";
}
} // namespace
// Verein > Werbung: the ground with its fourteen boards on the left, the five pictures for
// shirt, television and the three budgets on the right. The pointer on a picture shows what
// stands there today; a click opens the offers as a note, or the number pad of a budget.
std::string App::render_advertising() {
const auto snapshot = engine_mode_ ? Snapshot{input_revision(), world_, Json::object()} : snap();
const auto view = engine_mode_ ? engine_advertising_projection(engine_data_) : demo_advertising_view(snapshot.state, *world_);
const auto ad_cash = [&](int64_t value) { return engine_mode_ ? money(value, {{"code", "EUR"}, {"minor_units", 2}}) : cash(value); };
if (!view.value("ok", false)) return {};
const auto &slots = view.at("slots");
const auto taken_at = [&](int i) { return slots[size_t(i)].at("active") == true; };
std::array<bool, 14> taken{};
int signed_boards = 0;
for (int i = 0; i < 14; ++i) if ((taken[size_t(i)] = taken_at(i))) ++signed_boards;
page_hint_ = std::to_string(signed_boards) + " von 14 Banden vergeben";
// what a contract says today
const auto terms = [&](const Json &slot) {
return std::to_string(slot.value("months", 0)) + (slot.value("months", 0) == 1 ? " Monat" : " Monate") + " · " + ad_cash(slot.value("amount", int64_t(0))) + " / Monat";
};
// The menu has two pages: the contracts with sponsors, and what the club invests itself.
const bool investing = advertising_page_ == "investments";
page_title_ = investing ? "Investitionen" : "Werbung";
const auto forecast = [&] {
std::string row = pg_kicker("Vereinsprognose / Monat") + "<div class=\"pg-row\" style=\"margin-top:" + pg(4) + ";\">";
for (const auto &[label, key] : std::array<std::pair<const char *, const char *>, 3>{{{"Einnahmen", "income"}, {"Ausgaben", "expenses"}, {"Saldo", "balance"}}}) {
const auto value = view.at(key).get<int64_t>();
row += "<div class=\"pg-grow\"><span class=\"pg-mut\" style=\"display:block;\">" + std::string(label) + "</span><strong class=\"pg-h" + std::string(std::string(key) == "balance" ? (value >= 0 ? " ad-plus" : " ad-minus") : "") + "\">" +
esc((std::string(key) == "balance" && value > 0 ? "+ " : "") + ad_cash(value)) + "</strong></div>";
}
return row + "</div>";
};
// A picture one can click: the pointer shows what stands there today. `shape` is "", "wide"
// or "big"; `amount` stands beside the title where the picture is large enough for it.
const auto tile = [&](const std::string &action, const std::string &id, const std::string &attrs, const std::string &art, const std::string &title, const std::string &kicker, const std::string &value, const std::string &detail, bool selected,
const std::string &shape = std::string(), const std::string &amount = std::string()) {
const double w = shape == "big" ? 921 : shape == "four" ? 612 : 520, h = shape == "big" ? 690 : 459;
return btn(action, "<span class=\"ad-tile-art\">" + img(art, w, h, false, true, shape.empty() ? 1100 : 1600) + "</span><span class=\"ad-tile-over\"><span class=\"ad-tile-k\">" + esc(pg_upper(kicker)) + "</span><strong>" + esc(value) + "</strong><span class=\"ad-tile-d\">" + esc(detail) +
"</span></span><span class=\"ad-tile-cap\"><span>" + esc(title) + "</span>" + (amount.empty() ? std::string() : "<strong>" + esc(amount) + "</strong>") + "</span>",
std::string("ad-tile") + (shape.empty() ? "" : " " + shape) + (selected ? " selected" : ""), "id=\"" + id + "\" " + attrs + " aria-label=\"" + esc(title + ": " + value + (detail.empty() ? "" : ", " + detail)) + "\"");
};
// what the game does not know yet is shown, and says so
const std::string soon = "disabled=\"disabled\" aria-disabled=\"true\"";
std::string delivery;
if (const int weeks = view.at("spending")[0].value("delivery_weeks", 0); weeks > 0) delivery = "Fanartikel: Die Lieferung läuft noch " + std::to_string(weeks) + (weeks == 1 ? " Woche." : " Wochen.");
std::string out = "<section class=\"pg-page\" id=\"ad-underlay\"><div class=\"pg-row pg-grow\" style=\"align-items:stretch;\">";
if (investing) {
page_hint_ = "Wohin der Verein sein Geld steckt";
static constexpr std::array<const char *, 3> spending_art{"advertising.scene.merchandise", "advertising.scene.press", "advertising.scene.fans"};
std::string rows, use;
int64_t largest = 0;
for (const auto &row : view.at("spending")) largest = std::max(largest, row.at("amount").get<int64_t>());
out += "<div class=\"ad-tiles wide\">";
for (int i = 0; i < 3; ++i) {
const auto &row = view.at("spending")[size_t(i)];
const bool waiting = i == 0 && !delivery.empty();
const auto amount = ad_cash(row.at("amount").get<int64_t>());
out += tile("ad-spending", "ad-spending-" + std::to_string(i), "data-ad-spending=\"" + std::to_string(i) + "\" data-id=\"" + std::to_string(i) + "\"", spending_art[size_t(i)], row.at("name").get<std::string>(), i == 0 ? "Bestellung" : "Monatsbudget", amount,
waiting ? "Die Lieferung läuft noch" : "Anklicken zum Ändern", false, "big", amount);
rows += "<div class=\"pg-kv\"><span>" + esc(row.at("name").get<std::string>()) + "</span><strong>" + esc(amount) + (i == 0 ? "" : " / Monat") + "</strong></div>";
// how much of what the budget may hold is used; without a limit the largest budget is the measure
const auto value = row.at("amount").get<int64_t>(), limit = row.value("max", int64_t(0));
const double share = limit > 0 ? double(value) * 100 / double(limit) : largest > 0 ? double(value) * 100 / double(largest) : 0;
use += "<div class=\"ad-use\"><div class=\"pg-row\" style=\"justify-content:space-between;\"><span>" + esc(row.at("name").get<std::string>()) + "</span><span class=\"pg-mut\">" +
esc(limit > 0 ? std::to_string(int(std::lround(share))) + " % von " + ad_cash(limit) : amount) + "</span></div>" + pg_bar(share, i == 0 ? "soft" : i == 1 ? "accent" : "sage") + "</div>";
}
out += tile("ad-soon", "ad-spending-international", soon, "investment.scene.international", "Internationale Vermarktung", "Neu", "Noch nicht im Spiel", "Diese Investition folgt", false, "big", "—") + "</div><div class=\"pg-col pg-grow\"><div class=\"pg-panel pg-col\" style=\"" +
pg_css("gap:4px;") + "\">" + pg_kicker("Investitionen") + rows + "<div class=\"pg-kv\"><span>Internationale Vermarktung</span><strong class=\"pg-mut\">folgt</strong></div>" +
(delivery.empty() ? std::string() : "<span class=\"pg-tag accent\" style=\"align-self:flex-start;margin-top:" + pg(6) + ";\">" + esc(delivery) + "</span>") + "</div><div class=\"pg-panel pg-col\" style=\"" + pg_css("gap:4px;") + "\">" + pg_kicker("Vereinsprognose / Monat") + "<div class=\"pg-kv\"><span>Einnahmen</span><strong>" + esc(ad_cash(view.at("income").get<int64_t>())) +
"</strong></div><div class=\"pg-kv\"><span>Ausgaben</span><strong>" + esc(ad_cash(view.at("expenses").get<int64_t>())) + "</strong></div><div class=\"pg-kv\"><span>Saldo</span><strong class=\"" + (view.at("balance").get<int64_t>() >= 0 ? "ad-plus" : "ad-minus") + "\">" +
esc((view.at("balance").get<int64_t>() > 0 ? "+ " : "") + ad_cash(view.at("balance").get<int64_t>())) + "</strong></div></div>";
// the note: only what the figures above say, in the manager's own hand
const auto monthly = view.at("spending")[1].at("amount").get<int64_t>() + view.at("spending")[2].at("amount").get<int64_t>();
const auto expenses = view.at("expenses").get<int64_t>(), merchandise = view.at("spending")[0].at("amount").get<int64_t>();
std::vector<std::string> lines;
if (monthly > 0) {
lines.push_back("Presse und Fans: " + ad_cash(monthly) + " im Monat.");
if (expenses > 0) lines.push_back("Das sind " + std::to_string(std::max<int64_t>(1, std::llround(double(monthly) * 100 / double(expenses)))) + " % aller Monatsausgaben.");
} else lines.push_back("Presse und Fans bekommen gerade nichts!");
lines.push_back(!delivery.empty() ? "Fanartikel sind unterwegs – abwarten." : merchandise > 0 ? "Fanartikel zuletzt bestellt für " + ad_cash(merchandise) + "." : "Fanshop leer. Nachbestellen?");
if (view.at("balance").get<int64_t>() < 0) lines.push_back("Achtung: Der Monat schließt im Minus.");
lines.push_back("Ausland: kommt noch.");
out += "<div class=\"pg-panel pg-col\" style=\"" + pg_css("gap:8px;") + "\">" + pg_kicker("Auslastung der Budgets") + use + "</div><span class=\"pg-sp\"></span><div class=\"ad-memo\"><span class=\"ad-memo-tape\"></span><strong>Merkzettel</strong>";
for (const auto &line : lines) out += "<span>" + esc(line) + "</span>";
out += "</div></div>";
} else {
out += "<div class=\"pg-col\" style=\"width:" + pg(ad_ground_w) + ";flex:none;\"><div class=\"ad-ground\" role=\"group\" aria-label=\"Vierzehn Werbebanden\">" +
picture(renderer_.diagram("advertising-ground", ad_ground_svg(taken, advertising_selected_ >= 0 && advertising_selected_ < 14 ? advertising_selected_ : -1), 3000), ad_ground_w * 2.25, ad_ground_h * 2.25);
for (int i = 0; i < 14; ++i) {
const auto &c = slots[size_t(i)];
const auto b = ad_board(i);
const bool on = taken[size_t(i)];
const auto name = c.at("name").get<std::string>();
// the boards at the ends are read from the pitch: their writing stands upright
const std::string face = "<span class=\"ad-board-face" + std::string(b.turn > 0 ? " right" : b.turn < 0 ? " left" : "") + "\" style=\"" + (b.turn ? "left:" + pg((b.w - b.h) / 2) + ";top:" + pg((b.h - b.w) / 2) + ";width:" + pg(b.h) + ";height:" + pg(b.w) + ";" : std::string()) +
"\"><span class=\"ad-board-no\">BANDE " + std::to_string(i + 1) + "</span><strong class=\"" + (on ? "" : "free") + "\">" + esc(on ? name : "Platz frei") + "</strong></span>";
out += btn("ad-contract", face, std::string("ad-board") + (on ? " on" : "") + (advertising_selected_ == i ? " selected" : ""),
"id=\"ad-contract-" + std::to_string(i) + "\" data-ad-contract=\"" + std::to_string(i) + "\" data-id=\"" + std::to_string(i) + "\" aria-pressed=\"" + (advertising_selected_ == i ? "true" : "false") + "\" aria-label=\"Bande " + std::to_string(i + 1) + ", " +
esc(on ? name + ", " + terms(c) : std::string("Platz frei")) + "\" title=\"" + esc(on ? name + " · " + terms(c) : std::string("Platz frei · anklicken für Angebote")) + "\" style=\"left:" + pg(b.x) + ";top:" + pg(b.y) + ";width:" + pg(b.w) + ";height:" + pg(b.h) + ";\"");
}
out += "</div><div class=\"ad-strip\">" + pg_kicker("Vereinsprognose / Monat");
for (const auto &[label, key] : std::array<std::pair<const char *, const char *>, 3>{{{"Einnahmen", "income"}, {"Ausgaben", "expenses"}, {"Saldo", "balance"}}}) {
const auto value = view.at(key).get<int64_t>();
out += "<span class=\"ad-strip-item\"><span class=\"pg-mut\">" + std::string(label) + "</span><strong class=\"" + std::string(std::string(key) == "balance" ? (value >= 0 ? "ad-plus" : "ad-minus") : "") + "\">" +
esc((std::string(key) == "balance" && value > 0 ? "+ " : "") + ad_cash(value)) + "</strong></span>";
}
out += "</div></div><div class=\"ad-tiles\">";
for (const auto &[slot, art, title] : std::array<std::tuple<int, const char *, const char *>, 2>{{{14, "advertising.scene.shirt", "Trikotwerbung"}, {15, "advertising.scene.tv", "TV-Rechte"}}}) {
const auto &c = slots[size_t(slot)];
const bool on = c.at("active") == true;
out += tile("ad-contract", "ad-contract-" + std::to_string(slot), "data-ad-contract=\"" + std::to_string(slot) + "\" data-id=\"" + std::to_string(slot) + "\" aria-pressed=\"" + (advertising_selected_ == slot ? "true" : "false") + "\"", art, title,
on ? (slot == 14 ? "Aktueller Sponsor" : "Aktueller Sender") : "Platz frei", on ? c.at("name").get<std::string>() : std::string("Kein Vertrag"), on ? terms(c) : std::string("Anklicken für Angebote"), advertising_selected_ == slot, "four");
}
out += tile("ad-soon", "ad-contract-naming", soon, "advertising.scene.arena", "Namensrecht Stadion", "Neu", "Noch nicht im Spiel", "Dieser Vertrag folgt", false, "four") + "</div>";
}
out += "</div></section>";
if (advertising_selected_ < 0 || advertising_selected_ > 15) return out;
// the offers for the chosen place, as a note
const auto &choices = engine_mode_ ? slots[size_t(advertising_selected_)].at("choices") : Json::array();
if (engine_mode_) advertising_offer_ = std::clamp(advertising_offer_, 0, int(choices.size()) - 1);
const auto quote = engine_mode_ ? engine_advertising_quote(engine_data_, advertising_selected_, advertising_offer_) : demo_advertising_quote(snapshot.state, advertising_selected_, advertising_offer_, *world_);
const bool active = quote.at("active");
const bool cycle = engine_mode_ ? quote.at("can_cycle").get<bool>() : !active;
const bool accept = engine_mode_ ? quote.at("can_accept").get<bool>() : !active;
const auto place = quote.at("label").get<std::string>(), sponsor = quote.at("name").get<std::string>();
// which of the offers this is: a running contract stands before them
const int running = engine_mode_ && !choices.empty() && choices[0].at("active") == true ? 1 : 0;
const int count = engine_mode_ ? int(choices.size()) - running : 3;
const bool none = engine_mode_ && !active && quote.value("offer_id", Json()).is_null();
const auto which = active ? std::string("Laufender Vertrag") : none ? std::string("Keine Angebote") : "Angebot " + std::to_string(advertising_offer_ - running + 1) + " von " + std::to_string(std::max(1, count));
const int boards = engine_mode_ ? quote.value("boards", 1) : 1;
out += "<div class=\"pg-ov\" id=\"ad-layer\"><section class=\"pg-dlg\" role=\"dialog\" aria-modal=\"true\" aria-labelledby=\"ad-offer-title\" aria-live=\"polite\" style=\"width:" + pg(560) + ";\"><div><h2 id=\"ad-offer-title\">" + esc(place) + "</h2><span class=\"pg-dlg-sub\">" +
std::string(active ? "Der Vertrag läuft; mit den Pfeilen siehst du, was sonst geboten wird." : "Mit den Pfeilen durch die Angebote blättern.") + "</span></div><div class=\"pg-panel pg-row\" style=\"" + pg_css("gap:14px;") + "\">" + (none ? std::string() : ad_mark(sponsor, 171)) +
"<div class=\"pg-grow\">" + pg_kicker(which) + "<h3 class=\"pg-h\" style=\"font-size:" + pg(22) + ";line-height:" + pg(27) + ";\">" + esc(sponsor) + "</h3><span class=\"pg-mut\" style=\"display:block;\">" +
(none ? std::string("Für diesen Platz liegt derzeit nichts vor.") : (active ? "Noch " : "Dauer ") + std::to_string(quote.at("months").get<int>()) + (quote.at("months").get<int>() == 1 ? " Monat" : " Monate") + (boards > 1 ? " · " + std::to_string(boards) + " Banden" : std::string())) +
"</span></div>" + (none ? std::string() : "<div style=\"text-align:right;\">" + pg_kicker("je Monat") + "<strong class=\"pg-big\">" + esc(ad_cash(quote.at("amount").get<int64_t>())) + "</strong></div>") + "</div><nav class=\"pg-dlg-act\">" +
pg_button("ad-offer", "‹", "round", "id=\"ad-offer-previous\" data-step=\"-1\" aria-label=\"Vorheriges Angebot\" " + std::string(cycle ? "" : "disabled=\"disabled\"")) +
pg_button("ad-offer", "›", "round", "id=\"ad-offer-next\" data-step=\"1\" aria-label=\"Nächstes Angebot\" " + std::string(cycle ? "" : "disabled=\"disabled\"")) + "<span class=\"pg-sp\"></span>" +
pg_button("ad-cancel", active ? "Schließen" : "Abbrechen", "", "id=\"ad-cancel\"") +
pg_button("ad-accept", active ? "Vertrag läuft" : accept ? "Annehmen" : "Nicht verfügbar", "primary", "id=\"ad-accept\" " + std::string(accept ? "" : "disabled=\"disabled\"")) + "</nav></section></div>";
return out;
}