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 <noreply@anthropic.com>
This commit is contained in:
MichaelandClaude Fable 5.2 committed 2026-11-15 21:13:57 +01:00
1 parent d9b0590705
commit 724f717421
4 files changed
+97 -1

No files matched your search

+16
View File
@@ -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);}
+78
View File
@@ -54,8 +54,86 @@ std::string App::files_details(bool layouts, bool save) {
}
return out + "</section><p class=\"files-timestamp\">" + (fresh ? "Diese Angaben werden mit dem Spielstand gespeichert." : (files_native_?"Datei geändert am ":"Gespeichert am ") + esc(files_entry_->created) + (files_native_?std::string():"<br/>Geändert am "+esc(files_entry_->modified)) + " · " + std::to_string(files_entry_->bytes) + " Bytes") + "</p>";
}
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 "<div class=\"pg-empty\"><strong class=\"pg-h\" style=\"font-size:" + pg(20) + ";\">" + esc(title) + "</strong><span style=\"display:block;\">" + esc(text) + "</span>" +
(more.empty() ? std::string() : "<span class=\"fl-error\">" + esc(more) + "</span>") + "</div>";
};
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 = "<div class=\"pg-row\" style=\"" + pg_css("gap:16px;") + "\"><span class=\"fl-crest\">" + (national ? img("career.national-de", 189, 189, false, false, 256) : crest(own, 189)) + "</span><div class=\"pg-grow\">" +
pg_kicker(fresh ? "Aktuelles Spiel" : "Gespeicherter Spielstand") + "<h3 class=\"pg-h\" style=\"font-size:" + pg(26) + ";line-height:" + pg(32) + ";\">" + esc(fresh ? "Neuer Speicherstand" : files_entry_->name) +
"</h3><span class=\"pg-mut\" style=\"display:block;\">" + esc(national ? "Deutschland" : own ? world_->name(*own) : "") + "</span></div></div>";
if (fresh) out += "<label class=\"fl-field\"><span>Bezeichnung</span><input id=\"files-name\" class=\"fl-input\" type=\"text\" data-change=\"files-name\" maxlength=\"64\" value=\"" + esc(files_name_) + "\"/></label>";
const auto iso = meta.at("date").get<std::string>();
out += "<div class=\"pg-row\" style=\"align-items:stretch;" + pg_css("gap:8px;") + "\">" + pg_stat("Saison", esc(meta.at("season").get<std::string>())) + pg_stat("Spieltag", esc(meta.at("matchday").get<std::string>())) +
pg_stat("Spieldatum", "<span style=\"font-size:" + pg(19) + ";\">" + esc(iso.substr(8, 2) + "." + iso.substr(5, 2) + "." + iso.substr(0, 4)) + "</span>") + pg_stat("Spieler", std::to_string(meta.at("human_count").get<size_t>())) + "</div><div>" +
pg_kicker("Mitspieler") + "<div class=\"fl-managers\">";
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 += "<div class=\"fl-manager\">" + (managed ? crest(managed, 72) : std::string()) + "<div><strong>" + esc(manager.value("name", "")) + "</strong><span class=\"pg-mut\">" + esc(team) + "</span></div></div>";
}
out += "</div></div><span class=\"pg-sp\"></span>";
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 + "<span class=\"pg-mut\" style=\"display:block;font-size:" + pg(12.5) + ";\">" + esc(note) + "</span>";
}
// 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, "<strong>" + esc(label) + "</strong><span class=\"pg-mut\">" + esc(subtitle) + "</span>", 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 = "<div class=\"pg-panel\"><div class=\"pg-empty\"><span>" + std::string(files_native_ && engine_files_busy_ ? "Spielstände werden geladen …" : "Noch keine Spielstände vorhanden.") + "</span></div></div>";
std::string details;
try { details = files_page_details(save); }
catch (const std::exception &e) { details = "<div class=\"pg-empty\"><strong class=\"pg-h\">Datei nicht verfügbar</strong><span style=\"display:block;\">" + esc(e.what()) + "</span></div>"; }
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 "<section class=\"pg-page\"><div class=\"pg-row pg-grow\" style=\"align-items:stretch;\"><div class=\"pg-col\" style=\"width:" + pg(440) + ";flex:none;" + pg_css("gap:8px;") + "\"><div class=\"pg-row\" style=\"justify-content:space-between;\"><strong class=\"pg-h\">Spielstände</strong><span class=\"pg-mut\">" +
std::to_string(files_rows_.size()) + "</span></div><div id=\"files-list\" class=\"fl-list\" role=\"listbox\" aria-label=\"Spielstand auswählen\">" + entries + "</div></div><div class=\"pg-panel pg-col pg-grow\" style=\"" + pg_css("gap:14px;") + "\">" + details +
"</div></div><nav class=\"pg-foot\">" + pg_button("files-import", "Importieren") + pg_button("files-export", "Exportieren", "", disabled) + pg_button("files-rename", "Umbenennen", "", disabled) +
pg_button("files-delete", "Löschen", "", files_entry_ && !files_entry_->token.empty() ? "" : "disabled=\"disabled\"") + "<span class=\"pg-status\" id=\"files-feedback\" role=\"status\">" + esc(feedback) + "</span><span class=\"pg-sp\"></span>" +
pg_button("files-close", "Abbrechen") + pg_button(save ? "files-save" : "files-load", save ? "Speichern" : "Laden", "primary", "id=\"files-confirm\" " + std::string((save ? can_save : selected) ? "" : "disabled=\"disabled\"")) + "</nav></section>";
}
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";
+2
View File
@@ -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 *);
+1 -1
View File
@@ -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<std::string> native{"stadium", "statistics", "news", "transfer", "training", "almanac", "tactics", "achievements", "highscore", "balance", "contracts", "environment", "tables", "league", "other", "strengths", "fairplay", "indoor", "scorers"};
static const std::set<std::string> 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";