From abbd4afe7077fb10878090c68e9c20863e01d45f Mon Sep 17 00:00:00 2001 From: Weyoune Date: Mon, 16 Nov 2026 17:27:41 +0100 Subject: [PATCH] Formations can be used and saved in the line-up The read "lineup" states the manager's eight formations (four given, four of his own) and the one in use; "lineup.setFormation" uses one, the assistant placing the eleven on it, or keeps the places as they stand as one of the own formations. The line-up page shows them as small pitches behind "Aufst.". Co-Authored-By: Claude Fable 5.2 --- assets/modern/pages.rcss | 6 ++++ docs/new_engine/ui-anbindung.md | 1 + src/modern/app/modern_session.cpp | 51 ++++++++++++++++++++++++++++++ src/modern/content/ui_contract.cpp | 2 +- src/modern/ui/engine_bridge.hpp | 1 + src/modern/ui/engine_dto.cpp | 20 ++++++++++++ src/modern/ui/engine_lineup.inc | 31 +++++++++++++++++- src/modern/ui/engine_state.inc | 1 + src/modern/ui/lineup_page.inc | 45 ++++++++++++++++++++++++-- 9 files changed, 153 insertions(+), 5 deletions(-) diff --git a/assets/modern/pages.rcss b/assets/modern/pages.rcss index a57f621..dcc57ac 100644 --- a/assets/modern/pages.rcss +++ b/assets/modern/pages.rcss @@ -1060,3 +1060,9 @@ body.midnight .cp-map-name,body.matchday .cp-map-name {color:#f0ece2;font-effect .lp-order .pg-bar {flex:1;} .lp-order-value {display:block;flex:none;width:60dp;text-align:center;font-family:Display;font-weight:normal;font-size:38dp;line-height:46dp;} .pg-root .pg-btn.lp-step {flex:none;width:58dp;height:58dp;padding:0;font-size:30dp;} +/* line-up: the formations */ +.lp-shapes {flex:none;align-items:stretch;gap:12dp;} +.pg-card.lp-shape-card,.pg-card.lp-shape-card:hover {display:flex;flex:1;flex-direction:row;align-items:center;justify-content:center;gap:18dp;padding:4dp 14dp;border-radius:24dp;min-width:0;} +.lp-shape-pitch {display:block;flex:none;width:60dp;height:80dp;} +.lp-shape-name {display:block;font-family:Display;font-weight:normal;font-size:48dp;line-height:54dp;} +.lp-shape-card[disabled] {opacity:0.45;} diff --git a/docs/new_engine/ui-anbindung.md b/docs/new_engine/ui-anbindung.md index d53aaf8..16cf5d8 100644 --- a/docs/new_engine/ui-anbindung.md +++ b/docs/new_engine/ui-anbindung.md @@ -107,6 +107,7 @@ Die UI ruft diese über `DataSource::read_almanac` und `read_statistics` direkt | `lineup.commit` | `order`: Spieler-IDs in der gewünschten Reihenfolge | öffnet die Aufstellung wie am Schreibtisch und tauscht die Zeilen; Fehler `unknown_player`, `lineup_refused` (z. B. Verletzte, Ausländerregel) | | `session.advance` (Zusatz) | `transferOffers {playerId: {accept: 0–3} \| {action: "decline"}}` | die Antwort des Verkäufers auf die Gebote für einen Spieler, den er auf die Transferliste gesetzt hat (Stichtag der Woche). Gefragt wird nur, wer das Feld sendet (auch leer); ohne das Feld läuft der Anstoß wie bisher und alle Gebote an menschliche Verkäufer verfallen. Ohne Antwort wird der Lauf zurückgenommen und `decision_pending` mit `args {decision: "transfer_offers", playerId, name, sellerManagerId, askingFee, offers [{index, teamId, fee, monthlySalary, months, loan, eligible}]}` gemeldet; die Oberfläche fragt und sendet den Anstoß erneut | | `transfer.submit` (Abwerben) | `action: "poach"`, `playerId` · `action: "poachOffer"`, `fee`, `monthlySalary`, `years` 1–4 · `action: "poachCancel"` | zweistufig wie im Original: `poach` prüft, fragt den Verein und zählt den Versuch (fünf je Saison); kann geboten werden, bleibt der Angebotseditor offen und die Antwort trägt `outcome: "poach_open"` und `poach {playerId, name, sellerId, askingFee, askingMonthlySalary, fee, monthlySalary, feeRange {min, max}, salaryRange {min, max}, years, attemptsLeft}`, sonst `poach_refused` mit der Begründung. `poachOffer` wird sofort entschieden (`poach_accepted`, `poach_rejected`; ein zu niedriges Gebot lässt den Editor offen: `poach_open`), `poachCancel` schließt ohne Gebot. Solange der Editor offen ist, verweigern andere Befehle; Fehler `poach_open`, `no_poach`, `unknown_player`, `transfer_refused` | +| `lineup.setFormation` | `formation` 1–8, optional `save: true` (nur 5–8) | ohne `save` wird die Formation übernommen und der Co-Trainer stellt die Elf darauf (`apply_pitch_formation_source`); mit `save` werden die jetzigen Plätze der Elf als eigene Formation gespeichert und benutzt. Der Read `lineup` trägt dazu `formations [{formation, own, available, positions [{depth, lane} × 11]}]` und `formation` (0 = freie Aufstellung). Fehler `lineup_refused` | | `lineup.setOrder` | `playerId`, `aspect` 0–3, `value` 2–40 | eine der vier Anweisungen eines aufgestellten Spielers (die vier Pfeile der Originalansicht; der Read `lineup` nennt sie je Feldspieler unter `positions[].orders`); Fehler `invalid_payload`, `unknown_player`, `lineup_refused` | | `lineup.setPiece` | `piece` `freeKick`/`penalty`/`corner` und `playerId`, oder `auto: true` | trägt einen Schützen ein (aufgestellt oder auf der Bank, einsatzfähig) bzw. gibt alle drei an den Assistenten zurück; der Read `lineup` nennt sie unter `setPieces` (`null` = Assistent); Fehler `invalid_payload`, `unknown_player`, `lineup_refused` | | `tactics.commit` | `values`: die acht Werte | jede geänderte Einstellung über die Prüfung der Taktiktafel (eine gesetzte Grundausrichtung beendet die Steuerung durch den Assistenten); Fehler `invalid_tactic` | diff --git a/src/modern/app/modern_session.cpp b/src/modern/app/modern_session.cpp index c1dbdd4..8b78fda 100644 --- a/src/modern/app/modern_session.cpp +++ b/src/modern/app/modern_session.cpp @@ -9261,8 +9261,26 @@ cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) co if ((g_.squad_slots[range.first + row] & 0x0fff) == stored - 1) return row_ids[row]; return nullptr; }; + // the eight formations of the manager (table of 0x160 bytes per manager, the hall's half at + // +0xb0; each formation 11 depths, then 11 lanes): 1-4 are given, 5-8 his own. Record + // +0x218 (+1 in the hall) says which exist; option byte 0 names the one in use, 0 a free + // placement. + A formations; + const size_t formation_table = size_t(manager) * 0x160 + (g_.indoor ? 0xb0 : 0); + const size_t formation_mask = size_t(manager) * 0xb0c + 0x218 + size_t(g_.indoor); + if (formation_table + 8 * 0x16 <= g_.formations.size() && formation_mask < g_.manager_records.size()) + for (int f = 0; f < 8; ++f) { + A places; + for (size_t i = 0; i < 11; ++i) + places.push_back(O{{"depth", int(int8_t(g_.formations[formation_table + size_t(f) * 0x16 + i]))}, + {"lane", int(int8_t(g_.formations[formation_table + size_t(f) * 0x16 + 11 + i]))}}); + formations.push_back(O{{"formation", f + 1}, {"own", f >= 4}, + {"available", (g_.manager_records[formation_mask] & (1u << f)) != 0}, {"positions", std::move(places)}}); + } + const int formation_in_use = g_.manager_options.size() > size_t(manager) * 5 ? int(g_.manager_options[size_t(manager) * 5]) : 0; return modern::ui_snapshot(g_, context, request_id, O{{"kind", "lineup"}, {"teamId", modern::ui_team_id(g_, team)}, {"formationId", nullptr}, {"order", std::move(order)}, + {"formations", std::move(formations)}, {"formation", formation_in_use >= 1 && formation_in_use <= 8 ? formation_in_use : 0}, {"setPieces", O{{"freeKick", taker(0xafc)}, {"penalty", taker(0xafe)}, {"corner", taker(0xb08)}}}, {"surface", g_.indoor ? "indoor" : "outdoor"}, {"durationMinutes", g_.indoor ? 40 : 90}, {"starterCount", 11}, {"pairs", std::move(pairs)}, @@ -11168,6 +11186,39 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision } revision = previous + 1; answer = modern::ui_command_result(request_id, previous, revision, {"lineup"}, "Anweisung übernommen."); + } else if (kind == "lineup.setFormation") { + // payload {formation 1-8}: the formation is used and the assistant places the eleven on it + // (apply_pitch_formation_source). {formation 5-8, save: true}: the places of the eleven as + // they stand become this own formation, which is used from then on + // (save_pitch_formation_source). + const int team = g_.manager_teams[size_t(manager)]; + const cli::Json* formation = ui_field(*payload, "formation"); + const cli::Json* save = ui_field(*payload, "save"); + const bool saving = save && save->boolean() && *save->boolean(); + if (!formation || !formation->integer() || *formation->integer() < 1 || *formation->integer() > 8 || (save && !save->boolean()) || + (saving && *formation->integer() < 5)) + return refuse("invalid_payload", "formation 1-8; save: true nur für die eigenen Formationen 5-8."); + const size_t rec = size_t(manager) * 0xb0c, board = size_t(manager) * 0x840; + if (rec + 0x288 >= g_.manager_records.size() || board + 11 * 0x58 > g_.tactics.size()) return refuse("lineup_refused", "Formationen sind hier nicht verfügbar."); + const uint8_t weights = g_.manager_records[rec + 0x288]; + bool ok = false; + if (saving) { + std::array places{}; + for (size_t row = 0; row < 11; ++row) { + places[row] = g_.tactics[board + row * 0x58 + 0x41]; + places[11 + row] = g_.tactics[board + row * 0x58 + 0x42]; + } + ok = save_pitch_formation_source(g_, manager, team, int(*formation->integer()) - 1, weights, places); + } else { + ok = apply_pitch_formation_source(g_, manager, team, int(*formation->integer()) - 1, weights); + } + if (!ok) { + restore(); + return refuse("lineup_refused", saving ? "Gespeichert wird nur eine vollständige Elf auf dem Feld." + : "Diese Formation gibt es nicht, oder die Elf lässt sich so nicht aufstellen."); + } + revision = previous + 1; + answer = modern::ui_command_result(request_id, previous, revision, {"lineup", "tactics", "squad"}, saving ? "Formation gespeichert." : "Formation übernommen."); } else if (kind == "lineup.setPiece") { // payload {piece: "freeKick" | "penalty" | "corner", playerId} names one taker; // {auto: true} hands all three back to the assistant (the original's AUTO) diff --git a/src/modern/content/ui_contract.cpp b/src/modern/content/ui_contract.cpp index 3487474..628c74c 100644 --- a/src/modern/content/ui_contract.cpp +++ b/src/modern/content/ui_contract.cpp @@ -151,7 +151,7 @@ A allowed_commands(const ModernState& g, const UiContext& c) { const int team = team_of(g, c.manager); const bool national = team == no_team(); static constexpr const char* kAll[] = { - "session.advance", "lineup.commit", "lineup.setPiece", "lineup.setOrder", "tactics.commit", "friendly.book", "manager.resign.commit", + "session.advance", "lineup.commit", "lineup.setPiece", "lineup.setOrder", "lineup.setFormation", "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", "contract.cancel", "news.update", "balance.commit", "settings.commit", "manager.join.commit"}; diff --git a/src/modern/ui/engine_bridge.hpp b/src/modern/ui/engine_bridge.hpp index d562f38..d14c8d2 100644 --- a/src/modern/ui/engine_bridge.hpp +++ b/src/modern/ui/engine_bridge.hpp @@ -23,6 +23,7 @@ Json engine_bank_projection(const Json &bundle); Json engine_bank_command(const Json &bundle, const Json &payload, const std::string &request_id); Json engine_order_command(const Json &bundle, const std::string &player, int aspect, int value, const std::string &request_id); Json engine_poach_command(const Json &bundle, const Json &payload, const std::string &request_id); +Json engine_formation_command(const Json &bundle, int formation, bool save, const std::string &request_id); Json engine_set_piece_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); diff --git a/src/modern/ui/engine_dto.cpp b/src/modern/ui/engine_dto.cpp index 50d5266..0a194ff 100644 --- a/src/modern/ui/engine_dto.cpp +++ b/src/modern/ui/engine_dto.cpp @@ -180,7 +180,18 @@ Json engine_lineup_projection(const Json &bundle) { set_pieces[key] = taker; } } + // the eight formations (1-4 given, 5-8 the manager's own) and the one in use; an older backend states none + Json formations = Json::array(); + if (lineup.contains("formations")) + for (const auto &entry : lineup.at("formations")) { + const int number = entry.at("formation").get(); + require(number >= 1 && number <= 8 && entry.at("positions").size() == 11 && entry.at("available").is_boolean(), "Ungültige Formation."); + Json places = Json::array(); + for (const auto &place : entry.at("positions")) places.push_back(Json::array({place.at("depth").get(), place.at("lane").get()})); + formations.push_back({{"formation", number}, {"own", number > 4}, {"available", entry.at("available")}, {"points", places}}); + } return {{"ok", true}, {"rows", rows}, {"field_count", points.size()}, {"set_pieces", set_pieces}, {"orders", orders}, + {"formations", formations}, {"formation", lineup.value("formation", 0)}, {"surface", surface.at("surface")}, {"duration", surface.at("duration")}, {"pairs", surface.at("pairs")}, {"board", {{"order", lineup.at("order")}, {"points", points}, {"depth_max", depth_max}, {"lane_max", lane_max}}}}; } @@ -190,6 +201,15 @@ Json engine_order_command(const Json &bundle, const std::string &player, int asp require(projection.at("orders").contains(player) && aspect >= 0 && aspect <= 3 && value >= 2 && value <= 40, "Ungültige Anweisung."); return sports_command(bundle, "lineup.setOrder", {{"playerId", player}, {"aspect", aspect}, {"value", value}}, request_id); } +Json engine_formation_command(const Json &bundle, int formation, bool save, const std::string &request_id) { + const auto projection = engine_lineup_projection(bundle); + bool known = false; + for (const auto &entry : projection.at("formations")) known |= entry.at("formation") == formation && (save ? entry.at("own").get() : entry.at("available").get()); + require(known, "Diese Formation gibt es nicht."); + Json payload{{"formation", formation}}; + if (save) payload["save"] = true; + return sports_command(bundle, "lineup.setFormation", payload, request_id); +} Json engine_poach_command(const Json &bundle, const Json &payload, const std::string &request_id) { const auto action = payload.at("action").get(); require(action == "poach" || action == "poachOffer" || action == "poachCancel", "Ungültiger Abwerbeauftrag."); diff --git a/src/modern/ui/engine_lineup.inc b/src/modern/ui/engine_lineup.inc index 3c7d1e9..eb06901 100644 --- a/src/modern/ui/engine_lineup.inc +++ b/src/modern/ui/engine_lineup.inc @@ -67,7 +67,9 @@ bool App::engine_lineup_action(const std::string &action, const std::string &id, } // "Schütze": the side panel names the takers of the set pieces; a click on a player then names him if (action == "lineup-side") { - lineup_side_ = (id == "takers" || id == "orders") && lineup_side_ != id ? id : "formations"; + // "Aufst." opens the formations; the same button again leads back to the plain swap panel + lineup_side_ = id == "formations" ? (lineup_side_ == "shapes" ? "formations" : "shapes") : (id == "takers" || id == "orders") && lineup_side_ != id ? id : "formations"; + lineup_shape_save_ = false; lineup_selected_.clear(); focus_after_render_ = "lineup-side-" + id; refresh(); return true; } if (action == "lineup-piece") { @@ -86,6 +88,33 @@ bool App::engine_lineup_action(const std::string &action, const std::string &id, }, true); } catch (const std::exception &e) { message(e.what()); } }; + // "Aufst.": a formation is used (the assistant places the eleven on it) or the places as they + // stand are kept as one of the four own formations + if (action == "lineup-formation-save") { + lineup_shape_save_ = !lineup_shape_save_; + focus_after_render_ = "lineup-formation-save"; refresh(); return true; + } + if (action == "lineup-formation") { + if (!engine_fresh_ || engine_busy_ || !target) return true; + const int number = target->GetAttribute("data-id", 0); + const bool save = lineup_shape_save_ && number > 4; + lineup_shape_save_ = false; + const std::string focus = target->GetId(); + confirmation(save ? "Die Plätze der Elf, wie sie jetzt stehen, als eigene Formation " + std::to_string(number - 4) + " speichern? Was dort gespeichert war, wird überschrieben." + : "Diese Formation übernehmen? Der Co-Trainer stellt die Elf dafür neu auf.", + [this, number, save, focus] { + try { + const auto command = engine_formation_command(engine_data_, number, save, editor::new_id("request:ui-")); + focus_after_render_ = focus; + auto link = engine_link_; + engine_start(save ? "Formation wird gespeichert …" : "Formation wird übernommen …", [link, command] { + auto response = link->command(command); + return EngineReply{link, link->snapshot(), response, nullptr}; + }, true); + } catch (const std::exception &e) { message(e.what()); } + }); + return true; + } if (action == "lineup-piece-auto") { send_takers({{"auto", true}}, "lineup-piece-auto"); return true; } // "Anweis.": the four instructions of the chosen starter, each moved by a step if (action == "lineup-order") { diff --git a/src/modern/ui/engine_state.inc b/src/modern/ui/engine_state.inc index 2e68bac..59d6050 100644 --- a/src/modern/ui/engine_state.inc +++ b/src/modern/ui/engine_state.inc @@ -5,6 +5,7 @@ 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 lineup_shape_save_ = false; // the next click on an own formation stores the places of the eleven there std::string lineup_piece_ = "freeKick"; // the set piece whose taker the next click on a player names // whose loan engine_credit_ shows ("bank" or a manager's id), the fellow manager chosen on the page // "Spieler", and a lender whose loan could not be read (not asked again until something changes) diff --git a/src/modern/ui/lineup_page.inc b/src/modern/ui/lineup_page.inc index a8152ce..7ab3050 100644 --- a/src/modern/ui/lineup_page.inc +++ b/src/modern/ui/lineup_page.inc @@ -129,7 +129,42 @@ std::string App::render_lineup_page() { } const bool takers = lineup_side_ == "takers" && projection.at("set_pieces").is_object(); const bool ordering = lineup_side_ == "orders" && projection.at("orders").is_object() && !projection.at("orders").empty(); - if (ordering) { + const bool shapes = lineup_side_ == "shapes" && !projection.at("formations").empty(); + if (shapes) { + // the eight formations as small pitches: four given, four of the manager's own + const int in_use = projection.at("formation").get(); + const std::string ink = theme_ == "silver" ? "#8c491a" : theme_ == "matchday" ? "#2f602c" : "#ebb87f"; + const std::string line = theme_ == "silver" ? "#b9ab8f" : "#6f7a6c"; + out += "
Formationen" + + pg_button("lineup-formation-save", "Plätze speichern", lineup_shape_save_ ? "primary" : "", "id=\"lineup-formation-save\"" + attr("aria-pressed", lineup_shape_save_ ? "true" : "false")) + "
"; + for (int group = 0; group < 2; ++group) { + out += pg_kicker(group ? "Eigene" : "Vorgaben") + "
"; + for (const auto &entry : projection.at("formations")) { + const int number = entry.at("formation").get(); + if ((number > 4) != (group == 1)) continue; + const bool available = entry.at("available").get(); + const bool usable = lineup_shape_save_ ? number > 4 : available; + std::string svg = "" + ""; + std::string key; + if (available) + for (const auto &point : entry.at("points")) { + // the own goal is at the bottom, as on the large pitch + const double x = 10 + std::clamp(point[1].get(), 0, 8) / 8.0 * 70, y = 110 - std::clamp(point[0].get(), 0, 19) / 19.0 * 100; + svg += ""; + key += std::to_string(point[0].get()) + "." + std::to_string(point[1].get()) + "-"; + } + svg += ""; + const std::string label = (number > 4 ? "Eigene " + std::to_string(number - 4) : "Vorgabe " + std::to_string(number)); + out += btn("lineup-formation", "" + picture(renderer_.diagram("lineup-shape-" + std::to_string(number) + "-" + theme_ + "-" + key, svg, 240), 60, 80) + "" + std::to_string(number > 4 ? number - 4 : number) + "", + std::string("pg-card lp-shape-card") + (in_use == number ? " sel" : ""), + attr("id", "lineup-formation-" + std::to_string(number)) + attr("data-id", std::to_string(number)) + attr("aria-label", label) + attr("aria-pressed", in_use == number ? "true" : "false") + + (usable ? "" : std::string(" disabled=\"disabled\" title=\"") + (lineup_shape_save_ ? "Vorgaben lassen sich nicht überschreiben" : "Noch nicht gespeichert") + "\"")); + } + out += "
"; + } + out += "
"; + } else if (ordering) { // the four instructions of the chosen starter: how far he goes forward and back, how wide he plays, how much he covers out += "
Anweisungen"; std::string who; @@ -197,12 +232,16 @@ std::string App::render_lineup_page() { if (!lineup_selected_.empty()) for (const auto &row : rows) if (row.at("id") == lineup_selected_) status = row.at("name").get() + " markiert · zweiten Spieler wählen."; if (lineup_side_ == "takers" && projection.at("set_pieces").is_object() && !engine_busy_) status = "Schützen: Karte wählen, dann Spieler anklicken."; + if (shapes && !engine_busy_ && !lineup_shape_save_ && engine_notice_.empty()) { + const int used = projection.at("formation").get(); + status = used ? std::string(used > 4 ? "Eigene " : "Vorgabe ") + std::to_string(used > 4 ? used - 4 : used) + " in Gebrauch." : "Freie Aufstellung."; + } else if (shapes && !engine_busy_) status = lineup_shape_save_ ? "Eigene Formation wählen, in der die Plätze gespeichert werden." : status; if (ordering && !engine_busy_) status = lineup_selected_.empty() ? "Anweisungen: einen Feldspieler anklicken." : "Anweisungen in Schritten von 1 oder 5 ändern."; if (status.empty()) status = "Kein Spieler markiert."; out += "
"; return out + engine_player_profile(projection); }