Complete Modern season preparation with persistent draw progress (by Codex)
This commit is contained in:
1 parent
967520190d
commit
e81ecf95f2
27 files changed
+1432
-208
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 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_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)
|
||||
add_library(bmh_modern_ui_core STATIC catalog.cpp model.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_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)
|
||||
@@ -26,7 +26,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 transfer.rcss career_reports.rcss rankings.rcss stadium.rcss statistics.rcss news.rcss settings.rcss widgets.rcss files.rcss front.rcss entry.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 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)
|
||||
configure_file("${CMAKE_SOURCE_DIR}/assets/modern/${asset}" "${modern_assets}/${asset}" COPYONLY)
|
||||
endforeach()
|
||||
|
||||
@@ -112,7 +112,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)
|
||||
foreach(component statistics news settings desktop files entry opening)
|
||||
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)
|
||||
|
||||
+14
-27
@@ -149,6 +149,7 @@ void App::ProcessEvent(Rml::Event &event) try {
|
||||
return;
|
||||
if(front_event(event))return;
|
||||
if (entry_event(event)) return;
|
||||
if (opening_event(event)) return;
|
||||
if (amount_event(event)) return;
|
||||
if (popup_.empty() && settings_event(event)) return;
|
||||
if (popup_.empty() && (files_event(event) || widget_event(event))) return;
|
||||
@@ -464,6 +465,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 (entry_action(action, target)) return;
|
||||
if (opening_action(action, target)) return;
|
||||
if (settings_action(action,target)) return;
|
||||
if (files_action(action,target) || widget_action(action,target)) return;
|
||||
if (lineup_action(action, target) || transfer_action(action, target)) return;
|
||||
@@ -674,33 +676,6 @@ void App::dispatch(const std::string &action, Rml::Element *target) {
|
||||
entry_begin();
|
||||
return;
|
||||
}
|
||||
if (action == "opening-play") {
|
||||
draw_playing_ = !draw_playing_;
|
||||
draw_at_ = SDL_GetTicks64() + 900;
|
||||
refresh();
|
||||
return;
|
||||
}
|
||||
if (action == "opening-next") {
|
||||
++opening_page_;
|
||||
if (opening_page_ == 3)
|
||||
draw_at_ = SDL_GetTicks64() + 900;
|
||||
refresh();
|
||||
return;
|
||||
}
|
||||
if (action == "opening-all") {
|
||||
draw_revealed_ = 64;
|
||||
opening_page_ = 4;
|
||||
refresh();
|
||||
return;
|
||||
}
|
||||
if (action == "opening-finish") {
|
||||
if (opening_page_ != 4)
|
||||
return;
|
||||
scene_ = "desktop";
|
||||
apply("opening", "complete");
|
||||
refresh();
|
||||
return;
|
||||
}
|
||||
if (action == "desktop-context") {
|
||||
context_menu({}, 0, 0);
|
||||
return;
|
||||
@@ -961,6 +936,18 @@ void App::script() {
|
||||
(command.value("shift", false) ? Rml::Input::KM_SHIFT : 0);
|
||||
context_->ProcessKeyDown(keys.at(name), mods);
|
||||
context_->ProcessKeyUp(keys.at(name), mods);
|
||||
} else if (type == "wait") {
|
||||
const int milliseconds = command.at("milliseconds").get<int>();
|
||||
if (milliseconds < 0 || milliseconds > 30000)
|
||||
throw editor::Error("UI-Wartezeit muss zwischen 0 und 30000 ms liegen.");
|
||||
const auto until = SDL_GetTicks64() + uint64_t(milliseconds);
|
||||
while (!closed_ && SDL_GetTicks64() < until) {
|
||||
pump_events();
|
||||
front_poll();
|
||||
opening_tick();
|
||||
frame();
|
||||
SDL_Delay(5);
|
||||
}
|
||||
} else if (type == "screenshot")
|
||||
screenshot(editor::path(command.at("path").get<std::string>()));
|
||||
else if (type == "checkpoint") {
|
||||
|
||||
@@ -0,0 +1,226 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/ui/demo_opening.hpp"
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
#include <set>
|
||||
|
||||
namespace bmh::modern_ui {
|
||||
namespace {
|
||||
bool integer(const Json &value, int low, int high) {
|
||||
if (!value.is_number_integer())
|
||||
return false;
|
||||
if (value.is_number_unsigned())
|
||||
return value.get<uint64_t>() >= uint64_t(low) &&
|
||||
value.get<uint64_t>() <= uint64_t(high);
|
||||
return value.get<int64_t>() >= low && value.get<int64_t>() <= high;
|
||||
}
|
||||
int tier(const Json *league) {
|
||||
const auto value = league->value("tier", Json());
|
||||
return integer(value, 0, 1000) ? value.get<int>()
|
||||
: std::numeric_limits<int>::max();
|
||||
}
|
||||
struct Participants {
|
||||
std::vector<std::string> pool;
|
||||
Json entrants = {{"uefa", Json::array()},
|
||||
{"champions", Json::array()},
|
||||
{"winners", Json::array()}};
|
||||
};
|
||||
Participants participants(const Catalog &world) {
|
||||
auto leagues = world.leagues("nation:de");
|
||||
// Tier determines the top available league; equal/missing tiers retain the
|
||||
// authored catalogue order, as do clubs within each league.
|
||||
std::stable_sort(
|
||||
leagues.begin(), leagues.end(),
|
||||
[](const auto *a, const auto *b) { return tier(a) < tier(b); });
|
||||
Participants result;
|
||||
std::set<std::string> used;
|
||||
bool top_found = false;
|
||||
for (const auto *league : leagues) {
|
||||
std::vector<std::string> clubs;
|
||||
for (const auto *club : world.clubs(league->value("id", ""))) {
|
||||
const auto id = club->value("id", "");
|
||||
if (world.manageable(id) && used.insert(id).second)
|
||||
clubs.push_back(id);
|
||||
}
|
||||
if (!top_found && !clubs.empty()) {
|
||||
top_found = true;
|
||||
for (size_t index = 0; index < clubs.size() && index < 6; ++index)
|
||||
result
|
||||
.entrants[index < 4 ? "uefa"
|
||||
: index == 4 ? "champions"
|
||||
: "winners"]
|
||||
.push_back(clubs[index]);
|
||||
}
|
||||
for (const auto &id : clubs)
|
||||
if (result.pool.size() < 64)
|
||||
result.pool.push_back(id);
|
||||
}
|
||||
// A tiny world gets real pairs only: do not duplicate a team or invent a bye.
|
||||
if (result.pool.size() % 2)
|
||||
result.pool.pop_back();
|
||||
return result;
|
||||
}
|
||||
bool valid(const Json &state, const Catalog &world) {
|
||||
if (!state.is_object() || !state.contains("opening_flow") ||
|
||||
!state.contains("opening") || !state.at("opening").is_string() ||
|
||||
!state.contains("opening_created") ||
|
||||
!state.at("opening_created").is_boolean())
|
||||
return false;
|
||||
const auto &flow = state.at("opening_flow");
|
||||
if (!flow.is_object() || flow.size() != 7 ||
|
||||
!integer(flow.at("schema"), 1, 1) || !flow.at("created").is_boolean() ||
|
||||
!flow.at("phase").is_string() || !flow.at("playing").is_boolean() ||
|
||||
!flow.at("order").is_array() || !flow.at("entrants").is_object())
|
||||
return false;
|
||||
const auto expected = participants(world);
|
||||
const auto &order = flow.at("order");
|
||||
if (order.size() != expected.pool.size() || order.size() > 64 ||
|
||||
order.size() % 2 || !integer(flow.at("revealed"), 0, int(order.size())) ||
|
||||
flow.at("entrants").size() != 3)
|
||||
return false;
|
||||
for (const auto *group : {"uefa", "champions", "winners"})
|
||||
if (!flow.at("entrants").contains(group) ||
|
||||
flow.at("entrants").at(group) != expected.entrants.at(group))
|
||||
return false;
|
||||
std::set<std::string> ids;
|
||||
for (const auto &id : order) {
|
||||
if (!id.is_string() || !ids.insert(id.get<std::string>()).second)
|
||||
return false;
|
||||
}
|
||||
if (ids != std::set<std::string>(expected.pool.begin(), expected.pool.end()))
|
||||
return false;
|
||||
const auto phase = flow.at("phase").get<std::string>();
|
||||
const bool created = flow.at("created").get<bool>(),
|
||||
playing = flow.at("playing").get<bool>();
|
||||
const int revealed = flow.at("revealed").get<int>();
|
||||
if (phase == "uefa" || phase == "champions" || phase == "winners") {
|
||||
if (revealed != 0 || playing)
|
||||
return false;
|
||||
} else if (phase == "draw") {
|
||||
if (order.empty() || revealed >= int(order.size()))
|
||||
return false;
|
||||
} else if (phase == "overview" || phase == "done") {
|
||||
if (revealed != int(order.size()) || playing)
|
||||
return false;
|
||||
} else
|
||||
return false;
|
||||
if (!created && phase != "done")
|
||||
return false;
|
||||
return state.at("opening").get<std::string>() ==
|
||||
(phase == "done" ? "complete" : "pending") &&
|
||||
state.at("opening_created").get<bool>() ==
|
||||
(phase == "done" && created);
|
||||
}
|
||||
} // namespace
|
||||
Json make_demo_opening(const Catalog &world, const Json & /*state*/,
|
||||
bool created) {
|
||||
auto data = participants(world);
|
||||
uint32_t seed = 20270701u;
|
||||
for (size_t count = data.pool.size(); count > 1; --count) {
|
||||
seed = seed * 1664525u + 1013904223u;
|
||||
std::swap(data.pool[count - 1], data.pool[size_t(seed) % count]);
|
||||
}
|
||||
return {{"schema", 1},
|
||||
{"created", created},
|
||||
{"phase", created ? "uefa" : "done"},
|
||||
{"revealed", created ? size_t(0) : data.pool.size()},
|
||||
{"playing", false},
|
||||
{"order", data.pool},
|
||||
{"entrants", data.entrants}};
|
||||
}
|
||||
bool migrate_demo_opening(Json &state, const Catalog &world) {
|
||||
try {
|
||||
if (!state.is_object())
|
||||
return false;
|
||||
auto next = state;
|
||||
if (!next.contains("opening"))
|
||||
next["opening"] = "complete";
|
||||
if (!next.contains("opening_created"))
|
||||
next["opening_created"] = false;
|
||||
if (!next.at("opening").is_string() ||
|
||||
!next.at("opening_created").is_boolean())
|
||||
return false;
|
||||
const auto phase = next.at("opening").get<std::string>();
|
||||
if (phase != "pending" && phase != "complete")
|
||||
return false;
|
||||
if (!next.contains("opening_flow")) {
|
||||
next["opening_flow"] = make_demo_opening(world, next, phase == "pending");
|
||||
if (phase == "complete")
|
||||
next["opening_flow"]["created"] = next.at("opening_created");
|
||||
}
|
||||
if (!valid(next, world))
|
||||
return false;
|
||||
state = std::move(next);
|
||||
return true;
|
||||
} catch (const std::exception &) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
std::string edit_demo_opening(Json &state, const Json &action,
|
||||
const Catalog &world) {
|
||||
try {
|
||||
if (!action.is_object() || action.size() != 1 || !action.contains("kind") ||
|
||||
!action.at("kind").is_string())
|
||||
return "Ungültige Aktion der Saisonvorbereitung.";
|
||||
auto next = state;
|
||||
if (!migrate_demo_opening(next, world))
|
||||
return "Die gespeicherte Saisonvorbereitung ist ungültig.";
|
||||
auto &flow = next.at("opening_flow");
|
||||
const auto kind = action.at("kind").get<std::string>(),
|
||||
phase = flow.at("phase").get<std::string>();
|
||||
const auto total = flow.at("order").size();
|
||||
if (kind == "next") {
|
||||
if (phase == "uefa")
|
||||
flow["phase"] = "champions";
|
||||
else if (phase == "champions")
|
||||
flow["phase"] = "winners";
|
||||
else if (phase == "winners") {
|
||||
flow["phase"] = total ? "draw" : "overview";
|
||||
flow["playing"] = total != 0;
|
||||
} else
|
||||
return "Weiter ist nur auf den ersten drei Vorbereitungsseiten "
|
||||
"möglich.";
|
||||
} else if (kind == "reveal") {
|
||||
if (phase != "draw" || !flow.at("playing").get<bool>())
|
||||
return "Die Auslosung läuft gerade nicht.";
|
||||
const auto count = flow.at("revealed").get<size_t>() + 1;
|
||||
flow["revealed"] = count;
|
||||
if (count == total) {
|
||||
flow["phase"] = "overview";
|
||||
flow["playing"] = false;
|
||||
}
|
||||
} else if (kind == "toggle" || kind == "pause") {
|
||||
if (phase != "draw")
|
||||
return "Nur eine laufende Auslosung kann pausiert oder fortgesetzt "
|
||||
"werden.";
|
||||
flow["playing"] =
|
||||
kind == "toggle" ? !flow.at("playing").get<bool>() : false;
|
||||
} else if (kind == "skip") {
|
||||
if (phase != "draw")
|
||||
return "Paarungen können nur während der Auslosung eingeblendet "
|
||||
"werden.";
|
||||
flow["revealed"] = total;
|
||||
flow["playing"] = false;
|
||||
flow["phase"] = "overview";
|
||||
} else if (kind == "finish") {
|
||||
if (phase != "overview" && phase != "done")
|
||||
return "Bitte zuerst die Paarungsübersicht öffnen.";
|
||||
flow["created"] = true;
|
||||
flow["phase"] = "done";
|
||||
flow["revealed"] = total;
|
||||
flow["playing"] = false;
|
||||
} else
|
||||
return "Unbekannte Aktion der Saisonvorbereitung.";
|
||||
const bool done = flow.at("phase").get<std::string>() == "done";
|
||||
next["opening"] = done ? "complete" : "pending";
|
||||
next["opening_created"] = done && flow.at("created").get<bool>();
|
||||
if (!valid(next, world))
|
||||
return "Die neue Saisonvorbereitung ist inkonsistent.";
|
||||
state = std::move(next);
|
||||
return {};
|
||||
} catch (const std::exception &) {
|
||||
return "Die Aktion der Saisonvorbereitung konnte nicht übernommen werden.";
|
||||
}
|
||||
}
|
||||
} // namespace bmh::modern_ui
|
||||
@@ -0,0 +1,13 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
#include "modern/ui/catalog.hpp"
|
||||
|
||||
namespace bmh::modern_ui {
|
||||
// Fictional UI participants, derived solely from the immutable catalogue.
|
||||
// No engine draw, actual qualification or gameplay random stream is involved.
|
||||
Json make_demo_opening(const Catalog &, const Json &state, bool created);
|
||||
// Missing legacy flows are migrated; existing inconsistent flows are rejected.
|
||||
// Both migration and edits leave the input untouched on rejection.
|
||||
bool migrate_demo_opening(Json &state, const Catalog &);
|
||||
std::string edit_demo_opening(Json &state, const Json &action, const Catalog &);
|
||||
} // namespace bmh::modern_ui
|
||||
@@ -448,9 +448,15 @@ Json report_match_rows(const Catalog &world, const Json &state, bool other) {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Json report_opening_pairs(const Catalog &world) {
|
||||
Json report_opening_pairs(const Catalog &world, const Json &flow) {
|
||||
std::vector<const Json *> pool;
|
||||
for (const auto *league : world.leagues("nation:de"))
|
||||
if (!flow.is_null()) {
|
||||
for (const auto &id : flow.at("order")) {
|
||||
const auto *club = world.find("clubs", id.get<std::string>());
|
||||
if (!club) throw editor::Error("unknown_demo_draw_club");
|
||||
pool.push_back(club);
|
||||
}
|
||||
} else for (const auto *league : world.leagues("nation:de"))
|
||||
for (const auto *club : world.clubs(league->at("id")))
|
||||
if (pool.size() < 64)
|
||||
pool.push_back(club);
|
||||
|
||||
@@ -21,9 +21,10 @@ 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.
|
||||
Json report_opening_pairs(const Catalog &);
|
||||
// Presentation-only opening pairs. A supplied persisted flow retains its exact
|
||||
// draw order; omitted flows preserve the legacy catalogue-order projection.
|
||||
// Goals remain null until a future runtime owns them.
|
||||
Json report_opening_pairs(const Catalog &, const Json &flow = Json());
|
||||
// A count (not a last index), always at least 1. Shared round state is clamped
|
||||
// on selection changes; non-league other previews deliberately use 34 rounds.
|
||||
int report_round_count(const Catalog &, const Json &, bool other = false);
|
||||
|
||||
@@ -81,7 +81,7 @@ void App::entry_begin() {
|
||||
? "desktop"
|
||||
: "main";
|
||||
entry_catalog_ = std::move(next);
|
||||
renderer_.world(entry_catalog_);
|
||||
bind_world(entry_catalog_);
|
||||
start_options_ = {{"duration", 5}, {"difficulty", 3}, {"players", 1},
|
||||
{"mode", 3}, {"league", true}, {"world", true}};
|
||||
adding_manager_ = false;
|
||||
@@ -100,7 +100,7 @@ void App::entry_add() {
|
||||
if (!source_)
|
||||
return;
|
||||
entry_catalog_.reset();
|
||||
renderer_.world(world_);
|
||||
bind_world(world_);
|
||||
entry_source_ = source_.get();
|
||||
entry_revision_ = snap().revision;
|
||||
managers_draft_ = snap().state.at("managers");
|
||||
@@ -125,7 +125,7 @@ void App::entry_add() {
|
||||
}
|
||||
void App::entry_cancel() {
|
||||
entry_catalog_.reset();
|
||||
renderer_.world(world_);
|
||||
bind_world(world_);
|
||||
manager_confirm_ = manager_success_ = manager_picker_ = false;
|
||||
club_search_.clear();
|
||||
scene_ = adding_manager_ ? "desktop" : entry_return_scene_;
|
||||
@@ -200,6 +200,7 @@ void App::entry_confirm() {
|
||||
result.error);
|
||||
return;
|
||||
}
|
||||
opening_write(*catalog, demo->snapshot().state, valid_desktop(desktop_) ? desktop_ : default_desktop());
|
||||
publish_world(catalog, std::move(demo));
|
||||
saved_desktop_ = Json::object();
|
||||
undo_.clear();
|
||||
@@ -208,9 +209,8 @@ void App::entry_confirm() {
|
||||
manager_confirm_ = false;
|
||||
entry_catalog_.reset();
|
||||
scene_ = start_options_.value("league", true) ? "opening" : "desktop";
|
||||
opening_page_ = draw_revealed_ = 0;
|
||||
draw_playing_ = true;
|
||||
draw_at_ = 0;
|
||||
opening_due_ = 0;
|
||||
opening_io_blocked_ = false;
|
||||
focus_after_render_.clear();
|
||||
}
|
||||
refresh();
|
||||
|
||||
@@ -0,0 +1,237 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
// Presentation-only automatic checkpoint. It neither replaces a user save nor
|
||||
// marks the game clean. The next state is written before the in-memory action
|
||||
// commits.
|
||||
fs::path App::opening_progress_path(const Catalog &catalog) const {
|
||||
const auto id = catalog.manifest().value("id", std::string("none"));
|
||||
return (config_.userdata.empty() ? root_ / "userdata" : config_.userdata) /
|
||||
"ui-demo" / content::sha256(id) / "opening-progress.json";
|
||||
}
|
||||
void App::opening_write(const Catalog &catalog, const Json &state,
|
||||
const Json &layout) {
|
||||
const auto path = opening_progress_path(catalog);
|
||||
const Json data = {{"schema", "openbmh-ui-opening@1"},
|
||||
{"world", catalog.manifest().value("id", "")},
|
||||
{"manifest", content::sha256(catalog.manifest().dump())},
|
||||
{"state", state},
|
||||
{"desktop", layout}};
|
||||
try {
|
||||
fs::create_directories(path.parent_path());
|
||||
editor::write_atomic(path, data.dump(2));
|
||||
} catch (const std::exception &) {
|
||||
throw editor::Error("Die Saisonvorbereitung konnte nicht gesichert werden. "
|
||||
"Bitte Schreibrechte prüfen und erneut versuchen.");
|
||||
}
|
||||
}
|
||||
bool App::opening_pending() const {
|
||||
if (!source_)
|
||||
return false;
|
||||
const auto state = snap().state;
|
||||
const auto &flow = state.at("opening_flow");
|
||||
return flow.at("created").get<bool>() && flow.at("phase") != "done";
|
||||
}
|
||||
void App::opening_restore_startup() {
|
||||
if (!gui_.available())
|
||||
return;
|
||||
if (!config_.state.empty()) {
|
||||
// Explicit loads supersede an older unfinished preparation of this world.
|
||||
if (source_ &&
|
||||
(opening_pending() || fs::exists(opening_progress_path(*world_))))
|
||||
opening_write(*world_, snap().state,
|
||||
valid_desktop(desktop_) ? desktop_ : default_desktop());
|
||||
if (opening_pending()) {
|
||||
scene_ = "opening";
|
||||
menu_.clear();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (scene_ != "main" && scene_ != "desktop" && scene_ != "opening")
|
||||
return;
|
||||
auto catalog = world_;
|
||||
try {
|
||||
if (!catalog) {
|
||||
auto *m = mod(active_mod_);
|
||||
if (!m || m->type != "Modern" || !m->error.empty())
|
||||
return;
|
||||
catalog = Catalog::open(m->file);
|
||||
}
|
||||
const auto path = opening_progress_path(*catalog);
|
||||
if (!fs::exists(path))
|
||||
return;
|
||||
if (fs::file_size(path) > 32 * 1024 * 1024)
|
||||
throw editor::Error("opening_progress_too_large");
|
||||
const auto data = Json::parse(editor::read_file(path));
|
||||
if (data.at("schema") != "openbmh-ui-opening@1" ||
|
||||
data.at("world") != catalog->manifest().at("id") ||
|
||||
data.at("manifest") != content::sha256(catalog->manifest().dump()) ||
|
||||
!valid_desktop(data.at("desktop")))
|
||||
throw editor::Error("invalid_opening_progress");
|
||||
auto demo = std::make_unique<DemoSource>(catalog);
|
||||
auto checkpoint = data.at("state");
|
||||
checkpoint["desktop"] = data.at("desktop");
|
||||
const auto layout = demo->load_data(std::move(checkpoint), false);
|
||||
const auto flow = demo->snapshot().state.at("opening_flow");
|
||||
if (!flow.at("created").get<bool>() || flow.at("phase") == "done")
|
||||
return;
|
||||
publish_world(catalog, std::move(demo));
|
||||
desktop_ = saved_desktop_ = layout;
|
||||
scene_ = "opening";
|
||||
menu_.clear();
|
||||
opening_due_ = 0;
|
||||
} catch (const std::exception &) {
|
||||
message("Die gesicherte Saisonvorbereitung konnte nicht geladen werden. "
|
||||
"Du kannst eine neue Partie beginnen oder einen Spielstand laden.");
|
||||
}
|
||||
}
|
||||
bool App::opening_change(const std::string &kind) {
|
||||
if (!source_)
|
||||
return false;
|
||||
const auto before = snap();
|
||||
auto next = before.state;
|
||||
const Json action = {{"kind", kind}};
|
||||
const auto error = edit_demo_opening(next, action, *world_);
|
||||
if (!error.empty())
|
||||
return false;
|
||||
try {
|
||||
opening_write(*world_, next,
|
||||
valid_desktop(desktop_) ? desktop_ : default_desktop());
|
||||
} catch (const std::exception &failure) {
|
||||
opening_io_blocked_ = true;
|
||||
opening_due_ = 0;
|
||||
message(failure.what());
|
||||
refresh();
|
||||
return false;
|
||||
}
|
||||
const auto applied =
|
||||
source_->apply({before.revision, "opening.flow", action});
|
||||
if (!applied.ok) {
|
||||
message("Die Vorbereitung hat sich geändert. Bitte erneut versuchen.");
|
||||
return false;
|
||||
}
|
||||
opening_due_ = 0;
|
||||
opening_io_blocked_ = false;
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
bool App::opening_action(const std::string &action, Rml::Element *) {
|
||||
if (scene_ != "opening" || !menu_.empty() || !popup_.empty())
|
||||
return false;
|
||||
if (action == "close")
|
||||
return true;
|
||||
std::string kind;
|
||||
if (action == "opening-next")
|
||||
kind = "next";
|
||||
else if (action == "opening-play")
|
||||
kind = opening_io_blocked_ &&
|
||||
snap().state.at("opening_flow").at("playing").get<bool>()
|
||||
? "reveal"
|
||||
: "toggle";
|
||||
else if (action == "opening-all")
|
||||
kind = "skip";
|
||||
else if (action == "opening-finish") {
|
||||
const auto phase =
|
||||
snap().state.at("opening_flow").at("phase").get<std::string>();
|
||||
if (phase == "done") {
|
||||
scene_ = "desktop";
|
||||
opening_due_ = 0;
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
kind = "finish";
|
||||
} else
|
||||
return false;
|
||||
if (!opening_change(kind))
|
||||
return true;
|
||||
const auto phase =
|
||||
snap().state.at("opening_flow").at("phase").get<std::string>();
|
||||
if (phase == "done") {
|
||||
scene_ = "desktop";
|
||||
focus_after_render_.clear();
|
||||
} else
|
||||
focus_after_render_ = phase == "overview" ? "opening-finish"
|
||||
: phase == "draw" ? "opening-play"
|
||||
: "opening-next";
|
||||
return true;
|
||||
}
|
||||
bool App::opening_event(Rml::Event &event) {
|
||||
if (scene_ != "opening" || !menu_.empty() || !popup_.empty())
|
||||
return false;
|
||||
if ((event.GetType() == "keydown" &&
|
||||
event.GetParameter<int>("key_identifier", 0) == Rml::Input::KI_ESCAPE) ||
|
||||
event.GetType() == "contextmenu" ||
|
||||
(event.GetType() == "mouseup" &&
|
||||
event.GetParameter<int>("button", 0) == 1)) {
|
||||
event.StopImmediatePropagation();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
void App::opening_tick() {
|
||||
if (scene_ != "opening" || !source_ || !menu_.empty() || !popup_.empty() ||
|
||||
opening_io_blocked_)
|
||||
return;
|
||||
const auto flow = snap().state.at("opening_flow");
|
||||
if (flow.at("phase") != "draw" || !flow.at("playing").get<bool>()) {
|
||||
opening_due_ = 0;
|
||||
return;
|
||||
}
|
||||
if (!(SDL_GetWindowFlags(video_.window) & SDL_WINDOW_INPUT_FOCUS)) {
|
||||
opening_change("pause");
|
||||
return;
|
||||
}
|
||||
const auto now = SDL_GetTicks64();
|
||||
if (!opening_due_)
|
||||
opening_due_ = now + 900;
|
||||
if (now < opening_due_)
|
||||
return;
|
||||
if (opening_change("reveal")) {
|
||||
if (snap().state.at("opening_flow").at("phase") == "overview")
|
||||
focus_after_render_ = "opening-finish";
|
||||
opening_due_ = SDL_GetTicks64() + 900;
|
||||
}
|
||||
}
|
||||
void App::handle_event(SDL_Event &event) {
|
||||
if (event.type == SDL_QUIT) {
|
||||
if (front_busy_) {
|
||||
front_feedback_ = "Bitte den laufenden Import abwarten.";
|
||||
dirty_ = true;
|
||||
} else if (source_ && scene_ != "main" && scene_ != "mods") {
|
||||
quit_closes_app_ = true;
|
||||
dispatch("context-quit", nullptr);
|
||||
} else
|
||||
closed_ = true;
|
||||
return;
|
||||
}
|
||||
if (event.type == SDL_WINDOWEVENT) {
|
||||
if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST) {
|
||||
desktop_cancel_drag();
|
||||
if (scene_ == "opening" && source_ && !opening_io_blocked_ &&
|
||||
snap().state.at("opening_flow").at("phase") == "draw" &&
|
||||
snap().state.at("opening_flow").at("playing").get<bool>())
|
||||
opening_change("pause");
|
||||
}
|
||||
resize();
|
||||
}
|
||||
int w, h, pw, ph;
|
||||
SDL_GetWindowSize(video_.window, &w, &h);
|
||||
video_.drawable_size(pw, ph);
|
||||
if (w > 0 && h > 0) {
|
||||
if (event.type == SDL_MOUSEMOTION) {
|
||||
event.motion.x = int(double(event.motion.x) * pw / w);
|
||||
event.motion.y = int(double(event.motion.y) * ph / h);
|
||||
}
|
||||
if (event.type == SDL_MOUSEBUTTONDOWN || event.type == SDL_MOUSEBUTTONUP) {
|
||||
event.button.x = int(double(event.button.x) * pw / w);
|
||||
event.button.y = int(double(event.button.y) * ph / h);
|
||||
context_->ProcessMouseMove(event.button.x, event.button.y,
|
||||
RmlSDL::GetKeyModifierState());
|
||||
}
|
||||
}
|
||||
RmlSDL::InputEventHandler(context_, video_.window, event);
|
||||
dirty_ = true;
|
||||
}
|
||||
void App::pump_events() {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event))
|
||||
handle_event(event);
|
||||
}
|
||||
@@ -0,0 +1,259 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
// Read-only presentation of canonical DemoSource opening_flow. No extra App
|
||||
// API. Timer, phase changes, persistence, keyboard handling and completion
|
||||
// belong to the controller. No participants or pairings are invented by the
|
||||
// renderer.
|
||||
std::string App::render_opening() {
|
||||
const auto state = snap().state;
|
||||
const auto &flow = state.at("opening_flow");
|
||||
const auto phase = flow.at("phase").get<std::string>();
|
||||
const bool playing = flow.value("playing", false) && !opening_io_blocked_;
|
||||
std::set<std::string> own;
|
||||
for (const auto &m : state.at("managers"))
|
||||
own.insert(m.value("club", ""));
|
||||
std::vector<const Json *> order;
|
||||
std::set<std::string> seen;
|
||||
for (const auto &id : flow.at("order")) {
|
||||
if (!id.is_string())
|
||||
continue;
|
||||
const auto key = id.get<std::string>();
|
||||
if (const auto *c = world_->find("clubs", key);
|
||||
c && seen.insert(key).second)
|
||||
order.push_back(c);
|
||||
}
|
||||
const int total = int(order.size()), pairs = total / 2;
|
||||
const int revealed = std::clamp(flow.value("revealed", 0), 0, total);
|
||||
const auto date = state.value(
|
||||
"date", world_->manifest().value("start_date", std::string()));
|
||||
std::string season = "–";
|
||||
if (date.size() >= 4 &&
|
||||
std::all_of(date.begin(), date.begin() + 4,
|
||||
[](char c) { return c >= '0' && c <= '9'; })) {
|
||||
const int year = std::stoi(date.substr(0, 4));
|
||||
const int following = (year + 1) % 100;
|
||||
season = std::to_string(year) + "/" + (following < 10 ? "0" : "") +
|
||||
std::to_string(following);
|
||||
}
|
||||
const auto owned = [&](const Json *c) {
|
||||
return c && own.contains(c->value("id", ""));
|
||||
};
|
||||
const auto heading = [&](const std::string &title,
|
||||
const std::string &subtitle,
|
||||
const std::string &detail) {
|
||||
return "<header class=\"opening-heading\"><div><h2><span>" + esc(title) +
|
||||
"</span></h2><p><span>" + esc(subtitle) +
|
||||
"</span></p></div>"
|
||||
"<span class=\"opening-heading-detail\">" +
|
||||
esc(detail) + "</span></header>";
|
||||
};
|
||||
const auto note = [](const std::string &text) {
|
||||
return "<span class=\"opening-demo-note\">" + esc(text) + "</span>";
|
||||
};
|
||||
const auto pair = [&](int index, int known, int logo_size,
|
||||
const std::string &extra) {
|
||||
if (index < 0 || index >= pairs)
|
||||
return std::string();
|
||||
const auto *home = order[size_t(index * 2)],
|
||||
*away = order[size_t(index * 2 + 1)];
|
||||
const auto side = [&](const Json *c, bool home_side, bool visible) {
|
||||
const auto name = visible ? world_->name(*c)
|
||||
: home_side ? "Heim"
|
||||
: "Noch nicht gezogen";
|
||||
const auto text = "<span class=\"opening-pair-name " +
|
||||
std::string(visible ? "" : "opening-unknown") +
|
||||
"\" title=\"" + esc(name) + "\"><span>" + esc(name) +
|
||||
"</span></span>";
|
||||
const auto logo = visible ? "<span class=\"opening-pair-crest\">" +
|
||||
crest(c, logo_size) + "</span>"
|
||||
: "";
|
||||
return "<span class=\"opening-pair-side " +
|
||||
std::string(home_side ? "home" : "away") + "\">" +
|
||||
(home_side ? text + logo : logo + text) + "</span>";
|
||||
};
|
||||
return "<div class=\"opening-pair-row " + extra +
|
||||
(owned(home) || owned(away) ? " own-pair" : "") +
|
||||
"\" data-index=\"" + std::to_string(index) + "\" data-home=\"" +
|
||||
esc(home->value("id", "")) + "\" data-away=\"" +
|
||||
esc(away->value("id", "")) +
|
||||
"\">"
|
||||
"<span class=\"opening-pair-number\"><span>" +
|
||||
std::to_string(index + 1) + "</span></span>" +
|
||||
side(home, true, known > 0) +
|
||||
"<span class=\"opening-pair-versus\"><span>–</span></span>" +
|
||||
side(away, false, known > 1) +
|
||||
"<span class=\"opening-pair-counter\" "
|
||||
"aria-hidden=\"true\"></span></div>";
|
||||
};
|
||||
const bool entrants_page =
|
||||
phase == "uefa" || phase == "champions" || phase == "winners";
|
||||
std::string body, titlebar;
|
||||
if (entrants_page) {
|
||||
const int page = phase == "uefa" ? 0 : phase == "champions" ? 1 : 2;
|
||||
const std::array<const char *, 3> titles = {"UEFA-Cup", "Champions League",
|
||||
"Europapokal der Pokalsieger"};
|
||||
std::vector<const Json *> entrants;
|
||||
std::set<std::string> entered;
|
||||
const auto &ids = flow.at("entrants").at(phase);
|
||||
for (const auto &id : ids) {
|
||||
if (!id.is_string())
|
||||
continue;
|
||||
const auto key = id.get<std::string>();
|
||||
if (const auto *c = world_->find("clubs", key);
|
||||
c && entered.insert(key).second)
|
||||
entrants.push_back(c);
|
||||
}
|
||||
const bool german =
|
||||
!entrants.empty() &&
|
||||
std::all_of(entrants.begin(), entrants.end(), [](const auto *c) {
|
||||
return c->value("nation", "") == "nation:de";
|
||||
});
|
||||
titlebar = german ? "Deutsche Teams" : "Teilnehmende Teams";
|
||||
body = "<section class=\"opening-layout opening-entrants\" data-phase=\"" +
|
||||
phase + "\">" +
|
||||
heading(titles[size_t(page)], titlebar + " · Saison " + season,
|
||||
std::to_string(page + 1) + " / 3") +
|
||||
"<div class=\"opening-entrant-grid\" id=\"opening-entrants\">";
|
||||
if (entrants.empty()) {
|
||||
body += "<div class=\"opening-empty-entrants\"><h3><span>Keine "
|
||||
"Teilnehmer eingetragen</span></h3>"
|
||||
"<p><span>Für diesen Wettbewerb sind in dieser Demo-Welt keine "
|
||||
"Vereine vorgesehen.</span></p></div>";
|
||||
} else {
|
||||
const bool single = entrants.size() == 1;
|
||||
const auto card = [&](const Json *c) {
|
||||
return "<article class=\"opening-entrant " +
|
||||
std::string(single ? "single-entrant " : "") +
|
||||
(owned(c) ? "own-entrant" : "") + "\" data-entrant-club=\"" +
|
||||
esc(c->value("id", "")) + "\">" +
|
||||
"<div class=\"opening-entrant-crest\">" +
|
||||
crest(c, single ? 620 : 360) +
|
||||
"</div>"
|
||||
"<h3><span>" +
|
||||
esc(world_->name(*c)) + "</span></h3>" +
|
||||
(owned(c) ? "<p><span>Dein Verein</span></p>" : "") +
|
||||
"</article>";
|
||||
};
|
||||
body += "<div class=\"opening-entrant-content " +
|
||||
std::string(single ? "single-entrant-content" : "") + "\">";
|
||||
if (single) {
|
||||
body += card(entrants.front());
|
||||
} else {
|
||||
const size_t rows = std::max(size_t(2), (entrants.size() + 1) / 2);
|
||||
for (size_t row = 0; row < rows; ++row) {
|
||||
body += "<div class=\"opening-entrant-row\">";
|
||||
for (size_t column = 0; column < 2; ++column) {
|
||||
const size_t index = row * 2 + column;
|
||||
body += index < entrants.size()
|
||||
? card(entrants[index])
|
||||
: "<div class=\"opening-entrant-spacer\" "
|
||||
"aria-hidden=\"true\"></div>";
|
||||
}
|
||||
body += "</div>";
|
||||
}
|
||||
}
|
||||
body += "</div>";
|
||||
}
|
||||
body += "</div><nav class=\"opening-actions\">" +
|
||||
note("Fiktive Demo-Qualifikation") +
|
||||
btn("opening-next", "Weiter", {}, "id=\"opening-next\"") +
|
||||
"</nav></section>";
|
||||
} else if (phase == "draw") {
|
||||
titlebar = "DFB-Pokal";
|
||||
body =
|
||||
"<section class=\"opening-layout opening-draw\" data-phase=\"draw\">" +
|
||||
heading("1. Runde", "DFB-Pokal · Saison " + season,
|
||||
std::to_string(revealed) + " / " + std::to_string(total) +
|
||||
" Mannschaften") +
|
||||
"<div class=\"opening-draw-scene " +
|
||||
std::string(playing ? "is-drawing" : "") + "\">";
|
||||
const auto art = renderer_.image("art.cup-draw-v1.png", false, 1800);
|
||||
if (!art.token.empty() && art.width > 0 && art.height > 0) {
|
||||
const double ratio = double(art.width) / art.height;
|
||||
const double width = std::min(2608.0, 846.0 * ratio),
|
||||
height = width / ratio;
|
||||
body += "<div class=\"opening-draw-art\" role=\"img\" "
|
||||
"aria-label=\"Fiktive Pokal-Auslosung am Tisch mit Glaskugel, "
|
||||
"Loszieher und Pressefotografen\" style=\"width:" +
|
||||
scalar(width) + "dp;height:" + scalar(height) + "dp;\">" +
|
||||
picture(art, width, height, false) + "</div>";
|
||||
} else {
|
||||
body += "<p class=\"opening-art-missing\"><span>Die Illustration der "
|
||||
"Auslosung ist nicht verfügbar.</span></p>";
|
||||
}
|
||||
body +=
|
||||
"<span id=\"opening-draw-indicator\" class=\"opening-draw-indicator " +
|
||||
std::string(playing ? "is-playing" : "is-paused") +
|
||||
"\" aria-hidden=\"true\"></span></div>"
|
||||
"<div id=\"opening-current-pair\" class=\"opening-current-pair\" "
|
||||
"aria-live=\"polite\" aria-atomic=\"true\">";
|
||||
if (pairs) {
|
||||
const int current = std::min(pairs - 1, std::max(0, (revealed - 1) / 2));
|
||||
const int known = std::clamp(revealed - current * 2, 0, 2);
|
||||
body += pair(current, known, 66, "current") +
|
||||
"</div><section class=\"opening-recent\" aria-label=\"Zuletzt "
|
||||
"gezogene Paarungen\">";
|
||||
const int first = std::max(0, current - 3);
|
||||
for (int i = first; i < current; ++i)
|
||||
body += "<div class=\"opening-recent-row\" style=\"top:" +
|
||||
std::to_string((i - first) * 181) + "dp;\">" +
|
||||
pair(i, 2, 42, "recent") + "</div>";
|
||||
body += "</section>";
|
||||
} else {
|
||||
body += "<p class=\"opening-no-pairs\"><span>Für diese Welt ist keine "
|
||||
"vollständige Paarung vorhanden.</span></p></div>";
|
||||
}
|
||||
body +=
|
||||
"<nav class=\"opening-actions\">" +
|
||||
note(total % 2
|
||||
? "Fiktive Demo-Auslosung · 1 Verein ohne vollständige Paarung"
|
||||
: "Fiktive Demo-Auslosung") +
|
||||
btn("opening-play",
|
||||
opening_io_blocked_ ? "Erneut versuchen"
|
||||
: playing ? "Pause"
|
||||
: "Fortsetzen",
|
||||
{},
|
||||
"id=\"opening-play\" aria-pressed=\"" +
|
||||
std::string(playing ? "true" : "false") + "\" " +
|
||||
(revealed >= total ? "disabled" : "")) +
|
||||
btn("opening-all", "Alle Paarungen anzeigen", {},
|
||||
"id=\"opening-all\"") +
|
||||
"</nav></section>";
|
||||
} else {
|
||||
titlebar = "DFB-Pokal";
|
||||
body = "<section class=\"opening-layout opening-overview\" data-phase=\"" +
|
||||
esc(phase) + "\">" +
|
||||
heading("DFB-Pokal", "1. Runde · Saison " + season,
|
||||
std::to_string(pairs) +
|
||||
(pairs == 1 ? " Paarung" : " Paarungen")) +
|
||||
"<div id=\"opening-overview\" class=\"opening-pair-columns\">";
|
||||
if (!pairs) {
|
||||
body += "<div class=\"opening-empty-overview\"><p><span>Für diese Welt "
|
||||
"sind keine vollständigen Paarungen vorhanden.</span></p></div>";
|
||||
} else {
|
||||
const int columns = pairs > 1 ? 2 : 1,
|
||||
per_column = (pairs + columns - 1) / columns;
|
||||
for (int column = 0; column < columns; ++column) {
|
||||
const int first = column * per_column,
|
||||
last = std::min(pairs, first + per_column);
|
||||
body += "<section class=\"opening-overview-column " +
|
||||
std::string(columns == 1 ? "single-column" : "") +
|
||||
"\" aria-label=\"Paarungen " + std::to_string(first + 1) +
|
||||
" bis " + std::to_string(last) +
|
||||
"\" style=\"left:" + std::to_string(column * 1323) +
|
||||
"dp;\"><div class=\"opening-overview-list\">";
|
||||
for (int i = first; i < last; ++i)
|
||||
body += "<div class=\"opening-overview-row\">" +
|
||||
pair(i, 2, 36, "compact") + "</div>";
|
||||
body += "</div></section>";
|
||||
}
|
||||
}
|
||||
body += "</div><nav class=\"opening-actions\">" +
|
||||
note(total % 2 ? "Fiktive Demo-Auslosung · ohne Paarung: " +
|
||||
world_->name(*order.back())
|
||||
: "Fiktive Demo-Auslosung") +
|
||||
btn("opening-finish", "Weiter zum Desktop", "primary",
|
||||
"id=\"opening-finish\"") +
|
||||
"</nav></section>";
|
||||
}
|
||||
return window(titlebar, body, false);
|
||||
}
|
||||
@@ -247,8 +247,13 @@ void App::files_load() {
|
||||
if (!files_bound())
|
||||
throw editor::Error("Die aktive Karriere wurde inzwischen geändert.");
|
||||
const auto selected_id = files_entry_->id, selected_name = files_entry_->name;
|
||||
if (next->snapshot().state.at("opening_flow").at("phase") != "done" ||
|
||||
fs::exists(opening_progress_path(*world_)))
|
||||
opening_write(*world_, next->snapshot().state, layout);
|
||||
ticket_.reset();
|
||||
source_ = std::move(next);
|
||||
opening_due_ = 0;
|
||||
opening_io_blocked_ = false;
|
||||
desktop_ = std::move(layout);
|
||||
saved_desktop_ = desktop_;
|
||||
reset_files();
|
||||
|
||||
@@ -3,7 +3,7 @@ void App::front_invalidate_world() {
|
||||
ticket_.reset();
|
||||
source_.reset();
|
||||
world_.reset();
|
||||
renderer_.world(nullptr);
|
||||
bind_world(nullptr);
|
||||
reset_files();
|
||||
reset_settings();
|
||||
reset_news();
|
||||
|
||||
+25
-6
@@ -7,6 +7,7 @@
|
||||
#include "modern/ui/demo_finance.hpp"
|
||||
#include "modern/ui/demo_lineup.hpp"
|
||||
#include "modern/ui/demo_news.hpp"
|
||||
#include "modern/ui/demo_opening.hpp"
|
||||
#include "modern/ui/demo_reports.hpp"
|
||||
#include "modern/ui/demo_settings.hpp"
|
||||
#include "modern/ui/demo_sports.hpp"
|
||||
@@ -226,6 +227,8 @@ DemoSource::DemoSource(std::shared_ptr<const Catalog> catalog)
|
||||
throw editor::Error("invalid_demo_news");
|
||||
if (!migrate_demo_settings(state_))
|
||||
throw editor::Error("invalid_demo_settings");
|
||||
if (!migrate_demo_opening(state_, *catalog_))
|
||||
throw editor::Error("Ungültige Saisonvorbereitung.");
|
||||
saved_ = state_;
|
||||
}
|
||||
Snapshot DemoSource::snapshot() const { return {revision_, catalog_, state_}; }
|
||||
@@ -294,6 +297,7 @@ ActionResult DemoSource::apply(const Action &action) {
|
||||
? "pending"
|
||||
: "complete";
|
||||
next["opening_created"] = false;
|
||||
next["opening_flow"] = make_demo_opening(*catalog_, next, action.value.at("setup").at("league").get<bool>());
|
||||
}
|
||||
} else if (action.kind == "environment" || action.kind == "advertising" ||
|
||||
action.kind == "toto") {
|
||||
@@ -364,12 +368,25 @@ ActionResult DemoSource::apply(const Action &action) {
|
||||
next["camp"]["focus"] = action.value;
|
||||
} else if (action.kind == "camp.remember")
|
||||
next["camp"]["confirmed"] = next["camp"]["selected"];
|
||||
else if (action.kind == "opening") {
|
||||
if (!action.value.is_string())
|
||||
else if (action.kind == "opening.flow") {
|
||||
const auto error = edit_demo_opening(next, action.value, *catalog_);
|
||||
if (!error.empty()) return {false, revision_, error};
|
||||
} else if (action.kind == "opening") {
|
||||
if (!action.value.is_string() ||
|
||||
(action.value.get<std::string>() != "complete" && action.value.get<std::string>() != "pending"))
|
||||
return {false, revision_, "invalid_opening_state"};
|
||||
next["opening"] = action.value;
|
||||
if (action.value == "complete")
|
||||
if (!migrate_demo_opening(next, *catalog_)) return {false, revision_, "Ungültige gespeicherte Saisonvorbereitung."};
|
||||
if (action.value.get<std::string>() == "complete") {
|
||||
// Old callers may finish directly, without stepping the new UI flow.
|
||||
auto &flow = next.at("opening_flow");
|
||||
flow["created"] = true; flow["phase"] = "done";
|
||||
flow["revealed"] = flow.at("order").size(); flow["playing"] = false;
|
||||
next["opening"] = "complete";
|
||||
next["opening_created"] = true;
|
||||
} else {
|
||||
next["opening"] = "pending"; next["opening_created"] = false;
|
||||
next["opening_flow"] = make_demo_opening(*catalog_, next, true);
|
||||
}
|
||||
} else if (action.kind == "preferences") {
|
||||
if (!preferences(action.value))
|
||||
return {false, revision_, "invalid_preferences"};
|
||||
@@ -405,7 +422,7 @@ bool DemoSource::mark_saved(uint64_t expected_revision) {
|
||||
saved_ = state_;
|
||||
return true;
|
||||
}
|
||||
Json DemoSource::load_data(Json data) {
|
||||
Json DemoSource::load_data(Json data, bool saved) {
|
||||
if (data.value("schema", "") != "openbmh-ui-demo@1" ||
|
||||
data.value("world", "") != catalog_->manifest().value("id", ""))
|
||||
throw editor::Error("wrong_demo_world");
|
||||
@@ -471,13 +488,15 @@ Json DemoSource::load_data(Json data) {
|
||||
throw editor::Error("invalid_demo_news");
|
||||
if (!migrate_demo_settings(data))
|
||||
throw editor::Error("invalid_demo_settings");
|
||||
if (!migrate_demo_opening(data, *catalog_))
|
||||
throw editor::Error("Ungültige oder inkonsistente Saisonvorbereitung.");
|
||||
auto next = data;
|
||||
auto desktop = next.value("desktop", Json::object());
|
||||
if (!migrate_desktop(desktop))
|
||||
throw editor::Error("invalid_demo_desktop");
|
||||
next.erase("desktop");
|
||||
state_ = std::move(next);
|
||||
saved_ = state_;
|
||||
if (saved) saved_ = state_;
|
||||
++revision_;
|
||||
return desktop;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,8 @@ public:
|
||||
Json read_statistics(const Json &) const override;
|
||||
void save(const fs::path &, const Json &desktop);
|
||||
Json load(const fs::path &);
|
||||
Json load_data(Json);
|
||||
// UI continuation may retain the previous explicit-save clean baseline.
|
||||
Json load_data(Json, bool saved = true);
|
||||
bool mark_saved(uint64_t expected_revision);
|
||||
bool dirty() const { return state_ != saved_; }
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ std::string App::render_reports(const std::string &mode) {
|
||||
const bool strengths = mode == "strengths", matches = mode == "league" || mode == "other";
|
||||
const bool opening = mode == "other" && state.value("competition", 0) == 3 &&
|
||||
snapshot.state.value("opening_created", false);
|
||||
const auto rows = matches ? (opening ? report_opening_pairs(*world_)
|
||||
const auto rows = matches ? (opening ? report_opening_pairs(*world_, snapshot.state.at("opening_flow"))
|
||||
: report_match_rows(*world_, state, mode == "other"))
|
||||
: strengths ? report_strength_rows(*world_, state)
|
||||
: report_table_rows(*world_, state);
|
||||
|
||||
@@ -72,108 +72,6 @@ std::string App::render_desktop() {
|
||||
}
|
||||
return out + "</div>";
|
||||
}
|
||||
std::string App::render_opening() {
|
||||
const std::array<const char *, 3> names = {"UEFA-Cup", "Champions League",
|
||||
"Europapokal der Pokalsieger"};
|
||||
const auto german = world_->clubs("comp:de-1");
|
||||
std::vector<const Json *> pool;
|
||||
for (auto *l : world_->leagues("nation:de"))
|
||||
for (auto *c : world_->clubs(l->value("id", "")))
|
||||
if (pool.size() < 64)
|
||||
pool.push_back(c);
|
||||
std::string body;
|
||||
if (opening_page_ < 3) {
|
||||
body = "<h2 style=\"font-size:46dp;\">" +
|
||||
std::string(names[size_t(opening_page_)]) +
|
||||
"</h2><p class=\"small\" style=\"margin-top:16dp;\">Deutsche Teams "
|
||||
"· Saison " +
|
||||
esc(snap().state.value("date", std::string()).substr(0, 4)) + "</p>";
|
||||
const int count = opening_page_ == 0 ? 4 : 1;
|
||||
for (int i = 0; i < count && size_t(i) < german.size(); ++i) {
|
||||
const auto *c = german[size_t((i + opening_page_) % int(german.size()))];
|
||||
const bool single = count == 1;
|
||||
const int x = single ? 704 : 150 + (i % 2) * 1178,
|
||||
y = single ? 360 : 180 + (i / 2) * 730;
|
||||
body += "<div class=\"panel center\" style=\"position:absolute;" +
|
||||
rect(x, y, single ? 1200 : 1128, single ? 1000 : 680) +
|
||||
"padding:65dp;\">" + crest(c, single ? 620 : 360) +
|
||||
"<h3 style=\"margin-top:26dp;font-size:" +
|
||||
std::to_string(single ? 64 : 50) + "dp;font-weight:normal;\">" +
|
||||
esc(world_->name(*c)) + "</h3></div>";
|
||||
}
|
||||
body +=
|
||||
"<div class=\"bottom-controls\" style=\"justify-content:flex-end;\">" +
|
||||
btn("opening-next", "Weiter", "primary",
|
||||
"style=\"flex:none;width:390dp;\"") +
|
||||
"</div>";
|
||||
} else {
|
||||
const auto pair = [&](int index, int known, int size) {
|
||||
const size_t a = size_t(index * 2), b = a + 1;
|
||||
if (b >= pool.size())
|
||||
return std::string();
|
||||
const auto label_for = [&](const Json *c, bool home, bool visible) {
|
||||
const auto text = "<span class=\"opening-pair-name\">" +
|
||||
(visible ? esc(world_->name(*c)) : home ? "Heim" : "Noch nicht gezogen") + "</span>";
|
||||
const auto logo = visible ? crest(c, size) : "";
|
||||
return "<span class=\"opening-pair-side " + std::string(home ? "home" : "away") + "\">" +
|
||||
(home ? text + logo : logo + text) + "</span>";
|
||||
};
|
||||
return "<div class=\"opening-pair-row " + std::string(size == 36 ? "compact" : size == 66 ? "current" : "") +
|
||||
"\"><span class=\"opening-pair-number\"><span>" + std::to_string(index + 1) + "</span></span>" +
|
||||
label_for(pool[a], true, known > 0) + "<span class=\"opening-pair-versus\"><span>–</span></span>" +
|
||||
label_for(pool[b], false, known > 1) + "<span class=\"opening-pair-counter\" aria-hidden=\"true\"></span></div>";
|
||||
};
|
||||
body = "<h2 style=\"font-size:46dp;\">" +
|
||||
std::string(opening_page_ == 3 ? "1. Runde" : "DFB-Pokal") +
|
||||
"</h2><p class=\"small\" style=\"margin-top:16dp;\">" +
|
||||
(opening_page_ == 3 ? "DFB-Pokal · Saison " : "1. Runde · Saison ") +
|
||||
esc(snap().state.value("date", std::string()).substr(0, 4)) + "</p>";
|
||||
if (opening_page_ == 3) {
|
||||
body += "<span class=\"small\" "
|
||||
"style=\"position:absolute;right:0;top:20dp;\">" +
|
||||
std::to_string(draw_revealed_) +
|
||||
" / 64 Mannschaften</span><div style=\"position:absolute;" +
|
||||
rect(0, 138, 2608, 850) + "\">" +
|
||||
img("art.cup-draw-v1.png", 2608, 850, false, false, 1800) +
|
||||
"</div>";
|
||||
const int current = std::max(0, (draw_revealed_ - 1) / 2),
|
||||
known = draw_revealed_ ? draw_revealed_ - current * 2 : 0;
|
||||
body += "<div class=\"panel\" style=\"position:absolute;" +
|
||||
rect(130, 1026, 2352, 126) +
|
||||
"padding:10dp 28dp;font-size:38dp;\">" +
|
||||
pair(current, known, 66) + "</div>";
|
||||
for (int i = std::max(0, current - 3); i < current; ++i)
|
||||
body +=
|
||||
"<div style=\"position:absolute;" +
|
||||
rect(158, 1190 + (i - std::max(0, current - 3)) * 155, 2296, 145) +
|
||||
"border-bottom:2dp var(--border);\">" + pair(i, 2, 42) + "</div>";
|
||||
body += "<div class=\"bottom-controls\" "
|
||||
"style=\"justify-content:flex-end;\">" +
|
||||
btn("opening-play", draw_playing_ ? "Pause" : "Fortsetzen", {},
|
||||
"style=\"flex:none;width:390dp;\"") +
|
||||
btn("opening-all", "Alle Paarungen anzeigen", {},
|
||||
"style=\"flex:none;width:600dp;\"") +
|
||||
"</div>";
|
||||
} else {
|
||||
for (int column = 0; column < 2; ++column) {
|
||||
body += "<div class=\"panel\" style=\"position:absolute;" +
|
||||
rect(column * 1323, 154, 1289, 1500) + "padding:12dp 18dp;\">";
|
||||
for (int row = 0; row < 16; ++row)
|
||||
body += "<div style=\"height:92dp;font-size:27dp;border-bottom:1dp "
|
||||
"var(--border);\">" +
|
||||
pair(column * 16 + row, 2, 36) + "</div>";
|
||||
body += "</div>";
|
||||
}
|
||||
body += "<div class=\"bottom-controls\" "
|
||||
"style=\"justify-content:flex-end;\">" +
|
||||
btn("opening-finish", "Weiter zum Desktop", "primary",
|
||||
"style=\"flex:none;width:550dp;\"") +
|
||||
"</div>";
|
||||
}
|
||||
}
|
||||
return window(opening_page_ < 3 ? "Deutsche Teams" : "DFB-Pokal", body,
|
||||
false);
|
||||
}
|
||||
std::string App::render_camp() {
|
||||
const auto index_file =
|
||||
Json::parse(editor::read_file(gui_.root() / "gui-assets.json"));
|
||||
|
||||
+33
-44
@@ -11,6 +11,7 @@
|
||||
#include "modern/ui/demo_advertising.hpp"
|
||||
#include "modern/ui/demo_toto.hpp"
|
||||
#include "modern/ui/demo_reports.hpp"
|
||||
#include "modern/ui/demo_opening.hpp"
|
||||
#include "modern/ui/demo_sports.hpp"
|
||||
#include "modern/ui/demo_lineup.hpp"
|
||||
#include "modern/ui/demo_transfer.hpp"
|
||||
@@ -428,10 +429,10 @@ class App final : public Rml::EventListener {
|
||||
bool context_open_ = false, context_dirty_ = false;
|
||||
std::string context_id_;
|
||||
int context_x_ = 0, context_y_ = 0;
|
||||
int opening_page_ = 0, draw_revealed_ = 0;
|
||||
uint64_t opening_due_ = 0;
|
||||
bool opening_io_blocked_ = false;
|
||||
int last_tactic_ = 0;
|
||||
bool draw_playing_ = true;
|
||||
uint64_t draw_at_ = 0;
|
||||
|
||||
#include "modern/ui/settings_state.inc"
|
||||
#include "modern/ui/widgets_state.inc"
|
||||
#include "modern/ui/files_state.inc"
|
||||
@@ -589,6 +590,12 @@ class App final : public Rml::EventListener {
|
||||
return &m;
|
||||
return nullptr;
|
||||
}
|
||||
void bind_world(std::shared_ptr<const Catalog> next) {
|
||||
renderer_.world(std::move(next));
|
||||
files_default_key_.clear();
|
||||
files_default_picture_ = Picture();
|
||||
files_default_pending_ = false;
|
||||
}
|
||||
void load_world(const fs::path &file) {
|
||||
auto next = Catalog::open(file);
|
||||
auto demo = std::make_unique<DemoSource>(next);
|
||||
@@ -599,9 +606,11 @@ class App final : public Rml::EventListener {
|
||||
reset_settings();
|
||||
reset_files();
|
||||
ticket_.reset();
|
||||
renderer_.world(next);
|
||||
bind_world(next);
|
||||
world_ = std::move(next);
|
||||
source_ = std::move(demo);
|
||||
opening_due_ = 0;
|
||||
opening_io_blocked_ = false;
|
||||
lineup_drag_ = Json(); lineup_drag_world_.reset(); lineup_selected_.clear(); lineup_ignore_click_ = false;
|
||||
lineup_pitch_ = true; lineup_data_ = lineup_page_ = 0; lineup_side_ = "formations";
|
||||
transfer_view_ = Json::object(); transfer_draft_ = transfer_search_draft_ = Json();
|
||||
@@ -756,6 +765,16 @@ class App final : public Rml::EventListener {
|
||||
std::string render_newgame();
|
||||
std::string render_manager();
|
||||
std::string render_opening();
|
||||
fs::path opening_progress_path(const Catalog &) const;
|
||||
void opening_write(const Catalog &, const Json &, const Json &);
|
||||
void opening_restore_startup();
|
||||
bool opening_pending() const;
|
||||
bool opening_change(const std::string &);
|
||||
bool opening_action(const std::string &, Rml::Element *);
|
||||
bool opening_event(Rml::Event &);
|
||||
void opening_tick();
|
||||
void handle_event(SDL_Event &);
|
||||
void pump_events();
|
||||
std::string render_menu(const std::string &);
|
||||
void dispatch(const std::string &, Rml::Element *);
|
||||
void change(Rml::Element *);
|
||||
@@ -810,6 +829,11 @@ class App final : public Rml::EventListener {
|
||||
needs_render_ = true;
|
||||
}
|
||||
void render() {
|
||||
if (scene_ == "desktop" && !files_capturing_ && opening_pending()) {
|
||||
scene_ = "opening";
|
||||
menu_.clear();
|
||||
opening_due_ = 0;
|
||||
}
|
||||
news_before_render();
|
||||
fixture_half_width_ = -1.f;
|
||||
almanac_list_width_ = -1.f;
|
||||
@@ -1238,6 +1262,7 @@ public:
|
||||
// A capture/CLI override is visual only and never edits a career.
|
||||
ui_preferences_["theme"]=theme_;
|
||||
}
|
||||
opening_restore_startup();
|
||||
if (scene_ == "manager" && selections_["manager-name"].empty())
|
||||
selections_["manager-name"] = "Alex Berger";
|
||||
doc_->Show();
|
||||
@@ -1278,15 +1303,7 @@ public:
|
||||
}
|
||||
while (!closed_) {
|
||||
front_poll();
|
||||
if (scene_ == "opening" && opening_page_ == 3 && draw_revealed_ < 64 &&
|
||||
draw_playing_ && SDL_GetTicks64() >= draw_at_ &&
|
||||
(SDL_GetWindowFlags(video_.window) & SDL_WINDOW_INPUT_FOCUS)) {
|
||||
++draw_revealed_;
|
||||
draw_at_ = SDL_GetTicks64() + 900;
|
||||
if (draw_revealed_ == 64)
|
||||
opening_page_ = 4;
|
||||
refresh();
|
||||
}
|
||||
opening_tick();
|
||||
if (needs_render_ || dirty_)
|
||||
frame();
|
||||
SDL_Event event;
|
||||
@@ -1294,37 +1311,7 @@ public:
|
||||
int(std::clamp(context_->GetNextUpdateDelay(), 0.0, .2) * 1000);
|
||||
bool got = SDL_WaitEventTimeout(&event, timeout) != 0;
|
||||
while (got) {
|
||||
if (event.type == SDL_QUIT) {
|
||||
if(front_busy_){front_feedback_="Bitte den laufenden Import abwarten.";dirty_=true;}
|
||||
else if (source_ && scene_ != "main" && scene_ != "mods") {
|
||||
quit_closes_app_=true;
|
||||
dispatch("context-quit", nullptr);
|
||||
} else
|
||||
closed_ = true;
|
||||
} else {
|
||||
if (event.type == SDL_WINDOWEVENT) {
|
||||
if(event.window.event==SDL_WINDOWEVENT_FOCUS_LOST)desktop_cancel_drag();
|
||||
resize();
|
||||
}
|
||||
int w, h, pw, ph;
|
||||
SDL_GetWindowSize(video_.window, &w, &h);
|
||||
video_.drawable_size(pw, ph);
|
||||
if (w > 0 && h > 0) {
|
||||
if (event.type == SDL_MOUSEMOTION) {
|
||||
event.motion.x = int(double(event.motion.x) * pw / w);
|
||||
event.motion.y = int(double(event.motion.y) * ph / h);
|
||||
}
|
||||
if (event.type == SDL_MOUSEBUTTONDOWN ||
|
||||
event.type == SDL_MOUSEBUTTONUP) {
|
||||
event.button.x = int(double(event.button.x) * pw / w);
|
||||
event.button.y = int(double(event.button.y) * ph / h);
|
||||
context_->ProcessMouseMove(event.button.x, event.button.y,
|
||||
RmlSDL::GetKeyModifierState());
|
||||
}
|
||||
}
|
||||
RmlSDL::InputEventHandler(context_, video_.window, event);
|
||||
dirty_ = true;
|
||||
}
|
||||
handle_event(event);
|
||||
got = SDL_PollEvent(&event) != 0;
|
||||
}
|
||||
if (context_->GetNextUpdateDelay() <= 0)
|
||||
@@ -1335,6 +1322,8 @@ public:
|
||||
};
|
||||
#include "modern/ui/entry_controls.inc"
|
||||
#include "modern/ui/entry_screens.inc"
|
||||
#include "modern/ui/entry_opening_controls.inc"
|
||||
#include "modern/ui/entry_opening_screens.inc"
|
||||
#include "modern/ui/controls.inc"
|
||||
#include "modern/ui/widgets_screens.inc"
|
||||
#include "modern/ui/widgets_controls.inc"
|
||||
|
||||
Reference in new issue
Block a user