Port planning menus and indoor tables (by Codex)
This commit is contained in:
1 parent
13461c693a
commit
9a93c4fcc8
32 files changed
+1667
-169
No files matched your search
@@ -14,7 +14,7 @@ endif()
|
||||
set(modern_assets "${CMAKE_BINARY_DIR}/assets/modern")
|
||||
FetchContent_GetProperties(rmlui)
|
||||
file(MAKE_DIRECTORY "${modern_assets}")
|
||||
foreach(asset modern.rml theme.rcss ticket.rcss sports.rcss calendar.rcss reports.rcss report_details.rcss report_pickers.rcss)
|
||||
foreach(asset modern.rml theme.rcss ticket.rcss sports.rcss calendar.rcss reports.rcss report_details.rcss report_pickers.rcss indoor.rcss planning.rcss)
|
||||
configure_file("${CMAKE_SOURCE_DIR}/assets/modern/${asset}" "${modern_assets}/${asset}" COPYONLY)
|
||||
endforeach()
|
||||
file(GLOB modern_icons CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/assets/modern/icons/*.svg")
|
||||
@@ -41,6 +41,12 @@ if(MSVC)
|
||||
target_compile_options(modern_ui_core_tests PRIVATE /utf-8)
|
||||
endif()
|
||||
add_test(NAME modern_ui_core_tests COMMAND modern_ui_core_tests)
|
||||
add_executable(modern_planning_tests ../../../tests/modern_planning_tests.cpp)
|
||||
target_link_libraries(modern_planning_tests PRIVATE bmh_modern_ui_core)
|
||||
if(MSVC)
|
||||
target_compile_options(modern_planning_tests PRIVATE /utf-8)
|
||||
endif()
|
||||
add_test(NAME modern_planning_tests COMMAND modern_planning_tests)
|
||||
add_executable(modern_reports_tests ../../../tests/modern_reports_tests.cpp)
|
||||
target_link_libraries(modern_reports_tests PRIVATE bmh_modern_ui_core)
|
||||
if(MSVC)
|
||||
|
||||
@@ -1,93 +1,86 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
std::string App::render_calendar() {
|
||||
const auto snapshot = snap();
|
||||
const auto &calendar = snapshot.state.at("calendar");
|
||||
namespace {
|
||||
std::string calendar_date_label(const std::string &iso) {
|
||||
return iso.substr(8, 2) + "." + iso.substr(5, 2) + "." + iso.substr(0, 4);
|
||||
}
|
||||
}
|
||||
|
||||
Json App::planning_calendar() const {
|
||||
auto calendar = snap().state.at("calendar");
|
||||
calendar["league"] = calendar_own_league(*world_, manager(snap()).value("club", ""));
|
||||
return calendar;
|
||||
}
|
||||
|
||||
std::string App::calendar_day_info(const Json &calendar) const {
|
||||
const auto days = calendar_days(calendar.at("start").get<std::string>());
|
||||
const auto fixtures = calendar_fixtures(calendar, *world_,
|
||||
manager(snapshot).value("club", ""));
|
||||
const int selected = calendar.at("selected").get<int>();
|
||||
const auto league_id = calendar.at("league").get<std::string>();
|
||||
const auto *league = world_->find("competitions", league_id);
|
||||
const auto nation = league ? league->value("nation", "") : "";
|
||||
const std::array<const char *, 12> months = {
|
||||
"Januar", "Februar", "März", "April", "Mai", "Juni",
|
||||
"Juli", "August", "September", "Oktober", "November", "Dezember"};
|
||||
const std::array<const char *, 7> weekdays = {"MO", "DI", "MI", "DO",
|
||||
"FR", "SA", "SO"};
|
||||
std::string body;
|
||||
const auto date = calendar_date_label(days.at(size_t(selected)).iso);
|
||||
const auto own = manager(snap()).value("club", "");
|
||||
for (const auto &f : calendar_fixtures(calendar, *world_, own))
|
||||
if (f.day == selected) {
|
||||
const auto *home = world_->find("clubs", f.home), *away = world_->find("clubs", f.away);
|
||||
return date + " · " + std::to_string(f.round + 1) + ". Spieltag · " +
|
||||
(home ? world_->name(*home) : "") + " – " + (away ? world_->name(*away) : "");
|
||||
}
|
||||
if (calendar.at("league") == calendar_own_league(*world_, own))
|
||||
for (const auto &f : calendar.at("friendlies"))
|
||||
if (f.at("day") == selected) {
|
||||
const auto *opponent = world_->find("clubs", f.at("opponent"));
|
||||
return date + " · Freundschaftsspiel: " + (opponent ? world_->name(*opponent) : "—");
|
||||
}
|
||||
return date + " · spielfrei";
|
||||
}
|
||||
|
||||
std::string App::calendar_grid(const Json &calendar, double top, double height,
|
||||
double gap_x, double gap_y, bool booking,
|
||||
bool postpone) {
|
||||
const auto days = calendar_days(calendar.at("start").get<std::string>());
|
||||
const auto own = manager(snap()).value("club", "");
|
||||
const auto fixtures = calendar_fixtures(calendar, *world_, own);
|
||||
const bool own_league = calendar.at("league") == calendar_own_league(*world_, own);
|
||||
const int selected = calendar.at("selected").get<int>();
|
||||
const double width = (2612 - gap_x * 3) / 4, card_height = (height - gap_y * 2) / 3;
|
||||
const double grid_top = postpone ? 58 : 66;
|
||||
const double cell_width = (width - 28 - 65) / 6;
|
||||
const double cell_height = (card_height - grid_top - (postpone ? 20 : 24)) / 7;
|
||||
const std::array<const char *, 12> months = {"Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"};
|
||||
const std::array<const char *, 7> weekdays = {"MO", "DI", "MI", "DO", "FR", "SA", "SO"};
|
||||
std::string body = "<div class=\"calendar-grid\">";
|
||||
int first = 0;
|
||||
for (int panel = 0; panel < 12; ++panel) {
|
||||
const int month = days[size_t(first)].month;
|
||||
const int offset = days[size_t(first)].weekday;
|
||||
const int month = days[size_t(first)].month, offset = days[size_t(first)].weekday;
|
||||
body += "<section class=\"calendar-month\" style=\"" +
|
||||
rect((panel % 4) * 660, (panel / 4) * 556, 632, 528) +
|
||||
"\"><h2>" + months[size_t(month - 1)] + "</h2>";
|
||||
constexpr double cell_width = (604.0 - 65) / 6, cell_height = 438.0 / 7;
|
||||
rect((panel % 4) * (width + gap_x), top + (panel / 4) * (card_height + gap_y), width, card_height) +
|
||||
"\"><h2" + std::string(postpone ? " style=\"top:12dp;\"" : "") + ">" + months[size_t(month - 1)] + "</h2>";
|
||||
for (int row = 0; row < 7; ++row) {
|
||||
body += "<span class=\"calendar-weekday " +
|
||||
std::string(row == 6 ? "sunday" : "") + "\" style=\"" +
|
||||
rect(12, 66 + row * cell_height, 65, cell_height) + "\">" +
|
||||
"<span>" + weekdays[size_t(row)] + "</span></span>";
|
||||
body += "<span class=\"calendar-weekday " + std::string(row == 6 ? "sunday" : "") + "\" style=\"" +
|
||||
rect(12, grid_top + row * cell_height, 65, cell_height) + "\"><span>" + weekdays[size_t(row)] + "</span></span>";
|
||||
for (int col = 0; col < 6; ++col) {
|
||||
const int number = col * 7 + row - offset + 1;
|
||||
const int index = first + number - 1;
|
||||
if (number < 1 || index >= int(days.size()) ||
|
||||
days[size_t(index)].month != month)
|
||||
continue;
|
||||
const bool match = std::any_of(fixtures.begin(), fixtures.end(),
|
||||
[&](const auto &f) {
|
||||
return f.day == index;
|
||||
});
|
||||
const bool chosen = selected == index;
|
||||
const auto &iso = days[size_t(index)].iso;
|
||||
const auto date = iso.substr(8, 2) + "." + iso.substr(5, 2) + "." +
|
||||
iso.substr(0, 4);
|
||||
body += btn(
|
||||
"calendar-select",
|
||||
(chosen ? "<span class=\"calendar-outline\" style=\"" +
|
||||
rect(3, 3, cell_width - 6, cell_height - 6) +
|
||||
"\"></span>"
|
||||
: "") +
|
||||
std::string("<span class=\"control-label\">") +
|
||||
std::to_string(number) + "</span>",
|
||||
std::string("calendar-day ") + (match ? "has-match " : "") +
|
||||
(chosen ? "selected-day" : ""),
|
||||
"id=\"calendar-day-" + std::to_string(index) + "\" data-id=\"" +
|
||||
std::to_string(index) + "\" aria-pressed=\"" +
|
||||
(chosen ? "true" : "false") + "\" aria-label=\"" + date +
|
||||
(match ? ", belegt" : ", frei") + "\" style=\"" +
|
||||
rect(77 + col * cell_width, 66 + row * cell_height,
|
||||
cell_width, cell_height) + "\"");
|
||||
const int day_number = col * 7 + row - offset + 1, index = first + day_number - 1;
|
||||
if (day_number < 1 || index >= int(days.size()) || days[size_t(index)].month != month) continue;
|
||||
const auto match = std::find_if(fixtures.begin(), fixtures.end(), [&](const auto &f) { return f.day == index; });
|
||||
const bool friendly = own_league && std::any_of(calendar.at("friendlies").begin(), calendar.at("friendlies").end(), [&](const auto &f) { return f.at("day") == index; });
|
||||
const bool occupied = match != fixtures.end() || friendly, chosen = selected == index;
|
||||
const bool source = postpone && match != fixtures.end() && match->from == calendar.value("source_day", -1);
|
||||
body += btn("calendar-select",
|
||||
(chosen || source ? "<span class=\"calendar-outline " + std::string(source ? "source-outline" : "") + "\" style=\"" + rect(3, 3, cell_width - 6, cell_height - 6) + "\"></span>" : "") +
|
||||
"<span class=\"control-label\">" + std::to_string(day_number) + "</span>",
|
||||
std::string("calendar-day ") + (occupied ? "has-match " : "") + (friendly ? "friendly-date " : "") + (source ? "source-day " : "") + (chosen ? "selected-day" : ""),
|
||||
"id=\"calendar-day-" + std::to_string(index) + "\" data-id=\"" + std::to_string(index) + "\" aria-pressed=\"" + (chosen ? "true" : "false") + "\" aria-label=\"" + calendar_date_label(days[size_t(index)].iso) +
|
||||
(occupied ? ", belegt" : ", frei") + "\" style=\"" + rect(77 + col * cell_width, grid_top + row * cell_height, cell_width, cell_height) + "\" " + (booking && (index < 7 || occupied) ? "disabled" : ""));
|
||||
}
|
||||
}
|
||||
body += "</section>";
|
||||
while (first < int(days.size()) && days[size_t(first)].month == month)
|
||||
++first;
|
||||
while (first < int(days.size()) && days[size_t(first)].month == month) ++first;
|
||||
}
|
||||
const auto &iso = days[size_t(selected)].iso;
|
||||
std::string info = iso.substr(8, 2) + "." + iso.substr(5, 2) + "." +
|
||||
iso.substr(0, 4) + " · spielfrei";
|
||||
for (const auto &f : fixtures)
|
||||
if (f.day == selected) {
|
||||
const auto *home = world_->find("clubs", f.home),
|
||||
*away = world_->find("clubs", f.away);
|
||||
info = iso.substr(8, 2) + "." + iso.substr(5, 2) + "." + iso.substr(0, 4) +
|
||||
" · " + std::to_string(f.round + 1) + ". Spieltag · " +
|
||||
(home ? world_->name(*home) : "") + " – " +
|
||||
(away ? world_->name(*away) : "");
|
||||
}
|
||||
body += "<p id=\"calendar-info\" class=\"calendar-info\">" + esc(info) +
|
||||
"</p><nav class=\"bottom-controls\">";
|
||||
std::vector<std::pair<std::string, std::string>> countries, leagues;
|
||||
std::set<std::string> seen;
|
||||
for (auto *l : world_->leagues()) {
|
||||
const auto id = l->value("nation", "");
|
||||
if (seen.insert(id).second)
|
||||
countries.emplace_back(id, world_->nation_name(id));
|
||||
if (id == nation)
|
||||
leagues.emplace_back(l->value("id", ""), world_->name(*l));
|
||||
}
|
||||
return body + select("calendar-country", countries, nation, "calendar-country") +
|
||||
select("calendar-league", leagues, league_id, "calendar-league") +
|
||||
"</nav>";
|
||||
return body + "</div>";
|
||||
}
|
||||
|
||||
std::string App::render_calendar() {
|
||||
const auto calendar = snap().state.at("calendar");
|
||||
return "<div id=\"report-underlay\" class=\"report-underlay\">" +
|
||||
calendar_grid(calendar, 0, 1640, 28, 28, false, false) +
|
||||
"<p id=\"calendar-info\" class=\"calendar-info\">" + esc(calendar_day_info(calendar)) +
|
||||
"</p><nav class=\"report-footer\">" + report_picker("country", 0, 1294) +
|
||||
report_picker("league", 1318, 1294) + "</nav></div>";
|
||||
}
|
||||
@@ -148,6 +148,24 @@ void App::ProcessEvent(Rml::Event &event) try {
|
||||
n = n->GetParentNode())
|
||||
if (n->GetId() == "native-ticket-layer")
|
||||
return;
|
||||
if (!planning_dialog_.empty() && popup_.empty()) {
|
||||
const bool key_event = type == "keydown";
|
||||
const auto key = key_event ? Rml::Input::KeyIdentifier(event.GetParameter<int>("key_identifier", 0)) : Rml::Input::KI_UNKNOWN;
|
||||
if ((key_event && key == Rml::Input::KI_ESCAPE) ||
|
||||
(type == "mouseup" && event.GetParameter<int>("button", 0) == 1)) {
|
||||
planning_action("planning-close", nullptr);
|
||||
event.StopImmediatePropagation();
|
||||
return;
|
||||
}
|
||||
bool inside = false;
|
||||
for (auto *node = event.GetTargetElement(); node && node != doc_; node = node->GetParentNode())
|
||||
if (node->GetId() == "planning-layer") inside = true;
|
||||
if (!inside && (type == "click" || type == "dblclick" || type == "mousedown" ||
|
||||
type == "mouseup" || (key_event && key != Rml::Input::KI_TAB))) {
|
||||
event.StopImmediatePropagation();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!report_detail_kind_.empty() && popup_.empty()) {
|
||||
const bool keyboard = type == "keydown";
|
||||
const auto key = keyboard
|
||||
@@ -167,8 +185,16 @@ void App::ProcessEvent(Rml::Event &event) try {
|
||||
event.StopImmediatePropagation();
|
||||
return;
|
||||
}
|
||||
} else if (report_detail_kind_.empty() && popup_.empty() && report_picker_event(event))
|
||||
} else if (report_detail_kind_.empty() && planning_dialog_.empty() && popup_.empty() && report_picker_event(event))
|
||||
return;
|
||||
if (menu_ == "friendlies" && planning_dialog_.empty() && popup_.empty() &&
|
||||
snap().state.at("calendar").at("friendly_stage") == 1 &&
|
||||
((type == "keydown" && event.GetParameter<int>("key_identifier", 0) == Rml::Input::KI_ESCAPE) ||
|
||||
(type == "mouseup" && event.GetParameter<int>("button", 0) == 1))) {
|
||||
planning_action("friendly-back", nullptr);
|
||||
event.StopImmediatePropagation();
|
||||
return;
|
||||
}
|
||||
if (type == "mouseup" && event.GetParameter<int>("button", 0) == 1) {
|
||||
if (scene_ == "desktop" && !menu_.empty() && popup_.empty()) {
|
||||
menu_.clear();
|
||||
@@ -313,10 +339,11 @@ void App::ProcessEvent(Rml::Event &event) try {
|
||||
(!menu_.empty() || !popup_.empty() || scene_ != "desktop")) {
|
||||
Rml::ElementList controls;
|
||||
auto *root = !popup_.empty() ? element("popup")
|
||||
: !planning_dialog_.empty() ? element("planning-layer")
|
||||
: !report_detail_kind_.empty() ? element("report-detail-layer")
|
||||
: element("canvas");
|
||||
root->QuerySelectorAll(
|
||||
controls, !popup_.empty() || !report_detail_kind_.empty()
|
||||
controls, !popup_.empty() || !report_detail_kind_.empty() || !planning_dialog_.empty()
|
||||
? "button,input,select"
|
||||
: ".window button,.window input,.window select");
|
||||
controls.erase(std::remove_if(controls.begin(), controls.end(),
|
||||
@@ -334,7 +361,8 @@ void App::ProcessEvent(Rml::Event &event) try {
|
||||
int(controls.size());
|
||||
controls[size_t(next)]->Focus(true);
|
||||
if (controls[size_t(next)]->GetId().starts_with("report-detail-player-") ||
|
||||
controls[size_t(next)]->GetId().starts_with("report-club-"))
|
||||
controls[size_t(next)]->GetId().starts_with("report-club-") ||
|
||||
controls[size_t(next)]->GetId().starts_with("friendly-opponent-"))
|
||||
controls[size_t(next)]->ScrollIntoView(
|
||||
Rml::ScrollIntoViewOptions(Rml::ScrollAlignment::Nearest));
|
||||
event.StopImmediatePropagation();
|
||||
@@ -374,6 +402,7 @@ void App::ProcessEvent(Rml::Event &event) try {
|
||||
void App::dispatch(const std::string &action, Rml::Element *target) {
|
||||
const auto id =
|
||||
target ? target->GetAttribute<Rml::String>("data-id", "") : std::string();
|
||||
if (planning_action(action, target) || indoor_action(action, target)) return;
|
||||
if (report_detail_action(action, target)) {
|
||||
close_report_picker(false);
|
||||
return;
|
||||
@@ -984,7 +1013,7 @@ void App::dispatch(const std::string &action, Rml::Element *target) {
|
||||
}
|
||||
static const std::set<std::string> available = {
|
||||
"tables", "strengths", "camp", "settings",
|
||||
"save", "load", "training", "tactics", "calendar", "league", "other"};
|
||||
"save", "load", "training", "tactics", "calendar", "league", "other", "postpone", "friendlies", "indoor"};
|
||||
if (!available.contains(route)) {
|
||||
message("Diese native Ansicht wird im nächsten Menüpaket übertragen.");
|
||||
return;
|
||||
@@ -992,6 +1021,7 @@ void App::dispatch(const std::string &action, Rml::Element *target) {
|
||||
menu_ = route;
|
||||
report_picker_.clear();
|
||||
report_detail_kind_.clear();
|
||||
planning_dialog_.clear();
|
||||
if (route == "settings") {
|
||||
settings_category_ = "display";
|
||||
draft_preferences_ = nullptr;
|
||||
@@ -1362,6 +1392,7 @@ void App::script() {
|
||||
Json{{"scene", scene_},
|
||||
{"menu", menu_},
|
||||
{"report_picker", report_picker_},
|
||||
{"planning_dialog", planning_dialog_},
|
||||
{"report_detail", {{"kind", report_detail_kind_},
|
||||
{"club", report_detail_club_},
|
||||
{"player", report_detail_player_}}},
|
||||
|
||||
+237
-44
@@ -5,6 +5,7 @@
|
||||
#include <iomanip>
|
||||
#include <numeric>
|
||||
#include <sstream>
|
||||
#include <set>
|
||||
|
||||
namespace bmh::modern_ui {
|
||||
std::vector<CalendarDay> calendar_days(const std::string &start) {
|
||||
@@ -30,65 +31,248 @@ std::vector<CalendarDay> calendar_days(const std::string &start) {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Json demo_calendar(const Catalog &world, const std::string &date) {
|
||||
auto year = std::stoi(date.substr(0, 4));
|
||||
if (date.substr(5, 2) < "07")
|
||||
--year;
|
||||
const auto leagues = world.leagues("nation:de");
|
||||
namespace {
|
||||
bool integer(const Json &v, int low, int high) {
|
||||
if (v.is_number_unsigned())
|
||||
return high >= 0 && v.get<uint64_t>() <= uint64_t(high) &&
|
||||
(low <= 0 || v.get<uint64_t>() >= uint64_t(low));
|
||||
return v.is_number_integer() && v.get<int64_t>() >= low &&
|
||||
v.get<int64_t>() <= high;
|
||||
}
|
||||
bool keys(const Json &v, std::initializer_list<const char *> expected) {
|
||||
if (!v.is_object() || v.size() != expected.size()) return false;
|
||||
return std::all_of(expected.begin(), expected.end(),
|
||||
[&](const auto *key) { return v.contains(key); });
|
||||
}
|
||||
std::string own_club(const Catalog &world, const std::string &managed) {
|
||||
if (!managed.empty()) return world.manageable(managed) ? managed : "";
|
||||
for (const auto *club : world.clubs())
|
||||
if (world.manageable(club->value("id", ""))) return club->value("id", "");
|
||||
return "";
|
||||
}
|
||||
bool league_exists(const Catalog &world, const std::string &id) {
|
||||
const auto leagues = world.leagues();
|
||||
return leagues.empty() ? id.empty() : std::any_of(
|
||||
leagues.begin(), leagues.end(), [&](auto *l) { return l->at("id") == id; });
|
||||
}
|
||||
std::string first_opponent(const Catalog &world, const std::string &league,
|
||||
const std::string &managed) {
|
||||
if (league.empty()) return "";
|
||||
for (auto *club : world.clubs(league))
|
||||
if (club->at("id") != managed) return club->at("id").get<std::string>();
|
||||
return "";
|
||||
}
|
||||
bool opponent_exists(const Catalog &world, const std::string &league,
|
||||
const std::string &opponent, const std::string &managed) {
|
||||
if (!league_exists(world, league)) return false;
|
||||
if (opponent.empty()) return first_opponent(world, league, managed).empty();
|
||||
const auto *club = world.find("clubs", opponent);
|
||||
return club && opponent != managed && club->value("type", "club") == "club" &&
|
||||
!league.empty() && club->value("competition", "") == league;
|
||||
}
|
||||
Json own_calendar(const Json &state, const Catalog &world,
|
||||
const std::string &managed) {
|
||||
auto own = state;
|
||||
own["league"] = calendar_own_league(world, managed);
|
||||
return own;
|
||||
}
|
||||
} // namespace
|
||||
std::string calendar_own_league(const Catalog &world, const std::string &managed) {
|
||||
const auto *club = world.find("clubs", own_club(world, managed));
|
||||
return club ? club->value("competition", "") : "";
|
||||
}
|
||||
Json demo_calendar(const Catalog &world, const std::string &date,
|
||||
const std::string &managed) {
|
||||
if (date.size() != 10 || date[4] != '-' || date[7] != '-' ||
|
||||
!std::all_of(date.begin(), date.end(), [](char c) {
|
||||
return (c >= '0' && c <= '9') || c == '-';
|
||||
})) throw editor::Error("invalid_demo_calendar");
|
||||
int year;
|
||||
try { year = std::stoi(date.substr(0, 4)); }
|
||||
catch (const std::exception &) { throw editor::Error("invalid_demo_calendar"); }
|
||||
if (date.substr(5, 2) < "07") --year;
|
||||
std::ostringstream start;
|
||||
start.imbue(std::locale::classic());
|
||||
start << std::setfill('0') << std::setw(4) << year << "-07-01";
|
||||
if (calendar_days(start.str()).empty())
|
||||
const auto days = calendar_days(start.str());
|
||||
if (days.empty() || std::none_of(days.begin(), days.end(),
|
||||
[&](const auto &day) { return day.iso == date; }))
|
||||
throw editor::Error("invalid_demo_calendar");
|
||||
return {{"start", start.str()},
|
||||
{"selected", 6},
|
||||
{"league", leagues.empty() ? "" : leagues.front()->value("id", "")},
|
||||
{"friendlies", Json::array()},
|
||||
{"moves", Json::array()}};
|
||||
auto leagues = world.leagues("nation:de");
|
||||
if (leagues.empty()) leagues = world.leagues();
|
||||
const auto preview = leagues.empty() ? "" : leagues.front()->value("id", "");
|
||||
const auto own = calendar_own_league(world, managed);
|
||||
const auto friendly = own.empty() ? preview : own;
|
||||
Json result = {{"start", start.str()}, {"selected", 6}, {"league", preview},
|
||||
{"source_day", -1}, {"friendly_league", friendly},
|
||||
{"opponent", first_opponent(world, friendly, own_club(world, managed))},
|
||||
{"home", true}, {"friendly_stage", 0},
|
||||
{"friendlies", Json::array()}, {"moves", Json::array()}};
|
||||
if (!valid_demo_calendar(result, world, managed))
|
||||
throw editor::Error("invalid_demo_calendar");
|
||||
return result;
|
||||
}
|
||||
bool valid_demo_calendar(const Json &v, const Catalog &world) {
|
||||
bool valid_demo_calendar(const Json &v, const Catalog &world,
|
||||
const std::string &managed) {
|
||||
try {
|
||||
if (!keys(v, {"start", "selected", "league", "source_day", "friendly_league",
|
||||
"opponent", "home", "friendly_stage", "friendlies", "moves"}) ||
|
||||
(!managed.empty() && !world.manageable(managed))) return false;
|
||||
const auto days = calendar_days(v.at("start").get<std::string>());
|
||||
if (days.empty() || !v.at("selected").is_number_integer() ||
|
||||
v["selected"] < 0 || v["selected"] >= days.size())
|
||||
if (days.empty() || !integer(v.at("selected"), 0, int(days.size()) - 1) ||
|
||||
!league_exists(world, v.at("league").get<std::string>()) ||
|
||||
!v.at("home").is_boolean() || !integer(v.at("friendly_stage"), 0, 1) ||
|
||||
!opponent_exists(world, v.at("friendly_league").get<std::string>(),
|
||||
v.at("opponent").get<std::string>(), own_club(world, managed)) ||
|
||||
!v.at("friendlies").is_array() || v.at("friendlies").size() > 20 ||
|
||||
(!v.at("friendlies").empty() && own_club(world, managed).empty()) ||
|
||||
!v.at("moves").is_array()) return false;
|
||||
auto base = own_calendar(v, world, managed);
|
||||
base["moves"] = Json::array();
|
||||
const auto fixtures = calendar_fixtures(base, world, own_club(world, managed));
|
||||
std::set<int> sources, destinations, occupied, originals;
|
||||
for (const auto &f : fixtures) originals.insert(f.from);
|
||||
if (!integer(v.at("source_day"), -1, int(days.size()) - 1) ||
|
||||
(v.at("source_day") != -1 && !originals.contains(v.at("source_day").get<int>())))
|
||||
return false;
|
||||
const auto league = v.at("league").get<std::string>();
|
||||
const auto leagues = world.leagues();
|
||||
if (std::none_of(leagues.begin(), leagues.end(), [&](auto *r) {
|
||||
return r->value("id", "") == league;
|
||||
}))
|
||||
return false;
|
||||
// Reserved projections for later native planning menus; no unimplemented
|
||||
// booking or rescheduling action is silently accepted by this preview.
|
||||
return v.at("friendlies").is_array() && v["friendlies"].empty() &&
|
||||
v.at("moves").is_array() && v["moves"].empty();
|
||||
} catch (const Json::exception &) {
|
||||
return false;
|
||||
}
|
||||
for (const auto &m : v.at("moves")) {
|
||||
if (!keys(m, {"from", "to"}) || !integer(m.at("from"), 0, int(days.size()) - 1) ||
|
||||
!integer(m.at("to"), 7, int(days.size()) - 1)) return false;
|
||||
const int from = m.at("from"), to = m.at("to");
|
||||
if (!originals.contains(from) || !sources.insert(from).second ||
|
||||
!destinations.insert(to).second) return false;
|
||||
}
|
||||
for (const auto &f : calendar_fixtures(own_calendar(v, world, managed), world,
|
||||
own_club(world, managed)))
|
||||
if (!occupied.insert(f.day).second) return false;
|
||||
for (const auto &f : v.at("friendlies")) {
|
||||
if (!keys(f, {"day", "opponent", "league", "home"}) ||
|
||||
!integer(f.at("day"), 7, int(days.size()) - 1) ||
|
||||
!f.at("home").is_boolean() || f.at("opponent") == "" ||
|
||||
!opponent_exists(world, f.at("league").get<std::string>(),
|
||||
f.at("opponent").get<std::string>(), own_club(world, managed)) ||
|
||||
!occupied.insert(f.at("day").get<int>()).second) return false;
|
||||
}
|
||||
return true;
|
||||
} catch (const Json::exception &) { return false; }
|
||||
}
|
||||
bool migrate_demo_calendar(Json &state, const Catalog &world,
|
||||
const std::string &managed) {
|
||||
try {
|
||||
if (!state.is_object()) return false;
|
||||
// OpenBMH deviates from the original: the native season follows its saved
|
||||
// start year (including leap days), rather than the HTML's fixed 2027/28.
|
||||
const auto defaults = demo_calendar(world, state.at("start").get<std::string>(), managed);
|
||||
auto next = state;
|
||||
for (const auto *field : {"source_day", "friendly_league", "opponent", "home",
|
||||
"friendly_stage", "friendlies", "moves"})
|
||||
if (!next.contains(field)) next[field] = defaults.at(field);
|
||||
if (!state.contains("opponent"))
|
||||
next["opponent"] = first_opponent(world, next.at("friendly_league").get<std::string>(),
|
||||
own_club(world, managed));
|
||||
if (!valid_demo_calendar(next, world, managed)) return false;
|
||||
state = std::move(next);
|
||||
return true;
|
||||
} catch (const std::exception &) { return false; }
|
||||
}
|
||||
bool calendar_day_occupied(const Json &state, const Catalog &world,
|
||||
const std::string &managed, int day) {
|
||||
for (const auto &f : calendar_fixtures(own_calendar(state, world, managed), world,
|
||||
own_club(world, managed)))
|
||||
if (f.day == day) return true;
|
||||
for (const auto &f : state.at("friendlies"))
|
||||
if (f.at("day") == day) return true;
|
||||
return false;
|
||||
}
|
||||
int calendar_friendly_fee(const Json &state, const Catalog &world) {
|
||||
const auto clubs = world.clubs(state.at("friendly_league").get<std::string>());
|
||||
const auto found = std::find_if(clubs.begin(), clubs.end(),
|
||||
[&](auto *club) { return club->at("id") == state.at("opponent"); });
|
||||
if (found == clubs.end()) return 0;
|
||||
return (state.at("home").get<bool>() ? 25000 : 12000) +
|
||||
int(found - clubs.begin()) * 500;
|
||||
}
|
||||
std::string edit_demo_calendar(Json &state, const Json &action,
|
||||
const Catalog &world) {
|
||||
const auto kind = action.at("kind").get<std::string>();
|
||||
auto next = state;
|
||||
if (kind == "select")
|
||||
next["selected"] = action.at("value");
|
||||
else if (kind == "league")
|
||||
next["league"] = action.at("value");
|
||||
else
|
||||
return "unknown_calendar_action";
|
||||
if (!valid_demo_calendar(next, world))
|
||||
return "invalid_calendar_selection";
|
||||
state = std::move(next);
|
||||
return {};
|
||||
const Catalog &world, const std::string &managed) {
|
||||
if (!valid_demo_calendar(state, world, managed)) return "invalid_calendar_state";
|
||||
try {
|
||||
if (!action.is_object() || !action.contains("kind") || !action.at("kind").is_string())
|
||||
return "invalid_calendar_action";
|
||||
const auto kind = action.at("kind").get<std::string>();
|
||||
const bool value = kind == "select" || kind == "league" ||
|
||||
kind == "friendly-country" || kind == "friendly-league" ||
|
||||
kind == "friendly-opponent" || kind == "friendly-venue" || kind == "friendly-stage";
|
||||
const bool command = kind == "friendly-book" || kind == "postpone-source" ||
|
||||
kind == "postpone-cancel" || kind == "postpone-move" || kind == "postpone-undo";
|
||||
if (!value && !command) return "unknown_calendar_action";
|
||||
if (!(value ? keys(action, {"kind", "value"}) : keys(action, {"kind"})))
|
||||
return "invalid_calendar_action";
|
||||
auto next = state;
|
||||
if (kind == "select") next["selected"] = action.at("value");
|
||||
else if (kind == "league") next["league"] = action.at("value");
|
||||
else if (kind == "friendly-country" || kind == "friendly-league") {
|
||||
const auto id = action.at("value").get<std::string>();
|
||||
auto league = id;
|
||||
if (kind == "friendly-country") {
|
||||
if (!world.find("nations", id)) return "invalid_calendar_selection";
|
||||
const auto leagues = world.leagues(id);
|
||||
if (leagues.empty()) return "invalid_calendar_selection";
|
||||
league = leagues.front()->at("id").get<std::string>();
|
||||
}
|
||||
if (!league_exists(world, league)) return "invalid_calendar_selection";
|
||||
next["friendly_league"] = league;
|
||||
next["opponent"] = first_opponent(world, league, own_club(world, managed));
|
||||
} else if (kind == "friendly-opponent") next["opponent"] = action.at("value");
|
||||
else if (kind == "friendly-venue") next["home"] = action.at("value");
|
||||
else if (kind == "friendly-stage") next["friendly_stage"] = action.at("value");
|
||||
else if (kind == "friendly-book" || kind == "postpone-move") {
|
||||
const int day = state.at("selected");
|
||||
if (day < 7 || calendar_day_occupied(state, world, managed, day))
|
||||
return "invalid_calendar_selection";
|
||||
if (kind == "friendly-book") {
|
||||
if (state.at("friendlies").size() >= 20 || state.at("opponent") == "" ||
|
||||
own_club(world, managed).empty()) return "invalid_calendar_selection";
|
||||
next["friendlies"].push_back({{"day", day}, {"opponent", state.at("opponent")},
|
||||
{"league", state.at("friendly_league")}, {"home", state.at("home")}});
|
||||
} else {
|
||||
const int from = state.at("source_day");
|
||||
if (from < 0) return "invalid_calendar_selection";
|
||||
auto &moves = next["moves"];
|
||||
moves.erase(std::remove_if(moves.begin(), moves.end(),
|
||||
[&](const auto &m) { return m.at("from") == from; }), moves.end());
|
||||
moves.push_back({{"from", from}, {"to", day}});
|
||||
next["source_day"] = -1;
|
||||
}
|
||||
} else if (kind == "postpone-source") {
|
||||
const auto fixtures = calendar_fixtures(own_calendar(state, world, managed), world,
|
||||
own_club(world, managed));
|
||||
const auto found = std::find_if(fixtures.begin(), fixtures.end(),
|
||||
[&](const auto &f) { return state.at("selected") == f.day; });
|
||||
if (found == fixtures.end()) return "invalid_calendar_selection";
|
||||
next["source_day"] = found->from;
|
||||
} else if (kind == "postpone-cancel") next["source_day"] = -1;
|
||||
else if (kind == "postpone-undo") {
|
||||
if (state.at("moves").empty() || calendar_day_occupied(state, world, managed,
|
||||
state.at("moves").back().at("from").get<int>()))
|
||||
return "invalid_calendar_selection";
|
||||
next["moves"].erase(next["moves"].end() - 1);
|
||||
}
|
||||
if (!valid_demo_calendar(next, world, managed)) return "invalid_calendar_selection";
|
||||
state = std::move(next);
|
||||
return {};
|
||||
} catch (const Json::exception &) { return "invalid_calendar_action"; }
|
||||
}
|
||||
std::vector<CalendarFixture> calendar_fixtures(const Json &state,
|
||||
const Catalog &world,
|
||||
const std::string &managed_club) {
|
||||
const auto clubs = world.clubs(state.at("league").get<std::string>());
|
||||
const auto league = state.at("league").get<std::string>();
|
||||
if (league.empty()) return {};
|
||||
const auto clubs = world.clubs(league);
|
||||
if (clubs.size() < 2)
|
||||
return {};
|
||||
const auto managed = own_club(world, managed_club);
|
||||
const auto found = std::find_if(clubs.begin(), clubs.end(), [&](auto *c) {
|
||||
return c->value("id", "") == managed_club;
|
||||
return c->value("id", "") == managed;
|
||||
});
|
||||
const int followed = found == clubs.end() ? 0 : int(found - clubs.begin());
|
||||
const int count = int(clubs.size()) + int(clubs.size() % 2);
|
||||
@@ -105,16 +289,25 @@ std::vector<CalendarFixture> calendar_fixtures(const Json &state,
|
||||
continue;
|
||||
first.push_back({30 + round * 7, round,
|
||||
clubs[size_t(home)]->value("id", ""),
|
||||
clubs[size_t(away)]->value("id", "")});
|
||||
clubs[size_t(away)]->value("id", ""), 30 + round * 7});
|
||||
}
|
||||
std::rotate(ring.begin() + 1, ring.end() - 1, ring.end());
|
||||
}
|
||||
result = first;
|
||||
for (const auto &fixture : first)
|
||||
result.push_back({fixture.day + (count - 1) * 7,
|
||||
fixture.round + count - 1, fixture.away, fixture.home});
|
||||
fixture.round + count - 1, fixture.away, fixture.home,
|
||||
fixture.from + (count - 1) * 7});
|
||||
const auto days = calendar_days(state.at("start").get<std::string>()).size();
|
||||
std::erase_if(result, [&](const auto &f) { return size_t(f.day) >= days; });
|
||||
// Foreign league previews keep their original dates and followed club.
|
||||
if (found != clubs.end() && league == calendar_own_league(world, managed_club))
|
||||
for (auto &fixture : result)
|
||||
for (const auto &move : state.at("moves"))
|
||||
if (move.at("from") == fixture.from) {
|
||||
fixture.day = move.at("to").get<int>();
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
} // namespace bmh::modern_ui
|
||||
@@ -10,12 +10,26 @@ struct CalendarDay {
|
||||
struct CalendarFixture {
|
||||
int day, round;
|
||||
std::string home, away;
|
||||
int from; // Stable original season day, even after repeated moves.
|
||||
};
|
||||
// Presentation fixtures only. No scheduler, RNG, session or match is called.
|
||||
std::vector<CalendarDay> calendar_days(const std::string &start);
|
||||
Json demo_calendar(const Catalog &, const std::string &date);
|
||||
bool valid_demo_calendar(const Json &, const Catalog &);
|
||||
std::string edit_demo_calendar(Json &, const Json &, const Catalog &);
|
||||
Json demo_calendar(const Catalog &, const std::string &date,
|
||||
const std::string &managed_club = "");
|
||||
bool valid_demo_calendar(const Json &, const Catalog &,
|
||||
const std::string &managed_club = "");
|
||||
std::string edit_demo_calendar(Json &, const Json &, const Catalog &,
|
||||
const std::string &managed_club = "");
|
||||
// Fill absent planning fields in older presentation checkpoints, atomically.
|
||||
// Present values are validated, never repaired or silently discarded.
|
||||
bool migrate_demo_calendar(Json &, const Catalog &,
|
||||
const std::string &managed_club = "");
|
||||
std::string calendar_own_league(const Catalog &,
|
||||
const std::string &managed_club = "");
|
||||
// Planning always checks the manager's schedule, independently of the preview.
|
||||
bool calendar_day_occupied(const Json &, const Catalog &,
|
||||
const std::string &managed_club, int day);
|
||||
int calendar_friendly_fee(const Json &, const Catalog &);
|
||||
std::vector<CalendarFixture> calendar_fixtures(const Json &, const Catalog &,
|
||||
const std::string &managed_club);
|
||||
} // namespace bmh::modern_ui
|
||||
@@ -72,11 +72,13 @@ bool sort_key(const std::string &view, const std::string &key) {
|
||||
static const std::set<std::string> table_keys = {
|
||||
"original", "rank", "played", "wins", "draw", "loss", "form",
|
||||
"points", "gf", "diff"};
|
||||
static const std::set<std::string> indoor_keys = {"original", "rank", "points"};
|
||||
static const std::set<std::string> strength_keys = {
|
||||
"original", "club", "keeper", "defence", "midfield", "attack",
|
||||
"strength"};
|
||||
return view == "tables" ? table_keys.contains(key)
|
||||
: view == "strengths" && strength_keys.contains(key);
|
||||
: view == "strengths" ? strength_keys.contains(key)
|
||||
: view == "indoor" && indoor_keys.contains(key);
|
||||
}
|
||||
std::vector<Fixture> fixtures(size_t club_count, int league) {
|
||||
if (club_count < 2 || club_count > size_t(std::numeric_limits<int>::max() / 2 - 1))
|
||||
@@ -211,7 +213,8 @@ Json demo_reports(const Catalog &world) {
|
||||
{"round", std::min(26, league_rounds(world, league) - 1)},
|
||||
{"filter", 0}, {"competition", 0},
|
||||
{"sorts", {{"tables", {{"key", "points"}, {"desc", true}}},
|
||||
{"strengths", {{"key", "original"}, {"desc", false}}}}}};
|
||||
{"strengths", {{"key", "original"}, {"desc", false}}},
|
||||
{"indoor", {{"key", "points"}, {"desc", true}}}}}};
|
||||
}
|
||||
bool valid_demo_reports(const Json &state, const Catalog &world) {
|
||||
try {
|
||||
@@ -224,9 +227,9 @@ bool valid_demo_reports(const Json &state, const Catalog &world) {
|
||||
const int count = std::max(league_rounds(world, state.at("league")),
|
||||
state.at("competition") == 0 ? 1 : other_rounds);
|
||||
if (!integer(state.at("round"), 0, count - 1) ||
|
||||
!keys(state.at("sorts"), {"tables", "strengths"}))
|
||||
!keys(state.at("sorts"), {"tables", "strengths", "indoor"}))
|
||||
return false;
|
||||
for (const auto *view : {"tables", "strengths"}) {
|
||||
for (const auto *view : {"tables", "strengths", "indoor"}) {
|
||||
const auto &sort = state.at("sorts").at(view);
|
||||
if (!keys(sort, {"key", "desc"}) || !sort.at("key").is_string() ||
|
||||
!sort.at("desc").is_boolean() || !sort_key(view, sort.at("key")))
|
||||
@@ -237,6 +240,19 @@ bool valid_demo_reports(const Json &state, const Catalog &world) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
bool migrate_demo_reports(Json &state, const Catalog &world) {
|
||||
if (valid_demo_reports(state, world))
|
||||
return true;
|
||||
if (!state.is_object() || !state.contains("sorts") ||
|
||||
!state.at("sorts").is_object() || state.at("sorts").contains("indoor"))
|
||||
return false;
|
||||
auto next = state;
|
||||
next["sorts"]["indoor"] = {{"key", "points"}, {"desc", true}};
|
||||
if (!valid_demo_reports(next, world))
|
||||
return false;
|
||||
state = std::move(next);
|
||||
return true;
|
||||
}
|
||||
int report_round_count(const Catalog &world, const Json &state, bool other) {
|
||||
if (!valid_demo_reports(state, world))
|
||||
return 1;
|
||||
@@ -389,6 +405,19 @@ Json report_strength_rows(const Catalog &world, const Json &state) {
|
||||
}
|
||||
return sorted(std::move(rows), state.at("sorts").at("strengths"));
|
||||
}
|
||||
Json report_indoor_rows(const Catalog &world, const Json &state) {
|
||||
if (!valid_demo_reports(state, world))
|
||||
return Json::array();
|
||||
const auto leagues = world.leagues("nation:de");
|
||||
if (leagues.empty())
|
||||
return Json::array();
|
||||
const auto clubs = world.clubs(leagues.front()->at("id"));
|
||||
std::vector<Json> rows;
|
||||
for (size_t i = 0; i < std::min(size_t(16), clubs.size()); ++i)
|
||||
rows.push_back({{"club", clubs[i]->at("id")}, {"original", i},
|
||||
{"rank", i + 1}, {"points", 324 - int(i) * 19}});
|
||||
return sorted(std::move(rows), state.at("sorts").at("indoor"));
|
||||
}
|
||||
Json report_match_rows(const Catalog &world, const Json &state, bool other) {
|
||||
Json result = Json::array();
|
||||
if (!valid_demo_reports(state, world))
|
||||
|
||||
@@ -7,6 +7,9 @@ namespace bmh::modern_ui {
|
||||
// Each function receives the reports subobject, not the complete DemoSource state.
|
||||
Json demo_reports(const Catalog &);
|
||||
bool valid_demo_reports(const Json &, const Catalog &);
|
||||
// Adds only the missing indoor sort to an otherwise valid legacy reports object.
|
||||
// Invalid existing fields reject atomically; current valid states are unchanged.
|
||||
bool migrate_demo_reports(Json &, const Catalog &);
|
||||
// Returns an empty string on success, an explicit error on rejection. Rejections
|
||||
// leave the reports object unchanged. Actions use kind/value, or kind=round with
|
||||
// step (+/-1) and optional other, or kind=sort with view/key.
|
||||
@@ -15,6 +18,8 @@ std::string edit_demo_reports(Json &, const Json &action, const Catalog &);
|
||||
// the corresponding squad positions have no usable OBW strength information.
|
||||
Json report_table_rows(const Catalog &, const Json &);
|
||||
Json report_strength_rows(const Catalog &, const Json &);
|
||||
// At most 16 clubs from the first German league, independent of report selection.
|
||||
Json report_indoor_rows(const Catalog &, const Json &);
|
||||
Json report_match_rows(const Catalog &, const Json &, bool other);
|
||||
// The presentation-only opening draw: adjacent pairs from at most 64 German
|
||||
// league clubs in catalog order; goals are null until a future runtime owns them.
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
std::string App::render_indoor() {
|
||||
const auto snapshot = snap();
|
||||
const auto &state = snapshot.state.at("reports");
|
||||
const auto &sort = state.at("sorts").at("indoor");
|
||||
const auto rows = report_indoor_rows(*world_, state);
|
||||
std::string body = "<div id=\"report-underlay\" class=\"report-underlay\">"
|
||||
"<div id=\"report-list\" class=\"report-list indoor-list\">"
|
||||
"<div class=\"report-table\" role=\"table\">"
|
||||
"<div class=\"report-row report-head\" role=\"row\">";
|
||||
for (const auto &[key, label] :
|
||||
std::array<std::pair<std::string, std::string>, 2>{
|
||||
{{"rank", "Pl. / Verein"}, {"points", "Punkte"}}}) {
|
||||
const bool current = sort.at("key") == key;
|
||||
const bool descending = sort.at("desc").get<bool>();
|
||||
std::string indicator = "<span class=\"report-sort-symbol\">";
|
||||
if (!current || !descending)
|
||||
indicator += "<span class=\"report-sort-arrow up\"></span>";
|
||||
if (!current || descending)
|
||||
indicator += "<span class=\"report-sort-arrow down\"></span>";
|
||||
indicator += "</span>";
|
||||
body += "<div class=\"report-cell " + std::string(key == "rank" ? "first" : "") +
|
||||
"\" role=\"columnheader\" aria-sort=\"" +
|
||||
(current ? descending ? "descending" : "ascending" : "none") + "\">" +
|
||||
btn("report-sort", "<span>" + esc(label) + "</span>" + indicator,
|
||||
"report-sort", "id=\"report-sort-" + key + "\" data-id=\"" + key +
|
||||
"\" aria-label=\"Nach " + esc(label) + " sortieren\"") + "</div>";
|
||||
}
|
||||
body += "</div>";
|
||||
for (size_t i = 0; i < rows.size(); ++i) {
|
||||
const auto &row = rows[i];
|
||||
body += "<div class=\"report-row " + std::string(i % 2 == 0 ? "striped" : "") +
|
||||
"\" role=\"row\" data-club=\"" + esc(row.at("club").get<std::string>()) +
|
||||
"\"><div class=\"report-cell first\" role=\"cell\">"
|
||||
"<span class=\"report-rank\"><span>" +
|
||||
std::to_string(row.at("rank").get<int>()) + ".</span></span>" +
|
||||
report_club_button(row.at("club").get<std::string>()) +
|
||||
"</div><div class=\"report-cell\" role=\"cell\">"
|
||||
"<span class=\"report-value\">" + std::to_string(row.at("points").get<int>()) +
|
||||
"</span></div></div>";
|
||||
}
|
||||
body += "</div></div><nav class=\"report-footer\">" +
|
||||
btn("indoor-info", "<span>Nach dem 5. Turnier</span>", "report-reset indoor-info",
|
||||
"id=\"indoor-info\"") + "</nav></div>";
|
||||
return body + render_report_detail();
|
||||
}
|
||||
|
||||
bool App::indoor_action(const std::string &action, Rml::Element *target) {
|
||||
if (action != "indoor-info")
|
||||
return false;
|
||||
if (menu_ != "indoor" || !world_ || !target)
|
||||
return true;
|
||||
report_detail_return_focus_ = target->GetId();
|
||||
report_detail_kind_ = "indoor-info";
|
||||
report_detail_club_.clear();
|
||||
report_detail_player_.clear();
|
||||
focus_after_render_ = "report-detail-close";
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
@@ -81,7 +81,7 @@ DemoSource::DemoSource(std::shared_ptr<const Catalog> catalog)
|
||||
state_["tactics"] = demo_tactics();
|
||||
if (!valid_date(state_.at("date")))
|
||||
throw editor::Error("invalid_demo_date");
|
||||
state_["calendar"] = demo_calendar(*catalog_, state_.at("date"));
|
||||
state_["calendar"] = demo_calendar(*catalog_, state_.at("date"), club);
|
||||
state_["reports"] = demo_reports(*catalog_);
|
||||
saved_ = state_;
|
||||
}
|
||||
@@ -118,6 +118,10 @@ ActionResult DemoSource::apply(const Action &action) {
|
||||
if (next.at("training").at("club") != first) {
|
||||
next["training"] = demo_training(*catalog_, first);
|
||||
next["tactics"] = demo_tactics();
|
||||
next["calendar"] = demo_calendar(*catalog_, next.at("date"), first);
|
||||
const auto error = edit_demo_reports(next["reports"],
|
||||
{{"kind", "league"}, {"value", next["calendar"]["league"]}}, *catalog_);
|
||||
if (!error.empty()) return {false, revision_, error};
|
||||
}
|
||||
} else if (action.kind == "training") {
|
||||
const auto error = edit_demo_training(next["training"], action.value);
|
||||
@@ -129,7 +133,7 @@ ActionResult DemoSource::apply(const Action &action) {
|
||||
return {false, revision_, error};
|
||||
} else if (action.kind == "calendar") {
|
||||
const auto error = edit_demo_calendar(next["calendar"], action.value,
|
||||
*catalog_);
|
||||
*catalog_, next["managers"][0]["club"]);
|
||||
if (!error.empty())
|
||||
return {false, revision_, error};
|
||||
if (action.value.value("kind", "") == "league") {
|
||||
@@ -216,8 +220,8 @@ Json DemoSource::load(const fs::path &file) {
|
||||
!camp_id(data.at("camp").at("selected")))
|
||||
throw editor::Error("invalid_demo_state");
|
||||
if (!data.contains("calendar"))
|
||||
data["calendar"] = demo_calendar(*catalog_, data.at("date"));
|
||||
if (!valid_demo_calendar(data.at("calendar"), *catalog_))
|
||||
data["calendar"] = demo_calendar(*catalog_, data.at("date"), club);
|
||||
if (!migrate_demo_calendar(data["calendar"], *catalog_, club))
|
||||
throw editor::Error("invalid_demo_calendar");
|
||||
if (!data.contains("reports")) {
|
||||
data["reports"] = demo_reports(*catalog_);
|
||||
@@ -228,7 +232,7 @@ Json DemoSource::load(const fs::path &file) {
|
||||
}
|
||||
if (!data.contains("opening_created"))
|
||||
data["opening_created"] = false;
|
||||
if (!valid_demo_reports(data.at("reports"), *catalog_) ||
|
||||
if (!migrate_demo_reports(data["reports"], *catalog_) ||
|
||||
!data.at("opening_created").is_boolean())
|
||||
throw editor::Error("invalid_demo_reports");
|
||||
data["calendar"]["league"] = data["reports"]["league"];
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
bool App::planning_action(const std::string &action, Rml::Element *target) {
|
||||
const auto id = target ? target->GetAttribute<Rml::String>("data-id", "") : "";
|
||||
if (action == "planning-close") {
|
||||
planning_dialog_.clear();
|
||||
focus_after_render_ = planning_return_focus_;
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
if (action.starts_with("postpone-")) {
|
||||
if (menu_ != "postpone") return true;
|
||||
if (action == "postpone-undo") {
|
||||
const auto calendar = planning_calendar();
|
||||
if (!calendar.at("moves").empty() && calendar_day_occupied(calendar, *world_, manager(snap()).value("club", ""), calendar.at("moves").back().at("from"))) {
|
||||
planning_dialog_ = "undo-blocked";
|
||||
planning_notice_ = "Der ursprüngliche Termin ist inzwischen belegt.";
|
||||
planning_return_focus_ = "postpone-undo";
|
||||
focus_after_render_ = "planning-close";
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (apply("calendar", {{"kind", action}})) {
|
||||
focus_after_render_ = action == "postpone-cancel" ? "postpone-source"
|
||||
: "calendar-day-" + std::to_string(snap().state.at("calendar").at("selected").get<int>());
|
||||
refresh();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (!action.starts_with("friendly-")) return false;
|
||||
if (menu_ != "friendlies") return true;
|
||||
const auto calendar = planning_calendar();
|
||||
if (action == "friendly-opponent" || action == "friendly-calendar") {
|
||||
if (action == "friendly-opponent" && !apply("calendar", {{"kind", "friendly-opponent"}, {"value", id}})) return true;
|
||||
if (snap().state.at("calendar").at("opponent") == "") return true;
|
||||
planning_return_focus_ = target ? target->GetId() : "friendly-calendar";
|
||||
planning_dialog_ = "venue";
|
||||
focus_after_render_ = "friendly-home";
|
||||
} else if (action == "friendly-venue") {
|
||||
if (!apply("calendar", {{"kind", "friendly-venue"}, {"value", id == "home"}})) return true;
|
||||
planning_dialog_ = "quote";
|
||||
focus_after_render_ = "planning-close";
|
||||
} else if (action == "friendly-quote-accept") {
|
||||
if (!apply("calendar", {{"kind", "friendly-stage"}, {"value", 1}})) return true;
|
||||
planning_dialog_.clear();
|
||||
// Keep a valid selected date; otherwise choose the first chronological free day.
|
||||
int selected = calendar.at("selected");
|
||||
const auto own = manager(snap()).value("club", "");
|
||||
const int count = int(calendar_days(calendar.at("start")).size());
|
||||
if (selected < 7 || calendar_day_occupied(calendar, *world_, own, selected)) {
|
||||
selected = 7;
|
||||
while (selected < count && calendar_day_occupied(calendar, *world_, own, selected)) ++selected;
|
||||
}
|
||||
focus_after_render_ = selected < count ? "calendar-day-" + std::to_string(selected) : "friendly-back";
|
||||
} else if (action == "friendly-back") {
|
||||
if (!apply("calendar", {{"kind", "friendly-stage"}, {"value", 0}})) return true;
|
||||
planning_dialog_.clear();
|
||||
focus_after_render_ = "friendly-opponent-" + calendar.at("opponent").get<std::string>();
|
||||
} else if (action == "friendly-book") {
|
||||
if (!apply("calendar", {{"kind", "friendly-book"}})) return true;
|
||||
const auto days = calendar_days(calendar.at("start"));
|
||||
const auto *opponent = world_->find("clubs", calendar.at("opponent"));
|
||||
planning_notice_ = calendar_date_label(days.at(calendar.at("selected").get<size_t>()).iso) + " · " +
|
||||
(opponent ? world_->name(*opponent) : "—") + " · " + (calendar.at("home").get<bool>() ? "Heim" : "Auswärts");
|
||||
planning_return_focus_ = "friendly-list";
|
||||
planning_dialog_ = "booked";
|
||||
focus_after_render_ = "planning-close";
|
||||
} else if (action == "friendly-list") {
|
||||
planning_return_focus_ = "friendly-list";
|
||||
planning_dialog_ = "list";
|
||||
focus_after_render_ = "planning-close";
|
||||
} else return false;
|
||||
close_report_picker(false);
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
std::string App::planning_progress(bool second, bool postpone) {
|
||||
const std::array<std::string, 2> captions = postpone
|
||||
? std::array<std::string, 2>{"Spiel wählen", "Termin wählen"}
|
||||
: std::array<std::string, 2>{"Gegner", "Termin"};
|
||||
std::string out = "<div class=\"planning-progress\">";
|
||||
for (int i = 0; i < 2; ++i)
|
||||
out += "<span class=\"planning-step " + std::string(second == bool(i) ? "current" : "") +
|
||||
"\"><span class=\"planning-step-number\"><span>" + std::to_string(i + 1) +
|
||||
"</span></span><span>" + captions[size_t(i)] + "</span></span>";
|
||||
return out + "</div>";
|
||||
}
|
||||
|
||||
std::string App::render_postpone() {
|
||||
const auto calendar = planning_calendar();
|
||||
const auto own = manager(snap()).value("club", "");
|
||||
const auto *league = world_->find("competitions", calendar.at("league"));
|
||||
const auto fixtures = calendar_fixtures(calendar, *world_, own);
|
||||
const int day = calendar.at("selected"), from = calendar.at("source_day");
|
||||
const auto selected = std::find_if(fixtures.begin(), fixtures.end(), [&](const auto &f) { return f.day == day; });
|
||||
const auto source = std::find_if(fixtures.begin(), fixtures.end(), [&](const auto &f) { return f.from == from; });
|
||||
const bool has_source = source != fixtures.end();
|
||||
const bool valid = has_source && day >= 7 && !calendar_day_occupied(calendar, *world_, own, day);
|
||||
const auto start = calendar.at("start").get<std::string>().substr(0, 4);
|
||||
const auto season = start + "/" + std::to_string((std::stoi(start) + 1) % 100);
|
||||
const auto status = !has_source ? "Zuerst ein gelb markiertes Ligaspiel wählen."
|
||||
: day < 7 ? "Bitte einen Termin ab dem 8. Juli wählen."
|
||||
: !valid ? "Dieser Termin ist bereits belegt." : "Freier Termin · Spiel kann verlegt werden.";
|
||||
auto source_calendar = calendar;
|
||||
source_calendar["selected"] = has_source ? source->day : day;
|
||||
const auto source_label = has_source || selected != fixtures.end() ? calendar_day_info(source_calendar)
|
||||
: "Ein gelb markiertes Ligaspiel im Kalender anklicken.";
|
||||
std::string body = "<div id=\"report-underlay\" class=\"report-underlay postpone-layout\">"
|
||||
"<header class=\"planning-heading\"><h2>" + esc(world_->name(*world_->find("clubs", own))) +
|
||||
"</h2><p>" + esc(league ? world_->name(*league) : "") + " · Saison " + season +
|
||||
"</p>" + planning_progress(has_source, true) + "</header>" +
|
||||
calendar_grid(calendar, 132, 1362, 28, 22, false, true) +
|
||||
"<section class=\"postpone-summary source " + std::string(has_source ? "selected-source" : "") + "\"><h3>Ausgangsspiel</h3><p>" + esc(source_label) +
|
||||
"</p><small>" + (has_source ? "Das Ausgangsspiel ist im Kalender grün umrahmt." : "Mit „Ausgangsspiel wählen“ bestätigen.") +
|
||||
"</small>" + (has_source ? btn("postpone-cancel", "×", "postpone-cancel", "id=\"postpone-cancel\" aria-label=\"Ausgangsspielauswahl aufheben\"") : "") +
|
||||
"</section><section class=\"postpone-summary target\"><h3>Neuer Termin</h3><p>" + esc(calendar_day_info(calendar)) +
|
||||
"</p><small class=\"" + (valid ? "valid" : "") + "\">" + status + "</small></section><nav class=\"planning-footer\">";
|
||||
body += btn("postpone-source", "Ausgangsspiel wählen", {}, "id=\"postpone-source\" " + std::string(selected == fixtures.end() ? "disabled" : "")) +
|
||||
btn("postpone-move", "Hierhin verlegen", {}, "id=\"postpone-move\" " + std::string(valid ? "" : "disabled")) +
|
||||
btn("postpone-undo", "Letzte Verlegung zurück", {}, "id=\"postpone-undo\" " + std::string(calendar.at("moves").empty() ? "disabled" : ""));
|
||||
return body + "</nav></div>" + render_planning_dialog();
|
||||
}
|
||||
|
||||
std::string App::render_friendlies() {
|
||||
const auto calendar = planning_calendar();
|
||||
const auto own = manager(snap()).value("club", "");
|
||||
const auto *league = world_->find("competitions", calendar.at("friendly_league"));
|
||||
const auto *opponent = world_->find("clubs", calendar.at("opponent"));
|
||||
const bool booking = calendar.at("friendly_stage") == 1, full = calendar.at("friendlies").size() >= 20;
|
||||
const int day = calendar.at("selected");
|
||||
const bool available = day >= 7 && !calendar_day_occupied(calendar, *world_, own, day);
|
||||
const auto start = calendar.at("start").get<std::string>().substr(0, 4);
|
||||
const auto season = start + "/" + std::to_string((std::stoi(start) + 1) % 100);
|
||||
const auto venue = calendar.at("home").get<bool>() ? "Heimspiel" : "Auswärtsspiel";
|
||||
std::string body = "<div id=\"report-underlay\" class=\"report-underlay friendlies-layout\">"
|
||||
"<header class=\"planning-heading " + std::string(booking ? "booking" : "") + "\"><h2>" + (booking ? label(opponent, 58) : esc(league ? world_->name(*league) : "—")) +
|
||||
"</h2><p>" + (booking ? std::string(venue) + " · Kostenbeitrag " + cash(calendar_friendly_fee(calendar, *world_))
|
||||
: "Freundschaftsspiel vereinbaren · Saison " + season) +
|
||||
"</p>" + planning_progress(booking, false) + "</header>";
|
||||
const auto count_label = "Vorgemerkte Spiele · " + std::to_string(calendar.at("friendlies").size());
|
||||
if (!booking) {
|
||||
const auto clubs = world_->clubs(calendar.at("friendly_league"));
|
||||
auto reports = snap().state.at("reports");
|
||||
reports["league"] = calendar.at("friendly_league");
|
||||
reports["round"] = 0;
|
||||
const auto strengths = report_strength_rows(*world_, reports);
|
||||
body += "<div id=\"friendly-opponents\" class=\"friendly-opponents\"><div class=\"friendly-table\"><div class=\"friendly-row head\">";
|
||||
for (const auto &heading : {"Gegner", "Stärke", "Platz", "Spiele"}) body += "<div class=\"friendly-cell\"><span>" + std::string(heading) + "</span></div>";
|
||||
body += "</div>";
|
||||
size_t visible = 0;
|
||||
for (size_t i = 0; i < clubs.size(); ++i) {
|
||||
const auto *c = clubs[i]; const auto id = c->value("id", "");
|
||||
if (id == own) continue;
|
||||
const auto value = std::find_if(strengths.begin(), strengths.end(), [&](const auto &r) { return r.at("club") == id; });
|
||||
const auto strength = value == strengths.end() ? "—" : report_number(value->at("strength"));
|
||||
body += "<div class=\"friendly-row " + std::string(visible++ % 2 == 0 ? "striped " : "") + (calendar.at("opponent") == id ? "selected" : "") + "\"><div class=\"friendly-cell\">" +
|
||||
btn("friendly-opponent", label(c, 42), "friendly-opponent", "id=\"friendly-opponent-" + esc(id) + "\" data-id=\"" + esc(id) + "\" aria-pressed=\"" + (calendar.at("opponent") == id ? "true" : "false") + "\"") +
|
||||
"</div><div class=\"friendly-cell\"><span>" + strength + "</span></div><div class=\"friendly-cell\"><span>" + std::to_string(i + 1) +
|
||||
"</span></div><div class=\"friendly-cell\"><span>26</span></div></div>";
|
||||
}
|
||||
body += "</div></div><nav class=\"report-footer\">" + report_picker("country", 0, 547.526882) + report_picker("league", 569.526882, 766.537634) +
|
||||
btn("friendly-calendar", "Termin auswählen", "report-reset", "id=\"friendly-calendar\" style=\"" + rect(1358.064516, 0, 547.526882, 94) + "\" " + (full || !opponent ? "disabled" : "")) +
|
||||
btn("friendly-list", count_label, "report-reset", "id=\"friendly-list\" style=\"" + rect(1927.591398, 0, 684.408602, 94) + "\"");
|
||||
} else {
|
||||
body += calendar_grid(calendar, 148, 1424, 22, 22, true, false) +
|
||||
"<section class=\"friendly-date-summary\"><div class=\"date-side\"><span>Gewählter Termin</span><p>" + esc(calendar_day_info(calendar)) +
|
||||
"</p></div><div class=\"status-side\"><div class=\"friendly-key\"><span class=\"league-dot\"></span><span>Ligaspiel</span><span class=\"friendly-dot\"></span><span>Freundschaftsspiel</span></div><p class=\"" + (available && !full ? "valid" : "") + "\">" +
|
||||
(full ? "Alle 20 Vormerkungen sind belegt." : available ? "Freier Termin · Spiel kann vorgemerkt werden." : "Bitte einen freien Termin ab dem 8. Juli wählen.") +
|
||||
"</p></div></section><nav class=\"planning-footer\">" +
|
||||
btn("friendly-back", "Gegner ändern", {}, "id=\"friendly-back\"") +
|
||||
btn("friendly-list", count_label, {}, "id=\"friendly-list\"") +
|
||||
btn("friendly-book", "Termin vormerken", {}, "id=\"friendly-book\" " + std::string(available && !full && opponent ? "" : "disabled"));
|
||||
}
|
||||
return body + "</nav></div>" + render_planning_dialog();
|
||||
}
|
||||
|
||||
std::string App::render_planning_dialog() {
|
||||
if (planning_dialog_.empty()) return {};
|
||||
const auto calendar = planning_calendar();
|
||||
const auto *opponent = world_->find("clubs", calendar.at("opponent"));
|
||||
std::string heading, body, actions;
|
||||
double height = planning_dialog_ == "undo-blocked" ? 332 : 341;
|
||||
const auto close = [&](const std::string &caption) { return btn("planning-close", caption, {}, "id=\"planning-close\""); };
|
||||
if (planning_dialog_ == "venue" || planning_dialog_ == "quote") {
|
||||
const bool quote = planning_dialog_ == "quote";
|
||||
heading = quote ? "Freundschaftsspiel · Kosten" : "Austragungsort";
|
||||
height = quote ? 720.5 : 496;
|
||||
body = "<div class=\"friendly-dialog-club\"><span class=\"club-label\"><span class=\"planning-badge\">" + crest(opponent, 72) + "</span><span>" + esc(opponent ? world_->name(*opponent) : "—") + "</span></span><span>" +
|
||||
(quote ? std::string(calendar.at("home").get<bool>() ? "Heimspiel" : "Auswärtsspiel") : "Heimspiel oder Auswärtsspiel?") + "</span></div>";
|
||||
if (quote) {
|
||||
body += "<div class=\"friendly-quote-amount\"><span>Fiktiver Kostenbeitrag</span><strong>" + cash(calendar_friendly_fee(calendar, *world_)) +
|
||||
"</strong></div><p class=\"friendly-quote-note\">Anschließend einen freien Termin im Kalender wählen.</p>";
|
||||
actions = close("Abbrechen") + btn("friendly-quote-accept", "Termin wählen", {}, "id=\"friendly-quote-accept\"");
|
||||
} else actions = btn("friendly-venue", "Heim", {}, "id=\"friendly-home\" data-id=\"home\"") +
|
||||
btn("friendly-venue", "Auswärts", {}, "id=\"friendly-away\" data-id=\"away\"") + close("Abbrechen");
|
||||
} else if (planning_dialog_ == "list") {
|
||||
heading = "Vorgemerkte Freundschaftsspiele";
|
||||
auto bookings = calendar.at("friendlies");
|
||||
std::sort(bookings.begin(), bookings.end(), [](const auto &a, const auto &b) { return a.at("day") < b.at("day"); });
|
||||
const auto days = calendar_days(calendar.at("start"));
|
||||
height = bookings.empty() ? 330.5 : 287 + std::min(1020., 80. * (bookings.size() + 1));
|
||||
body = "<div class=\"friendly-bookings\">";
|
||||
if (bookings.empty()) body += "<p>Noch keine Freundschaftsspiele vorgemerkt.</p>";
|
||||
else {
|
||||
body += "<div class=\"friendly-booking-row head\"><span><span>Datum</span></span><span><span>Gegner</span></span><span><span>Ort</span></span></div>";
|
||||
for (const auto &f : bookings)
|
||||
body += "<div class=\"friendly-booking-row\"><span><span>" + calendar_date_label(days.at(f.at("day").get<size_t>()).iso) +
|
||||
"</span></span><span>" + label(world_->find("clubs", f.at("opponent")), 42) + "</span><span><span>" +
|
||||
(f.at("home").get<bool>() ? "Heim" : "Auswärts") + "</span></span></div>";
|
||||
}
|
||||
body += "</div>";
|
||||
actions = close("Zurück");
|
||||
} else {
|
||||
heading = planning_dialog_ == "booked" ? "Spiel vorgemerkt" : "Rücknahme nicht möglich";
|
||||
body = "<p class=\"planning-notice\">" + esc(planning_notice_) + "</p>";
|
||||
actions = close("Verstanden");
|
||||
}
|
||||
return "<div id=\"planning-layer\" class=\"planning-layer\"><section id=\"planning-dialog\" class=\"planning-dialog " + planning_dialog_ +
|
||||
"\" role=\"dialog\" aria-modal=\"true\" aria-labelledby=\"planning-dialog-title\" style=\"height:" + scalar(height) +
|
||||
"dp;\"><h2 id=\"planning-dialog-title\">" + heading + "</h2>" + body +
|
||||
"<nav class=\"planning-dialog-actions\">" + actions + "</nav></section></div>";
|
||||
}
|
||||
@@ -121,7 +121,18 @@ std::string App::render_report_detail() {
|
||||
"id=\"report-detail-close\"");
|
||||
};
|
||||
std::string title, body, actions;
|
||||
if (report_detail_kind_ == "club" && club) {
|
||||
if (report_detail_kind_ == "indoor-info") {
|
||||
title = "Hallenmasters";
|
||||
std::string season = "—";
|
||||
if (const auto date = report_detail_date(current_date)) {
|
||||
const int start = (*date)[0] - ((*date)[1] < 7 ? 1 : 0);
|
||||
const auto next = std::to_string((start + 1) % 100);
|
||||
season = std::to_string(start) + "/" + (next.size() < 2 ? "0" : "") + next;
|
||||
}
|
||||
body = "<p class=\"report-detail-info-text\">Fiktive Ergebnisse und Platzierungen zur Saison " +
|
||||
esc(season) + ".</p>";
|
||||
actions = close("Zurück");
|
||||
} else if (report_detail_kind_ == "club" && club) {
|
||||
title = display_name(club);
|
||||
const Json *stadium = nullptr;
|
||||
if (const auto id = club->find("stadium");
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
namespace {
|
||||
bool report_picker_menu(const std::string &menu) {
|
||||
return menu == "tables" || menu == "strengths" || menu == "league" ||
|
||||
menu == "other";
|
||||
menu == "other" || menu == "calendar" || menu == "friendlies";
|
||||
}
|
||||
bool report_picker_kind(const std::string &kind) {
|
||||
return kind == "country" || kind == "league" || kind == "filter" ||
|
||||
@@ -46,8 +46,7 @@ App::report_picker_items(const std::string &kind) const {
|
||||
});
|
||||
return items;
|
||||
}
|
||||
const auto reports = snap().state.at("reports");
|
||||
const auto *league = world_->find("competitions", reports.at("league").get<std::string>());
|
||||
const auto *league = world_->find("competitions", report_picker_value("league"));
|
||||
if (league)
|
||||
for (const auto *candidate : world_->leagues(league->value("nation", "")))
|
||||
items.emplace_back(candidate->value("id", ""), world_->name(*candidate));
|
||||
@@ -60,7 +59,9 @@ std::string App::report_picker_value(const std::string &kind) const {
|
||||
const auto reports = snap().state.at("reports");
|
||||
if (kind == "filter" || kind == "competition")
|
||||
return std::to_string(reports.at(kind).get<int>());
|
||||
const auto league = reports.at("league").get<std::string>();
|
||||
const auto league = menu_ == "friendlies" ? snap().state.at("calendar").at("friendly_league").get<std::string>()
|
||||
: menu_ == "calendar" ? snap().state.at("calendar").at("league").get<std::string>()
|
||||
: reports.at("league").get<std::string>();
|
||||
if (kind == "league")
|
||||
return league;
|
||||
const auto *row = world_->find("competitions", league);
|
||||
@@ -170,7 +171,14 @@ bool App::report_picker_action(const std::string &action, Rml::Element *target)
|
||||
? Json(std::stoi(value)) : Json(value);
|
||||
close_report_picker(false);
|
||||
// Commit even an unchanged country: the Gold resets its first league.
|
||||
apply("reports", {{"kind", kind}, {"value", selection}});
|
||||
if (menu_ == "friendlies")
|
||||
apply("calendar", {{"kind", "friendly-" + kind}, {"value", selection}});
|
||||
else if (menu_ == "calendar") {
|
||||
const auto leagues = kind == "country" ? world_->leagues(value) : std::vector<const Json *>{};
|
||||
const auto league = kind == "country" && !leagues.empty() ? leagues.front()->value("id", "") : value;
|
||||
apply("calendar", {{"kind", "league"}, {"value", league}});
|
||||
} else
|
||||
apply("reports", {{"kind", kind}, {"value", selection}});
|
||||
focus_after_render_ = "report-picker-" + kind;
|
||||
refresh();
|
||||
return true;
|
||||
|
||||
@@ -885,6 +885,12 @@ std::string App::render_menu(const std::string &key) {
|
||||
std::string body;
|
||||
if (key == "tables" || key == "strengths" || key == "league" || key == "other")
|
||||
body = render_reports(key);
|
||||
else if (key == "postpone")
|
||||
body = render_postpone();
|
||||
else if (key == "friendlies")
|
||||
body = render_friendlies();
|
||||
else if (key == "indoor")
|
||||
body = render_indoor();
|
||||
else if (key == "training")
|
||||
body = render_training();
|
||||
else if (key == "tactics")
|
||||
@@ -903,5 +909,5 @@ std::string App::render_menu(const std::string &key) {
|
||||
else
|
||||
throw editor::Error("Diese native Ansicht ist noch nicht verfügbar.");
|
||||
return "<div class=\"fill\" style=\"z-index:100;\">" +
|
||||
window(title(key), body) + "</div>";
|
||||
window(key == "postpone" ? "Spiel verlegen" : title(key), body) + "</div>";
|
||||
}
|
||||
+24
-2
@@ -310,6 +310,7 @@ class App final : public Rml::EventListener {
|
||||
std::string last_report_state_, report_picker_, report_detail_kind_,
|
||||
report_detail_club_, report_detail_player_, report_detail_return_focus_,
|
||||
report_option_to_scroll_;
|
||||
std::string planning_dialog_, planning_notice_, planning_return_focus_;
|
||||
float device_ratio_ = 1.f;
|
||||
Json desktop_ = Json::object(), saved_desktop_ = Json::object(),
|
||||
options_ = Json::object();
|
||||
@@ -616,6 +617,16 @@ class App final : public Rml::EventListener {
|
||||
std::string render_training();
|
||||
std::string render_tactics();
|
||||
std::string render_calendar();
|
||||
Json planning_calendar() const;
|
||||
std::string calendar_day_info(const Json &) const;
|
||||
std::string calendar_grid(const Json &, double, double, double, double, bool, bool);
|
||||
std::string render_postpone();
|
||||
std::string render_friendlies();
|
||||
std::string render_planning_dialog();
|
||||
std::string planning_progress(bool, bool);
|
||||
bool planning_action(const std::string &, Rml::Element *);
|
||||
std::string render_indoor();
|
||||
bool indoor_action(const std::string &, Rml::Element *);
|
||||
std::string training_balls(const std::string &, int, int, bool,
|
||||
const std::string &player = {}, int size = 56,
|
||||
int gap = 10, bool overtraining = false);
|
||||
@@ -675,6 +686,13 @@ class App final : public Rml::EventListener {
|
||||
dirty_ = true;
|
||||
}
|
||||
void render() {
|
||||
// A window-close save prompt can leave a menu while its local dialog is
|
||||
// open. Never keep that menu's modal/input gate in the destination view.
|
||||
if (menu_ != last_rendered_menu_) {
|
||||
planning_dialog_.clear();
|
||||
report_detail_kind_.clear();
|
||||
report_picker_.clear();
|
||||
}
|
||||
training_scroll_.reset();
|
||||
if (menu_ == "training" && last_rendered_menu_ == "training")
|
||||
if (auto *roster = element("training-roster"))
|
||||
@@ -705,7 +723,7 @@ class App final : public Rml::EventListener {
|
||||
if (!menu_.empty())
|
||||
markup += render_menu(menu_);
|
||||
element("canvas")->SetInnerRML(markup);
|
||||
if (!report_detail_kind_.empty()) {
|
||||
if (!report_detail_kind_.empty() || !planning_dialog_.empty()) {
|
||||
Rml::ElementList behind;
|
||||
doc_->QuerySelectorAll(behind,
|
||||
"#report-underlay button,#report-underlay input,#report-underlay select,.window .titlebar button");
|
||||
@@ -736,7 +754,8 @@ class App final : public Rml::EventListener {
|
||||
if (!focus_after_render_.empty()) {
|
||||
if (auto *node = element(focus_after_render_))
|
||||
node->Focus(keyboard_navigation_);
|
||||
if (focus_after_render_.starts_with("report-option-"))
|
||||
if (focus_after_render_.starts_with("report-option-") ||
|
||||
focus_after_render_.starts_with("friendly-opponent-"))
|
||||
report_option_to_scroll_ = focus_after_render_;
|
||||
focus_after_render_.clear();
|
||||
}
|
||||
@@ -1039,6 +1058,9 @@ public:
|
||||
#include "modern/ui/report_pickers.inc"
|
||||
#include "modern/ui/report_details.inc"
|
||||
#include "modern/ui/reports_screens.inc"
|
||||
#include "modern/ui/indoor_screen.inc"
|
||||
#include "modern/ui/planning_screens.inc"
|
||||
#include "modern/ui/planning_controls.inc"
|
||||
} // namespace
|
||||
bool is_modern_world(const fs::path &file) {
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user