// SPDX-License-Identifier: GPL-3.0-only bool App::national_action(const std::string &action, Rml::Element *target) { if (!action.starts_with("national-") || !source_ || !world_) return false; const auto s = snap(); if (s.state.at("career").value("role", "club") != "national" || !std::set{"achievements", "scorers", "friendlies"}.contains( menu_) || !popup_.empty()) return false; const auto id = target ? target->GetAttribute("data-id", "") : ""; const auto commit = [&](Json value) { value["manager_portrait"] = national_portrait_; if (national_source_ != source_.get()) { national_dialog_.clear(); message("Die Nationalansicht hat sich geändert. Bitte erneut öffnen."); return false; } const auto result = source_->apply({national_revision_, "national", value}); if (!result.ok) { national_dialog_.clear(); message("Die Nationalplanung hat sich geändert. Bitte erneut öffnen."); return false; } refresh(); return true; }; if (action == "national-close") { national_dialog_.clear(); national_pending_.clear(); focus_after_render_ = national_return_focus_; refresh(); return true; } if (!national_dialog_.empty()) { if (national_dialog_ == "venue" && (action == "national-home" || action == "national-away")) { const auto opponent = national_pending_; national_dialog_.clear(); if (commit({{"kind", "opponent"}, {"opponent", opponent}, {"home", action == "national-home"}})) { const auto dates = national_ui_dates(snap().state); focus_after_render_ = dates.empty() ? "national-back" : "national-day-" + dates[0].get(); } return true; } if (national_dialog_ == "book" && action == "national-confirm") { national_dialog_.clear(); if (commit({{"kind", "book"}})) focus_after_render_ = "national-list"; return true; } return true; } if (target) national_return_focus_ = target->GetId(); if (action == "national-opponent") { national_pending_ = id; national_dialog_ = "venue"; focus_after_render_ = "national-home"; refresh(); return true; } if (action == "national-month") { try { commit({{"kind", "month"}, {"value", std::stoi(id)}}); } catch (const std::exception &) { } return true; } if (action == "national-day") { if (commit({{"kind", "day"}, {"value", id}})) focus_after_render_ = "national-day-" + id; return true; } if (action == "national-back") { commit({{"kind", "back"}}); return true; } if (action == "national-book") { national_dialog_ = "book"; focus_after_render_ = "national-close"; refresh(); return true; } if (action == "national-list") { national_dialog_ = "list"; focus_after_render_ = "national-close"; refresh(); return true; } if (action == "national-stat") { try { if (commit({{"kind", "scorer_kind"}, {"value", std::stoi(id)}})) focus_after_render_ = "national-stat-" + id; } catch (const std::exception &) { } return true; } if (action == "national-player") { national_pending_ = id; national_dialog_ = "player"; focus_after_render_ = "national-close"; refresh(); return true; } return true; } bool App::national_event(Rml::Event &event) { if (!source_ || !std::set{"achievements", "scorers", "friendlies"}.contains( menu_) || snap().state.at("career").value("role", "club") != "national" || national_dialog_.empty() || !popup_.empty()) return false; const auto type = event.GetType(); const bool key = type == "keydown"; const auto code = key ? Rml::Input::KeyIdentifier( event.GetParameter("key_identifier", 0)) : Rml::Input::KI_UNKNOWN; if (code == Rml::Input::KI_ESCAPE || (type == "mouseup" && event.GetParameter("button", 0) == 1)) { national_action("national-close", nullptr); event.StopImmediatePropagation(); return true; } if (code == Rml::Input::KI_TAB) { Rml::ElementList rows; if (auto *dialog = element("national-dialog-layer")) dialog->QuerySelectorAll(rows, "button:not([disabled])"); if (!rows.empty()) { const auto old = std::find(rows.begin(), rows.end(), context_->GetFocusElement()); const int at = old == rows.end() ? -1 : int(old - rows.begin()), step = event.GetParameter("shift_key", 0) ? -1 : 1; rows[size_t((at + step + int(rows.size())) % int(rows.size()))]->Focus( true); } event.StopImmediatePropagation(); return true; } bool inside = false; for (auto *n = event.GetTargetElement(); n && n != doc_; n = n->GetParentNode()) if (n->GetId() == "national-dialog-layer") inside = true; if (!inside && (type == "mousedown" || type == "mouseup" || type == "click" || type == "dblclick")) { event.StopImmediatePropagation(); return true; } return false; }