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
@@ -140,6 +140,10 @@ int main(int argc, char** argv) {
|
||||
modern_config.file_import = launch::path_from_utf8(args[++i]);
|
||||
} else if (is("--ui-file-export") && value) {
|
||||
modern_config.file_export = launch::path_from_utf8(args[++i]);
|
||||
} else if (is("--ui-mods") && value) {
|
||||
modern_config.mods = launch::path_from_utf8(args[++i]);
|
||||
} else if (is("--ui-mod-import") && value) {
|
||||
modern_config.mod_import = launch::path_from_utf8(args[++i]);
|
||||
} else if (is("--ui-size") && value) {
|
||||
const auto size = args[++i];
|
||||
const auto separator = size.find('x');
|
||||
|
||||
@@ -2,8 +2,20 @@
|
||||
add_library(bmh_modern_ui_core STATIC catalog.cpp model.cpp gui_assets.cpp desktop.cpp demo_sports.cpp demo_calendar.cpp demo_reports.cpp demo_almanac.cpp demo_finance.cpp demo_environment.cpp demo_advertising.cpp demo_toto.cpp demo_lineup.cpp demo_transfer.cpp demo_career_reports.cpp demo_rankings.cpp demo_stadium.cpp demo_statistics.cpp demo_news.cpp demo_settings.cpp ui_preferences.cpp demo_widgets.cpp demo_files.cpp)
|
||||
target_include_directories(bmh_modern_ui_core PUBLIC ../..)
|
||||
target_link_libraries(bmh_modern_ui_core PUBLIC bmh_asset_io)
|
||||
add_library(bmh_modern_ui_mods STATIC mod_library.cpp)
|
||||
target_link_libraries(bmh_modern_ui_mods PUBLIC bmh_modern_ui_core bmh_launcher)
|
||||
add_executable(modern_mods_ui_tests ../../../tests/modern_mods_ui_tests.cpp)
|
||||
target_link_libraries(modern_mods_ui_tests PRIVATE bmh_modern_ui_mods)
|
||||
if(MSVC)
|
||||
target_compile_options(bmh_modern_ui_mods PRIVATE /W4 /utf-8)
|
||||
target_compile_options(modern_mods_ui_tests PRIVATE /W4 /utf-8)
|
||||
else()
|
||||
target_compile_options(bmh_modern_ui_mods PRIVATE -Wall -Wextra -Wpedantic)
|
||||
endif()
|
||||
add_test(NAME modern_mods_ui_tests COMMAND modern_mods_ui_tests)
|
||||
find_package(Threads REQUIRED)
|
||||
add_library(bmh_modern_ui STATIC view.cpp ticket_popover.cpp)
|
||||
target_link_libraries(bmh_modern_ui PUBLIC bmh_modern_ui_core PRIVATE bmh_rmlui bmh_launcher nfd::nfd ${BMH_SDL_TARGET})
|
||||
target_link_libraries(bmh_modern_ui PUBLIC bmh_modern_ui_core PRIVATE Threads::Threads bmh_modern_ui_mods bmh_rmlui bmh_launcher nfd::nfd ${BMH_SDL_TARGET})
|
||||
if(MSVC)
|
||||
target_compile_options(bmh_modern_ui_core PRIVATE /W4 /utf-8)
|
||||
target_compile_options(bmh_modern_ui PRIVATE /W4 /utf-8 /bigobj)
|
||||
@@ -14,7 +26,7 @@ endif()
|
||||
set(modern_assets "${CMAKE_BINARY_DIR}/assets/modern")
|
||||
FetchContent_GetProperties(rmlui)
|
||||
file(MAKE_DIRECTORY "${modern_assets}")
|
||||
foreach(asset modern.rml theme.rcss ticket.rcss sports.rcss calendar.rcss reports.rcss report_details.rcss report_pickers.rcss indoor.rcss planning.rcss almanac.rcss finance.rcss bank.rcss contracts.rcss amount.rcss environment.rcss advertising.rcss toto.rcss lineup.rcss transfer.rcss career_reports.rcss rankings.rcss stadium.rcss statistics.rcss news.rcss settings.rcss widgets.rcss files.rcss)
|
||||
foreach(asset modern.rml theme.rcss ticket.rcss sports.rcss calendar.rcss reports.rcss report_details.rcss report_pickers.rcss indoor.rcss planning.rcss almanac.rcss finance.rcss bank.rcss contracts.rcss amount.rcss environment.rcss advertising.rcss toto.rcss lineup.rcss transfer.rcss career_reports.rcss rankings.rcss stadium.rcss statistics.rcss news.rcss settings.rcss widgets.rcss files.rcss front.rcss)
|
||||
configure_file("${CMAKE_SOURCE_DIR}/assets/modern/${asset}" "${modern_assets}/${asset}" COPYONLY)
|
||||
endforeach()
|
||||
|
||||
|
||||
+12
-141
@@ -145,6 +145,7 @@ void App::ProcessEvent(Rml::Event &event) try {
|
||||
n = n->GetParentNode())
|
||||
if (n->GetId() == "native-ticket-layer")
|
||||
return;
|
||||
if(front_event(event))return;
|
||||
if (amount_event(event)) return;
|
||||
if (popup_.empty() && settings_event(event)) return;
|
||||
if (popup_.empty() && (files_event(event) || widget_event(event))) return;
|
||||
@@ -457,6 +458,7 @@ void App::ProcessEvent(Rml::Event &event) try {
|
||||
void App::dispatch(const std::string &action, Rml::Element *target) {
|
||||
const auto id =
|
||||
target ? target->GetAttribute<Rml::String>("data-id", "") : std::string();
|
||||
if(front_action(action,target))return;
|
||||
if (settings_action(action,target)) return;
|
||||
if (files_action(action,target) || widget_action(action,target)) return;
|
||||
if (lineup_action(action, target) || transfer_action(action, target)) return;
|
||||
@@ -618,6 +620,7 @@ void App::dispatch(const std::string &action, Rml::Element *target) {
|
||||
return;
|
||||
}
|
||||
if (action == "load") {
|
||||
if(auto *active=mod(active_mod_);active&&active->type=="Modern"&&(!world_||world_->source()!=fs::absolute(active->file).lexically_normal()))load_world(active->file);
|
||||
if (!source_) {
|
||||
if (auto *m = mod(active_mod_); m && m->type == "Modern")
|
||||
load_world(m->file);
|
||||
@@ -639,7 +642,7 @@ void App::dispatch(const std::string &action, Rml::Element *target) {
|
||||
contents->content_id,
|
||||
{},
|
||||
m->file.parent_path()};
|
||||
launch::ModLibrary library(root_);
|
||||
launch::ModLibrary library(front_library_root());
|
||||
const auto user = library.user_directory(entry);
|
||||
SDL_HideWindow(video_.window);
|
||||
const int code =
|
||||
@@ -674,142 +677,6 @@ void App::dispatch(const std::string &action, Rml::Element *target) {
|
||||
refresh();
|
||||
return;
|
||||
}
|
||||
if (action == "mod-select") {
|
||||
selected_mod_ = id;
|
||||
refresh();
|
||||
return;
|
||||
}
|
||||
if (action == "mod-activate") {
|
||||
if (auto *m = mod(selected_mod_)) {
|
||||
if (!m->error.empty()) {
|
||||
message(m->error);
|
||||
return;
|
||||
}
|
||||
active_mod_ = m->name;
|
||||
}
|
||||
refresh();
|
||||
return;
|
||||
}
|
||||
if (action == "mod-remove") {
|
||||
if (auto *m = mod(selected_mod_)) {
|
||||
const auto name = m->name;
|
||||
confirmation(
|
||||
"Mod „" + name + "“ löschen? Persönliche Daten bleiben erhalten.",
|
||||
[this, name] {
|
||||
auto *m = mod(name);
|
||||
if (!m)
|
||||
return;
|
||||
launch::ModLibrary library(root_);
|
||||
library.remove({m->name, m->type, {}, {}, m->file.parent_path()});
|
||||
if (active_mod_ == name)
|
||||
active_mod_.clear();
|
||||
selected_mod_.clear();
|
||||
collect_mods();
|
||||
refresh();
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (action == "mod-rename") {
|
||||
auto *m = mod(selected_mod_);
|
||||
if (!m)
|
||||
return;
|
||||
const auto previous = m->name;
|
||||
text_dialog("Mod umbenennen", previous,
|
||||
[this, previous](const std::string &name) {
|
||||
launch::ModLibrary::validate_name(name);
|
||||
auto *m = mod(previous);
|
||||
if (!m)
|
||||
throw editor::Error("Mod ist nicht mehr vorhanden.");
|
||||
launch::ModLibrary library(root_);
|
||||
library.rename(
|
||||
{m->name, m->type, {}, {}, m->file.parent_path()}, name);
|
||||
if (active_mod_ == previous)
|
||||
active_mod_ = name;
|
||||
selected_mod_ = name;
|
||||
collect_mods();
|
||||
refresh();
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (action == "import-modern") {
|
||||
NFD::Guard guard;
|
||||
NFD::UniquePath chosen;
|
||||
const nfdfilteritem_t filter[] = {{"OpenBMH-Welt", "obw"}};
|
||||
const auto result = NFD::OpenDialog(chosen, filter, 1);
|
||||
if (result == NFD_CANCEL)
|
||||
return;
|
||||
if (result != NFD_OKAY) {
|
||||
message("Die Dateiauswahl konnte nicht geöffnet werden.");
|
||||
return;
|
||||
}
|
||||
const auto file = editor::path(chosen.get());
|
||||
auto candidate = Catalog::open(file);
|
||||
auto initial = candidate->title();
|
||||
for (char &c : initial)
|
||||
if (std::string("/\\:*?\"<>|").find(c) != std::string::npos)
|
||||
c = '-';
|
||||
if (initial.empty())
|
||||
initial = "Modern";
|
||||
text_dialog("Bezeichnung der neuen Mod", initial,
|
||||
[this, file](const std::string &name) {
|
||||
launch::ModLibrary::validate_name(name);
|
||||
const auto destination = root_ / "mods" / editor::path(name);
|
||||
if (fs::exists(destination))
|
||||
throw editor::Error(
|
||||
"Eine Mod mit diesem Namen ist bereits vorhanden.");
|
||||
fs::create_directories(destination.parent_path());
|
||||
const auto staging =
|
||||
destination.parent_path() /
|
||||
(".ui-import-" + std::to_string(SDL_GetTicks64()));
|
||||
if (!fs::create_directory(staging))
|
||||
throw editor::Error("Import wird bereits vorbereitet.");
|
||||
try {
|
||||
fs::copy_file(file, staging / "content.obw");
|
||||
(void)Catalog::open(staging / "content.obw");
|
||||
fs::rename(staging, destination);
|
||||
} catch (...) {
|
||||
fs::remove_all(staging);
|
||||
throw;
|
||||
}
|
||||
collect_mods();
|
||||
selected_mod_ = name;
|
||||
refresh();
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (action == "import-classic") {
|
||||
NFD::Guard guard;
|
||||
NFD::UniquePath chosen;
|
||||
const auto result = NFD::PickFolder(chosen);
|
||||
if (result == NFD_CANCEL)
|
||||
return;
|
||||
if (result != NFD_OKAY) {
|
||||
message("Die Ordnerauswahl konnte nicht geöffnet werden.");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
launch::AddMod request;
|
||||
request.source = editor::path(chosen.get());
|
||||
const auto game = launch::check_game_directory(request.source);
|
||||
request.name = game.family == launch::GameFamily::english ? "FTDL-classic"
|
||||
: "BMH-classic";
|
||||
request.migrate = false;
|
||||
text_dialog("Bezeichnung der neuen Mod", request.name,
|
||||
[this, request](const std::string &name) mutable {
|
||||
launch::ModLibrary::validate_name(name);
|
||||
request.name = name;
|
||||
launch::ModLibrary library(root_);
|
||||
library.add(request, migrate_);
|
||||
collect_mods();
|
||||
selected_mod_ = name;
|
||||
refresh();
|
||||
});
|
||||
} catch (const std::exception &e) {
|
||||
message(e.what());
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (action == "setup-step") {
|
||||
const auto step = target->GetAttribute<int>("data-step", 0);
|
||||
const int limit = id == "duration" ? 5
|
||||
@@ -1082,7 +949,7 @@ void App::dispatch(const std::string &action, Rml::Element *target) {
|
||||
}
|
||||
}
|
||||
void App::change(Rml::Element *target) {
|
||||
if(files_change(target) || widget_change(target) || settings_change(target))return;
|
||||
if(front_change(target)||files_change(target) || widget_change(target) || settings_change(target))return;
|
||||
const auto kind = target->GetAttribute<Rml::String>("data-change", "");
|
||||
auto *control = dynamic_cast<Rml::ElementFormControl *>(target);
|
||||
if (!control)
|
||||
@@ -1146,7 +1013,7 @@ void App::change(Rml::Element *target) {
|
||||
}
|
||||
}
|
||||
void App::input(Rml::Element *target) {
|
||||
if(files_change(target) || widget_change(target) || settings_change(target))return;
|
||||
if(front_change(target)||files_change(target) || widget_change(target) || settings_change(target))return;
|
||||
const auto kind = target->GetAttribute<Rml::String>("data-input", "");
|
||||
auto *control = dynamic_cast<Rml::ElementFormControl *>(target);
|
||||
if (!control)
|
||||
@@ -1211,7 +1078,11 @@ void App::script() {
|
||||
try {
|
||||
const auto command = Json::parse(line);
|
||||
const auto type = command.value("type", std::string());
|
||||
if (type == "click" || type == "right") {
|
||||
if(type=="front-wait"){
|
||||
const auto end=SDL_GetTicks64()+command.value("timeout_ms",uint64_t(300000));
|
||||
while(front_busy_&&SDL_GetTicks64()<end){front_poll();if(needs_render_||dirty_)frame();SDL_Delay(10);}
|
||||
if(front_busy_)throw editor::Error("Modvorgang hat das QA-Zeitlimit überschritten.");
|
||||
} else if (type == "click" || type == "right") {
|
||||
const auto point = locate(command);
|
||||
const int button = type == "right" ? 1 : 0;
|
||||
context_->ProcessMouseMove(point.x, point.y, 0);
|
||||
@@ -1274,7 +1145,7 @@ void App::script() {
|
||||
{"transfer_view", transfer_view_}, {"transfer_dialog", transfer_dialog_}, {"transfer_draft", transfer_draft_},
|
||||
{"career_view", career_view_}, {"rankings_view", rankings_view_},
|
||||
{"stadium_view", stadium_view_},
|
||||
{"files_view",{{"mode",files_mode_},{"selected",files_selected_},{"name",files_name_},{"feedback",files_feedback_}}}, {"widget_view",{{"query",widget_query_},{"notice",widget_notice_}}}, {"ui_preferences",ui_preferences_}, {"settings_draft",settings_draft_}, {"settings_category",settings_category_}, {"settings_query",settings_query_}, {"settings_notice",settings_notice_},
|
||||
{"front_view",front_snapshot_view()}, {"files_view",{{"mode",files_mode_},{"selected",files_selected_},{"name",files_name_},{"feedback",files_feedback_}}}, {"widget_view",{{"query",widget_query_},{"notice",widget_notice_}}}, {"ui_preferences",ui_preferences_}, {"settings_draft",settings_draft_}, {"settings_category",settings_category_}, {"settings_query",settings_query_}, {"settings_notice",settings_notice_},
|
||||
{"statistics_view", statistics_view_}, {"statistics_trophy", statistics_trophy_},
|
||||
{"statistics_scrolls", statistics_scrolls_},
|
||||
{"news_view", news_view_}, {"news_dialog", news_dialog_},
|
||||
|
||||
@@ -0,0 +1,460 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
void App::front_invalidate_world() {
|
||||
ticket_.reset();
|
||||
source_.reset();
|
||||
world_.reset();
|
||||
renderer_.world(nullptr);
|
||||
reset_files();
|
||||
reset_settings();
|
||||
reset_news();
|
||||
desktop_ = Json::object();
|
||||
saved_desktop_ = Json::object();
|
||||
working_desktop_initialized_ = false;
|
||||
working_desktop_base_ = Json();
|
||||
files_default_key_.clear();
|
||||
files_default_picture_ = Picture();
|
||||
files_default_pending_ = false;
|
||||
undo_.clear();
|
||||
undo_themes_.clear();
|
||||
pending_selects_.clear();
|
||||
amount_.reset();
|
||||
}
|
||||
void App::front_start(std::function<FrontResult()> work) {
|
||||
if (front_busy_)
|
||||
return;
|
||||
front_busy_ = true;
|
||||
front_dialog_.clear();
|
||||
front_feedback_ = "Dateien werden verarbeitet …";
|
||||
front_job_ = std::async(std::launch::async, std::move(work));
|
||||
refresh();
|
||||
}
|
||||
void App::front_poll() {
|
||||
if (!front_busy_ || !front_job_.valid())
|
||||
return;
|
||||
if (front_job_.wait_for(std::chrono::milliseconds(0)) !=
|
||||
std::future_status::ready) {
|
||||
if (front_progress_) {
|
||||
std::lock_guard lock(front_progress_->mutex);
|
||||
if (!front_progress_->text.empty() &&
|
||||
front_progress_->text != front_feedback_) {
|
||||
front_feedback_ = front_progress_->text;
|
||||
if (auto *text = element("mod-feedback"))
|
||||
text->SetInnerRML(esc(front_feedback_));
|
||||
dirty_ = true;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
const auto previous = active_mod_;
|
||||
front_busy_ = false;
|
||||
try {
|
||||
auto result = front_job_.get();
|
||||
if (result.plan) {
|
||||
front_plan_ = std::move(result.plan);
|
||||
front_name_ = front_plan_->metadata.name;
|
||||
front_dialog_ = "name";
|
||||
front_feedback_.clear();
|
||||
front_selection_token_ = front_snapshot_.selection_token;
|
||||
front_validate_name();
|
||||
focus_after_render_ = "front-mod-name";
|
||||
front_select_name_ = true;
|
||||
} else {
|
||||
if (result.activate)
|
||||
front_external_override_ = false;
|
||||
selected_mod_ = result.selected;
|
||||
collect_mods();
|
||||
front_plan_.reset();
|
||||
front_target_.reset();
|
||||
front_feedback_ = result.feedback;
|
||||
if ((!front_external_override_ && previous != active_mod_) ||
|
||||
(world_ && !fs::exists(world_->source()))) {
|
||||
front_external_override_ = false;
|
||||
front_invalidate_world();
|
||||
}
|
||||
front_select(selected_mod_);
|
||||
}
|
||||
} catch (const std::exception &error) {
|
||||
front_error_ = error.what();
|
||||
front_dialog_ = "error";
|
||||
front_plan_.reset();
|
||||
front_target_.reset();
|
||||
try {
|
||||
collect_mods();
|
||||
if (!front_external_override_ && previous != active_mod_)
|
||||
front_invalidate_world();
|
||||
} catch (const std::exception &) { /* The original error remains visible. */
|
||||
}
|
||||
}
|
||||
front_progress_.reset();
|
||||
refresh();
|
||||
}
|
||||
void App::front_validate_name() {
|
||||
front_name_error_.clear();
|
||||
try {
|
||||
const auto clean = UiModLibrary::clean_name(front_name_),
|
||||
key = UiModLibrary::name_key(clean);
|
||||
for (const auto &entry : front_snapshot_.entries) {
|
||||
if (front_dialog_ == "rename" && front_target_ &&
|
||||
entry.id == front_target_->id)
|
||||
continue;
|
||||
std::string existing;
|
||||
try {
|
||||
existing = UiModLibrary::name_key(entry.name);
|
||||
} catch (const std::exception &) {
|
||||
continue;
|
||||
}
|
||||
if (existing == key)
|
||||
throw editor::Error("Diese Mod-Bezeichnung wird bereits verwendet.");
|
||||
}
|
||||
} catch (const std::exception &error) {
|
||||
front_name_error_ = error.what();
|
||||
}
|
||||
if (auto *error = element("front-name-error"))
|
||||
error->SetInnerRML(esc(front_name_error_));
|
||||
if (auto *button = element("front-name-confirm")) {
|
||||
if (front_name_error_.empty() && !front_busy_)
|
||||
button->RemoveAttribute("disabled");
|
||||
else
|
||||
button->SetAttribute("disabled", true);
|
||||
}
|
||||
dirty_ = true;
|
||||
}
|
||||
void App::front_select(const std::string &id) {
|
||||
selected_mod_ = id;
|
||||
front_reveal_selection_ = true;
|
||||
for (size_t i = 0; i < front_snapshot_.entries.size(); ++i)
|
||||
if (front_snapshot_.entries[i].id == id)
|
||||
focus_after_render_ = "mod-entry-" + std::to_string(i);
|
||||
refresh();
|
||||
}
|
||||
void App::front_after_render() {
|
||||
if (scene_ != "mods")
|
||||
return;
|
||||
if (front_select_name_) {
|
||||
if (auto *input = dynamic_cast<Rml::ElementFormControlInput *>(
|
||||
element("front-mod-name")))
|
||||
input->Select();
|
||||
front_select_name_ = false;
|
||||
}
|
||||
if (auto *list = element("mod-list")) {
|
||||
if (front_restore_scroll_) {
|
||||
list->SetScrollTop(front_list_scroll_);
|
||||
front_restore_scroll_ = false;
|
||||
}
|
||||
if (front_reveal_selection_) {
|
||||
for (size_t i = 0; i < front_snapshot_.entries.size(); ++i)
|
||||
if (front_snapshot_.entries[i].id == selected_mod_)
|
||||
if (auto *row = element("mod-entry-" + std::to_string(i)))
|
||||
row->ScrollIntoView(
|
||||
Rml::ScrollIntoViewOptions(Rml::ScrollAlignment::Nearest));
|
||||
front_reveal_selection_ = false;
|
||||
}
|
||||
}
|
||||
if (!front_dialog_.empty()) {
|
||||
Rml::ElementList behind;
|
||||
doc_->QuerySelectorAll(
|
||||
behind, ".front-mod-content button,.front-mod-window>.titlebar button");
|
||||
for (auto *control : behind) {
|
||||
control->SetAttribute("disabled", true);
|
||||
control->SetProperty("pointer-events", "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
void App::front_pick(const std::string &kind) {
|
||||
if (front_busy_)
|
||||
return;
|
||||
fs::path selected = config_.mod_import;
|
||||
if (selected.empty()) {
|
||||
NFD::Guard guard;
|
||||
NFD::UniquePath chosen;
|
||||
const nfdfilteritem_t filters[] = {{"OpenBMH-Weltpaket", "obw,zip"}};
|
||||
const auto result = kind == "package" ? NFD::OpenDialog(chosen, filters, 1)
|
||||
: NFD::PickFolder(chosen);
|
||||
if (result == NFD_CANCEL)
|
||||
return;
|
||||
if (result != NFD_OKAY) {
|
||||
front_error_ = "Die Dateiauswahl konnte nicht geöffnet werden.";
|
||||
front_dialog_ = "error";
|
||||
refresh();
|
||||
return;
|
||||
}
|
||||
selected = editor::path(chosen.get());
|
||||
}
|
||||
const auto root = front_library_root();
|
||||
front_start([root, selected] {
|
||||
UiModLibrary library(root);
|
||||
FrontResult result;
|
||||
result.plan = library.inspect(selected);
|
||||
return result;
|
||||
});
|
||||
}
|
||||
bool App::front_change(Rml::Element *target) {
|
||||
if (!target || target->GetId() != "front-mod-name" || front_busy_)
|
||||
return false;
|
||||
front_name_ = field("front-mod-name");
|
||||
front_validate_name();
|
||||
return true;
|
||||
}
|
||||
bool App::front_action(const std::string &action, Rml::Element *target) {
|
||||
const bool front = scene_ == "main" || scene_ == "mods";
|
||||
if (!front)
|
||||
return false;
|
||||
if (front_busy_) {
|
||||
if (action != "")
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
const auto id =
|
||||
target ? target->GetAttribute<Rml::String>("data-id", "") : std::string();
|
||||
if (action == "load") {
|
||||
if (auto *active = mod(active_mod_);
|
||||
active && active->type == "Classic" && active->error.empty()) {
|
||||
dispatch("new", target);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (action == "mods") {
|
||||
collect_mods();
|
||||
front_tab_ = "installed";
|
||||
front_dialog_.clear();
|
||||
front_plan_.reset();
|
||||
front_feedback_.clear();
|
||||
front_list_scroll_ = 0;
|
||||
if (!front_selected())
|
||||
selected_mod_ = front_snapshot_.entries.empty()
|
||||
? ""
|
||||
: front_snapshot_.entries.front().id;
|
||||
scene_ = "mods";
|
||||
focus_after_render_ = "mod-installed";
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
if (action == "front-home" || (action == "close" && scene_ == "mods")) {
|
||||
scene_ = "main";
|
||||
front_dialog_.clear();
|
||||
front_plan_.reset();
|
||||
front_target_.reset();
|
||||
focus_after_render_ = "front-mods";
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
if (action == "front-tab") {
|
||||
if (auto *list = element("mod-list"))
|
||||
front_list_scroll_ = list->GetScrollTop();
|
||||
if (id == "installed" || id == "downloads") {
|
||||
front_tab_ = id;
|
||||
front_restore_scroll_ = true;
|
||||
focus_after_render_ =
|
||||
id == "installed" ? "mod-installed" : "mod-downloads";
|
||||
refresh();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (action == "mod-select") {
|
||||
front_select(id);
|
||||
return true;
|
||||
}
|
||||
if (action == "front-import") {
|
||||
front_dialog_ = "choice";
|
||||
front_return_focus_ = "front-import-button";
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
if (action == "front-pick") {
|
||||
front_pick(id);
|
||||
return true;
|
||||
}
|
||||
if (action == "front-dismiss") {
|
||||
front_dialog_.clear();
|
||||
front_plan_.reset();
|
||||
front_target_.reset();
|
||||
front_name_error_.clear();
|
||||
focus_after_render_ =
|
||||
front_return_focus_.empty() ? "mod-installed" : front_return_focus_;
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
if (action == "front-name-confirm") {
|
||||
front_name_ = field("front-mod-name");
|
||||
front_validate_name();
|
||||
if (!front_name_error_.empty())
|
||||
return true;
|
||||
const auto name = UiModLibrary::clean_name(front_name_);
|
||||
const auto root = front_library_root();
|
||||
if (front_dialog_ == "name" && front_plan_) {
|
||||
const auto plan = *front_plan_;
|
||||
front_progress_ = std::make_shared<FrontProgress>();
|
||||
const auto progress = front_progress_;
|
||||
front_start([root, plan, name, progress] {
|
||||
UiModLibrary library(root);
|
||||
const auto row =
|
||||
library.commit(plan, name, [progress](const std::string &text) {
|
||||
std::lock_guard lock(progress->mutex);
|
||||
progress->text = text;
|
||||
});
|
||||
return FrontResult{{},
|
||||
row.id,
|
||||
"Mod importiert. Du kannst sie jetzt aktivieren.",
|
||||
false};
|
||||
});
|
||||
} else if (front_dialog_ == "rename" && front_target_) {
|
||||
const auto row = *front_target_;
|
||||
const auto token = front_selection_token_;
|
||||
front_start([root, row, name, token] {
|
||||
UiModLibrary library(root);
|
||||
const auto renamed = library.rename(row, name, token);
|
||||
return FrontResult{{}, renamed.id, "Mod umbenannt.", false};
|
||||
});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (action == "mod-rename") {
|
||||
if (auto *entry = front_selected()) {
|
||||
front_target_ = *entry;
|
||||
front_selection_token_ = front_snapshot_.selection_token;
|
||||
front_name_ = entry->name;
|
||||
front_dialog_ = "rename";
|
||||
front_return_focus_ = "mod-rename-button";
|
||||
front_validate_name();
|
||||
focus_after_render_ = "front-mod-name";
|
||||
front_select_name_ = true;
|
||||
refresh();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (action == "mod-remove") {
|
||||
if (auto *entry = front_selected()) {
|
||||
front_target_ = *entry;
|
||||
front_selection_token_ = front_snapshot_.selection_token;
|
||||
front_dialog_ = "delete";
|
||||
front_return_focus_ = "mod-remove-button";
|
||||
refresh();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (action == "front-delete-confirm" && front_target_) {
|
||||
const auto entry = *front_target_;
|
||||
const auto token = front_selection_token_;
|
||||
const auto root = front_library_root();
|
||||
front_start([root, entry, token] {
|
||||
UiModLibrary library(root);
|
||||
library.remove(entry, token);
|
||||
return FrontResult{
|
||||
{}, "", "Mod entfernt. Persönliche Daten wurden erhalten.", false};
|
||||
});
|
||||
return true;
|
||||
}
|
||||
if (action == "mod-activate") {
|
||||
if (auto *entry = front_selected(); entry && entry->valid()) {
|
||||
const auto row = *entry;
|
||||
const auto token = front_snapshot_.selection_token;
|
||||
const auto root = front_library_root();
|
||||
front_start([root, row, token] {
|
||||
UiModLibrary library(root);
|
||||
library.activate(row, token);
|
||||
return FrontResult{{}, row.id, "Mod aktiviert.", true};
|
||||
});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (action == "front-noop" || action == "network")
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
bool App::front_event(Rml::Event &event) {
|
||||
if (scene_ != "main" && scene_ != "mods")
|
||||
return false;
|
||||
if (!popup_.empty() || !menu_.empty())
|
||||
return false;
|
||||
const auto type = event.GetType();
|
||||
auto *target = event.GetTargetElement();
|
||||
if ((type == "input" || type == "change") && front_change(target))
|
||||
return true;
|
||||
if (type != "keydown")
|
||||
return false;
|
||||
const auto key =
|
||||
Rml::Input::KeyIdentifier(event.GetParameter<int>("key_identifier", 0));
|
||||
if (front_busy_) {
|
||||
event.StopImmediatePropagation();
|
||||
return true;
|
||||
}
|
||||
if (key == Rml::Input::KI_ESCAPE) {
|
||||
if (!front_dialog_.empty())
|
||||
front_action("front-dismiss", nullptr);
|
||||
else if (scene_ == "mods")
|
||||
front_action("front-home", nullptr);
|
||||
event.StopImmediatePropagation();
|
||||
return true;
|
||||
}
|
||||
if (!front_dialog_.empty() && target->GetId() == "front-mod-name" &&
|
||||
(key == Rml::Input::KI_RETURN || key == Rml::Input::KI_NUMPADENTER)) {
|
||||
front_action("front-name-confirm", nullptr);
|
||||
event.StopImmediatePropagation();
|
||||
return true;
|
||||
}
|
||||
if (key == Rml::Input::KI_TAB) {
|
||||
Rml::ElementList controls;
|
||||
auto *region = scene_ == "main" ? doc_->QuerySelector(".main-options")
|
||||
: !front_dialog_.empty()
|
||||
? doc_->QuerySelector(".front-dialog")
|
||||
: doc_->QuerySelector(".front-mod-window");
|
||||
if (region)
|
||||
region->QuerySelectorAll(controls, "button,input,select");
|
||||
std::erase_if(controls, [](auto *node) {
|
||||
return node->HasAttribute("disabled") || !node->IsVisible(true);
|
||||
});
|
||||
if (!controls.empty()) {
|
||||
const auto it = std::find(controls.begin(), controls.end(),
|
||||
context_->GetFocusElement());
|
||||
const int pos = it == controls.end() ? -1 : int(it - controls.begin()),
|
||||
n = int(controls.size());
|
||||
const bool reverse = event.GetParameter<int>("shift_key", 0) != 0;
|
||||
controls[size_t(pos < 0 ? (reverse ? n - 1 : 0)
|
||||
: (pos + (reverse ? -1 : 1) + n) % n)]
|
||||
->Focus(true);
|
||||
}
|
||||
event.StopImmediatePropagation();
|
||||
return true;
|
||||
}
|
||||
if (front_dialog_.empty() &&
|
||||
(key == Rml::Input::KI_UP || key == Rml::Input::KI_DOWN ||
|
||||
key == Rml::Input::KI_HOME || key == Rml::Input::KI_END)) {
|
||||
if (scene_ == "main") {
|
||||
Rml::ElementList options;
|
||||
doc_->QuerySelectorAll(options, ".main-options button");
|
||||
std::erase_if(options,
|
||||
[](auto *n) { return n->HasAttribute("disabled"); });
|
||||
if (!options.empty()) {
|
||||
const auto it = std::find(options.begin(), options.end(),
|
||||
context_->GetFocusElement());
|
||||
const int n = int(options.size()),
|
||||
pos = it == options.end() ? 0 : int(it - options.begin());
|
||||
const int index =
|
||||
key == Rml::Input::KI_HOME ? 0
|
||||
: key == Rml::Input::KI_END
|
||||
? n - 1
|
||||
: (pos + (key == Rml::Input::KI_UP ? -1 : 1) + n) % n;
|
||||
options[size_t(index)]->Focus(true);
|
||||
}
|
||||
event.StopImmediatePropagation();
|
||||
return true;
|
||||
}
|
||||
if (target->IsClassSet("front-mod-entry")) {
|
||||
size_t index = 0;
|
||||
for (size_t i = 0; i < front_snapshot_.entries.size(); ++i)
|
||||
if (front_snapshot_.entries[i].id == selected_mod_)
|
||||
index = i;
|
||||
if (!front_snapshot_.entries.empty()) {
|
||||
index = key == Rml::Input::KI_HOME ? 0
|
||||
: key == Rml::Input::KI_END ? front_snapshot_.entries.size() - 1
|
||||
: key == Rml::Input::KI_UP
|
||||
? (index ? index - 1 : 0)
|
||||
: std::min(index + 1, front_snapshot_.entries.size() - 1);
|
||||
front_select(front_snapshot_.entries[index].id);
|
||||
}
|
||||
event.StopImmediatePropagation();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -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()}};
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
struct FrontProgress {
|
||||
std::mutex mutex;
|
||||
std::string text;
|
||||
};
|
||||
struct FrontResult {
|
||||
std::optional<ModImportPlan> plan;
|
||||
std::string selected, feedback;
|
||||
bool activate = false;
|
||||
};
|
||||
ModSnapshot front_snapshot_;
|
||||
std::string front_tab_ = "installed", front_dialog_, front_name_,
|
||||
front_name_error_, front_feedback_, front_error_,
|
||||
front_return_focus_;
|
||||
std::optional<ModImportPlan> front_plan_;
|
||||
std::optional<UiModEntry> front_target_;
|
||||
std::string front_selection_token_;
|
||||
std::future<FrontResult> front_job_;
|
||||
std::shared_ptr<FrontProgress> front_progress_;
|
||||
bool front_busy_ = false, front_external_override_ = false;
|
||||
float front_list_scroll_ = 0;
|
||||
bool front_restore_scroll_ = false, front_reveal_selection_ = false;
|
||||
fs::path front_library_root() const;
|
||||
const UiModEntry *front_selected() const;
|
||||
std::string front_source_name(const UiModEntry &) const;
|
||||
std::string front_size(uint64_t) const;
|
||||
std::string front_modal();
|
||||
std::string front_mod_details();
|
||||
void front_start(std::function<FrontResult()>);
|
||||
void front_poll();
|
||||
void front_pick(const std::string &);
|
||||
void front_validate_name();
|
||||
void front_select(const std::string &);
|
||||
void front_after_render();
|
||||
void front_invalidate_world();
|
||||
bool front_action(const std::string &, Rml::Element *);
|
||||
bool front_event(Rml::Event &);
|
||||
bool front_change(Rml::Element *);
|
||||
|
||||
Json front_snapshot_view() const;
|
||||
|
||||
bool front_select_name_ = false;
|
||||
@@ -0,0 +1,405 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/ui/mod_library.hpp"
|
||||
#include "modern/ui/demo_files.hpp"
|
||||
#include "content/package.hpp"
|
||||
#include "launch/mods.hpp"
|
||||
#include "launch/game_data.hpp"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <fstream>
|
||||
#include <set>
|
||||
|
||||
namespace bmh::modern_ui {
|
||||
namespace {
|
||||
constexpr uint64_t limit = 512ull * 1024 * 1024;
|
||||
constexpr const char *selection_file = ".ui-active-mod.json";
|
||||
constexpr const char *journal_file = ".ui-mod-transaction.json";
|
||||
void directory(const fs::path &path, bool create = false) {
|
||||
fs::path cursor;
|
||||
for (const auto &part : fs::absolute(path).lexically_normal()) {
|
||||
cursor /= part;
|
||||
const auto status = fs::symlink_status(cursor);
|
||||
if (fs::is_symlink(status) || (fs::exists(status) && !fs::is_directory(status)))
|
||||
throw editor::Error("Unsicheres Mod-Verzeichnis.");
|
||||
}
|
||||
if (create) fs::create_directories(path);
|
||||
}
|
||||
std::string regular(const fs::path &path, uint64_t maximum = limit) {
|
||||
if (fs::is_symlink(fs::symlink_status(path)) || !fs::is_regular_file(path))
|
||||
throw editor::Error("Die Mod-Datei fehlt oder ist verknüpft.");
|
||||
return editor::read_file(path, maximum);
|
||||
}
|
||||
std::string file_digest(const fs::path &path) {
|
||||
if (fs::is_symlink(fs::symlink_status(path)) || !fs::is_regular_file(path) || fs::file_size(path) > limit)
|
||||
throw editor::Error("Unsichere oder zu große Mod-Datei.");
|
||||
std::ifstream stream(path, std::ios::binary);
|
||||
if (!stream) throw editor::Error("Mod-Datei nicht lesbar.");
|
||||
std::string buffer(1024 * 1024, '\0'), blocks; uint64_t count = 0;
|
||||
while (stream) {
|
||||
stream.read(buffer.data(), std::streamsize(buffer.size()));
|
||||
const auto received = stream.gcount();
|
||||
if (received > 0) { count += uint64_t(received); if (count > limit) throw editor::Error("Mod-Datei zu groß."); blocks += content::sha256(std::string_view(buffer.data(), size_t(received))); }
|
||||
}
|
||||
if (!stream.eof() || count != fs::file_size(path)) throw editor::Error("Mod-Datei wurde beim Lesen geändert.");
|
||||
return content::sha256(std::to_string(count) + ":" + blocks);
|
||||
}
|
||||
struct Temp {
|
||||
fs::path path;
|
||||
Temp() : path(fs::temp_directory_path() / editor::new_id("openbmh-mod-plan-")) {
|
||||
if (!fs::create_directory(path)) throw editor::Error("Temporärer Mod-Ordner nicht verfügbar.");
|
||||
}
|
||||
~Temp() { std::error_code error; fs::remove_all(path, error); }
|
||||
};
|
||||
struct Lock {
|
||||
fs::path path;
|
||||
explicit Lock(const fs::path &root) : path(root / ".ui-mod-lock") {
|
||||
directory(root, true);
|
||||
if (!fs::create_directory(path)) throw editor::Error("Die Mod-Bibliothek ist gerade belegt.");
|
||||
}
|
||||
~Lock() { std::error_code error; fs::remove(path, error); }
|
||||
};
|
||||
void member_name(const std::string &name) {
|
||||
try { UiModLibrary::clean_name(name); }
|
||||
catch (const std::exception &) {
|
||||
// Existing 0.2 ASCII names may exceed the new UI's64-character limit.
|
||||
launch::ModLibrary::validate_name(name);
|
||||
}
|
||||
}
|
||||
std::string member_key(const std::string &name) {
|
||||
try { return DemoFiles::name_key(name); }
|
||||
catch (const std::exception &) { member_name(name); return editor::folded(name); }
|
||||
}
|
||||
std::string fingerprint(const fs::path &source) {
|
||||
if (fs::is_symlink(fs::symlink_status(source))) throw editor::Error("Verknüpfte Mod-Quellen werden nicht übernommen.");
|
||||
if (fs::is_regular_file(source)) return content::sha256("file:" + file_digest(source));
|
||||
if (!fs::is_directory(source)) throw editor::Error("Die Mod-Quelle fehlt.");
|
||||
std::map<std::string, std::string> files; uint64_t bytes = 0;
|
||||
std::set<std::string> paths;
|
||||
for (const auto &entry : fs::recursive_directory_iterator(source)) {
|
||||
if (entry.is_symlink()) throw editor::Error("Verknüpfte Mod-Inhalte werden nicht übernommen.");
|
||||
if (!entry.is_regular_file()) {
|
||||
if (!entry.is_directory()) throw editor::Error("Nicht unterstützter Dateityp in der Mod.");
|
||||
continue;
|
||||
}
|
||||
const auto name = editor::utf8(entry.path().lexically_relative(source));
|
||||
if (!editor::safe_name(name) || !paths.insert(editor::folded(name)).second || files.size() >= 12000 ||
|
||||
entry.file_size() > limit || (bytes += entry.file_size()) > limit)
|
||||
throw editor::Error("Unsichere, doppelte oder zu große Mod-Inhalte.");
|
||||
files[name] = file_digest(entry.path());
|
||||
}
|
||||
return content::sha256(Json(files).dump());
|
||||
}
|
||||
std::string description(const Json &manifest) {
|
||||
auto text = localized(manifest.value("description", Json()));
|
||||
if (text.empty()) text = localized(manifest.value("title", Json()));
|
||||
if (text.size() > 4000) throw editor::Error("Die Mod-Beschreibung ist zu lang.");
|
||||
return text;
|
||||
}
|
||||
bool feature(const Json &manifest, const std::string &name) {
|
||||
const auto required = manifest.value("requires", Json::array());
|
||||
return required.is_array() && std::find(required.begin(), required.end(), Json(name)) != required.end();
|
||||
}
|
||||
struct Package {
|
||||
std::shared_ptr<editor::ArchiveStore> archive;
|
||||
UiModEntry metadata;
|
||||
};
|
||||
Package package(const fs::path &path) {
|
||||
Package value; value.archive = editor::ArchiveStore::open(path);
|
||||
const auto manifest = Json::parse(value.archive->read("manifest.json"));
|
||||
if (manifest.value("format", "") != "openbmh-world" || manifest.value("kind", "") != "world")
|
||||
throw editor::Error("Die Quelle ist kein OpenBMH-Weltpaket.");
|
||||
auto &row = value.metadata;
|
||||
row.name = manifest.value("mod", std::string());
|
||||
if (row.name.empty()) row.name = localized(manifest.value("title", Json()));
|
||||
try { row.name = UiModLibrary::clean_name(row.name); } catch (...) { row.name = "OpenBMH-Mod"; }
|
||||
row.description = description(manifest);
|
||||
row.version = manifest.value("version", manifest.value("format_version", std::string()));
|
||||
if (row.version.size() > 120) throw editor::Error("Ungültige Mod-Version.");
|
||||
row.format = fs::is_directory(path) ? "obw-directory" : "obw";
|
||||
Json hashes = Json::object();
|
||||
for (const auto &name : value.archive->names()) {
|
||||
if (++row.file_count > 12000 || (row.bytes += value.archive->size(name)) > limit)
|
||||
throw editor::Error("Das Weltpaket ist zu groß.");
|
||||
// Reading every entry checks compressed payload integrity, not just JSON.
|
||||
hashes[name] = content::sha256(value.archive->read(name));
|
||||
}
|
||||
const bool classic = feature(manifest, "runtime:classic-v1");
|
||||
if (classic) {
|
||||
if (feature(manifest, "runtime:modern-v1")) throw editor::Error("Mehrdeutiges Classic-/Modern-Profil.");
|
||||
Temp temp; const auto packed = temp.path / "content.obw";
|
||||
value.archive->save(packed, {}, {});
|
||||
const auto checked = content::open(packed);
|
||||
row.type = "Classic"; row.source = checked->english ? "FTLD" : "BMH";
|
||||
row.content_id = checked->content_id;
|
||||
} else {
|
||||
const auto required = manifest.value("requires", Json::array());
|
||||
if (!required.is_array()) throw editor::Error("Ungültige Weltanforderungen.");
|
||||
for (const auto &requirement : required)
|
||||
if (requirement != "editor:world-v1" && requirement != "runtime:modern-v1")
|
||||
throw editor::Error("Diese Weltanforderung wird von der nativen Oberfläche nicht unterstützt.");
|
||||
if (!Catalog::modern_manifest(manifest)) throw editor::Error("Dieses Weltprofil wird nicht unterstützt.");
|
||||
const auto checked = Catalog::open(path);
|
||||
const auto clubs = checked->clubs();
|
||||
if (std::none_of(clubs.begin(), clubs.end(), [&](const auto *club) {
|
||||
return checked->manageable(club->value("id", ""));
|
||||
})) throw editor::Error("Diese Welt besitzt keinen von der UI-Demo unterstützten Verein.");
|
||||
row.type = "Modern"; row.source = "OpenBMH"; row.content_id = content::sha256(hashes.dump());
|
||||
}
|
||||
return value;
|
||||
}
|
||||
struct Selection {
|
||||
std::optional<std::string> active;
|
||||
std::string token, transaction, error;
|
||||
};
|
||||
Selection selection(const fs::path &root) {
|
||||
Selection out; const auto file = root / selection_file;
|
||||
if (!fs::exists(fs::symlink_status(file))) { out.token = content::sha256("absent"); return out; }
|
||||
try {
|
||||
const auto bytes = regular(file, 1024 * 1024); out.token = content::sha256("file:" + bytes);
|
||||
const auto state = Json::parse(bytes);
|
||||
if (state.at("schema").get<std::string>() != "openbmh-ui-active-mod@1" ||
|
||||
(!state.at("active").is_null() && !state.at("active").is_string())) throw editor::Error("Ungültige aktive Mod-Auswahl.");
|
||||
if (!state.at("active").is_null()) {
|
||||
const auto name = state.at("active").get<std::string>(); member_name(name); out.active = name;
|
||||
}
|
||||
out.transaction = state.value("transaction", "");
|
||||
} catch (const std::exception &e) { out.active.reset(); out.error = e.what(); }
|
||||
return out;
|
||||
}
|
||||
void publish_selection(const fs::path &root, const std::optional<std::string> &active, const std::string &transaction) {
|
||||
editor::write_atomic(root / selection_file, Json{{"schema", "openbmh-ui-active-mod@1"},
|
||||
{"active", active ? Json(*active) : Json()}, {"transaction", transaction}}.dump(2));
|
||||
}
|
||||
void selection_matches(const fs::path &root, const std::string &token) {
|
||||
if (token.empty() || selection(root).token != token) throw editor::Error("Die aktive Mod-Auswahl wurde inzwischen geändert.");
|
||||
}
|
||||
void recover(const fs::path &root) {
|
||||
const auto file = root / journal_file;
|
||||
if (!fs::exists(fs::symlink_status(file))) return;
|
||||
const auto journal = Json::parse(regular(file, 1024 * 1024));
|
||||
if (journal.at("schema").get<std::string>() != "openbmh-ui-mod-transaction@1") throw editor::Error("Ungültiges Mod-Transaktionsjournal.");
|
||||
const auto from = journal.at("from").get<std::string>(); member_name(from);
|
||||
const auto to = journal.at("to").get<std::string>();
|
||||
const auto nonce = journal.at("nonce").get<std::string>();
|
||||
const auto operation = journal.at("operation").get<std::string>();
|
||||
if (nonce.empty() || nonce.find_first_not_of("0123456789abcdef") != nonce.npos || nonce.size() != 64)
|
||||
throw editor::Error("Ungültige Mod-Transaktionskennung.");
|
||||
if (operation == "rename") UiModLibrary::clean_name(to);
|
||||
else if (operation != "remove" || to != ".ui-trash-" + nonce) throw editor::Error("Ungültiges Mod-Transaktionsziel.");
|
||||
const auto old_path = root / "mods" / editor::path(from), new_path = root / "mods" / editor::path(to);
|
||||
const auto intermediate = root / "mods" / (".ui-rename-" + nonce);
|
||||
const auto rollback = root / "mods" / (".ui-rollback-" + nonce);
|
||||
directory(root / "mods");
|
||||
if (fs::is_symlink(fs::symlink_status(old_path)) || fs::is_symlink(fs::symlink_status(new_path)) || fs::is_symlink(fs::symlink_status(intermediate)))
|
||||
throw editor::Error("Unsichere Mod-Wiederherstellung.");
|
||||
const bool committed = selection(root).transaction == nonce;
|
||||
const auto candidate = fs::exists(new_path) ? new_path : fs::exists(intermediate) ? intermediate : rollback;
|
||||
if (!committed && fs::exists(candidate)) {
|
||||
std::error_code equivalent_error;
|
||||
const bool same = fs::equivalent(old_path, candidate, equivalent_error);
|
||||
if ((fs::exists(old_path) && (equivalent_error || !same)) || fingerprint(candidate) != journal.at("token").get<std::string>())
|
||||
throw editor::Error("Mod-Wiederherstellung benötigt eine manuelle Prüfung; Daten bleiben erhalten.");
|
||||
if (candidate != rollback) {
|
||||
if (fs::exists(rollback)) throw editor::Error("Mod-Rollback benötigt eine manuelle Prüfung.");
|
||||
fs::rename(candidate, rollback);
|
||||
}
|
||||
fs::rename(rollback, old_path);
|
||||
}
|
||||
if (committed && operation == "remove") { std::error_code error; fs::remove_all(new_path, error); }
|
||||
std::error_code error; fs::remove(file, error);
|
||||
if (error) throw editor::Error("Das Mod-Transaktionsjournal konnte nicht aufgeräumt werden.");
|
||||
}
|
||||
void available(const fs::path &root, const std::string &name, const std::string &except = {}) {
|
||||
directory(root / "mods");
|
||||
if (!fs::exists(root / "mods")) return;
|
||||
for (const auto &entry : fs::directory_iterator(root / "mods")) {
|
||||
const auto current = editor::utf8(entry.path().filename());
|
||||
if (current == except || current.starts_with('.')) continue;
|
||||
bool conflict = false;
|
||||
try { conflict = member_key(current) == UiModLibrary::name_key(name); } catch (const std::exception &) {}
|
||||
if (conflict) throw editor::Error("Diese Mod-Bezeichnung wird bereits verwendet.");
|
||||
}
|
||||
}
|
||||
UiModEntry entry(const fs::path &root, const std::string &name) {
|
||||
UiModEntry row; row.id = row.name = name; row.path = root / "mods" / editor::path(name);
|
||||
try {
|
||||
row.token = content::sha256("member:" + name + ":" + fingerprint(row.path));
|
||||
member_name(name);
|
||||
if (!fs::is_directory(row.path)) throw editor::Error("Kein Mod-Verzeichnis.");
|
||||
for (const auto &file : fs::directory_iterator(row.path))
|
||||
if (file.path().filename() != "content.obw" && file.path().filename() != "mod.json")
|
||||
throw editor::Error("Unerwartete Datei im Mod-Verzeichnis.");
|
||||
const auto checked = package(row.path / "content.obw");
|
||||
const auto token = row.token;
|
||||
row = checked.metadata; row.id = row.name = name; row.path = root / "mods" / editor::path(name); row.token = token;
|
||||
if (fs::exists(row.path / "mod.json")) {
|
||||
const auto profile = Json::parse(regular(row.path / "mod.json", 1024 * 1024));
|
||||
if (profile.value("schema", "") != "openbmh-mod@1.0") throw editor::Error("Ungültiges Mod-Profil.");
|
||||
// Authored profile hints never override the verified package type.
|
||||
if (profile.contains("content_id") && profile.at("content_id").get<std::string>() != row.content_id)
|
||||
throw editor::Error("Mod-Profil und geprüfter Inhalt stimmen nicht überein.");
|
||||
}
|
||||
} catch (const std::exception &e) { row.error = e.what(); }
|
||||
return row;
|
||||
}
|
||||
UiModEntry owned(const fs::path &root, const UiModEntry &expected, bool require_valid) {
|
||||
if (expected.id != expected.name || expected.path != root / "mods" / editor::path(expected.id))
|
||||
throw editor::Error("Die Mod gehört nicht zu dieser Bibliothek.");
|
||||
member_name(expected.id);
|
||||
if (fs::is_symlink(fs::symlink_status(expected.path)) || !fs::is_directory(expected.path))
|
||||
throw editor::Error("Unsicheres oder fehlendes Mod-Verzeichnis.");
|
||||
const auto actual = entry(root, expected.id);
|
||||
if (expected.token.empty() || actual.token != expected.token) throw editor::Error("Diese Mod wurde inzwischen geändert. Bitte erneut auswählen.");
|
||||
if (require_valid && !actual.valid()) throw editor::Error(actual.error);
|
||||
return actual;
|
||||
}
|
||||
void transact(const fs::path &root, const UiModEntry &old, const std::string &to,
|
||||
const std::string &operation, const std::optional<std::string> &active, const std::string &nonce) {
|
||||
const Json journal = {{"schema", "openbmh-ui-mod-transaction@1"}, {"from", old.name},
|
||||
{"to", to}, {"operation", operation}, {"nonce", nonce}, {"token", fingerprint(old.path)}};
|
||||
editor::write_atomic(root / journal_file, journal.dump(2), false);
|
||||
try {
|
||||
if (operation == "rename") {
|
||||
const auto intermediate = root / "mods" / (".ui-rename-" + nonce);
|
||||
fs::rename(old.path, intermediate);
|
||||
fs::rename(intermediate, root / "mods" / editor::path(to));
|
||||
} else fs::rename(old.path, root / "mods" / editor::path(to));
|
||||
publish_selection(root, active, nonce);
|
||||
} catch (...) {
|
||||
recover(root);
|
||||
throw;
|
||||
}
|
||||
// The selection nonce is the commit point. Cleanup never undoes that commit.
|
||||
recover(root);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
struct ModImportPlan::Payload {
|
||||
UiModEntry metadata;
|
||||
fs::path source, original_exe;
|
||||
std::string token;
|
||||
int start_year = 2026;
|
||||
std::shared_ptr<editor::ArchiveStore> archive;
|
||||
};
|
||||
UiModLibrary::UiModLibrary(fs::path root) : root_(fs::weakly_canonical(fs::absolute(std::move(root)))) {}
|
||||
std::string UiModLibrary::clean_name(const std::string &raw) {
|
||||
const auto name = DemoFiles::clean_name(raw);
|
||||
if (name.size() > 240 || name.front() == '.' || name.back() == '.' || name.find_first_of("/\\:*?\"<>|") != name.npos)
|
||||
throw editor::Error("Bitte einen portablen Mod-Namen ohne Sonderzeichen oder abschließenden Punkt verwenden.");
|
||||
const auto stem = DemoFiles::name_key(name.substr(0, name.find('.')));
|
||||
const std::set<std::string> reserved = {"con", "prn", "aux", "nul", "com1", "com2", "com3", "com4", "com5", "com6", "com7", "com8", "com9", "lpt1", "lpt2", "lpt3", "lpt4", "lpt5", "lpt6", "lpt7", "lpt8", "lpt9"};
|
||||
if (reserved.contains(stem)) throw editor::Error("Dieser Mod-Name ist vom Betriebssystem reserviert.");
|
||||
return name;
|
||||
}
|
||||
std::string UiModLibrary::name_key(const std::string &name) { return DemoFiles::name_key(clean_name(name)); }
|
||||
ModSnapshot UiModLibrary::snapshot() const {
|
||||
ModSnapshot result;
|
||||
try {
|
||||
directory(root_); directory(root_ / "mods");
|
||||
if (fs::exists(root_ / journal_file)) { Lock lock(root_); recover(root_); }
|
||||
if (fs::exists(root_ / ".ui-mod-lock")) throw editor::Error("Die Mod-Bibliothek ist gerade belegt.");
|
||||
const auto selected = selection(root_); result.selection_token = selected.token; result.error = selected.error;
|
||||
if (fs::exists(root_ / "mods"))
|
||||
for (const auto &file : fs::directory_iterator(root_ / "mods")) {
|
||||
const auto name = editor::utf8(file.path().filename());
|
||||
if (!name.starts_with('.')) result.entries.push_back(entry(root_, name));
|
||||
}
|
||||
std::sort(result.entries.begin(), result.entries.end(), [](const auto &a, const auto &b) { return a.name < b.name; });
|
||||
if (selected.active) {
|
||||
auto found = std::find_if(result.entries.begin(), result.entries.end(), [&](const auto &row) { return row.id == *selected.active && row.valid(); });
|
||||
if (found != result.entries.end()) { found->active = true; result.active = found->id; }
|
||||
else if (result.error.empty()) result.error = "Die gespeicherte aktive Mod fehlt oder ist ungültig; keine Mod ist aktiviert.";
|
||||
}
|
||||
} catch (const std::exception &e) { result.error = e.what(); }
|
||||
return result;
|
||||
}
|
||||
ModImportPlan UiModLibrary::inspect(const fs::path &input, int start_year) const {
|
||||
if (start_year < 1900 || start_year > 9998) throw editor::Error("Ungültiges Startjahr.");
|
||||
const auto source = fs::absolute(input).lexically_normal();
|
||||
if (fs::is_symlink(fs::symlink_status(source))) throw editor::Error("Verknüpfte Mod-Quellen werden nicht übernommen.");
|
||||
auto state = std::make_shared<ModImportPlan::Payload>(); state->source = source; state->start_year = start_year;
|
||||
state->token = fingerprint(source);
|
||||
fs::path content = source;
|
||||
if (fs::is_directory(source) && fs::exists(source / "content.obw")) content /= "content.obw";
|
||||
const bool world = fs::is_regular_file(content) && editor::folded(editor::utf8(content.extension())) != ".exe";
|
||||
if (world || (fs::is_directory(content) && fs::exists(content / "manifest.json"))) {
|
||||
auto checked = package(content); state->archive = std::move(checked.archive); state->metadata = checked.metadata;
|
||||
} else {
|
||||
const auto checked = launch::check_game_directory(source);
|
||||
if (checked.family == launch::GameFamily::unknown || checked.family == launch::GameFamily::disk1994 ||
|
||||
!checked.unsupported.empty() || !checked.problems.empty()) {
|
||||
std::string error = "Originalinstallation nicht unterstützt oder unvollständig.";
|
||||
if (!checked.unsupported.empty()) error += " " + checked.unsupported;
|
||||
for (const auto &problem : checked.problems) error += "\n" + problem;
|
||||
throw editor::Error(error);
|
||||
}
|
||||
if (fs::is_directory(source) && launch::find_file(checked.directory, "BMH.EXE") && launch::find_file(checked.directory, "FLTD.EXE"))
|
||||
throw editor::Error("Mehrdeutige Originalinstallation; bitte die gewünschte EXE auswählen.");
|
||||
state->source = checked.directory; state->original_exe = checked.exe; state->token = fingerprint(state->source);
|
||||
auto &row = state->metadata; row.type = "Classic";
|
||||
row.source = checked.family == launch::GameFamily::english ? "FTLD" : "BMH";
|
||||
row.name = row.source == "FTLD" ? "FLTD-classic" : "BMH-classic";
|
||||
row.version = "Originalimport"; row.description = checked.title; row.format = "legacy-source";
|
||||
for (const auto &file : fs::recursive_directory_iterator(state->source)) if (file.is_regular_file()) { ++row.file_count; row.bytes += file.file_size(); }
|
||||
}
|
||||
if (fingerprint(state->source) != state->token) throw editor::Error("Die Quelle wurde während der Prüfung geändert.");
|
||||
ModImportPlan plan; plan.metadata = state->metadata; plan.source = source; plan.source_token = state->token; plan.start_year = start_year; plan.payload_ = std::move(state); return plan;
|
||||
}
|
||||
UiModEntry UiModLibrary::commit(const ModImportPlan &plan, const std::string &raw_name, const ModProgress &progress) {
|
||||
const auto name = clean_name(raw_name);
|
||||
if (!plan.payload_) throw editor::Error("Der Importplan fehlt.");
|
||||
const auto &state = *plan.payload_;
|
||||
if (fingerprint(state.source) != state.token) throw editor::Error("Die Importquelle wurde inzwischen geändert. Bitte erneut auswählen.");
|
||||
directory(root_); available(root_, name);
|
||||
Temp temporary; const auto prepared = temporary.path / "content.obw";
|
||||
if (progress) progress("Inhalte werden geprüft und vorbereitet …");
|
||||
if (state.archive) state.archive->save(prepared, {}, {});
|
||||
else {
|
||||
launch::AddMod request; request.source = state.original_exe; request.name = "prepared"; request.start_year = state.start_year; request.migrate = false;
|
||||
const auto converted = launch::ModLibrary(temporary.path).add(request, {}, progress);
|
||||
fs::copy_file(converted.mod.directory / "content.obw", prepared);
|
||||
}
|
||||
const auto checked = package(prepared);
|
||||
Lock lock(root_); recover(root_); available(root_, name); directory(root_ / "mods", true);
|
||||
const auto staging = root_ / "mods" / editor::path(editor::new_id(".ui-import-"));
|
||||
if (!fs::create_directory(staging)) throw editor::Error("Mod-Zwischenablage konnte nicht angelegt werden.");
|
||||
struct Cleanup { fs::path path; ~Cleanup() { std::error_code error; fs::remove_all(path, error); } } cleanup{staging};
|
||||
fs::copy_file(prepared, staging / "content.obw");
|
||||
// The existing Classic launcher owns a content-only directory contract.
|
||||
// Its verified package already contains all metadata needed by this UI.
|
||||
if (checked.metadata.type == "Modern")
|
||||
editor::write_atomic(staging / "mod.json", Json{{"schema", "openbmh-mod@1.0"}, {"name", name},
|
||||
{"type", checked.metadata.type}, {"content_id", checked.metadata.content_id}, {"source", checked.metadata.source}}.dump(2));
|
||||
if (progress) progress("Mod wird in die Bibliothek übernommen …");
|
||||
if (fingerprint(state.source) != state.token) throw editor::Error("Die Importquelle wurde während der Vorbereitung geändert.");
|
||||
available(root_, name);
|
||||
fs::rename(staging, root_ / "mods" / editor::path(name));
|
||||
return entry(root_, name);
|
||||
}
|
||||
void UiModLibrary::activate(const UiModEntry &expected, const std::string &token) {
|
||||
Lock lock(root_); recover(root_); directory(root_ / "mods");
|
||||
const auto current = owned(root_, expected, true); selection_matches(root_, token);
|
||||
publish_selection(root_, current.id, content::sha256(editor::new_id("activate-")));
|
||||
}
|
||||
void UiModLibrary::deactivate(const std::string &token) {
|
||||
Lock lock(root_); recover(root_); selection_matches(root_, token);
|
||||
publish_selection(root_, {}, content::sha256(editor::new_id("deactivate-")));
|
||||
}
|
||||
UiModEntry UiModLibrary::rename(const UiModEntry &expected, const std::string &raw_name, const std::string &token) {
|
||||
const auto name = clean_name(raw_name);
|
||||
Lock lock(root_); recover(root_); directory(root_ / "mods");
|
||||
const auto current = owned(root_, expected, false); selection_matches(root_, token);
|
||||
if (name == current.name) return current;
|
||||
available(root_, name, current.name);
|
||||
auto active = selection(root_).active; if (active == current.id) active = name;
|
||||
transact(root_, current, name, "rename", active, content::sha256(editor::new_id("rename-")));
|
||||
return entry(root_, name);
|
||||
}
|
||||
void UiModLibrary::remove(const UiModEntry &expected, const std::string &token) {
|
||||
Lock lock(root_); recover(root_); directory(root_ / "mods");
|
||||
const auto current = owned(root_, expected, false); selection_matches(root_, token);
|
||||
auto active = selection(root_).active; if (active == current.id) active.reset();
|
||||
const auto nonce = content::sha256(editor::new_id("remove-"));
|
||||
transact(root_, current, ".ui-trash-" + nonce, "remove", active, nonce);
|
||||
}
|
||||
} // namespace bmh::modern_ui
|
||||
@@ -0,0 +1,55 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
#include "modern/ui/catalog.hpp"
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
|
||||
namespace bmh::modern_ui {
|
||||
struct UiModEntry {
|
||||
// IDs are current library directory names. Rename returns the new identity.
|
||||
// path is always the installed MOD DIRECTORY; its package is path/content.obw.
|
||||
std::string id, name, type, source, version, description, format, content_id;
|
||||
std::string token, error;
|
||||
fs::path path;
|
||||
uint64_t file_count = 0, bytes = 0;
|
||||
bool active = false;
|
||||
bool valid() const { return error.empty(); }
|
||||
};
|
||||
struct ModSnapshot {
|
||||
std::vector<UiModEntry> entries;
|
||||
std::optional<std::string> active;
|
||||
std::string selection_token, error;
|
||||
};
|
||||
struct ModImportPlan {
|
||||
// Suggested name and validated source details. This is not yet a member:
|
||||
// metadata.id/path stay empty until commit. Public metadata is display-only.
|
||||
UiModEntry metadata;
|
||||
fs::path source;
|
||||
std::string source_token;
|
||||
int start_year = 2026;
|
||||
private:
|
||||
struct Payload;
|
||||
std::shared_ptr<const Payload> payload_;
|
||||
friend class UiModLibrary;
|
||||
};
|
||||
using ModProgress = std::function<void(const std::string &)>;
|
||||
class UiModLibrary {
|
||||
public:
|
||||
// portable_root contains mods/ and .ui-active-mod.json, never source content.
|
||||
explicit UiModLibrary(fs::path portable_root);
|
||||
static std::string clean_name(const std::string &);
|
||||
static std::string name_key(const std::string &);
|
||||
ModSnapshot snapshot() const;
|
||||
ModImportPlan inspect(const fs::path &, int start_year = 2026) const;
|
||||
UiModEntry commit(const ModImportPlan &, const std::string &name,
|
||||
const ModProgress &progress = {});
|
||||
void activate(const UiModEntry &, const std::string &selection_token);
|
||||
void deactivate(const std::string &selection_token);
|
||||
UiModEntry rename(const UiModEntry &, const std::string &name,
|
||||
const std::string &selection_token);
|
||||
void remove(const UiModEntry &, const std::string &selection_token);
|
||||
const fs::path &root() const { return root_; }
|
||||
private:
|
||||
fs::path root_;
|
||||
};
|
||||
} // namespace bmh::modern_ui
|
||||
+20
-97
@@ -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"
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
namespace bmh::modern_ui {
|
||||
struct Config {
|
||||
std::filesystem::path world, gui_assets, screenshot, commands, state, preferences, userdata, file_import, file_export;
|
||||
std::filesystem::path world, gui_assets, screenshot, commands, state, preferences, userdata, file_import, file_export, mods, mod_import;
|
||||
std::string scene = "main", theme;
|
||||
int width = 1280, height = 720;
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user