diff --git a/Runtime/CMain.cpp b/Runtime/CMain.cpp index 2a6dc9f2b..985b3fa64 100644 --- a/Runtime/CMain.cpp +++ b/Runtime/CMain.cpp @@ -114,6 +114,7 @@ extern std::string ExeDir; namespace metaforce { std::optional g_mainMP1; +SDL_Window* g_window; static std::string CPUFeatureString(const zeus::CPUInfo& cpuInf) { std::string features; @@ -441,7 +442,6 @@ static bool IsClientLoggingEnabled(int argc, char** argv) { } static std::unique_ptr g_app; -static SDL_Window* g_window; static bool g_paused; static void aurora_log_callback(AuroraLogLevel level, const char* module, const char* message, unsigned int len) { @@ -465,7 +465,7 @@ static void aurora_log_callback(AuroraLogLevel level, const char* module, const const std::string_view view(message, len); if (level == LOG_FATAL) { auto msg = fmt::format("Metaforce encountered an internal error:\n\n{}", view); - SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Metaforce", msg.c_str(), g_window); + SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Metaforce", msg.c_str(), metaforce::g_window); } spdlog::log(severity, "[{}] {}", module, view); } @@ -547,7 +547,7 @@ int main(int argc, char** argv) { .imGuiInitCallback = aurora_imgui_init_callback, }; const auto info = aurora_initialize(argc, argv, &config); - g_window = info.window; + metaforce::g_window = info.window; g_app->onImGuiAddTextures(); g_app->onAppLaunched(info); g_app->onAppWindowResized(info.windowSize); diff --git a/Runtime/CMakeLists.txt b/Runtime/CMakeLists.txt index 763db5893..d01244df0 100644 --- a/Runtime/CMakeLists.txt +++ b/Runtime/CMakeLists.txt @@ -224,9 +224,6 @@ add_executable(metaforce WIN32 CMain.cpp ${PLAT_SRCS} ImGuiEntitySupport.hpp ImGuiEntitySupport.cpp) # RUNTIME_LIBRARIES repeated here for link ordering target_link_libraries(metaforce PUBLIC RuntimeCommon RuntimeCommonB ${RUNTIME_LIBRARIES} ${PLAT_LIBS} aurora::main musyx) -if (TARGET nfd) - target_link_libraries(metaforce PRIVATE nfd) -endif() target_compile_definitions(metaforce PUBLIC "-DMETAFORCE_TARGET_BYTE_ORDER=__BYTE_ORDER__") if (WIN32) target_link_options(metaforce PRIVATE /ENTRY:wWinMainCRTStartup) diff --git a/Runtime/ImGuiConsole.cpp b/Runtime/ImGuiConsole.cpp index 93ae4ea16..7992a7cc8 100644 --- a/Runtime/ImGuiConsole.cpp +++ b/Runtime/ImGuiConsole.cpp @@ -5,6 +5,7 @@ y = v.y(); \ } \ operator zeus::CVector2f() const { return zeus::CVector2f{x, y}; } + #include "ImGuiConsole.hpp" #include "../version.h" @@ -13,16 +14,13 @@ #include "Runtime/GameGlobalObjects.hpp" #include "Runtime/ImGuiEntitySupport.hpp" #include "Runtime/World/CPlayer.hpp" - #include "ImGuiEngine.hpp" -#include "magic_enum.hpp" -#ifdef NATIVEFILEDIALOG_SUPPORTED -#include -#endif - #include "Runtime/Logging.hpp" #include "Runtime/Formatting.hpp" +#include +#include +#include #include namespace ImGui { @@ -48,13 +46,10 @@ namespace metaforce { std::array ImGuiConsole::entities; std::set ImGuiConsole::inspectingEntities; ImGuiPlayerLoadouts ImGuiConsole::loadouts; +extern SDL_Window* g_window; ImGuiConsole::ImGuiConsole(CVarManager& cvarMgr, CVarCommons& cvarCommons) -: m_cvarMgr(cvarMgr), m_cvarCommons(cvarCommons) { -#ifdef NATIVEFILEDIALOG_SUPPORTED - NFD::Init(); -#endif -} +: m_cvarMgr(cvarMgr), m_cvarCommons(cvarCommons) {} void ImGuiStringViewText(std::string_view text) { // begin()/end() do not work on MSVC @@ -659,6 +654,22 @@ void ImGuiConsole::ShowConsoleVariablesWindow() { ImGui::End(); } +void fileDialogCallback(void* userdata, const char* const* filelist, [[maybe_unused]] int filter) { + auto* self = static_cast(userdata); + if (filelist != nullptr) { + if (filelist[0] == nullptr) { + // Cancelled + self->m_gameDiscSelected.reset(); + } else { + self->m_gameDiscSelected = filelist[0]; + } + } else { + // Error occurred + self->m_gameDiscSelected.reset(); + self->m_errorString = fmt::format("File dialog error: {}", SDL_GetError()); + } +} + void ImGuiConsole::ShowAboutWindow(bool preLaunch) { // Center window ImVec2 center = ImGui::GetMainViewport()->GetCenter(); @@ -690,18 +701,10 @@ void ImGuiConsole::ShowAboutWindow(bool preLaunch) { if (ImGuiButtonCenter("Settings")) { m_showPreLaunchSettingsWindow = true; } -#ifdef NATIVEFILEDIALOG_SUPPORTED ImGui::Dummy(padding); if (ImGuiButtonCenter("Select Game")) { - NFD::UniquePathU8 outPath; - nfdresult_t nfdResult = NFD::OpenDialog(outPath, nullptr, 0, nullptr); - if (nfdResult == NFD_OKAY) { - m_gameDiscSelected = outPath.get(); - } else if (nfdResult != NFD_CANCEL) { - spdlog::error("nativefiledialog error: {}", NFD::GetError()); - } + SDL_ShowOpenFileDialog(&fileDialogCallback, this, g_window, nullptr, 0, nullptr, false); } -#endif #ifdef EMSCRIPTEN if (ImGuiButtonCenter("Load Game")) { m_gameDiscSelected = "game.iso"; @@ -1444,9 +1447,6 @@ void ImGuiConsole::PostUpdate() { void ImGuiConsole::Shutdown() { dummyWorlds.clear(); stringTables.clear(); -#ifdef NATIVEFILEDIALOG_SUPPORTED - NFD::Quit(); -#endif } static constexpr std::array GeneralItems{ diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt index 2db76a0c2..843b584f0 100644 --- a/extern/CMakeLists.txt +++ b/extern/CMakeLists.txt @@ -30,20 +30,6 @@ add_subdirectory(nod EXCLUDE_FROM_ALL) add_subdirectory(jbus EXCLUDE_FROM_ALL) add_subdirectory(kabufuda EXCLUDE_FROM_ALL) -option(NFD_PORTAL "Use xdg-desktop-portal instead of GTK" ON) -if (CMAKE_SYSTEM_NAME STREQUAL "Linux") - add_subdirectory(nativefiledialog-extended) - target_compile_definitions(nfd INTERFACE NATIVEFILEDIALOG_SUPPORTED) -elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin") - add_subdirectory(nativefiledialog-extended) - target_compile_definitions(nfd INTERFACE NATIVEFILEDIALOG_SUPPORTED) -elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows") - add_subdirectory(nativefiledialog-extended) - target_compile_definitions(nfd INTERFACE NATIVEFILEDIALOG_SUPPORTED) -else () - message(WARNING "nativefiledialog unsupported for ${CMAKE_SYSTEM_NAME}") -endif () - option(OPTICK_ENABLED "Enable profiling with Optick" OFF) set(OPTICK_USE_VULKAN ${DAWN_ENABLE_VULKAN} CACHE BOOL "Built-in support for Vulkan" FORCE) set(OPTICK_INSTALL_TARGETS OFF CACHE BOOL "Should optick be installed? Set to OFF if you use add_subdirectory to include Optick." FORCE) diff --git a/extern/nativefiledialog-extended b/extern/nativefiledialog-extended deleted file mode 160000 index dd2c57c64..000000000 --- a/extern/nativefiledialog-extended +++ /dev/null @@ -1 +0,0 @@ -Subproject commit dd2c57c648ccf3472e44fb368181a2d2684d9127