diff --git a/include/keyboard.hpp b/include/keyboard.hpp index 29adb50..ee77a08 100644 --- a/include/keyboard.hpp +++ b/include/keyboard.hpp @@ -9,6 +9,8 @@ namespace Input { std::string Numpad(uint maxLength, std::string Text); // -1 if invaild text entered int getUint(int max, std::string Text); + + std::string getString(const std::string &hint, uint maxLength); } #endif \ No newline at end of file diff --git a/include/screens/mainMenu.hpp b/include/screens/mainMenu.hpp index c4105e7..bbf7ffa 100644 --- a/include/screens/mainMenu.hpp +++ b/include/screens/mainMenu.hpp @@ -40,10 +40,12 @@ public: private: int Selection = 0; std::vector mainButtons = { - {10, 75, 140, 35, -1}, // ScriptList. - {170, 75, 140, 35, -1}, // ScriptBrowse. - {10, 140, 140, 35, -1}, // Language. - {170, 140, 140, 35, -1}, // Colors. + {10, 40, 140, 35, -1}, // Scriptlist. + {170, 40, 140, 35, -1}, // ScriptBrowse. + {10, 100, 140, 35, -1}, // TinyDB. + {170, 100, 140, 35, -1}, // ScriptCreator. + {10, 160, 140, 35, -1}, // Language. + {170, 160, 140, 35, -1}, // Colors. }; }; diff --git a/include/screens/scriptCreator.hpp b/include/screens/scriptCreator.hpp new file mode 100644 index 0000000..abca930 --- /dev/null +++ b/include/screens/scriptCreator.hpp @@ -0,0 +1,51 @@ +/* +* This file is part of Universal-Updater +* Copyright (C) 2019 VoltZ, Epicpkmn11, Flame, RocketRobz, TotallyNotGuy +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* Additional Terms 7.b and 7.c of GPLv3 apply to this file: +* * Requiring preservation of specified reasonable legal notices or +* author attributions in that material or in the Appropriate Legal +* Notices displayed by works containing it. +* * Prohibiting misrepresentation of the origin of that material, +* or requiring that modified versions of such material be marked in +* reasonable ways as different from the original version. +*/ +#ifndef SCRIPTCREATOR_HPP +#define SCRIPTCREATOR_HPP + +#include "screens/screen.hpp" +#include "screens/screenCommon.hpp" + +#include "utils/json.hpp" + +class ScriptCreator : public Screen +{ +public: + void Draw(void) const override; + void Logic(u32 hDown, u32 hHeld, touchPosition touch) override; + ScriptCreator(); + +private: + void openJson(); + void save(); + + + void setBool(const std::string &object, const std::string &key, bool v); + void setInt(const std::string &object, const std::string &key, int v); + void setString(const std::string &object, const std::string &key, const std::string &v); +}; + +#endif \ No newline at end of file diff --git a/include/screens/tinyDB.hpp b/include/screens/tinyDB.hpp new file mode 100644 index 0000000..b949f55 --- /dev/null +++ b/include/screens/tinyDB.hpp @@ -0,0 +1,41 @@ +/* +* This file is part of Universal-Updater +* Copyright (C) 2019 VoltZ, Epicpkmn11, Flame, RocketRobz, TotallyNotGuy +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* Additional Terms 7.b and 7.c of GPLv3 apply to this file: +* * Requiring preservation of specified reasonable legal notices or +* author attributions in that material or in the Appropriate Legal +* Notices displayed by works containing it. +* * Prohibiting misrepresentation of the origin of that material, +* or requiring that modified versions of such material be marked in +* reasonable ways as different from the original version. +*/ +#ifndef TINYDB_HPP +#define TINYDB_HPP + +#include "screens/screen.hpp" +#include "screens/screenCommon.hpp" + +class TinyDB : public Screen +{ +public: + void Draw(void) const override; + void Logic(u32 hDown, u32 hHeld, touchPosition touch) override; + +private: +}; + +#endif \ No newline at end of file diff --git a/romfs/lang/en/app.json b/romfs/lang/en/app.json index 8a37d38..e0baeb2 100644 --- a/romfs/lang/en/app.json +++ b/romfs/lang/en/app.json @@ -51,5 +51,7 @@ "FAILED_GET_IP": "Failed to get IP.", "FAILED_INITIALIZE_FTP": "Failed to initialize FTP.", "B_FTP_EXIT": "Press B to exit from FTP.", - "WIFI_NOT_ENABLED": "WiFi not enabled." + "WIFI_NOT_ENABLED": "WiFi not enabled.", + + "SCRIPTCREATOR": "Script Creator" } diff --git a/source/keyboard.cpp b/source/keyboard.cpp index 537d914..2770852 100644 --- a/source/keyboard.cpp +++ b/source/keyboard.cpp @@ -149,4 +149,25 @@ int Input::getUint(int max, std::string Text) { int i = atoi(s.c_str()); if(i>max) return 255; return i; +} + +std::string Input::getString(const std::string &hint, uint maxLength) +{ + std::string string; + C3D_FrameEnd(0); + SwkbdState state; + const char *hintText = hint.c_str(); + swkbdInit(&state, SWKBD_TYPE_NORMAL, 2, maxLength); + swkbdSetHintText(&state, hintText); + swkbdSetValidation(&state, SWKBD_NOTBLANK_NOTEMPTY, SWKBD_FILTER_PROFANITY, 0); + char input[maxLength + 1] = {0}; + SwkbdButton ret = swkbdInputText(&state, input, sizeof(input)); + input[maxLength] = '\0'; + if (ret == SWKBD_BUTTON_CONFIRM) + { + string = input; + return string; + } else { + return ""; + } } \ No newline at end of file diff --git a/source/screens/mainMenu.cpp b/source/screens/mainMenu.cpp index e8de14d..c9f59fb 100644 --- a/source/screens/mainMenu.cpp +++ b/source/screens/mainMenu.cpp @@ -29,15 +29,20 @@ #include "screens/ftpScreen.hpp" #include "screens/mainMenu.hpp" #include "screens/scriptBrowse.hpp" +#include "screens/scriptCreator.hpp" #include "screens/scriptlist.hpp" #include "screens/settings.hpp" - +#include "screens/tinyDB.hpp" #include "utils/config.hpp" extern int mode; extern bool exiting; extern bool touching(touchPosition touch, Structs::ButtonPos button); +extern bool checkWifiStatus(void); + +// This is for the Script Creator, so no one can access it for now, until it is stable or so. +bool isTesting = false; void MainMenu::Draw(void) const { Gui::DrawTop(); @@ -45,7 +50,7 @@ void MainMenu::Draw(void) const { Gui::DrawString(397-Gui::GetStringWidth(0.5f, VERSION_STRING), 237-Gui::GetStringHeight(0.5f, VERSION_STRING), 0.5f, Config::TxtColor, VERSION_STRING); Gui::DrawBottom(); - for (int i = 0; i < 4; i++) { + for (int i = 0; i < 6; i++) { if (Selection == i) { Gui::Draw_Rect(mainButtons[i].x, mainButtons[i].y, mainButtons[i].w, mainButtons[i].h, Config::SelectedColor); } else { @@ -55,8 +60,10 @@ void MainMenu::Draw(void) const { Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("SCRIPTLIST")))/2-150+70, mainButtons[0].y+10, 0.6f, Config::TxtColor, Lang::get("SCRIPTLIST"), 140); Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("GET_SCRIPTS")))/2+150-70, mainButtons[1].y+10, 0.6f, Config::TxtColor, Lang::get("GET_SCRIPTS"), 140); - Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("LANGUAGE")))/2-150+70, mainButtons[2].y+10, 0.6f, Config::TxtColor, Lang::get("LANGUAGE"), 140); - Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("COLORS")))/2+150-70, mainButtons[3].y+10, 0.6f, Config::TxtColor, Lang::get("COLORS"), 140); + Gui::DrawString((320-Gui::GetStringWidth(0.6f, "TinyDB"))/2-150+70, mainButtons[2].y+10, 0.6f, Config::TxtColor, "TinyDB", 140); + Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("SCRIPTCREATOR")))/2+150-70, mainButtons[3].y+10, 0.6f, Config::TxtColor, Lang::get("SCRIPTCREATOR"), 140); + Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("LANGUAGE")))/2-150+70, mainButtons[4].y+10, 0.6f, Config::TxtColor, Lang::get("LANGUAGE"), 140); + Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("COLORS")))/2+150-70, mainButtons[5].y+10, 0.6f, Config::TxtColor, Lang::get("COLORS"), 140); } void MainMenu::Logic(u32 hDown, u32 hHeld, touchPosition touch) { @@ -64,13 +71,19 @@ void MainMenu::Logic(u32 hDown, u32 hHeld, touchPosition touch) { exiting = true; } - if(hDown & KEY_UP) { + if (hDown & KEY_UP) { if(Selection > 1) Selection -= 2; - } else if(hDown & KEY_DOWN) { - if(Selection < 3 && Selection != 2 && Selection != 3) Selection += 2; - } else if (hDown & KEY_LEFT) { + } + + if (hDown & KEY_DOWN) { + if(Selection < 4) Selection += 2; + } + + if (hDown & KEY_LEFT) { if (Selection%2) Selection--; - } else if (hDown & KEY_RIGHT) { + } + + if (hDown & KEY_RIGHT) { if (!(Selection%2)) Selection++; } @@ -80,13 +93,25 @@ void MainMenu::Logic(u32 hDown, u32 hHeld, touchPosition touch) { Gui::setScreen(std::make_unique()); break; case 1: - Gui::setScreen(std::make_unique()); + if (checkWifiStatus() == true) { + Gui::setScreen(std::make_unique()); + } else { + notConnectedMsg(); + } break; case 2: + Gui::setScreen(std::make_unique()); + break; + case 3: + if (isTesting == true) { + Gui::setScreen(std::make_unique()); + } + break; + case 4: mode = 0; Gui::setScreen(std::make_unique()); break; - case 3: + case 5: mode = 1; Gui::setScreen(std::make_unique()); break; @@ -94,18 +119,31 @@ void MainMenu::Logic(u32 hDown, u32 hHeld, touchPosition touch) { } if (hDown & KEY_X) { - Gui::setScreen(std::make_unique()); + if (checkWifiStatus() == true) { + Gui::setScreen(std::make_unique()); + } } if (hDown & KEY_TOUCH) { if (touching(touch, mainButtons[0])) { Gui::setScreen(std::make_unique()); } else if (touching(touch, mainButtons[1])) { - Gui::setScreen(std::make_unique()); - } else if (touching(touch, mainButtons[2])) { + if (checkWifiStatus() == true) { + Gui::setScreen(std::make_unique()); + } else { + notConnectedMsg(); + } + + } else if (touching(touch, mainButtons[2])) { + Gui::setScreen(std::make_unique()); + } else if (touching(touch, mainButtons[3])) { + if (isTesting == true) { + Gui::setScreen(std::make_unique()); + } + } else if (touching(touch, mainButtons[4])) { mode = 0; Gui::setScreen(std::make_unique()); - } else if (touching(touch, mainButtons[3])) { + } else if (touching(touch, mainButtons[5])) { mode = 1; Gui::setScreen(std::make_unique()); } diff --git a/source/screens/scriptCreator.cpp b/source/screens/scriptCreator.cpp new file mode 100644 index 0000000..0ebeda0 --- /dev/null +++ b/source/screens/scriptCreator.cpp @@ -0,0 +1,91 @@ +/* +* This file is part of Universal-Updater +* Copyright (C) 2019 VoltZ, Epicpkmn11, Flame, RocketRobz, TotallyNotGuy +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* Additional Terms 7.b and 7.c of GPLv3 apply to this file: +* * Requiring preservation of specified reasonable legal notices or +* author attributions in that material or in the Appropriate Legal +* Notices displayed by works containing it. +* * Prohibiting misrepresentation of the origin of that material, +* or requiring that modified versions of such material be marked in +* reasonable ways as different from the original version. +*/ + +#include "keyboard.hpp" + +#include "screens/scriptCreator.hpp" + +#include "utils/config.hpp" + +// The to editing script. +nlohmann::json editScript; + +void ScriptCreator::openJson() { + FILE* file = fopen("sdmc:/3ds/Universal-Updater/Test.json", "r"); + if(file) editScript = nlohmann::json::parse(file, nullptr, false); + fclose(file); +} + +void ScriptCreator::setBool(const std::string &object, const std::string &key, bool v) { + editScript[object][key] = v; +} + +void ScriptCreator::setInt(const std::string &object, const std::string &key, int v) { + editScript[object][key] = v; +} + +void ScriptCreator::setString(const std::string &object, const std::string &key, const std::string &v) { + editScript[object][key] = v; +} + +void ScriptCreator::Draw(void) const { + Gui::DrawTop(); + Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, Lang::get("SCRIPTCREATOR"), 400); + Gui::DrawBottom(); +} + +// Testing purpose for now. +ScriptCreator::ScriptCreator() { + openJson(); +} + +void ScriptCreator::save() { + FILE* file = fopen("sdmc:/3ds/Universal-Updater/Test.json", "w"); + if(file) fwrite(editScript.dump(1, '\t').c_str(), 1, editScript.dump(1, '\t').size(), file); + fclose(file); +} + +void ScriptCreator::Logic(u32 hDown, u32 hHeld, touchPosition touch) { + if (hDown & KEY_B) { + save(); + Gui::screenBack(); + return; + } + + if (hDown & KEY_X) { + const std::string &test = Input::getString("Enter the Title of the Script.", 50); + const std::string &test2 = Input::getString("Enter the Author name of the Script.", 50); + const std::string &test3 = Input::getString("Enter the short description of the Script.", 80); + const std::string &test4 = Input::getString("Enter the long description of the Script.", 300); + + setString("info", "title", test); + setString("info", "author", test2); + setString("info", "shortDesc", test3); + setString("info", "description", test4); + setInt("info", "version", 2); + setInt("info", "revision", 1); + } +} \ No newline at end of file diff --git a/source/screens/tinyDB.cpp b/source/screens/tinyDB.cpp new file mode 100644 index 0000000..f3c1ff6 --- /dev/null +++ b/source/screens/tinyDB.cpp @@ -0,0 +1,43 @@ +/* +* This file is part of Universal-Updater +* Copyright (C) 2019 VoltZ, Epicpkmn11, Flame, RocketRobz, TotallyNotGuy +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* Additional Terms 7.b and 7.c of GPLv3 apply to this file: +* * Requiring preservation of specified reasonable legal notices or +* author attributions in that material or in the Appropriate Legal +* Notices displayed by works containing it. +* * Prohibiting misrepresentation of the origin of that material, +* or requiring that modified versions of such material be marked in +* reasonable ways as different from the original version. +*/ + +#include "screens/tinyDB.hpp" + +#include "utils/config.hpp" + +// To-Do. +void TinyDB::Draw(void) const { + Gui::DrawTop(); + Gui::DrawStringCentered(0, 2, 0.7f, Config::TxtColor, "TinyDB", 400); + Gui::DrawBottom(); +} + +void TinyDB::Logic(u32 hDown, u32 hHeld, touchPosition touch) { + if (hDown & KEY_B) { + Gui::screenBack(); + return; + } +} \ No newline at end of file