From 1af53ec26a45f74887b6634318ca8121c6ac2bf7 Mon Sep 17 00:00:00 2001 From: Weyoune Date: Sun, 15 Nov 2026 18:03:32 +0100 Subject: [PATCH] Tactics as a pencil sketch on the page, after the design The pitch, the own eleven, the runs of the forwards, the passes and the goal kick are drawn in pencil; their shape follows the settings. Wide players and arrow heads are dragged, the two boxes and the exclamation marks are clicked, the list at the right steps every setting. The question before a change is the same cream note as the other dialogs. The chalkboard picture stays in the library for its tests. Co-Authored-By: Claude Fable 5.2 --- assets/modern/pages.rcss | 36 ++++++ src/modern/ui/controls.inc | 11 ++ src/modern/ui/engine_sports.inc | 10 +- src/modern/ui/pages.inc | 2 +- src/modern/ui/sports_screens.inc | 42 ------- src/modern/ui/tactics_page.inc | 191 +++++++++++++++++++++++++++++++ src/modern/ui/view.cpp | 6 +- 7 files changed, 253 insertions(+), 45 deletions(-) create mode 100644 src/modern/ui/tactics_page.inc diff --git a/assets/modern/pages.rcss b/assets/modern/pages.rcss index 564e2c8..ff7e8cc 100644 --- a/assets/modern/pages.rcss +++ b/assets/modern/pages.rcss @@ -240,3 +240,39 @@ body .pg-btn.pg-go:hover {decorator:none;background-color:var(--p-a6);border-col .pg-root .pg-btn,.pg-ov .pg-btn {font-family:Display;font-size:31dp;} .pg-root .pg-tabs button,.pg-ov .pg-tabs button {font-family:Display;font-size:34dp;} .pg-root .pg-btn.round {font-size:44dp;} + +/* --- tactics: a pencil sketch on the page --- */ +.tk-sketch {display:block;position:relative;flex:none;} +.tk-text {display:block;position:absolute;font-family:Chalk;white-space:nowrap;pointer-events:none;} +.tk-number {text-align:center;font-weight:bold;} +.tk-hot,.tk-hot:hover {position:absolute;padding:0;border:0dp;border-radius:14dp;background-color:transparent;decorator:none;} +.tk-hot:hover {background-color:var(--p-row);} +.tk-mark,.tk-mark:hover,.tk-mark:disabled {position:absolute;display:block;padding:0;border:0dp;background-color:transparent;decorator:none;font-family:Chalk;font-weight:bold;font-size:107dp;line-height:116dp;text-align:center;} +.pg-root .tk-mark {font-family:Chalk;font-size:107dp;} +.tk-mark span {display:block;} +.tk-mark:hover {background-color:var(--p-row);border-radius:14dp;} +.tk-drag {display:block;position:absolute;border-radius:60dp;cursor:move;} +.tk-drag:hover {background-color:var(--p-row);} +.tk-title {display:block;flex:none;font-family:Chalk;font-weight:bold;font-size:68dp;line-height:72dp;} +.tk-row,.tk-row:hover {display:flex;flex:1;align-items:center;gap:18dp;width:100%;padding:4dp;border:0dp;border-bottom:3dp var(--p-n4);border-radius:0dp;background-color:transparent;decorator:none;text-align:left;} +button.tk-row:hover {background-color:var(--p-row);} +.tk-row.last {border-bottom-width:0dp;} +.tk-row .pg-k {flex:none;white-space:normal;} +.tk-value {display:block;flex:1;font-family:Chalk;font-weight:bold;font-size:60dp;line-height:62dp;color:var(--p-text);} +.tk-value.off {text-decoration:line-through;opacity:.6;} +.tk-hint {display:block;font-size:30dp;line-height:40dp;} +.tk-hint strong {display:block;font-weight:bold;} +.tk-hint span {display:block;} +.tk-note {display:block;flex:none;min-height:36dp;font-size:28dp;line-height:36dp;} + +/* --- the question and the notice of the whole game: the same note --- */ +body .popup-backdrop {background-color:var(--p-shade);} +body .popup-box {width:1000dp;padding:45dp 50dp;border:2dp var(--p-n4);border-radius:63dp;background-color:var(--p-bg);decorator:none;color:var(--p-text);} +body .popup-box h2 {margin:0 0 27dp 0;font-family:Display;font-weight:normal;font-size:54dp;line-height:62dp;color:var(--p-text);} +body .popup-box p {margin:0 0 36dp 0;font-size:34dp;line-height:46dp;color:var(--p-text);} +body .popup-box footer {gap:18dp;} +body .popup-box footer button {height:68dp;padding:0 32dp;border:2dp var(--p-div);border-radius:36dp;background-color:var(--p-n1);decorator:none;font-family:Display;font-size:31dp;color:var(--p-text);} +body .popup-box footer button:hover {background-color:var(--p-n2);} +body .popup-box footer button.primary {background-color:var(--p-accent);border-color:var(--p-accent);color:var(--p-on-accent);} +body .popup-box footer button.primary:hover {background-color:var(--p-a6);} +body .popup-box input {height:84dp;padding:0 26dp;border:2dp var(--p-div);border-radius:36dp;background-color:var(--p-n1);color:var(--p-text);} diff --git a/src/modern/ui/controls.inc b/src/modern/ui/controls.inc index 406df25..781341f 100644 --- a/src/modern/ui/controls.inc +++ b/src/modern/ui/controls.inc @@ -124,6 +124,7 @@ void App::drag_event(Rml::Event &event) { void App::ProcessEvent(Rml::Event &event) try { const auto type = event.GetType(); if (notebook_home_event(event)) return; + if (tactics_page_event(event)) return; if (engine_mode_) { engine_event(event); return; } // Native widgets can emit intermediate selected values while their options // are being constructed. Opening a squad menu must stay read-only. @@ -746,6 +747,16 @@ void App::dispatch(const std::string &action, Rml::Element *target) { } return; } + if (action == "tactic-effort-set") { + int value = std::clamp(std::stoi(id), 0, 11); + if (snap().state.at("tactics").at("values")[7] == value) value = std::max(0, value - 1); + if (apply("tactics", {{"kind", "effort"}, {"value", value}})) { + last_tactic_ = 7; + focus_after_render_ = "tactic-effort-" + id; + refresh(); + } + return; + } if (action == "tactic-cycle") { const int i = std::stoi(id); if (i < 0 || i > 6) diff --git a/src/modern/ui/engine_sports.inc b/src/modern/ui/engine_sports.inc index 831f458..adbb484 100644 --- a/src/modern/ui/engine_sports.inc +++ b/src/modern/ui/engine_sports.inc @@ -66,6 +66,14 @@ bool App::engine_sports_action(const std::string &action, const std::string &id, auto &v = engine_tactics_draft_["values"][size_t(i)]; v = v.get() == hi ? lo : v.get() + 1; last_tactic_ = i; focus_after_render_ = target->GetId(); refresh(); return true; } + // an exclamation mark sets the effort to its number; the highest one that is set takes itself back + if (action == "tactic-effort-set" && menu_ == "tactics" && engine_fresh_) { + const int lo = engine_tactics_draft_.at("minima")[7], hi = engine_tactics_draft_.at("limits")[7]; + int value = std::clamp(std::stoi(id), lo, hi); + if (engine_tactics_draft_.at("values")[7] == value) value = std::max(lo, value - 1); + engine_tactics_draft_["values"][7] = value; + last_tactic_ = 7; focus_after_render_ = target->GetId(); refresh(); return true; + } if (action == "training-ball" && menu_ == "training" && engine_fresh_) { const auto group = target->GetAttribute("data-group", ""); const int i = std::stoi(id), value = target->GetAttribute("data-value", 0); @@ -78,7 +86,7 @@ bool App::engine_sports_action(const std::string &action, const std::string &id, } focus_after_render_ = target->GetId(); refresh(); return true; } - return action.starts_with("training-") || action.starts_with("sports-"); + return action.starts_with("training-") || action.starts_with("sports-") || action.starts_with("tactic-"); } bool App::engine_sports_event(Rml::Event &event) { if (menu_ != "tactics" || !popup_.empty() || engine_busy_) return false; diff --git a/src/modern/ui/pages.inc b/src/modern/ui/pages.inc index 5b7ebf5..9f74c19 100644 --- a/src/modern/ui/pages.inc +++ b/src/modern/ui/pages.inc @@ -5,7 +5,7 @@ // The menus that are laid out as a page of the notebook. Every other career menu is still a // sheet of the old format, shown scaled inside the book. bool App::page_native() const { - static const std::set native{"achievements", "highscore", "balance", "contracts", "environment", "tables", "league", "other", "strengths", "fairplay", "indoor", "scorers"}; + static const std::set native{"tactics", "achievements", "highscore", "balance", "contracts", "environment", "tables", "league", "other", "strengths", "fairplay", "indoor", "scorers"}; return notebook_page() && native.contains(menu_); } diff --git a/src/modern/ui/sports_screens.inc b/src/modern/ui/sports_screens.inc index 92eb3d0..42f0731 100644 --- a/src/modern/ui/sports_screens.inc +++ b/src/modern/ui/sports_screens.inc @@ -141,45 +141,3 @@ std::string App::render_training() { } return body + "" + (engine_mode_ ? engine_sports_footer() : ""); } -std::string App::render_tactics() { - const auto t = engine_mode_ ? engine_tactics_draft_ : snap().state.at("tactics"); - const std::array names = engine_mode_ ? t.at("labels").get>() : std::array{ - "Defensiv / offensiv", "Pass-/Schussbild unten", - "Pass-/Schussbild Mitte", "Pass-/Schussbild links", - "Flache / hohe Bälle", "Flügelbild links", - "Flügelbild rechts", "Einsatz"}; - const std::array limits = engine_mode_ ? t.at("limits").get>() : std::array{3, 3, 3, 3, 1, 1, 1, 11}; - // the board is drawn at 8dp a unit (tactics_diagram: 320 x 200 units); the pitch of the - // attitude and the six tiles are its click areas, each with its name underneath - const auto tile = [](size_t i) { return std::array{168 + int((i - 1) % 3) * 46, i <= 3 ? 30 : 80}; }; - std::string body = - "
" + - picture(renderer_.diagram("tactics", tactics_diagram(t, theme_, engine_mode_ ? t.at("board").at("points") : snap().state.value("lineup", Json::object()).value("points", Json()), engine_mode_ ? t.at("board").at("depth_max").get() : 18, engine_mode_ ? t.at("board").at("lane_max").get() : 8)), 2560, 1600); - static const std::array chalk_names{"GRUNDAUSRICHTUNG", "FLÜGELSPIEL", "STEILPÄSSE", "ABSCHLAG", "FLACH / HOCH", "ABSEITSFALLE", "PRESSING"}; - for (size_t i = 0; i < 7; ++i) { - const std::array a = i ? std::array{tile(i)[0], tile(i)[1], 40, 46} : std::array{20, 30, 132, 96}; - const bool off = i >= 5 && t["values"][i].get() == 0; - body += "
" + chalk_names[i] + "
"; - body += btn("tactic-cycle", "", "tactic-hotspot", - "id=\"tactic-cycle-" + std::to_string(i) + "\" data-id=\"" + - std::to_string(i) + "\" aria-label=\"" + esc(names[i]) + - "\" style=\"position:absolute;" + rect(a[0] * 8, a[1] * 8, a[2] * 8, a[3] * 8) + "\""); - } - const int effort = t["values"][7].get(); - body += - "
EINSATZ" + - std::string(size_t(effort), '!') + - "
() : 0) + "\" max=\"" + std::to_string(limits[7]) + "\" step=\"1\" value=\"" + - std::to_string(effort) + - "\"/>
LOCKERVOLLGAS

" + - (engine_mode_ - ? "" + esc(names[size_t(last_tactic_)] + ": " + tactic_value_text(size_t(last_tactic_), t["values"][size_t(last_tactic_)].get(), limits[size_t(last_tactic_)])) + "" + esc(tactic_effect_text(size_t(last_tactic_))) + "" - : esc(names[size_t(last_tactic_)]) + ": " + - std::to_string(t["values"][size_t(last_tactic_)].get()) + " / " + - std::to_string(limits[size_t(last_tactic_)])) + "

"; - return body + (engine_mode_ ? engine_sports_footer() : ""); -} diff --git a/src/modern/ui/tactics_page.inc b/src/modern/ui/tactics_page.inc new file mode 100644 index 0000000..6e67bb4 --- /dev/null +++ b/src/modern/ui/tactics_page.inc @@ -0,0 +1,191 @@ +// SPDX-License-Identifier: GPL-3.0-only +// Tactics as a pencil sketch on the page: the pitch with the own eleven, the runs of the +// forwards, the passes and the goal kick drawn as arrows whose shape follows the settings. +// Wide players and arrow heads are dragged, the two boxes and the exclamation marks are +// clicked; the list at the right names every setting and steps it on a click. The sketch is +// 900 x 610 units; the lines are one picture, texts and click areas lie over it. +namespace { +constexpr double tactics_unit = 2.32; // dp per unit of the sketch +struct TacticsArrow { std::string svg; double mid_x, mid_y; }; +// A pencil arrow from a to b, bent sideways by `bend` units, with an open head. +TacticsArrow tactics_arrow(double ax, double ay, double bx, double by, const std::string &colour, double bend = 0, double width = 2.6, bool dashed = false) { + const double dx = bx - ax, dy = by - ay, length = std::max(1.0, std::hypot(dx, dy)); + bend = std::clamp(bend, -length * .4, length * .4); // a short arrow cannot arch far + const double cx = (ax + bx) / 2 + dy / length * bend, cy = (ay + by) / 2 - dx / length * bend, angle = std::atan2(by - cy, bx - cx); + const auto head = [&](double turn) { return "M" + scalar(bx) + " " + scalar(by) + "L" + scalar(bx - std::cos(angle + turn) * 14) + " " + scalar(by - std::sin(angle + turn) * 14); }; + return {"", + ax * .25 + cx * .5 + bx * .25, ay * .25 + cy * .5 + by * .25}; +} +double tactics_mix(double a, double b, double t) { return a + (b - a) * std::clamp(t, 0.0, 1.0); } +// A point between three anchors: `level` runs from 0 (the first) over 1 to 2 (the last). +std::array tactics_between(const std::array, 3> &p, double level) { + const size_t from = level <= 1 ? 0 : 1; + const double t = level <= 1 ? level : level - 1; + return {tactics_mix(p[from][0], p[from + 1][0], t), tactics_mix(p[from][1], p[from + 1][1], t)}; +} +} // namespace + +std::string App::render_tactics() { + const auto t = engine_mode_ ? engine_tactics_draft_ : snap().state.at("tactics"); + const std::array limits = engine_mode_ ? t.at("limits").get>() : std::array{3, 3, 3, 3, 1, 1, 1, 11}; + const std::array minima = engine_mode_ ? t.at("minima").get>() : std::array{0, 0, 0, 0, 0, 0, 0, 0}; + std::array values{}; + for (size_t i = 0; i < 8; ++i) values[i] = t["values"][i].get(); + // every setting as a level from 0 to 2, whatever its number of steps + const auto level = [&](size_t i) { return limits[i] > minima[i] ? double(values[i] - minima[i]) / (limits[i] - minima[i]) * 2 : 0.0; }; + const auto text_of = [&](size_t i) { return tactic_value_text(i, values[i], limits[i]); }; + static const std::array names{"Grundausrichtung", "Flügelspiel", "Steilpässe", "Abschlag", "Flach / Hoch", "Abseitsfalle", "Pressing", "Einsatz"}; + const bool light = theme_ != "midnight"; + const std::string ink = light ? "#2f3542" : "#e6e2d8", red = light ? "#a8452f" : "#e58a70", blue = light ? "#2b5f8f" : "#8fc0ea", grey = light ? "#5a6170" : "#aab0bb", faint = light ? "#b9b2a4" : "#5b606b", + paper = light ? "#fffdf6" : "#2a2d34"; + + // --- where everything stands --- + const double shift = (level(0) - 1) * 84, wings = level(1), wide_front = wings <= 1 ? tactics_mix(.72, 1, wings) : tactics_mix(1, 1.18, wings - 1), wide_back = 1 + (wide_front - 1) * .6; + const double xd = 215 + shift * .7, xm = 390 + shift, xa = 570 + shift * 1.15; + // the eleven: keeper, four at the back, three in midfield, three up front; the third value says to which side a player moves when dragged + const std::array, 11> players{{{85, 300, 0}, {xd, 300 - 190 * wide_back, -1}, {xd, 235, 0}, {xd, 365, 0}, {xd, 300 + 190 * wide_back, 1}, {xm, 300 - 130 * wide_back, -1}, {xm, 300, 0}, + {xm, 300 + 130 * wide_back, 1}, {xa, 300 - 170 * wide_front, -1}, {xa + 14, 300, 0}, {xa, 300 + 170 * wide_front, 1}}}; + std::string lines, over; // the drawing, and what lies over it: texts and click areas + const auto at = [&](double x, double y, double w, double h) { + return "left:" + scalar(x * tactics_unit) + "dp;top:" + scalar(y * tactics_unit) + "dp;width:" + scalar(w * tactics_unit) + "dp;height:" + scalar(h * tactics_unit) + "dp;"; + }; + // a line of handwriting whose baseline is at y; `anchor` is start, middle or end + const auto write = [&](double x, double y, const std::string &text, double size, const std::string &colour, const char *anchor = "start", bool bold = false, bool struck = false) { + const double box = 420, left = std::string(anchor) == "middle" ? x - box / 2 : std::string(anchor) == "end" ? x - box : x; + over += "" + esc(text) + ""; + }; + // the pitch + lines += "" + ""; + // the opponents as crosses + for (const auto &[x, y] : std::array, 5>{{{822, 300}, {700, 120}, {712, 240}, {712, 360}, {700, 480}}}) + lines += ""; + write(770, 76, "Gegner", 20, red); + // play on the wings: the runs of the three forwards + const std::array, 3>, 3> runs{{{{{xa + 95, 262}, {xa + 105, 180}, {xa + 120, players[8][1] - 4}}}, {{{xa + 110, 300}, {xa + 110, 300}, {xa + 110, 300}}}, {{{xa + 95, 338}, {xa + 105, 420}, {xa + 120, players[10][1] + 4}}}}}; + for (size_t k = 0; k < 3; ++k) { + const auto target = tactics_between(runs[k], wings); + lines += tactics_arrow(players[8 + k][0] + 22, players[8 + k][1], std::min(835.0, target[0]), target[1], blue, wings > 1.5 && k != 1 ? (k ? 18 : -18) : 0).svg; + } + if (wings > 1.5) + lines += tactics_arrow(std::min(835.0, xa + 124), players[8][1] + 8, std::min(820.0, xa + 150), 250, blue, -14, 2.6, true).svg + tactics_arrow(std::min(835.0, xa + 124), players[10][1] - 8, std::min(820.0, xa + 150), 350, blue, 14, 2.6, true).svg; + write(players[8][0] - 20, players[8][1] - 30, text_of(1), 22, blue, "middle"); + // passes: their length (through balls) and their arc (flat or high) + const double through = level(2), arc = tactics_mix(0, 58, level(4) / 2); + const auto pass_to = tactics_between({{{xm + 78, 232}, {xa - 22, 268}, {std::min(800.0, xa + 128), 246}}}, through); + const auto pass = tactics_arrow(xm + 20, 292, pass_to[0], pass_to[1], ink, arc, 3); + lines += pass.svg; + if (through < .5) lines += tactics_arrow(pass_to[0] + 6, pass_to[1] + 6, pass_to[0] + 58, pass_to[1] + 52, ink, arc).svg + tactics_arrow(pass_to[0] + 62, pass_to[1] + 46, pass_to[0] + 112, pass_to[1] - 2, ink, arc).svg; + else if (through < 1.5) lines += tactics_arrow(xm + 16, 314, xm + 60, 372, ink).svg; + write(pass_to[0] > 690 ? pass_to[0] - 14 : pass_to[0] + 14, pass_to[1] - 20, text_of(2), 21, ink, pass_to[0] > 690 ? "end" : "start"); + write(pass.mid_x, pass.mid_y - 16, values[4] > minima[4] ? "hoch" : "flach", 19, grey, "middle"); + // the goal kick + const double kick = level(3); + const std::array kick_to{tactics_mix(xd - 24, xm + 50, kick - 1), tactics_mix(246, 150, kick - 1)}; + lines += tactics_arrow(108, 296, kick_to[0], kick_to[1], ink, tactics_mix(0, 60, kick - 1), 3).svg; + if (kick > .4 && kick < 1.6) lines += tactics_arrow(108, 296, xm + 30, 160, ink, 55, 2.6, true).svg; + write(kick_to[0] - 6, kick_to[1] - 16, text_of(3), 20, ink, "middle"); + // offside trap and pressing + const bool trap = values[5] > minima[5], pressing = values[6] > minima[6]; + if (trap) + lines += ""; + if (pressing) + for (size_t i = 8; i < 11; ++i) + lines += ""; + // the two boxes above the pitch + const auto box = [&](size_t index, double x, const std::string &label, bool on) { + lines += ""; + if (on) lines += ""; + write(x + 30, 28, label, 25, ink, "start", true, !on); + over += btn("tactic-cycle", "", "tk-hot", "id=\"tactic-box-" + std::to_string(index) + "\" data-id=\"" + std::to_string(index) + "\" aria-label=\"" + esc(label + (on ? " an" : " aus")) + "\" aria-pressed=\"" + (on ? "true" : "false") + + "\" style=\"" + at(x - 8, 2, double(label.size()) * 12 + 44, 34) + "\""); + }; + box(5, 150, "Abseitsfalle", trap); + box(6, 520, "Pressing", pressing); + // attitude and effort under the pitch + write(44, 592, "Ausrichtung:", 20, grey); + write(190, 592, text_of(0), 26, ink, "start", true); + write(560, 592, "Einsatz:", 26, ink, "start", true); + const double mark_step = limits[7] > 6 ? 17 : 24; + for (int n = 1; n <= limits[7]; ++n) + over += btn("tactic-effort-set", "!", std::string("tk-mark") + (n <= values[7] ? " on" : ""), + "id=\"tactic-effort-" + std::to_string(n) + "\" data-id=\"" + std::to_string(n) + "\" aria-label=\"Einsatz " + std::to_string(n) + " von " + std::to_string(limits[7]) + "\" " + (n < minima[7] ? "disabled " : "") + "style=\"" + + at(672 + (n - 1) * mark_step, 556, mark_step, 50) + "color:" + (n <= values[7] ? red : faint) + ";\""); + // the own eleven; the wide ones are dragged out and in + for (size_t i = 0; i < 11; ++i) { + const auto &[x, y, side] = players[i]; + lines += ""; + over += "" + std::to_string(i + 1) + ""; + if (side != 0) over += "
"; + } + // the three knobs: head of the pass, its arc, head of the goal kick + const auto knob = [&](const char *kind, double x, double y, const std::string &colour, const char *label) { + lines += ""; + over += "
"; + }; + knob("through", pass_to[0], pass_to[1], ink, "Pfeilspitze ziehen: Steilpässe"); + knob("arc", pass.mid_x, pass.mid_y, grey, "Bogen ziehen: flach oder hoch"); + knob("kick", kick_to[0], kick_to[1], ink, "Pfeilspitze ziehen: Abschlag"); + // the pencil went over every line twice + const std::string svg = "" + lines + "" + lines + ""; + const double sketch_w = 900 * tactics_unit, sketch_h = 610 * tactics_unit; + + // --- the page --- + std::string out = "
" + picture(renderer_.diagram("tactics-sketch-" + theme_, svg, 2088), sketch_w, sketch_h) + over + "
Meine Taktik
"; + for (size_t i = 0; i < 7; ++i) { + const bool toggle = i >= 5, on = values[i] > minima[i]; + out += btn("tactic-cycle", pg_kicker(names[i], "width:122px;font-size:10px;") + "" + esc(toggle ? (on ? "an" : "aus") : text_of(i)) + "", "tk-row", + "id=\"tactic-cycle-" + std::to_string(i) + "\" data-id=\"" + std::to_string(i) + "\" aria-label=\"" + esc(std::string(names[i]) + ": " + text_of(i)) + "\""); + } + out += "
" + pg_kicker("Einsatz", "width:122px;font-size:10px;") + "" + std::string(size_t(values[7]), '!') + + "
" + pg_kicker("Wirkung") + "
" + + esc(std::string(names[size_t(last_tactic_)]) + ": " + text_of(size_t(last_tactic_))) + "" + esc(tactic_effect_text(size_t(last_tactic_))) + "
"; + if (engine_mode_) + out += "
" + pg_button("sports-reset", "Zurücksetzen", "", "id=\"sports-reset\"") + pg_button("sports-apply", "Anwenden", "primary", "id=\"sports-apply\"") + "
"; + else out += "Jede Änderung gilt sofort."; + return out + "
"; +} + +// Dragging on the sketch: a wide player out or in, the head of the pass along the pitch, its +// arc up or down, the head of the goal kick along the pitch. Each step of a setting is a +// stretch of the drag; the sketch is redrawn whenever the setting changes. +bool App::tactics_page_event(Rml::Event &event) { + if (menu_ != "tactics" || !engine_mode_ || engine_busy_ || !popup_.empty() || !engine_tactics_draft_.is_object()) return false; + const auto type = event.GetType(); + const auto mouse = [&] { return Rml::Vector2f{(event.GetParameter("mouse_x", 0) - float(canvas_left_)) / float(scale_), (event.GetParameter("mouse_y", 0) - float(canvas_top_)) / float(scale_)}; }; + if (type == "mousedown" && event.GetParameter("button", 0) == 0) { + for (auto *node = event.GetTargetElement(); node && node != doc_; node = node->GetParentNode()) { + const auto kind = node->GetAttribute("data-tactic-drag", ""); + if (kind.empty()) continue; + const size_t index = kind == "wings" ? 1 : kind == "through" ? 2 : kind == "arc" ? 4 : 3; + const auto at = mouse(); + tactic_drag_ = {{"kind", kind}, {"index", index}, {"side", node->GetAttribute("data-side", 1)}, {"x", at.x}, {"y", at.y}, {"from", engine_tactics_draft_.at("values")[index]}}; + event.StopImmediatePropagation(); + return true; + } + return false; + } + if (!tactic_drag_.is_object()) return false; + if (type == "mouseup") { tactic_drag_ = Json(); refresh(); return true; } + if (type != "mousemove") return false; + const auto at = mouse(); + const double dx = (at.x - tactic_drag_.at("x").get()) / tactics_unit, dy = (at.y - tactic_drag_.at("y").get()) / tactics_unit; + const size_t index = tactic_drag_.at("index").get(); + const auto kind = tactic_drag_.at("kind").get(); + const int lo = engine_tactics_draft_.at("minima")[index], hi = engine_tactics_draft_.at("limits")[index]; + // how far the mouse travels for the whole range of the setting + const double travel = kind == "wings" ? 56 : kind == "through" ? 140 : kind == "arc" ? 52 : 160; + const double moved = kind == "wings" ? dy * tactic_drag_.at("side").get() : kind == "arc" ? -dy : dx; + const int value = std::clamp(tactic_drag_.at("from").get() + int(std::lround(moved / travel * (hi - lo))), lo, hi); + if (engine_tactics_draft_.at("values")[index] != value) { + engine_tactics_draft_["values"][index] = value; + last_tactic_ = int(index); + refresh(); + } + return true; +} diff --git a/src/modern/ui/view.cpp b/src/modern/ui/view.cpp index 819d066..92e9e3a 100644 --- a/src/modern/ui/view.cpp +++ b/src/modern/ui/view.cpp @@ -892,6 +892,9 @@ class App final : public Rml::EventListener { static std::string pg_dialog(const std::string &title, const std::string &sub, const std::string &body, const std::string &actions, double width, const std::string &attrs = {}); std::string pg_club(const std::string &id, double size = 50, bool reverse = false); void notebook_finish(std::string &markup); + // the tactics sketch (tactics_page.inc): what is being dragged on it + bool tactics_page_event(Rml::Event &event); + Json tactic_drag_; // what the page says in the heading of the sheet instead of its plain name, and after it std::string page_title_, page_hint_; // a career menu is a page of the notebook, not a window of its own @@ -1270,7 +1273,7 @@ class App final : public Rml::EventListener { return; element("popup")->SetInnerRML( "

Dreierpack Manager

" + + "class=\"popup-box\">

" + std::string(confirm_ || text_accept_ ? "Rückfrage" : "Hinweis") + "

" + esc(popup_) + "

" + (popup_has_input_ ? "