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 <noreply@anthropic.com>
This commit is contained in:
1 parent
03b46a32f7
commit
1af53ec26a
7 files changed
+253
-45
No files matched your search
@@ -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);}
|
||||
@@ -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)
|
||||
|
||||
@@ -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<int>() == hi ? lo : v.get<int>() + 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<Rml::String>("data-group", "");
|
||||
const int i = std::stoi(id), value = target->GetAttribute<int>("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;
|
||||
|
||||
@@ -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<std::string> native{"achievements", "highscore", "balance", "contracts", "environment", "tables", "league", "other", "strengths", "fairplay", "indoor", "scorers"};
|
||||
static const std::set<std::string> native{"tactics", "achievements", "highscore", "balance", "contracts", "environment", "tables", "league", "other", "strengths", "fairplay", "indoor", "scorers"};
|
||||
return notebook_page() && native.contains(menu_);
|
||||
}
|
||||
|
||||
|
||||
@@ -141,45 +141,3 @@ std::string App::render_training() {
|
||||
}
|
||||
return body + "</div>" + (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<std::string, 8> names = engine_mode_ ? t.at("labels").get<std::array<std::string, 8>>() : std::array<std::string, 8>{
|
||||
"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<int, 8> limits = engine_mode_ ? t.at("limits").get<std::array<int, 8>>() : std::array<int, 8>{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<int, 2>{168 + int((i - 1) % 3) * 46, i <= 3 ? 30 : 80}; };
|
||||
std::string body =
|
||||
"<div class=\"tactics-board\">" +
|
||||
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<int>() : 18, engine_mode_ ? t.at("board").at("lane_max").get<int>() : 8)), 2560, 1600);
|
||||
static const std::array<const char *, 7> chalk_names{"GRUNDAUSRICHTUNG", "FLÜGELSPIEL", "STEILPÄSSE", "ABSCHLAG", "FLACH / HOCH", "ABSEITSFALLE", "PRESSING"};
|
||||
for (size_t i = 0; i < 7; ++i) {
|
||||
const std::array<int, 4> a = i ? std::array<int, 4>{tile(i)[0], tile(i)[1], 40, 46} : std::array<int, 4>{20, 30, 132, 96};
|
||||
const bool off = i >= 5 && t["values"][i].get<int>() == 0;
|
||||
body += "<div class=\"tactic-chalk-name" + std::string(off ? " off" : "") + "\" style=\"position:absolute;" +
|
||||
rect((a[0] - 6) * 8, (a[1] + a[3] - 11) * 8, (a[2] + 12) * 8, 80) + "\"><span>" + chalk_names[i] + "</span></div>";
|
||||
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<int>();
|
||||
body +=
|
||||
"<div class=\"tactic-effort\"><div "
|
||||
"class=\"tactic-effort-label\"><span>EINSATZ</span><span "
|
||||
"id=\"tactic-effort-value\" class=\"tactic-effort-marks\">" +
|
||||
std::string(size_t(effort), '!') +
|
||||
"</span></div><input type=\"range\" id=\"tactic-effort\" "
|
||||
"data-input=\"tactic-effort\" min=\"" + std::to_string(engine_mode_ ? t.at("minima")[7].get<int>() : 0) + "\" max=\"" + std::to_string(limits[7]) + "\" step=\"1\" value=\"" +
|
||||
std::to_string(effort) +
|
||||
"\"/><div class=\"tactic-effort-ends\"><span>LOCKER</span><span>VOLLGAS</span></div></div><p id=\"tactic-hint\" class=\"tactic-hint\">" +
|
||||
(engine_mode_
|
||||
? "<strong>" + esc(names[size_t(last_tactic_)] + ": " + tactic_value_text(size_t(last_tactic_), t["values"][size_t(last_tactic_)].get<int>(), limits[size_t(last_tactic_)])) + "</strong><span>" + esc(tactic_effect_text(size_t(last_tactic_))) + "</span>"
|
||||
: esc(names[size_t(last_tactic_)]) + ": " +
|
||||
std::to_string(t["values"][size_t(last_tactic_)].get<int>()) + " / " +
|
||||
std::to_string(limits[size_t(last_tactic_)])) + "</p></div>";
|
||||
return body + (engine_mode_ ? engine_sports_footer() : "");
|
||||
}
|
||||
@@ -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 {"<path d=\"M" + scalar(ax) + " " + scalar(ay) + "Q" + scalar(cx) + " " + scalar(cy) + " " + scalar(bx) + " " + scalar(by) + "\" fill=\"none\" stroke=\"" + colour + "\" stroke-width=\"" + scalar(width) +
|
||||
"\" stroke-linecap=\"round\"" + (dashed ? " stroke-dasharray=\"9 8\"" : "") + "/><path d=\"" + head(.45) + head(-.45) + "\" fill=\"none\" stroke=\"" + colour + "\" stroke-width=\"" + scalar(width) + "\" stroke-linecap=\"round\"/>",
|
||||
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<double, 2> tactics_between(const std::array<std::array<double, 2>, 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<int, 8> limits = engine_mode_ ? t.at("limits").get<std::array<int, 8>>() : std::array<int, 8>{3, 3, 3, 3, 1, 1, 1, 11};
|
||||
const std::array<int, 8> minima = engine_mode_ ? t.at("minima").get<std::array<int, 8>>() : std::array<int, 8>{0, 0, 0, 0, 0, 0, 0, 0};
|
||||
std::array<int, 8> values{};
|
||||
for (size_t i = 0; i < 8; ++i) values[i] = t["values"][i].get<int>();
|
||||
// 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<const char *, 8> 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<std::array<double, 3>, 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 += "<span class=\"tk-text\" style=\"" + at(left, y - size * .82, box, size * 1.2) + "font-size:" + scalar(size * tactics_unit) + "dp;line-height:" + scalar(size * 1.2 * tactics_unit) + "dp;color:" + colour + ";text-align:" +
|
||||
(std::string(anchor) == "middle" ? "center" : std::string(anchor) == "end" ? "right" : "left") + ";" + (bold ? "font-weight:bold;" : "") + (struck ? "text-decoration:line-through;opacity:.6;" : "") + "\">" + esc(text) + "</span>";
|
||||
};
|
||||
// the pitch
|
||||
lines += "<g fill=\"none\" stroke=\"" + ink + "\" stroke-width=\"2.2\" stroke-linecap=\"round\"><path d=\"M40 42H860V558H40ZM450 42V558M40 170H170V430H40M860 170H730V430H860M40 240H88V360H40M860 240H812V360H860M28 262V338M872 262V338\"/>"
|
||||
"<ellipse cx=\"450\" cy=\"300\" rx=\"62\" ry=\"60\"/><circle cx=\"450\" cy=\"300\" r=\"2.5\" fill=\"" + ink + "\"/></g>";
|
||||
// the opponents as crosses
|
||||
for (const auto &[x, y] : std::array<std::pair<int, int>, 5>{{{822, 300}, {700, 120}, {712, 240}, {712, 360}, {700, 480}}})
|
||||
lines += "<path d=\"M" + std::to_string(x - 11) + " " + std::to_string(y - 11) + "l22 22M" + std::to_string(x + 11) + " " + std::to_string(y - 11) + "l-22 22\" stroke=\"" + red + "\" stroke-width=\"2.6\" stroke-linecap=\"round\" opacity=\".55\"/>";
|
||||
write(770, 76, "Gegner", 20, red);
|
||||
// play on the wings: the runs of the three forwards
|
||||
const std::array<std::array<std::array<double, 2>, 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<double, 2> 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 += "<path d=\"M" + scalar(xd + 30) + " 48V552\" stroke=\"" + red + "\" stroke-width=\"2.6\" stroke-dasharray=\"11 9\" stroke-linecap=\"round\"/><path d=\"M" + scalar(xd + 30) + " 48l22 9-22 9\" fill=\"" + red +
|
||||
"\" fill-opacity=\".35\" stroke=\"" + red + "\" stroke-width=\"2.2\" stroke-linejoin=\"round\"/>";
|
||||
if (pressing)
|
||||
for (size_t i = 8; i < 11; ++i)
|
||||
lines += "<path d=\"M" + scalar(players[i][0] + 26) + " " + scalar(players[i][1] + 16) + "l12 7-12 7M" + scalar(players[i][0] + 38) + " " + scalar(players[i][1] + 16) + "l12 7-12 7\" fill=\"none\" stroke=\"" + red +
|
||||
"\" stroke-width=\"2.6\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>";
|
||||
// the two boxes above the pitch
|
||||
const auto box = [&](size_t index, double x, const std::string &label, bool on) {
|
||||
lines += "<path d=\"M" + scalar(x) + " 9h20v20h-20z\" fill=\"" + paper + "\" stroke=\"" + ink + "\" stroke-width=\"2.2\"/>";
|
||||
if (on) lines += "<path d=\"M" + scalar(x + 3) + " 18l6 8 15-22\" fill=\"none\" stroke=\"" + red + "\" stroke-width=\"3.2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>";
|
||||
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", "<span>!</span>", 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 += "<circle cx=\"" + scalar(x) + "\" cy=\"" + scalar(y) + "\" r=\"17\" fill=\"" + paper + "\" fill-opacity=\".85\" stroke=\"" + ink + "\" stroke-width=\"2.6\"/>";
|
||||
over += "<span class=\"tk-text tk-number\" style=\"" + at(x - 25, y - 14, 50, 28) + "font-size:" + scalar(23 * tactics_unit) + "dp;line-height:" + scalar(28 * tactics_unit) + "dp;color:" + ink + ";\">" + std::to_string(i + 1) + "</span>";
|
||||
if (side != 0) over += "<div class=\"tk-drag\" data-tactic-drag=\"wings\" data-side=\"" + std::to_string(int(side)) + "\" title=\"Nach außen oder innen ziehen\" style=\"" + at(x - 25, y - 25, 50, 50) + "\"></div>";
|
||||
}
|
||||
// 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 += "<circle cx=\"" + scalar(x) + "\" cy=\"" + scalar(y) + "\" r=\"8\" fill=\"" + paper + "\" stroke=\"" + colour + "\" stroke-width=\"2.4\"/><circle cx=\"" + scalar(x) + "\" cy=\"" + scalar(y) + "\" r=\"2.6\" fill=\"" + colour + "\"/>";
|
||||
over += "<div class=\"tk-drag\" data-tactic-drag=\"" + std::string(kind) + "\" title=\"" + label + "\" style=\"" + at(x - 18, y - 18, 36, 36) + "\"></div>";
|
||||
};
|
||||
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 = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 900 610\"><g>" + lines + "</g><g opacity=\".32\" transform=\"translate(1.4 1) rotate(.22 450 305)\">" + lines + "</g></svg>";
|
||||
const double sketch_w = 900 * tactics_unit, sketch_h = 610 * tactics_unit;
|
||||
|
||||
// --- the page ---
|
||||
std::string out = "<div class=\"pg-page\"><div class=\"pg-body\"><div class=\"tk-sketch\" id=\"tactics-sketch\" role=\"group\" aria-label=\"Taktikskizze\" style=\"width:" + scalar(sketch_w) + "dp;height:" + scalar(sketch_h) + "dp;margin-top:" +
|
||||
scalar((1620 - sketch_h) / 2) + "dp;\">" + picture(renderer_.diagram("tactics-sketch-" + theme_, svg, 2088), sketch_w, sketch_h) + over + "</div><div class=\"pg-col pg-grow\"><strong class=\"tk-title\">Meine Taktik</strong><div class=\"pg-col pg-grow\" style=\"gap:0dp;\">";
|
||||
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;") + "<span class=\"tk-value" + std::string(toggle && !on ? " off" : "") + "\">" + esc(toggle ? (on ? "an" : "aus") : text_of(i)) + "</span>", "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 += "<div class=\"tk-row last\">" + pg_kicker("Einsatz", "width:122px;font-size:10px;") + "<span class=\"tk-value\" id=\"tactic-effort-value\" style=\"color:" + red + ";letter-spacing:" + pg(3) + ";\">" + std::string(size_t(values[7]), '!') +
|
||||
"</span></div></div><div class=\"pg-surf\" style=\"" + pg_css("padding:10px 14px;") + "\">" + pg_kicker("Wirkung") + "<div id=\"tactic-hint\" class=\"tk-hint\"><strong>" +
|
||||
esc(std::string(names[size_t(last_tactic_)]) + ": " + text_of(size_t(last_tactic_))) + "</strong><span>" + esc(tactic_effect_text(size_t(last_tactic_))) + "</span></div></div>";
|
||||
if (engine_mode_)
|
||||
out += "<span id=\"sports-note\" class=\"pg-mut tk-note\"></span><div class=\"pg-row\">" + pg_button("sports-reset", "Zurücksetzen", "", "id=\"sports-reset\"") + pg_button("sports-apply", "Anwenden", "primary", "id=\"sports-apply\"") + "</div>";
|
||||
else out += "<span class=\"pg-mut tk-note\">Jede Änderung gilt sofort.</span>";
|
||||
return out + "</div></div></div>";
|
||||
}
|
||||
|
||||
// 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<float>("mouse_x", 0) - float(canvas_left_)) / float(scale_), (event.GetParameter<float>("mouse_y", 0) - float(canvas_top_)) / float(scale_)}; };
|
||||
if (type == "mousedown" && event.GetParameter<int>("button", 0) == 0) {
|
||||
for (auto *node = event.GetTargetElement(); node && node != doc_; node = node->GetParentNode()) {
|
||||
const auto kind = node->GetAttribute<Rml::String>("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<int>("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<double>()) / tactics_unit, dy = (at.y - tactic_drag_.at("y").get<double>()) / tactics_unit;
|
||||
const size_t index = tactic_drag_.at("index").get<size_t>();
|
||||
const auto kind = tactic_drag_.at("kind").get<std::string>();
|
||||
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<int>() : kind == "arc" ? -dy : dx;
|
||||
const int value = std::clamp(tactic_drag_.at("from").get<int>() + 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;
|
||||
}
|
||||
@@ -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(
|
||||
"<div class=\"fill popup-backdrop\"></div><div "
|
||||
"class=\"popup-box\"><h2>Dreierpack Manager</h2><p>" +
|
||||
"class=\"popup-box\"><h2>" + std::string(confirm_ || text_accept_ ? "Rückfrage" : "Hinweis") + "</h2><p>" +
|
||||
esc(popup_) + "</p>" +
|
||||
(popup_has_input_
|
||||
? "<input id=\"popup-text\" value=\"" + esc(popup_input_) +
|
||||
@@ -1774,6 +1777,7 @@ public:
|
||||
#include "modern/ui/notebook.inc"
|
||||
#include "modern/ui/notebook_home.inc"
|
||||
#include "modern/ui/pages.inc"
|
||||
#include "modern/ui/tactics_page.inc"
|
||||
#include "modern/ui/finance_simulation.inc"
|
||||
#include "modern/ui/statistics_analysis.inc"
|
||||
#include "modern/ui/engine_rankings.inc"
|
||||
|
||||
Reference in new issue
Block a user