From 0fb5d03a87ef10789747bc5c9bc288b1b37072b4 Mon Sep 17 00:00:00 2001 From: StackZ <47382115+SuperSaiyajinStackZ@users.noreply.github.com> Date: Wed, 25 Dec 2019 21:35:20 +0100 Subject: [PATCH] Add Script path Selection inside U-U! Press inside the Settings Sub Menu to select it. --- include/screens/settings.hpp | 1 + include/utils/fileBrowse.h | 2 + romfs/lang/en/app.json | 9 +- source/screens/mainMenu.cpp | 2 +- source/screens/settings.cpp | 4 + source/utils/fileBrowse.cpp | 162 ++++++++++++++++++++++++++++++++++- 6 files changed, 176 insertions(+), 4 deletions(-) diff --git a/include/screens/settings.hpp b/include/screens/settings.hpp index bc69d5f..cd5bd00 100644 --- a/include/screens/settings.hpp +++ b/include/screens/settings.hpp @@ -30,6 +30,7 @@ #include "screens/screen.hpp" #include "screens/screenCommon.hpp" +#include "utils/fileBrowse.h" #include "utils/structs.hpp" #include diff --git a/include/utils/fileBrowse.h b/include/utils/fileBrowse.h index bc77720..50eeffd 100644 --- a/include/utils/fileBrowse.h +++ b/include/utils/fileBrowse.h @@ -28,4 +28,6 @@ void getDirectoryContents(std::vector& dirContents, const std::vector< void getDirectoryContents(std::vector& dirContents); std::vector getContents(const std::string &name, const std::vector &extensionList); +std::string selectFilePath(std::string selectText, int selectionMode = 1); + #endif //FILE_BROWSE_H \ No newline at end of file diff --git a/romfs/lang/en/app.json b/romfs/lang/en/app.json index 7d8332f..f85b871 100644 --- a/romfs/lang/en/app.json +++ b/romfs/lang/en/app.json @@ -77,5 +77,12 @@ "TITLE_ID": "Title ID: ", "FILE_SIZE": "File size: ", - "GET_SCRIPTS_FIRST": "Get some Scripts first!" + "GET_SCRIPTS_FIRST": "Get some Scripts first!", + + "OPEN": "Open", + "SELECT": "Select", + "REFRESH": "Refresh", + "BACK": "Back", + "FILEBROWSE_MSG": "Press X to select, Select to refresh.", + "SELECT_SCRIPT_PATH": "Select the Script Path." } diff --git a/source/screens/mainMenu.cpp b/source/screens/mainMenu.cpp index 2ed985a..7249db8 100644 --- a/source/screens/mainMenu.cpp +++ b/source/screens/mainMenu.cpp @@ -167,7 +167,7 @@ void MainMenu::Logic(u32 hDown, u32 hHeld, touchPosition touch) { } else { notConnectedMsg(); } - } else if (touching(touch, mainButtons[2])) { + } else if (touching(touch, mainButtons[2])) { if (checkWifiStatus() == true) { Screen::set(std::make_unique()); } else { diff --git a/source/screens/settings.cpp b/source/screens/settings.cpp index f31b03b..d2606bc 100644 --- a/source/screens/settings.cpp +++ b/source/screens/settings.cpp @@ -217,6 +217,10 @@ void Settings::SubMenuLogic(u32 hDown, u32 hHeld, touchPosition touch) { if(Selection > 0) Selection--; } + if (hDown & KEY_Y) { + Config::ScriptPath = selectFilePath(Lang::get("SELECT_SCRIPT_PATH")); + } + if (hDown & KEY_DOWN) { if(Selection < 2) Selection++; } diff --git a/source/utils/fileBrowse.cpp b/source/utils/fileBrowse.cpp index 20182c9..da31121 100644 --- a/source/utils/fileBrowse.cpp +++ b/source/utils/fileBrowse.cpp @@ -1,6 +1,11 @@ -#include "utils/fileBrowse.h" - #include "gui.hpp" + +#include "screens/screenCommon.hpp" + +#include "utils/config.hpp" +#include "utils/fileBrowse.h" +#include "utils/structs.hpp" + #include <3ds.h> #include #include @@ -21,6 +26,17 @@ extern int keyRepeatDelay; extern bool dirChanged; extern std::vector dirContents; +extern bool touching(touchPosition touch, Structs::ButtonPos button); +extern touchPosition touch; + +std::vector buttonPositions = { + {295, 0, 25, 25, -1}, // Arrow Up. + {295, 215, 25, 25, -1}, // Arrow Down. + {15, 220, 50, 15, -1}, // Open. + {80, 220, 50, 15, -1}, // Select. + {145, 220, 50, 15, -1}, // Refresh. + {210, 220, 50, 15, -1}, // Back. +}; /** * Get the title ID. @@ -171,4 +187,146 @@ std::vector getContents(const std::string &name, const std::vector< } closedir(pdir); return dirContents; +} + +// returns a Path or file to 'std::string'. +// selectText is the Text which is displayed on the bottom bar of the top screen. +// selectionMode is how you select it. 1 -> Path, 2 -> File. +std::string selectFilePath(std::string selectText, int selectionMode) { + static uint selectedFile = 0; + std::string selectedPath = ""; + static int keyRepeatDelay = 4; + static bool dirChanged = true; + static bool fastMode = false; + std::vector dirContents; + + while (1) { + Gui::clearTextBufs(); + C3D_FrameBegin(C3D_FRAME_SYNCDRAW); + C2D_TargetClear(top, BLACK); + C2D_TargetClear(bottom, BLACK); + Gui::DrawTop(); + char path[PATH_MAX]; + getcwd(path, PATH_MAX); + Gui::DrawString((400-(Gui::GetStringWidth(0.60f, path)))/2, 0, 0.60f, Config::TxtColor, path); + Gui::DrawStringCentered(0, 218, 0.60f, Config::TxtColor, selectText, 400); + std::string dirs; + for (uint i=(selectedFile<5) ? 0 : selectedFile-5;i dirContentsTemp; + getDirectoryContents(dirContentsTemp); + for(uint i=0;i 0) selectedFile--; + } + + if (hidKeysDown() & KEY_TOUCH && touching(touch, buttonPositions[1])) { + if (selectedFile < dirContents.size()-1) selectedFile++; + } + + if (hidKeysHeld() & KEY_UP) { + if (selectedFile > 0 && !keyRepeatDelay) { + selectedFile--; + if (fastMode == true) { + keyRepeatDelay = 3; + } else if (fastMode == false){ + keyRepeatDelay = 6; + } + } + } + if (hidKeysHeld() & KEY_DOWN && !keyRepeatDelay) { + if (selectedFile < dirContents.size()-1) { + selectedFile++; + if (fastMode == true) { + keyRepeatDelay = 3; + } else if (fastMode == false){ + keyRepeatDelay = 6; + } + } + } + + if (hidKeysDown() & KEY_B || hidKeysDown() & KEY_TOUCH && touching(touch, buttonPositions[5])) { + char path[PATH_MAX]; + getcwd(path, PATH_MAX); + if(strcmp(path, "sdmc:/") == 0 || strcmp(path, "/") == 0) { + } else { + chdir(".."); + selectedFile = 0; + dirChanged = true; + } + } + + if (hidKeysDown() & KEY_X || hidKeysDown() & KEY_TOUCH && touching(touch, buttonPositions[3])) { + char path[PATH_MAX]; + getcwd(path, PATH_MAX); + selectedPath = path; + if (selectionMode == 2) { + selectedPath += dirContents[selectedFile].name; + } + return selectedPath; + } + + if (hidKeysDown() & KEY_R) { + fastMode = true; + } + + if (hidKeysDown() & KEY_L) { + fastMode = false; + } + } } \ No newline at end of file