mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-05-13 15:51:22 +00:00
Replace nativefiledialog with SDL_ShowOpenFileDialog
This commit is contained in:
parent
5dfbe86d56
commit
6def5bd623
@ -114,6 +114,7 @@ extern std::string ExeDir;
|
|||||||
|
|
||||||
namespace metaforce {
|
namespace metaforce {
|
||||||
std::optional<MP1::CMain> g_mainMP1;
|
std::optional<MP1::CMain> g_mainMP1;
|
||||||
|
SDL_Window* g_window;
|
||||||
|
|
||||||
static std::string CPUFeatureString(const zeus::CPUInfo& cpuInf) {
|
static std::string CPUFeatureString(const zeus::CPUInfo& cpuInf) {
|
||||||
std::string features;
|
std::string features;
|
||||||
@ -441,7 +442,6 @@ static bool IsClientLoggingEnabled(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static std::unique_ptr<metaforce::Application> g_app;
|
static std::unique_ptr<metaforce::Application> g_app;
|
||||||
static SDL_Window* g_window;
|
|
||||||
static bool g_paused;
|
static bool g_paused;
|
||||||
|
|
||||||
static void aurora_log_callback(AuroraLogLevel level, const char* module, const char* message, unsigned int len) {
|
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);
|
const std::string_view view(message, len);
|
||||||
if (level == LOG_FATAL) {
|
if (level == LOG_FATAL) {
|
||||||
auto msg = fmt::format("Metaforce encountered an internal error:\n\n{}", view);
|
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);
|
spdlog::log(severity, "[{}] {}", module, view);
|
||||||
}
|
}
|
||||||
@ -547,7 +547,7 @@ int main(int argc, char** argv) {
|
|||||||
.imGuiInitCallback = aurora_imgui_init_callback,
|
.imGuiInitCallback = aurora_imgui_init_callback,
|
||||||
};
|
};
|
||||||
const auto info = aurora_initialize(argc, argv, &config);
|
const auto info = aurora_initialize(argc, argv, &config);
|
||||||
g_window = info.window;
|
metaforce::g_window = info.window;
|
||||||
g_app->onImGuiAddTextures();
|
g_app->onImGuiAddTextures();
|
||||||
g_app->onAppLaunched(info);
|
g_app->onAppLaunched(info);
|
||||||
g_app->onAppWindowResized(info.windowSize);
|
g_app->onAppWindowResized(info.windowSize);
|
||||||
|
@ -224,9 +224,6 @@ add_executable(metaforce WIN32 CMain.cpp ${PLAT_SRCS}
|
|||||||
ImGuiEntitySupport.hpp ImGuiEntitySupport.cpp)
|
ImGuiEntitySupport.hpp ImGuiEntitySupport.cpp)
|
||||||
# RUNTIME_LIBRARIES repeated here for link ordering
|
# RUNTIME_LIBRARIES repeated here for link ordering
|
||||||
target_link_libraries(metaforce PUBLIC RuntimeCommon RuntimeCommonB ${RUNTIME_LIBRARIES} ${PLAT_LIBS} aurora::main musyx)
|
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__")
|
target_compile_definitions(metaforce PUBLIC "-DMETAFORCE_TARGET_BYTE_ORDER=__BYTE_ORDER__")
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
target_link_options(metaforce PRIVATE /ENTRY:wWinMainCRTStartup)
|
target_link_options(metaforce PRIVATE /ENTRY:wWinMainCRTStartup)
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
y = v.y(); \
|
y = v.y(); \
|
||||||
} \
|
} \
|
||||||
operator zeus::CVector2f() const { return zeus::CVector2f{x, y}; }
|
operator zeus::CVector2f() const { return zeus::CVector2f{x, y}; }
|
||||||
|
|
||||||
#include "ImGuiConsole.hpp"
|
#include "ImGuiConsole.hpp"
|
||||||
|
|
||||||
#include "../version.h"
|
#include "../version.h"
|
||||||
@ -13,16 +14,13 @@
|
|||||||
#include "Runtime/GameGlobalObjects.hpp"
|
#include "Runtime/GameGlobalObjects.hpp"
|
||||||
#include "Runtime/ImGuiEntitySupport.hpp"
|
#include "Runtime/ImGuiEntitySupport.hpp"
|
||||||
#include "Runtime/World/CPlayer.hpp"
|
#include "Runtime/World/CPlayer.hpp"
|
||||||
|
|
||||||
#include "ImGuiEngine.hpp"
|
#include "ImGuiEngine.hpp"
|
||||||
#include "magic_enum.hpp"
|
|
||||||
#ifdef NATIVEFILEDIALOG_SUPPORTED
|
|
||||||
#include <nfd.hpp>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "Runtime/Logging.hpp"
|
#include "Runtime/Logging.hpp"
|
||||||
#include "Runtime/Formatting.hpp"
|
#include "Runtime/Formatting.hpp"
|
||||||
|
|
||||||
|
#include <SDL3/SDL_dialog.h>
|
||||||
|
#include <SDL3/SDL_error.h>
|
||||||
|
#include <magic_enum.hpp>
|
||||||
#include <zeus/CEulerAngles.hpp>
|
#include <zeus/CEulerAngles.hpp>
|
||||||
|
|
||||||
namespace ImGui {
|
namespace ImGui {
|
||||||
@ -48,13 +46,10 @@ namespace metaforce {
|
|||||||
std::array<ImGuiEntityEntry, kMaxEntities> ImGuiConsole::entities;
|
std::array<ImGuiEntityEntry, kMaxEntities> ImGuiConsole::entities;
|
||||||
std::set<TUniqueId> ImGuiConsole::inspectingEntities;
|
std::set<TUniqueId> ImGuiConsole::inspectingEntities;
|
||||||
ImGuiPlayerLoadouts ImGuiConsole::loadouts;
|
ImGuiPlayerLoadouts ImGuiConsole::loadouts;
|
||||||
|
extern SDL_Window* g_window;
|
||||||
|
|
||||||
ImGuiConsole::ImGuiConsole(CVarManager& cvarMgr, CVarCommons& cvarCommons)
|
ImGuiConsole::ImGuiConsole(CVarManager& cvarMgr, CVarCommons& cvarCommons)
|
||||||
: m_cvarMgr(cvarMgr), m_cvarCommons(cvarCommons) {
|
: m_cvarMgr(cvarMgr), m_cvarCommons(cvarCommons) {}
|
||||||
#ifdef NATIVEFILEDIALOG_SUPPORTED
|
|
||||||
NFD::Init();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGuiStringViewText(std::string_view text) {
|
void ImGuiStringViewText(std::string_view text) {
|
||||||
// begin()/end() do not work on MSVC
|
// begin()/end() do not work on MSVC
|
||||||
@ -659,6 +654,22 @@ void ImGuiConsole::ShowConsoleVariablesWindow() {
|
|||||||
ImGui::End();
|
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) {
|
void ImGuiConsole::ShowAboutWindow(bool preLaunch) {
|
||||||
// Center window
|
// Center window
|
||||||
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
|
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
|
||||||
@ -690,18 +701,10 @@ void ImGuiConsole::ShowAboutWindow(bool preLaunch) {
|
|||||||
if (ImGuiButtonCenter("Settings")) {
|
if (ImGuiButtonCenter("Settings")) {
|
||||||
m_showPreLaunchSettingsWindow = true;
|
m_showPreLaunchSettingsWindow = true;
|
||||||
}
|
}
|
||||||
#ifdef NATIVEFILEDIALOG_SUPPORTED
|
|
||||||
ImGui::Dummy(padding);
|
ImGui::Dummy(padding);
|
||||||
if (ImGuiButtonCenter("Select Game")) {
|
if (ImGuiButtonCenter("Select Game")) {
|
||||||
NFD::UniquePathU8 outPath;
|
SDL_ShowOpenFileDialog(&fileDialogCallback, this, g_window, nullptr, 0, nullptr, false);
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#ifdef EMSCRIPTEN
|
#ifdef EMSCRIPTEN
|
||||||
if (ImGuiButtonCenter("Load Game")) {
|
if (ImGuiButtonCenter("Load Game")) {
|
||||||
m_gameDiscSelected = "game.iso";
|
m_gameDiscSelected = "game.iso";
|
||||||
@ -1444,9 +1447,6 @@ void ImGuiConsole::PostUpdate() {
|
|||||||
void ImGuiConsole::Shutdown() {
|
void ImGuiConsole::Shutdown() {
|
||||||
dummyWorlds.clear();
|
dummyWorlds.clear();
|
||||||
stringTables.clear();
|
stringTables.clear();
|
||||||
#ifdef NATIVEFILEDIALOG_SUPPORTED
|
|
||||||
NFD::Quit();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr std::array GeneralItems{
|
static constexpr std::array GeneralItems{
|
||||||
|
14
extern/CMakeLists.txt
vendored
14
extern/CMakeLists.txt
vendored
@ -30,20 +30,6 @@ add_subdirectory(nod EXCLUDE_FROM_ALL)
|
|||||||
add_subdirectory(jbus EXCLUDE_FROM_ALL)
|
add_subdirectory(jbus EXCLUDE_FROM_ALL)
|
||||||
add_subdirectory(kabufuda 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)
|
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_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)
|
set(OPTICK_INSTALL_TARGETS OFF CACHE BOOL "Should optick be installed? Set to OFF if you use add_subdirectory to include Optick." FORCE)
|
||||||
|
1
extern/nativefiledialog-extended
vendored
1
extern/nativefiledialog-extended
vendored
@ -1 +0,0 @@
|
|||||||
Subproject commit dd2c57c648ccf3472e44fb368181a2d2684d9127
|
|
Loading…
x
Reference in New Issue
Block a user