Add Searching in UniStore v2!

This commit is contained in:
StackZ
2020-06-19 12:56:12 +02:00
parent 62e16be262
commit e03cf47b67
4 changed files with 56 additions and 3 deletions
+2
View File
@@ -61,6 +61,8 @@ public:
int returnJSONIndex(const int index);
int getSize();
bool getAscending() { return this->ascending; }
int searchForEntries(const std::string searchResult);
void reset() { this->sortedStore = this->unsortedStore; }
const int getSortType() {
if (this->sorttype == SortType::TITLE) return 0;
+3 -1
View File
@@ -193,5 +193,7 @@
"ASCENDING": "Ascending",
"TITLE_BTN": "Title",
"AUTHOR_BTN": "Author",
"LAST_UPDATED_BTN": "Last updated"
"LAST_UPDATED_BTN": "Last updated",
"ENTER_SEARCH": "Enter what you like to search.",
"NO_RESULTS_FOUND": "No results found!"
}
+35 -2
View File
@@ -26,6 +26,7 @@
#include "download.hpp"
#include "json.hpp"
#include "keyboard.hpp"
#include "scriptHelper.hpp"
#include "unistore_v2.hpp"
@@ -334,7 +335,7 @@ void UniStoreV2::Draw(void) const {
this->DrawGrid();
Gui::DrawStringCentered(0, 218, 0.6f, this->returnTextColor(), std::to_string(this->storePage + 1) + " | " + std::to_string(1 + (this->storeJson.at("storeContent").size() / STORE_ENTRIES)));
Gui::DrawStringCentered(0, 218, 0.6f, this->returnTextColor(), std::to_string(this->storePage + 1) + " | " + std::to_string(1 + (this->sortedStore->getSize() / STORE_ENTRIES)));
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha));
this->DrawBaseBottom();
@@ -351,7 +352,7 @@ void UniStoreV2::Draw(void) const {
}
this->DrawList();
Gui::DrawStringCentered(0, 218, 0.6f, this->returnTextColor(), std::to_string(this->storePageList + 1) + " | " + std::to_string(1 + (this->storeJson.at("storeContent").size() / STORE_ENTRIES_LIST)));
Gui::DrawStringCentered(0, 218, 0.6f, this->returnTextColor(), std::to_string(this->storePageList + 1) + " | " + std::to_string(1 + (this->sortedStore->getSize() / STORE_ENTRIES_LIST)));
if (fadealpha > 0) Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(fadecolor, fadecolor, fadecolor, fadealpha));
this->DrawBaseBottom();
@@ -461,6 +462,22 @@ void UniStoreV2::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
}
}
if (hDown & KEY_X) {
std::string temp = Input::getStringLong(Lang::get("ENTER_SEARCH"));
if (temp != "") {
this->selectedBox = 0;
this->storePage = 0;
int amount = this->sortedStore->searchForEntries(temp);
if (amount == 0) Msg::DisplayWarnMsg(Lang::get("NO_RESULTS_FOUND"));
}
}
if (hDown & KEY_Y) {
this->selectedBox = 0;
this->storePage = 0;
this->sortedStore->reset();
}
if (hDown & KEY_L) {
if (this->storePage > 0) {
this->selectedBox = 0;
@@ -548,6 +565,22 @@ void UniStoreV2::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
}
}
if (hDown & KEY_X) {
std::string temp = Input::getStringLong(Lang::get("ENTER_SEARCH"));
if (temp != "") {
this->selectedBoxList = 0;
this->storePageList = 0;
int amount = this->sortedStore->searchForEntries(temp);
if (amount == 0) Msg::DisplayWarnMsg(Lang::get("NO_RESULTS_FOUND"));
}
}
if (hDown & KEY_Y) {
this->selectedBoxList = 0;
this->storePageList = 0;
this->sortedStore->reset();
}
} else if (this->mode == 2) {
if (hDown & KEY_TOUCH) {
if (this->objects.size() > 0) {
+16
View File
@@ -82,6 +82,22 @@ UniStoreV2Struct Store::getData(const int index) {
return temp;
}
int Store::searchForEntries(const std::string searchResult) {
std::vector<UniStoreV2Struct> temp;
for (int i = 0; i < (int)this->sortedStore.size(); i++) {
if (this->sortedStore[i].title.find(searchResult) != std::string::npos) {
temp.push_back({this->sortedStore[i]});
}
}
if (temp.size() != 0) {
this->sortedStore = temp;
}
return (int)temp.size();
}
// Title.
bool compareTitleDescending(const UniStoreV2Struct& a, const UniStoreV2Struct& b) {
int result = a.title.compare(b.title);