// 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;
if (gui_.contains("menu.club-office"))
out = "
" +
img("menu.club-office", 3840, 2160, false, true, 2048) + "
";
out += "
";
const std::array, 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" || !menu_.empty() || network ||
(std::string(key) == "new" && !available &&
!(front_external_override_ && world_));
out += btn(key,
"" + std::string(title) + " " +
(network ? "Demnächst " : "") +
"› ",
"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 +=
"
";
return out;
}
std::string App::front_mod_details() {
const auto *entry = front_selected();
if (!entry)
return "Noch keine Mods "
"installiert Importiere einen Originalordner oder ein "
"OpenBMH-Paket.
";
const bool active = entry->active && !front_external_override_;
const auto provenance = entry->description.empty() ? front_source_name(*entry)
: entry->description;
std::string out =
"" +
img("background", 1360, 360, false, true, 1600) +
"OpenBMH
" +
esc(provenance) + "
" + esc(entry->name) +
" " +
(active ? "Aktiv"
: entry->valid() ? "Installiert"
: "Fehlerhaft") +
" ";
if (!entry->valid())
out += "
" + esc(entry->error) + "
";
const auto *current = mod(active_mod_);
out +=
"
" +
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.") +
"
";
return out +
btn("mod-activate", active ? "Aktiv" : "Aktivieren",
"front-mod-activate",
"id=\"mod-activate\" " +
std::string(active || !entry->valid() || front_busy_
? "disabled"
: "")) +
"
";
}
std::string App::front_modal() {
if (front_dialog_.empty())
return {};
std::string heading, body, buttons;
if (front_dialog_ == "choice") {
heading = "Mod importieren";
body = "Wähle einen Originalordner oder einen Export im "
"OpenBMH-Format.
";
const std::array, 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",
"" + std::string(c[1]) + " " + c[2] + " ",
"front-import-choice", "data-id=\"" + std::string(c[0]) + "\"");
body += "
";
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 = "Bezeichnung ";
if (importing && front_plan_) {
const auto &m = front_plan_->metadata;
body +=
"" + esc(m.description) + " · " +
esc(m.type) + " " + std::to_string(m.file_count) +
(m.file_count == 1 ? " Datei" : " Dateien") + " · " +
front_size(m.bytes) + "
" +
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.
";
}
body += "" +
esc(front_name_error_) + "
";
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 = "„" + esc(front_target_ ? front_target_->name : "") +
"“ wirklich aus der lokalen Bibliothek entfernen?
";
if (front_target_ && front_target_->active)
body += "Danach ist keine Mod aktiviert. "
"Wähle eine andere Mod für das nächste neue Spiel.
";
body += "Persönliche Spielstände und "
"Desktopansichten bleiben erhalten.
";
buttons = btn("front-dismiss", "Abbrechen") +
btn("front-delete-confirm", "Löschen", "primary");
} else {
heading = "Vorgang nicht möglich";
body = "" + esc(front_error_) + "
";
buttons = btn("front-dismiss", "Verstanden");
}
return "" +
esc(heading) + " " + body + "
";
}
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",
"" + esc(entry.name) +
" " +
(active
? "Aktiv "
: "" + esc(entry.valid() ? entry.source : "Fehlerhaft") +
" ") +
" " + esc(entry.type) +
" ",
"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 = "Noch keine Mods vorhanden.
";
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"
? "" + front_mod_details() + "
"
: "" +
img("icon.download", 180, 180) +
"Neue Welten entdecken Hier findest du später Mods "
"aus der zentralen OpenBMH-Datenbank.
" +
btn("front-noop", "Downloads demnächst", {}, "disabled") +
" ";
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 =
"" +
tabs + " " +
pane +
"
" +
esc(feedback) + "
" +
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")) +
"
";
return main_menu() +
"" +
btn("front-home", "× ", "close",
"id=\"window-close\" aria-label=\"Mod-Verwaltung schließen\" " +
std::string(front_busy_ ? "disabled" : "")) +
"Mod " + body + front_modal() + "
";
}
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()}};
}