The bank's services as sheets with charts and readings
Every service has the house's head and tabs to the others. The overview shows the club's wealth as a ring by where it lies and the stock market's change per company; stocks carry a spark line, the change on the day before, the course with a five-day average, high and low, and a reading of trend and swing; properties compare the six prices. Stocks and properties are named in full by the bank read: the company from the game's texts, the property from its stem and singular ending. Soft shadows inside windows are gone, they drew stray lines in the Direct3D renderer. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
143e45e3a2
commit
e3edd2f9ed
13 files changed
+422
-84
No files matched your search
@@ -59,7 +59,7 @@ std::string App::render_advertising() {
|
||||
btn("ad-accept", active ? "Vertrag läuft" : accept ? "Annehmen" : "Nicht verfügbar", "advertising-control", "id=\"ad-accept\" " + std::string(accept ? "" : "disabled")) + "</nav>";
|
||||
}
|
||||
if (engine_mode_) out += "<span class=\"engine-ad-preview-label\">Vereinsprognose / Monat</span>";
|
||||
out += "<div class=\"advertising-totals\" aria-label=\"" + std::string(engine_mode_ ? "Monatliche Vereinsprognose der Engine" : "Werbevorschau") + "\">";
|
||||
out += "<div class=\"advertising-totals\" aria-label=\"" + std::string(engine_mode_ ? "Monatliche Vereinsprognose" : "Werbevorschau") + "\">";
|
||||
for (const auto &[label, key] : std::array<std::pair<const char *, const char *>, 3>{{{"Einnahmen", "income"}, {"Ausgaben", "expenses"}, {"Saldo", "balance"}}})
|
||||
out += "<div><span>" + std::string(label) + "</span><output class=\"" + (engine_mode_ ? money_classes(view.at(key)) : std::string()) + "\">" + esc(ad_cash(view.at(key).get<int64_t>())) + "</output></div>";
|
||||
return out + "</div></section></div>";
|
||||
|
||||
+235
-64
@@ -49,60 +49,188 @@ std::string App::render_bank() {
|
||||
if (bank_view_ == "entrance")
|
||||
return out + "<p id=\"bank-interaction-hint\" role=\"status\" aria-live=\"polite\"><span>" +
|
||||
esc(bank_hint_.empty() ? "Ein Element in der Bankhalle auswählen." : bank_hint_) + "</span></p></div>";
|
||||
out += "<section class=\"bank-overlay " + esc(bank_view_) + "-overlay\">";
|
||||
// Every service of the bank shares one head: the house's name, the service, and tabs that
|
||||
// lead to the other services without a walk back through the hall.
|
||||
const std::array<std::pair<const char *, const char *>, 5> bank_tabs{{{"overview", "Übersicht"}, {"stocks", "Aktien"}, {"properties", "Immobilien"}, {"savings", "Sparbuch"}, {"credit", "Kredit"}}};
|
||||
std::string service;
|
||||
for (const auto &[id, label] : bank_tabs) if (bank_view_ == id) service = label;
|
||||
out += "<section class=\"bank-overlay " + esc(bank_view_) + "-overlay\"><header class=\"bank-head\"><div class=\"bank-brand\"><strong>Waldpark Bank</strong><span>" +
|
||||
service + "</span></div><nav class=\"bank-tabs\" aria-label=\"Bankdienste\">";
|
||||
for (const auto &[id, label] : bank_tabs)
|
||||
out += btn("bank-view", label, std::string("bank-tab") + (bank_view_ == id ? " selected" : ""),
|
||||
"id=\"bank-tab-" + std::string(id) + "\" data-view=\"" + id + "\" aria-pressed=\"" + (bank_view_ == id ? "true" : "false") + "\"");
|
||||
out += "</nav></header>";
|
||||
const auto one = [](double value) {
|
||||
std::ostringstream text;
|
||||
text << std::fixed << std::setprecision(1) << value;
|
||||
auto result = text.str();
|
||||
std::replace(result.begin(), result.end(), '.', ',');
|
||||
return result;
|
||||
};
|
||||
// what the club owns, by where it lies
|
||||
const int64_t in_cash = summary.at("cash").get<int64_t>(), in_deposit = summary.at("deposit").get<int64_t>(),
|
||||
in_property = summary.at("properties").get<int64_t>(), in_stock = summary.at("stocks").get<int64_t>();
|
||||
const int64_t wealth = std::max<int64_t>(0, in_cash) + in_deposit + in_property + in_stock;
|
||||
const auto share = [&](int64_t part) { return wealth > 0 ? one(std::max<int64_t>(0, part) * 100.0 / wealth) + " %" : std::string("—"); };
|
||||
const std::string ink = theme_ == "silver" ? "#233443" : "#e8eef2", faint = theme_ == "silver" ? "#4a433430" : "#dfeaf530",
|
||||
up = theme_ == "silver" ? "#3f7d63" : "#8fd3ad", down = theme_ == "silver" ? "#a23f45" : "#f0a6a7",
|
||||
gold = theme_ == "silver" ? "#9a7a3a" : "#d9bd7c", line = theme_ == "silver" ? "#25617a" : "#9ac7d8";
|
||||
// an engine name arrives in capitals
|
||||
const auto calm_name = [](std::string name) {
|
||||
bool first = true;
|
||||
std::string result;
|
||||
for (size_t i = 0; i < name.size(); ++i) {
|
||||
const unsigned char c = static_cast<unsigned char>(name[i]);
|
||||
if (c == 0xc3 && i + 1 < name.size()) { // Ä Ö Ü
|
||||
unsigned char next = static_cast<unsigned char>(name[i + 1]);
|
||||
if (!first && (next == 0x84 || next == 0x96 || next == 0x9c)) next = static_cast<unsigned char>(next + 0x20);
|
||||
result += name[i]; result += static_cast<char>(next); ++i; first = false;
|
||||
continue;
|
||||
}
|
||||
if (std::isalpha(c)) { result += static_cast<char>(first ? c : std::tolower(c)); first = false; }
|
||||
else { result += name[i]; if (c == ' ' || c == '-') first = true; }
|
||||
}
|
||||
return result;
|
||||
};
|
||||
const auto factor = engine_mode_ ? 100 : finance_currency_factor(*world_);
|
||||
const auto course = [&](int index) {
|
||||
std::vector<double> history;
|
||||
const auto &stock = assets.at("stocks")[size_t(index)];
|
||||
if (engine_mode_) {
|
||||
for (const auto &value : stock.at("history")) if (value.get<double>() > 0) history.push_back(value.get<double>() / factor);
|
||||
} else {
|
||||
const double price = stock.at("price").get<double>() / factor;
|
||||
for (int i = 0; i < 30; ++i) history.push_back(price * (.85 + .08 * std::sin(i * .6 + index) + i * .003));
|
||||
}
|
||||
return history;
|
||||
};
|
||||
if (bank_view_ == "savings") {
|
||||
out += "<div class=\"passbook\">" + img("art.bank-passbook-v1.png", 2100, 1293.109375, false, false, 2400) +
|
||||
"<div class=\"passbook-left\"><h2>Waldpark Bank</h2><h3>Sparbuch</h3><p class=\"passbook-note-one\">Bitte beachten Sie:</p>"
|
||||
"<p class=\"passbook-note-two\">" + std::string(engine_mode_ ? "Einzahlungen und Abhebungen werden nach Bestätigung im Spielstand verbucht." : "Einzahlungen und Abhebungen werden hier als fiktive Vorschau verbucht.") + "</p>"
|
||||
"<p class=\"passbook-note-three\">" + (engine_mode_ ? "" : "2,5 % Beispielzins") + "</p></div><div class=\"passbook-right\"><h2>Guthaben</h2><output>" +
|
||||
esc(bank_money(snapshot.state.at("deposit").get<int64_t>())) + "</output></div></div>" + actions("Einzahlen", "deposit", "Abheben", "withdraw");
|
||||
"<p class=\"passbook-note-three\">" + (engine_mode_ ? "Anteil am Vermögen: " + share(in_deposit) : std::string("2,5 % Beispielzins")) + "</p></div><div class=\"passbook-right\"><h2>Guthaben</h2><output>" +
|
||||
esc(bank_money(snapshot.state.at("deposit").get<int64_t>())) + "</output><p class=\"passbook-cash\">Auf dem Konto: " + esc(bank_money(in_cash)) + "</p></div></div>" + actions("Einzahlen", "deposit", "Abheben", "withdraw");
|
||||
} else if (bank_view_ == "properties") {
|
||||
out += "<h2>Immobilien</h2>";
|
||||
const auto &owned = assets.at("properties")[size_t(bank_owned_)], &offer = assets.at("properties")[size_t(bank_property_)];
|
||||
const auto count = finance.at("properties")[size_t(bank_owned_)].get<int64_t>();
|
||||
out += "<div class=\"property-row owned-property\"><div class=\"property-description\"><h3>Ihre Immobilien</h3>" +
|
||||
(count ? "<p>" + std::to_string(count) + " × " + esc(owned.at("name").get<std::string>()) + "</p><p>Wert: " +
|
||||
esc(bank_money(count * owned.at("price").get<int64_t>())) + "</p>" : "<p>Keine Immobilien im Bestand</p>") +
|
||||
"</div>" + btn("property-owned-next", count ? img(engine_mode_ ? owned.at("image").get<std::string>() : "bank.property." + std::to_string(bank_owned_), 996, 566, false, false, 1200)
|
||||
: "<span class=\"property-empty\"></span>", "property-picture", "id=\"property-owned-next\" aria-label=\"Nächste eigene Immobilie\" " + std::string(count ? "" : "disabled")) + "</div>";
|
||||
out += "<div class=\"property-row offered-property\"><div class=\"property-description\"><h3>Kaufangebot</h3><p>" +
|
||||
esc(offer.at("name").get<std::string>()) + "</p><p>Kaufpreis: " + esc(bank_money(offer.at("price").get<int64_t>())) +
|
||||
"</p></div>" + btn("property-next", img(engine_mode_ ? offer.at("image").get<std::string>() : "bank.property." + std::to_string(bank_property_), 996, 566, false, false, 1200),
|
||||
"property-picture", "id=\"property-next\" aria-label=\"Nächstes Immobilienangebot\"") + "</div>" +
|
||||
int64_t houses = 0;
|
||||
for (const auto &held : finance.at("properties")) houses += held.get<int64_t>();
|
||||
const auto fact = [](const std::string &label, const std::string &value) { return "<div class=\"bank-fact\"><span>" + label + "</span><strong>" + value + "</strong></div>"; };
|
||||
out += "<div class=\"property-card owned-property\"><h3>Dein Bestand</h3>" +
|
||||
btn("property-owned-next", count ? img(engine_mode_ ? owned.at("image").get<std::string>() : "bank.property." + std::to_string(bank_owned_), 1150, 653.5, false, false, 1400)
|
||||
: "<span class=\"property-empty\"><span>Noch keine Immobilie im Bestand</span></span>", "property-picture", "id=\"property-owned-next\" aria-label=\"Nächste eigene Immobilie\" " + std::string(count ? "" : "disabled")) +
|
||||
(count ? "<h4>" + esc(calm_name(owned.at("name").get<std::string>())) + "</h4>" + fact("Im Bestand", number(count) + " Stück") +
|
||||
fact("Wert heute", esc(bank_money(count * owned.at("price").get<int64_t>())))
|
||||
: "<h4>Kein Bestand</h4>" + fact("Immobilienwert", esc(bank_money(in_property))) + fact("Anteil am Vermögen", share(in_property))) +
|
||||
"<div class=\"property-prices\"><h5>Preise im Vergleich · " + number(houses) + " im Bestand</h5>";
|
||||
{
|
||||
int64_t dearest = 1;
|
||||
for (const auto &item : assets.at("properties")) dearest = std::max(dearest, item.at("price").get<int64_t>());
|
||||
for (int i = 0; i < property_count; ++i) {
|
||||
const auto &item = assets.at("properties")[size_t(i)];
|
||||
out += "<div class=\"property-price" + std::string(i == bank_property_ ? " chosen" : "") + "\"><span class=\"name\" title=\"" + esc(item.at("name").get<std::string>()) + "\">" + esc(calm_name(item.at("name").get<std::string>())) +
|
||||
"</span><div class=\"bank-part-track\"><div style=\"width:" + scalar(item.at("price").get<int64_t>() * 100.0 / dearest) + "%;\"></div></div><span class=\"sum\">" +
|
||||
esc(bank_money(item.at("price").get<int64_t>())) + "</span></div>";
|
||||
}
|
||||
}
|
||||
out += "</div></div>";
|
||||
out += "<div class=\"property-card offered-property\"><h3>Kaufangebot " + std::to_string(bank_property_ + 1) + " von " + std::to_string(property_count) + "</h3>" +
|
||||
btn("property-next", img(engine_mode_ ? offer.at("image").get<std::string>() : "bank.property." + std::to_string(bank_property_), 1150, 653.5, false, false, 1400),
|
||||
"property-picture", "id=\"property-next\" aria-label=\"Nächstes Immobilienangebot\"") +
|
||||
"<h4>" + esc(calm_name(offer.at("name").get<std::string>())) + "</h4>" + fact("Kaufpreis", esc(bank_money(offer.at("price").get<int64_t>()))) +
|
||||
fact("Anteil am Konto", in_cash > 0 ? one(offer.at("price").get<int64_t>() * 100.0 / in_cash) + " %" : std::string("—")) +
|
||||
(offer.contains("maxToBuy") ? fact("Bezahlbar", number(offer.at("maxToBuy").get<int64_t>()) + " Stück") : std::string()) +
|
||||
"<p class=\"property-hint\">Das Bild anklicken, um das nächste Angebot zu sehen.</p></div>" +
|
||||
actions("Kaufen", "property-buy", "Verkaufen", "property-sell");
|
||||
} else if (bank_view_ == "stocks") {
|
||||
out += "<h2>Aktien</h2><div class=\"stock-table\"><div class=\"stock-row stock-head\">";
|
||||
for (const auto *label : {"Wert", "Kurs", "Vortag", "Bestand"}) out += "<div><span>" + std::string(label) + "</span></div>";
|
||||
const auto move = [&](double from, double to) {
|
||||
if (from <= 0) return std::string("<span class=\"stock-move flat\">—</span>");
|
||||
const double change = (to - from) * 100.0 / from;
|
||||
return std::string("<span class=\"stock-move ") + (change > 0.05 ? "up" : change < -0.05 ? "down" : "flat") + "\">" +
|
||||
(change > 0.05 ? "▲ +" : change < -0.05 ? "▼ −" : "") + one(std::abs(change)) + " %</span>";
|
||||
};
|
||||
out += "<div class=\"stock-table\"><div class=\"stock-row stock-head\">";
|
||||
for (const auto *label : {"Wert", "30 Tage", "Kurs", "zum Vortag", "Bestand"}) out += "<div><span>" + std::string(label) + "</span></div>";
|
||||
out += "</div>";
|
||||
const auto factor = engine_mode_ ? 100 : finance_currency_factor(*world_);
|
||||
for (int i = 0; i < stock_count; ++i) {
|
||||
const auto &s = assets.at("stocks")[size_t(i)];
|
||||
out += "<div class=\"stock-row\"><div>" + btn("bank-stock", esc(s.at("name").get<std::string>()), "stock-name",
|
||||
const auto history = course(i);
|
||||
std::string spark = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 240 60\">";
|
||||
if (history.size() > 1) {
|
||||
const double lo = *std::min_element(history.begin(), history.end()), hi = std::max(lo + .01, *std::max_element(history.begin(), history.end()));
|
||||
std::string points;
|
||||
for (size_t at = 0; at < history.size(); ++at) points += scalar(4 + at * 232.0 / (history.size() - 1)) + "," + scalar(54 - (history[at] - lo) / (hi - lo) * 48) + " ";
|
||||
spark += "<polyline points=\"" + points + "\" fill=\"none\" stroke=\"" + (history.back() >= history.front() ? up : down) + "\" stroke-width=\"4\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/>";
|
||||
}
|
||||
spark += "</svg>";
|
||||
out += "<div class=\"stock-row" + std::string(i == bank_stock_ ? " chosen" : "") + "\"><div>" + btn("bank-stock", esc(s.at("name").get<std::string>()), "stock-name",
|
||||
"id=\"bank-stock-" + std::to_string(i) + "\" data-bank-stock=\"" + std::to_string(i) + "\" data-id=\"" + std::to_string(i) +
|
||||
"\" aria-pressed=\"" + (i == bank_stock_ ? "true" : "false") + "\"") + "</div><div><span>" +
|
||||
number(s.at("price").get<int64_t>() / factor) + "</span></div><div><span>" + number(s.at("previous").get<int64_t>() / factor) +
|
||||
"</span></div><div><span>" + number(finance.at("stocks")[size_t(i)].get<int64_t>()) + "</span></div></div>";
|
||||
"\" aria-pressed=\"" + (i == bank_stock_ ? "true" : "false") + "\"") + "</div><div>" + picture(renderer_.diagram("bank-spark-" + std::to_string(i), spark, 480), 240, 60) +
|
||||
"</div><div><span>" + number(s.at("price").get<int64_t>() / factor) + "</span></div><div>" + move(s.at("previous").get<double>(), s.at("price").get<double>()) +
|
||||
"</div><div><span>" + number(finance.at("stocks")[size_t(i)].get<int64_t>()) + "</span></div></div>";
|
||||
}
|
||||
const double price = assets.at("stocks")[size_t(bank_stock_)].at("price").get<double>() / factor;
|
||||
std::vector<double> history;
|
||||
if (engine_mode_) {
|
||||
for (const auto &value : assets.at("stocks")[size_t(bank_stock_)].at("history")) history.push_back(value.get<double>() / factor);
|
||||
} else for (int i = 0; i < 30; ++i) history.push_back(price * (.85 + .08 * std::sin(i * .6 + bank_stock_) + i * .003));
|
||||
const double lo = history.empty() ? 0 : *std::min_element(history.begin(), history.end()) * .95;
|
||||
const double hi = history.empty() ? 1 : std::max(lo + 1., *std::max_element(history.begin(), history.end()) * 1.05);
|
||||
std::string points;
|
||||
for (size_t i = 0; i < history.size(); ++i) points += scalar(20 + i * 690. / std::max<size_t>(1, history.size() - 1)) + "," + scalar(900 - (history[size_t(i)] - lo) / (hi - lo) * 830) + " ";
|
||||
const auto stroke = theme_ == "silver" ? "#526779" : theme_ == "matchday" ? "#b7b4b9" : "#9ac7d8";
|
||||
const auto axis = theme_ == "silver" ? "#526779" : theme_ == "matchday" ? "#b7b4b9" : "#6c8798";
|
||||
const auto svg = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"740\" height=\"1320\" viewBox=\"0 0 740 950\">"
|
||||
"<path d=\"M10 10V930H730\" fill=\"none\" stroke=\"" + std::string(axis) + "\" stroke-width=\"5\"/>"
|
||||
"<polyline points=\"" + points + "\" fill=\"none\" stroke=\"" + stroke + "\" stroke-width=\"9\"/></svg>";
|
||||
out += "</div><div class=\"stock-chart\" role=\"img\" aria-label=\"" + std::string(engine_mode_ ? "Kursverlauf aus dem Spielstand für " : "Erfundener Kursverlauf für ") +
|
||||
esc(assets.at("stocks")[size_t(bank_stock_)].at("name").get<std::string>()) + "\">" +
|
||||
picture(renderer_.diagram("bank-stock", svg, 1600), 740, 1320) + "</div>" + actions("Kaufen", "stock-buy", "Verkaufen", "stock-sell");
|
||||
out += "</div>";
|
||||
// the chosen stock: its course with a five-day average, its range, and what the numbers say
|
||||
const auto &chosen = assets.at("stocks")[size_t(bank_stock_)];
|
||||
const auto history = course(bank_stock_);
|
||||
const double price = chosen.at("price").get<double>() / factor;
|
||||
out += "<div class=\"stock-detail\"><h3>" + esc(chosen.at("name").get<std::string>()) + "</h3><div class=\"stock-quote\"><strong>" + number(chosen.at("price").get<int64_t>() / factor) +
|
||||
"</strong>" + move(chosen.at("previous").get<double>(), chosen.at("price").get<double>()) + "</div>";
|
||||
if (history.size() > 1) {
|
||||
const double lo = *std::min_element(history.begin(), history.end()), hi = *std::max_element(history.begin(), history.end());
|
||||
const double floor = lo * .97, ceiling = std::max(floor + 1., hi * 1.03);
|
||||
const auto px = [&](size_t at) { return 30 + at * 860.0 / (history.size() - 1); };
|
||||
const auto py = [&](double value) { return 470 - (value - floor) / (ceiling - floor) * 430; };
|
||||
std::string svg = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 920 500\"><defs><linearGradient id=\"under\" x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\"><stop offset=\"0\" stop-color=\"" +
|
||||
line + "\" stop-opacity=\".32\"/><stop offset=\"1\" stop-color=\"" + line + "\" stop-opacity=\".02\"/></linearGradient></defs>";
|
||||
for (int row = 0; row < 5; ++row) svg += "<line x1=\"30\" y1=\"" + scalar(40 + row * 107.5) + "\" x2=\"890\" y2=\"" + scalar(40 + row * 107.5) + "\" stroke=\"" + faint + "\" stroke-width=\"2\"/>";
|
||||
std::string points, average;
|
||||
size_t high_at = 0, low_at = 0;
|
||||
for (size_t at = 0; at < history.size(); ++at) {
|
||||
points += scalar(px(at)) + "," + scalar(py(history[at])) + " ";
|
||||
if (history[at] > history[high_at]) high_at = at;
|
||||
if (history[at] < history[low_at]) low_at = at;
|
||||
if (at >= 4) {
|
||||
double sum = 0;
|
||||
for (size_t back = 0; back < 5; ++back) sum += history[at - back];
|
||||
average += scalar(px(at)) + "," + scalar(py(sum / 5)) + " ";
|
||||
}
|
||||
}
|
||||
svg += "<polygon points=\"30,470 " + points + "890,470\" fill=\"url(#under)\"/><polyline points=\"" + average + "\" fill=\"none\" stroke=\"" + gold +
|
||||
"\" stroke-width=\"4\" stroke-dasharray=\"12 9\"/><polyline points=\"" + points + "\" fill=\"none\" stroke=\"" + line +
|
||||
"\" stroke-width=\"6\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/><circle cx=\"" + scalar(px(high_at)) + "\" cy=\"" + scalar(py(history[high_at])) +
|
||||
"\" r=\"9\" fill=\"" + up + "\"/><circle cx=\"" + scalar(px(low_at)) + "\" cy=\"" + scalar(py(history[low_at])) + "\" r=\"9\" fill=\"" + down +
|
||||
"\"/><circle cx=\"" + scalar(px(history.size() - 1)) + "\" cy=\"" + scalar(py(history.back())) + "\" r=\"10\" fill=\"" + line + "\" stroke=\"" + ink + "\" stroke-width=\"3\"/></svg>";
|
||||
double mean = 0, spread = 0;
|
||||
for (const double value : history) mean += value;
|
||||
mean /= double(history.size());
|
||||
for (const double value : history) spread += (value - mean) * (value - mean);
|
||||
spread = mean > 0 ? std::sqrt(spread / double(history.size())) * 100.0 / mean : 0;
|
||||
const double trend = history.front() > 0 ? (history.back() - history.front()) * 100.0 / history.front() : 0;
|
||||
const double below = hi > 0 ? (hi - history.back()) * 100.0 / hi : 0;
|
||||
const auto held = finance.at("stocks")[size_t(bank_stock_)].get<int64_t>();
|
||||
const auto tile = [](const std::string &label, const std::string &value, const char *tone = "") {
|
||||
return "<div class=\"stock-tile " + std::string(tone) + "\"><strong>" + value + "</strong><span>" + label + "</span></div>";
|
||||
};
|
||||
out += "<div class=\"stock-chart\" role=\"img\" aria-label=\"" + std::string(engine_mode_ ? "Kursverlauf aus dem Spielstand für " : "Erfundener Kursverlauf für ") +
|
||||
esc(chosen.at("name").get<std::string>()) + "\">" + picture(renderer_.diagram("bank-stock", svg, 1840), 920, 500) + "</div>"
|
||||
"<div class=\"stock-legend\"><span class=\"key course\"></span><span>Kurs</span><span class=\"key average\"></span><span>Fünf-Tage-Schnitt</span><span class=\"key high\"></span><span>Hoch</span><span class=\"key low\"></span><span>Tief</span></div>"
|
||||
"<div class=\"stock-tiles\">" +
|
||||
tile("Hoch", number(int64_t(std::llround(hi)))) + tile("Tief", number(int64_t(std::llround(lo)))) +
|
||||
tile(std::to_string(history.size()) + " Tage", (trend > 0 ? "+" : trend < 0 ? "−" : "") + one(std::abs(trend)) + " %", trend > 0.05 ? "up" : trend < -0.05 ? "down" : "") +
|
||||
tile("Schwankung", one(spread) + " %") + tile("Depotwert", esc(bank_money(held * chosen.at("price").get<int64_t>()))) +
|
||||
(chosen.contains("maxToBuy") ? tile("Kaufbar", number(chosen.at("maxToBuy").get<int64_t>())) : tile("Bestand", number(held))) + "</div>"
|
||||
"<div class=\"bank-insight\"><h4>Analyse</h4><p>" +
|
||||
std::string(trend > 5 ? "Aufwärtstrend: " : trend < -5 ? "Abwärtstrend: " : "Seitwärtsbewegung: ") + "über " + std::to_string(history.size()) + " Tage " +
|
||||
(trend > 0 ? "+" : trend < 0 ? "−" : "") + one(std::abs(trend)) + " %. " +
|
||||
(below < 0.5 ? "Der Kurs steht am Hoch dieses Zeitraums." : "Der Kurs liegt " + one(below) + " % unter dem Hoch dieses Zeitraums.") + " " +
|
||||
(spread > 12 ? "Das Papier schwankt stark." : spread > 5 ? "Das Papier schwankt mäßig." : "Das Papier läuft ruhig.") + "</p></div>";
|
||||
(void)price;
|
||||
} else out += "<p class=\"player-card-none\">Für dieses Papier liegt noch kein Kursverlauf vor.</p>";
|
||||
out += "</div>" + actions("Kaufen", "stock-buy", "Verkaufen", "stock-sell");
|
||||
} else if (bank_view_ == "credit") {
|
||||
if (engine_mode_) return out + engine_credit_view() + "</section></div>";
|
||||
out += "<h2>Kredit</h2><div class=\"credit-portrait\">" + img("art.bank-adviser-v1.png", 620, 515, false, false, 1000) +
|
||||
out += "<div class=\"credit-portrait\">" + img("art.bank-adviser-v1.png", 620, 515, false, false, 1000) +
|
||||
"</div><div class=\"credit-facts\">";
|
||||
const auto fact = [&](const char *label, const std::string &value, int row) {
|
||||
constexpr std::array<int, 5> y{0, 83, 166, 273, 356};
|
||||
@@ -116,16 +244,13 @@ std::string App::render_bank() {
|
||||
fact("Maximaler Kredit", esc(bank_money(5000000 * finance_currency_factor(*world_))), 4) + "</div>";
|
||||
const int term = finance.at("term");
|
||||
const auto principal = summary.at("schedule_principal").get<int64_t>();
|
||||
const auto color = theme_ == "silver" ? "#233443" : theme_ == "matchday" ? "#efeded" : "#a8c0cf";
|
||||
const auto accent = theme_ == "silver" ? "#25617a" : theme_ == "matchday" ? "#efb2aa" : "#a9dfd1";
|
||||
const auto grid_color = theme_ == "silver" ? "#58738c38" : "#b7d0de24";
|
||||
std::string svg = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"2240\" height=\"420\" viewBox=\"0 0 2240 420\">"
|
||||
"<defs><linearGradient id=\"fill\" x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\"><stop offset=\"0\" stop-color=\"#9ddbd1\" stop-opacity=\".23\"/>"
|
||||
"<stop offset=\"1\" stop-color=\"#9ddbd1\" stop-opacity=\".01\"/></linearGradient></defs>";
|
||||
"<defs><linearGradient id=\"fill\" 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=\".02\"/></linearGradient></defs>";
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
const auto y = 30 + i * 77.5;
|
||||
svg += "<line x1=\"220\" y1=\"" + scalar(y) + "\" x2=\"2180\" y2=\"" + scalar(y) + "\" stroke=\"" + grid_color + "\" stroke-width=\"2\"/>"
|
||||
"<text x=\"184\" y=\"" + scalar(y + 9) + "\" text-anchor=\"end\" fill=\"" + color + "\" font-size=\"28\" font-family=\"Arial, Liberation Sans, sans-serif\">" +
|
||||
svg += "<line x1=\"220\" y1=\"" + scalar(y) + "\" x2=\"2180\" y2=\"" + scalar(y) + "\" stroke=\"" + faint + "\" stroke-width=\"2\"/>"
|
||||
"<text x=\"184\" y=\"" + scalar(y + 9) + "\" text-anchor=\"end\" fill=\"" + ink + "\" font-size=\"28\" font-family=\"Arial, Liberation Sans, sans-serif\">" +
|
||||
esc(bank_money((principal * (4 - i) + 2) / 4)) + "</text>";
|
||||
}
|
||||
const int interval = term <= 12 ? 3 : term <= 24 ? 6 : 12;
|
||||
@@ -134,15 +259,15 @@ std::string App::render_bank() {
|
||||
if (labels.back() != term) labels.push_back(term);
|
||||
for (const int month : labels) {
|
||||
svg += "<text x=\"" + scalar(220 + double(month) / term * 1960) + "\" y=\"394\" text-anchor=\"" +
|
||||
std::string(month == 0 ? "start" : month == term ? "end" : "middle") + "\" fill=\"" + color +
|
||||
std::string(month == 0 ? "start" : month == term ? "end" : "middle") + "\" fill=\"" + ink +
|
||||
"\" font-size=\"28\" font-family=\"Arial, Liberation Sans, sans-serif\">" + (month == 0 ? "Heute" : std::to_string(month) + (month == term ? " Monate" : "")) + "</text>";
|
||||
}
|
||||
std::string points;
|
||||
for (const auto &point : summary.at("schedule")) points += scalar(220 + point.at("month").get<double>() / term * 1960) + "," +
|
||||
scalar(340 - point.at("remaining").get<double>() / principal * 310) + " ";
|
||||
svg += "<path d=\"M220 340 L220 30 L2180 340 Z\" fill=\"url(#fill)\"/><polyline points=\"" + points + "\" fill=\"none\" stroke=\"" +
|
||||
accent + "\" stroke-width=\"6\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/><circle cx=\"220\" cy=\"30\" r=\"7\" fill=\"#c1ecdf\" stroke=\"#294553\" stroke-width=\"4\"/>"
|
||||
"<circle cx=\"2180\" cy=\"340\" r=\"7\" fill=\"#c1ecdf\" stroke=\"#294553\" stroke-width=\"4\"/></svg>";
|
||||
line + "\" stroke-width=\"6\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/><circle cx=\"220\" cy=\"30\" r=\"9\" fill=\"" + gold + "\"/>"
|
||||
"<circle cx=\"2180\" cy=\"340\" r=\"9\" fill=\"" + gold + "\"/></svg>";
|
||||
out += "<figure class=\"credit-schedule\"><div class=\"credit-schedule-caption\"><h3>Restschuld über die Laufzeit</h3><p class=\"credit-schedule-amount\">" +
|
||||
esc(bank_money(principal)) + " <span>→</span> " + esc(bank_money(0)) + "</p><div class=\"credit-schedule-context\"><span>" + std::to_string(term) +
|
||||
" Monate</span><p>" + (summary.at("schedule_example") == true ? "Beispiel · kein laufender Kredit" : "Aktueller Kredit") +
|
||||
@@ -151,23 +276,69 @@ std::string App::render_bank() {
|
||||
"</div><p class=\"credit-schedule-note\">Gleichmäßige monatliche Tilgung · Restschuld ohne Zinsen</p></figure>"
|
||||
"<p class=\"bank-note credit-note\">Fiktiver Kredit. Im POC erfolgen keine Zins- oder Ratenbuchungen.</p>" + actions("Aufnehmen", "loan", "Tilgen", "repay");
|
||||
} else if (bank_view_ == "overview") {
|
||||
out += "<h2>Finanzübersicht</h2><div class=\"bank-overview\">";
|
||||
if (engine_mode_) {
|
||||
const std::array<std::pair<const char *, const char *>, 5> fields{{{"Konto", "cash"}, {"Sparbuch", "deposit"}, {"Immobilien", "properties"}, {"Aktien", "stocks"}, {"Kreditlinie", "credit_line"}}};
|
||||
for (const auto &[label, key] : fields) {
|
||||
const auto value = summary.at(key).get<int64_t>();
|
||||
out += "<div class=\"bank-overview-row\"><span>" + std::string(label) + "</span><strong class=\"" + money_classes(value) + "\">" + esc(bank_money(value)) + "</strong></div>";
|
||||
}
|
||||
return out + "</div><p class=\"bank-note overview-note\">Bestände und Kurse aus dem Spielstand · Kredite beim Bankberater.</p></section></div>";
|
||||
// where the money lies: a ring by share, the four places with their sums, and a reading of it
|
||||
struct Part { const char *label; int64_t value; const char *colour; };
|
||||
const std::array<Part, 4> parts{{{"Konto", std::max<int64_t>(0, in_cash), "#2f6f8f"}, {"Sparbuch", in_deposit, "#c9a24a"},
|
||||
{"Immobilien", in_property, "#6f8a52"}, {"Aktien", in_stock, "#a8574f"}}};
|
||||
const double around = 2 * 3.14159265358979 * 300;
|
||||
std::string ring = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 800 800\"><circle cx=\"400\" cy=\"400\" r=\"300\" fill=\"none\" stroke=\"" + faint + "\" stroke-width=\"110\"/>";
|
||||
double turned = 0;
|
||||
for (const auto &part : parts) {
|
||||
if (wealth <= 0 || part.value <= 0) continue;
|
||||
const double length = around * double(part.value) / double(wealth);
|
||||
if (part.value == wealth) { ring += "<circle cx=\"400\" cy=\"400\" r=\"300\" fill=\"none\" stroke=\"" + std::string(part.colour) + "\" stroke-width=\"110\"/>"; break; }
|
||||
ring += "<circle cx=\"400\" cy=\"400\" r=\"300\" fill=\"none\" stroke=\"" + std::string(part.colour) + "\" stroke-width=\"110\" stroke-dasharray=\"" + scalar(length) + " " +
|
||||
scalar(around - length) + "\" stroke-dashoffset=\"" + scalar(-turned) + "\" transform=\"rotate(-90 400 400)\"/>";
|
||||
turned += length;
|
||||
}
|
||||
const std::array<std::pair<const char *, int64_t>, 6> fields{{
|
||||
{"Konto", summary.at("cash")}, {"Sparbuch", summary.at("deposit")},
|
||||
{"Immobilien", summary.at("properties")}, {"Aktien", summary.at("stocks")},
|
||||
{"Kredit", -summary.at("debt").get<int64_t>()}, {"Saldo", summary.at("net")}}};
|
||||
for (size_t i = 0; i < fields.size(); ++i)
|
||||
out += "<div class=\"bank-overview-row " + std::string(i == 5 ? "bank-overview-total" : "") + "\"><span>" +
|
||||
fields[i].first + "</span><strong>" + (i == 4 ? "-" + esc(bank_money(summary.at("debt").get<int64_t>())) : esc(bank_money(fields[i].second))) + "</strong></div>";
|
||||
out += "</div><p class=\"bank-note overview-note\">Erfundene Bestände · Änderungen betreffen ausschließlich die Bankvorschau.</p>";
|
||||
ring += "</svg>";
|
||||
out += "<div class=\"bank-ring\">" + picture(renderer_.diagram("bank-ring", ring, 1600), 860, 860) + "<div class=\"bank-ring-centre\"><span>Vermögen</span><strong>" +
|
||||
esc(bank_money(wealth)) + "</strong></div></div><div class=\"bank-parts\">";
|
||||
const Part *largest = &parts[0];
|
||||
for (const auto &part : parts) {
|
||||
if (part.value > largest->value) largest = ∂
|
||||
const double width = wealth > 0 ? std::max<int64_t>(0, part.value) * 100.0 / wealth : 0;
|
||||
out += "<div class=\"bank-part\"><div class=\"bank-part-line\"><span class=\"chip\" style=\"background-color:" + std::string(part.colour) + ";\"></span><span class=\"label\">" + part.label +
|
||||
"</span><strong>" + esc(bank_money(std::string(part.label) == "Konto" ? in_cash : part.value)) + "</strong><span class=\"share\">" + share(part.value) +
|
||||
"</span></div><div class=\"bank-part-track\"><div style=\"width:" + scalar(width) + "%;background-color:" + part.colour + ";\"></div></div></div>";
|
||||
}
|
||||
if (engine_mode_)
|
||||
out += "<div class=\"bank-part plain\"><div class=\"bank-part-line\"><span class=\"chip none\"></span><span class=\"label\">Kreditlinie</span><strong>" +
|
||||
esc(bank_money(summary.at("credit_line").get<int64_t>())) + "</strong><span class=\"share\"></span></div></div>";
|
||||
else
|
||||
out += "<div class=\"bank-part plain\"><div class=\"bank-part-line\"><span class=\"chip none\"></span><span class=\"label\">Kredit</span><strong>−" +
|
||||
esc(bank_money(summary.at("debt").get<int64_t>())) + "</strong><span class=\"share\"></span></div></div>"
|
||||
"<div class=\"bank-part plain\"><div class=\"bank-part-line\"><span class=\"chip none\"></span><span class=\"label\">Saldo</span><strong>" +
|
||||
esc(bank_money(summary.at("net").get<int64_t>())) + "</strong><span class=\"share\"></span></div></div>";
|
||||
out += "</div><div class=\"bank-insight overview-insight\"><h4>Analyse</h4><p>";
|
||||
if (wealth > 0) {
|
||||
const int64_t invested = in_deposit + in_property + in_stock;
|
||||
out += "Größter Posten: " + std::string(largest->label) + " mit " + share(largest->value) + " des Vermögens. " +
|
||||
(invested > 0 ? "Angelegt in Sparbuch, Immobilien und Aktien sind " + share(invested) + "."
|
||||
: std::string("Bisher ist nichts angelegt: Das ganze Vermögen liegt auf dem Konto."));
|
||||
} else out += "Es ist kein Vermögen vorhanden.";
|
||||
out += "</p></div>";
|
||||
// the market at a glance: every stock's change over its recorded days
|
||||
std::vector<std::pair<std::string, double>> market;
|
||||
double widest = 1;
|
||||
for (int i = 0; i < stock_count; ++i) {
|
||||
const auto history = course(i);
|
||||
if (history.size() < 2 || history.front() <= 0) continue;
|
||||
const double change = (history.back() - history.front()) * 100.0 / history.front();
|
||||
market.emplace_back(assets.at("stocks")[size_t(i)].at("name").get<std::string>(), change);
|
||||
widest = std::max(widest, std::abs(change));
|
||||
}
|
||||
if (!market.empty()) {
|
||||
out += "<div class=\"bank-market\"><h4>Aktienmarkt · Veränderung über die aufgezeichneten Tage</h4><div class=\"bank-market-bars\">";
|
||||
for (const auto &[name, change] : market) {
|
||||
const double height = std::abs(change) / widest * 120;
|
||||
out += "<div class=\"bank-market-column\"><div class=\"rise\">" + (change > 0 ? "<span>+" + one(change) + " %</span><div class=\"bar up\" style=\"height:" + scalar(height) + "dp;\"></div>" : std::string()) +
|
||||
"</div><div class=\"fall\">" + (change <= 0 ? "<div class=\"bar down\" style=\"height:" + scalar(height) + "dp;\"></div><span>−" + one(std::abs(change)) + " %</span>" : std::string()) +
|
||||
"</div><strong>" + esc(name) + "</strong></div>";
|
||||
}
|
||||
out += "</div></div>";
|
||||
}
|
||||
out += "<p class=\"bank-note overview-note\">" + std::string(engine_mode_ ? "Bestände und Kurse aus dem Spielstand." : "Erfundene Bestände · Änderungen betreffen ausschließlich die Bankvorschau.") + "</p>";
|
||||
}
|
||||
return out + "</section></div>";
|
||||
}
|
||||
@@ -53,7 +53,7 @@ void App::engine_balance_preview(const EngineReply &reply) {
|
||||
engine_balance_base_ = read;
|
||||
balance_future_ = true;
|
||||
engine_balance_feedback_ = engine_balance_edits_.empty()
|
||||
? "Prognose der Engine für zwölf Monate."
|
||||
? "Prognose für zwölf Monate."
|
||||
: "Planentwurf · Noch nicht übernommen.";
|
||||
focus_after_render_ = "balance-toggle";
|
||||
}
|
||||
|
||||
@@ -98,22 +98,44 @@ bool App::engine_bank_action(const std::string &action, Rml::Element *target) {
|
||||
open_amount(std::move(request)); return true;
|
||||
}
|
||||
std::string App::engine_credit_view() {
|
||||
std::string out = "<h2>Kredit</h2><div class=\"credit-portrait\">" + img("art.bank-adviser-v1.png", 620, 515, false, false, 1000) + "</div>";
|
||||
std::string out = "<div class=\"credit-portrait\">" + img("art.bank-adviser-v1.png", 620, 515, false, false, 1000) + "</div>";
|
||||
Json data;
|
||||
try { data = engine_credit_projection(engine_data_, engine_credit_); }
|
||||
catch (const std::exception &) { return out + "<p class=\"bank-note\">Der Bankkredit ist in diesem Kontext nicht verfügbar.</p>"; }
|
||||
out += "<div class=\"credit-facts\" style=\"top:135dp;height:520dp;\">";
|
||||
// the original's labels arrive in capitals: one capital per word reads calmer
|
||||
const auto calm = [](std::string text) {
|
||||
bool first = true;
|
||||
for (size_t i = 0; i < text.size(); ++i) {
|
||||
const unsigned char c = static_cast<unsigned char>(text[i]);
|
||||
if (c == 0xc3 && i + 1 < text.size()) {
|
||||
unsigned char next = static_cast<unsigned char>(text[i + 1]);
|
||||
if (!first && (next == 0x84 || next == 0x96 || next == 0x9c)) text[i + 1] = static_cast<char>(next + 0x20);
|
||||
++i; first = false;
|
||||
} else if (std::isalpha(c)) { if (!first) text[i] = static_cast<char>(std::tolower(c)); first = false; }
|
||||
else if (c == ' ' || c == '-') first = true;
|
||||
}
|
||||
return text;
|
||||
};
|
||||
out += "<div class=\"credit-facts engine-credit\">";
|
||||
int64_t total = 0, paid = 0;
|
||||
for (size_t i = 0; i < 8; ++i) {
|
||||
const auto &f = data.at("fields")[i]; const auto value = f.at("value").get<int64_t>();
|
||||
if (i == 1) total = value;
|
||||
if (i == 5) paid = value;
|
||||
const auto text = i == 3 || i == 4 ? number(value) + " Monate" : money(value * 100, {{"code", "EUR"}, {"minor_units", 2}});
|
||||
out += "<div class=\"credit-fact\" style=\"top:" + std::to_string(i * 65) + "dp;font-size:30dp;\"><span>" + esc(engine_text(f.at("label"))) + "</span><strong>";
|
||||
if (data.at("saved")[0] == 0 && f.at("editable") == true) out += btn("engine-credit-edit", esc(text), "bank-control", "id=\"engine-credit-" + std::to_string(i) + "\" data-id=\"" + std::to_string(i) + "\" style=\"width:780dp;height:56dp;font-size:30dp;\"");
|
||||
out += "<div class=\"credit-fact\" style=\"top:" + std::to_string(i * 64) + "dp;\"><span>" + esc(calm(engine_text(f.at("label")))) + "</span><strong>";
|
||||
if (data.at("saved")[0] == 0 && f.at("editable") == true) out += btn("engine-credit-edit", esc(text), "bank-control", "id=\"engine-credit-" + std::to_string(i) + "\" data-id=\"" + std::to_string(i) + "\"");
|
||||
else out += esc(text);
|
||||
out += "</strong></div>";
|
||||
}
|
||||
out += "</div><figure class=\"credit-schedule\"><div class=\"credit-schedule-caption\"><h3>Kreditvorschau</h3></div>";
|
||||
out += "<div style=\"position:absolute;top:140dp;left:60dp;right:60dp;font-size:39dp;line-height:1.8;\"><p>Gebühren: " + esc(engine_price(data.at("fees"))) + "</p><p>Erstattung: " + esc(engine_price(data.at("refund"))) + "</p><p>Bereits getilgter Betrag: " + esc(engine_price(data.at("principalPaid"))) + "</p></div>";
|
||||
out += "<p class=\"credit-schedule-note\">" + std::string(data.at("saved")[0] == 0 ? "Die Engine berechnet Laufzeit, Raten und Gebühren. Änderungen erst nach Bestätigung." : "Laufender Kredit · Änderungen folgen mit vollständiger Gebührenvorschau.") + "</p></figure>";
|
||||
out += "</div><figure class=\"credit-schedule engine-credit\"><div class=\"credit-schedule-caption\"><h3>Kreditvorschau</h3></div><div class=\"stock-tiles credit-tiles\">";
|
||||
for (const auto &[label, key] : std::array<std::pair<const char *, const char *>, 3>{{{"Gebühren", "fees"}, {"Erstattung", "refund"}, {"Bereits getilgt", "principalPaid"}}})
|
||||
out += "<div class=\"stock-tile\"><strong>" + esc(engine_price(data.at(key))) + "</strong><span>" + label + "</span></div>";
|
||||
// how much of the whole sum is paid back
|
||||
const double done = total > 0 ? std::clamp(double(paid) * 100.0 / double(total), 0.0, 100.0) : 0;
|
||||
out += "</div><div class=\"credit-progress\"><div class=\"credit-progress-label\"><span>Zurückgezahlt</span><strong>" + (total > 0 ? std::to_string(int(std::lround(done))) + " %" : std::string("kein Kredit")) +
|
||||
"</strong></div><div class=\"bank-part-track\"><div style=\"width:" + scalar(done) + "%;\"></div></div></div>";
|
||||
out += "<p class=\"credit-schedule-note\">" + std::string(data.at("saved")[0] == 0 ? "Die Bank berechnet Laufzeit, Raten und Gebühren. Gebucht wird erst nach deiner Bestätigung." : "Laufender Kredit · Änderungen folgen mit vollständiger Gebührenvorschau.") + "</p></figure>";
|
||||
out += "<nav class=\"bank-actions\">" + btn("engine-credit-reset", "Zurücksetzen", "bank-control", "id=\"engine-credit-reset\"") + btn("engine-credit-apply", "Verbindlich buchen", "bank-control", "id=\"engine-credit-apply\" " + std::string(engine_credit_edits_.empty() ? "disabled" : "")) + "</nav>";
|
||||
return out;
|
||||
}
|
||||
@@ -552,7 +552,7 @@ std::string App::render_transfer_dialog() {
|
||||
std::to_string(i) + "\"") +
|
||||
"</div>";
|
||||
body += "</div></section><p class=\"transfer-offer-note\">" +
|
||||
std::string(engine_mode_ ? "Die Engine entscheidet nach Bestätigung über dieses Angebot. Die Konditionen werden erst beim Absenden verbindlich." : mine ? "Der Spieler wird zum " +
|
||||
std::string(engine_mode_ ? "Über das Angebot wird nach deiner Bestätigung entschieden. Die Konditionen werden erst beim Absenden verbindlich." : mine ? "Der Spieler wird zum " +
|
||||
std::string(loan ? "Verleihen" : "Verkauf") +
|
||||
" auf dem Markt vorgemerkt."
|
||||
: "Das Angebot wird vorgemerkt; die Entscheidung "
|
||||
|
||||
Reference in new issue
Block a user