Files
Dreierpack-Manager/src/modern/ui/front_screens.inc
T
MichaelandClaude Fable 5.2 048ccbecaa The entry into the game on a pad: main menu, new game, managers, clubs, the season's opening
The main menu and everything up to the first day are written on one pad
that lies in the middle of a table: the settings of a new game, the
managers with their portraits, the clubs of a league, the entrants of the
European cups, the cup draw and its overview. Saved games, mods and the
sound open on the same pad. The table fills the window at any aspect while
the pad stays whole. There is one style of portrait. The main menu asks
before it leaves, and the ribbon of the notebook leads back to it.

A stage that changes its height while it is drawn is now drawn once more;
before, the notebook kept the height of the screen it came from.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-16 12:41:25 +01:00

202 lines
17 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// SPDX-License-Identifier: GPL-3.0-only
fs::path App::front_library_root() const {
return config_.mods.empty() ? root_ : config_.mods;
}
const UiModEntry *App::front_selected() const {
for (const auto &entry : front_snapshot_.entries)
if (entry.id == selected_mod_)
return &entry;
return nullptr;
}
std::string App::front_source_name(const UiModEntry &entry) const {
return entry.source == "BMH" ? "Bundesliga Manager Hattrick"
: entry.source == "FTLD" || entry.source == "FLTD" ? "Football Limited"
: "OpenBMH";
}
std::string App::front_size(uint64_t bytes) const {
const auto tenths = (bytes * 10 + 524288) / 1048576;
return number(int64_t(tenths / 10)) +
(tenths % 10 ? "," + std::to_string(tenths % 10) : "") + " MiB";
}
// A length of the entry's design in dp: the table is drawn 1672 units across.
std::string App::es(double units) { return scalar(units * kEntryUnit) + "dp"; }
// The table with the pad on it; `over` lies above the pad (a note that asks something).
std::string App::entry_stage(const std::string &paper, const std::string &over) {
return "<div class=\"es-stage\"><div class=\"es-table\">" + (gui_.contains("entry.table") ? img("entry.table", 3840, 2160, false, true, 2048) : std::string()) +
"</div><section class=\"es-paper pg-root\">" + paper + "</section>" + over + "</div>";
}
// What is written on the pad: a small line, the heading, a rule, the body and the buttons at
// its foot. `right` stands beside the heading; without it the paper clip keeps its room.
std::string App::entry_sheet(const std::string &kicker, const std::string &title, const std::string &body, const std::string &foot, const std::string &right) {
return "<header class=\"es-head\"><div class=\"es-grow\"><span class=\"es-k\">" + esc(pg_upper(kicker)) + "</span><h1 class=\"es-h1\">" + esc(title) + "</h1></div>" +
(right.empty() ? std::string("<span class=\"es-clip\"></span>") : right) + "</header><div class=\"es-rule\"></div>" + body + (foot.empty() ? std::string() : "<nav class=\"es-foot\">" + foot + "</nav>");
}
std::string App::entry_pad(const std::string &kicker, const std::string &title, const std::string &body, const std::string &foot, const std::string &right, const std::string &over) {
return entry_stage(entry_sheet(kicker, title, body, foot, right), over);
}
std::string App::main_menu() {
const auto *active = mod(active_mod_);
const bool available = active && active->error.empty();
std::string rows;
const std::array<std::pair<const char *, const char *>, 6> actions{
{{"new", "Neues Spiel"}, {"load", "Spiel laden"}, {"network", "Netzwerk"}, {"mods", "Mod"}, {"settings", "Einstellungen"}, {"exit", "Beenden"}}};
for (const auto &[key, title] : actions) {
const std::string id = key;
const bool network = id == "network",
disabled = scene_ != "main" || !menu_.empty() || network || front_quit_ || (id == "new" && !available && !(front_external_override_ && world_));
rows += btn(key, "<span>" + std::string(title) + "</span>" + (network ? "<span class=\"es-mb-s\">DEMNÄCHST</span>" : "") + "<span class=\"es-grow\"></span><span class=\"es-mb-a\">›</span>",
std::string("es-mb") + (id == "load" || id == "exit" ? " gap" : ""), "id=\"front-" + id + "\" " + (disabled ? "disabled=\"disabled\"" : ""));
}
const auto label = front_external_override_ && world_ ? world_->title() : available ? active->name : "Keine Mod aktiviert";
const std::string ask = front_quit_ ? "<div class=\"es-box es-ask\"><strong>Das Spiel wirklich beenden?</strong><div class=\"es-row\" style=\"justify-content:flex-end;margin-top:" + es(10) + ";\">" +
pg_button("front-quit-no", "Abbrechen", "sm", "id=\"front-quit-no\"") + pg_button("front-quit-yes", "Beenden", "primary sm", "id=\"front-quit-yes\"") + "</div></div>"
: std::string();
return entry_stage("<h1 class=\"es-title\">Dreierpack Manager</h1><div class=\"es-gold\"></div><div class=\"es-fill\" style=\"align-items:stretch;gap:" + es(34) + ";\"><nav class=\"es-menu\" aria-label=\"Hauptmenü\">" + rows +
"</nav><div class=\"es-side\">" + ask + "<span class=\"es-mut\">Aktive Mod</span><strong id=\"front-active-name\">" + esc(label) + "</strong><span class=\"es-mut\" style=\"margin-top:" + es(8) + ";\">Version " +
std::string(kOpenBmhVersion) + (config_.preview_only ? " · UI-Demo" : " · Entwicklung") + "</span></div></div>");
}
std::string App::front_mod_details() {
const auto *entry = front_selected();
if (!entry)
return "<div class=\"es-box es-detail\" style=\"align-items:center;justify-content:center;text-align:center;\"><h2 class=\"es-h\" style=\"font-size:" + es(21) + ";line-height:" + es(26) +
";\">Noch keine Mods installiert</h2><span class=\"es-mut\" style=\"display:block;\">Importiere einen Originalordner oder ein OpenBMH-Paket.</span></div>";
const bool active = entry->active && !front_external_override_;
const auto provenance = entry->description.empty() ? front_source_name(*entry) : entry->description;
std::string out = "<div class=\"es-box es-detail\"><span class=\"es-k\">" + esc(pg_upper(active ? "Aktiv" : entry->valid() ? "Installiert" : "Fehlerhaft")) + "</span><h2 class=\"es-h\" style=\"font-size:" + es(21) + ";line-height:" + es(26) +
";\">" + esc(entry->name) + "</h2><span class=\"es-mut\" style=\"display:block;\">" + esc(provenance) + "</span><div>";
const std::vector<std::pair<std::string, std::string>> fields = {
{"Art", entry->type},
{"Herkunft", front_source_name(*entry)},
{"Version", entry->version},
{"Inhalt", std::to_string(entry->file_count) + (entry->file_count == 1 ? " Datei" : " Dateien") + " · " + front_size(entry->bytes)}};
for (const auto &[label, value] : fields) out += "<div class=\"es-kv\"><span>" + esc(label) + "</span><strong>" + esc(value) + "</strong></div>";
out += "</div>";
if (!entry->valid()) out += "<span class=\"es-error\">" + esc(entry->error) + "</span>";
const auto *current = mod(active_mod_);
out += "<span class=\"es-grow\"></span><span class=\"es-mut\" style=\"display:block;font-size:" + es(12) + ";\">" +
esc(active ? "Diese Mod ist für das nächste Spiel ausgewählt." : current ? "Aktivieren ersetzt die Auswahl „" + current->name + "“." : "Aktiviere diese Mod für das nächste Spiel.") + "</span><div class=\"es-row\">";
return out + pg_button("mod-activate", active ? "Aktiv" : "Aktivieren", "primary sm", "id=\"mod-activate\" " + std::string(active || !entry->valid() || front_busy_ ? "disabled=\"disabled\"" : "")) + "</div></div>";
}
std::string App::front_modal() {
if (front_dialog_.empty())
return {};
std::string heading, body, buttons;
if (front_dialog_ == "choice") {
heading = "Mod importieren";
body = "<p>Wähle einen Originalordner oder einen Export im OpenBMH-Format.</p>";
const std::array<std::array<const char *, 3>, 3> choices{
{{{"original", "BMH / Football Limited", "Originalordner mit BMH.EXE oder FLTD.EXE"}},
{{"package", "OpenBMH-Paket", "Weltpaket im neuen Format · .obw oder .zip"}},
{{"folder", "OpenBMH-Exportordner", "Entpackte Welt oder Mod-Ordner mit content.obw"}}}};
for (const auto &c : choices)
body += btn("front-pick", "<strong>" + std::string(c[1]) + "</strong><span>" + c[2] + "</span>", "es-choice", "data-id=\"" + std::string(c[0]) + "\"");
buttons = pg_button("front-dismiss", "Abbrechen");
} else if (front_dialog_ == "name" || front_dialog_ == "rename") {
const bool importing = front_dialog_ == "name";
heading = importing ? "Mod übernehmen" : "Mod umbenennen";
body = "<div><span class=\"es-k\">BEZEICHNUNG</span><input type=\"text\" class=\"es-in\" id=\"front-mod-name\" value=\"" + esc(front_name_) + "\" maxlength=\"64\" style=\"margin-top:" + es(3) + ";\"/></div>";
if (importing && front_plan_) {
const auto &m = front_plan_->metadata;
body += "<p>" + esc(m.description) + " · " + esc(m.type) + " · " + std::to_string(m.file_count) + (m.file_count == 1 ? " Datei" : " Dateien") + " · " + front_size(m.bytes) + "</p><p class=\"es-mut\">" +
std::string(m.type == "Classic" ? "Der vorhandene OpenBMH-Importer konvertiert die Originaldaten in ein eigenständiges Classic-Paket."
: "Das geprüfte Weltpaket wird in deine Mod-Bibliothek übernommen.") +
" Anschließend kannst du die Mod aktivieren.</p>";
}
body += "<span id=\"front-name-error\" class=\"es-error\">" + esc(front_name_error_) + "</span>";
buttons = pg_button("front-dismiss", "Abbrechen") +
pg_button("front-name-confirm", importing ? "Importieren" : "Umbenennen", "primary", "id=\"front-name-confirm\" " + std::string(front_name_error_.empty() ? "" : "disabled=\"disabled\""));
} else if (front_dialog_ == "delete") {
heading = "Mod löschen?";
body = "<p>„" + esc(front_target_ ? front_target_->name : "") + "“ wirklich aus der lokalen Bibliothek entfernen?</p>";
if (front_target_ && front_target_->active) body += "<p class=\"es-mut\">Danach ist keine Mod aktiviert. Wähle eine andere Mod für das nächste neue Spiel.</p>";
body += "<p class=\"es-mut\">Persönliche Spielstände bleiben erhalten.</p>";
buttons = pg_button("front-dismiss", "Abbrechen") + pg_button("front-delete-confirm", "Löschen", "primary");
} else {
heading = "Vorgang nicht möglich";
body = "<p>" + esc(front_error_) + "</p>";
buttons = pg_button("front-dismiss", "Verstanden");
}
return "<div class=\"es-veil pg-root\"><section class=\"es-dlg\" role=\"dialog\" aria-modal=\"true\"><h2>" + esc(heading) + "</h2>" + body + "<div class=\"es-dlg-act\">" + buttons + "</div></section></div>";
}
std::string App::mods_page() {
std::string rows;
for (size_t i = 0; i < front_snapshot_.entries.size(); ++i) {
const auto &entry = front_snapshot_.entries[i];
const bool active = entry.active && !front_external_override_, chosen = entry.id == selected_mod_;
rows += btn("mod-select", "<strong>" + esc(entry.name) + "</strong><span>" + esc(active ? "Aktiv" : entry.valid() ? entry.source : "Fehlerhaft") + " · " + esc(entry.type) + "</span>", std::string("es-li") + (chosen ? " sel" : ""),
"id=\"mod-entry-" + std::to_string(i) + "\" role=\"option\" aria-selected=\"" + (chosen ? "true" : "false") + "\" data-id=\"" + esc(entry.id) + "\" " + (front_busy_ ? "disabled=\"disabled\"" : ""));
}
if (rows.empty()) rows = "<span class=\"es-mut\" style=\"display:block;padding:" + es(8) + " " + es(12) + ";\">Noch keine Mods vorhanden.</span>";
const auto tab = [&](const char *id, const std::string &label) {
const bool on = front_tab_ == id;
return btn("front-tab", "<span>" + label + "</span>", on ? "on" : "", "id=\"mod-" + std::string(id) + "\" role=\"tab\" aria-selected=\"" + (on ? "true" : "false") + "\" data-id=\"" + id + "\" " + (front_busy_ ? "disabled=\"disabled\"" : ""));
};
const auto tabs = "<nav class=\"pg-tabs\" role=\"tablist\" style=\"margin-right:" + es(60) + ";\">" + tab("installed", "Installiert · " + std::to_string(front_snapshot_.entries.size())) + tab("downloads", "Downloads") + "</nav>";
const auto pane = front_tab_ == "installed"
? "<div class=\"es-fill\" style=\"gap:" + es(14) + ";align-items:stretch;\"><div class=\"es-list\" id=\"mod-list\" role=\"listbox\" aria-label=\"Mod auswählen\" style=\"width:" + es(270) + ";\">" + rows + "</div>" +
front_mod_details() + "</div>"
: std::string("<div class=\"es-box es-fill\" style=\"align-items:center;justify-content:center;\"><span class=\"es-mut\">Downloads folgen in einer späteren Version.</span></div>");
const bool selected = front_selected() != nullptr, enabled = !front_busy_ && selected && front_tab_ == "installed";
const auto feedback = front_busy_ ? front_feedback_ : !front_feedback_.empty() ? front_feedback_ : !front_snapshot_.error.empty() ? front_snapshot_.error : "Es kann genau eine Mod aktiv sein.";
const std::string off = "disabled=\"disabled\"";
const auto foot = (front_tab_ == "installed" ? pg_button("front-import", "Importieren", "sm", "id=\"front-import-button\" " + (front_busy_ ? off : std::string())) +
pg_button("mod-rename", "Umbenennen", "sm", "id=\"mod-rename-button\" " + (enabled ? std::string() : off)) +
pg_button("mod-remove", "Löschen", "sm", "id=\"mod-remove-button\" " + (enabled ? std::string() : off))
: std::string()) +
"<span class=\"es-note\" id=\"mod-feedback\">" + esc(feedback) + "</span>" + pg_button("front-home", "Zurück", "primary", "id=\"window-close\" " + (front_busy_ ? off : std::string()));
return entry_pad("Hauptmenü", "Mod", pane, foot, tabs, front_modal());
}
// Spiel laden from the main menu: the saves on the left, the chosen one on the right.
std::string App::render_files_pad() {
std::string entries;
for (size_t i = 0; i < files_rows_.size(); ++i) {
const auto &entry = files_rows_[i];
const bool chosen = files_selected_ == entry.id;
entries += btn("files-select", "<strong>" + esc(entry.name) + "</strong><span>" + esc(entry.valid() ? "Gespeichert am " + files_when(entry.created) : "Datei kann nicht geöffnet werden") + "</span>", std::string("es-li") + (chosen ? " sel" : ""),
"id=\"files-entry-" + std::to_string(i) + "\" role=\"option\" data-id=\"" + esc(entry.id) + "\" data-file-row=\"true\" aria-selected=\"" + (chosen ? "true" : "false") + "\"");
}
if (entries.empty()) entries = "<span class=\"es-mut\" style=\"display:block;padding:" + es(8) + " " + es(12) + ";\">" + std::string(files_native_ && engine_files_busy_ ? "Spielstände werden geladen …" : "Noch keine Spielstände vorhanden.") + "</span>";
std::string details;
try { details = files_page_details(false); }
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();
const std::string off = "disabled=\"disabled\"";
const auto feedback = files_feedback_.empty() ? std::string("Klick oder Pfeiltasten wählen einen Eintrag.") : files_feedback_;
return entry_pad("Hauptmenü", "Spiel laden",
"<div class=\"es-fill\" style=\"gap:" + es(14) + ";align-items:stretch;\"><div id=\"files-list\" class=\"es-list\" role=\"listbox\" aria-label=\"Spielstand auswählen\" style=\"width:" + es(290) + ";\">" + entries +
"</div><div class=\"es-box es-detail\">" + details + "</div></div>",
pg_button("files-import", "Importieren", "sm") + pg_button("files-rename", "Umbenennen", "sm", selected ? std::string() : off) +
pg_button("files-delete", "Löschen", "sm", files_entry_ && !files_entry_->token.empty() ? std::string() : off) + "<span class=\"es-note\" id=\"files-feedback\" role=\"status\">" + esc(feedback) + "</span>" +
pg_button("files-close", "Abbrechen") + pg_button("files-load", "Laden", "primary", "id=\"files-confirm\" " + (selected ? std::string() : off)));
}
Json App::front_snapshot_view() const {
Json rows = Json::array();
for (const auto &row : front_snapshot_.entries)
rows.push_back({{"id", row.id},
{"name", row.name},
{"type", row.type},
{"source", row.source},
{"version", row.version},
{"error", row.error},
{"active", row.active},
{"bytes", row.bytes},
{"file_count", row.file_count},
{"token", row.token}});
return {{"tab", front_tab_},
{"dialog", front_dialog_},
{"busy", front_busy_},
{"selected", selected_mod_},
{"active", active_mod_},
{"external_override", front_external_override_},
{"feedback", front_feedback_},
{"name_error", front_name_error_},
{"library_error", front_snapshot_.error},
{"entries", rows},
{"plan", front_plan_ ? Json{{"name", front_plan_->metadata.name},
{"type", front_plan_->metadata.type},
{"source", front_plan_->metadata.source},
{"bytes", front_plan_->metadata.bytes}}
: Json()}};
}