From 4ad8b486ff9f6ab315276fa8736f6f6c92f4a543 Mon Sep 17 00:00:00 2001 From: altalk23 <45172705+altalk23@users.noreply.github.com> Date: Sun, 25 Jun 2023 19:52:01 +0300 Subject: [PATCH] implement save and open panel --- bindings/GeometryDash.bro | 2 +- loader/src/platform/mac/util.mm | 66 ++++++++++++++++++++++----------- loader/test/members/MacOS.cpp | 3 ++ 3 files changed, 48 insertions(+), 23 deletions(-) diff --git a/bindings/GeometryDash.bro b/bindings/GeometryDash.bro index 664b784e..561bfa30 100644 --- a/bindings/GeometryDash.bro +++ b/bindings/GeometryDash.bro @@ -4144,7 +4144,7 @@ class LocalLevelManager : GManager { cocos2d::CCDictionary* getAllLevelsInDict() = mac 0x35e3d0, win 0x18d7c0; - PAD = mac 0x10, win 0x1C; + PAD = mac 0x4, win 0x1C; cocos2d::CCDictionary* m_loadData; cocos2d::CCDictionary* m_levelData; cocos2d::CCArray* m_localLevels; diff --git a/loader/src/platform/mac/util.mm b/loader/src/platform/mac/util.mm index b5bf11c1..192494f9 100644 --- a/loader/src/platform/mac/util.mm +++ b/loader/src/platform/mac/util.mm @@ -75,25 +75,14 @@ void utils::web::openLinkInBrowser(std::string const& url) { @implementation FileDialog +(Result>) filePickerWithMode:(file::PickMode)mode options:(file::FilePickOptions const&)options multiple:(bool)mult { - NSOpenPanel* panel = [NSOpenPanel openPanel]; + NSSavePanel* panel; + if (mode == file::PickMode::SaveFile) + panel = [NSSavePanel savePanel]; + else + panel = [NSOpenPanel openPanel]; - // allowed files - NSMutableArray* allowed = [NSMutableArray array]; + [panel setCanCreateDirectories: TRUE]; - for (auto& f : options.filters) { - for (auto& i : f.files) { - auto nsstr = [NSString stringWithUTF8String: i.c_str()]; - - if (![allowed containsObject: nsstr]) - [allowed addObject: nsstr]; - } - } - - if (options.filters.size()) - [panel setAllowedFileTypes: allowed]; - - // multiple - [panel setAllowsMultipleSelection: mult]; // default path if (options.defaultPath) { @@ -102,8 +91,36 @@ void utils::web::openLinkInBrowser(std::string const& url) { } // other - [panel setCanChooseDirectories: NO]; - [panel setCanChooseFiles: YES]; + if (mode != file::PickMode::SaveFile) { + auto openPanel = (NSOpenPanel*)panel; + + if (mode == file::PickMode::OpenFile){ + [openPanel setCanChooseDirectories: NO]; + [openPanel setCanChooseFiles: YES]; + } + else { + [openPanel setCanChooseDirectories: YES]; + [openPanel setCanChooseFiles: NO]; + } + + [openPanel setAllowsMultipleSelection: mult]; + + // allowed files + // TODO: allowed files using the NSOpenSavePanelDelegate xd + // NSMutableArray* allowed = [NSMutableArray array]; + + // for (auto& f : options.filters) { + // for (auto& i : f.files) { + // auto nsstr = [NSString stringWithUTF8String: i.c_str()]; + + // if (![allowed containsObject: nsstr]) + // [allowed addObject: nsstr]; + // } + // } + + // if (options.filters.size()) + // [panel setAllowedFileTypes: allowed]; + } // run thing @@ -111,11 +128,16 @@ void utils::web::openLinkInBrowser(std::string const& url) { if (result == NSModalResponseOK) { std::vector fileURLs; - - for (NSURL* i in panel.URLs) { - fileURLs.push_back(std::string(i.path.UTF8String)); + if (mode == file::PickMode::SaveFile) { + fileURLs.push_back(std::string([[[panel URL] path] UTF8String])); } + else { + auto openPanel = (NSOpenPanel*)panel; + for (NSURL* i in openPanel.URLs) { + fileURLs.push_back(std::string(i.path.UTF8String)); + } + } return Ok(fileURLs); } else { return Err("File picker cancelled"); diff --git a/loader/test/members/MacOS.cpp b/loader/test/members/MacOS.cpp index fbb3f072..42eb843b 100644 --- a/loader/test/members/MacOS.cpp +++ b/loader/test/members/MacOS.cpp @@ -72,4 +72,7 @@ GEODE_MEMBER_CHECK(LevelBrowserLayer, m_leftArrow, 0x1a8); GEODE_MEMBER_CHECK(LevelBrowserLayer, m_searchObject, 0x1d8); GEODE_MEMBER_CHECK(LevelBrowserLayer, m_itemCount, 0x208); +// LocalLevelManager +GEODE_MEMBER_CHECK(LocalLevelManager, m_localLevels, 0x140); + #endif \ No newline at end of file