Complete the Modern main menu and persistent mod library (by Codex)
This commit is contained in:
1 parent
ab4a962a39
commit
6bcd95d668
21 files changed
+2043
-248
No files matched your search
@@ -0,0 +1,288 @@
|
||||
// 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";
|
||||
}
|
||||
std::string App::main_menu() {
|
||||
const auto *active = mod(active_mod_);
|
||||
const bool available = active && active->error.empty();
|
||||
std::string out =
|
||||
"<div class=\"fill front-shade\"></div><div class=\"front-home\"><header "
|
||||
"class=\"brand\"><p>FUSSBALLMANAGER</p><h1>Open<span>BMH</span></h1></"
|
||||
"header><nav class=\"main-options\" aria-label=\"Hauptmenü\">";
|
||||
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 bool network = std::string(key) == "network",
|
||||
disabled = scene_ != "main" || network ||
|
||||
(std::string(key) == "new" && !available &&
|
||||
!(front_external_override_ && world_));
|
||||
out += btn(key,
|
||||
"<span>" + std::string(title) + "</span>" +
|
||||
(network ? "<small>Demnächst</small>" : "") +
|
||||
"<span class=\"front-hover-arrow\">›</span>",
|
||||
"front-menu-action",
|
||||
"id=\"front-" + std::string(key) + "\" " +
|
||||
(disabled ? "disabled" : ""));
|
||||
}
|
||||
const auto label = front_external_override_ && world_ ? world_->title()
|
||||
: available ? active->name
|
||||
: "Keine Mod aktiviert";
|
||||
out +=
|
||||
"</nav><footer class=\"front-footer\"><div class=\"front-active\"><span "
|
||||
"class=\"front-active-dot\"></span><div><small>Aktive Mod</small><strong "
|
||||
"id=\"front-active-name\">" +
|
||||
esc(label) + "</strong></div></div><small class=\"front-version\">v" +
|
||||
std::string(kOpenBmhVersion) + " · UI-Demo</small></footer></div>";
|
||||
return out;
|
||||
}
|
||||
std::string App::front_mod_details() {
|
||||
const auto *entry = front_selected();
|
||||
if (!entry)
|
||||
return "<div class=\"front-mod-empty\"><h2>Noch keine Mods "
|
||||
"installiert</h2><p>Importiere einen Originalordner oder ein "
|
||||
"OpenBMH-Paket.</p></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=\"front-mod-details\"><div class=\"front-mod-cover\">" +
|
||||
img("background", 1360, 360, false, true, 1600) +
|
||||
"<span>Open<span>BMH</span></span></div><header><div><p>" +
|
||||
esc(provenance) + "</p><h2>" + esc(entry->name) +
|
||||
"</h2></div><span class=\"front-mod-status " +
|
||||
(active ? "is-active" : "") + "\">" +
|
||||
(active ? "Aktiv"
|
||||
: entry->valid() ? "Installiert"
|
||||
: "Fehlerhaft") +
|
||||
"</span></header><div class=\"front-mod-metadata\">";
|
||||
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><span>" + esc(label) + "</span><strong>" + esc(value) +
|
||||
"</strong></div>";
|
||||
out += "</div>";
|
||||
if (!entry->valid())
|
||||
out += "<p class=\"front-mod-error\">" + esc(entry->error) + "</p>";
|
||||
const auto *current = mod(active_mod_);
|
||||
out +=
|
||||
"<p class=\"front-mod-activation-note\">" +
|
||||
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.") +
|
||||
"</p>";
|
||||
return out +
|
||||
btn("mod-activate", active ? "Aktiv" : "Aktivieren",
|
||||
"front-mod-activate",
|
||||
"id=\"mod-activate\" " +
|
||||
std::string(active || !entry->valid() || front_busy_
|
||||
? "disabled"
|
||||
: "")) +
|
||||
"</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><div class=\"front-import-choices\">";
|
||||
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>",
|
||||
"front-import-choice", "data-id=\"" + std::string(c[0]) + "\"");
|
||||
body += "</div>";
|
||||
buttons = btn("front-dismiss", "Abbrechen");
|
||||
} else if (front_dialog_ == "name" || front_dialog_ == "rename") {
|
||||
const bool importing = front_dialog_ == "name";
|
||||
heading = importing ? "Mod übernehmen" : "Mod umbenennen";
|
||||
body = "<label class=\"front-name-label\"><span>Bezeichnung</span><input "
|
||||
"type=\"text\" id=\"front-mod-name\" value=\"" +
|
||||
esc(front_name_) + "\" maxlength=\"64\"/></label>";
|
||||
if (importing && front_plan_) {
|
||||
const auto &m = front_plan_->metadata;
|
||||
body +=
|
||||
"<p class=\"front-import-summary\">" + esc(m.description) + " · " +
|
||||
esc(m.type) + "<br/>" + std::to_string(m.file_count) +
|
||||
(m.file_count == 1 ? " Datei" : " Dateien") + " · " +
|
||||
front_size(m.bytes) + "</p><p class=\"front-import-note\">" +
|
||||
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 += "<p id=\"front-name-error\" class=\"front-name-error\">" +
|
||||
esc(front_name_error_) + "</p>";
|
||||
buttons = btn("front-dismiss", "Abbrechen") +
|
||||
btn("front-name-confirm",
|
||||
importing ? "Importieren" : "Umbenennen", "primary",
|
||||
"id=\"front-name-confirm\" " +
|
||||
std::string(front_name_error_.empty() ? "" : "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=\"front-import-note\">Danach ist keine Mod aktiviert. "
|
||||
"Wähle eine andere Mod für das nächste neue Spiel.</p>";
|
||||
body += "<p class=\"front-import-note\">Persönliche Spielstände und "
|
||||
"Desktopansichten bleiben erhalten.</p>";
|
||||
buttons = btn("front-dismiss", "Abbrechen") +
|
||||
btn("front-delete-confirm", "Löschen", "primary");
|
||||
} else {
|
||||
heading = "Vorgang nicht möglich";
|
||||
body = "<p>" + esc(front_error_) + "</p>";
|
||||
buttons = btn("front-dismiss", "Verstanden");
|
||||
}
|
||||
return "<div class=\"front-dialog-layer\"><section class=\"front-dialog\" "
|
||||
"role=\"dialog\" aria-modal=\"true\"><h2>" +
|
||||
esc(heading) + "</h2>" + body + "<footer>" + buttons +
|
||||
"</footer></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_;
|
||||
rows += btn(
|
||||
"mod-select",
|
||||
"<span class=\"front-mod-copy\"><strong>" + esc(entry.name) +
|
||||
"</strong><small>" +
|
||||
(active
|
||||
? "<span "
|
||||
"class=\"front-mod-active-dot\"></span><span>Aktiv</span>"
|
||||
: "<span>" + esc(entry.valid() ? entry.source : "Fehlerhaft") +
|
||||
"</span>") +
|
||||
"</small></span><span class=\"front-mod-type\">" + esc(entry.type) +
|
||||
"</span>",
|
||||
"front-mod-entry " +
|
||||
std::string(entry.id == selected_mod_ ? "selected" : ""),
|
||||
"id=\"mod-entry-" + std::to_string(i) +
|
||||
"\" role=\"option\" aria-selected=\"" +
|
||||
(entry.id == selected_mod_ ? "true" : "false") + "\" data-id=\"" +
|
||||
esc(entry.id) + "\" " + (front_busy_ ? "disabled" : ""));
|
||||
}
|
||||
if (rows.empty())
|
||||
rows = "<p class=\"front-mod-empty-list\">Noch keine Mods vorhanden.</p>";
|
||||
const auto tabs =
|
||||
btn("front-tab",
|
||||
"Installiert · " + std::to_string(front_snapshot_.entries.size()),
|
||||
front_tab_ == "installed" ? "active" : "",
|
||||
"id=\"mod-installed\" role=\"tab\" aria-selected=\"" +
|
||||
std::string(front_tab_ == "installed" ? "true" : "false") +
|
||||
"\" data-id=\"installed\" " + (front_busy_ ? "disabled" : "")) +
|
||||
btn("front-tab", "Downloads", front_tab_ == "downloads" ? "active" : "",
|
||||
"id=\"mod-downloads\" role=\"tab\" aria-selected=\"" +
|
||||
std::string(front_tab_ == "downloads" ? "true" : "false") +
|
||||
"\" data-id=\"downloads\" " + (front_busy_ ? "disabled" : ""));
|
||||
const auto pane =
|
||||
front_tab_ == "installed"
|
||||
? "<div class=\"front-mod-layout\"><section "
|
||||
"class=\"front-mod-browser\"><header><span>Mod</span><span>Art</"
|
||||
"span></header><div class=\"front-mod-list\" id=\"mod-list\" "
|
||||
"role=\"listbox\" aria-label=\"Mod auswählen\">" +
|
||||
rows + "</div></section>" + front_mod_details() + "</div>"
|
||||
: "<section class=\"front-mod-downloads\">" +
|
||||
img("icon.download", 180, 180) +
|
||||
"<h2>Neue Welten entdecken</h2><p>Hier findest du später Mods "
|
||||
"aus der zentralen OpenBMH-Datenbank.</p>" +
|
||||
btn("front-noop", "Downloads demnächst", {}, "disabled") +
|
||||
"</section>";
|
||||
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 auto body =
|
||||
"<div class=\"front-mod-content\"><nav class=\"front-mod-tabs\" "
|
||||
"role=\"tablist\">" +
|
||||
tabs + "</nav><div class=\"front-mod-tabpanel\" role=\"tabpanel\">" +
|
||||
pane +
|
||||
"</div><footer class=\"front-mod-actions\"><p id=\"mod-feedback\">" +
|
||||
esc(feedback) + "</p><div>" +
|
||||
btn("front-import", "Importieren", {},
|
||||
"id=\"front-import-button\" " +
|
||||
std::string(front_busy_ ? "disabled" : "")) +
|
||||
btn("mod-rename", "Umbenennen", {},
|
||||
"id=\"mod-rename-button\" " +
|
||||
std::string(enabled ? "" : "disabled")) +
|
||||
btn("mod-remove", "Löschen", {},
|
||||
"id=\"mod-remove-button\" " +
|
||||
std::string(enabled ? "" : "disabled")) +
|
||||
"</div></footer></div>";
|
||||
return main_menu() +
|
||||
"<div class=\"fill front-mod-layer\" style=\"z-index:100;\"><section "
|
||||
"class=\"window front-mod-window\"><header class=\"titlebar\">" +
|
||||
btn("front-home", "<span>×</span>", "close",
|
||||
"id=\"window-close\" aria-label=\"Mod-Verwaltung schließen\" " +
|
||||
std::string(front_busy_ ? "disabled" : "")) +
|
||||
"<h1>Mod</h1></header>" + body + front_modal() + "</section></div>";
|
||||
}
|
||||
|
||||
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()}};
|
||||
}
|
||||
Reference in new issue
Block a user