Complete the Modern main menu and persistent mod library (by Codex)

This commit is contained in:
Codex committed 2026-10-26 08:46:36 +01:00
1 parent ab4a962a39
commit 6bcd95d668
21 files changed
+2043 -248

No files matched your search

+20 -97
View File
@@ -26,6 +26,9 @@
#include "modern/ui/demo_files.hpp"
#include "modern/ui/gui_assets.hpp"
#include "modern/ui/model.hpp"
#include "modern/ui/mod_library.hpp"
#include <future>
#include <mutex>
#include "modern/ui/ticket_popover.hpp"
#include "modern/ui/view.hpp"
#include "version.hpp"
@@ -426,6 +429,7 @@ class App final : public Rml::EventListener {
#include "modern/ui/settings_state.inc"
#include "modern/ui/widgets_state.inc"
#include "modern/ui/files_state.inc"
#include "modern/ui/front_state.inc"
std::map<std::string, std::string> selections_;
Rml::Element *element(const std::string &id) const {
return doc_->GetElementById(id);
@@ -568,31 +572,10 @@ class App final : public Rml::EventListener {
dirty_ = true;
}
void collect_mods() {
mods_.clear();
const auto folder = root_ / "mods";
if (!fs::exists(folder))
return;
for (const auto &entry : fs::directory_iterator(folder)) {
if (!entry.is_directory() || entry.is_symlink() ||
editor::utf8(entry.path().filename()).starts_with('.'))
continue;
Mod m{editor::utf8(entry.path().filename()),
"",
{},
entry.path() / "content.obw",
{}};
try {
auto store = editor::ArchiveStore::open(m.file);
m.manifest = Json::parse(store->read("manifest.json"));
m.type = Catalog::modern_manifest(m.manifest) ? "Modern" : "Classic";
} catch (const std::exception &e) {
m.error = e.what();
m.type = "Unbekannt";
}
mods_.push_back(std::move(m));
}
std::sort(mods_.begin(), mods_.end(),
[](const auto &a, const auto &b) { return a.name < b.name; });
front_snapshot_=UiModLibrary(front_library_root()).snapshot();mods_.clear();
for(const auto &entry:front_snapshot_.entries)mods_.push_back({entry.name,entry.type,entry.error,entry.path/"content.obw",Json::object()});
active_mod_=front_external_override_?"":front_snapshot_.active.value_or("");
if(!front_selected())selected_mod_=front_snapshot_.entries.empty()?"":front_snapshot_.entries.front().id;
}
Mod *mod(const std::string &name) {
for (auto &m : mods_)
@@ -649,74 +632,8 @@ class App final : public Rml::EventListener {
: world_->leagues("nation:de").front()->value("id", "");
selected_club_ = manager(snap()).value("club", "");
}
std::string main_menu() {
const auto *m = mod(active_mod_);
std::string out =
"<div class=\"fill front-shade\"></div><div "
"class=\"brand\"><p>FUSSBALLMANAGER</p><h1>Open<span>BMH</span></h1></"
"div><div class=\"main-options\">";
const std::array<std::pair<std::string, std::string>, 6> actions = {
{{"new", "Neues Spiel"},
{"load", "Spiel laden"},
{"network", "Netzwerk"},
{"mods", "Mod"},
{"settings", "Einstellungen"},
{"exit", "Beenden"}}};
for (const auto &[key, name] : actions)
out += btn(
key,
(key == "network" ? "<span>" + esc(name) + "</span>" : esc(name)) +
(key == "network" ? "<small>Demnächst</small>" : ""),
{},
key == "network" || (key == "new" && !m && !world_) ? "disabled"
: "");
out +=
"</div><div class=\"front-footer\"><div><small>Aktive Mod</small><p>" +
esc(m ? m->name
: world_ ? world_->title()
: "Keine Mod aktiviert") +
"</p></div><small>v" + std::string(kOpenBmhVersion) +
(m && m->type == "Classic" ? "" : " · Modern UI Demo") +
"</small></div>";
return out;
}
std::string mods_page() {
if (selected_mod_.empty() && !mods_.empty())
selected_mod_ = mods_.front().name;
std::string left = "<h3 style=\"padding:28dp;\">Installierte Mods</h3><div "
"class=\"list\" style=\"height:1310dp;\">";
for (const auto &m : mods_)
left += btn(
"mod-select",
"<span class=\"grow\">" + esc(m.name) + "</span><span>" +
esc(m.type) + "</span>",
std::string("row choice ") +
(m.name == selected_mod_ ? "selected" : ""),
"data-id=\"" + esc(m.name) +
"\" style=\"width:100%;margin-bottom:12dp;min-height:120dp;\"");
left += "</div>";
std::string right;
if (auto *m = mod(selected_mod_))
right =
"<div class=\"column\" style=\"padding:38dp;\">" +
img("background", 1300, 400, false, true, 1600) + "<h2>" +
esc(m->name) + "</h2><p class=\"muted\">" + esc(m->type) +
(m->type == "Modern" ? " · Oberfläche bis zum Anstoß" : "") +
"</p><p>" + esc(m->error) + "</p>" +
btn("mod-activate", m->name == active_mod_ ? "Aktiv" : "Aktivieren",
"primary", m->name == active_mod_ ? "disabled" : "") +
"</div>";
return window(
"Mod",
"<div class=\"row\" style=\"height:1560dp;align-items:stretch;\"><div "
"class=\"panel\" style=\"width:1120dp;\">" +
left + "</div><div class=\"panel grow\">" + right +
"</div></div><div class=\"bottom-controls\">" +
btn("import-modern", "OBW-Paket hinzufügen") +
btn("import-classic", "BMH / Football Limited") +
btn("mod-rename", "Umbenennen") + btn("mod-remove", "Löschen") +
"</div>");
}
std::string main_menu();
std::string mods_page();
std::string render_desktop();
void init_desktop();
std::string widget(const std::string &, const Json &);
@@ -1056,6 +973,7 @@ class App final : public Rml::EventListener {
return true;
}
void frame() {
front_poll();
flush_selects();
if (ticket_)
ticket_->update();
@@ -1098,6 +1016,7 @@ class App final : public Rml::EventListener {
if (menu_ == "statistics") statistics_restore_scroll();
if (menu_ == "settings") settings_after_render();
files_after_render();
front_after_render();
if(menu_=="widgets" && widget_restore_scroll_){if(auto *gallery=element("widget-gallery"))gallery->SetScrollTop(widget_gallery_scroll_);widget_restore_scroll_=false;}
if (!report_option_to_scroll_.empty()) {
if (auto *node = element(report_option_to_scroll_))
@@ -1261,14 +1180,14 @@ public:
if (!config_.theme.empty()) theme_ = config_.theme;
if (theme_ != "midnight" && theme_ != "silver" && theme_ != "matchday")
throw editor::Error("Unbekanntes Modern-Theme.");
front_external_override_=!config_.world.empty();
collect_mods();
if (!mods_.empty())
active_mod_ = mods_.front().name;
if(config_.world.empty() && config_.scene=="mods")scene_="mods";
if (!config_.world.empty()) {
active_mod_.clear();
load_world(config_.world);
scene_ = config_.scene;
if (scene_ != "main" && scene_ != "newgame" && scene_ != "manager" &&
if (scene_ != "main" && scene_ != "mods" && scene_ != "newgame" && scene_ != "manager" &&
scene_ != "opening" && scene_ != "desktop") {
menu_ = scene_;
scene_ = "desktop";
@@ -1325,6 +1244,7 @@ public:
return 0;
}
while (!closed_) {
front_poll();
if (scene_ == "opening" && opening_page_ == 3 && draw_revealed_ < 64 &&
draw_playing_ && SDL_GetTicks64() >= draw_at_ &&
(SDL_GetWindowFlags(video_.window) & SDL_WINDOW_INPUT_FOCUS)) {
@@ -1342,7 +1262,8 @@ public:
bool got = SDL_WaitEventTimeout(&event, timeout) != 0;
while (got) {
if (event.type == SDL_QUIT) {
if (source_ && scene_ != "main") {
if(front_busy_){front_feedback_="Bitte den laufenden Import abwarten.";dirty_=true;}
else if (source_ && scene_ != "main" && scene_ != "mods") {
quit_closes_app_=true;
dispatch("context-quit", nullptr);
} else
@@ -1384,6 +1305,8 @@ public:
#include "modern/ui/widgets_controls.inc"
#include "modern/ui/files_screens.inc"
#include "modern/ui/files_controls.inc"
#include "modern/ui/front_screens.inc"
#include "modern/ui/front_controls.inc"
#include "modern/ui/screens.inc"
#include "modern/ui/sports_screens.inc"
#include "modern/ui/calendar_screen.inc"