Some next TinyDB Screen work.

To-Do: Figure out how to handle that info stuff from the arrays.
This commit is contained in:
VoltZ
2019-11-12 17:45:00 +01:00
parent 9100258f9e
commit 1a50afbbed
7 changed files with 207 additions and 5 deletions
+2
View File
@@ -1,4 +1,6 @@
--atlas -f rgba -z auto --atlas -f rgba -z auto
sprites/search.png
sprites/credits/discord.png sprites/credits/discord.png
sprites/credits/voltZ.png sprites/credits/voltZ.png
Binary file not shown.

After

Width:  |  Height:  |  Size: 456 B

+8
View File
@@ -34,8 +34,16 @@ class TinyDB : public Screen
public: public:
void Draw(void) const override; void Draw(void) const override;
void Logic(u32 hDown, u32 hHeld, touchPosition touch) override; void Logic(u32 hDown, u32 hHeld, touchPosition touch) override;
TinyDB();
private: private:
void execute();
mutable int selection = 0;
int screenPos = 0;
int listMode = 0;
mutable int screenPosList = 0;
int keyRepeatDelay = 0;
int fastMode = false;
}; };
#endif #endif
+3 -1
View File
@@ -67,5 +67,7 @@
"SCRIPTCREATORS": "All Script Creators", "SCRIPTCREATORS": "All Script Creators",
"CREATING_SCRIPTS": "- For creating Scripts for Universal-Updater.", "CREATING_SCRIPTS": "- For creating Scripts for Universal-Updater.",
"SHOW_QR": "Click here to show the QR Code.", "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..."
} }
+14 -2
View File
@@ -99,7 +99,11 @@ void MainMenu::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
} }
break; break;
case 2: case 2:
Gui::setScreen(std::make_unique<TinyDB>()); if (checkWifiStatus() == true) {
Gui::setScreen(std::make_unique<TinyDB>());
} else {
notConnectedMsg();
}
break; break;
case 3: case 3:
if (isTesting == true) { if (isTesting == true) {
@@ -112,6 +116,8 @@ void MainMenu::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
case 5: case 5:
if (checkWifiStatus() == true) { if (checkWifiStatus() == true) {
Gui::setScreen(std::make_unique<FTPScreen>()); Gui::setScreen(std::make_unique<FTPScreen>());
} else {
notConnectedMsg();
} }
break; break;
} }
@@ -134,7 +140,11 @@ void MainMenu::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
} }
} else if (touching(touch, mainButtons[2])) { } else if (touching(touch, mainButtons[2])) {
Gui::setScreen(std::make_unique<TinyDB>()); if (checkWifiStatus() == true) {
Gui::setScreen(std::make_unique<TinyDB>());
} else {
notConnectedMsg();
}
} else if (touching(touch, mainButtons[3])) { } else if (touching(touch, mainButtons[3])) {
if (isTesting == true) { if (isTesting == true) {
Gui::setScreen(std::make_unique<ScriptCreator>()); Gui::setScreen(std::make_unique<ScriptCreator>());
@@ -144,6 +154,8 @@ void MainMenu::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
} else if (touching(touch, mainButtons[5])) { } else if (touching(touch, mainButtons[5])) {
if (checkWifiStatus() == true) { if (checkWifiStatus() == true) {
Gui::setScreen(std::make_unique<FTPScreen>()); Gui::setScreen(std::make_unique<FTPScreen>());
} else {
notConnectedMsg();
} }
} }
} }
+3
View File
@@ -128,6 +128,9 @@ void ScriptBrowse::Draw(void) const {
Gui::DrawStringCentered(0, 215, 0.7f, Config::TxtColor, Lang::get("FUTURE_SCRIPT"), 400); Gui::DrawStringCentered(0, 215, 0.7f, Config::TxtColor, Lang::get("FUTURE_SCRIPT"), 400);
} }
Gui::DrawBottom(); 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); 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) { if (listMode == 0) {
+177 -2
View File
@@ -24,20 +24,195 @@
* reasonable ways as different from the original version. * reasonable ways as different from the original version.
*/ */
#include "download/download.hpp"
#include "screens/tinyDB.hpp" #include "screens/tinyDB.hpp"
#include "utils/config.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<std::string> 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<std::string> objs;
for(auto it = tinyDBJson.begin();it != tinyDBJson.end(); it++) {
if(it.key() != "info") {
objs.push_back(it.key());
}
}
return objs;
}
std::vector<std::string> tinyDBList;
TinyDB::TinyDB() {
DisplayMsg(Lang::get("TINYDB_DOWNLOADING"));
downloadToFile("https://tinydb.eiphax.tech/api/universal.json?raw=true", tinyDBFile);
tinyDBList = parseObjects();
}
// To-Do. // To-Do.
void TinyDB::Draw(void) const { 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::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<ENTRIES_PER_SCREEN && i<(int)tinyDBList.size();i++) {
info = tinyDBList[screenPos + i];
if(screenPos + i == selection) {
Gui::Draw_Rect(0, 40+(i*57), 320, 45, C2D_Color32(120, 192, 216, 255));
} else {
Gui::Draw_Rect(0, 40+(i*57), 320, 45, C2D_Color32(77, 118, 132, 255));
}
Gui::DrawStringCentered(0, 50+(i*57), 0.7f, WHITE, info, 320);
}
} else if (listMode == 1) {
for(int i=0;i<ENTRIES_PER_LIST && i<(int)tinyDBList.size();i++) {
info = tinyDBList[screenPosList + i];
if(screenPosList + i == selection) {
Gui::Draw_Rect(0, 30+(i*25), 320, 30, Config::SelectedColor);
}
Gui::DrawStringCentered(0, 35+(i*25), 0.7f, Config::TxtColor, info, 320);
}
}
} }
void TinyDB::Logic(u32 hDown, u32 hHeld, touchPosition touch) { void TinyDB::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
if (keyRepeatDelay) keyRepeatDelay--;
if (hDown & KEY_B) { if (hDown & KEY_B) {
Gui::screenBack(); Gui::screenBack();
return; return;
} }
if (hDown & KEY_R) {
fastMode = true;
}
if (hDown & KEY_L) {
fastMode = false;
}
if (hHeld & KEY_UP && !keyRepeatDelay) {
if (selection > 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();
} }