2024-01-01 22:36:06 -05:00
|
|
|
#include "recomp_ui.h"
|
2024-06-05 01:12:43 +02:00
|
|
|
#include "zelda_config.h"
|
|
|
|
#include "librecomp/game.hpp"
|
|
|
|
#include "ultramodern/ultramodern.hpp"
|
2024-01-01 22:36:06 -05:00
|
|
|
#include "RmlUi/Core.h"
|
2024-03-03 21:00:49 -05:00
|
|
|
#include "nfd.h"
|
|
|
|
#include <filesystem>
|
|
|
|
|
2025-02-14 18:38:10 -05:00
|
|
|
static std::string version_string;
|
2024-03-15 19:47:29 -04:00
|
|
|
|
2024-03-03 21:00:49 -05:00
|
|
|
Rml::DataModelHandle model_handle;
|
|
|
|
bool mm_rom_valid = false;
|
|
|
|
|
2024-06-05 01:12:43 +02:00
|
|
|
extern std::vector<recomp::GameEntry> supported_games;
|
|
|
|
|
2024-03-03 21:00:49 -05:00
|
|
|
void select_rom() {
|
|
|
|
nfdnchar_t* native_path = nullptr;
|
|
|
|
nfdresult_t result = NFD_OpenDialogN(&native_path, nullptr, 0, nullptr);
|
|
|
|
|
|
|
|
if (result == NFD_OKAY) {
|
|
|
|
std::filesystem::path path{native_path};
|
|
|
|
|
|
|
|
NFD_FreePathN(native_path);
|
|
|
|
native_path = nullptr;
|
|
|
|
|
2024-06-05 01:12:43 +02:00
|
|
|
recomp::RomValidationError rom_error = recomp::select_rom(path, supported_games[0].game_id);
|
|
|
|
switch (rom_error) {
|
|
|
|
case recomp::RomValidationError::Good:
|
|
|
|
mm_rom_valid = true;
|
|
|
|
model_handle.DirtyVariable("mm_rom_valid");
|
|
|
|
break;
|
|
|
|
case recomp::RomValidationError::FailedToOpen:
|
|
|
|
recompui::message_box("Failed to open ROM file.");
|
|
|
|
break;
|
|
|
|
case recomp::RomValidationError::NotARom:
|
|
|
|
recompui::message_box("This is not a valid ROM file.");
|
|
|
|
break;
|
|
|
|
case recomp::RomValidationError::IncorrectRom:
|
|
|
|
recompui::message_box("This ROM is not the correct game.");
|
|
|
|
break;
|
|
|
|
case recomp::RomValidationError::NotYet:
|
|
|
|
recompui::message_box("This game isn't supported yet.");
|
|
|
|
break;
|
|
|
|
case recomp::RomValidationError::IncorrectVersion:
|
|
|
|
recompui::message_box(
|
|
|
|
"This ROM is the correct game, but the wrong version.\nThis project requires the NTSC-U N64 version of the game.");
|
|
|
|
break;
|
|
|
|
case recomp::RomValidationError::OtherError:
|
|
|
|
recompui::message_box("An unknown error has occurred.");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2024-03-03 21:00:49 -05:00
|
|
|
}
|
2024-01-01 22:36:06 -05:00
|
|
|
|
2024-06-05 01:12:43 +02:00
|
|
|
class LauncherMenu : public recompui::MenuController {
|
2024-01-01 22:36:06 -05:00
|
|
|
public:
|
|
|
|
LauncherMenu() {
|
2024-06-05 01:12:43 +02:00
|
|
|
mm_rom_valid = recomp::is_rom_valid(supported_games[0].game_id);
|
2024-01-01 22:36:06 -05:00
|
|
|
}
|
|
|
|
~LauncherMenu() override {
|
|
|
|
|
|
|
|
}
|
|
|
|
Rml::ElementDocument* load_document(Rml::Context* context) override {
|
|
|
|
return context->LoadDocument("assets/launcher.rml");
|
|
|
|
}
|
2024-06-05 01:12:43 +02:00
|
|
|
void register_events(recompui::UiEventListenerInstancer& listener) override {
|
|
|
|
recompui::register_event(listener, "select_rom",
|
2024-03-03 21:00:49 -05:00
|
|
|
[](const std::string& param, Rml::Event& event) {
|
|
|
|
select_rom();
|
|
|
|
}
|
|
|
|
);
|
2024-06-05 01:12:43 +02:00
|
|
|
recompui::register_event(listener, "rom_selected",
|
2024-03-03 21:00:49 -05:00
|
|
|
[](const std::string& param, Rml::Event& event) {
|
|
|
|
mm_rom_valid = true;
|
|
|
|
model_handle.DirtyVariable("mm_rom_valid");
|
|
|
|
}
|
|
|
|
);
|
2024-06-05 01:12:43 +02:00
|
|
|
recompui::register_event(listener, "start_game",
|
2024-01-07 02:03:12 -05:00
|
|
|
[](const std::string& param, Rml::Event& event) {
|
2024-06-05 01:12:43 +02:00
|
|
|
recomp::start_game(supported_games[0].game_id);
|
|
|
|
recompui::set_current_menu(recompui::Menu::None);
|
2024-01-08 01:28:50 -05:00
|
|
|
}
|
|
|
|
);
|
2024-06-05 01:12:43 +02:00
|
|
|
recompui::register_event(listener, "open_controls",
|
2024-01-08 01:28:50 -05:00
|
|
|
[](const std::string& param, Rml::Event& event) {
|
2024-06-05 01:12:43 +02:00
|
|
|
recompui::set_current_menu(recompui::Menu::Config);
|
|
|
|
recompui::set_config_submenu(recompui::ConfigSubmenu::Controls);
|
2024-01-08 01:28:50 -05:00
|
|
|
}
|
|
|
|
);
|
2024-06-05 01:12:43 +02:00
|
|
|
recompui::register_event(listener, "open_settings",
|
2024-01-08 01:28:50 -05:00
|
|
|
[](const std::string& param, Rml::Event& event) {
|
2024-06-05 01:12:43 +02:00
|
|
|
recompui::set_current_menu(recompui::Menu::Config);
|
|
|
|
recompui::set_config_submenu(recompui::ConfigSubmenu::General);
|
2024-01-01 22:36:06 -05:00
|
|
|
}
|
|
|
|
);
|
2025-01-08 21:14:55 -03:00
|
|
|
recompui::register_event(listener, "open_mods",
|
|
|
|
[](const std::string ¶m, Rml::Event &event) {
|
|
|
|
recompui::set_current_menu(recompui::Menu::Config);
|
|
|
|
recompui::set_config_submenu(recompui::ConfigSubmenu::Mods);
|
|
|
|
}
|
|
|
|
);
|
2024-06-05 01:12:43 +02:00
|
|
|
recompui::register_event(listener, "exit_game",
|
2024-01-07 23:46:44 -05:00
|
|
|
[](const std::string& param, Rml::Event& event) {
|
|
|
|
ultramodern::quit();
|
|
|
|
}
|
|
|
|
);
|
2024-01-01 22:36:06 -05:00
|
|
|
}
|
|
|
|
void make_bindings(Rml::Context* context) override {
|
2024-03-03 21:00:49 -05:00
|
|
|
Rml::DataModelConstructor constructor = context->CreateDataModel("launcher_model");
|
|
|
|
|
|
|
|
constructor.Bind("mm_rom_valid", &mm_rom_valid);
|
2025-02-14 18:38:10 -05:00
|
|
|
|
|
|
|
version_string = recomp::get_project_version().to_string();
|
|
|
|
constructor.Bind("version_number", &version_string);
|
2024-01-01 22:36:06 -05:00
|
|
|
|
2024-03-03 21:00:49 -05:00
|
|
|
model_handle = constructor.GetModelHandle();
|
2024-01-01 22:36:06 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-06-05 01:12:43 +02:00
|
|
|
std::unique_ptr<recompui::MenuController> recompui::create_launcher_menu() {
|
2024-01-01 22:36:06 -05:00
|
|
|
return std::make_unique<LauncherMenu>();
|
|
|
|
}
|