diff --git a/include/screens/unistore_v2.hpp b/include/screens/unistore_v2.hpp index 59e098d..36c4fd4 100644 --- a/include/screens/unistore_v2.hpp +++ b/include/screens/unistore_v2.hpp @@ -45,13 +45,14 @@ private: std::unique_ptr sortedStore; bool darkMode = true, sheetLoaded = false, canDisplay = false, hasLoaded = false, isDropDown = false; - 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; + int selectedBox = 0, lastViewMode = 0, dropSelection = 0, searchSelection = 0, iconAmount = 0, categorySelection = 0, selectedBoxList = 0, selection = -1, storePage = 0, downloadPage = 0, storePageList = 0, mode = 0, subSelection = 0, categoryPage = 0; nlohmann::json storeJson; C2D_SpriteSheet sheet; std::vector objects; void DrawSortingMenu(void) const; void DrawSearchMenu(void) const; + void DrawCategoryMenu(void) const; // Base stuff. void DrawBaseTop(void) const; diff --git a/include/utils/store.hpp b/include/utils/store.hpp index 53d704f..5f3b02f 100644 --- a/include/utils/store.hpp +++ b/include/utils/store.hpp @@ -77,8 +77,11 @@ public: else return -1; // Should not happen. } + const std::vector getCategories() { return this->availableCategories; } + private: std::vector sortedStore, unsortedStore; + std::vector availableCategories; bool ascending = false; nlohmann::json storeJson; SortType sorttype = SortType::TITLE; diff --git a/romfs/lang/en/app.json b/romfs/lang/en/app.json index bb9a6e0..d3c7ade 100644 --- a/romfs/lang/en/app.json +++ b/romfs/lang/en/app.json @@ -204,5 +204,7 @@ "AUTHOR_SEARCH": "Author search", "CATEGORY_SEARCH": "Category search", "CONSOLE_SEARCH": "Console search", - "SEARCHING_FOR": "Searching for..." + "SEARCHING_FOR": "Searching for...", + "SELECT_CATEGORY": "Select a category you like to view.", + "NO_CATEGORIES_AVAILABLE": "No categories available." } diff --git a/source/screens/unistore_v2.cpp b/source/screens/unistore_v2.cpp index c3aa5cf..a229249 100644 --- a/source/screens/unistore_v2.cpp +++ b/source/screens/unistore_v2.cpp @@ -386,12 +386,41 @@ void UniStoreV2::Draw(void) const { this->displaySelectedEntry(this->selection); } else if (this->mode == 3) { this->DrawSearchMenu(); + } else if (this->mode == 4) { + this->DrawCategoryMenu(); } if (this->mode < 2) GFX::DrawSpriteBlend(sprites_dropdown_idx, iconPos[0].x, iconPos[0].y); this->DropDownMenu(); } +void UniStoreV2::DrawCategoryMenu(void) const { + this->DrawBaseTop(); + + if (config->useBars() == true) { + Gui::DrawStringCentered(0, 0, 0.6f, this->returnTextColor(), Lang::get("SELECT_CATEGORY"), 400); + } else { + Gui::DrawStringCentered(0, 2, 0.6f, this->returnTextColor(), Lang::get("SELECT_CATEGORY"), 400); + } + + this->DrawBaseBottom(); + + if (this->sortedStore->getCategories().size() > 0) { + for (int i = 0, i2 = (this->categoryPage * DOWNLOAD_ENTRIES); i2 < DOWNLOAD_ENTRIES + (this->categoryPage * DOWNLOAD_ENTRIES) && i2 < (int)this->sortedStore->getCategories().size(); i2++, i++) { + if (i + (this->categoryPage * DOWNLOAD_ENTRIES) == this->categorySelection) { + this->drawBox(downloadBoxes[i].x, downloadBoxes[i].y, downloadBoxes[i].w, downloadBoxes[i].h, true); + } else { + this->drawBox(downloadBoxes[i].x, downloadBoxes[i].y, downloadBoxes[i].w, downloadBoxes[i].h, false); + } + + Gui::DrawStringCentered(0, downloadBoxes[i].y+4, 0.5f, this->returnTextColor(), this->sortedStore->getCategories()[i + (this->downloadPage * DOWNLOAD_ENTRIES)], 280); + } + } else { + Gui::DrawStringCentered(0, downloadBoxes[0].y+4, 0.5f, this->returnTextColor(), Lang::get("NO_CATEGORIES_AVAILABLE"), 280); + } +} + + void UniStoreV2::DropLogic(u32 hDown, u32 hHeld, touchPosition touch) { if (this->mode != 2) { if (hDown & KEY_DOWN) { @@ -706,20 +735,17 @@ void UniStoreV2::Logic(u32 hDown, u32 hHeld, touchPosition touch) { this->mode = this->lastViewMode; } else if (touching(touch, searchPos[2])) { - std::string temp = Input::getStringLong(Lang::get("ENTER_SEARCH")); - if (temp != "") { + if (this->lastViewMode == 0) { this->selectedBox = 0; this->storePage = 0; + this->sortedStore->reset(); + } else if (this->lastViewMode == 1) { 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->sortedStore->reset(); } - this->mode = this->lastViewMode; - + this->mode = 4; } else if (touching(touch, searchPos[3])) { std::string temp = Input::getStringLong(Lang::get("ENTER_SEARCH")); if (temp != "") { @@ -772,6 +798,7 @@ void UniStoreV2::Logic(u32 hDown, u32 hHeld, touchPosition touch) { } else { Msg::DisplayWarnMsg(Lang::get("INVALID_INPUT")); } + this->mode = this->lastViewMode; break; case 1: temp = Input::getStringLong(Lang::get("ENTER_SEARCH")); @@ -785,19 +812,19 @@ void UniStoreV2::Logic(u32 hDown, u32 hHeld, touchPosition touch) { } else { Msg::DisplayWarnMsg(Lang::get("INVALID_INPUT")); } + this->mode = this->lastViewMode; break; case 2: - temp = Input::getStringLong(Lang::get("ENTER_SEARCH")); - if (temp != "") { + if (this->lastViewMode == 0) { this->selectedBox = 0; this->storePage = 0; + this->sortedStore->reset(); + } else if (this->lastViewMode == 1) { 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")); + this->sortedStore->reset(); } + this->mode = 4; break; case 3: temp = Input::getStringLong(Lang::get("ENTER_SEARCH")); @@ -811,14 +838,72 @@ void UniStoreV2::Logic(u32 hDown, u32 hHeld, touchPosition touch) { } else { Msg::DisplayWarnMsg(Lang::get("INVALID_INPUT")); } + this->mode = this->lastViewMode; break; } - this->mode = this->lastViewMode; } + } else if (this->mode == 4) { + if (hDown & KEY_TOUCH) { + if (this->sortedStore->getCategories().size() > 0) { + for (int i = 0, i2 = 0 + (this->categoryPage * DOWNLOAD_ENTRIES); i2 < DOWNLOAD_ENTRIES + (this->categoryPage * DOWNLOAD_ENTRIES) && i2 < (int)this->sortedStore->getCategories().size(); i2++, i++) { + if (touching(touch, downloadBoxes[i])) { + this->sortedStore->searchForCategory(this->objects[i + (this->categoryPage * DOWNLOAD_ENTRIES)]); + this->mode = this->lastViewMode; + } + } + } + } + + if (hDown & KEY_A) { + if ((int)this->sortedStore->getCategories().size() > 0) { + if ((int)this->sortedStore->getCategories().size() >= this->categorySelection) { + this->sortedStore->searchForCategory(this->sortedStore->getCategories()[this->categorySelection]); + this->mode = this->lastViewMode; + } + } + } + + if (hDown & KEY_DOWN) { + if (this->categorySelection < (int)this->sortedStore->getCategories().size()-1) { + if (this->categorySelection < DOWNLOAD_ENTRIES + (this->categoryPage * DOWNLOAD_ENTRIES)-1) { + this->categorySelection++; + } + } + } + + if (hDown & KEY_UP) { + if (this->categorySelection > 0) { + if (this->categorySelection > this->categoryPage * DOWNLOAD_ENTRIES) { + this->categorySelection--; + } + } + } + + + if (hDown & KEY_R || hDown & KEY_RIGHT) { + if (DOWNLOAD_ENTRIES + (this->categoryPage * DOWNLOAD_ENTRIES) < (int)this->sortedStore->getCategories().size()-1) { + this->categoryPage++; + this->categorySelection = this->categoryPage * DOWNLOAD_ENTRIES; + } + } + + if (hDown & KEY_L || hDown & KEY_LEFT) { + if (this->categoryPage > 0) { + this->categoryPage--; + this->categorySelection = this->categoryPage * DOWNLOAD_ENTRIES; + } + } + + if (hDown & KEY_B) { + this->categoryPage = 0; // Reset page to 0. + this->categorySelection = 0; + this->mode = 3; + } + } if ((hDown & KEY_SELECT) || (hDown & KEY_TOUCH && touching(touch, iconPos[0]))) { - if (this->mode != 2 || this->mode != 3) { + if (this->mode < 2) { this->dropSelection = 0; this->isDropDown = true; } diff --git a/source/utils/store.cpp b/source/utils/store.cpp index 1c3c688..4be3ee3 100644 --- a/source/utils/store.cpp +++ b/source/utils/store.cpp @@ -33,6 +33,9 @@ Store::Store(nlohmann::json &JS) { } this->sortedStore = this->unsortedStore; // Put that to sorted store as well. + if (this->storeJson.at("storeInfo").contains("categories")) { + this->availableCategories = this->storeJson["storeInfo"]["categories"].get>(); + } } // Here we get the data of the UniStore!