From 724f71742161ab93f04848d4e2da467e069ae08b Mon Sep 17 00:00:00 2001 From: Weyoune Date: Sun, 15 Nov 2026 21:13:57 +0100 Subject: [PATCH] Saving and loading as pages of the notebook, after the design The saves on the left, the chosen one with crest, season, matchday and fellow players on the right, and in the foot what can be done with a file. Co-Authored-By: Claude Fable 5.2 --- assets/modern/pages.rcss | 16 +++++++ src/modern/ui/files_screens.inc | 78 +++++++++++++++++++++++++++++++++ src/modern/ui/files_state.inc | 2 + src/modern/ui/pages.inc | 2 +- 4 files changed, 97 insertions(+), 1 deletion(-) diff --git a/assets/modern/pages.rcss b/assets/modern/pages.rcss index a63c3ee..0fe9bec 100644 --- a/assets/modern/pages.rcss +++ b/assets/modern/pages.rcss @@ -556,3 +556,19 @@ body.midnight .sd-stage,body.matchday .sd-stage {background-color:var(--p-n2);} .sd-option .pg-h,.sd-option .pg-mut {display:block;} .pg-ov .sd-feedback {max-width:none;white-space:normal;height:auto;min-height:60dp;line-height:40dp;padding:10dp 27dp;} .sd-card .pg-bar {flex:none;} + +/* --- save and load: the saves on the left, the chosen one on the right --- */ +.fl-list {display:flex;flex-direction:column;flex:1;min-height:0;gap:14dp;padding:7dp;overflow-y:auto;} +.pg-root .pg-card.fl-entry {flex:none;gap:2dp;padding:20dp 32dp;border-radius:36dp;} +.fl-entry strong {display:block;font-size:34dp;line-height:42dp;font-weight:bold;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;} +.fl-entry span {display:block;font-size:28dp;line-height:36dp;} +.fl-crest {display:block;flex:none;width:189dp;height:189dp;} +.fl-field {display:block;} +.fl-field span {display:block;margin-bottom:9dp;font-size:27dp;color:var(--p-n7);} +.pg-root .fl-input {display:block;width:100%;height:86dp;padding:0 32dp;border:2dp var(--p-n4);border-radius:27dp;background-color:var(--p-bg);decorator:none;font-family:Modern;font-size:34dp;line-height:82dp;color:var(--p-text);} +.pg-root .fl-input:focus {border-color:var(--p-a6);} +.fl-managers {display:flex;flex-wrap:wrap;gap:22dp 54dp;margin-top:14dp;} +.fl-manager {display:flex;align-items:center;gap:22dp;} +.fl-manager strong {display:block;font-size:31dp;font-weight:bold;} +.fl-manager span {display:block;font-size:28dp;} +.fl-error {display:block;margin-top:14dp;color:var(--p-a7);} diff --git a/src/modern/ui/files_screens.inc b/src/modern/ui/files_screens.inc index 69c5447..b9f9609 100644 --- a/src/modern/ui/files_screens.inc +++ b/src/modern/ui/files_screens.inc @@ -54,8 +54,86 @@ std::string App::files_details(bool layouts, bool save) { } return out + "

" + (fresh ? "Diese Angaben werden mit dem Spielstand gespeichert." : (files_native_?"Datei geändert am ":"Gespeichert am ") + esc(files_entry_->created) + (files_native_?std::string():"
Geändert am "+esc(files_entry_->modified)) + " · " + std::to_string(files_entry_->bytes) + " Bytes") + "

"; } +namespace { +// The time a file was written, as it is said here: "2026-11-15 20:11 UTC" becomes "15.11.2026, 20:11". +std::string files_when(const std::string &stamp) { + if (stamp.size() < 16 || stamp[4] != '-' || stamp[7] != '-' || stamp[13] != ':') return stamp; + return stamp.substr(8, 2) + "." + stamp.substr(5, 2) + "." + stamp.substr(0, 4) + ", " + stamp.substr(11, 5); +} +} // namespace +// What the chosen save holds, on the right of the page: whose game it is, its name, season, +// matchday and date, who plays along, and the file itself. +std::string App::files_page_details(bool save) { + const auto empty = [](const std::string &title, const std::string &text, const std::string &more = std::string()) { + return "
" + esc(title) + "" + esc(text) + "" + + (more.empty() ? std::string() : "" + esc(more) + "") + "
"; + }; + if (files_native_ && engine_files_busy_ && save && !engine_files_metadata_.is_object()) return empty("Spielstände werden geladen …", ""); + const bool fresh = save && files_selected_.empty(); + if (files_entry_ && !files_entry_->valid()) return empty(files_entry_->name, "Diese Datei kann nicht geöffnet werden.", files_entry_->error); + if (!fresh && !files_entry_) return empty("Kein Spielstand ausgewählt", "Wähle links einen Eintrag aus."); + const auto data = fresh ? (files_native_ ? engine_files_metadata_ : snap().state) : files_entry_->data; + const auto meta = files_native_ ? data : DemoFiles::career_metadata(data); + const auto &managers = meta.at("managers"); + const bool national = meta.at("role") == "national"; + const Json *own = managers.empty() ? nullptr : world_->find("clubs", meta.at("current_manager").value("club", "")); + std::string out = "
" + (national ? img("career.national-de", 189, 189, false, false, 256) : crest(own, 189)) + "
" + + pg_kicker(fresh ? "Aktuelles Spiel" : "Gespeicherter Spielstand") + "

" + esc(fresh ? "Neuer Speicherstand" : files_entry_->name) + + "

" + esc(national ? "Deutschland" : own ? world_->name(*own) : "") + "
"; + if (fresh) out += ""; + const auto iso = meta.at("date").get(); + out += "
" + pg_stat("Saison", esc(meta.at("season").get())) + pg_stat("Spieltag", esc(meta.at("matchday").get())) + + pg_stat("Spieldatum", "" + esc(iso.substr(8, 2) + "." + iso.substr(5, 2) + "." + iso.substr(0, 4)) + "") + pg_stat("Spieler", std::to_string(meta.at("human_count").get())) + "
" + + pg_kicker("Mitspieler") + "
"; + for (const auto &manager : managers) { + const auto *managed = world_->find("clubs", manager.value("club", "")); + const auto team = files_native_ ? manager.value("team_name", std::string()) : national && manager.value("portrait", 0) == meta.at("current_manager").value("portrait", 0) ? std::string("Deutschland") : managed ? world_->name(*managed) : std::string(); + out += "
" + (managed ? crest(managed, 72) : std::string()) + "
" + esc(manager.value("name", "")) + "" + esc(team) + "
"; + } + out += "
"; + std::string note = "Die Datei wird im Spielstandordner abgelegt."; + if (!fresh) { + const double bytes = double(files_entry_->bytes); + char size[32]; + if (bytes >= 1048576) std::snprintf(size, sizeof size, "%.1f MB", bytes / 1048576); + else std::snprintf(size, sizeof size, "%.0f KB", std::max(1.0, bytes / 1024)); + std::string text = size; + std::replace(text.begin(), text.end(), '.', ','); + note = (files_native_ ? "Datei geändert am " : "Gespeichert am ") + files_when(files_entry_->created) + (files_native_ ? std::string() : " · geändert am " + files_when(files_entry_->modified)) + " · " + text; + } + return out + "" + esc(note) + ""; +} +// Speichern and Laden as pages of the notebook: the saves on the left, the chosen one on the +// right, and in the foot what can be done with a file. +std::string App::render_files_page(bool save) { + std::string entries; + const auto row = [&](const std::string &action, const std::string &id, const std::string &label, const std::string &subtitle, bool selected, const std::string &identity) { + return btn(action, "" + esc(label) + "" + esc(subtitle) + "", std::string("pg-card fl-entry") + (selected ? " sel" : ""), + "id=\"" + identity + "\" role=\"option\" data-id=\"" + esc(id) + "\" data-file-row=\"true\" aria-selected=\"" + (selected ? "true" : "false") + "\""); + }; + if (save) entries += row("files-new", "", "Neuer Speicherstand", "Aktuellen Spielstand neu speichern", files_selected_.empty(), "files-new"); + for (size_t i = 0; i < files_rows_.size(); ++i) { + const auto &entry = files_rows_[i]; + entries += row("files-select", entry.id, entry.name, entry.valid() ? "Gespeichert am " + files_when(entry.created) : "Datei kann nicht geöffnet werden", files_selected_ == entry.id, "files-entry-" + std::to_string(i)); + } + if (entries.empty()) entries = "
" + std::string(files_native_ && engine_files_busy_ ? "Spielstände werden geladen …" : "Noch keine Spielstände vorhanden.") + "
"; + std::string details; + try { details = files_page_details(save); } + catch (const std::exception &e) { details = "
Datei nicht verfügbar" + esc(e.what()) + "
"; } + const bool selected = files_entry_ && files_entry_->valid(); + bool can_save = save && (!files_entry_ || selected) && (!files_native_ || engine_files_metadata_.is_object()); + if (save && !selected) try { if (files_native_) CareerFiles::clean_name(files_name_); else DemoFiles::clean_name(files_name_); } catch (...) { can_save = false; } + const std::string disabled = selected ? "" : "disabled=\"disabled\""; + const auto feedback = files_feedback_.empty() ? std::string(save ? "Enter im Namensfeld speichert." : "Klick oder Pfeiltasten wählen einen Eintrag.") : files_feedback_; + return "
Spielstände" + + std::to_string(files_rows_.size()) + "
" + entries + "
" + details + + "
"; +} std::string App::render_files(bool layouts, bool save) { if (files_mode_ != menu_) files_begin(menu_); + if (!layouts && page_native()) return render_files_page(save); std::string entries; const auto row = [&](const std::string &action, const std::string &id, const std::string &label, const std::string &subtitle, bool selected, const std::string &identity, bool fresh = false) { const auto icon = fresh ? "plus" : id == "standard" ? "grid" : layouts ? "image" : "save"; diff --git a/src/modern/ui/files_state.inc b/src/modern/ui/files_state.inc index 93ffd44..3972da3 100644 --- a/src/modern/ui/files_state.inc +++ b/src/modern/ui/files_state.inc @@ -19,6 +19,8 @@ void files_select(const std::string &); void files_before_render(); void files_after_render(); std::string render_files(bool layouts, bool save); +std::string render_files_page(bool save); +std::string files_page_details(bool save); std::string files_details(bool layouts, bool save); std::string files_standard_preview(); bool files_action(const std::string &, Rml::Element *); diff --git a/src/modern/ui/pages.inc b/src/modern/ui/pages.inc index 44563e0..990ecfa 100644 --- a/src/modern/ui/pages.inc +++ b/src/modern/ui/pages.inc @@ -5,7 +5,7 @@ // The menus that are laid out as a page of the notebook. Every other career menu is still a // sheet of the old format, shown scaled inside the book. bool App::page_native() const { - static const std::set native{"stadium", "statistics", "news", "transfer", "training", "almanac", "tactics", "achievements", "highscore", "balance", "contracts", "environment", "tables", "league", "other", "strengths", "fairplay", "indoor", "scorers"}; + static const std::set native{"save", "load", "stadium", "statistics", "news", "transfer", "training", "almanac", "tactics", "achievements", "highscore", "balance", "contracts", "environment", "tables", "league", "other", "strengths", "fairplay", "indoor", "scorers"}; if (menu_ == "calendar" || menu_ == "postpone" || menu_ == "lineup") return notebook_page() && engine_mode_; // a national coach arranges friendlies on the older sheet if (menu_ == "friendlies") return notebook_page() && engine_mode_ && engine_data_.contains("desktop") && engine_data_.at("desktop").at("meta").at("scope").at("role") == "club";