Bind confirmed bank and ticket actions to real careers (by Codex)

This commit is contained in:
Codex committed 2026-10-28 11:04:11 +01:00
1 parent f75e0f8e49
commit dcf42f2da7
23 files changed
+535 -56

No files matched your search

+3 -3
View File
@@ -19,13 +19,13 @@ std::string App::amount_error() const {
return {};
}
void App::open_amount(AmountRequest request) {
if (!source_) return;
if (!source_ && !engine_mode_) return;
close_report_picker(false);
request.step = std::max<int64_t>(1, request.step);
request.suggestion_step = std::max<int64_t>(1, request.suggestion_step);
if (request.return_focus.empty() && context_->GetFocusElement())
request.return_focus = context_->GetFocusElement()->GetId();
amount_ = AmountDraft{std::move(request), {}, {}, menu_, false, snap().revision, world_};
amount_ = AmountDraft{std::move(request), {}, {}, menu_, false, input_revision(), world_};
amount_->raw = std::to_string(amount_->request.value);
amount_select_all_ = true;
amount_caret_end_ = false;
@@ -135,7 +135,7 @@ bool App::amount_action(const std::string &action, Rml::Element *target) {
}
if (action == "calc-confirm") {
if (!amount_error().empty()) return true;
if (world_ != amount_->world || !source_ || snap().revision != amount_->revision) {
if (world_ != amount_->world || (!source_ && !engine_mode_) || input_revision() != amount_->revision) {
amount_->error = "Die Daten haben sich geändert. Bitte die Eingabe schließen und neu öffnen.";
if (amount_->review) refresh(); else update_amount();
return true;
+9 -7
View File
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-only
bool App::bank_action(const std::string &action, Rml::Element *target) {
if (menu_ != "bank" || !source_ || !world_) return false;
if (menu_ != "bank" || (!source_ && !engine_mode_) || !world_) return false;
if (action == "close") {
if (bank_view_ == "entrance") return false;
bank_view_ = "entrance";
@@ -20,16 +20,17 @@ bool App::bank_action(const std::string &action, Rml::Element *target) {
}
if (action == "property-next") {
if (bank_view_ != "properties") return true;
bank_property_ = (bank_property_ + 1) % 6;
bank_property_ = (bank_property_ + 1) % (engine_mode_ ? int(engine_bank_projection(engine_data_).at("assets").at("properties").size()) : 6);
focus_after_render_ = "property-next";
refresh();
return true;
}
if (action == "property-owned-next") {
if (bank_view_ != "properties") return true;
const auto state = snap().state;
for (int step = 1; step <= 6; ++step) {
const int next = (bank_owned_ + step) % 6;
const auto state = engine_mode_ ? engine_bank_projection(engine_data_).at("state") : snap().state;
const int count = int(state.at("finance").at("properties").size());
for (int step = 1; step <= count; ++step) {
const int next = (bank_owned_ + step) % count;
if (state.at("finance").at("properties")[size_t(next)] != 0) { bank_owned_ = next; break; }
}
focus_after_render_ = "property-owned-next";
@@ -44,6 +45,7 @@ bool App::bank_action(const std::string &action, Rml::Element *target) {
refresh();
return true;
}
if (engine_mode_) return engine_bank_action(action, target);
if (action != "bank-calc" || !target) return false;
const auto kind = target->GetAttribute<Rml::String>("data-kind", "");
const bool property = kind == "property-buy" || kind == "property-sell";
@@ -94,7 +96,7 @@ bool App::bank_action(const std::string &action, Rml::Element *target) {
}
bool App::bank_event(Rml::Event &event) {
if (menu_ != "bank" || !source_ || amount_ || !popup_.empty()) return false;
if (menu_ != "bank" || (!source_ && !engine_mode_) || amount_ || !popup_.empty()) return false;
const auto type = event.GetType();
auto *target = event.GetTargetElement();
const bool keyboard = type == "keydown";
@@ -122,7 +124,7 @@ bool App::bank_event(Rml::Event &event) {
event.StopImmediatePropagation();
return true;
}
if (type == "change" && target->GetId() == "bank-term") {
if (!engine_mode_ && type == "change" && target->GetId() == "bank-term") {
auto *select = dynamic_cast<Rml::ElementFormControlSelect *>(target);
if (!select || bank_view_ != "credit" || snap().state.at("debt") != 0) return true;
const auto raw = select->GetValue();
+42 -27
View File
@@ -1,15 +1,18 @@
// SPDX-License-Identifier: GPL-3.0-only
std::string App::render_bank() {
const auto snapshot = snap();
const auto assets = demo_bank_assets(*world_);
const auto summary = demo_bank_summary(snapshot.state, *world_);
const auto projected = engine_mode_ ? engine_bank_projection(engine_data_) : Json();
const auto snapshot = engine_mode_ ? Snapshot{0, world_, projected.at("state")} : snap();
const auto assets = engine_mode_ ? projected.at("assets") : demo_bank_assets(*world_);
const auto summary = engine_mode_ ? projected.at("summary") : demo_bank_summary(snapshot.state, *world_);
const auto bank_money = [&](int64_t value) { return engine_mode_ ? money(value, {{"code", "EUR"}, {"minor_units", 2}}) : cash(value); };
const int property_count = int(assets.at("properties").size()), stock_count = int(assets.at("stocks").size());
if (!summary.value("ok", false)) return {};
const auto &finance = snapshot.state.at("finance");
bank_property_ = std::clamp(bank_property_, 0, 5);
bank_stock_ = std::clamp(bank_stock_, 0, 11);
bank_owned_ = std::clamp(bank_owned_, 0, 5);
bank_property_ = std::clamp(bank_property_, 0, property_count - 1);
bank_stock_ = std::clamp(bank_stock_, 0, stock_count - 1);
bank_owned_ = std::clamp(bank_owned_, 0, property_count - 1);
if (finance.at("properties")[size_t(bank_owned_)] == 0)
for (int i = 0; i < 6; ++i)
for (int i = 0; i < property_count; ++i)
if (finance.at("properties")[size_t(i)] != 0) { bank_owned_ = i; break; }
const auto actions = [&](const char *left, const char *lk, const char *right, const char *rk) {
return "<nav class=\"bank-actions\">" +
@@ -41,29 +44,29 @@ std::string App::render_bank() {
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\">Einzahlungen und Abhebungen werden hier als fiktive Vorschau verbucht.</p>"
"<p class=\"passbook-note-three\">2,5 % Beispielzins</p></div><div class=\"passbook-right\"><h2>Guthaben</h2><output>" +
esc(cash(snapshot.state.at("deposit").get<int64_t>())) + "</output></div></div>" + actions("Einzahlen", "deposit", "Abheben", "withdraw");
"<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");
} 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(cash(count * owned.at("price").get<int64_t>())) + "</p>" : "<p>Keine Immobilien im Bestand</p>") +
"</div>" + btn("property-owned-next", count ? img("bank.property." + std::to_string(bank_owned_), 996, 566, false, false, 1200)
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(cash(offer.at("price").get<int64_t>())) +
"</p></div>" + btn("property-next", img("bank.property." + std::to_string(bank_property_), 996, 566, false, false, 1200),
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>" +
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>";
out += "</div>";
const auto factor = finance_currency_factor(*world_);
for (int i = 0; i < 12; ++i) {
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",
"id=\"bank-stock-" + std::to_string(i) + "\" data-bank-stock=\"" + std::to_string(i) + "\" data-id=\"" + std::to_string(i) +
@@ -72,32 +75,36 @@ std::string App::render_bank() {
"</span></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::array<double, 30> history{};
for (int i = 0; i < 30; ++i) history[size_t(i)] = price * (.85 + .08 * std::sin(i * .6 + bank_stock_) + i * .003);
const double lo = *std::min_element(history.begin(), history.end()) * .95, hi = *std::max_element(history.begin(), history.end()) * 1.05;
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 (int i = 0; i < 30; ++i) points += scalar(20 + i * 690. / 29) + "," + scalar(900 - (history[size_t(i)] - lo) / (hi - lo) * 830) + " ";
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=\"Erfundener Kursverlauf für " +
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");
} 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) +
"</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};
return "<div class=\"credit-fact\" style=\"top:" + std::to_string(y[size_t(row)]) + "dp;\"><span>" + label + "</span><strong>" + value + "</strong></div>";
};
out += fact("Restschuld", esc(cash(summary.at("debt").get<int64_t>())), 0) + fact("Beispielzins", "8 % pro Jahr", 1);
out += fact("Restschuld", esc(bank_money(summary.at("debt").get<int64_t>())), 0) + fact("Beispielzins", "8 % pro Jahr", 1);
std::string select = "<select id=\"bank-term\" aria-label=\"Kreditlaufzeit\" " + std::string(summary.at("debt") == 0 ? "" : "disabled") + ">";
for (const auto &term : demo_bank_terms()) select += "<option value=\"" + std::to_string(term.get<int>()) + "\" " +
std::string(term == finance.at("term") ? "selected" : "") + ">" + std::to_string(term.get<int>()) + " Monate</option>";
out += fact("Laufzeit", select + "</select>", 2) + fact("Monatsrate, Beispiel", esc(cash(summary.at("monthly_rate").get<int64_t>())), 3) +
fact("Maximaler Kredit", esc(cash(5000000 * finance_currency_factor(*world_))), 4) + "</div>";
out += fact("Laufzeit", select + "</select>", 2) + fact("Monatsrate, Beispiel", esc(bank_money(summary.at("monthly_rate").get<int64_t>())), 3) +
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";
@@ -110,7 +117,7 @@ std::string App::render_bank() {
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\">" +
esc(cash((principal * (4 - i) + 2) / 4)) + "</text>";
esc(bank_money((principal * (4 - i) + 2) / 4)) + "</text>";
}
const int interval = term <= 12 ? 3 : term <= 24 ? 6 : 12;
std::vector<int> labels;
@@ -128,7 +135,7 @@ std::string App::render_bank() {
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>";
out += "<figure class=\"credit-schedule\"><div class=\"credit-schedule-caption\"><h3>Restschuld über die Laufzeit</h3><p class=\"credit-schedule-amount\">" +
esc(cash(principal)) + " <span>→</span> " + esc(cash(0)) + "</p><div class=\"credit-schedule-context\"><span>" + std::to_string(term) +
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") +
"</p></div></div><div class=\"credit-chart\" role=\"img\" aria-label=\"Restschuld über " + std::to_string(term) +
" Monate bei gleichmäßiger Tilgung ohne Zinsen\">" + picture(renderer_.diagram("bank-credit", svg, 2400), 2432, 420) +
@@ -136,13 +143,21 @@ std::string App::render_bank() {
"<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>";
}
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(cash(summary.at("debt").get<int64_t>())) : esc(cash(fields[i].second))) + "</strong></div>";
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>";
}
return out + "</section></div>";
+4 -1
View File
@@ -30,7 +30,7 @@ std::shared_ptr<EngineBridge> EngineBridge::open(const fs::path &world, const fs
}
Json EngineBridge::snapshot() const {
Json bundle = Json::object();
for (const auto *kind : {"session", "desktop", "camps", "squad", "lineup", "tactics", "training"})
for (const auto *kind : {"session", "desktop", "camps", "squad", "lineup", "tactics", "training", "bank", "stadium", "credit"})
bundle[kind] = from_engine(impl_->session->ui_read(cli::Json::Object{{"kind", kind}}, impl_->revision));
validate_engine_desk(bundle);
return bundle;
@@ -38,6 +38,9 @@ Json EngineBridge::snapshot() const {
Json EngineBridge::command(const Json &request) {
return from_engine(impl_->session->ui_command(cli::parse_json(request.dump()), impl_->revision));
}
Json EngineBridge::read(const Json &request) const {
return from_engine(impl_->session->ui_read(cli::parse_json(request.dump()), impl_->revision));
}
Json EngineBridge::save_copy(const fs::path &path) {
if (fs::weakly_canonical(path) == impl_->input || fs::exists(path))
throw editor::Error("Bitte eine neue Datei wählen. Der geladene Spielstand wird nicht überschrieben.");
+7
View File
@@ -19,6 +19,12 @@ Json engine_tactics_command(const Json &bundle, const Json &values,
const std::string &request_id);
Json engine_training_command(const Json &bundle, const Json &draft,
const std::string &request_id);
Json engine_bank_projection(const Json &bundle);
Json engine_bank_command(const Json &bundle, const Json &payload, const std::string &request_id);
Json engine_credit_projection(const Json &bundle, const Json &read);
Json engine_credit_command(const Json &bundle, const Json &read, const Json &edits, const std::string &request_id);
Json engine_ticket_projection(const Json &bundle);
Json engine_ticket_command(const Json &bundle, int euros, const std::string &request_id);
// Single-session facade. Its owner serializes all calls on a background worker.
// No RmlUI objects or callbacks cross this boundary.
@@ -27,6 +33,7 @@ public:
static std::shared_ptr<EngineBridge> open(const fs::path &world, const fs::path &save);
~EngineBridge();
Json snapshot() const;
Json read(const Json &request) const;
Json command(const Json &request);
Json save_copy(const fs::path &path);
private:
+34 -2
View File
@@ -12,6 +12,16 @@ void App::engine_poll() {
try {
auto result = engine_job_.get();
validate_engine_desk(result.bundle);
if (result.response.value("messageType", "") == "credit_preview") {
const auto &read = result.response.at("read");
if (read.value("messageType", "") == "error") engine_notice_ = "Kreditvorschau abgewiesen: " + read.value("code", "unknown_error");
else {
(void)engine_credit_projection(result.bundle, read);
engine_credit_ = read; engine_credit_edits_ = result.response.at("edits");
engine_notice_ = "Kreditvorschau berechnet · Noch keine Buchung.";
}
refresh(); return;
}
engine_fresh_ = true;
if (result.catalog) { world_ = std::move(result.catalog); bind_world(world_); }
engine_link_ = std::move(result.connection); engine_data_ = std::move(result.bundle);
@@ -25,6 +35,8 @@ void App::engine_poll() {
} else if (engine_response_.value("messageType", "") == "saved") {
engine_dirty_ = false; engine_notice_ = "Spielstand als neue OBS-Datei gespeichert.";
} else engine_notice_ = "Spielstand geladen · Weitere Menüs werden schrittweise angebunden.";
engine_credit_ = engine_data_.value("credit", Json()); engine_credit_edits_ = Json::array();
engine_ticket_bind();
engine_sports_reset();
const auto &f = engine_data_.at("camps").at("data").at("focus");
engine_focus_ = {{"condition", f.at("condition")}, {"technique", f.at("technique")}, {"play", f.at("play")}};
@@ -37,16 +49,25 @@ void App::engine_frame() {
engine_poll();
if (needs_render_) engine_render();
engine_sports_update();
if (ticket_) ticket_->update();
render_popup(); context_->Update();
if (center_selects(*doc_)) context_->Update();
if (menu_ == "lineup" && lineup_roster_scroll_) {
if (auto *roster = element("lineup-roster-scroll")) roster->SetScrollTop(*lineup_roster_scroll_);
lineup_roster_scroll_.reset();
}
if (popup_.empty() && !focus_after_render_.empty()) {
if (!engine_busy_ && popup_.empty() && !focus_after_render_.empty()) {
if (auto *node = element(focus_after_render_)) node->Focus(keyboard_navigation_);
focus_after_render_.clear();
}
if (amount_select_all_) {
if (auto *input = dynamic_cast<Rml::ElementFormControlInput *>(element("calculator-value"))) input->Select();
amount_select_all_ = false;
}
if (amount_caret_end_) {
if (auto *input = dynamic_cast<Rml::ElementFormControlInput *>(element("calculator-value"))) input->SetSelectionRange(int(input->GetValue().size()), int(input->GetValue().size()));
amount_caret_end_ = false;
}
renderer_.Clear(); renderer_.BeginFrame(); context_->Render(); renderer_.EndFrame(); video_.present(); dirty_ = false;
}
void App::engine_save() {
@@ -72,6 +93,11 @@ 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;
for (auto *node = target; node && node != doc_; node = node->GetParentNode())
if (node->GetId() == "native-ticket-layer") return; // owned by the compact control
if (ticket_ && ticket_->is_open()) return;
if (amount_event(event)) return;
if (!engine_busy_ && bank_event(event)) return;
if (engine_sports_event(event)) return;
Rml::ElementFormControl *range = nullptr;
for (auto *node = target; node && node != doc_; node = node->GetParentNode())
@@ -134,9 +160,15 @@ void App::engine_event(Rml::Event &event) {
if (action == "popup-confirm") { auto callback = std::move(confirm_); popup_.clear(); dirty_ = true; if (callback) callback(); }
return;
}
if (bank_action(action, node)) return;
if (engine_sports_action(action, id, node)) return;
if (engine_lineup_action(action, id, node)) return;
if (action == "close") { menu_.clear(); refresh(); }
else if (action == "engine-ticket" && engine_fresh_) {
const auto price = engine_ticket_projection(engine_data_);
ticket_->open(node, device_ratio_, price.at("min"), price.at("max")); dirty_ = true;
}
else if (action == "engine-open" && id == "bank") { bank_view_ = "entrance"; bank_hint_.clear(); menu_ = "bank"; refresh(); }
else if (action == "engine-open" && id == "save") engine_save();
else if (action == "engine-open" && (id == "training" || id == "tactics")) { engine_sports_reset(); menu_ = id; refresh(); }
else if (action == "engine-open" && id == "lineup") { menu_ = "lineup"; lineup_selected_.clear(); lineup_reset_scroll_ = true; refresh(); }
@@ -157,5 +189,5 @@ void App::engine_event(Rml::Event &event) {
}
Json App::engine_snapshot() const {
return {{"mode", engine_mode_}, {"busy", engine_busy_}, {"dirty", engine_dirty_}, {"fresh", engine_fresh_}, {"bundle", engine_data_},
{"response", engine_response_}, {"training_draft", engine_training_draft_}, {"tactics_draft", engine_tactics_draft_}, {"player_profile", engine_player_}, {"lineup_selected", lineup_selected_}, {"focus", engine_focus_}, {"selected_camp", engine_camp_}, {"notice", engine_notice_}};
{"response", engine_response_}, {"credit_preview", engine_credit_}, {"credit_edits", engine_credit_edits_}, {"training_draft", engine_training_draft_}, {"tactics_draft", engine_tactics_draft_}, {"player_profile", engine_player_}, {"lineup_selected", lineup_selected_}, {"focus", engine_focus_}, {"selected_camp", engine_camp_}, {"notice", engine_notice_}};
}
+112 -2
View File
@@ -4,6 +4,7 @@
#include <array>
#include <charconv>
#include <set>
#include <limits>
namespace bmh::modern_ui {
namespace {
@@ -90,9 +91,9 @@ namespace {
const Json &lineup_read(const Json &bundle, const char *kind) {
const auto &read = bundle.at(kind), &meta = bundle.at("desktop").at("meta");
require(read.value("messageType", "") == "snapshot" && read.at("data").value("kind", "") == kind,
"Kader oder Aufstellung sind in diesem Kontext nicht verfügbar.");
"Diese Engine-Ansicht ist in diesem Kontext nicht verfügbar.");
for (const auto *key : {"contractVersion", "careerId", "worldId", "worldRevision", "stateRevision", "scope"})
require(read.at("meta").at(key) == meta.at(key), "Kader und Aufstellung haben unterschiedliche Kontexte.");
require(read.at("meta").at(key) == meta.at(key), "Engine-Ansichten haben unterschiedliche Kontexte.");
return read.at("data");
}
Json metric_value(const Json &row, const char *key) {
@@ -277,4 +278,113 @@ Json engine_training_command(const Json &bundle, const Json &draft, const std::s
}
return sports_command(bundle, "training.commit", {{"types", draft.at("types")}, {"areas", draft.at("areas")}, {"players", changed}}, id);
}
Json engine_bank_projection(const Json &bundle) {
validate_engine_desk(bundle);
const auto &data = lineup_read(bundle, "bank");
require(data.at("teamId") == bundle.at("desktop").at("meta").at("scope").at("teamId"), "Bank gehört einer anderen Mannschaft.");
const auto &accounts = data.at("accounts");
const auto cash = engine_money_minor(accounts.at("cash")), deposit = engine_money_minor(accounts.at("deposit"));
require(cash == engine_money_minor(bundle.at("desktop").at("data").at("accounts").at("cash")) && deposit >= 0, "Widersprüchliche Kontostände.");
Json assets = {{"stocks", Json::array()}, {"properties", Json::array()}};
Json finance = {{"stocks", Json::array()}, {"properties", Json::array()}};
int64_t properties = 0, stocks = 0;
for (const auto *key : {"stocks", "funds"}) {
const bool stock = std::string(key) == "stocks";
const auto dest = stock ? "stocks" : "properties";
const auto &rows = data.at(key);
require(rows.is_array() && !rows.empty() && rows.size() <= size_t(stock ? 12 : 6), "Ungültiger Bankkatalog.");
std::set<std::string> ids;
for (const auto &row : rows) {
const auto id = row.at("id").get<std::string>();
bool known = false;
for (int i = 0; i < (stock ? 12 : 6); ++i) known |= id == std::string(stock ? "stock:" : "fund:") + std::to_string(i);
require(known && ids.insert(id).second, "Unbekannte oder doppelte Bankanlage.");
const auto price = engine_money_minor(row.at("price"));
const int owned = whole_in_range(row.at("owned"), 0, 65535), max = whole_in_range(row.at("maxToBuy"), 0, 99999999);
require(price >= 0 && price <= 99999999999LL, "Ungültiger Anlagenpreis.");
require(price == 0 || max <= std::numeric_limits<int64_t>::max() / price, "Anlagengesamtpreis ist zu groß.");
std::string name = row.at("name").is_string() ? row.at("name").get<std::string>() : row.at("name").value("text", "");
// A missing backend label is identified, never filled from a demo company.
if (name.empty() || name.starts_with("%%")) name = std::string(stock ? "Aktie · " : "Immobilie · ") + id;
Json item = {{"id", id}, {"name", name}, {"price", price}, {"owned", owned}, {"maxToBuy", max}};
if (stock) {
item["previous"] = engine_money_minor(row.at("previousPrice"));
item["history"] = Json::array();
require(row.at("history").is_array() && row.at("history").size() <= 1000, "Ungültiger Kursverlauf.");
for (const auto &point : row.at("history")) item["history"].push_back(engine_money_minor(point));
stocks += price * owned;
} else {
item["image"] = "bank.property." + id.substr(5);
properties += price * owned;
}
assets[dest].push_back(item); finance[dest].push_back(owned);
}
}
return {{"assets", assets}, {"state", {{"deposit", deposit}, {"finance", finance}}},
{"summary", {{"ok", true}, {"cash", cash}, {"deposit", deposit}, {"properties", properties}, {"stocks", stocks},
{"credit_line", engine_money_minor(accounts.at("creditLine"))}}}};
}
Json engine_bank_command(const Json &bundle, const Json &payload, const std::string &request_id) {
const auto projection = engine_bank_projection(bundle);
const auto action = payload.at("action").get<std::string>();
if (action == "deposit" || action == "withdraw") {
require(payload.size() == 2, "Ungültiger Bankauftrag.");
const auto amount = engine_money_minor(payload.at("amount"));
require(amount > 0 && amount % 100 == 0 && amount <= 9999999900LL &&
amount <= projection.at("summary").at(action == "deposit" ? "cash" : "deposit").get<int64_t>(), "Betrag überschreitet das verfügbare Guthaben.");
} else if (action == "buy" || action == "sell") {
require(payload.size() == 3, "Ungültiger Anlagenauftrag.");
const auto id = payload.at("assetId").get<std::string>();
const Json *asset = nullptr;
for (const auto *key : {"stocks", "properties"}) for (const auto &row : projection.at("assets").at(key)) if (row.at("id") == id) asset = &row;
require(asset, "Unbekannte Bankanlage.");
(void)whole_in_range(payload.at("count"), 1, asset->at(action == "buy" ? "maxToBuy" : "owned").get<int>());
} else require(false, "Nicht unterstützter Bankauftrag.");
return sports_command(bundle, "bank.commit", payload, request_id);
}
Json engine_ticket_projection(const Json &bundle) {
validate_engine_desk(bundle);
const auto &data = lineup_read(bundle, "stadium");
require(data.at("teamId") == bundle.at("desktop").at("meta").at("scope").at("teamId"), "Eintritt gehört einer anderen Mannschaft.");
const auto price = engine_money_minor(data.at("ticketPrice"));
const auto lo = engine_money_minor(data.at("ticketPriceRange").at("min")), hi = engine_money_minor(data.at("ticketPriceRange").at("max"));
require(lo >= 0 && hi <= 9999999900LL && lo <= price && price <= hi && lo % 100 == 0 && hi % 100 == 0 && price % 100 == 0, "Ungültige Eintrittspreise.");
return {{"ticket", price / 100}, {"min", lo / 100}, {"max", hi / 100}};
}
Json engine_ticket_command(const Json &bundle, int euros, const std::string &request_id) {
const auto price = engine_ticket_projection(bundle);
require(euros >= price.at("min").get<int64_t>() && euros <= price.at("max").get<int64_t>(), "Eintritt außerhalb des erlaubten Bereichs.");
return sports_command(bundle, "ticket.commit", {{"price", {{"currency", "EUR"}, {"minorUnits", 2}, {"minor", std::to_string(int64_t(euros) * 100)}}}}, request_id);
}
Json engine_credit_projection(const Json &bundle, const Json &read) {
validate_engine_desk(bundle);
auto context = bundle; context["credit"] = read;
const auto data = lineup_read(context, "credit");
require(data.at("lenderId") == "bank" && data.at("fields").is_array() && data.at("fields").size() == 8 && data.at("saved").size() == 6,
"Ungültige Kreditansicht.");
for (int i = 0; i < 8; ++i) {
const auto &f = data.at("fields")[size_t(i)];
require(f.at("field") == i && f.at("editable").is_boolean(), "Ungültiges Kreditfeld.");
(void)whole_in_range(f.at("value"), 0, INT32_MAX);
if (f.at("editable") == true) {
const auto lo = whole_in_range(f.at("min"), 0, INT32_MAX), hi = whole_in_range(f.at("max"), lo, INT32_MAX);
(void)hi;
}
}
for (const auto *key : {"fees", "refund", "principalPaid"}) require(engine_money_minor(data.at(key)) >= 0, "Ungültige Kreditkosten.");
return data;
}
Json engine_credit_command(const Json &bundle, const Json &read, const Json &edits, const std::string &request_id) {
const auto credit = engine_credit_projection(bundle, read);
require(credit.at("saved")[0] == 0, "Für Änderungen laufender Kredite fehlt noch die vollständige Gebührenvorschau.");
require(edits.is_array() && !edits.empty() && edits.size() <= 64, "Keine gültigen Kreditänderungen.");
for (const auto &e : edits) {
require(e.is_object() && e.size() == 2, "Ungültige Kreditänderung.");
(void)whole_in_range(e.at("field"), 0, 7); (void)whole_in_range(e.at("value"), 0, 99999999);
}
// The engine replays this ordered edit list and owns fees and all loan maths.
return sports_command(bundle, "bank.commit", {{"action", "credit"}, {"lenderId", "bank"}, {"edits", edits}, {"acceptFees", true}}, request_id);
}
} // namespace bmh::modern_ui
+115
View File
@@ -0,0 +1,115 @@
// SPDX-License-Identifier: GPL-3.0-only
void App::engine_finance_submit(const Json &command) {
auto link = engine_link_;
engine_start("Änderung wird verarbeitet …", [link, command] {
auto response = link->command(command);
return EngineReply{link, link->snapshot(), response, nullptr};
}, true);
}
void App::engine_ticket_bind() {
if (ticket_) return;
ticket_ = std::make_unique<TicketPopover>(*context_, *doc_, [this] {
Json state;
if (engine_fresh_ && !engine_busy_) {
try { state = engine_ticket_projection(engine_data_); } catch (const std::exception &) {}
}
return Snapshot{input_revision(), world_, state};
}, [this](const Action &action) {
try {
if (!engine_fresh_ || engine_busy_ || action.revision != input_revision()) return ActionResult{false, input_revision(), "Die Daten haben sich geändert."};
auto command = engine_ticket_command(engine_data_, action.value.get<int>(), editor::new_id("request:ui-"));
engine_finance_submit(command);
return ActionResult{true, input_revision(), {}};
} catch (const std::exception &e) { return ActionResult{false, input_revision(), e.what()}; }
}, [this] { focus_after_render_ = "account-ticket"; dirty_ = true; });
}
bool App::engine_bank_action(const std::string &action, Rml::Element *target) {
if (!engine_fresh_ || engine_busy_) return true;
if (action == "engine-credit-reset") {
engine_credit_ = engine_data_.at("credit"); engine_credit_edits_ = Json::array(); refresh(); return true;
}
if (action == "engine-credit-apply") {
const auto data = engine_credit_projection(engine_data_, engine_credit_);
const auto command = engine_credit_command(engine_data_, engine_credit_, engine_credit_edits_, editor::new_id("request:ui-"));
std::string text = "Kreditänderungen verbindlich buchen? Gebühren: " + engine_price(data.at("fees")) +
". Erstattung: " + engine_price(data.at("refund")) + ".";
for (const auto &f : data.at("fields")) text += " " + engine_text(f.at("label")) + ": " + number(f.at("value").get<int64_t>()) + ((f.at("field") == 3 || f.at("field") == 4) ? " Monate." : " €. ");
confirmation(text, [this, command] { focus_after_render_ = "window-close"; engine_finance_submit(command); }); return true;
}
if (action != "bank-calc" && action != "engine-credit-edit") return false;
if (!target) return true;
AmountRequest request; request.return_focus = target->GetId(); request.step = 1;
const auto meta = engine_data_.at("desktop").at("meta");
const auto fresh = [this, meta] { return engine_fresh_ && !engine_busy_ && menu_ == "bank" && meta == engine_data_.at("desktop").at("meta"); };
if (action == "engine-credit-edit") {
const auto index = target->GetAttribute<int>("data-id", -1);
const auto credit = engine_credit_projection(engine_data_, engine_credit_);
if (credit.at("saved")[0] != 0) return true;
if (index < 0 || index > 7 || credit.at("fields")[size_t(index)].at("editable") != true) return true;
const auto f = credit.at("fields")[size_t(index)];
request.title = engine_text(f.at("label")); request.unit = index == 3 || index == 4 ? "Monate" : "€";
request.min = f.at("min"); request.max = std::min<int64_t>(99999999, f.at("max").get<int64_t>());
request.value = std::clamp(f.at("value").get<int64_t>(), request.min, request.max);
request.suggestion_step = index == 3 || index == 4 ? 6 : 100000; request.review = false;
const auto edits_before = engine_credit_edits_;
if (edits_before.size() >= 64) { message("Bitte den Kreditentwurf zurücksetzen, bevor du weitere Felder änderst."); return true; }
request.accept = [this, fresh, edits_before, index](int64_t value) {
if (!fresh() || bank_view_ != "credit" || engine_credit_edits_ != edits_before) return false;
auto edits = edits_before; edits.push_back({{"field", index}, {"value", value}});
auto link = engine_link_;
engine_start("Kreditvorschau wird berechnet …", [link, edits] {
auto response = link->read({{"kind", "credit"}, {"lenderId", "bank"}, {"edits", edits}});
return EngineReply{link, link->snapshot(), {{"messageType", "credit_preview"}, {"read", response}, {"edits", edits}}, nullptr};
}); return true;
};
} else {
const auto kind = target->GetAttribute<Rml::String>("data-kind", "");
const auto bank = engine_bank_projection(engine_data_);
Json payload; int64_t unit_price = 0;
const bool transfer = kind == "deposit" || kind == "withdraw";
if (transfer && bank_view_ == "savings") {
payload = {{"action", kind}};
request.title = kind == "deposit" ? "Einzahlen" : "Abheben"; request.unit = "€";
request.max = std::min<int64_t>(99999999, bank.at("summary").at(kind == "deposit" ? "cash" : "deposit").get<int64_t>() / 100);
request.suggestion_step = 100000;
} else {
const bool property = kind == "property-buy" || kind == "property-sell";
const bool stock = kind == "stock-buy" || kind == "stock-sell";
if ((!property && !stock) || (property && bank_view_ != "properties") || (stock && bank_view_ != "stocks")) return true;
const bool buy = kind == "property-buy" || kind == "stock-buy";
const auto &asset = bank.at("assets").at(property ? "properties" : "stocks").at(size_t(property ? (buy ? bank_property_ : bank_owned_) : bank_stock_));
payload = {{"action", buy ? "buy" : "sell"}, {"assetId", asset.at("id")}}; unit_price = asset.at("price");
request.title = std::string(buy ? "Kaufen: " : "Verkaufen: ") + asset.at("name").get<std::string>(); request.unit = "Stück";
request.max = std::min<int64_t>(99999999, asset.at(buy ? "maxToBuy" : "owned").get<int64_t>()); request.suggestion_step = property ? 1 : 100;
request.review_text = [unit_price](int64_t value) { return "Kurswert ohne zusätzliche Gebühren: " + money(unit_price * value, {{"code", "EUR"}, {"minor_units", 2}}) + ". Kauf- und Verkaufskosten berechnet die Bank."; };
}
request.min = 1; request.value = request.max >= 1 ? 1 : 0;
request.accept = [this, fresh, payload, transfer](int64_t value) mutable {
if (!fresh()) return false;
if (transfer) payload["amount"] = {{"currency", "EUR"}, {"minorUnits", 2}, {"minor", std::to_string(value * 100)}};
else payload["count"] = value;
engine_finance_submit(engine_bank_command(engine_data_, payload, editor::new_id("request:ui-"))); return true;
};
}
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>";
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;\">";
for (size_t i = 0; i < 8; ++i) {
const auto &f = data.at("fields")[i]; const auto value = f.at("value").get<int64_t>();
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;\"");
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 += "<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;
}
+16 -3
View File
@@ -36,6 +36,7 @@ Json App::engine_camp_view() const {
return {{"maps", maps}, {"training_camps", camps}};
}
void App::engine_render() {
if (ticket_) ticket_->close(false);
if (menu_ == "lineup") {
if (auto *roster = element("lineup-roster-scroll")) lineup_roster_scroll_ = lineup_reset_scroll_ ? 0.f : roster->GetScrollTop();
lineup_reset_scroll_ = false;
@@ -59,6 +60,12 @@ void App::engine_render() {
bool training_available = false, tactics_available = false;
try { (void)engine_training_projection(engine_data_); training_available = true; } catch (const std::exception &) {}
try { (void)engine_tactics_projection(engine_data_); tactics_available = true; } catch (const std::exception &) {}
bool bank_available = false, ticket_available = false;
try { (void)engine_bank_projection(engine_data_); bank_available = true; } catch (const std::exception &) {}
try { (void)engine_ticket_projection(engine_data_); ticket_available = true; } catch (const std::exception &) {}
const auto allowed = meta.at("scope").value("allowedCommands", Json::array());
bank_available = bank_available && std::find(allowed.begin(), allowed.end(), Json("bank.commit")) != allowed.end();
ticket_available = ticket_available && std::find(allowed.begin(), allowed.end(), Json("ticket.commit")) != allowed.end();
init_desktop();
for (const auto &[id, o] : desktop_.at("objects").items()) {
if (!o.value("visible", false)) continue;
@@ -79,8 +86,8 @@ void App::engine_render() {
const std::array<const char *, 7> weekdays{"Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"};
body = "<div class=\"desk-calendar-month\"><span>" + std::string(months[size_t(m - 1)]) + " " + std::to_string(y) + "</span></div><div class=\"desk-calendar-body\"><span>" + weekdays[std::chrono::weekday{std::chrono::sys_days(ymd)}.c_encoding()] + "</span><strong>" + std::to_string(d) + "</strong><small>" + esc(meta.at("season").at("label").get<std::string>()) + "</small></div>";
} else if (id == "account") {
const auto savings = desk.at("accounts").at("savings");
body = widget_heading("Vereinskasse", false) + "<div class=\"desk-account-main\"><span>Guthaben</span><strong class=\"" + money_classes(engine_money_minor(desk.at("accounts").at("cash"))) + "\">" + esc(engine_price(desk.at("accounts").at("cash"))) + "</strong></div><div class=\"desk-account-bottom\"><div><span>Sparbuch</span><strong>" + (savings.is_null() ? std::string("—") : esc(engine_price(savings))) + "</strong></div>" + btn("engine-unavailable", glyph("ticket", 36) + "<span><span>Eintritt</span><strong>—</strong></span>", "desk-ticket", "disabled") + "</div>";
const auto savings = bank_available ? engine_data_.at("bank").at("data").at("accounts").at("deposit") : desk.at("accounts").at("savings");
body = widget_heading("Vereinskasse", false) + "<div class=\"desk-account-main\"><span>Guthaben</span><strong class=\"" + money_classes(engine_money_minor(desk.at("accounts").at("cash"))) + "\">" + esc(engine_price(desk.at("accounts").at("cash"))) + "</strong></div><div class=\"desk-account-bottom\"><div><span>Sparbuch</span><strong>" + (savings.is_null() ? std::string("—") : esc(engine_price(savings))) + "</strong></div>" + btn("engine-ticket", glyph("ticket", 36) + "<span><span>Eintritt</span><strong>" + (ticket_available ? esc(engine_price(engine_data_.at("stadium").at("data").at("ticketPrice"))) : std::string("—")) + "</strong></span>", "desk-ticket", "id=\"account-ticket\" " + std::string(ticket_available && engine_fresh_ && !engine_busy_ ? "" : "disabled")) + "</div>";
} else if (id == "opponent-crest" && desk.at("nextFixture").is_object()) {
const auto &next = desk.at("nextFixture");
const auto &other = next.at(next.at("home").at("id") == team.at("id") ? "away" : "home");
@@ -91,16 +98,18 @@ void App::engine_render() {
const auto route = id.substr(4);
const bool camp_allowed = desk.at("menuAvailability").at("camps").value("status", "") == "available";
const auto commands = meta.at("scope").value("allowedCommands", Json::array());
const bool supported = (route == "training" && training_available && engine_fresh_) || (route == "tactics" && tactics_available && engine_fresh_) || (route == "lineup" && lineup_available && engine_fresh_) || route == "save" || (route == "camp" && engine_fresh_ && camp_allowed && std::find(commands.begin(), commands.end(), Json("camp.book")) != commands.end());
const bool supported = (route == "bank" && bank_available && engine_fresh_) || (route == "training" && training_available && engine_fresh_) || (route == "tactics" && tactics_available && engine_fresh_) || (route == "lineup" && lineup_available && engine_fresh_) || route == "save" || (route == "camp" && engine_fresh_ && camp_allowed && std::find(commands.begin(), commands.end(), Json("camp.book")) != commands.end());
out += desktop_button(id, o, "engine-open", supported && !engine_busy_);
}
}
out += "</div>";
if (menu_ == "bank") out += "<div class=\"fill\" style=\"z-index:100;\">" + window("Bank", render_bank()) + "</div>";
if (menu_ == "training") out += "<div class=\"fill\" style=\"z-index:100;\">" + window("Training", render_training()) + "</div>";
if (menu_ == "tactics") out += "<div class=\"fill\" style=\"z-index:100;\">" + window("Taktik", render_tactics()) + "</div>";
if (menu_ == "lineup") out += "<div class=\"fill\" style=\"z-index:100;\">" + window("Aufstellung", render_lineup()) + "</div>";
if (menu_ == "camp") out += "<div class=\"fill\" style=\"z-index:100;\">" + window("Trainingslager", render_camp()) + "</div>";
}
if (menu_ == "bank" && !amount_) out += "<div class=\"panel\" style=\"position:absolute;bottom:12dp;left:700dp;right:700dp;padding:9dp;font-size:25dp;z-index:110;\" id=\"engine-status\">" + esc(engine_busy_ ? engine_operation_ : engine_notice_) + "</div>";
if (menu_.empty() || engine_data_.empty()) out += "<div class=\"panel\" style=\"position:absolute;left:850dp;bottom:24dp;right:100dp;padding:18dp;font-size:27dp;\" id=\"engine-status\">" + esc(engine_busy_ ? engine_operation_ : engine_notice_) + "</div>";
element("canvas")->SetInnerRML(out); ++document_generation_;
scale_chalk_shadow();
@@ -111,6 +120,10 @@ void App::engine_render() {
const auto size = context_->GetDimensions();
element("background")->SetInnerRML(img("background", size.x / scale_, size.y / scale_, false, true, 2048));
element("background")->SetProperty("filter", theme_ == "silver" ? "saturate(0.2) brightness(0.9)" : theme_ == "matchday" ? "saturate(0.13) brightness(0.56)" : "saturate(0.34) brightness(0.70)");
if (amount_) {
Rml::ElementList underlay; doc_->QuerySelectorAll(underlay, ".window>.content,.window>.titlebar");
for (auto *node : underlay) { node->SetProperty("pointer-events", "none"); node->SetProperty("filter", "blur(10dp)"); }
}
if (engine_busy_) {
Rml::ElementList controls; doc_->QuerySelectorAll(controls, "#canvas button,#canvas input");
for (auto *node : controls) node->SetAttribute("disabled", true);
+5
View File
@@ -4,6 +4,11 @@
std::future<EngineReply> engine_job_;
Json engine_data_, engine_response_, engine_focus_, engine_training_draft_, engine_tactics_draft_;
std::string engine_camp_, engine_operation_, engine_notice_, engine_player_;
Json engine_credit_, engine_credit_edits_ = Json::array();
bool engine_bank_action(const std::string &, Rml::Element *);
std::string engine_credit_view();
void engine_finance_submit(const Json &);
void engine_ticket_bind();
void engine_start(std::string, std::function<EngineReply()>, bool mutating = false);
void engine_poll();
void engine_render();
+10 -4
View File
@@ -60,7 +60,13 @@ bool inside(Rml::Element *node, Rml::Element *root) {
TicketPopover::TicketPopover(Rml::Context &context,
Rml::ElementDocument &document, DataSource &source,
std::function<void()> on_commit)
: context_(context), document_(document), source_(source),
: TicketPopover(context, document, [&source] { return source.snapshot(); },
[&source](const Action &a) { return source.apply(a); }, std::move(on_commit)) {}
TicketPopover::TicketPopover(Rml::Context &context, Rml::ElementDocument &document,
std::function<Snapshot()> read,
std::function<ActionResult(const Action &)> submit,
std::function<void()> on_commit)
: context_(context), document_(document), read_(std::move(read)), submit_(std::move(submit)),
on_commit_(std::move(on_commit)) {
auto layer = document_.CreateElement("div");
layer->SetId("native-ticket-layer");
@@ -83,7 +89,7 @@ TicketPopover::~TicketPopover() {
bool TicketPopover::open(Rml::Element *anchor, float device_pixel_ratio,
int min, int max, int step) {
close(false);
const auto snapshot = source_.snapshot();
const auto snapshot = read_();
const auto current = price(snapshot);
const auto interval = int64_t(max) - min;
if (!anchor || anchor->GetOwnerDocument() != &document_ ||
@@ -125,7 +131,7 @@ void TicketPopover::close(bool restore_focus) {
focus_opener();
}
bool TicketPopover::fresh() const {
const auto snapshot = source_.snapshot();
const auto snapshot = read_();
return snapshot.revision == revision_ && snapshot.world == world_ &&
price(snapshot) == original_;
}
@@ -267,7 +273,7 @@ void TicketPopover::confirm() {
close(false);
return;
}
const auto result = source_.apply({revision_, "ticket", value_});
const auto result = submit_({revision_, "ticket", value_});
if (!result.ok) {
if (!fresh()) {
close(false);
+8 -1
View File
@@ -21,6 +21,12 @@ class TicketPopover final : public Rml::EventListener {
public:
TicketPopover(Rml::Context &, Rml::ElementDocument &, DataSource &,
std::function<void()> on_commit);
// submit accepts a confirmed proposal; async owners publish only the later
// authoritative response. The control never changes the displayed account.
TicketPopover(Rml::Context &, Rml::ElementDocument &,
std::function<Snapshot()> read,
std::function<ActionResult(const Action &)> submit,
std::function<void()> on_commit);
~TicketPopover() override;
TicketPopover(const TicketPopover &) = delete;
TicketPopover &operator=(const TicketPopover &) = delete;
@@ -43,7 +49,8 @@ private:
Rml::Context &context_;
Rml::ElementDocument &document_;
DataSource &source_;
std::function<Snapshot()> read_;
std::function<ActionResult(const Action &)> submit_;
std::function<void()> on_commit_;
Rml::Element *layer_ = nullptr;
std::string anchor_id_, error_;
+2
View File
@@ -473,6 +473,7 @@ class App final : public Rml::EventListener {
return p ? p->GetValue() : "";
}
Snapshot snap() const { return source_->snapshot(); }
uint64_t input_revision() const { return engine_mode_ ? std::stoull(engine_data_.at("desktop").at("meta").at("stateRevision").get<std::string>()) : snap().revision; }
const Json &manager(const Snapshot &s) const {
return demo_career_manager(s.state);
}
@@ -1515,6 +1516,7 @@ public:
#include "modern/ui/engine_controls.inc"
#include "modern/ui/engine_lineup.inc"
#include "modern/ui/engine_sports.inc"
#include "modern/ui/engine_finance.inc"
} // namespace
bool is_modern_world(const fs::path &file) {
try {