diff --git a/include/keyboard.hpp b/include/keyboard.hpp index ee77a08..1d8a537 100644 --- a/include/keyboard.hpp +++ b/include/keyboard.hpp @@ -5,12 +5,13 @@ namespace Input { void DrawNumpad(); + void drawKeyboard(); std::string Numpad(std::string Text); 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); + std::string getString(std::string Text); + std::string getString(uint maxLength, std::string Text); } #endif \ No newline at end of file diff --git a/include/screens/scriptCreator.hpp b/include/screens/scriptCreator.hpp index 3d17d87..e7ed9cc 100644 --- a/include/screens/scriptCreator.hpp +++ b/include/screens/scriptCreator.hpp @@ -44,12 +44,21 @@ public: private: int Selection = 0; void openJson(std::string fileName); - void save(std::string fileName); + void createNewJson(std::string fileName); + void save(); void setInfoStuff(void); + void createDownloadRelease(); void setBool(const std::string &object, const std::string &key, bool v); + void setBool2(const std::string &object, const std::string &key, const std::string &key2, bool v); + void setInt(const std::string &object, const std::string &key, int v); + void setInt2(const std::string &object, const std::string &key, const std::string &key2, int v); + void setString(const std::string &object, const std::string &key, const std::string &v); + void setString2(const std::string &object, const std::string &key, const std::string &key2, const std::string &v); + + void createEntry(const std::string &Entryname); std::vector mainButtons = { {90, 40, 140, 35, -1}, // New Script. diff --git a/include/utils/config.hpp b/include/utils/config.hpp index 7177f3e..3373c07 100644 --- a/include/utils/config.hpp +++ b/include/utils/config.hpp @@ -32,7 +32,7 @@ namespace Config { // [UI] extern int lang; // The current Language. - extern int Color1, Color2, Color3, TxtColor, SelectedColor, UnselectedColor, viewMode; + extern int Color1, Color2, Color3, TxtColor, SelectedColor, UnselectedColor, viewMode, ColorKeys; extern std::string ScriptPath; void load(); diff --git a/include/utils/structs.hpp b/include/utils/structs.hpp index 64cc5cb..72f2d81 100644 --- a/include/utils/structs.hpp +++ b/include/utils/structs.hpp @@ -44,6 +44,7 @@ public: std::string character; int x; int y; + int w; }; private: }; diff --git a/source/keyboard.cpp b/source/keyboard.cpp index 2770852..6e47583 100644 --- a/source/keyboard.cpp +++ b/source/keyboard.cpp @@ -14,6 +14,27 @@ extern C3D_RenderTarget* bottom; bool caps = false, enter = false; int shift = 0; +Structs::Key keysQWERTY[] = { + {"1", 0, 0}, {"2", 25, 0}, {"3", 50, 0}, {"4", 75, 0}, {"5", 100, 0}, {"6", 125, 0}, {"7", 150, 0}, {"8", 175, 0}, {"9", 200, 0}, {"0", 225, 0}, {"-", 250, 0}, {"=", 275, 0}, + {"q", 12, 22}, {"w", 37, 22}, {"e", 62, 22}, {"r", 87, 22}, {"t", 112, 22}, {"y", 137, 22}, {"u", 162, 22}, {"i", 187, 22}, {"o", 212, 22}, {"p", 237, 22}, {"[", 262, 22}, {"]", 287, 22}, + {"a", 25, 45}, {"s", 50, 45}, {"d", 75, 45}, {"f", 100, 45}, {"g", 125, 45}, {"h", 150, 45}, {"j", 175, 45}, {"k", 200, 45}, {"l", 225, 45}, {";", 250, 45}, {"'", 275, 45}, + {"z", 35, 67}, {"x", 60, 67}, {"c", 85, 67}, {"v", 110, 67}, {"b", 135, 67}, {"n", 160, 67}, {"m", 185, 67}, {",", 210, 67}, {".", 235, 67}, {"/", 260, 67}, {"\\", 210, 90}, +}; +Structs::Key keysQWERTYShift[] = { + {"!", 0, 0}, {"@", 25, 0}, {"#", 50, 0}, {"$", 75, 0}, {"%", 100, 0}, {"^", 125, 0}, {"&", 150, 0}, {"*", 175, 0}, {"(", 200, 0}, {")", 225, 0}, {"_", 250, 0}, {"+", 275, 0}, + {"Q", 12, 22}, {"W", 37, 22}, {"E", 62, 22}, {"R", 87, 22}, {"T", 112, 22}, {"Y", 137, 22}, {"U", 162, 22}, {"I", 187, 22}, {"O", 212, 22}, {"P", 237, 22}, {"{", 262, 22}, {"}", 287, 22}, + {"A", 25, 45}, {"S", 50, 45}, {"D", 75, 45}, {"F", 100, 45}, {"G", 125, 45}, {"H", 150, 45}, {"J", 175, 45}, {"K", 200, 45}, {"L", 225, 45}, {":", 250, 45}, {"\"", 275, 45}, + {"Z", 35, 67}, {"X", 60, 67}, {"C", 85, 67}, {"V", 110, 67}, {"B", 135, 67}, {"N", 160, 67}, {"M", 185, 67}, {"<,", 210, 67}, {">", 235, 67}, {"?", 260, 67}, {"\\", 210, 90}, +}; +Structs::Key modifierKeys[] = { + {"bksp", 300, 0, 20}, // Backspace + {"caps", 0, 45, 20}, // Caps Lock + {"entr", 300, 45, 20}, // Enter + {"lsft", 0, 67, 30}, // Left Shift + {"rsft", 285, 67, 35}, // Right Shift + {" ", 60, 90, 20}, // Tab + {" ", 85, 90, 120}, // Space +}; Structs::Key NumpadStruct[] = { {"1", 10, 30}, @@ -35,7 +56,6 @@ Structs::Key NumpadStruct[] = { {"Backspace", 250, 30}, }; - Structs::ButtonPos Numbers [] = { {10, 30, 60, 50}, // 1 {90, 30, 60, 50}, // 2 @@ -68,6 +88,22 @@ void Input::DrawNumpad() } } +void Input::drawKeyboard() { + for(uint i=0;i<(sizeof(keysQWERTY)/sizeof(keysQWERTY[0]));i++) { + C2D_DrawRectSolid(keysQWERTY[i].x, keysQWERTY[i].y+103, 0.5f, 20, 20, Config::ColorKeys & C2D_Color32(255, 255, 255, 200)); + if(shift) { + char c[2] = {caps ? (char)toupper(keysQWERTYShift[i].character[0]) : keysQWERTYShift[i].character[0]}; + Gui::DrawString(keysQWERTYShift[i].x+(10-(Gui::GetStringWidth(0.50, c)/2)), keysQWERTYShift[i].y+103+(10-(Gui::GetStringHeight(0.50, c)/2)), 0.50, Config::TxtColor, c); + } else { + char c[2] = {caps ? (char)toupper(keysQWERTY[i].character[0]) : keysQWERTY[i].character[0]}; + Gui::DrawString(keysQWERTY[i].x+(10-(Gui::GetStringWidth(0.50, c)/2)), keysQWERTY[i].y+103+(10-(Gui::GetStringHeight(0.50, c)/2)), 0.50, Config::TxtColor, c); + } + } + for(uint i=0;i<(sizeof(modifierKeys)/sizeof(modifierKeys[0]));i++) { + C2D_DrawRectSolid(modifierKeys[i].x, modifierKeys[i].y+103, 0.5f, modifierKeys[i].w, 20, Config::ColorKeys & C2D_Color32(255, 255, 255, 200)); + } +} + std::string Input::Numpad(std::string Text) { return Input::Numpad(-1, Text); } std::string Input::Numpad(uint maxLength, std::string Text) @@ -151,23 +187,93 @@ int Input::getUint(int max, std::string Text) { return i; } -std::string Input::getString(const std::string &hint, uint maxLength) -{ +std::string Input::getString(std::string Text) { return Input::getString(-1, Text); } + +std::string Input::getString(uint maxLength, std::string Text) { + int hDown; + touchPosition touch; 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 ""; + int keyDownDelay = 10, cursorBlink = 20; + caps = false, shift = 0, enter = false; + while(1) { + do { + C3D_FrameEnd(0); + Gui::clearTextBufs(); + C3D_FrameBegin(C3D_FRAME_SYNCDRAW); + Gui::DrawTop(); + Gui::DrawString((400-Gui::GetStringWidth(0.55f, Text))/2, 2, 0.55f, WHITE, Text, 400); + Gui::DrawBottom(); + drawKeyboard(); + C2D_DrawRectSolid(0, 81, 0.5f, 320, 20, Config::ColorKeys & C2D_Color32(200, 200, 200, 200)); + Gui::DrawString(5, 82, 0.6, Config::TxtColor, (string+(cursorBlink-- > 0 ? "_" : "")).c_str()); + if(cursorBlink < -20) cursorBlink = 20; + scanKeys(); + hDown = keysDown(); + if(keyDownDelay > 0) { + keyDownDelay--; + } else if(keyDownDelay == 0) { + keyDownDelay--; + } + } while(!hDown); + if(keyDownDelay > 0) { + } + keyDownDelay = 10; + + if(hDown & KEY_TOUCH) { + touchRead(&touch); + if(string.length() < maxLength) { + // Check if a regular key was pressed + for(uint i=0;i<(sizeof(keysQWERTY)/sizeof(keysQWERTY[0]));i++) { + if((touch.px > keysQWERTY[i].x-2 && touch.px < keysQWERTY[i].x+18) && (touch.py > keysQWERTY[i].y+(103)-2 && touch.py < keysQWERTY[i].y+18+(103))) { + char c = (shift ? keysQWERTYShift[i] : keysQWERTY[i]).character[0]; + string += (shift || caps ? toupper(c) : c); + shift = 0; + break; + } + } + } + // Check if a modifier key was pressed + for(uint i=0;i<(sizeof(modifierKeys)/sizeof(modifierKeys[0]));i++) { + if((touch.px > modifierKeys[i].x-2 && touch.px < modifierKeys[i].x+modifierKeys[i].w+2) && (touch.py > modifierKeys[i].y+(103)-2 && touch.py < modifierKeys[i].y+18+(103))) { + if(modifierKeys[i].character == "bksp") { + string = string.substr(0, string.length()-1); + } else if(modifierKeys[i].character == "caps") { + caps = !caps; + } else if(modifierKeys[i].character == "entr") { + enter = true; + } else if(modifierKeys[i].character == "lsft") { + if(shift) shift = 0; + else shift = 1; + if(shift) { + keyDownDelay = -1; + } else { + keyDownDelay = 0; + } + } else if(modifierKeys[i].character == "rsft") { + if(shift) shift = 0; + else shift = 2; + if(shift) { + keyDownDelay = -1; + } else { + keyDownDelay = 0; + } + } else if(modifierKeys[i].character == " " || modifierKeys[i].character == " ") { + if(string.length() < maxLength) { + shift = 0; + string += modifierKeys[i].character[0]; + } + } + break; + } + } + } else if(hDown & KEY_B) { + string = string.substr(0, string.length()-1); + Gui::DrawString(0, 103, 0.5, BLACK, string.c_str(), 320); + } + + if(hDown & KEY_START || enter) { + break; + } } + return string; } \ No newline at end of file diff --git a/source/screens/scriptCreator.cpp b/source/screens/scriptCreator.cpp index 182c193..1818876 100644 --- a/source/screens/scriptCreator.cpp +++ b/source/screens/scriptCreator.cpp @@ -30,6 +30,8 @@ #include "utils/config.hpp" +#include + // The to editing script. nlohmann::json editScript; @@ -40,17 +42,30 @@ void ScriptCreator::openJson(std::string fileName) { fclose(file); } +// BOOL. void ScriptCreator::setBool(const std::string &object, const std::string &key, bool v) { editScript[object][key] = v; } +void ScriptCreator::setBool2(const std::string &object, const std::string &key, const std::string &key2, bool v) { + editScript[object][key][key2] = v; +} + +// INT. void ScriptCreator::setInt(const std::string &object, const std::string &key, int v) { editScript[object][key] = v; } +void ScriptCreator::setInt2(const std::string &object, const std::string &key, const std::string &key2, int v) { + editScript[object][key][key2] = v; +} +// STRING void ScriptCreator::setString(const std::string &object, const std::string &key, const std::string &v) { editScript[object][key] = v; } +void ScriptCreator::setString2(const std::string &object, const std::string &key, const std::string &key2, const std::string &v) { + editScript[object][key][key2] = v; +} void ScriptCreator::Draw(void) const { Gui::DrawTop(); @@ -69,14 +84,80 @@ void ScriptCreator::Draw(void) const { Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("EXISTING_SCRIPT")))/2, mainButtons[1].y+10, 0.6f, Config::TxtColor, Lang::get("EXISTING_SCRIPT"), 140); } -// Testing purpose for now. -ScriptCreator::ScriptCreator() { - openJson("Test.json"); +std::string jsonFileName; + +void ScriptCreator::createNewJson(std::string fileName) { + std::ofstream ofstream; + ofstream.open(fileName.c_str(), std::ofstream::out | std::ofstream::app); + ofstream.close(); } -void ScriptCreator::save(std::string fileName) { - std::string scriptFile = Config::ScriptPath + fileName; - FILE* file = fopen(scriptFile.c_str(), "w"); +// Test. +void ScriptCreator::createDownloadRelease() { + // Repo. + std::string repo = Input::getString(50, "Enter the name of the Owner."); + repo += "/"; + repo += Input::getString(50, "Enter the name of the repo."); + // File. + std::string file = Input::getString(50, "Enter the name of the file."); + // Output. + std::string output = Input::getString(50, "Enter the name of the Output path."); + // Prerelease. + bool prerelease = true; + // Message. + std::string message = Input::getString(50, "Enter the Message."); + + editScript["Test"] = { {{"type", "downloadRelease"}, {"repo", repo}, {"file", file}, {"output", output}, {"includePrerelease", prerelease}, {"message", message}} }; +} + +// To-Do. +/* +void ScriptCreator::createDownloadFile(const std::string &Entryname, const std::string &file, const std::string output, const std::string &message) { + editScript[Entryname] = { {{"type", "downloadFile"}, {"file", file}, {"output", output}, {"message", message}} }; +} + +void ScriptCreator::createDeleteFile(const std::string &Entryname, const std::string &file, const std::string &message) { + editScript[Entryname] = { {{"type", "deleteFile"}, {"file", file}, {"message", message}} }; +} + +void ScriptCreator::createExtractFile(const std::string &Entryname, const std::string &file, const std::string &input, const std::string &output, const std::string &message) { + editScript[Entryname] = { {{"type", "extractFile"}, {"file", file}, {"input", input}, {"output", output}, {"message", message}} }; +} + +void ScriptCreator::createInstallCia(const std::string &Entryname, const std::string &file, const std::string &message) { + editScript[Entryname] = { {{"type", "installCia"}, {"file", file}, {"message", message}} }; +} + +void ScriptCreator::createMkDir(const std::string &Entryname, const std::string &directory) { + editScript[Entryname] = { {{"type", "mkdir"}, {"directory", directory}} }; +} + +void ScriptCreator::createRmDir(const std::string &Entryname, const std::string &directory) { + editScript[Entryname] = { {{"type", "rmdir"}, {"directory", directory}} }; +} + +void ScriptCreator::createMkFile(const std::string &Entryname, const std::string &file) { + editScript[Entryname] = { {{"type", "mkfile"}, {"file", file}} }; +} + +void ScriptCreator::createTimeMsg(const std::string &Entryname, const std::string &message, int seconds) { + editScript[Entryname] = { {{"type", "rmdir"}, {"message", message}, {"seconds", seconds}} }; +} +*/ + +// Testing purpose for now. +ScriptCreator::ScriptCreator() { + jsonFileName = Config::ScriptPath; + jsonFileName += Input::getString(20, "Enter the name of the JSON file."); + if (jsonFileName != "") { + jsonFileName += ".json"; + createNewJson(jsonFileName); + openJson(jsonFileName); + } +} + +void ScriptCreator::save() { + FILE* file = fopen(jsonFileName.c_str(), "w"); if(file) fwrite(editScript.dump(1, '\t').c_str(), 1, editScript.dump(1, '\t').size(), file); fclose(file); } @@ -84,10 +165,10 @@ void ScriptCreator::save(std::string fileName) { // Importaant to make Scripts valid. void ScriptCreator::setInfoStuff(void) { // Get needed things. - 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); + const std::string &test = Input::getString(50, "Enter the Title of the script."); + const std::string &test2 = Input::getString(50, "Enter the Author name of the script."); + const std::string &test3 = Input::getString(80, "Enter the short description of the script."); + const std::string &test4 = Input::getString(300, "Enter the long description of the script."); int scriptRevision = Input::getUint(99, "Enter the script revision."); // Set the real JSON stuff. setString("info", "title", test); @@ -102,7 +183,7 @@ void ScriptCreator::setInfoStuff(void) { void ScriptCreator::Logic(u32 hDown, u32 hHeld, touchPosition touch) { if (hDown & KEY_B) { - save("Test.json"); + save(); Gui::screenBack(); return; } @@ -115,7 +196,11 @@ void ScriptCreator::Logic(u32 hDown, u32 hHeld, touchPosition touch) { if(Selection == 0) Selection = 1; } - if (hDown & KEY_X) { + if (hDown & KEY_Y) { setInfoStuff(); } + + if (hDown & KEY_X) { + createDownloadRelease(); + } } \ No newline at end of file diff --git a/source/utils/config.cpp b/source/utils/config.cpp index bde1dab..609056c 100644 --- a/source/utils/config.cpp +++ b/source/utils/config.cpp @@ -41,6 +41,7 @@ int Config::TxtColor; int Config::SelectedColor; int Config::UnselectedColor; int Config::viewMode; +int Config::ColorKeys; std::string Config::ScriptPath; nlohmann::json configJson; @@ -57,6 +58,7 @@ void Config::load() { Config::ScriptPath = getString("SCRIPTPATH"); Config::lang = getInt("LANGUAGE"); Config::viewMode = getInt("VIEWMODE"); + Config::ColorKeys = getInt("COLORKEYS"); fclose(file); } else { Config::Color1 = BarColor; @@ -68,6 +70,7 @@ void Config::load() { Config::ScriptPath = SCRIPTS_PATH; Config::lang = 2; Config::viewMode = 0; + Config::ColorKeys = C2D_Color32(0, 0, 200, 255); } } @@ -81,6 +84,7 @@ void Config::save() { Config::setString("SCRIPTPATH", Config::ScriptPath); Config::setInt("LANGUAGE", Config::lang); Config::setInt("VIEWMODE", Config::viewMode); + Config::setInt("COLORKEYS", Config::ColorKeys); FILE* file = fopen("sdmc:/3ds/Universal-Updater/Settings.json", "w"); if(file) fwrite(configJson.dump(1, '\t').c_str(), 1, configJson.dump(1, '\t').size(), file); fclose(file); @@ -98,6 +102,7 @@ void Config::initializeNewConfig() { Config::setString("SCRIPTPATH", SCRIPTS_PATH); Config::setInt("LANGUAGE", 2); Config::setInt("VIEWMODE", 0); + Config::setInt("COLORKEYS", C2D_Color32(0, 0, 200, 255)); if(file) fwrite(configJson.dump(1, '\t').c_str(), 1, configJson.dump(1, '\t').size(), file); fclose(file); }