From 1a50afbbed656027e2c3603c3d91d14cabe04fdc Mon Sep 17 00:00:00 2001 From: VoltZ <47382115+SuperSaiyajinVoltZ@users.noreply.github.com> Date: Tue, 12 Nov 2019 17:45:00 +0100 Subject: [PATCH] Some next TinyDB Screen work. To-Do: Figure out how to handle that info stuff from the arrays. --- assets/gfx/sprites.t3s | 2 + assets/gfx/sprites/search.png | Bin 0 -> 456 bytes include/screens/tinyDB.hpp | 8 ++ romfs/lang/en/app.json | 4 +- source/screens/mainMenu.cpp | 16 ++- source/screens/scriptBrowse.cpp | 3 + source/screens/tinyDB.cpp | 179 +++++++++++++++++++++++++++++++- 7 files changed, 207 insertions(+), 5 deletions(-) create mode 100644 assets/gfx/sprites/search.png 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 0000000000000000000000000000000000000000..0b2a2ef6a4541f943c7c4c0eaa78c5091f08b015 GIT binary patch literal 456 zcmV;(0XP1MP)?#ptY9v{0W-C z6OfDjhF6QCO^-gLybbMWep ziH5Iui7e-B4}M47AyD)&&?3vZPc92UUoj5d7n26t*L(?ldKmZsuJr7ch6l|3mJeB| zDaOEu9E)5IFtDl^vAdWzpGyG-Qtr1DPHNy;^G1MyP0cSp25vR)1Q^)WeB(n-uVI8; zsk|6@4JSnjYb*&?g7e~pz(NGp)zVU2&%v8YDF&!u2Pies;rDbDuzx<4W>g_-udifn zwhx?PMW(D#(^}uz*Cn7GyW)|4H?Vw;`yd$td%nV>#8VWp6Ws&uu?iRKxuwbxXu7?C$h|h&MSe5(fz|9ox{}f+f=J*1B-G3@Zc3YGH0000()); + 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