diff --git a/include/screens/unistore_v2.hpp b/include/screens/unistore_v2.hpp index bcb5bef..59e098d 100644 --- a/include/screens/unistore_v2.hpp +++ b/include/screens/unistore_v2.hpp @@ -45,12 +45,13 @@ private: std::unique_ptr sortedStore; bool darkMode = true, sheetLoaded = false, canDisplay = false, hasLoaded = false, isDropDown = false; - int selectedBox = 0, lastViewMode = 0, dropSelection = 0, iconAmount = 0, selectedBoxList = 0, selection = -1, storePage = 0, downloadPage = 0, storePageList = 0, mode = 0, subSelection = 0; + int selectedBox = 0, lastViewMode = 0, dropSelection = 0, searchSelection = 0, iconAmount = 0, selectedBoxList = 0, selection = -1, storePage = 0, downloadPage = 0, storePageList = 0, mode = 0, subSelection = 0; nlohmann::json storeJson; C2D_SpriteSheet sheet; std::vector objects; void DrawSortingMenu(void) const; + void DrawSearchMenu(void) const; // Base stuff. void DrawBaseTop(void) const; @@ -120,6 +121,13 @@ private: {115, 170, 100, 30} // Last Updated. }; + const std::vector searchPos = { + {0, 60, 149, 52}, // Title. + {162, 60, 149, 52}, // Author. + {0, 130, 149, 52}, // Category. + {162, 130, 149, 52} // Console. + }; + u32 barColorLight, barColorDark, bgColorLight, bgColorDark, textColorLight, textColorDark, boxColorLight, boxColorDark, outlineColorLight, outlineColorDark; }; diff --git a/include/utils/store.hpp b/include/utils/store.hpp index 976faf3..53d704f 100644 --- a/include/utils/store.hpp +++ b/include/utils/store.hpp @@ -61,7 +61,13 @@ public: int returnJSONIndex(const int index); int getSize(); bool getAscending() { return this->ascending; } + + // Searching stuff. int searchForEntries(const std::string searchResult); + int searchForAuthor(const std::string searchResult); + int searchForCategory(const std::string searchResult); + int searchForConsole(const std::string searchResult); + void reset() { this->sortedStore = this->unsortedStore; } const int getSortType() { diff --git a/romfs/lang/en/app.json b/romfs/lang/en/app.json index f6511c4..bb9a6e0 100644 --- a/romfs/lang/en/app.json +++ b/romfs/lang/en/app.json @@ -198,5 +198,11 @@ "NO_RESULTS_FOUND": "No results found!", "SEARCH": "Search Entry", "INVALID_INPUT": "Invalid input!", - "RESET": "Reset" + "RESET": "Reset", + "SEARCH_MENU": "Search Menu", + "TITLE_SEARCH": "Title search", + "AUTHOR_SEARCH": "Author search", + "CATEGORY_SEARCH": "Category search", + "CONSOLE_SEARCH": "Console search", + "SEARCHING_FOR": "Searching for..." } diff --git a/source/screens/unistore_v2.cpp b/source/screens/unistore_v2.cpp index 7fa369b..5b78820 100644 --- a/source/screens/unistore_v2.cpp +++ b/source/screens/unistore_v2.cpp @@ -228,8 +228,25 @@ void UniStoreV2::parseObjects(int selection) { } } +void UniStoreV2::DrawSearchMenu(void) const { + this->DrawBaseTop(); + if (Config::UseBars == true) { + Gui::DrawStringCentered(0, 0, 0.7f, this->returnTextColor(), Lang::get("SEARCH_MENU"), 400); + } else { + Gui::DrawStringCentered(0, 2, 0.7f, this->returnTextColor(), Lang::get("SEARCH_MENU"), 400); + } + + this->DrawBaseBottom(); + GFX::DrawButton(searchPos[0].x, searchPos[0].y,Lang::get("TITLE_SEARCH")); + GFX::DrawButton(searchPos[1].x, searchPos[1].y, Lang::get("AUTHOR_SEARCH")); + GFX::DrawButton(searchPos[2].x, searchPos[2].y, Lang::get("CATEGORY_SEARCH")); + GFX::DrawButton(searchPos[3].x, searchPos[3].y, Lang::get("CONSOLE_SEARCH")); + + Animation::Button(searchPos[this->searchSelection].x, searchPos[this->searchSelection].y, .060); +} + void UniStoreV2::DropDownMenu(void) const { - if (this->mode != 2) { + if (this->mode != 2 || this->mode != 3) { // DropDown Menu. if (this->isDropDown) { // Draw Operation Box. @@ -250,7 +267,7 @@ void UniStoreV2::DropDownMenu(void) const { // Dropdown Text. Gui::DrawString(this->dropPos[0].x+30, this->dropPos[0].y+5, 0.4f, this->returnTextColor(), Lang::get("CHANGE_THEME"), 100); Gui::DrawString(this->dropPos[1].x+30, this->dropPos[1].y+5, 0.4f, this->returnTextColor(), Lang::get("CHANGE_STYLE"), 100); - Gui::DrawString(this->dropPos[2].x+30, this->dropPos[2].y+5, 0.4f, this->returnTextColor(), Lang::get("SEARCH"), 100); + Gui::DrawString(this->dropPos[2].x+30, this->dropPos[2].y+5, 0.4f, this->returnTextColor(), Lang::get("SEARCHING_FOR"), 100); Gui::DrawString(this->dropPos[3].x+30, this->dropPos[3].y+5, 0.4f, this->returnTextColor(), Lang::get("RESET"), 100); } } @@ -366,9 +383,11 @@ void UniStoreV2::Draw(void) const { if (fadealpha > 0) Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha)); } else if (this->mode == 2) { this->displaySelectedEntry(this->selection); + } else if (this->mode == 3) { + this->DrawSearchMenu(); } - if (this->mode != 2) GFX::DrawSpriteBlend(sprites_dropdown_idx, iconPos[0].x, iconPos[0].y); + if (this->mode < 2) GFX::DrawSpriteBlend(sprites_dropdown_idx, iconPos[0].x, iconPos[0].y); this->DropDownMenu(); } @@ -383,8 +402,6 @@ void UniStoreV2::DropLogic(u32 hDown, u32 hHeld, touchPosition touch) { } if (hDown & KEY_A) { - std::string temp; - int amount; switch(this->dropSelection) { case 0: if (this->darkMode) this->darkMode = false; @@ -395,20 +412,8 @@ void UniStoreV2::DropLogic(u32 hDown, u32 hHeld, touchPosition touch) { else this->mode = 0; break; case 2: - temp = Input::getStringLong(Lang::get("ENTER_SEARCH")); - if (temp != "") { - if (this->mode == 0) { - this->selectedBox = 0; - this->storePage = 0; - } else if (this->mode == 1) { - this->selectedBoxList = 0; - this->storePageList = 0; - } - amount = this->sortedStore->searchForEntries(temp); - if (amount == 0) Msg::DisplayWarnMsg(Lang::get("NO_RESULTS_FOUND")); - } else { - Msg::DisplayWarnMsg(Lang::get("INVALID_INPUT")); - } + this->lastViewMode = this->mode; + this->mode = 3; break; case 3: if (this->mode == 0) { @@ -439,20 +444,8 @@ void UniStoreV2::DropLogic(u32 hDown, u32 hHeld, touchPosition touch) { else this->mode = 0; this->isDropDown = false; } else if (touching(touch, this->dropPos[2])) { - std::string temp = Input::getStringLong(Lang::get("ENTER_SEARCH")); - if (temp != "") { - if (this->mode == 0) { - this->selectedBox = 0; - this->storePage = 0; - } else if (this->mode == 1) { - this->selectedBoxList = 0; - this->storePageList = 0; - } - int amount = this->sortedStore->searchForEntries(temp); - if (amount == 0) Msg::DisplayWarnMsg(Lang::get("NO_RESULTS_FOUND")); - } else { - Msg::DisplayWarnMsg(Lang::get("INVALID_INPUT")); - } + this->lastViewMode = this->mode; + this->mode = 3; this->isDropDown = false; } else if (touching(touch, this->dropPos[3])) { if (this->mode == 0) { @@ -534,7 +527,6 @@ void UniStoreV2::Logic(u32 hDown, u32 hHeld, touchPosition touch) { } } - if (hDown & KEY_A) { if (this->sortedStore->returnJSONIndex(this->selectedBox + (this->storePage * STORE_ENTRIES)) < (int)this->storeJson.at("storeContent").size()) { this->selection = this->sortedStore->returnJSONIndex(this->selectedBox + (this->storePage * STORE_ENTRIES)); @@ -672,10 +664,158 @@ void UniStoreV2::Logic(u32 hDown, u32 hHeld, touchPosition touch) { this->subSelection = 0; this->mode = this->lastViewMode; } + + } else if (this->mode == 3) { + if (hDown & KEY_B) { + this->mode = this->lastViewMode; + } + + // Search menu. + if (hDown & KEY_TOUCH) { + if (touching(touch, searchPos[0])) { + std::string temp = Input::getStringLong(Lang::get("ENTER_SEARCH")); + if (temp != "") { + this->selectedBox = 0; + this->storePage = 0; + this->selectedBoxList = 0; + this->storePageList = 0; + int amount = this->sortedStore->searchForEntries(temp); + if (amount == 0) Msg::DisplayWarnMsg(Lang::get("NO_RESULTS_FOUND")); + } else { + Msg::DisplayWarnMsg(Lang::get("INVALID_INPUT")); + } + + this->mode = this->lastViewMode; + + } else if (touching(touch, searchPos[1])) { + std::string temp = Input::getStringLong(Lang::get("ENTER_SEARCH")); + if (temp != "") { + this->selectedBox = 0; + this->storePage = 0; + this->selectedBoxList = 0; + this->storePageList = 0; + int amount = this->sortedStore->searchForAuthor(temp); + if (amount == 0) Msg::DisplayWarnMsg(Lang::get("NO_RESULTS_FOUND")); + } else { + Msg::DisplayWarnMsg(Lang::get("INVALID_INPUT")); + } + + this->mode = this->lastViewMode; + + } else if (touching(touch, searchPos[2])) { + std::string temp = Input::getStringLong(Lang::get("ENTER_SEARCH")); + if (temp != "") { + this->selectedBox = 0; + this->storePage = 0; + this->selectedBoxList = 0; + this->storePageList = 0; + int amount = this->sortedStore->searchForCategory(temp); + if (amount == 0) Msg::DisplayWarnMsg(Lang::get("NO_RESULTS_FOUND")); + } else { + Msg::DisplayWarnMsg(Lang::get("INVALID_INPUT")); + } + + this->mode = this->lastViewMode; + + } else if (touching(touch, searchPos[3])) { + std::string temp = Input::getStringLong(Lang::get("ENTER_SEARCH")); + if (temp != "") { + this->selectedBox = 0; + this->storePage = 0; + this->selectedBoxList = 0; + this->storePageList = 0; + int amount = this->sortedStore->searchForConsole(temp); + if (amount == 0) Msg::DisplayWarnMsg(Lang::get("NO_RESULTS_FOUND")); + } else { + Msg::DisplayWarnMsg(Lang::get("INVALID_INPUT")); + } + + this->mode = this->lastViewMode; + } + } + + if (hDown & KEY_RIGHT || hDown & KEY_R) { + if (this->searchSelection == 0) this->searchSelection = 1; + else if (this->searchSelection == 2) this->searchSelection = 3; + } + + if (hDown & KEY_LEFT || hDown & KEY_L) { + if (this->searchSelection == 1) this->searchSelection = 0; + else if (this->searchSelection == 3) this->searchSelection = 2; + } + + if (hDown & KEY_DOWN) { + if (this->searchSelection == 0) this->searchSelection = 2; + else if (this->searchSelection == 1) this->searchSelection = 3; + } + + if (hDown & KEY_UP) { + if (this->searchSelection == 2) this->searchSelection = 0; + else if (this->searchSelection == 3) this->searchSelection = 1; + } + + if (hDown & KEY_A) { + std::string temp; int amount; + switch(this->searchSelection) { + case 0: + temp = Input::getStringLong(Lang::get("ENTER_SEARCH")); + if (temp != "") { + this->selectedBox = 0; + this->storePage = 0; + this->selectedBoxList = 0; + this->storePageList = 0; + amount = this->sortedStore->searchForEntries(temp); + if (amount == 0) Msg::DisplayWarnMsg(Lang::get("NO_RESULTS_FOUND")); + } else { + Msg::DisplayWarnMsg(Lang::get("INVALID_INPUT")); + } + break; + case 1: + temp = Input::getStringLong(Lang::get("ENTER_SEARCH")); + if (temp != "") { + this->selectedBox = 0; + this->storePage = 0; + this->selectedBoxList = 0; + this->storePageList = 0; + amount = this->sortedStore->searchForAuthor(temp); + if (amount == 0) Msg::DisplayWarnMsg(Lang::get("NO_RESULTS_FOUND")); + } else { + Msg::DisplayWarnMsg(Lang::get("INVALID_INPUT")); + } + break; + case 2: + temp = Input::getStringLong(Lang::get("ENTER_SEARCH")); + if (temp != "") { + this->selectedBox = 0; + this->storePage = 0; + this->selectedBoxList = 0; + this->storePageList = 0; + amount = this->sortedStore->searchForCategory(temp); + if (amount == 0) Msg::DisplayWarnMsg(Lang::get("NO_RESULTS_FOUND")); + } else { + Msg::DisplayWarnMsg(Lang::get("INVALID_INPUT")); + } + break; + case 3: + temp = Input::getStringLong(Lang::get("ENTER_SEARCH")); + if (temp != "") { + this->selectedBox = 0; + this->storePage = 0; + this->selectedBoxList = 0; + this->storePageList = 0; + amount = this->sortedStore->searchForConsole(temp); + if (amount == 0) Msg::DisplayWarnMsg(Lang::get("NO_RESULTS_FOUND")); + } else { + Msg::DisplayWarnMsg(Lang::get("INVALID_INPUT")); + } + break; + } + this->mode = this->lastViewMode; + } } if ((hDown & KEY_SELECT) || (hDown & KEY_TOUCH && touching(touch, iconPos[0]))) { - if (this->mode != 2) { + if (this->mode != 2 || this->mode != 3) { this->dropSelection = 0; this->isDropDown = true; } diff --git a/source/utils/store.cpp b/source/utils/store.cpp index a6a6cf0..1c3c688 100644 --- a/source/utils/store.cpp +++ b/source/utils/store.cpp @@ -82,6 +82,54 @@ UniStoreV2Struct Store::getData(const int index) { return temp; } +int Store::searchForCategory(const std::string searchResult) { + std::vector temp; + + for (int i = 0; i < (int)this->sortedStore.size(); i++) { + if (this->sortedStore[i].category.find(searchResult) != std::string::npos) { + temp.push_back({this->sortedStore[i]}); + } + } + + if (temp.size() != 0) { + this->sortedStore = temp; + } + + return (int)temp.size(); +} + +int Store::searchForConsole(const std::string searchResult) { + std::vector temp; + + for (int i = 0; i < (int)this->sortedStore.size(); i++) { + if (this->sortedStore[i].console.find(searchResult) != std::string::npos) { + temp.push_back({this->sortedStore[i]}); + } + } + + if (temp.size() != 0) { + this->sortedStore = temp; + } + + return (int)temp.size(); +} + +int Store::searchForAuthor(const std::string searchResult) { + std::vector temp; + + for (int i = 0; i < (int)this->sortedStore.size(); i++) { + if (this->sortedStore[i].author.find(searchResult) != std::string::npos) { + temp.push_back({this->sortedStore[i]}); + } + } + + if (temp.size() != 0) { + this->sortedStore = temp; + } + + return (int)temp.size(); +} + int Store::searchForEntries(const std::string searchResult) { std::vector temp;