Bind player negotiations and release cancelled contract quotes (by Codex)

This commit is contained in:
Codex committed 2026-10-28 12:57:40 +01:00
1 parent e9483048f4
commit 622973c2cf
18 files changed
+381 -28

No files matched your search

+10
View File
@@ -10018,6 +10018,16 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
answer = modern::ui_command_result(request_id, previous, revision, {"stadium", "desktop", "bank"},
!feedback.empty() ? feedback : yes ? "Der Bau beginnt." : "Abgelehnt.");
}
} else if (kind == "contract.cancel") {
// Close only this owner's exact quote. Releasing the UI owner must
// neither rewind nor advance either engine random stream.
const int team = g_.manager_teams[size_t(manager)];
if (!contract_quote_ || ui_text(*payload, "quoteId") != "quote:contract-" + std::to_string(contract_quote_->quote_id) ||
contract_quote_->manager_slot != manager || contract_quote_->runtime_club != team)
return refuse("stale_quote", "Diese Verhandlung ist nicht mehr geöffnet.");
contract_quote_.reset();
revision = previous + 1;
answer = modern::ui_command_result(request_id, previous, revision, {"contracts"}, "Verhandlung abgebrochen.");
} else if (kind == "quote.request" || kind == "contract.offer") {
// quote.request {kind: "contract", playerId}: the player's demands for one to four years
// (draws a random number, as at the desk); contract.offer {quoteId, years 1-4,
+1 -1
View File
@@ -139,7 +139,7 @@ A allowed_commands(const ModernState& g, const UiContext& c) {
"session.advance", "lineup.commit", "tactics.commit", "friendly.book", "manager.resign.commit",
"training.commit", "camp.book", "bank.commit", "toto.submit", "quote.request", "contract.offer",
"stadium.commit", "advertising.accept", "budget.commit", "ticket.commit", "transfer.submit",
"sponsor.answer", "environment.commit", "fixture.reschedule"};
"sponsor.answer", "environment.commit", "fixture.reschedule", "contract.cancel"};
A out;
for (size_t i = 0; i < std::size(kAll); ++i)
if (!national || i < 5) out.push_back(kAll[i]);
+2
View File
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-only
void App::close_contracts(bool focus) {
if (engine_mode_) { engine_contracts_close(focus); return; }
auto restore = contracts_return_focus_;
if (focus && !restore.empty()) {
const auto snapshot = snap();
@@ -22,6 +23,7 @@ void App::close_contracts(bool focus) {
bool App::contracts_action(const std::string &action, Rml::Element *target) {
if (menu_ != "contracts") return false;
if (engine_mode_) return engine_contracts_action(action, target);
constexpr std::array<std::string_view, 10> actions = {"contracts-tab", "contract-player", "contract-close",
"contract-term", "contract-salary", "contract-submit", "contract-insurance",
"contract-insure", "contracts-bonuses", "contract-bonus"};
+31 -20
View File
@@ -72,15 +72,16 @@ bool contracts_bound(const Snapshot &snapshot, uint64_t revision,
} // namespace
std::string App::render_contracts() {
const auto snapshot = snap();
const auto projection = contracts_projection(snapshot);
const auto snapshot = engine_mode_ ? Snapshot{input_revision(), world_, Json::object()} : snap();
const auto projection = engine_mode_ ? engine_contracts_projection(engine_data_) : contracts_projection(snapshot);
const auto show_money = [&](const Json &v) { return engine_mode_ ? (v.is_number_integer() ? money(v.get<int64_t>(), {{"code", "EUR"}, {"minor_units", 2}}) : std::string("—")) : contracts_money(v, *snapshot.world); };
const bool ready = projection.value("ok", false) && snapshot.world;
const auto &rows = contracts_field(projection, "rows");
const size_t count = rows.is_array() ? rows.size() : 0;
if (contracts_tab_ < 0 || contracts_tab_ > 2) contracts_tab_ = 2;
if (contracts_dialog_.empty() && contracts_player_.empty() && count)
contracts_player_ = contracts_text(contracts_field(rows[0], "id"), "");
const auto managed = contracts_managed(snapshot);
const auto managed = engine_mode_ ? projection.at("club").get<std::string>() : contracts_managed(snapshot);
const auto *own = snapshot.world ? snapshot.world->find("clubs", managed) : nullptr;
const auto club_name = own ? snapshot.world->name(*own) : std::string("—");
std::string output = "<div id=\"contracts-underlay\" class=\"contracts-overview\">"
@@ -88,8 +89,8 @@ std::string App::render_contracts() {
(own ? img(own->value("crest", ""), 58, 58, true) : "") +
"<span>" + esc(club_name) + "</span></div><p>" + std::to_string(count) +
" Spieler · Spieler anklicken, um einen Vertrag zu verhandeln</p></div>"
"<div class=\"contracts-salary-total\"><span>Monatsgehälter</span><span class=\"contracts-total-value\">" +
(ready ? esc(contracts_money(contracts_field(projection, "salary_total"), *snapshot.world)) : "—") +
"<div class=\"contracts-salary-total\"><span>Monatsgehälter</span><span class=\"contracts-total-value money-amount\">" +
(ready ? esc(show_money(contracts_field(projection, "salary_total"))) : "—") +
"</span></div></header><div id=\"contracts-roster-scroll\" class=\"contracts-roster\">"
"<div class=\"contracts-table\" role=\"table\"><div class=\"contracts-row contracts-table-head\" role=\"row\">";
const std::array<std::vector<std::pair<std::string, std::string>>, 3> headings = {{
@@ -126,7 +127,7 @@ std::string App::render_contracts() {
else {
std::string value;
if (key == "position") value = contracts_position(row);
else if (key == "salary") value = ready ? contracts_money(contracts_field(row, "salary"), *snapshot.world) : "—";
else if (key == "salary") value = ready ? show_money(contracts_field(row, "salary")) : "—";
else if (key == "months") value = contracts_number(contracts_field(row, "months")) + " Monate";
else if (key == "insurance") {
const auto &insurance = contracts_field(row, "insurance");
@@ -152,7 +153,7 @@ std::string App::render_contracts() {
"id=\"contracts-tab-" + std::to_string(tab) + "\" data-id=\"" + std::to_string(tab) +
"\" aria-pressed=\"" + (contracts_tab_ == tab ? "true" : "false") + "\"");
output += btn("contracts-bonuses", "<span>Team-Prämien</span>", "contract-control bonuses",
"id=\"contracts-bonuses\" " + std::string(ready ? "" : "disabled")) + "</nav></div>";
"id=\"contracts-bonuses\" " + std::string(ready && !engine_mode_ ? "" : "disabled")) + "</nav></div>";
if (contracts_dialog_.empty()) return output;
const auto &draft_row = contracts_field(contract_draft_, "row");
@@ -173,9 +174,12 @@ std::string App::render_contracts() {
const auto &proposed = contracts_field(contract_draft_, "salary");
const auto &months = contracts_field(contract_draft_, "months");
const auto source = contracts_text(contracts_field(draft_row, "source_label"));
const int64_t factor = world ? finance_currency_factor(*world) : 1;
// Fictional asking price follows the HTML preview, never an engine demand.
const Json demand = salary.is_number_integer()
const int64_t factor = engine_mode_ ? 100 : world ? finance_currency_factor(*world) : 1;
const auto engine_quote = engine_mode_ ? projection.at("quote") : Json();
const bool quoted = engine_quote.is_object() && engine_quote.at("player") == contracts_player_;
const int term_index = months.is_number_integer() ? std::clamp(months.get<int>() / 12 - 1, 0, 3) : 0;
// Demo asking prices never enter a real negotiation.
const Json demand = engine_mode_ ? (quoted ? engine_quote.at("demands")[size_t(term_index)] : Json()) : salary.is_number_integer()
? Json(((salary.get<int64_t>() / factor * 11 + 5) / 10) * factor) : Json();
body = "<p class=\"contract-player-summary\">" + esc(contracts_position(draft_row)) +
" · Stärke " + esc(contracts_number(contracts_field(draft_row, "strength"))) +
@@ -184,26 +188,33 @@ std::string App::render_contracts() {
"</div><div class=\"contract-scene\">" + img("contracts.scene.1", 955, 291.0625) + "</div></div>"
"<div class=\"contract-amounts\"><div class=\"contract-amount-card\" title=\"" + esc(source) +
"\"><span class=\"contract-amount-label\">Aktuelles Monatsgehalt</span><span class=\"contract-amount-value\">" +
(world ? esc(contracts_money(salary, *world)) : "—") +
"</span></div><div class=\"contract-amount-card\"><span class=\"contract-amount-label\">Fiktive Forderung</span>"
"<span class=\"contract-amount-value\">" + (world ? esc(contracts_money(demand, *world)) : "—") +
(world ? esc(show_money(salary)) : "—") +
"</span></div><div class=\"contract-amount-card\"><span class=\"contract-amount-label\">" + std::string(engine_mode_ ? "Forderung für die gewählte Laufzeit" : "Fiktive Forderung") + "</span>"
"<span class=\"contract-amount-value\">" + (world ? esc(show_money(demand)) : "—") +
"</span></div></div><div class=\"contract-duration-heading\"><span>Laufzeit</span><span class=\"contract-duration-value\">" +
esc(contracts_number(months)) + " Monate</span></div><nav class=\"contract-duration\" aria-label=\"Vertragslaufzeit\">";
for (const int term : {12, 24, 36, 48})
body += btn("contract-term", "<span>" + std::to_string(term / 12) +
(term == 12 ? " Jahr" : " Jahre") + "</span>", "contract-control " +
std::string(months == term ? "selected" : ""), "id=\"contract-term-" + std::to_string(term) +
"\" data-id=\"" + std::to_string(term) + "\" aria-pressed=\"" + (months == term ? "true" : "false") + "\"");
"\" data-id=\"" + std::to_string(term) + "\" aria-pressed=\"" + (months == term ? "true" : "false") + "\" " + std::string(engine_mode_ && quoted && engine_quote.at("demands")[size_t(term / 12 - 1)].is_null() ? "disabled" : ""));
body += "</nav><div class=\"contract-salary\"><div class=\"contract-salary-label\"><span>Dein Angebot pro Monat</span>"
"<span class=\"contract-salary-hint\">Betrag über die gemeinsame Zahleneingabe ändern</span></div>" +
btn("contract-salary", "<span>" + (world && proposed.is_number_integer()
? esc(std::to_string(proposed.get<int64_t>())) : "—") + "</span>",
"contract-salary-input amount-trigger", "id=\"contract-salary\" aria-haspopup=\"dialog\" aria-label=\"Angebotenes Monatsgehalt ändern\"") +
"</div><p class=\"contract-draft-note\">Erst „Angebot machen“ übernimmt Gehalt und Laufzeit.</p>";
? esc(engine_mode_ ? money(proposed.get<int64_t>() * 100, {{"code", "EUR"}, {"minor_units", 2}}) : std::to_string(proposed.get<int64_t>())) : "—") + "</span>",
"contract-salary-input amount-trigger", "id=\"contract-salary\" aria-haspopup=\"dialog\" aria-label=\"Angebotenes Monatsgehalt ändern\" " + std::string(engine_mode_ && !quoted ? "disabled" : "")) +
"</div><p class=\"contract-draft-note\">" + std::string(engine_mode_ ? (!contracts_notice_.empty() ? contracts_notice_ : "Forderungen ausdrücklich abfragen. Erst das bestätigte Angebot wird verhandelt.") : "Erst „Angebot machen“ übernimmt Gehalt und Laufzeit.") + "</p>";
actions = close("Abbrechen") +
btn("contract-insurance", "<span>Versichern</span>", "contract-control", "id=\"contract-insurance\"") +
btn("contract-insurance", "<span>" + std::string(engine_mode_ ? "Details" : "Versichern") + "</span>", "contract-control", "id=\"contract-insurance\"") +
(engine_mode_ && !quoted ? btn("contract-quote", "<span>Forderungen abfragen</span>", "contract-control contract-submit", "id=\"contract-quote\" " + std::string(draft_row.value("can_request", false) && engine_quote.is_null() ? "" : "disabled")) :
btn("contract-submit", "<span>Angebot machen</span>", "contract-control contract-submit",
"id=\"contract-submit\" " + std::string(proposed.is_number_integer() ? "" : "disabled"));
"id=\"contract-submit\" " + std::string(proposed.is_number_integer() && (!engine_mode_ || (!demand.is_null() && engine_quote.value("can_offer", false) && proposed.get<int64_t>() >= 0 && proposed.get<int64_t>() <= engine_quote.at("max_salary").get<int64_t>() / 100)) ? "" : "disabled")));
} else if (engine_mode_ && contracts_dialog_ == "engine-details") {
title = "Versicherung und Prämien · " + player_name;
body = "<p class=\"contract-player-summary\">Versicherung: " + contracts_number(draft_row.at("insurance")) + " Monate · Versicherung und Prämien sind hier schreibgeschützt.</p><div class=\"contract-bonuses\">";
const std::array<const char *, 7> labels{"Torprämie", "Punktprämie", "Auflaufprämie", "Meisterprämie", "Prämie Pl. 2–5", "Prämie Pl. 6–10", "Nichtabstiegsprämie"};
for (size_t i = 0; i < labels.size(); ++i) body += "<div class=\"contract-bonus-row\"><span>" + std::string(labels[i]) + "</span><span>Stufe " + contracts_number(draft_row.at("premiums")[i]) + "</span></div>";
body += "</div>"; actions = close("Zurück zur Verhandlung");
} else if (insurance) {
const auto current = contracts_field(draft_row, "insurance");
body = "<p class=\"contract-insurance-prompt\">Wähle die Versicherungsdauer für diesen Spieler.</p>"
@@ -238,7 +249,7 @@ std::string App::render_contracts() {
actions = close("Verstanden");
}
return output + "<div id=\"contracts-layer\" class=\"contracts-layer\"><section id=\"contracts-dialog\" "
"class=\"contracts-dialog contracts-dialog-" + esc(contracts_dialog_) +
"class=\"contracts-dialog " + std::string(contracts_dialog_ == "engine-details" ? "contracts-dialog-bonuses " : "") + "contracts-dialog-" + esc(contracts_dialog_) +
"\" role=\"dialog\" aria-modal=\"true\" aria-labelledby=\"contract-dialog-title\">"
"<h2 id=\"contract-dialog-title\">" + esc(title) + "</h2>" + body +
"<nav class=\"contract-dialog-actions\">" + actions + "</nav></section></div>";
+1 -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", "bank", "stadium", "credit", "environment", "advertising"})
for (const auto *kind : {"session", "desktop", "camps", "squad", "lineup", "tactics", "training", "bank", "stadium", "credit", "environment", "advertising", "contracts"})
bundle[kind] = from_engine(impl_->session->ui_read(cli::Json::Object{{"kind", kind}}, impl_->revision));
validate_engine_desk(bundle);
return bundle;
+5
View File
@@ -33,6 +33,11 @@ Json engine_advertising_quote(const Json &bundle, int slot, int choice);
Json engine_advertising_command(const Json &bundle, const std::string &offer, const std::string &request_id);
Json engine_budget_command(const Json &bundle, const std::string &budget, int64_t euros, const std::string &request_id);
Json engine_contracts_projection(const Json &bundle);
Json engine_contract_request(const Json &bundle, const std::string &player, const std::string &request_id);
Json engine_contract_offer(const Json &bundle, const std::string &player, const std::string &quote, int years, int64_t euros, const std::string &request_id);
Json engine_contract_cancel(const Json &bundle, const std::string &quote, 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.
class EngineBridge {
+97
View File
@@ -0,0 +1,97 @@
// SPDX-License-Identifier: GPL-3.0-only
void App::engine_contracts_clear(bool focus) {
if (focus && !contracts_return_focus_.empty()) focus_after_render_ = contracts_return_focus_;
contract_draft_ = Json(); contracts_dialog_.clear(); contracts_notice_.clear(); contracts_return_focus_.clear();
contracts_world_.reset(); contracts_revision_ = 0; refresh();
}
void App::engine_contracts_close(bool focus) {
if (engine_busy_) return;
if (contracts_dialog_ == "engine-details") {
contracts_dialog_ = "offer"; focus_after_render_ = "contract-insurance"; refresh(); return;
}
const auto view = engine_contracts_projection(engine_data_);
if (view.at("quote").is_object()) {
const auto command = engine_contract_cancel(engine_data_, view.at("quote").at("id"), editor::new_id("request:ui-"));
engine_contract_operation_ = "cancel"; engine_finance_submit(command); return;
}
engine_contracts_clear(focus);
}
void App::engine_contracts_poll() {
const auto operation = std::exchange(engine_contract_operation_, {});
if (operation.empty()) return;
const auto view = engine_contracts_projection(engine_data_);
if (engine_response_.value("messageType", "") == "error") {
contracts_notice_ = engine_notice_;
if (view.at("quote").is_null()) { contract_draft_["notice_title"] = "Nicht übernommen"; contracts_dialog_ = "notice"; }
focus_after_render_ = "contract-close"; return;
}
if (operation == "cancel" && engine_response_.value("messageType", "") == "command_result") { engine_contracts_clear(); return; }
if (operation == "quote") {
const auto &quote = view.at("quote");
if (quote.is_object() && quote.at("player") == contracts_player_) {
contracts_revision_ = input_revision();
const int index = contract_draft_.at("months").get<int>() / 12 - 1;
if (quote.at("demands")[size_t(index)].is_null())
for (int i = 0; i < 4; ++i) if (!quote.at("demands")[size_t(i)].is_null()) { contract_draft_["months"] = (i + 1) * 12; break; }
focus_after_render_ = "contract-term-" + std::to_string(contract_draft_.at("months").get<int>());
}
} else if (operation == "offer" && view.at("quote").is_null()) {
const bool rejected = engine_response_.value("outcome", "") == "offer_rejected";
contract_draft_["notice_title"] = rejected ? "Angebot abgelehnt" : "Verhandlung abgeschlossen";
contracts_notice_ = engine_text(engine_response_.value("feedback", Json(engine_notice_)));
contracts_dialog_ = "notice"; focus_after_render_ = "contract-close";
}
}
bool App::engine_contracts_action(const std::string &action, Rml::Element *target) {
const std::set<std::string> actions{"contracts-tab", "contract-player", "contract-close", "contract-term", "contract-salary", "contract-submit", "contract-insurance", "contract-insure", "contracts-bonuses", "contract-bonus", "contract-quote"};
if (!actions.contains(action)) return false;
if (!engine_fresh_ || engine_busy_) return true;
const auto id = target ? target->GetAttribute<Rml::String>("data-id", "") : std::string();
if (action == "contract-close") { engine_contracts_close(); return true; }
if (action == "contracts-tab" && contracts_dialog_.empty()) {
if (id == "0" || id == "1" || id == "2") { contracts_tab_ = std::stoi(id); focus_after_render_ = target->GetId(); refresh(); } return true;
}
if (action == "contract-player" && contracts_dialog_.empty()) {
const auto view = engine_contracts_projection(engine_data_); const auto row = contracts_row(view, id);
if (!row.is_object()) return true;
contracts_player_ = id; contracts_world_ = world_; contracts_revision_ = input_revision(); contracts_return_focus_ = target->GetId(); contracts_notice_.clear();
contract_draft_ = {{"club", view.at("club")}, {"row", row}, {"salary", row.at("salary").get<int64_t>() / 100}, {"months", 12}};
contracts_dialog_ = "offer"; focus_after_render_ = "contract-term-12"; refresh(); return true;
}
if (action == "contract-insurance" && contracts_dialog_ == "offer") {
contracts_dialog_ = "engine-details"; focus_after_render_ = "contract-close"; refresh(); return true;
}
if (action == "contract-term" && contracts_dialog_ == "offer") {
if (id == "12" || id == "24" || id == "36" || id == "48") { contract_draft_["months"] = std::stoi(id); focus_after_render_ = target->GetId(); refresh(); } return true;
}
if (action == "contract-quote" && contracts_dialog_ == "offer") {
const auto command = engine_contract_request(engine_data_, contracts_player_, editor::new_id("request:ui-"));
engine_contract_operation_ = "quote"; engine_finance_submit(command); return true;
}
if (action == "contract-salary" && contracts_dialog_ == "offer") {
const auto view = engine_contracts_projection(engine_data_), quote = view.at("quote");
if (!quote.is_object() || quote.at("player") != contracts_player_) return true;
const auto meta = engine_data_.at("desktop").at("meta"), quote_id = quote.at("id");
const auto player = contracts_player_;
AmountRequest request; request.title = "Angebotenes Monatsgehalt"; request.unit = "€"; request.return_focus = "contract-salary";
request.value = contract_draft_.at("salary"); request.min = 0; request.max = quote.at("max_salary").get<int64_t>() / 100;
request.step = 1; request.suggestion_step = 5000; request.review = true;
request.review_text = [](int64_t) { return "Entwurf ändern. Das Vertragsangebot wird danach separat bestätigt."; };
request.accept = [this, meta, player, quote_id](int64_t value) {
if (!engine_fresh_ || engine_busy_ || menu_ != "contracts" || contracts_dialog_ != "offer" || contracts_player_ != player || meta != engine_data_.at("desktop").at("meta")) return false;
const auto quote = engine_contracts_projection(engine_data_).at("quote");
if (!quote.is_object() || quote.at("id") != quote_id) return false;
contract_draft_["salary"] = value; refresh(); return true;
};
open_amount(std::move(request)); return true;
}
if (action == "contract-submit" && contracts_dialog_ == "offer") {
const auto quote = engine_contracts_projection(engine_data_).at("quote"); if (!quote.is_object()) return true;
const auto salary = contract_draft_.at("salary").get<int64_t>(); const int years = contract_draft_.at("months").get<int>() / 12;
const auto command = engine_contract_offer(engine_data_, contracts_player_, quote.at("id"), years, salary, editor::new_id("request:ui-"));
confirmation(contract_draft_.at("row").at("name").get<std::string>() + ": " + std::to_string(years) + " Jahre zu " + money(salary * 100, {{"code", "EUR"}, {"minor_units", 2}}) + " pro Monat verbindlich anbieten?", [this, command] {
engine_contract_operation_ = "offer"; engine_finance_submit(command);
}); return true;
}
return true; // Missing insurance/bonus write APIs stay read-only.
}
+11 -1
View File
@@ -31,13 +31,16 @@ void App::engine_poll() {
engine_notice_ = engine_text(engine_response_.at("feedback")) + (engine_dirty_ ? " · Änderungen noch nicht gespeichert." : "");
} else if (engine_response_.value("messageType", "") == "error") {
engine_dirty_ = engine_base_dirty_;
engine_notice_ = "Änderung abgewiesen: " + engine_response_.value("code", "unknown_error");
auto reason = engine_text(engine_response_.value("message", Json()));
if (reason.empty() || reason == "—") reason = engine_response_.value("code", "unknown_error");
engine_notice_ = "Änderung abgewiesen: " + reason;
} 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.";
if (engine_response_.value("messageType", "") == "command_result") { advertising_selected_ = -1; advertising_offer_ = 0; }
engine_credit_ = engine_data_.value("credit", Json()); engine_credit_edits_ = Json::array();
engine_ticket_bind();
engine_contracts_poll();
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")}};
@@ -52,6 +55,10 @@ void App::engine_frame() {
engine_sports_update();
if (ticket_) ticket_->update();
render_popup(); context_->Update();
if (menu_ == "contracts" && engine_contract_scroll_) {
if (auto *roster = element("contracts-roster-scroll")) roster->SetScrollTop(*engine_contract_scroll_);
engine_contract_scroll_.reset();
}
if (center_selects(*doc_)) context_->Update();
if (menu_ == "lineup" && lineup_roster_scroll_) {
if (auto *roster = element("lineup-roster-scroll")) roster->SetScrollTop(*lineup_roster_scroll_);
@@ -100,6 +107,7 @@ void App::engine_event(Rml::Event &event) {
if (amount_event(event)) return;
if (!engine_busy_ && bank_event(event)) return;
if (!engine_busy_ && advertising_event(event)) return;
if (!engine_busy_ && popup_.empty() && contracts_event(event)) return;
if (engine_sports_event(event)) return;
Rml::ElementFormControl *range = nullptr;
for (auto *node = target; node && node != doc_; node = node->GetParentNode())
@@ -162,6 +170,7 @@ 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 (contracts_action(action, node)) return;
if (environment_action(action, node)) return;
if (advertising_action(action, node)) return;
if (bank_action(action, node)) return;
@@ -173,6 +182,7 @@ void App::engine_event(Rml::Event &event) {
ticket_->open(node, device_ratio_, price.at("min"), price.at("max")); dirty_ = true;
}
else if (action == "engine-open" && (id == "environment" || id == "advertising")) { menu_ = id; advertising_selected_ = -1; advertising_offer_ = 0; refresh(); }
else if (action == "engine-open" && id == "contracts") { menu_ = id; engine_contracts_clear(false); contracts_player_.clear(); engine_contract_scroll_ = 0.f; refresh(); }
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(); }
+67
View File
@@ -502,4 +502,71 @@ Json engine_budget_command(const Json &bundle, const std::string &id, int64_t eu
"Budget ist gesperrt oder außerhalb des verfügbaren Bereichs.");
return sports_command(bundle, "budget.commit", {{"budgetId", id}, {"amount", {{"currency", "EUR"}, {"minorUnits", 2}, {"minor", std::to_string(euros * 100)}}}}, request_id);
}
Json engine_contracts_projection(const Json &bundle) {
validate_engine_desk(bundle);
const auto &data = lineup_read(bundle, "contracts"), &meta = bundle.at("desktop").at("meta");
require(data.at("teamId") == meta.at("scope").at("teamId"), "Verträge gehören einer anderen Mannschaft.");
const auto squad = engine_lineup_projection(bundle);
require(data.at("players").is_array() && data.at("players").size() == squad.at("rows").size(), "Verträge und Kader passen nicht zusammen.");
const auto commands = meta.at("scope").value("allowedCommands", Json::array());
const auto allowed = [&](const char *name) { return commands.is_array() && std::find(commands.begin(), commands.end(), Json(name)) != commands.end(); };
Json rows = Json::array(); int64_t total = 0; std::set<std::string> ids;
for (const auto &member : squad.at("rows")) {
const Json *person = nullptr; const auto id = member.at("id").get<std::string>();
for (const auto &p : data.at("players")) if (p.at("playerId") == id) { require(!person, "Doppelte Vertrags-ID."); person = &p; }
require(person, "Vertrag fehlt für einen Kaderspieler.");
auto row = member;
const auto salary = engine_money_minor(person->at("salaryMonthly"));
require(salary >= 0 && salary <= std::numeric_limits<int64_t>::max() - total, "Ungültiges Monatsgehalt."); total += salary;
require(person->at("contractRemaining").at("unit") == "months" && person->at("offerBlocked").is_boolean(), "Unbekannte Vertragseinheit oder Sperre.");
row["name"] = person->at("name"); row["position"] = person->at("position");
row["age"] = whole_in_range(person->at("age"), 0, 255);
row["salary"] = salary; row["months"] = whole_in_range(person->at("contractRemaining").at("value"), 0, 255);
row["insurance"] = whole_in_range(person->at("insuranceMonths"), 0, 255);
row["insurance_fee"] = engine_money_minor(person->at("insuranceFee"));
require(row.at("insurance_fee").get<int64_t>() >= 0, "Ungültiger Versicherungsbetrag.");
row["source_label"] = "Aktuelles Monatsgehalt";
row["shoot"] = member.at("shooting"); row["pass"] = member.at("passing"); row["team"] = member.at("teamplay");
row["can_request"] = !person->at("offerBlocked").get<bool>() && allowed("quote.request") && allowed("contract.offer") && allowed("contract.cancel");
require(person->at("bonuses").is_array() && person->at("bonuses").size() == 7, "Unvollständige Prämienstufen.");
row["premiums"] = Json::array(); for (const auto &v : person->at("bonuses")) row["premiums"].push_back(whole_in_range(v, 0, 255));
rows.push_back(row); ids.insert(id);
}
Json quote;
if (!data.at("quote").is_null()) {
const auto &q = data.at("quote"); const auto id = q.at("id").get<std::string>();
require(id.starts_with("quote:contract-") && id.size() > 15 && q.at("playerId").is_string() && ids.contains(q.at("playerId").get<std::string>()), "Verhandlung gehört einem fremden Spieler.");
require(q.at("demands").is_array() && q.at("demands").size() == 4, "Unvollständige Gehaltsforderungen.");
const auto max = engine_money_minor(q.at("maxMonthlySalary"));
require(max >= 0 && max % 100 == 0 && max <= 9999999900LL, "Ungültige Gehaltsgrenze.");
Json demands = Json::array({nullptr,nullptr,nullptr,nullptr}); std::set<int> terms;
for (const auto &d : q.at("demands")) {
const int years = whole_in_range(d.at("years"), 1, 4); require(terms.insert(years).second, "Doppelte Vertragslaufzeit.");
const auto amount = engine_money_minor(d.at("monthlyDemand")); require(amount >= 0 && amount % 100 == 0, "Ungültige Gehaltsforderung.");
// The legacy contract service uses zero / UINT32_MAX for unavailable terms.
if (amount > 0 && amount != 429496729500LL) demands[size_t(years - 1)] = amount;
}
quote = {{"id", id}, {"player", q.at("playerId")}, {"demands", demands}, {"max_salary", max}, {"can_offer", allowed("contract.offer")}};
}
return {{"ok", true}, {"club", data.at("teamId")}, {"rows", rows}, {"salary_total", total}, {"bonuses", Json::array()}, {"quote", quote}};
}
Json engine_contract_request(const Json &bundle, const std::string &id, const std::string &request_id) {
const auto view = engine_contracts_projection(bundle); bool allowed = false;
require(view.at("quote").is_null(), "Bitte zuerst die laufende Verhandlung schließen.");
for (const auto &r : view.at("rows")) if (r.at("id") == id) allowed = r.at("can_request");
require(allowed, "Dieser Spieler kann derzeit nicht verhandeln.");
return sports_command(bundle, "quote.request", {{"kind", "contract"}, {"playerId", id}}, request_id);
}
Json engine_contract_offer(const Json &bundle, const std::string &player, const std::string &id, int years, int64_t euros, const std::string &request_id) {
const auto q = engine_contracts_projection(bundle).at("quote");
require(q.is_object() && q.at("id") == id && q.at("player") == player, "Die Verhandlung ist nicht mehr aktuell.");
require(years >= 1 && years <= 4 && !q.at("demands")[size_t(years - 1)].is_null() && euros >= 0 && euros <= q.at("max_salary").get<int64_t>() / 100, "Ungültige Laufzeit oder Gehalt.");
return sports_command(bundle, "contract.offer", {{"quoteId", id}, {"years", years}, {"monthlySalary", {{"currency", "EUR"}, {"minorUnits", 2}, {"minor", std::to_string(euros * 100)}}}}, request_id);
}
Json engine_contract_cancel(const Json &bundle, const std::string &id, const std::string &request_id) {
const auto q = engine_contracts_projection(bundle).at("quote");
require(q.is_object() && q.at("id") == id, "Diese Verhandlung ist nicht mehr geöffnet.");
return sports_command(bundle, "contract.cancel", {{"quoteId", id}}, request_id);
}
} // namespace bmh::modern_ui
+10 -2
View File
@@ -37,6 +37,7 @@ Json App::engine_camp_view() const {
}
void App::engine_render() {
if (ticket_) ticket_->close(false);
if (menu_ == "contracts") if (auto *roster = element("contracts-roster-scroll")) engine_contract_scroll_ = roster->GetScrollTop();
if (menu_ == "lineup") {
if (auto *roster = element("lineup-roster-scroll")) lineup_roster_scroll_ = lineup_reset_scroll_ ? 0.f : roster->GetScrollTop();
lineup_reset_scroll_ = false;
@@ -71,6 +72,8 @@ void App::engine_render() {
try { (void)engine_advertising_projection(engine_data_); advertising_available = true; } catch (const std::exception &) {}
environment_available = environment_available && std::find(allowed.begin(), allowed.end(), Json("environment.commit")) != allowed.end();
advertising_available = advertising_available && (std::find(allowed.begin(), allowed.end(), Json("advertising.accept")) != allowed.end() || std::find(allowed.begin(), allowed.end(), Json("budget.commit")) != allowed.end());
bool contracts_available = false;
try { (void)engine_contracts_projection(engine_data_); contracts_available = true; } catch (const std::exception &) {}
init_desktop();
for (const auto &[id, o] : desktop_.at("objects").items()) {
if (!o.value("visible", false)) continue;
@@ -103,11 +106,12 @@ 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 == "environment" && environment_available && engine_fresh_) || (route == "advertising" && advertising_available && engine_fresh_) || (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());
const bool supported = (route == "contracts" && contracts_available && engine_fresh_) || (route == "environment" && environment_available && engine_fresh_) || (route == "advertising" && advertising_available && engine_fresh_) || (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_ == "contracts") out += "<div class=\"fill\" style=\"z-index:100;\">" + window("Verträge", render_contracts()) + "</div>";
if (menu_ == "environment") out += "<div class=\"fill\" style=\"z-index:100;\">" + window("Umfeld", render_environment()) + "</div>";
if (menu_ == "advertising") out += "<div class=\"fill\" style=\"z-index:100;\">" + window("Werbung", render_advertising()) + "</div>";
if (menu_ == "bank") out += "<div class=\"fill\" style=\"z-index:100;\">" + window("Bank", render_bank()) + "</div>";
@@ -116,7 +120,7 @@ void App::engine_render() {
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" || menu_ == "environment" || menu_ == "advertising") && !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_ == "bank" || menu_ == "environment" || menu_ == "advertising" || menu_ == "contracts") && !amount_ && contracts_dialog_.empty()) 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();
@@ -127,6 +131,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 (!contracts_dialog_.empty()) {
Rml::ElementList underlay; doc_->QuerySelectorAll(underlay, "#contracts-underlay button,.contracts-actions button,#window-close");
for (auto *node : underlay) { node->SetAttribute("disabled", true); node->SetProperty("pointer-events", "none"); }
}
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)"); }
+6
View File
@@ -5,6 +5,12 @@
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();
std::string engine_contract_operation_;
std::optional<float> engine_contract_scroll_;
bool engine_contracts_action(const std::string &, Rml::Element *);
void engine_contracts_poll();
void engine_contracts_clear(bool focus = true);
void engine_contracts_close(bool focus = true);
bool engine_commerce_action(const std::string &, Rml::Element *);
bool engine_bank_action(const std::string &, Rml::Element *);
std::string engine_credit_view();
+1
View File
@@ -1518,6 +1518,7 @@ public:
#include "modern/ui/engine_sports.inc"
#include "modern/ui/engine_finance.inc"
#include "modern/ui/engine_commerce.inc"
#include "modern/ui/engine_contracts.inc"
} // namespace
bool is_modern_world(const fs::path &file) {
try {