- Material: menu windows are sheets of paper (warm surface, edge, two sheets beneath, serif headings) that slide in once when their menu opens; the desk stays glass. Source Serif 4 and Cabin Sketch ship in assets/modern/fonts (SIL OFL, see THIRD_PARTY_NOTICES.md); system fonts remain the fallback. - Tactics board: 320 x 200 units mirrored about its middle - the pitch of the attitude on the left, six equal tiles for the play settings on the right with their names in chalk, the commitment with a scale across the foot. - Live match: a 4:3 sheet like the menus (same window zoom) on the darkened stadium. One score board per match of a human manager - a full-width card for one match, two side by side, a 2 x 2 grid for three or four - with crests, a score plate in the clubs' colours (read from the crests), a clock ring, a pressure bar, and a time line of goals, cards and injuries. Compact ticker rows with a mark per kind, a goal banner on the card, a horizontal speed control, and optional halts at half time and when falling behind. - QA: script command demo-start begins a demo career with 1-4 managers. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
108 lines
6.8 KiB
C++
108 lines
6.8 KiB
C++
// SPDX-License-Identifier: GPL-3.0-only
|
|
void App::engine_sports_reset() {
|
|
try { engine_training_draft_ = engine_training_projection(engine_data_); } catch (const std::exception &) { engine_training_draft_ = Json(); }
|
|
try { engine_tactics_draft_ = engine_tactics_projection(engine_data_); } catch (const std::exception &) { engine_tactics_draft_ = Json(); }
|
|
}
|
|
bool App::engine_sports_dirty() const {
|
|
if (menu_ == "training") return !engine_training_draft_.is_null() &&
|
|
(!engine_training_draft_.at("initialized").get<bool>() || engine_training_draft_ != engine_training_projection(engine_data_));
|
|
if (menu_ == "tactics") return !engine_tactics_draft_.is_null() &&
|
|
engine_tactics_draft_.at("values") != engine_tactics_projection(engine_data_).at("values");
|
|
return false;
|
|
}
|
|
std::string App::engine_sports_footer() {
|
|
const bool training = menu_ == "training";
|
|
return "<p id=\"sports-note\" class=\"small muted\" style=\"position:absolute;" +
|
|
(training ? rect(0, 1580, 1060, 112) : rect(0, 1688, 2616, 60) + "text-align:center;") + "\"></p>"
|
|
"<div class=\"row\" style=\"position:absolute;" +
|
|
(training ? rect(0, 1720, 1060, 94) : rect(856, 1764, 904, 94)) + "\">" +
|
|
btn("sports-reset", "Zurücksetzen", "", "id=\"sports-reset\" style=\"width:440dp;height:94dp;\"") +
|
|
btn("sports-apply", "Anwenden", "primary", "id=\"sports-apply\" style=\"width:440dp;height:94dp;\"") + "</div>";
|
|
}
|
|
void App::engine_sports_update() {
|
|
if (menu_ != "training" && menu_ != "tactics") return;
|
|
bool changed = false, valid = false; std::string note;
|
|
try {
|
|
changed = engine_sports_dirty();
|
|
if (menu_ == "training") (void)engine_training_command(engine_data_, engine_training_draft_, "request:validate-only");
|
|
else (void)engine_tactics_command(engine_data_, engine_tactics_draft_.at("values"), "request:validate-only");
|
|
valid = true;
|
|
note = changed ? "Entwurf · Änderungen werden erst mit Anwenden übernommen." : engine_notice_;
|
|
if (menu_ == "training" && !engine_training_draft_.at("initialized").get<bool>()) note = "Mit Anwenden wird das Training erstmals eingerichtet.";
|
|
} catch (const std::exception &e) { note = e.what(); }
|
|
if (auto *button = element("sports-apply")) {
|
|
if (valid && changed && engine_fresh_ && !engine_busy_) button->RemoveAttribute("disabled");
|
|
else button->SetAttribute("disabled", true);
|
|
}
|
|
if (auto *button = element("sports-reset")) {
|
|
if (changed && !engine_busy_) button->RemoveAttribute("disabled");
|
|
else button->SetAttribute("disabled", true);
|
|
}
|
|
if (auto *text = element("sports-note")) {
|
|
const auto value = esc(engine_busy_ ? engine_operation_ : note);
|
|
if (text->GetInnerRML() != value) text->SetInnerRML(value);
|
|
text->SetProperty("color", valid ? "var(--muted)" : "var(--danger)");
|
|
}
|
|
}
|
|
bool App::engine_sports_action(const std::string &action, const std::string &id, Rml::Element *target) {
|
|
if (menu_ != "training" && menu_ != "tactics") return false;
|
|
if (action == "close") { engine_sports_reset(); menu_.clear(); refresh(); return true; }
|
|
if (action == "sports-reset") { engine_sports_reset(); focus_after_render_ = "sports-reset"; refresh(); return true; }
|
|
if (action == "sports-apply" && engine_fresh_ && engine_sports_dirty()) {
|
|
const auto command = menu_ == "training"
|
|
? engine_training_command(engine_data_, engine_training_draft_, editor::new_id("request:ui-"))
|
|
: engine_tactics_command(engine_data_, engine_tactics_draft_.at("values"), editor::new_id("request:ui-"));
|
|
confirmation(menu_ == "training" ? "Diesen Trainingsplan übernehmen?" : "Diese Taktikeinstellungen übernehmen?", [this, command] {
|
|
auto link = engine_link_;
|
|
engine_start("Änderungen werden übernommen …", [link, command] {
|
|
auto response = link->command(command); return EngineReply{link, link->snapshot(), response, nullptr};
|
|
}, true);
|
|
});
|
|
return true;
|
|
}
|
|
if (action == "tactic-cycle" && menu_ == "tactics" && engine_fresh_) {
|
|
const int i = std::stoi(id); if (i < 0 || i > 6) return true;
|
|
const int lo = engine_tactics_draft_.at("minima")[size_t(i)], hi = engine_tactics_draft_.at("limits")[size_t(i)];
|
|
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;
|
|
}
|
|
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);
|
|
if (value < 1 || value > 3) return true;
|
|
if ((group == "type" && i >= 0 && i < 4) || (group == "area" && i >= 0 && i < 9))
|
|
engine_training_draft_[group == "type" ? "types" : "areas"][size_t(i)] = value;
|
|
else if (group == "player") {
|
|
const auto player = target->GetAttribute<Rml::String>("data-player", "");
|
|
if (engine_training_draft_.at("players").contains(player)) engine_training_draft_["players"][player]["intensity"] = value;
|
|
}
|
|
focus_after_render_ = target->GetId(); refresh(); return true;
|
|
}
|
|
return action.starts_with("training-") || action.starts_with("sports-");
|
|
}
|
|
bool App::engine_sports_event(Rml::Event &event) {
|
|
if (menu_ != "tactics" || !popup_.empty() || engine_busy_) return false;
|
|
Rml::ElementFormControl *range = nullptr;
|
|
for (auto *node = event.GetTargetElement(); node && node != doc_; node = node->GetParentNode())
|
|
if (node->GetId() == "tactic-effort") { range = dynamic_cast<Rml::ElementFormControl *>(node); break; }
|
|
if (!range) return false;
|
|
const auto type = event.GetType();
|
|
int value = std::stoi(range->GetValue()); bool change = type == "input" || type == "change";
|
|
if (type == "mouseup") { focus_after_render_ = "tactic-effort"; dirty_ = true; }
|
|
if (type == "keydown") {
|
|
const auto key = Rml::Input::KeyIdentifier(event.GetParameter<int>("key_identifier", 0));
|
|
const int lo = engine_tactics_draft_.at("minima")[7], hi = engine_tactics_draft_.at("limits")[7];
|
|
if (key == Rml::Input::KI_HOME) value = lo;
|
|
else if (key == Rml::Input::KI_END) value = hi;
|
|
else if (key == Rml::Input::KI_LEFT || key == Rml::Input::KI_DOWN) value = std::max(lo, value - 1);
|
|
else if (key == Rml::Input::KI_RIGHT || key == Rml::Input::KI_UP) value = std::min(hi, value + 1);
|
|
else return false;
|
|
event.StopImmediatePropagation(); range->SetValue(std::to_string(value)); change = true;
|
|
}
|
|
if (!change) return false;
|
|
engine_tactics_draft_["values"][7] = value; last_tactic_ = 7;
|
|
element("tactic-effort-value")->SetInnerRML(std::string(size_t(value), '!'));
|
|
element("tactic-hint")->SetInnerRML("<strong>" + esc(engine_tactics_draft_.at("labels")[7].get<std::string>() + ": " + tactic_value_text(7, value, engine_tactics_draft_.at("limits")[7].get<int>())) + "</strong><span>" + esc(tactic_effect_text(7)) + "</span>");
|
|
engine_sports_update(); dirty_ = true; return true;
|
|
}
|