From 343e072924fd0ca29551db1d5042b8a19d52a4e3 Mon Sep 17 00:00:00 2001 From: Waterdish Date: Wed, 29 May 2024 09:33:20 -0700 Subject: [PATCH] GUI Scaling fixes --- libultraship | 2 +- mm/2s2h/BenGui/BenGui.cpp | 2 +- mm/2s2h/BenGui/BenMenuBar.cpp | 11 ++++--- mm/2s2h/Extractor/Extract.cpp | 57 ++++++++++++++++++++++++++++++++++- 4 files changed, 65 insertions(+), 7 deletions(-) diff --git a/libultraship b/libultraship index bb5133163..b8757e77c 160000 --- a/libultraship +++ b/libultraship @@ -1 +1 @@ -Subproject commit bb5133163dc60bc26d8931d2f04bdf021f3cdb73 +Subproject commit b8757e77c7e4a9bb44e930bbb04181de7c5bd1b8 diff --git a/mm/2s2h/BenGui/BenGui.cpp b/mm/2s2h/BenGui/BenGui.cpp index 1b605880a..d2feba0f4 100644 --- a/mm/2s2h/BenGui/BenGui.cpp +++ b/mm/2s2h/BenGui/BenGui.cpp @@ -50,7 +50,7 @@ void SetupGuiElements() { gui->SetMenuBar(std::reinterpret_pointer_cast(mBenMenuBar)); if (gui->GetMenuBar() && !gui->GetMenuBar()->IsVisible()) { -#if defined(__SWITCH__) || defined(__WIIU__) +#if defined(__SWITCH__) || defined(__WIIU__) || defined(__ANDROID__) gui->GetGameOverlay()->TextDrawNotification(30.0f, true, "Press - to access enhancements menu"); #else gui->GetGameOverlay()->TextDrawNotification(30.0f, true, "Press F1 to access enhancements menu"); diff --git a/mm/2s2h/BenGui/BenMenuBar.cpp b/mm/2s2h/BenGui/BenMenuBar.cpp index 5cea0a443..cb2aec8c8 100644 --- a/mm/2s2h/BenGui/BenMenuBar.cpp +++ b/mm/2s2h/BenGui/BenMenuBar.cpp @@ -74,6 +74,9 @@ void DrawMenuBarIcon() { #elif defined(__WIIU__) ImVec2 iconSize = ImVec2(16.0f * 2, 16.0f * 2); float posScale = 2.0f; +#elif defined(__ANDROID__) + ImVec2 iconSize = ImVec2(16.0f * 2, 16.0f * 2); + float posScale = 2.0f; #else ImVec2 iconSize = ImVec2(16.0f, 16.0f); float posScale = 1.0f; @@ -88,7 +91,7 @@ void DrawMenuBarIcon() { void DrawBenMenu() { if (UIWidgets::BeginMenu("2Ship")) { if (UIWidgets::MenuItem("Hide Menu Bar", -#if !defined(__SWITCH__) && !defined(__WIIU__) +#if !defined(__SWITCH__) && !defined(__WIIU__) && !defined(__ANDROID__) "F1" #else "[-]" @@ -96,7 +99,7 @@ void DrawBenMenu() { )) { Ship::Context::GetInstance()->GetWindow()->GetGui()->GetMenuBar()->ToggleVisibility(); } -#if !defined(__SWITCH__) && !defined(__WIIU__) +#if !defined(__SWITCH__) && !defined(__WIIU__) && !defined(__ANDROID__) if (UIWidgets::MenuItem("Toggle Fullscreen", "F11")) { Ship::Context::GetInstance()->GetWindow()->ToggleFullscreen(); } @@ -104,7 +107,7 @@ void DrawBenMenu() { if (UIWidgets::MenuItem("Reset", #ifdef __APPLE__ "Command-R" -#elif !defined(__SWITCH__) && !defined(__WIIU__) +#elif !defined(__SWITCH__) && !defined(__WIIU__) && !defined(__ANDROID__) "Ctrl+R" #else "" @@ -114,7 +117,7 @@ void DrawBenMenu() { Ship::Context::GetInstance()->GetWindow()->GetGui()->GetGuiWindow("Console")) ->Dispatch("reset"); } -#if !defined(__SWITCH__) && !defined(__WIIU__) +#if !defined(__SWITCH__) && !defined(__WIIU__) && !defined(__ANDROID__) if (UIWidgets::MenuItem("Open App Files Folder")) { std::string filesPath = Ship::Context::GetInstance()->GetAppDirectoryPath(); SDL_OpenURL(std::string("file:///" + std::filesystem::absolute(filesPath).string()).c_str()); diff --git a/mm/2s2h/Extractor/Extract.cpp b/mm/2s2h/Extractor/Extract.cpp index 16c823d38..49ac680c4 100644 --- a/mm/2s2h/Extractor/Extract.cpp +++ b/mm/2s2h/Extractor/Extract.cpp @@ -38,6 +38,12 @@ #define UNREACHABLE __builtin_unreachable(); #endif +#ifdef __ANDROID__ +#include +#include +#include +#endif + #include #include @@ -95,6 +101,28 @@ enum class ButtonId : int { FIND, }; +#ifdef __ANDROID__ + +const char* javaRomPath = NULL; +bool fileDialogOpen = false; + +//function to be called from C +void openFilePickerFromC(JNIEnv* env, jobject javaObject) { + fileDialogOpen = true; + jclass javaClass = env->GetObjectClass(javaObject); + jmethodID openFilePickerMethod = env->GetMethodID(javaClass, "openFilePicker", "()V"); + env->CallVoidMethod(javaObject, openFilePickerMethod); +} +// Define the native method to handle the selected file path +extern "C" void JNICALL Java_com_dishii_mm_MainActivity_nativeHandleSelectedFile(JNIEnv* env, jobject obj, jstring filePath) { + const char* filePathStr = env->GetStringUTFChars(filePath, 0); + javaRomPath = strdup(filePathStr); // save filepath to string + fileDialogOpen = false; + env->ReleaseStringUTFChars(filePath, filePathStr); +} + +#endif + void Extractor::ShowErrorBox(const char* title, const char* text) { #ifdef _WIN32 MessageBoxA(nullptr, text, title, MB_OK | MB_ICONERROR); @@ -297,8 +325,20 @@ bool Extractor::GetRomPathFromBox() { } mCurrentRomPath = nameBuffer; #else +#ifndef __ANDROID__ auto selection = pfd::open_file("Select a file", ".", { "N64 Roms", "*.z64 *.n64 *.v64" }).result(); - +#else + JNIEnv* javaEnv = (JNIEnv*)SDL_AndroidGetJNIEnv(); + jobject javaObject = (jobject)SDL_AndroidGetActivity(); + std::vector selection; + openFilePickerFromC(javaEnv, javaObject); + while(fileDialogOpen){ + //Do nothing until it's chosen + SDL_Delay(250); + } + SDL_Log("%s",javaRomPath); + selection.push_back(javaRomPath); +#endif if (selection.empty()) { return false; } @@ -306,6 +346,12 @@ bool Extractor::GetRomPathFromBox() { mCurrentRomPath = selection[0]; #endif mCurRomSize = GetCurRomSize(); +#ifdef __ANDROID__ + if (javaRomPath) { + free((void*)javaRomPath); + javaRomPath = NULL; + } +#endif return true; } @@ -520,7 +566,11 @@ const char* Extractor::GetZapdVerStr() const { } std::string Extractor::Mkdtemp() { +#ifndef __ANDROID__ std::string temp_dir = std::filesystem::temp_directory_path().string(); +#else + std::string temp_dir = SDL_AndroidGetExternalStoragePath(); +#endif // create 6 random alphanumeric characters static const char charset[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; @@ -560,7 +610,12 @@ bool Extractor::CallZapd(std::string installPath, std::string exportdir) { std::filesystem::copy(installPath + "/assets", tempdir + "/assets", std::filesystem::copy_options::recursive | std::filesystem::copy_options::update_existing); #else +#ifndef __ANDROID__ std::filesystem::create_symlink(installPath + "/assets", tempdir + "/assets"); +#else + std::filesystem::copy(installPath + "/assets", tempdir + "/assets", + std::filesystem::copy_options::recursive | std::filesystem::copy_options::update_existing); +#endif #endif std::filesystem::current_path(tempdir);