2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-05-13 09:11:22 +00:00

Replace nativefiledialog with SDL_ShowOpenFileDialog

This commit is contained in:
Luke Street 2025-04-06 16:04:11 -06:00
parent 5dfbe86d56
commit 6def5bd623
5 changed files with 26 additions and 44 deletions

View File

@ -114,6 +114,7 @@ extern std::string ExeDir;
namespace metaforce {
std::optional<MP1::CMain> 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<metaforce::Application> 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);

View File

@ -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)

View File

@ -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 <nfd.hpp>
#endif
#include "Runtime/Logging.hpp"
#include "Runtime/Formatting.hpp"
#include <SDL3/SDL_dialog.h>
#include <SDL3/SDL_error.h>
#include <magic_enum.hpp>
#include <zeus/CEulerAngles.hpp>
namespace ImGui {
@ -48,13 +46,10 @@ namespace metaforce {
std::array<ImGuiEntityEntry, kMaxEntities> ImGuiConsole::entities;
std::set<TUniqueId> 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<ImGuiConsole*>(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{

14
extern/CMakeLists.txt vendored
View File

@ -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)

@ -1 +0,0 @@
Subproject commit dd2c57c648ccf3472e44fb368181a2d2684d9127