diff --git a/assets/gfx/sprites.t3s b/assets/gfx/sprites.t3s index c40ca54..b025216 100644 --- a/assets/gfx/sprites.t3s +++ b/assets/gfx/sprites.t3s @@ -1,4 +1,6 @@ --atlas -f rgba -z auto +sprites/search.png + sprites/credits/discord.png sprites/credits/voltZ.png \ No newline at end of file diff --git a/assets/gfx/sprites/search.png b/assets/gfx/sprites/search.png new file mode 100644 index 0000000..0b2a2ef Binary files /dev/null and b/assets/gfx/sprites/search.png differ diff --git a/include/screens/tinyDB.hpp b/include/screens/tinyDB.hpp index b949f55..b57cb52 100644 --- a/include/screens/tinyDB.hpp +++ b/include/screens/tinyDB.hpp @@ -34,8 +34,16 @@ class TinyDB : public Screen public: void Draw(void) const override; void Logic(u32 hDown, u32 hHeld, touchPosition touch) override; + TinyDB(); private: + void execute(); + mutable int selection = 0; + int screenPos = 0; + int listMode = 0; + mutable int screenPosList = 0; + int keyRepeatDelay = 0; + int fastMode = false; }; #endif \ No newline at end of file diff --git a/romfs/lang/en/app.json b/romfs/lang/en/app.json index 834c650..9de4e9a 100644 --- a/romfs/lang/en/app.json +++ b/romfs/lang/en/app.json @@ -67,5 +67,7 @@ "SCRIPTCREATORS": "All Script Creators", "CREATING_SCRIPTS": "- For creating Scripts for Universal-Updater.", "SHOW_QR": "Click here to show the QR Code.", - "LINK": "Join our Discord: https://discord.gg/KDJCfGF" + "LINK": "Join our Discord: https://discord.gg/KDJCfGF", + + "TINYDB_DOWNLOADING": "Downloading database of available titles from TinyDB..." } diff --git a/source/screens/mainMenu.cpp b/source/screens/mainMenu.cpp index e52c02a..bb4cbda 100644 --- a/source/screens/mainMenu.cpp +++ b/source/screens/mainMenu.cpp @@ -99,7 +99,11 @@ void MainMenu::Logic(u32 hDown, u32 hHeld, touchPosition touch) { } break; case 2: - Gui::setScreen(std::make_unique()); + if (checkWifiStatus() == true) { + Gui::setScreen(std::make_unique()); + } else { + notConnectedMsg(); + } break; case 3: if (isTesting == true) { @@ -112,6 +116,8 @@ void MainMenu::Logic(u32 hDown, u32 hHeld, touchPosition touch) { case 5: if (checkWifiStatus() == true) { Gui::setScreen(std::make_unique()); + } else { + notConnectedMsg(); } break; } @@ -134,7 +140,11 @@ void MainMenu::Logic(u32 hDown, u32 hHeld, touchPosition touch) { } } else if (touching(touch, mainButtons[2])) { - Gui::setScreen(std::make_unique()); + if (checkWifiStatus() == true) { + Gui::setScreen(std::make_unique()); + } else { + notConnectedMsg(); + } } else if (touching(touch, mainButtons[3])) { if (isTesting == true) { Gui::setScreen(std::make_unique()); @@ -144,6 +154,8 @@ void MainMenu::Logic(u32 hDown, u32 hHeld, touchPosition touch) { } else if (touching(touch, mainButtons[5])) { if (checkWifiStatus() == true) { Gui::setScreen(std::make_unique()); + } else { + notConnectedMsg(); } } } diff --git a/source/screens/scriptBrowse.cpp b/source/screens/scriptBrowse.cpp index af41fe4..1a65c27 100644 --- a/source/screens/scriptBrowse.cpp +++ b/source/screens/scriptBrowse.cpp @@ -128,6 +128,9 @@ void ScriptBrowse::Draw(void) const { Gui::DrawStringCentered(0, 215, 0.7f, Config::TxtColor, Lang::get("FUTURE_SCRIPT"), 400); } Gui::DrawBottom(); + Gui::Draw_Rect(0, 0, 27, 30, WHITE); + Gui::sprite(sprites_search_idx, -3, 0); + Gui::DrawString(7.5, 1.5, 0.72f, BLACK, "\uE003"); Gui::DrawString(317-Gui::GetStringWidth(0.6f, std::to_string(selection + 1) + " / " + maxScripts), 4, 0.6f, Config::TxtColor, std::to_string(selection + 1) + " / " + maxScripts); if (listMode == 0) { diff --git a/source/screens/tinyDB.cpp b/source/screens/tinyDB.cpp index f3c1ff6..dd4324d 100644 --- a/source/screens/tinyDB.cpp +++ b/source/screens/tinyDB.cpp @@ -24,20 +24,195 @@ * reasonable ways as different from the original version. */ +#include "download/download.hpp" + #include "screens/tinyDB.hpp" #include "utils/config.hpp" +#include "utils/fileBrowse.h" +#include "utils/json.hpp" + +#define ENTRIES_PER_SCREEN 3 +#define ENTRIES_PER_LIST 7 + +// JSON file for TinyDB. +nlohmann::json tinyDBJson; +std::string selectedOption; + +#define tinyDBFile "sdmc:/3ds/Universal-Updater/TinyDB.json" + +extern std::string get(nlohmann::json json, const std::string &key, const std::string &key2); +std::string maxEntries; + +// Parse the Objects. +std::vector parseObjects() { + FILE* file = fopen(tinyDBFile, "rt"); + if(!file) { + printf("File not found\n"); + fclose(file); + return {{""}}; + } + tinyDBJson = nlohmann::json::parse(file, nullptr, false); + fclose(file); + + std::vector objs; + for(auto it = tinyDBJson.begin();it != tinyDBJson.end(); it++) { + if(it.key() != "info") { + objs.push_back(it.key()); + } + } + return objs; +} + +std::vector tinyDBList; + +TinyDB::TinyDB() { + DisplayMsg(Lang::get("TINYDB_DOWNLOADING")); + downloadToFile("https://tinydb.eiphax.tech/api/universal.json?raw=true", tinyDBFile); + tinyDBList = parseObjects(); +} // To-Do. void TinyDB::Draw(void) const { - Gui::DrawTop(); + std::string info; + Gui::ScreenDraw(top); + Gui::Draw_Rect(0, 0, 400, 30, C2D_Color32(63, 81, 181, 255)); + Gui::Draw_Rect(0, 30, 400, 180, C2D_Color32(140, 140, 140, 255)); + Gui::Draw_Rect(0, 210, 400, 30, C2D_Color32(63, 81, 181, 255)); + Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, "TinyDB", 400); - Gui::DrawBottom(); + std::string entryAmount = std::to_string(selection+1) + " / " + std::to_string(tinyDBList.size()); + Gui::DrawString(397-Gui::GetStringWidth(0.6f, entryAmount), 237-Gui::GetStringHeight(0.6f, entryAmount), 0.6f, Config::TxtColor, entryAmount); + + + Gui::ScreenDraw(bottom); + Gui::Draw_Rect(0, 0, 320, 30, C2D_Color32(63, 81, 181, 255)); + Gui::Draw_Rect(0, 30, 320, 180, C2D_Color32(140, 140, 140, 255)); + Gui::Draw_Rect(0, 210, 320, 30, C2D_Color32(63, 81, 181, 255)); + + // Search Icon. + Gui::sprite(sprites_search_idx, -3, 0); + Gui::DrawString(7.5, 1.5, 0.72f, BLACK, "\uE003"); + + if (listMode == 0) { + for(int i=0;i 0) { + selection--; + } else { + selection = (int)tinyDBList.size()-1; + } + if (fastMode == true) { + keyRepeatDelay = 3; + } else if (fastMode == false){ + keyRepeatDelay = 6; + } + } + + if (hHeld & KEY_DOWN && !keyRepeatDelay) { + if (selection < (int)tinyDBList.size()-1) { + selection++; + } else { + selection = 0; + } + if (fastMode == true) { + keyRepeatDelay = 3; + } else if (fastMode == false){ + keyRepeatDelay = 6; + } + } + + if (listMode == 0) { + if(selection < screenPos) { + screenPos = selection; + } else if (selection > screenPos + ENTRIES_PER_SCREEN - 1) { + screenPos = selection - ENTRIES_PER_SCREEN + 1; + } + } else if (listMode == 1) { + if(selection < screenPosList) { + screenPosList = selection; + } else if (selection > screenPosList + ENTRIES_PER_LIST - 1) { + screenPosList = selection - ENTRIES_PER_LIST + 1; + } + } + + if (hDown & KEY_X) { + if (listMode == 0) { + listMode = 1; + } else { + listMode = 0; + } + } + + if (hDown & KEY_A) { + selectedOption = tinyDBList[selection]; + execute(); + } +} + +void TinyDB::execute() { + for(int i=0;i<(int)tinyDBJson.at(selectedOption).size();i++) { + std::string type = tinyDBJson.at(selectedOption).at(i).at("type"); + if(type == "deleteFile") { + bool missing = false; + std::string file, message; + if(tinyDBJson.at(selectedOption).at(i).contains("file")) file = tinyDBJson.at(selectedOption).at(i).at("file"); + else missing = true; + if(tinyDBJson.at(selectedOption).at(i).contains("message")) message = tinyDBJson.at(selectedOption).at(i).at("message"); + if(!missing) download::deleteFileList(file, message); + + } else if(type == "downloadFile") { + bool missing = false; + std::string file, output, message; + if(tinyDBJson.at(selectedOption).at(i).contains("file")) file = tinyDBJson.at(selectedOption).at(i).at("file"); + else missing = true; + if(tinyDBJson.at(selectedOption).at(i).contains("output")) output = tinyDBJson.at(selectedOption).at(i).at("output"); + else missing = true; + if(tinyDBJson.at(selectedOption).at(i).contains("message")) message = tinyDBJson.at(selectedOption).at(i).at("message"); + if(!missing) download::downloadFile(file, output, message); + + } else if(type == "installCia") { + bool missing = false; + std::string file, message; + if(tinyDBJson.at(selectedOption).at(i).contains("file")) file = tinyDBJson.at(selectedOption).at(i).at("file"); + else missing = true; + if(tinyDBJson.at(selectedOption).at(i).contains("message")) message = tinyDBJson.at(selectedOption).at(i).at("message"); + if(!missing) download::installFileList(file, message); + } + } + doneMsg(); } \ No newline at end of file