The interested clubs fill a sheet of their own

The change of club is a far-reaching decision: the clubs are listed large
on the left, and the chosen one is shown on the right beside the manager's
own club - the team part by part, its places over the season, the cash,
the ground and the squad. Taking a club asks once more.

The read "assembly" reports lines, places, squad size and ground per club.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
MichaelandClaude Fable 5.2 committed 2026-11-17 13:38:21 +01:00
1 parent a2b9770d81
commit 101273f777
7 files changed
+226 -31

No files matched your search

+127 -19
View File
@@ -82,37 +82,145 @@ void App::engine_assembly_tick() {
engine_assembly_started_ = 0;
}
}
// The clubs that want the manager: crest, league, the strength of their eleven beside his own,
// and the cash they give him to start with.
// The clubs that want the manager, on a sheet as large as a page of the notebook: the clubs on
// the left, and on the right what the chosen one is like beside the manager's own club.
void App::engine_assembly_clubs(bool forced) {
engine_assembly_forced_ = forced;
const Json offers = engine_assembly_.value("offers", Json::array());
if (offers.empty()) {
engine_assembly_open_ = false;
message("Zurzeit interessiert sich kein Verein für dich.");
return;
}
engine_assembly_open_ = true;
engine_assembly_pick_ = offers.front().value("teamId", std::string());
engine_assembly_scroll_ = 0.f;
refresh();
}
namespace {
// 1234567 -> 1.234.567
std::string assembly_count(int64_t n) {
std::string digits = std::to_string(n < 0 ? -n : n), out;
for (size_t i = 0; i < digits.size(); ++i) {
if (i && (digits.size() - i) % 3 == 0) out += '.';
out += digits[i];
}
return (n < 0 ? "−" : "") + out;
}
// Money of the contract ({minor: "…"}) in whole euros.
int64_t assembly_euros(const Json &money) {
try {
return std::stoll(money.at("minor").get<std::string>()) / 100;
} catch (const std::exception &) { return 0; }
}
// Two bars side by side for one part of the team: the manager's club and the other one.
std::string assembly_pair(const char *name, int own, int other) {
const auto bar = [](int value, const char *css) {
return "<div class=\"cs-col\"><span class=\"cs-num\">" + std::to_string(value) + "</span><div class=\"cs-bar " + std::string(css) + "\" style=\"height:" + scalar(std::clamp(value, 0, 99) * 4.6 + 6) + "dp;\"></div></div>";
};
return "<div class=\"cs-grp\"><div class=\"cs-bars\">" + bar(own, "own") + bar(other, "new") + "</div><span class=\"cs-cap\">" + esc(name) + "</span></div>";
}
} // namespace
std::string App::engine_assembly_sheet() {
const Json offers = engine_assembly_.value("offers", Json::array());
const Json own = engine_assembly_.value("club", Json::object());
std::string body = "<div class=\"po-offers\">";
const Json *chosen = nullptr;
for (const auto &offer : offers)
if (offer.value("teamId", std::string()) == engine_assembly_pick_) chosen = &offer;
if (!chosen && !offers.empty()) chosen = &offers.front();
const auto name_of = [&](const Json &row) {
const auto *club = world_->find("clubs", row.value("teamId", std::string()));
return club ? world_->name(*club) : row.value("name", std::string("Verein"));
};
const auto place_of = [](const Json &row) {
return row.contains("position") && row.at("position").is_number_integer() ? "Platz " + std::to_string(row.at("position").get<int>()) : std::string("noch ohne Platz");
};
const bool forced = engine_assembly_forced_;
std::string out = "<div id=\"assembly-layer\" class=\"pg-ov\"><section class=\"pg-dlg cs-sheet\" role=\"dialog\" aria-modal=\"true\"><header class=\"cs-head\"><span class=\"pg-k\">" +
std::string(forced ? "NACH DER ABWAHL" : "VEREINSWECHSEL") + "</span><h2>Interessierte Vereine</h2><span class=\"pg-dlg-sub\">" +
esc(forced ? "Einen dieser Vereine musst du übernehmen, bevor die neue Saison beginnt." : "Diese Vereine wollen dich verpflichten. Die Liste wechselt alle zwei Wochen.") +
"</span></header><div class=\"cs-body\"><div id=\"assembly-list\" class=\"cs-list\">";
for (const auto &offer : offers) {
const std::string id = offer.value("teamId", std::string());
const auto *club = world_->find("clubs", id);
const std::string name = club ? world_->name(*club) : offer.value("name", std::string("Ein Verein"));
body += "<div class=\"po-offer\"><span class=\"po-crest\">" + (club ? crest(club, 72) : std::string()) + "</span><div class=\"po-text\"><strong>" + esc(name) + "</strong><span>" + esc(offer.value("league", std::string())) +
(offer.contains("position") && offer.at("position").is_number_integer() ? " · Platz " + std::to_string(offer.at("position").get<int>()) : std::string()) + " · Stärke " + std::to_string(offer.value("strength", 0)) +
" · Startkapital " + esc(offer.contains("cash") ? engine_price(offer.at("cash")) : std::string("—")) + "</span></div>" +
pg_button("assembly-club", "Übernehmen", "primary", "id=\"assembly-club-" + esc(id) + "\" data-id=\"" + esc(id) + "\"") + "</div>";
const bool on = chosen && id == chosen->value("teamId", std::string());
out += "<button data-action=\"assembly-pick\" class=\"cs-club" + std::string(on ? " on" : "") + "\" id=\"assembly-pick-" + esc(id) + "\" data-id=\"" + esc(id) + "\" aria-pressed=\"" + (on ? "true" : "false") +
"\"><span class=\"cs-crest\">" + (club ? crest(club, 150) : std::string()) + "</span><div class=\"cs-text\"><div class=\"cs-name\">" + esc(name_of(offer)) + "</div><div class=\"cs-line\">" + esc(offer.value("league", std::string())) + " · " +
esc(place_of(offer)) + "</div><div class=\"cs-line\">Startkapital " + esc(offer.contains("cash") ? engine_price(offer.at("cash")) : std::string("—")) + "</div></div><div class=\"cs-power\"><div class=\"cs-figure\">" +
std::to_string(offer.value("strength", 0)) + "</div><div class=\"cs-line\">Stärke</div></div></button>";
}
body += "</div>";
const std::string strength = own.contains("strength") ? " Deine Elf hat die Stärke " + std::to_string(own.value("strength", 0)) + "." : std::string();
message(offers.empty() ? "Zurzeit interessiert sich kein Verein für dich."
: forced ? "Diese Vereine wollen dich verpflichten. Einen davon musst du übernehmen, bevor die neue Saison beginnt." + strength
: "Diese Vereine wollen dich verpflichten. Die Liste wechselt alle zwei Wochen." + strength);
popup_title_ = "Interessierte Vereine";
popup_close_ = forced ? "Zum Schreibtisch" : "Abbrechen";
popup_body_ = body;
out += "</div><div class=\"cs-detail\">";
if (chosen) {
const Json &c = *chosen;
const auto *club = world_->find("clubs", c.value("teamId", std::string()));
const std::string name = name_of(c), mine = name_of(own);
out += "<div class=\"cs-top\"><span class=\"cs-big\">" + (club ? crest(club, 230) : std::string()) + "</span><div class=\"cs-title\"><h3>" + esc(name) + "</h3><span>" + esc(c.value("league", std::string())) + " · " +
esc(place_of(c)) + (c.contains("leagueSize") ? " von " + std::to_string(c.value("leagueSize", 0)) : std::string()) + "</span></div><div class=\"cs-key\"><span class=\"own\">" + esc(mine) +
"</span><span class=\"new\">" + esc(name) + "</span></div></div>";
// the team, part by part
const Json a = own.value("lines", Json::object()), b = c.value("lines", Json::object());
out += "<div class=\"cs-row\"><section class=\"cs-box cs-team\"><span class=\"pg-k\">MANNSCHAFT IM VERGLEICH</span><div class=\"cs-chart\">" + assembly_pair("Tor", a.value("goal", 0), b.value("goal", 0)) +
assembly_pair("Abwehr", a.value("defence", 0), b.value("defence", 0)) + assembly_pair("Mittelfeld", a.value("midfield", 0), b.value("midfield", 0)) +
assembly_pair("Angriff", a.value("attack", 0), b.value("attack", 0)) + assembly_pair("Elf gesamt", own.value("strength", 0), c.value("strength", 0)) + "</div></section>";
// the season so far, place by round
const Json places = c.value("positions", Json::array());
const int size = std::max(c.value("leagueSize", 18), 2);
std::string curve;
if (places.size() >= 2) {
std::string points;
for (size_t i = 0; i < places.size(); ++i)
points += scalar(12 + 576.0 * double(i) / double(places.size() - 1)) + "," + scalar(12 + 336.0 * double(std::clamp(places[i].get<int>(), 1, size) - 1) / double(size - 1)) + " ";
const std::string last_y = scalar(12 + 336.0 * double(std::clamp(places.back().get<int>(), 1, size) - 1) / double(size - 1));
curve = picture(renderer_.diagram("assembly-places-" + c.value("teamId", std::string()) + "-" + std::to_string(places.size()),
"<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 600 360'><path d='M12 12H588M12 180H588M12 348H588' stroke='#8a7d6b' stroke-opacity='.35' stroke-width='1.5'/><polyline points='" + points +
"' fill='none' stroke='#c2693a' stroke-width='5' stroke-linejoin='round' stroke-linecap='round'/><circle cx='588' cy='" + last_y + "' r='9' fill='#c2693a'/></svg>", 1200), 780, 468);
}
out += "<section class=\"cs-box cs-season\"><span class=\"pg-k\">TABELLENPLATZ IN DIESER SAISON</span>" +
(curve.empty() ? std::string("<div class=\"cs-none\">Noch zu wenige Spieltage.</div>")
: "<div class=\"cs-curve\"><span class=\"cs-axis top\">1.</span><span class=\"cs-axis bottom\">" + std::to_string(size) + ".</span>" + curve + "</div>") + "</section></div>";
// money, ground and squad
const int64_t now = assembly_euros(engine_assembly_.value("cash", Json::object())), then = assembly_euros(c.value("cash", Json::object()));
const double scale = double(std::max<int64_t>({std::llabs(now), std::llabs(then), 1}));
const auto money_bar = [&](const char *label, int64_t value, const char *css) {
return "<div class=\"cs-money\"><span class=\"cs-label\">" + std::string(label) + "</span><div class=\"cs-track\"><div class=\"cs-fill " + std::string(value < 0 ? "debt" : css) + "\" style=\"width:" +
scalar(std::max(2.0, 100.0 * double(std::llabs(value)) / scale)) + "%;\"></div></div><span class=\"cs-sum\">" + assembly_count(value) + " €</span></div>";
};
out += "<div class=\"cs-row\"><section class=\"cs-box cs-cash\"><span class=\"pg-k\">VEREINSKASSE</span>" + money_bar("Dein Konto heute", now, "own") + money_bar("Startkapital dort", then, "new") +
"</section><section class=\"cs-box cs-fact\"><span class=\"pg-k\">STADION</span><strong>" +
(c.contains("stadiumCapacity") && c.at("stadiumCapacity").is_number_integer() ? assembly_count(c.at("stadiumCapacity").get<int64_t>()) : std::string("—")) +
"</strong><span>Plätze zum Start</span></section><section class=\"cs-box cs-fact\"><span class=\"pg-k\">KADER</span><strong>" + std::to_string(c.value("squad", 0)) + "</strong><span>Spieler</span></section></div>" +
"<p class=\"cs-note\">Beim Wechsel bleiben dein Konto, deine Aktien, Fonds und Kredite zurück. Stadion, Verträge und Werbung beginnen beim neuen Verein neu.</p>";
}
out += "</div></div><nav class=\"pg-dlg-act\">" + pg_button("assembly-close", forced ? "Zum Schreibtisch" : "Abbrechen", "", "id=\"assembly-close\"") +
pg_button("assembly-take", chosen ? name_of(*chosen) + " übernehmen" : std::string("Übernehmen"), "primary", "id=\"assembly-take\" " + std::string(chosen ? "" : "disabled=\"disabled\"")) + "</nav></section></div>";
return out;
}
// A club of the list was chosen: asked once more, because nothing of the old club comes along.
bool App::engine_assembly_action(const std::string &action, const std::string &id) {
if (action == "assembly-pick") {
engine_assembly_pick_ = id;
focus_after_render_ = "assembly-pick-" + id;
refresh();
return true;
}
if (action == "assembly-close") {
engine_assembly_open_ = false;
refresh();
return true;
}
if (action == "assembly-take" && !engine_busy_) {
engine_assembly_choose(engine_assembly_pick_);
return true;
}
return false;
}
// A club was taken: asked once more, because nothing of the old club comes along.
void App::engine_assembly_choose(const std::string &team) {
const auto *club = world_->find("clubs", team);
const std::string name = club ? world_->name(*club) : std::string("diesem Verein");
if (team.empty() || !club) return;
const std::string name = world_->name(*club);
const bool forced = engine_assembly_forced_;
confirmation("Wirklich zu " + name + " wechseln? Dein Konto, deine Aktien, Fonds und Kredite bleiben zurück; beim neuen Verein beginnst du mit dessen Startkapital und einem neuen Vertragswerk.", [this, team, forced] {
confirmation("Wirklich zu " + name + " wechseln? Das lässt sich nicht zurücknehmen. Dein Konto, deine Aktien, Fonds und Kredite bleiben zurück; beim neuen Verein beginnst du mit dessen Startkapital und neuen Verträgen.", [this, team, forced] {
engine_assembly_open_ = false;
if (forced) {
engine_advance_payload_["assembly"] = {{"seen", true}, {"teamId", team}};
engine_kickoff();
+5 -6
View File
@@ -272,6 +272,10 @@ void App::engine_frame() {
if(menu_=="news")news_after_render();
if(rendered&&files_native_){files_after_render();context_->Update();}
if (center_selects(*doc_)) context_->Update();
if (engine_assembly_scroll_) {
if (auto *clubs = element("assembly-list")) clubs->SetScrollTop(*engine_assembly_scroll_);
engine_assembly_scroll_.reset();
}
if (menu_ == "lineup" && lineup_roster_scroll_) {
if (auto *roster = element("lineup-roster-scroll")) roster->SetScrollTop(*lineup_roster_scroll_);
lineup_roster_scroll_.reset();
@@ -477,12 +481,6 @@ void App::engine_event(Rml::Event &event) {
const auto action = node->GetAttribute<Rml::String>("data-action", ""), id = node->GetAttribute<Rml::String>("data-id", "");
if (!popup_.empty()) {
if(action=="balance-discard"){engine_balance_action(action,node);return;}
if (action == "assembly-club") {
const std::string team = id;
popup_.clear(); reset_popup(); confirm_ = {}; dirty_ = true;
engine_assembly_choose(team);
return;
}
if (action == "engine-offer-accept") {
const auto player = engine_offer_player_;
const int index = node->GetAttribute<int>("data-id", -1);
@@ -502,6 +500,7 @@ void App::engine_event(Rml::Event &event) {
if (action == "popup-confirm") { auto callback=std::move(confirm_);auto text_callback=std::move(text_accept_);const auto text=field("popup-text");popup_.clear();reset_popup();dirty_=true;if(text_callback)text_callback(text);else if(callback)callback(); }
return;
}
if (engine_assembly_open_) { engine_assembly_action(action, id); return; } // the sheet of the interested clubs lies over everything
if (action == "engine-widget-warning" && menu_.empty() && !engine_busy_) {
const auto rows = engine_widgets_projection(engine_data_).at("warnings");
std::string text;
+2
View File
@@ -45,6 +45,7 @@ void App::engine_render() {
if (menu_ == "settings") { settings_remember_scroll(); last_rendered_menu_ = menu_; }
if (menu_ == "friendlies") if (auto *list = element("friendly-opponents")) engine_friendly_scroll_ = list->GetScrollTop();
if (menu_ == "contracts") if (auto *roster = element("contracts-roster-scroll")) engine_contract_scroll_ = roster->GetScrollTop();
if (auto *clubs = element("assembly-list")) engine_assembly_scroll_ = clubs->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;
@@ -230,6 +231,7 @@ void App::engine_render() {
element("canvas")->SetProperty("overflow",statistics_trophy_.contains("asset")?"visible":"hidden");
setting_menu_markup_ = true;
notebook_finish(out);
if (engine_assembly_open_) out += engine_assembly_sheet();
element("canvas")->SetInnerRML(out); ++document_generation_;
setting_menu_markup_ = false;
needs_render_ = false;
+7
View File
@@ -53,6 +53,13 @@
void engine_assembly_ask(const Json &args);
void engine_assembly_clubs(bool forced);
void engine_assembly_choose(const std::string &team);
// The big sheet of the interested clubs: open or not, the club whose details are shown, and
// where its list was scrolled to before the sheet was drawn again.
bool engine_assembly_open_ = false;
std::string engine_assembly_pick_;
std::optional<float> engine_assembly_scroll_;
std::string engine_assembly_sheet();
bool engine_assembly_action(const std::string &action, const std::string &id);
// The needle of the meeting: when it started to swing (0 = at rest) and where it comes to rest.
uint64_t engine_assembly_started_ = 0;
int engine_assembly_target_ = 50;