Port scoped National UI routes and isolated dummy planning (by Codex)
This commit is contained in:
1 parent
4fddecb06e
commit
1eb5e99847
19 files changed
+1075
-8
No files matched your search
@@ -1,5 +1,5 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
add_library(bmh_modern_ui_core STATIC catalog.cpp model.cpp demo_career.cpp gui_assets.cpp desktop.cpp demo_sports.cpp demo_calendar.cpp demo_reports.cpp demo_almanac.cpp demo_finance.cpp demo_environment.cpp demo_advertising.cpp demo_toto.cpp demo_lineup.cpp demo_live.cpp demo_transfer.cpp demo_career_reports.cpp demo_rankings.cpp demo_stadium.cpp demo_statistics.cpp demo_news.cpp demo_settings.cpp ui_preferences.cpp demo_widgets.cpp demo_files.cpp demo_opening.cpp)
|
||||
add_library(bmh_modern_ui_core STATIC catalog.cpp model.cpp demo_career.cpp demo_national_ui.cpp gui_assets.cpp desktop.cpp demo_sports.cpp demo_calendar.cpp demo_reports.cpp demo_almanac.cpp demo_finance.cpp demo_environment.cpp demo_advertising.cpp demo_toto.cpp demo_lineup.cpp demo_live.cpp demo_transfer.cpp demo_career_reports.cpp demo_rankings.cpp demo_stadium.cpp demo_statistics.cpp demo_news.cpp demo_settings.cpp ui_preferences.cpp demo_widgets.cpp demo_files.cpp demo_opening.cpp)
|
||||
target_include_directories(bmh_modern_ui_core PUBLIC ../..)
|
||||
target_link_libraries(bmh_modern_ui_core PUBLIC bmh_asset_io)
|
||||
add_library(bmh_modern_ui_mods STATIC mod_library.cpp)
|
||||
@@ -38,7 +38,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 indoor.rcss planning.rcss almanac.rcss finance.rcss bank.rcss contracts.rcss amount.rcss environment.rcss advertising.rcss toto.rcss lineup.rcss live.rcss transfer.rcss career_reports.rcss rankings.rcss stadium.rcss statistics.rcss news.rcss settings.rcss widgets.rcss files.rcss front.rcss entry.rcss opening.rcss select_menu.rcss career.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 almanac.rcss finance.rcss bank.rcss contracts.rcss amount.rcss environment.rcss advertising.rcss toto.rcss lineup.rcss live.rcss transfer.rcss career_reports.rcss rankings.rcss stadium.rcss statistics.rcss news.rcss settings.rcss widgets.rcss files.rcss front.rcss entry.rcss opening.rcss select_menu.rcss career.rcss national.rcss)
|
||||
configure_file("${CMAKE_SOURCE_DIR}/assets/modern/${asset}" "${modern_assets}/${asset}" COPYONLY)
|
||||
endforeach()
|
||||
|
||||
@@ -124,7 +124,7 @@ foreach(component environment advertising toto lineup transfer stadium)
|
||||
add_test(NAME modern_${component}_ui_tests COMMAND modern_${component}_ui_tests)
|
||||
endforeach()
|
||||
|
||||
foreach(component statistics news settings desktop files entry opening career live)
|
||||
foreach(component statistics news settings desktop files entry opening career live national)
|
||||
add_executable(modern_${component}_ui_tests ../../../tests/modern_${component}_ui_tests.cpp)
|
||||
target_link_libraries(modern_${component}_ui_tests PRIVATE bmh_modern_ui_core)
|
||||
if(MSVC)
|
||||
|
||||
@@ -149,6 +149,7 @@ void App::ProcessEvent(Rml::Event &event) try {
|
||||
return;
|
||||
if(front_event(event))return;
|
||||
if (live_event(event)) return;
|
||||
if(national_event(event))return;
|
||||
if (career_event(event)) return;
|
||||
if (entry_event(event)) return;
|
||||
if (opening_event(event)) return;
|
||||
@@ -467,6 +468,7 @@ void App::dispatch(const std::string &action, Rml::Element *target) {
|
||||
target ? target->GetAttribute<Rml::String>("data-id", "") : std::string();
|
||||
if(front_action(action,target))return;
|
||||
if (live_action(action, target)) return;
|
||||
if(national_action(action,target))return;
|
||||
if (career_action(action,target)) return;
|
||||
if (entry_action(action, target)) return;
|
||||
if (opening_action(action, target)) return;
|
||||
@@ -991,7 +993,7 @@ void App::script() {
|
||||
{"transfer_view", transfer_view_}, {"transfer_dialog", transfer_dialog_}, {"transfer_draft", transfer_draft_},
|
||||
{"career_view", career_view_}, {"rankings_view", rankings_view_},
|
||||
{"stadium_view", stadium_view_},
|
||||
{"select_menu", select_menu_ ? select_menu_->snapshot() : Json()}, {"career_context",source_?demo_career_context(snap().state,*world_):Json()}, {"manager_hub",{{"resign_open",career_resign_open_},{"game_end",career_game_end_},{"owner",field("career-resign-owner")}}}, {"entry_view", entry_snapshot()}, {"front_view",front_snapshot_view()}, {"files_view",{{"mode",files_mode_},{"selected",files_selected_},{"name",files_name_},{"feedback",files_feedback_}}}, {"widget_view",{{"query",widget_query_},{"notice",widget_notice_}}}, {"ui_preferences",ui_preferences_}, {"settings_draft",settings_draft_}, {"settings_category",settings_category_}, {"settings_query",settings_query_}, {"settings_notice",settings_notice_},
|
||||
{"select_menu", select_menu_ ? select_menu_->snapshot() : Json()}, {"career_context",source_?demo_career_context(snap().state,*world_):Json()}, {"national_view",{{"dialog",national_dialog_},{"menu",national_menu_},{"portrait",national_portrait_},{"revision",national_revision_}}}, {"manager_hub",{{"resign_open",career_resign_open_},{"game_end",career_game_end_},{"owner",field("career-resign-owner")}}}, {"entry_view", entry_snapshot()}, {"front_view",front_snapshot_view()}, {"files_view",{{"mode",files_mode_},{"selected",files_selected_},{"name",files_name_},{"feedback",files_feedback_}}}, {"widget_view",{{"query",widget_query_},{"notice",widget_notice_}}}, {"ui_preferences",ui_preferences_}, {"settings_draft",settings_draft_}, {"settings_category",settings_category_}, {"settings_query",settings_query_}, {"settings_notice",settings_notice_},
|
||||
{"statistics_view", statistics_view_}, {"statistics_trophy", statistics_trophy_},
|
||||
{"statistics_scrolls", statistics_scrolls_},
|
||||
{"news_view", news_view_}, {"news_dialog", news_dialog_},
|
||||
|
||||
@@ -0,0 +1,272 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/ui/demo_national_ui.hpp"
|
||||
#include "modern/ui/demo_career.hpp"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
#include <iomanip>
|
||||
#include <optional>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
namespace bmh::modern_ui {
|
||||
namespace {
|
||||
std::optional<std::chrono::sys_days> day(const Json &v) {
|
||||
if (!v.is_string())
|
||||
return {};
|
||||
const auto s = v.get<std::string>();
|
||||
if (s.size() != 10 || s[4] != '-' || s[7] != '-')
|
||||
return {};
|
||||
for (size_t i = 0; i < s.size(); ++i)
|
||||
if (i != 4 && i != 7 && (s[i] < '0' || s[i] > '9'))
|
||||
return {};
|
||||
const auto ymd = std::chrono::year_month_day{
|
||||
std::chrono::year{std::stoi(s.substr(0, 4))},
|
||||
std::chrono::month{unsigned(std::stoi(s.substr(5, 2)))},
|
||||
std::chrono::day{unsigned(std::stoi(s.substr(8, 2)))}};
|
||||
if (!ymd.ok() || int(ymd.year()) < 1)
|
||||
return {};
|
||||
return std::chrono::sys_days{ymd};
|
||||
}
|
||||
std::string iso(std::chrono::sys_days value) {
|
||||
const auto ymd = std::chrono::year_month_day{value};
|
||||
std::ostringstream out;
|
||||
out << int(ymd.year()) << '-' << std::setfill('0') << std::setw(2)
|
||||
<< unsigned(ymd.month()) << '-' << std::setw(2) << unsigned(ymd.day());
|
||||
return out.str();
|
||||
}
|
||||
bool opponent(const Json &v) {
|
||||
return v.is_string() &&
|
||||
std::any_of(national_ui_opponents().begin(),
|
||||
national_ui_opponents().end(),
|
||||
[&](const auto &row) { return row.at("id") == v; });
|
||||
}
|
||||
bool integer(const Json &v, int low, int high) {
|
||||
return v.is_number_integer() && v >= low && v <= high;
|
||||
}
|
||||
int season(const Json &state) {
|
||||
const auto date = day(state.at("date"));
|
||||
if (!date)
|
||||
throw editor::Error("invalid_national_date");
|
||||
const auto ymd = std::chrono::year_month_day{*date};
|
||||
return int(ymd.year()) - (unsigned(ymd.month()) < 7);
|
||||
}
|
||||
bool season_date(const Json &state, const Json &v) {
|
||||
const auto d = day(v);
|
||||
if (!d)
|
||||
return false;
|
||||
const int year = season(state);
|
||||
return *d >= std::chrono::sys_days{std::chrono::year{year} / 7 / 1} &&
|
||||
*d <= std::chrono::sys_days{std::chrono::year{year + 1} / 6 / 30};
|
||||
}
|
||||
Json attribute(const Json &p, const char *key) {
|
||||
if (p.contains("attributes") && p.at("attributes").is_object()) {
|
||||
const auto i = p.at("attributes").find(key);
|
||||
if (i != p.at("attributes").end() && i->is_number_integer() &&
|
||||
std::isfinite(i->get<double>()) && *i >= 0)
|
||||
return *i;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
} // namespace
|
||||
const Json &national_ui_opponents() {
|
||||
static const Json rows = [] {
|
||||
Json out = Json::array();
|
||||
int i = 0;
|
||||
for (const auto &[code, name] :
|
||||
std::array<std::pair<const char *, const char *>, 8>{
|
||||
{{"fr", "Frankreich"},
|
||||
{"it", "Italien"},
|
||||
{"es", "Spanien"},
|
||||
{"en", "England"},
|
||||
{"nl", "Niederlande"},
|
||||
{"pl", "Polen"},
|
||||
{"se", "Schweden"},
|
||||
{"at", "Österreich"}}}) {
|
||||
out.push_back({{"id", std::string("national-") + code},
|
||||
{"name", name},
|
||||
{"code", code},
|
||||
{"gui_image", std::string("career.national-") + code},
|
||||
{"strength", 85 - (i++ % 5) * 2}});
|
||||
}
|
||||
return out;
|
||||
}();
|
||||
return rows;
|
||||
}
|
||||
Json default_national_ui() {
|
||||
return {{"opponent", "national-fr"},
|
||||
{"home", true},
|
||||
{"day", ""},
|
||||
{"month", 0},
|
||||
{"stage", "opponents"},
|
||||
{"scorer_kind", 0},
|
||||
{"friendlies", Json::array()}};
|
||||
}
|
||||
bool valid_national_ui(const Json &state) {
|
||||
try {
|
||||
if (!day(state.at("date")))
|
||||
return false;
|
||||
const auto &n = state.at("national");
|
||||
if (!n.is_object() || n.size() != 7 || !opponent(n.at("opponent")) ||
|
||||
!n.at("home").is_boolean() || !n.at("day").is_string() ||
|
||||
(!n.at("day").get<std::string>().empty() &&
|
||||
!season_date(state, n.at("day"))) ||
|
||||
!integer(n.at("month"), 0, 11) || !n.at("stage").is_string() ||
|
||||
(n.at("stage") != "opponents" && n.at("stage") != "calendar") ||
|
||||
!integer(n.at("scorer_kind"), 0, 3) || !n.at("friendlies").is_array() ||
|
||||
n.at("friendlies").size() > 12)
|
||||
return false;
|
||||
std::set<std::string> used;
|
||||
for (const auto &row : n.at("friendlies"))
|
||||
if (!row.is_object() || row.size() != 3 ||
|
||||
!season_date(state, row.at("date")) ||
|
||||
!opponent(row.at("opponent")) || !row.at("home").is_boolean() ||
|
||||
!used.insert(row.at("date").get<std::string>()).second)
|
||||
return false;
|
||||
if (n.at("day") != "") {
|
||||
const auto dates = national_ui_dates(state);
|
||||
if (std::find(dates.begin(), dates.end(), n.at("day")) == dates.end())
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} catch (const std::exception &) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
bool migrate_national_ui(Json &state) {
|
||||
auto next = state;
|
||||
if (!next.contains("national"))
|
||||
next["national"] = default_national_ui();
|
||||
if (!valid_national_ui(next))
|
||||
return false;
|
||||
state = std::move(next);
|
||||
return true;
|
||||
}
|
||||
Json national_ui_dates(const Json &state) {
|
||||
Json dates = Json::array();
|
||||
try {
|
||||
const auto current = day(state.at("date"));
|
||||
if (!current)
|
||||
return dates;
|
||||
for (int i = 0; i < 12; ++i) {
|
||||
const auto value = iso(*current + std::chrono::days{7 + i * 14});
|
||||
if (!season_date(state, value))
|
||||
continue;
|
||||
const auto &bookings = state.at("national").at("friendlies");
|
||||
if (std::none_of(bookings.begin(), bookings.end(),
|
||||
[&](const auto &r) { return r.at("date") == value; }))
|
||||
dates.push_back(value);
|
||||
}
|
||||
} catch (const std::exception &) {
|
||||
}
|
||||
return dates;
|
||||
}
|
||||
std::string edit_national_ui(Json &state, const Json &action) {
|
||||
try {
|
||||
if (!valid_national_ui(state) || !action.is_object() ||
|
||||
!action.contains("kind") || !action.at("kind").is_string() ||
|
||||
!action.contains("manager_portrait") ||
|
||||
!action.at("manager_portrait").is_number_integer())
|
||||
return "invalid_national_action";
|
||||
if (state.at("career").value("role", "club") != "national" ||
|
||||
state.at("career").value("ended", false) ||
|
||||
action.at("manager_portrait") !=
|
||||
demo_career_manager(state).value("portrait", 0))
|
||||
return "national_context_changed";
|
||||
auto next = state;
|
||||
auto &n = next["national"];
|
||||
const auto kind = action.at("kind").get<std::string>();
|
||||
if (kind == "opponent") {
|
||||
if (action.size() != 4 || !opponent(action.at("opponent")) ||
|
||||
!action.at("home").is_boolean())
|
||||
return "invalid_national_opponent";
|
||||
n["opponent"] = action.at("opponent");
|
||||
n["home"] = action.at("home");
|
||||
n["stage"] = "calendar";
|
||||
n["day"] = "";
|
||||
const auto ymd = std::chrono::year_month_day{*day(state.at("date"))};
|
||||
n["month"] = (int(ymd.year()) - season(state)) * 12 +
|
||||
int(unsigned(ymd.month())) - 7;
|
||||
} else if (kind == "month") {
|
||||
if (action.size() != 3 || !integer(action.at("value"), 0, 11))
|
||||
return "invalid_national_month";
|
||||
n["month"] = action.at("value");
|
||||
} else if (kind == "day") {
|
||||
const auto dates = national_ui_dates(state);
|
||||
if (action.size() != 3 || !action.at("value").is_string() ||
|
||||
std::find(dates.begin(), dates.end(), action.at("value")) ==
|
||||
dates.end())
|
||||
return "invalid_national_day";
|
||||
n["day"] = action.at("value");
|
||||
} else if (kind == "book") {
|
||||
const auto dates = national_ui_dates(state);
|
||||
if (action.size() != 2 || n.at("friendlies").size() >= 12 ||
|
||||
std::find(dates.begin(), dates.end(), n.at("day")) == dates.end())
|
||||
return "invalid_national_booking";
|
||||
n["friendlies"].push_back({{"date", n.at("day")},
|
||||
{"opponent", n.at("opponent")},
|
||||
{"home", n.at("home")}});
|
||||
n["day"] = "";
|
||||
} else if (kind == "back") {
|
||||
if (action.size() != 2)
|
||||
return "invalid_national_action";
|
||||
n["stage"] = "opponents";
|
||||
} else if (kind == "scorer_kind") {
|
||||
if (action.size() != 3 || !integer(action.at("value"), 0, 3))
|
||||
return "invalid_national_stat";
|
||||
n["scorer_kind"] = action.at("value");
|
||||
} else
|
||||
return "invalid_national_action";
|
||||
if (!valid_national_ui(next))
|
||||
return "invalid_national_state";
|
||||
state = std::move(next);
|
||||
return {};
|
||||
} catch (const std::exception &) {
|
||||
return "invalid_national_action";
|
||||
}
|
||||
}
|
||||
Json query_national_ui(const Catalog &world, const Json &state,
|
||||
const std::string &menu) {
|
||||
if (!valid_national_ui(state))
|
||||
return {{"ok", false}, {"error", "invalid_national_state"}};
|
||||
const auto context = demo_career_context(state, world);
|
||||
if (context.at("role") != "national" || context.at("ended") == true)
|
||||
return {{"ok", false}, {"error", "national_context_changed"}};
|
||||
Json out = {{"ok", true},
|
||||
{"fictional", true},
|
||||
{"source", "ui-demo-unrecorded-national"},
|
||||
{"team", context.at("current_team")},
|
||||
{"manager", context.at("current_manager")},
|
||||
{"planning", state.at("national")},
|
||||
{"opponents", national_ui_opponents()},
|
||||
{"available_dates", national_ui_dates(state)},
|
||||
{"season", season(state)}};
|
||||
if (menu == "achievements") {
|
||||
out["tournaments"] =
|
||||
Json::array({{{"name", "Weltmeisterschaft"},
|
||||
{"gui_image", "trophy.world-cup"},
|
||||
{"titles", nullptr}},
|
||||
{{"name", "Europameisterschaft"},
|
||||
{"gui_image", "trophy.european-championship"},
|
||||
{"titles", nullptr}}});
|
||||
out["history"] = Json::array();
|
||||
} else if (menu == "scorers") {
|
||||
out["recorded_matches"] = 0;
|
||||
out["rows"] = Json::array();
|
||||
out["roster_basis_club"] = demo_career_manager(state).value("club", "");
|
||||
for (auto *p : world.squad(out.at("roster_basis_club").get<std::string>()))
|
||||
out["rows"].push_back({{"id", p->at("id")},
|
||||
{"name", world.name(*p)},
|
||||
{"position", p->value("positions", Json::array())},
|
||||
{"goals", nullptr},
|
||||
{"assists", nullptr},
|
||||
{"yellow", nullptr},
|
||||
{"red", nullptr},
|
||||
{"caps", attribute(*p, "caps")},
|
||||
{"catalog_international_goals",
|
||||
attribute(*p, "international_goals")}});
|
||||
} else if (menu != "friendlies")
|
||||
return {{"ok", false}, {"error", "unsupported_national_view"}};
|
||||
return out;
|
||||
}
|
||||
} // namespace bmh::modern_ui
|
||||
@@ -0,0 +1,12 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
#include "modern/ui/catalog.hpp"
|
||||
namespace bmh::modern_ui {
|
||||
const Json &national_ui_opponents();
|
||||
Json default_national_ui();
|
||||
bool migrate_national_ui(Json &);
|
||||
bool valid_national_ui(const Json &);
|
||||
Json national_ui_dates(const Json &);
|
||||
Json query_national_ui(const Catalog &, const Json &, const std::string &menu);
|
||||
std::string edit_national_ui(Json &, const Json &);
|
||||
} // namespace bmh::modern_ui
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "modern/ui/demo_almanac.hpp"
|
||||
#include "modern/ui/demo_calendar.hpp"
|
||||
#include "modern/ui/demo_career.hpp"
|
||||
#include "modern/ui/demo_national_ui.hpp"
|
||||
#include "modern/ui/demo_environment.hpp"
|
||||
#include "modern/ui/demo_finance.hpp"
|
||||
#include "modern/ui/demo_lineup.hpp"
|
||||
@@ -233,6 +234,7 @@ DemoSource::DemoSource(std::shared_ptr<const Catalog> catalog)
|
||||
throw editor::Error("Ungültige Saisonvorbereitung.");
|
||||
if (!migrate_demo_career(state_, *catalog_))
|
||||
throw editor::Error("invalid_demo_career");
|
||||
if(!migrate_national_ui(state_))throw editor::Error("invalid_demo_national");
|
||||
saved_ = state_;
|
||||
}
|
||||
Snapshot DemoSource::snapshot() const { return {revision_, catalog_, state_}; }
|
||||
@@ -251,7 +253,8 @@ ActionResult DemoSource::apply(const Action &action) {
|
||||
if(state_.value("career",Json::object()).value("ended",false)&&action.kind!="start")return {false,revision_,"career_ended"};
|
||||
auto next = state_;
|
||||
try {
|
||||
if (action.kind == "career") {
|
||||
if(action.kind=="national"){const auto error=edit_national_ui(next,action.value);if(!error.empty())return {false,revision_,error};
|
||||
} else if (action.kind == "career") {
|
||||
const auto previous_club = demo_career_manager(next).value("club", "");
|
||||
const auto old_view = demo_career_view(next);
|
||||
const auto error = edit_demo_career(next, action.value, *catalog_);
|
||||
@@ -552,6 +555,7 @@ Json DemoSource::load_data(Json data, bool saved) {
|
||||
throw editor::Error("invalid_demo_settings");
|
||||
if (!migrate_demo_opening(data, *catalog_))
|
||||
throw editor::Error("Ungültige oder inkonsistente Saisonvorbereitung.");
|
||||
if(!migrate_national_ui(data))throw editor::Error("invalid_demo_national");
|
||||
for (const auto &[id,view]:data.at("career_views").items()) {
|
||||
auto probe=data;probe["career_views"]=Json::object();probe["desktop"]=default_desktop();
|
||||
probe["managers"]=Json::array({{{"name","Vorschau"},{"club",id},{"portrait",0}}});
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
// 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<std::string>{"achievements", "scorers", "friendlies"}.contains(
|
||||
menu_) ||
|
||||
!popup_.empty())
|
||||
return false;
|
||||
const auto id =
|
||||
target ? target->GetAttribute<Rml::String>("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<std::string>();
|
||||
}
|
||||
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<std::string>{"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<int>("key_identifier", 0))
|
||||
: Rml::Input::KI_UNKNOWN;
|
||||
if (code == Rml::Input::KI_ESCAPE ||
|
||||
(type == "mouseup" && event.GetParameter<int>("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<int>("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;
|
||||
}
|
||||
@@ -0,0 +1,253 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
std::string App::render_national(const std::string &key) {
|
||||
const auto s = snap();
|
||||
const auto data = query_national_ui(*s.world, s.state, key);
|
||||
if (!data.value("ok", false))
|
||||
return "<p>Für diese Nationalansicht liegen keine Daten vor.</p>";
|
||||
const auto context = demo_career_context(s.state, *s.world);
|
||||
if (!national_dialog_.empty() &&
|
||||
(national_source_ != source_.get() || national_revision_ != s.revision ||
|
||||
national_portrait_ !=
|
||||
context.at("current_manager").value("portrait", 0))) {
|
||||
national_dialog_.clear();
|
||||
national_pending_.clear();
|
||||
}
|
||||
national_source_ = source_.get();
|
||||
national_revision_ = s.revision;
|
||||
national_portrait_ = context.at("current_manager").value("portrait", 0);
|
||||
if (national_menu_ != key) {
|
||||
national_dialog_.clear();
|
||||
national_pending_.clear();
|
||||
national_menu_ = key;
|
||||
}
|
||||
const auto &n = data.at("planning");
|
||||
const auto team = [&](const Json &t, int size = 62) {
|
||||
return "<span class=\"national-team-label\">" +
|
||||
img(t.value("gui_image", "career.national-de"), size,
|
||||
size * 72.0 / 62.0, false, false, 256) +
|
||||
"<span>" + esc(t.value("name", "Deutschland")) + "</span></span>";
|
||||
};
|
||||
const auto &opponents = national_ui_opponents();
|
||||
const auto find_opponent = [&](const std::string &id) -> Json {
|
||||
for (const auto &o : opponents)
|
||||
if (o.at("id") == id)
|
||||
return o;
|
||||
return Json::object();
|
||||
};
|
||||
const auto own =
|
||||
Json{{"name", "Deutschland"}, {"gui_image", "career.national-de"}};
|
||||
std::string body =
|
||||
"<div class=\"national-root\" id=\"national-underlay\"><header "
|
||||
"class=\"national-heading\">";
|
||||
if (key == "achievements") {
|
||||
body += "<h2><span>Erfolge der "
|
||||
"Nationalmannschaft</span></h2><p><span>Weltmeisterschaft und "
|
||||
"Europameisterschaft</span></p></header>";
|
||||
for (size_t i = 0; i < 2; ++i) {
|
||||
const auto &t = data.at("tournaments")[i];
|
||||
body += "<section class=\"national-cup\" style=\"" +
|
||||
rect(i * 1326, 150, 1286, 1450) +
|
||||
"\"><div class=\"national-cup-art\">" +
|
||||
img(t.at("gui_image"), 1200, 600, false, false, 1200) +
|
||||
"</div><h3>" + esc(t.at("name").get<std::string>()) +
|
||||
"</h3><strong>—</strong><p>Keine Turnierergebnisse in dieser "
|
||||
"POC-Karriere aufgezeichnet.</p></section>";
|
||||
}
|
||||
body += "<section "
|
||||
"class=\"national-history\"><h3>Turnierhistorie</h3><p>Noch keine "
|
||||
"abgeschlossene WM- oder EM-Teilnahme aufgezeichnet.</p></section>";
|
||||
} else if (key == "scorers") {
|
||||
body += "<h2><span>Spielerstatistiken</span></h2><p>" + team(own, 40) +
|
||||
"<span> · keine erfassten abgeschlossenen "
|
||||
"POC-Länderspiele</span></p></header><nav "
|
||||
"class=\"national-stat-tabs\" role=\"tablist\">";
|
||||
const std::array<const char *, 4> names = {"Tore", "Vorlagen",
|
||||
"Gelbe Karten", "Rote Karten"};
|
||||
const int kind = n.at("scorer_kind");
|
||||
for (int i = 0; i < 4; ++i)
|
||||
body +=
|
||||
btn("national-stat", names[size_t(i)], i == kind ? "selected" : "",
|
||||
"id=\"national-stat-" + std::to_string(i) + "\" data-id=\"" +
|
||||
std::to_string(i) + "\" role=\"tab\" aria-selected=\"" +
|
||||
(i == kind ? "true" : "false") + "\"");
|
||||
body += "</nav><div class=\"national-stat-scroll\" "
|
||||
"id=\"national-stat-scroll\"><div class=\"national-stat-row "
|
||||
"national-stat-head\"><span>Pl.</span><span>Spieler</"
|
||||
"span><span>Nationalmannschaft</span><span>" +
|
||||
std::string(names[size_t(kind)]) + "</span></div>";
|
||||
size_t row = 0;
|
||||
for (const auto &p : data.at("rows")) {
|
||||
const auto index = row++;
|
||||
body +=
|
||||
"<div class=\"national-stat-row\"><span>" +
|
||||
std::to_string(index + 1) + "</span>" +
|
||||
btn("national-player", esc(p.at("name").get<std::string>()),
|
||||
"national-player",
|
||||
"data-id=\"" + esc(p.at("id").get<std::string>()) +
|
||||
"\" id=\"national-player-" + std::to_string(index) + "\"") +
|
||||
team(own, 35) + "<span>—</span></div>";
|
||||
}
|
||||
body += "</div><p class=\"national-note\">POC-Kaderbasis des gewählten "
|
||||
"Managers, keine echte Nationalberufung. Fehlende Länderspielwerte "
|
||||
"und Vorlagen bleiben —.</p>";
|
||||
} else {
|
||||
const bool booking = n.at("stage") == "calendar";
|
||||
const auto opponent = find_opponent(n.at("opponent"));
|
||||
body += "<h2>" +
|
||||
std::string(booking ? team(own) + "<span>–</span>" + team(opponent)
|
||||
: "<span>Länderspiel vereinbaren</span>") +
|
||||
"</h2><p><span>" +
|
||||
(booking ? std::string(n.at("home") == true ? "Heimspiel"
|
||||
: "Auswärtsspiel") +
|
||||
" · Dummytermin auswählen"
|
||||
: "Gegner für die deutsche Nationalmannschaft wählen") +
|
||||
"</span></p></header>";
|
||||
if (!booking) {
|
||||
for (size_t i = 0; i < opponents.size(); ++i) {
|
||||
const auto &o = opponents[i];
|
||||
body += btn(
|
||||
"national-opponent",
|
||||
img(o.at("gui_image"), 160, 184, false, false, 384) + "<strong>" +
|
||||
esc(o.at("name").get<std::string>()) +
|
||||
"</strong><small>Stärke " +
|
||||
std::to_string(o.at("strength").get<int>()) + " · POC</small>",
|
||||
"national-opponent",
|
||||
"id=\"national-opponent-" + o.at("code").get<std::string>() +
|
||||
"\" data-id=\"" + o.at("id").get<std::string>() +
|
||||
"\" style=\"" +
|
||||
rect((i % 4) * 661.75, 150 + (i / 4) * 804.5, 626.75, 769.5) +
|
||||
"\"");
|
||||
}
|
||||
body += "<footer class=\"national-actions\">" +
|
||||
btn("national-list",
|
||||
"Vorgemerkte Spiele · " +
|
||||
std::to_string(n.at("friendlies").size()),
|
||||
{}, "id=\"national-list\"") +
|
||||
"</footer>";
|
||||
} else {
|
||||
using namespace std::chrono;
|
||||
const int season = data.at("season"), offset = n.at("month");
|
||||
const auto ym = year_month{year{season}, month{7}} + months{offset};
|
||||
const auto start = sys_days{ym / 1};
|
||||
const int count =
|
||||
int(unsigned(year_month_day{sys_days{ym / last}}.day())),
|
||||
lead = int(weekday{start}.iso_encoding()) - 1,
|
||||
weeks = (count + lead + 6) / 7;
|
||||
const std::array<const char *, 12> month_names = {
|
||||
"Januar", "Februar", "März", "April", "Mai", "Juni",
|
||||
"Juli", "August", "September", "Oktober", "November", "Dezember"};
|
||||
body += "<section class=\"national-month\"><header>" +
|
||||
btn("national-month", "‹", {},
|
||||
"id=\"national-month-prev\" data-id=\"" +
|
||||
std::to_string(offset - 1) + "\" " +
|
||||
(offset == 0 ? "disabled" : "")) +
|
||||
"<h3><span>" +
|
||||
std::string(month_names[unsigned(ym.month()) - 1]) + " " +
|
||||
std::to_string(int(ym.year())) + "</span></h3>" +
|
||||
btn("national-month", "›", {},
|
||||
"id=\"national-month-next\" data-id=\"" +
|
||||
std::to_string(offset + 1) + "\" " +
|
||||
(offset == 11 ? "disabled" : "")) +
|
||||
"</header>";
|
||||
const std::array<const char *, 7> weekdays = {"Mo", "Di", "Mi", "Do",
|
||||
"Fr", "Sa", "So"};
|
||||
const double cell_w = 195.46, gap = 18,
|
||||
cell_h = (1356.0 - (weeks - 1) * 18) / weeks;
|
||||
for (int i = 0; i < 7; ++i)
|
||||
body += "<span class=\"national-weekday\" style=\"" +
|
||||
rect(26 + i * (cell_w + gap), 124, cell_w, 50) + "\"><span>" +
|
||||
weekdays[size_t(i)] + "</span></span>";
|
||||
for (int d = 1; d <= count; ++d) {
|
||||
const auto date = year_month_day{ym / unsigned(d)};
|
||||
std::ostringstream iso;
|
||||
iso << int(date.year()) << '-' << std::setfill('0') << std::setw(2)
|
||||
<< unsigned(date.month()) << '-' << std::setw(2) << d;
|
||||
const auto value = iso.str();
|
||||
const int index = lead + d - 1;
|
||||
const auto &available = data.at("available_dates");
|
||||
const bool open = std::find(available.begin(), available.end(),
|
||||
value) != available.end();
|
||||
body +=
|
||||
btn("national-day", std::to_string(d),
|
||||
n.at("day") == value ? "national-day selected" : "national-day",
|
||||
"id=\"national-day-" + value + "\" data-id=\"" + value +
|
||||
"\" aria-pressed=\"" +
|
||||
(n.at("day") == value ? "true" : "false") + "\" style=\"" +
|
||||
rect(26 + (index % 7) * (cell_w + gap),
|
||||
192 + (index / 7) * (cell_h + 18), cell_w, cell_h) +
|
||||
"\" " + (open ? "" : "disabled"));
|
||||
}
|
||||
body += "</section><aside class=\"national-selection\"><h3>Deine "
|
||||
"Auswahl</h3><p>" +
|
||||
(n.at("day") == ""
|
||||
? std::string("Einen hervorgehobenen Dummytermin wählen.")
|
||||
: esc(n.at("day").get<std::string>())) +
|
||||
"</p><p>" + std::to_string(n.at("friendlies").size()) +
|
||||
" / 12 Spiele vorgemerkt</p><h4>Nur POC-Vormerkung</h4><p>Keine "
|
||||
"FIFA-Termine, keine Vereinstermine, keine Kostenbuchung.</p>";
|
||||
for (const auto &b : n.at("friendlies"))
|
||||
body +=
|
||||
"<p>" + esc(b.at("date").get<std::string>()) + " · " +
|
||||
esc(find_opponent(b.at("opponent")).at("name").get<std::string>()) +
|
||||
"</p>";
|
||||
body +=
|
||||
"</aside><footer class=\"national-actions\">" +
|
||||
btn("national-back", "Gegner ändern", {}, "id=\"national-back\"") +
|
||||
btn("national-list", "Vorgemerkte Spiele", {},
|
||||
"id=\"national-list\"") +
|
||||
btn("national-book", "Termin vormerken", {},
|
||||
"id=\"national-book\" " +
|
||||
std::string(n.at("day") == "" ||
|
||||
n.at("friendlies").size() >= 12
|
||||
? "disabled"
|
||||
: "")) +
|
||||
"</footer>";
|
||||
}
|
||||
}
|
||||
body += "</div>";
|
||||
if (!national_dialog_.empty()) {
|
||||
std::string title, content, actions;
|
||||
if (national_dialog_ == "venue") {
|
||||
title = "Austragungsort";
|
||||
content = team(find_opponent(national_pending_)) +
|
||||
"<p>Heimspiel oder Auswärtsspiel?</p>";
|
||||
actions = btn("national-home", "Heim", {}, "id=\"national-home\"") +
|
||||
btn("national-away", "Auswärts", {}, "id=\"national-away\"") +
|
||||
btn("national-close", "Abbrechen", {}, "id=\"national-close\"");
|
||||
} else if (national_dialog_ == "book") {
|
||||
title = "Länderspiel vormerken?";
|
||||
content = team(find_opponent(n.at("opponent"))) + "<p>" +
|
||||
esc(n.at("day").get<std::string>()) + " · " +
|
||||
(n.at("home") == true ? "Heimspiel" : "Auswärtsspiel") +
|
||||
" · reine POC-Vormerkung</p>";
|
||||
actions =
|
||||
btn("national-close", "Abbrechen", {}, "id=\"national-close\"") +
|
||||
btn("national-confirm", "Vormerken", {}, "id=\"national-confirm\"");
|
||||
} else if (national_dialog_ == "list") {
|
||||
title = "Vorgemerkte Länderspiele";
|
||||
for (const auto &b : n.at("friendlies"))
|
||||
content += "<p>" + esc(b.at("date").get<std::string>()) + " · " +
|
||||
team(find_opponent(b.at("opponent"))) + " · " +
|
||||
(b.at("home") == true ? "Heim" : "Auswärts") + "</p>";
|
||||
if (content.empty())
|
||||
content = "<p>Noch kein Länderspiel vorgemerkt.</p>";
|
||||
actions = btn("national-close", "Schließen", {}, "id=\"national-close\"");
|
||||
} else {
|
||||
title = "POC-Kaderbasis";
|
||||
for (const auto &p : data.value("rows", Json::array()))
|
||||
if (p.at("id") == national_pending_)
|
||||
content = "<h3>" + esc(p.at("name").get<std::string>()) +
|
||||
"</h3><p>Deutschland · keine echte Berufung</p><p>Im "
|
||||
"Datensatz erfasste Länderspiele: " +
|
||||
(p.at("caps").is_number() ? p.at("caps").dump() : "—") +
|
||||
"</p><p>Erfasste POC-Vorlagen: —</p>";
|
||||
actions = btn("national-close", "Schließen", {}, "id=\"national-close\"");
|
||||
}
|
||||
body += "<div id=\"national-dialog-layer\" class=\"entry-dialog-layer "
|
||||
"national-dialog-layer\"><section class=\"entry-dialog "
|
||||
"national-dialog\" role=\"dialog\" aria-modal=\"true\"><h2>" +
|
||||
title + "</h2>" + content + "<footer>" + actions +
|
||||
"</footer></section></div>";
|
||||
}
|
||||
return body;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
std::string national_dialog_, national_pending_, national_menu_,
|
||||
national_return_focus_;
|
||||
uint64_t national_revision_ = 0;
|
||||
int national_portrait_ = 0;
|
||||
const DataSource *national_source_ = nullptr;
|
||||
std::string render_national(const std::string &);
|
||||
bool national_action(const std::string &, Rml::Element *);
|
||||
bool national_event(Rml::Event &);
|
||||
@@ -167,7 +167,9 @@ std::string App::render_menu(const std::string &key) {
|
||||
if (key == "news")
|
||||
return "<div class=\"fill\" style=\"z-index:100;\">" + render_news() + "</div>";
|
||||
std::string body;
|
||||
if (key == "tables" || key == "strengths" || key == "league" || key == "other")
|
||||
if(source_ && snap().state.at("career").value("role","club")=="national" && std::set<std::string>{"achievements","friendlies","scorers"}.contains(key))
|
||||
body=render_national(key);
|
||||
else if (key == "tables" || key == "strengths" || key == "league" || key == "other")
|
||||
body = render_reports(key);
|
||||
else if (key == "almanac")
|
||||
body = render_almanac();
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "modern/ui/demo_lineup.hpp"
|
||||
#include "modern/ui/demo_live.hpp"
|
||||
#include "modern/ui/demo_career.hpp"
|
||||
#include "modern/ui/demo_national_ui.hpp"
|
||||
#include "modern/ui/demo_transfer.hpp"
|
||||
#include "modern/ui/demo_career_reports.hpp"
|
||||
#include "modern/ui/demo_rankings.hpp"
|
||||
@@ -452,6 +453,7 @@ class App final : public Rml::EventListener {
|
||||
#include "modern/ui/files_state.inc"
|
||||
#include "modern/ui/front_state.inc"
|
||||
#include "modern/ui/live_state.inc"
|
||||
#include "modern/ui/national_state.inc"
|
||||
std::map<std::string, std::string> selections_;
|
||||
Rml::Element *element(const std::string &id) const {
|
||||
return doc_->GetElementById(id);
|
||||
@@ -961,6 +963,7 @@ class App final : public Rml::EventListener {
|
||||
Rml::ElementList background;doc_->QuerySelectorAll(background,".desktop-layer button,.desktop-layer [data-action]");
|
||||
for(auto *node:background){node->SetProperty("pointer-events","none");node->SetAttribute("tabindex",-1);}
|
||||
}
|
||||
if(!national_dialog_.empty() && source_ && snap().state.at("career").value("role","club")=="national"){Rml::ElementList behind;doc_->QuerySelectorAll(behind,"#national-underlay button,#national-underlay select,.window>.titlebar button");for(auto *node:behind){node->SetProperty("pointer-events","none");node->SetAttribute("tabindex",-1);}}
|
||||
news_after_render();
|
||||
if (!report_detail_kind_.empty() || !planning_dialog_.empty() || !contracts_dialog_.empty() || !toto_dialog_.empty() || !transfer_dialog_.empty() || !career_view_.value("dialog", "").empty() || !stadium_view_.value("dialog", "").empty()) {
|
||||
Rml::ElementList behind;
|
||||
@@ -1412,6 +1415,8 @@ public:
|
||||
}
|
||||
};
|
||||
#include "modern/ui/entry_controls.inc"
|
||||
#include "modern/ui/national_screens.inc"
|
||||
#include "modern/ui/national_controls.inc"
|
||||
#include "modern/ui/career_screens.inc"
|
||||
#include "modern/ui/career_controls.inc"
|
||||
#include "modern/ui/entry_screens.inc"
|
||||
|
||||
Reference in new issue
Block a user