Mods folder button.

This commit is contained in:
Dario
2025-01-27 20:45:48 -03:00
committed by Mr-Wiseguy
parent 6ddd650cf2
commit b8f0658343
2 changed files with 22 additions and 0 deletions
+20
View File
@@ -5,6 +5,10 @@
#include <string>
#ifdef WIN32
#include <shellapi.h>
#endif
// TODO:
// - Set up navigation.
// - Add hover and active state for mod entries.
@@ -110,6 +114,19 @@ void ModMenu::refresh_mods() {
create_mod_list();
}
void ModMenu::open_mods_folder() {
std::filesystem::path mods_directory = recomp::mods::get_mods_directory();
#if defined(WIN32)
std::wstring path_wstr = mods_directory.wstring();
ShellExecuteW(NULL, L"open", path_wstr.c_str(), NULL, NULL, SW_SHOWDEFAULT);
#elif defined(__linux__)
std::string command = "xdg-open " + mods_directory.string() + " &";
std::system(command.c_str());
#else
static_assert(false, "Not implemented for this platform.");
#endif
}
void ModMenu::mod_toggled(bool enabled) {
if (active_mod_index >= 0) {
recomp::mods::enable_mod(mod_details[active_mod_index].mod_id, enabled);
@@ -360,6 +377,9 @@ ModMenu::ModMenu(Element *parent) : Element(parent) {
{
refresh_button = context.create_element<Button>(footer_container, "Refresh", recompui::ButtonStyle::Primary);
refresh_button->add_pressed_callback(std::bind(&ModMenu::refresh_mods, this));
mods_folder_button = context.create_element<Button>(footer_container, "Open Mods Folder", recompui::ButtonStyle::Primary);
mods_folder_button->add_pressed_callback(std::bind(&ModMenu::open_mods_folder, this));
} // footer_container
} // this