diff --git a/assets/modern/pages.rcss b/assets/modern/pages.rcss index d3e0a03..a57f621 100644 --- a/assets/modern/pages.rcss +++ b/assets/modern/pages.rcss @@ -1054,3 +1054,9 @@ body.midnight .cp-map-name,body.matchday .cp-map-name {color:#f0ece2;font-effect .po-text {display:block;flex:1;min-width:0;} .po-text strong {display:block;font-size:32dp;line-height:40dp;} .po-text span {display:block;font-size:27dp;line-height:36dp;} +/* line-up: the four instructions of a starter */ +.lp-order {flex:none;gap:14dp;height:70dp;} +.lp-order-icon {display:block;flex:none;width:50dp;height:50dp;} +.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;} diff --git a/docs/new_engine/ui-anbindung.md b/docs/new_engine/ui-anbindung.md index bb18fec..943e89b 100644 --- a/docs/new_engine/ui-anbindung.md +++ b/docs/new_engine/ui-anbindung.md @@ -106,6 +106,7 @@ Die UI ruft diese über `DataSource::read_almanac` und `read_statistics` direkt | `news.update` | `messageId`, `action` `read`/`unread`/`archive`/`trash`/`restore` | eine Nachricht des eigenen Postfachs: gelesen und Papierkorb sind Markierungen der Oberfläche (im Spielstand, `news_marks` je Manager; die Nachricht bleibt im Postfach des Originals, `restore` holt sie zurück), `archive` ist das „Behalten“ des Originals (eine behaltene Nachricht wird bei vollem Postfach nicht verdrängt), `restore` gibt sie wieder frei. Endgültiges Löschen bietet die Schnittstelle nicht an. Unverändert: `no_change`; Fehler `unknown_message` | | `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 | +| `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` | | `training.commit` | optional `types` (4), `areas` (9), `players [{playerId, intensity}]` | richtet das Training bei Bedarf ein, setzt erst die Senkungen, dann die Erhöhungen (jeder Zwischenstand bleibt in den Grenzen); Fehler `training_unavailable`, `unknown_player` und die Gründe der Engine | diff --git a/src/modern/app/modern_session.cpp b/src/modern/app/modern_session.cpp index 66cb665..0628cd3 100644 --- a/src/modern/app/modern_session.cpp +++ b/src/modern/app/modern_session.cpp @@ -9240,8 +9240,11 @@ cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) co const size_t at = size_t(manager) * 0x840 + row * 0x58; if (row < 11 && at + 0x43 <= g_.tactics.size()) { const int partner = partner_of(row); + // "orders": the four instructions of a starter (board bytes +2..+5, each 2-40), which + // the original's ORDER view sets with its four arrows positions.push_back(O{{"playerId", id}, {"depth", int(int8_t(g_.tactics[at + 0x41]))}, {"lane", int(int8_t(g_.tactics[at + 0x42]))}, + {"orders", A{int(g_.tactics[at + 2]), int(g_.tactics[at + 3]), int(g_.tactics[at + 4]), int(g_.tactics[at + 5])}}, {"partnerId", partner >= 0 ? cli::Json(row_ids[size_t(partner)]) : cli::Json(nullptr)}}); } } @@ -11032,6 +11035,28 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision if (!ok) { restore(); return refuse(error == "unknown_player" ? "unknown_player" : "lineup_refused", error); } revision = previous + 1; answer = modern::ui_command_result(request_id, previous, revision, {"lineup", "squad"}, "Aufstellung übernommen."); + } else if (kind == "lineup.setOrder") { + // payload {playerId, aspect 0-3, value 2-40}: one instruction of a starter (set_player_order_source) + const int team = g_.manager_teams[size_t(manager)]; + const SquadRange range = squad_range(team); + const std::string id = ui_text(*payload, "playerId"); + const cli::Json* aspect = ui_field(*payload, "aspect"); + const cli::Json* value = ui_field(*payload, "value"); + if (id.empty() || !aspect || !aspect->integer() || *aspect->integer() < 0 || *aspect->integer() > 3 || !value || !value->integer() || + *value->integer() < kOrderMin || *value->integer() > kOrderMax) + return refuse("invalid_payload", "playerId, aspect 0-3 und value 2-40 nötig."); + size_t at = range.count; + for (size_t row = 0; row < range.count; ++row) { + const int p = g_.squad_slots[range.first + row] & 0x0fff; + if (p != 0x0fff && modern::ui_player_id(g_, p) == id) at = row; + } + if (at == range.count) return refuse("unknown_player", "Dieser Spieler gehört nicht zum Kader."); + if (!set_player_order_source(g_, manager, team, int(at), g_.squad_slots[range.first + at] & 0x0fff, int(*aspect->integer()), int(*value->integer()))) { + restore(); + return refuse("lineup_refused", "Anweisungen bekommt nur, wer aufgestellt ist."); + } + revision = previous + 1; + answer = modern::ui_command_result(request_id, previous, revision, {"lineup"}, "Anweisung ü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 585e3bf..3487474 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", "tactics.commit", "friendly.book", "manager.resign.commit", + "session.advance", "lineup.commit", "lineup.setPiece", "lineup.setOrder", "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 490fc5b..5539eaf 100644 --- a/src/modern/ui/engine_bridge.hpp +++ b/src/modern/ui/engine_bridge.hpp @@ -21,6 +21,7 @@ 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_order_command(const Json &bundle, const std::string &player, int aspect, int value, 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 d8236d4..ce6dac0 100644 --- a/src/modern/ui/engine_dto.cpp +++ b/src/modern/ui/engine_dto.cpp @@ -131,7 +131,14 @@ Json engine_lineup_projection(const Json &bundle) { const auto depth_max = lineup.at("depthMax").get(), lane_max = lineup.at("laneMax").get(); require(depth_max > 0 && lane_max > 0, "Ungültige Spielfeldkoordinaten."); const auto surface = lineup_surface_context(lineup, positions); - Json rows = Json::array(), points = Json::array(); std::set ids; + Json rows = Json::array(), points = Json::array(), orders = Json::object(); std::set ids; + // the four instructions of every starter, where the backend states them + for (const auto &[id, point] : positions) + if (point.contains("orders") && point.at("orders").is_array() && point.at("orders").size() == 4) { + Json four = Json::array(); + for (const auto &value : point.at("orders")) { require(value.is_number_integer() && value.get() >= 0 && value.get() <= 255, "Ungültige Anweisung."); four.push_back(value.get()); } + orders[id] = four; + } for (const auto &value : lineup.at("order")) { const auto id = value.get(); require(members.contains(id) && roles.contains(id) && ids.insert(id).second, "Aufstellung enthält fremde oder doppelte Spieler."); @@ -173,11 +180,16 @@ Json engine_lineup_projection(const Json &bundle) { set_pieces[key] = taker; } } - return {{"ok", true}, {"rows", rows}, {"field_count", points.size()}, {"set_pieces", set_pieces}, + return {{"ok", true}, {"rows", rows}, {"field_count", points.size()}, {"set_pieces", set_pieces}, {"orders", orders}, {"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}}}}; } namespace { Json sports_command(const Json &bundle, const char *kind, const Json &payload, const std::string &id); } +Json engine_order_command(const Json &bundle, const std::string &player, int aspect, int value, const std::string &request_id) { + const auto projection = engine_lineup_projection(bundle); + 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_set_piece_command(const Json &bundle, const Json &payload, const std::string &request_id) { const auto projection = engine_lineup_projection(bundle); require(projection.at("set_pieces").is_object(), "Schützen sind in diesem Kontext nicht verfügbar."); diff --git a/src/modern/ui/engine_lineup.inc b/src/modern/ui/engine_lineup.inc index 0813383..3c7d1e9 100644 --- a/src/modern/ui/engine_lineup.inc +++ b/src/modern/ui/engine_lineup.inc @@ -67,8 +67,8 @@ 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" && lineup_side_ != "takers" ? "takers" : "formations"; - lineup_selected_.clear(); focus_after_render_ = "lineup-side-takers"; refresh(); return true; + lineup_side_ = (id == "takers" || id == "orders") && lineup_side_ != id ? id : "formations"; + lineup_selected_.clear(); focus_after_render_ = "lineup-side-" + id; refresh(); return true; } if (action == "lineup-piece") { if (id == "freeKick" || id == "penalty" || id == "corner") lineup_piece_ = id; @@ -87,8 +87,31 @@ bool App::engine_lineup_action(const std::string &action, const std::string &id, } catch (const std::exception &e) { message(e.what()); } }; 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") { + if (!engine_fresh_ || engine_busy_ || lineup_selected_.empty() || !target) return true; + try { + const auto orders = engine_lineup_projection(engine_data_).at("orders"); + const int aspect = target->GetAttribute("data-id", -1), step = target->GetAttribute("data-step", 0); + if (!orders.contains(lineup_selected_) || aspect < 0 || aspect > 3 || !step) return true; + const int value = std::clamp(orders.at(lineup_selected_)[size_t(aspect)].get() + step, 2, 40); + const auto command = engine_order_command(engine_data_, lineup_selected_, aspect, value, editor::new_id("request:ui-")); + focus_after_render_ = target->GetId(); + auto link = engine_link_; + engine_start("Anweisung 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-player" && action != "player-detail") return action.starts_with("lineup-"); const auto projection = engine_lineup_projection(engine_data_); + if (action == "lineup-player" && lineup_side_ == "orders") { + // a click chooses whose instructions are shown; nobody is swapped here + lineup_selected_ = lineup_selected_ == id ? "" : id; + focus_after_render_ = target->GetId(); refresh(); return true; + } if (action == "lineup-player" && lineup_side_ == "takers" && projection.at("set_pieces").is_object()) { send_takers({{"piece", lineup_piece_}, {"playerId", id}}, target->GetId()); return true; diff --git a/src/modern/ui/lineup_page.inc b/src/modern/ui/lineup_page.inc index b9b5758..a8152ce 100644 --- a/src/modern/ui/lineup_page.inc +++ b/src/modern/ui/lineup_page.inc @@ -128,7 +128,31 @@ std::string App::render_lineup_page() { out += ""; } const bool takers = lineup_side_ == "takers" && projection.at("set_pieces").is_object(); - if (takers) { + const bool ordering = lineup_side_ == "orders" && projection.at("orders").is_object() && !projection.at("orders").empty(); + 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; + for (const auto &row : rows) if (row.at("id") == lineup_selected_) who = row.at("name").get(); + const bool starter = !lineup_selected_.empty() && projection.at("orders").contains(lineup_selected_); + out += esc(starter ? who : lineup_selected_.empty() ? std::string("Einen Feldspieler anklicken.") : who + " ist nicht aufgestellt.") + "
"; + if (starter) { + static constexpr std::array paths{"M8 34L34 8M14 8H34V28", "M8 34L34 8M8 14V34H28", "M4 22H40M13 13L4 22L13 31M31 13L40 22L31 31", "M22 4V40M13 13L22 4L31 13M13 31L22 40L31 31"}; + static constexpr std::array spoken{"nach vorn", "nach hinten", "in die Breite", "in die Tiefe"}; + const std::string ink = theme_ == "silver" ? "#8c491a" : theme_ == "matchday" ? "#2f602c" : "#ebb87f"; + for (int i = 0; i < 4; ++i) { + const int value = projection.at("orders").at(lineup_selected_)[size_t(i)].get(); + const auto step = [&](int by, const char *label) { + return pg_button("lineup-order", label, "round lp-step", attr("id", "lineup-order-" + std::to_string(i) + (by < 0 ? "-less" : "-more") + (std::abs(by) > 1 ? "-far" : "")) + attr("data-id", std::to_string(i)) + attr("data-step", std::to_string(by)) + + attr("aria-label", std::string("Anweisung ") + spoken[size_t(i)] + (by < 0 ? " verringern" : " erhöhen")) + ((by < 0 && value <= 2) || (by > 0 && value >= 40) ? " disabled=\"disabled\"" : "")); + }; + out += "
" + + picture(renderer_.diagram("lineup-order-" + std::to_string(i) + "-" + theme_, "", 96), 50, 50) + + "" + step(-5, "«") + step(-1, "−") + pg_bar((value - 2) * 100.0 / 38, i < 2 ? "accent" : "sage") + "" + std::to_string(value) + "" + step(1, "+") + step(5, "»") + "
"; + } + } + out += "
"; + } else if (takers) { // who takes the set pieces: one of the three is chosen, the next click on a player names him out += "
Standardschützen" + pg_button("lineup-piece-auto", "Alle dem Co-Trainer", "", "id=\"lineup-piece-auto\"") + "
"; @@ -173,11 +197,12 @@ 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 (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); }