11#pragma once
22
3- class MLE_MainMenu : public geode ::Popup<> {
3+ class MLE_MainMenu : public geode ::Popup {
44protected:
5- using FileEvent = Task<Result<std::filesystem::path>>;
6- EventListener<FileEvent> m_listener;
5+ // using FileEvent = Task<Result<std::filesystem::path>>;
6+ // EventListener<FileEvent> m_listener;
77 static auto resolveListEntry (Ref<TextInput> textinput, Ref<GJGameLevel> level) {
88 // parse input
99 std::string input = textinput->getString ();
@@ -170,7 +170,8 @@ class MLE_MainMenu : public geode::Popup<> {
170170 menu->addChildAtPosition (item, Anchor::Left, { 4 .f , -0 .f }, !" nopls" );
171171 }
172172 }
173- bool setup () override {
173+ bool init () override {
174+ Popup::init (258 .000f , 284 .000f );
174175 this ->setTitle (" " );
175176
176177 // menu
@@ -377,10 +378,11 @@ class MLE_MainMenu : public geode::Popup<> {
377378 auto IMPORT_PICK_OPTIONS = file::FilePickOptions{
378379 std::nullopt , {{ " Extended Shared Level File" , { " *.level" } }}
379380 };
380- __this->m_listener .bind ([](FileEvent::Event* e) {
381- if (e->getValue ()) {
382- if (e->getValue ()->isOk ()) {
383- auto path = e->getValue ()->unwrap ();
381+ async::spawn (
382+ file::pick (file::PickMode::OpenFile, IMPORT_PICK_OPTIONS ),
383+ [](Result<std::optional<std::filesystem::path>> e) {
384+ if (e.isOk ()) {
385+ auto path = e.unwrapOrDefault ().value_or (" " );
384386 auto exist = CCFileUtils::get ()->isFileExist (string::pathToString (path).c_str ());
385387 if (!string::endsWith (string::pathToString (path), " .level" ) and !exist) {
386388 path = std::filesystem::path (string::pathToString (path) + " .level" );
@@ -419,11 +421,9 @@ class MLE_MainMenu : public geode::Popup<> {
419421 MDPopup::create (" Failed to load level!" , level_import.err ().value_or (" UNK ERROR" ), " OK" )->show ();
420422 }
421423 }
422- else log::error (" Something went wrong when picking files: {}" , e-> getValue ()-> err ());
424+ else log::error (" Something went wrong when picking files: {}" , e. err ());
423425 }
424- else log::error (" Something went wrong when picking files: Value is empty." );
425- });
426- __this->m_listener .setFilter (file::pick (file::PickMode::OpenFile, IMPORT_PICK_OPTIONS ));
426+ );
427427 }
428428 );
429429 if (menu and load_level) {
@@ -438,10 +438,11 @@ class MLE_MainMenu : public geode::Popup<> {
438438 auto IMPORT_PICK_OPTIONS = file::FilePickOptions{
439439 std::nullopt , {{ " Extended Shared Level File" , { " *.level" } }}
440440 };
441- __this->m_listener .bind ([](FileEvent::Event* e) {
442- if (e->getValue ()) {
443- if (e->getValue ()->isOk ()) {
444- auto path = e->getValue ()->unwrap ();
441+ async::spawn (
442+ file::pick (file::PickMode::OpenFile, IMPORT_PICK_OPTIONS ),
443+ [](Result<std::optional<std::filesystem::path>> e) {
444+ if (e.isOk ()) {
445+ auto path = e.unwrapOrDefault ().value_or (" " );
445446 auto exist = CCFileUtils::get ()->isFileExist (string::pathToString (path).c_str ());
446447 if (!string::endsWith (string::pathToString (path), " .level" ) and !exist) {
447448 path = std::filesystem::path (string::pathToString (path) + " .level" );
@@ -456,11 +457,9 @@ class MLE_MainMenu : public geode::Popup<> {
456457 MDPopup::create (" Failed to load level!" , level_import.err ().value_or (" UNK ERROR" ), " OK" )->show ();
457458 }
458459 }
459- else log::error (" Something went wrong when picking files: {}" , e-> getValue ()-> err ());
460+ else log::error (" Something went wrong when picking files: {}" , e. err ());
460461 }
461- else log::error (" Something went wrong when picking files: Value is empty." );
462- });
463- __this->m_listener .setFilter (file::pick (file::PickMode::OpenFile, IMPORT_PICK_OPTIONS ));
462+ );
464463 }
465464 );
466465 if (menu and edit_level) {
@@ -537,11 +536,11 @@ class MLE_MainMenu : public geode::Popup<> {
537536 getMod ()->getConfigDir () / fmt::format (" {}.level" , level->m_levelID .value ()),
538537 {{ " Extended Shared Level File" , { " *.level" } }}
539538 };
540- __this-> m_listener . bind ([level](FileEvent::Event* e) {
541- if (e-> getValue ()) {
542- if (e-> getValue ()-> isOk () ) {
543- // path
544- auto path = e-> getValue ()-> unwrap ( );
539+ async::spawn (
540+ file::pick (file::PickMode::SaveFile, IMPORT_PICK_OPTIONS ),
541+ [level](Result<std::optional<std::filesystem::path>> e ) {
542+ if (e. isOk ()) {
543+ auto path = e. unwrapOrDefault (). value_or ( " " );
545544 path = string::endsWith (string::pathToString (path), " .level"
546545 ) ? string::pathToString (path) : (string::pathToString (path) + " .level" );
547546 // dir
@@ -595,14 +594,10 @@ class MLE_MainMenu : public geode::Popup<> {
595594 }
596595 }
597596 else {
598- log::error (" Something went wrong when picking files: {}" , e-> getValue ()-> err ());
597+ log::error (" Something went wrong when picking files: {}" , e. err ());
599598 }
600599 }
601- else {
602- log::error (" Something went wrong when picking files: Value is empty." );
603- }
604- });
605- __this->m_listener .setFilter (file::pick (file::PickMode::SaveFile, IMPORT_PICK_OPTIONS ));
600+ );
606601 }
607602 );
608603 if (menu and export_level) {
@@ -989,7 +984,7 @@ class MLE_MainMenu : public geode::Popup<> {
989984 ->setGrowCrossAxis (true )
990985 ->setCrossAxisOverflow (false )
991986 );
992- menu->getLayout ()->ignoreInvisibleChildren (true ); // lol
987+ ((ColumnLayout*) menu->getLayout () )->ignoreInvisibleChildren (true ); // lol
993988 menu->updateLayout (); // xd ^^^
994989 limitNodeWidth (menu, this ->m_mainLayer ->getContentWidth () - 16 .f , 1 .f , 0 .1f );
995990
@@ -998,7 +993,7 @@ class MLE_MainMenu : public geode::Popup<> {
998993public:
999994 static MLE_MainMenu* create () {
1000995 auto ret = new MLE_MainMenu ();
1001- if (ret->initAnchored ( 258 . 000f , 284 . 000f )) {
996+ if (ret->init ( )) {
1002997 ret->autorelease ();
1003998 return ret;
1004999 }
0 commit comments