The balance sheet with shares and a what-if calculation; season counts in the line-up
The balance shows its sums as numerals and every position with its share. A calculation with sliders for ticket price, crowd and home matches ahead draws where the cash goes; it is arithmetic on the booked figures, not a forecast. The squad read carries goals, assists and matches of the running season from the almanac, and the line-up shows them. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
c560268373
commit
d75617052f
11 files changed
+246
-11
No files matched your search
@@ -38,3 +38,56 @@ body.midnight .balance-plan-value {background-color:#111f2a80;border-color:#c5d9
|
||||
/* Balances use semantic money colours in every skin. */
|
||||
body .balance-native .balance-summary-item.money-amount {color:var(--money);}
|
||||
body .balance-native .balance-summary-item.money-amount.is-negative {color:var(--danger);}
|
||||
|
||||
/* the balance: sums as numerals, every position with its share */
|
||||
.balance-tile {position:absolute;border:2dp var(--rule);border-radius:10dp;background-color:var(--panel);display:flex;flex-direction:column;align-items:center;justify-content:center;}
|
||||
.balance-tile strong {display:block;font-family:Display;font-size:58dp;line-height:72dp;font-weight:bold;white-space:nowrap;}
|
||||
.balance-tile span {display:block;font-size:32dp;line-height:42dp;color:var(--muted);}
|
||||
.balance-tile.loss strong {color:var(--loss);}
|
||||
.balance-tile.gain strong {color:var(--win);}
|
||||
.balance-scale {position:absolute;left:0;top:224dp;width:2612dp;height:60dp;display:flex;border-radius:8dp;overflow:hidden;}
|
||||
.balance-scale>div {display:flex;align-items:center;justify-content:center;min-width:0;overflow:hidden;}
|
||||
.balance-scale span {display:block;font-size:28dp;white-space:nowrap;color:#ffffff;}
|
||||
.balance-scale .in {background-color:#3f8a63;}
|
||||
.balance-scale .out {background-color:#b24a4f;}
|
||||
.balance-panel {top:308dp;height:1330dp;background-color:var(--panel);border-color:var(--rule);border-radius:10dp;}
|
||||
.balance-panel h2 {font-family:Display;font-size:44dp;line-height:54dp;font-weight:bold;text-align:left;margin:0 0 0 10dp;}
|
||||
.balance-table {top:96dp;}
|
||||
.balance-row {align-items:center;height:92dp;border-bottom:2dp var(--rule);font-size:34dp;}
|
||||
.balance-row>span,.balance-row>span:last-child {width:auto;max-width:none;padding:0 10dp;line-height:44dp;flex-shrink:0;}
|
||||
.balance-row .name {width:420dp;}
|
||||
.balance-bar {flex:1;height:22dp;border-radius:11dp;background-color:var(--rule);overflow:hidden;}
|
||||
.balance-bar>div {height:22dp;border-radius:11dp;background-color:#3f8a63;}
|
||||
.balance-panel.costs .balance-bar>div {background-color:#b24a4f;}
|
||||
.balance-row .share {width:110dp;text-align:right;font-size:28dp;color:var(--muted);}
|
||||
.balance-row .sum {width:330dp;text-align:right;font-family:Display;font-weight:bold;font-size:36dp;}
|
||||
.balance-row.none {color:var(--muted);}
|
||||
.balance-row.none .sum {font-weight:normal;}
|
||||
.balance-games {position:absolute;left:10dp;top:1656dp;width:2592dp;height:44dp;margin:0;line-height:44dp;font-size:30dp;color:var(--muted);}
|
||||
.balance-row {font-size:40dp;}
|
||||
.balance-row .name {width:520dp;}
|
||||
.balance-row .sum {width:400dp;font-size:44dp;}
|
||||
.balance-row .share {width:130dp;font-size:32dp;}
|
||||
.balance-bar,.balance-bar>div {height:28dp;border-radius:14dp;}
|
||||
.balance-tile strong {font-size:66dp;line-height:80dp;}
|
||||
.balance-tile span {font-size:36dp;}
|
||||
.balance-games {font-size:34dp;}
|
||||
|
||||
/* the what-if calculation */
|
||||
.balance-toggle {left:560dp;width:2052dp;}
|
||||
.balance-sim-button {position:absolute;left:0;bottom:0;width:536dp;height:94dp;display:flex;align-items:center;justify-content:center;}
|
||||
.balance-sim {position:absolute;left:0;top:0;right:0;bottom:120dp;}
|
||||
.balance-sim-controls {position:absolute;left:0;top:0;width:2612dp;height:210dp;display:flex;gap:30dp;}
|
||||
.balance-sim-control {flex:1;border:2dp var(--rule);border-radius:10dp;background-color:var(--panel);padding:22dp 36dp;}
|
||||
.balance-sim-label {display:flex;align-items:baseline;justify-content:space-between;height:76dp;font-size:36dp;}
|
||||
.balance-sim-label span,.balance-sim-label strong {display:block;}
|
||||
.balance-sim-label strong {font-family:Display;font-size:60dp;font-weight:bold;}
|
||||
.balance-sim-control input {display:block;width:100%;height:60dp;margin-top:16dp;}
|
||||
.balance-sim-out {position:absolute;left:0;top:240dp;width:2612dp;height:1480dp;}
|
||||
.balance-sim-graph {position:absolute;left:0;top:226dp;width:2612dp;height:880dp;border:2dp var(--rule);border-radius:10dp;background-color:var(--panel);padding:18dp 14dp;}
|
||||
.balance-sim-legend {position:absolute;left:10dp;top:1126dp;height:44dp;display:flex;align-items:center;font-size:32dp;color:var(--muted);}
|
||||
.balance-sim-legend span {display:block;flex-shrink:0;}
|
||||
.balance-sim-legend .key {width:60dp;height:12dp;border-radius:6dp;margin:0 14dp 0 0;}
|
||||
.balance-sim-legend .key.sim {background-color:#25617a;}
|
||||
.balance-sim-legend .key.now {background-color:#9a7a3a;margin-left:50dp;}
|
||||
.balance-sim-reading {position:absolute;left:10dp;top:1190dp;width:2592dp;margin:0;font-size:36dp;line-height:50dp;}
|
||||
@@ -278,6 +278,25 @@ J squad_data(const ModernState& g, const UiContext& c, int team, const std::stri
|
||||
const bool own = team == team_of(g, c.manager) && team < league_clubs();
|
||||
const size_t board = size_t(c.manager) * 0x840;
|
||||
const SquadRange r = squad_range(team);
|
||||
// what the almanac recorded of the running season, by world player id: goals, assists and
|
||||
// matches in the starting eleven or coming on (no shoot-out kicks)
|
||||
struct Tally { int goals = 0, assists = 0, games = 0; };
|
||||
std::map<std::string, Tally> season;
|
||||
{
|
||||
const auto& s = g.almanac.current;
|
||||
const auto id_of = [&](uint16_t p) { return p < s.players.size() ? s.players[p].id : std::string(); };
|
||||
for (const auto& m : s.matches) {
|
||||
for (const auto& side : m.lineup)
|
||||
for (size_t i = 0; i < side.size() && i < 11; ++i)
|
||||
if (side[i] != kAlmanacNone) ++season[id_of(side[i])].games;
|
||||
for (const auto& e : m.events) {
|
||||
if (e.kind == AlmanacEventKind::Goal) {
|
||||
if (e.player != kAlmanacNone) ++season[id_of(e.player)].goals;
|
||||
if (e.other != kAlmanacNone) ++season[id_of(e.other)].assists;
|
||||
} else if (e.kind == AlmanacEventKind::Substitution && e.player != kAlmanacNone) ++season[id_of(e.player)].games;
|
||||
}
|
||||
}
|
||||
}
|
||||
A players;
|
||||
for (size_t s = r.first; s < r.first + r.count && s < g.squad_slots.size(); ++s) {
|
||||
const uint16_t e = g.squad_slots[s];
|
||||
@@ -323,6 +342,9 @@ J squad_data(const ModernState& g, const UiContext& c, int team, const std::stri
|
||||
row["contractRemaining"] = nullptr;
|
||||
}
|
||||
row["contractUntil"] = nullptr;
|
||||
const auto tally = season.find(pid);
|
||||
row["season"] = O{{"goals", tally == season.end() ? 0 : tally->second.goals}, {"assists", tally == season.end() ? 0 : tally->second.assists},
|
||||
{"games", tally == season.end() ? 0 : tally->second.games}};
|
||||
players.push_back(std::move(row));
|
||||
}
|
||||
return O{{"kind", "squad"}, {"team", team_ref(g, team, today)}, {"players", std::move(players)}};
|
||||
|
||||
@@ -155,6 +155,7 @@ void App::ProcessEvent(Rml::Event &event) try {
|
||||
if (entry_event(event)) return;
|
||||
if (opening_event(event)) return;
|
||||
if (amount_event(event)) return;
|
||||
if (balance_simulation_event(event)) return;
|
||||
if (popup_.empty() && settings_event(event)) return;
|
||||
if (popup_.empty() && (files_event(event) || widget_event(event))) return;
|
||||
if ((menu_ == "lineup" || menu_ == "transfer" || scene_ == "manager") && (type == "change" || type == "input")) {
|
||||
|
||||
@@ -120,6 +120,13 @@ void App::engine_balance_close(const std::string &after) {
|
||||
}
|
||||
bool App::engine_balance_action(const std::string &action,
|
||||
Rml::Element *target) {
|
||||
if (menu_ == "balance" && action == "balance-sim") {
|
||||
balance_sim_ = !balance_sim_;
|
||||
if (balance_sim_) balance_sim_price_ = 0;
|
||||
focus_after_render_ = "balance-sim";
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
if (menu_ != "balance")
|
||||
return false;
|
||||
if (action == "balance-discard") {
|
||||
|
||||
@@ -276,6 +276,7 @@ void App::engine_event(Rml::Event &event) {
|
||||
const auto type = event.GetType(); auto *target = event.GetTargetElement();
|
||||
if (type == "keydown") keyboard_navigation_ = true;
|
||||
if (type == "mousedown") keyboard_navigation_ = false;
|
||||
if (balance_simulation_event(event)) return;
|
||||
if (scene_ == "live" && live_.available()) {
|
||||
// The ticker of a played kickoff: only its own controls, nothing of the desk beneath.
|
||||
if (live_event(event)) return;
|
||||
|
||||
@@ -144,6 +144,10 @@ Json engine_lineup_projection(const Json &bundle) {
|
||||
for (const auto *key : {"corner", "free_kick", "tackling", "passing", "shooting", "speed", "teamplay"})
|
||||
row[key] = raw.at("skills").value(key, Json());
|
||||
for (const auto *key : {"motivation", "goals", "assists", "games", "grade"}) row[key] = nullptr;
|
||||
// the season's counts from the almanac, when the engine sends them
|
||||
if (raw.contains("season") && raw.at("season").is_object())
|
||||
for (const auto *key : {"goals", "assists", "games"})
|
||||
if (raw.at("season").value(key, Json()).is_number_integer()) row[key] = raw.at("season").at(key);
|
||||
const auto role = roles.at(id).get<std::string>();
|
||||
require(role == "starter" || role == "bench" || role == "reserve", "Unbekannter Kaderstatus.");
|
||||
row["status"] = role == "starter" ? "Startelf" : role == "bench" ? "Ersatzbank" : "—";
|
||||
|
||||
@@ -10,6 +10,13 @@ bool App::commit_finance(const Json &change, uint64_t revision) {
|
||||
return true;
|
||||
}
|
||||
bool App::finance_action(const std::string &action, Rml::Element *target) {
|
||||
if (menu_ == "balance" && action == "balance-sim") {
|
||||
balance_sim_ = !balance_sim_;
|
||||
if (balance_sim_) balance_sim_price_ = 0; // start again from the booked values
|
||||
focus_after_render_ = "balance-sim";
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
if(engine_mode_)return engine_balance_action(action,target);
|
||||
if (menu_ != "balance") return false;
|
||||
if (action == "balance-toggle") {
|
||||
|
||||
@@ -3,7 +3,8 @@ 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_future_) {
|
||||
if (balance_sim_) out += render_balance_simulation();
|
||||
else if (balance_future_) {
|
||||
out += "<section class=\"balance-plan\"><h2>Ausgabenplanung</h2><div class=\"balance-plan-rows\">";
|
||||
int i = 0;
|
||||
for (const auto &row : rows.at("plan")) {
|
||||
@@ -17,18 +18,47 @@ std::string App::render_balance() {
|
||||
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>";
|
||||
} 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;
|
||||
for (const auto &kind : {std::string("income"), std::string("costs")}) {
|
||||
for (const auto &row : rows.at(kind)) sums[side] += std::max<int64_t>(0, row.at("amount").get<int64_t>());
|
||||
++side;
|
||||
}
|
||||
}
|
||||
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>";
|
||||
// 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>";
|
||||
int index = 0;
|
||||
for (const auto &kind : {std::string("income"), std::string("costs")}) {
|
||||
out += "<section class=\"balance-panel\" style=\"left:" + std::to_string(index++ * 1322) +
|
||||
"dp;\"><h2>" + (kind == "income" ? "Einnahmen" : "Ausgaben") + "</h2><div class=\"balance-table\">"
|
||||
"<div class=\"balance-row balance-head\"><span>Position</span><span>Betrag</span></div>";
|
||||
int n = 0;
|
||||
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())));
|
||||
for (const auto &row : rows.at(kind)) {
|
||||
out += "<div class=\"balance-row" + std::string(n++ % 2 == 0 ? " striped" : "") + "\"><span>" +
|
||||
esc(row.at("name").get<std::string>()) + "</span><span>" + esc(balance_cash(row.at("amount").get<int64_t>())) + "</span></div>";
|
||||
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></section>";
|
||||
}
|
||||
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",
|
||||
@@ -36,11 +66,12 @@ std::string App::render_balance() {
|
||||
"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 < 6; ++i)
|
||||
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 += btn("balance-toggle", "<span>" + std::string(balance_future_ ? "Zukunft" : "Aktuell") +
|
||||
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>";
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
// A what-if calculation on the balance sheet: the manager sets ticket price and crowd and sees
|
||||
// where the cash goes over the coming home matches. It is arithmetic on the season's booked
|
||||
// figures, not the engine's forecast: how the crowd answers a price is the engine's to decide.
|
||||
std::string App::balance_simulation_result() {
|
||||
const auto rows = balance_rows();
|
||||
if (!rows.value("ok", false)) return {};
|
||||
const double unit = engine_mode_ ? 100.0 : double(finance_currency_factor(*world_)); // row units per euro
|
||||
const double ticket = rows.at("ticket").get<double>() / unit, crowd = rows.at("attendance_average").get<double>();
|
||||
const int played = std::max<int>(1, int(rows.at("league_home_games").get<int64_t>() + rows.at("other_home_games").get<int64_t>()));
|
||||
double costs = 0, other_income = 0;
|
||||
for (const auto &row : rows.at("costs")) costs += std::max<int64_t>(0, row.at("amount").get<int64_t>()) / unit;
|
||||
for (const auto &row : rows.at("income")) other_income += std::max<int64_t>(0, row.at("amount").get<int64_t>()) / unit;
|
||||
other_income = std::max(0.0, other_income - ticket * crowd * played); // everything but the gate
|
||||
const double cost_per_match = costs / played, other_per_match = other_income / played;
|
||||
const double cash = rows.at("cash").get<double>() / unit;
|
||||
const int matches = balance_sim_matches_;
|
||||
const auto per_match = [&](double price, double people) { return price * people + other_per_match - cost_per_match; };
|
||||
const double now = per_match(ticket, crowd), then = per_match(balance_sim_price_, balance_sim_crowd_);
|
||||
const auto euro = [&](double value) { return esc(balance_cash(int64_t(std::llround(value * unit)))); };
|
||||
std::string out;
|
||||
const std::array<std::array<std::string, 3>, 4> tiles{{
|
||||
{euro(balance_sim_price_ * balance_sim_crowd_), "Zuschauereinnahme je Heimspiel", ""},
|
||||
{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" : ""}}};
|
||||
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>";
|
||||
// the cash after each home match: as booked so far, and with the sliders' values
|
||||
const double base = cash;
|
||||
(void)base;
|
||||
const double low = std::min({now * matches, then * matches, 0.0}), high = std::max({now * matches, then * matches, 0.0});
|
||||
const double span = std::max(1.0, high - low), floor = low - span * .08, ceiling = high + span * .08;
|
||||
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",
|
||||
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>";
|
||||
for (int row = 0; row <= 4; ++row) {
|
||||
const double value = floor + (ceiling - floor) * row / 4;
|
||||
svg += "<line x1=\"250\" y1=\"" + scalar(py(value)) + "\" x2=\"2540\" y2=\"" + scalar(py(value)) + "\" stroke=\"" + faint + "\" stroke-width=\"2\"/><text x=\"230\" y=\"" + scalar(py(value) + 10) +
|
||||
"\" text-anchor=\"end\" fill=\"" + ink + "\" font-size=\"30\" font-family=\"Arial, Liberation Sans, sans-serif\">" + number(int64_t(std::llround(value / 1000))) + " T€</text>";
|
||||
}
|
||||
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";
|
||||
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>";
|
||||
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. ") +
|
||||
(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>";
|
||||
return out;
|
||||
}
|
||||
std::string App::render_balance_simulation() {
|
||||
const auto rows = balance_rows();
|
||||
const double unit = engine_mode_ ? 100.0 : double(finance_currency_factor(*world_));
|
||||
if (balance_sim_price_ <= 0) { // start from the booked values
|
||||
balance_sim_price_ = std::clamp(int(std::lround(rows.at("ticket").get<double>() / unit)), 5, 60);
|
||||
balance_sim_crowd_ = std::clamp(int(rows.at("attendance_average").get<int64_t>()) / 500 * 500, 1000, 100000);
|
||||
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 +
|
||||
"\" 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\">" +
|
||||
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>";
|
||||
}
|
||||
bool App::balance_simulation_event(Rml::Event &event) {
|
||||
if (menu_ != "balance" || !balance_sim_ || !popup_.empty()) return false;
|
||||
const auto type = event.GetType();
|
||||
if (type != "change" && type != "input") return false;
|
||||
auto *target = event.GetTargetElement();
|
||||
if (!target || !target->GetId().starts_with("balance-sim-")) return false;
|
||||
if (setting_menu_markup_) return true;
|
||||
const auto read = [&](const char *id, int fallback) {
|
||||
if (auto *input = dynamic_cast<Rml::ElementFormControl *>(element(id))) { try { return std::stoi(input->GetValue()); } catch (const std::exception &) {} }
|
||||
return fallback;
|
||||
};
|
||||
balance_sim_price_ = std::clamp(read("balance-sim-price", balance_sim_price_), 5, 60);
|
||||
balance_sim_crowd_ = std::clamp(read("balance-sim-crowd", balance_sim_crowd_), 1000, 100000);
|
||||
balance_sim_matches_ = std::clamp(read("balance-sim-matches", balance_sim_matches_), 1, 34);
|
||||
// the sliders stay as they are under the pointer; only figures and graph are drawn anew
|
||||
if (auto *node = element("balance-sim-price-value")) node->SetInnerRML(std::to_string(balance_sim_price_) + " €");
|
||||
if (auto *node = element("balance-sim-crowd-value")) node->SetInnerRML(number(balance_sim_crowd_));
|
||||
if (auto *node = element("balance-sim-matches-value")) node->SetInnerRML(std::to_string(balance_sim_matches_));
|
||||
if (auto *node = element("balance-sim-out")) node->SetInnerRML(balance_simulation_result());
|
||||
dirty_ = true;
|
||||
return true;
|
||||
}
|
||||
@@ -202,7 +202,7 @@ std::string App::render_lineup() {
|
||||
"lineup-head\" role=\"row\">";
|
||||
const std::array<std::array<const char *, 12>, 2> headings{
|
||||
{{{"Nr.", "Name", "Pos.", "Ko", "Te", "Fo", "Stärke", "Status", "Land",
|
||||
"Mot.", "Tore", "Ass."}},
|
||||
"Sp.", "Tore", "Vorl."}},
|
||||
{{"Nr.", "Name", "Alter", "Eck.", "Frei.", "Zwei.", "Pass", "Schuss",
|
||||
"Schn.", "Team", "Spiele", "Note"}}}};
|
||||
for (int c = 0; c < 12; ++c)
|
||||
@@ -240,7 +240,7 @@ std::string App::render_lineup() {
|
||||
row.at("nation").is_string()
|
||||
? row.at("nation").get<std::string>()
|
||||
: "—",
|
||||
lineup_value(row.at("motivation")),
|
||||
lineup_value(row.at(engine_mode_ ? "games" : "motivation")),
|
||||
lineup_value(row.at("goals")),
|
||||
lineup_value(row.at("assists"))};
|
||||
else
|
||||
|
||||
@@ -457,6 +457,12 @@ class App final : public Rml::EventListener {
|
||||
std::string bank_view_ = "entrance", bank_hint_;
|
||||
int bank_property_ = 0, bank_owned_ = 0, bank_stock_ = 11;
|
||||
bool balance_future_ = false;
|
||||
// the balance sheet's what-if calculation (finance_simulation.inc)
|
||||
bool balance_sim_ = false;
|
||||
int balance_sim_price_ = 0, balance_sim_crowd_ = 0, balance_sim_matches_ = 17;
|
||||
std::string balance_simulation_result();
|
||||
std::string render_balance_simulation();
|
||||
bool balance_simulation_event(Rml::Event &);
|
||||
Json contract_draft_;
|
||||
std::string contracts_player_, contracts_dialog_, contracts_return_focus_, contracts_notice_;
|
||||
int contracts_tab_ = 2;
|
||||
@@ -776,6 +782,7 @@ class App final : public Rml::EventListener {
|
||||
bank_view_ = "entrance";
|
||||
bank_hint_.clear();
|
||||
balance_future_ = false;
|
||||
balance_sim_ = false;
|
||||
almanac_year_ = 0;
|
||||
almanac_day_.clear();
|
||||
almanac_match_.clear();
|
||||
@@ -1683,6 +1690,7 @@ public:
|
||||
#include "modern/ui/engine_friendlies.inc"
|
||||
#include "modern/ui/engine_almanac.inc"
|
||||
#include "modern/ui/engine_reports.inc"
|
||||
#include "modern/ui/finance_simulation.inc"
|
||||
#include "modern/ui/statistics_analysis.inc"
|
||||
#include "modern/ui/engine_rankings.inc"
|
||||
#include "modern/ui/engine_creation.inc"
|
||||
|
||||
Reference in new issue
Block a user