Add search and A-Z sort to Plandomizer item filter
This commit is contained in:
@@ -34,6 +34,7 @@ static int32_t getTabID = TAB_HINTS;
|
|||||||
static int32_t selectedItemFilterIndex = 0;
|
static int32_t selectedItemFilterIndex = 0;
|
||||||
static std::vector<RandomizerGet> itemFilterList;
|
static std::vector<RandomizerGet> itemFilterList;
|
||||||
static std::vector<std::string> itemFilterNames;
|
static std::vector<std::string> itemFilterNames;
|
||||||
|
static char itemFilterSearch[64] = "";
|
||||||
|
|
||||||
void PlandomizerPopulateItemFilterMap();
|
void PlandomizerPopulateItemFilterMap();
|
||||||
|
|
||||||
@@ -1081,11 +1082,53 @@ void PlandomizerDrawOptions() {
|
|||||||
ImGui::EndCombo();
|
ImGui::EndCombo();
|
||||||
}
|
}
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
|
ImGui::SetNextItemWidth(150);
|
||||||
|
if (ImGui::InputText("##ItemSearch", itemFilterSearch, sizeof(itemFilterSearch), ImGuiInputTextFlags_EnterReturnsTrue)) {
|
||||||
|
if (strlen(itemFilterSearch) > 0) {
|
||||||
|
for (int i = 0; i < (int32_t)itemFilterNames.size(); i++) {
|
||||||
|
std::string lowerSearch = itemFilterSearch;
|
||||||
|
std::transform(lowerSearch.begin(), lowerSearch.end(), lowerSearch.begin(), ::tolower);
|
||||||
|
std::string lowerName = itemFilterNames[i];
|
||||||
|
std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), ::tolower);
|
||||||
|
if (lowerName.find(lowerSearch) != std::string::npos) {
|
||||||
|
selectedItemFilterIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ImGui::IsItemHovered()) {
|
||||||
|
ImGui::SetTooltip("Type to search and press Enter");
|
||||||
|
}
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (UIWidgets::Button("A-Z", UIWidgets::ButtonOptions()
|
||||||
|
.Color(THEME_COLOR)
|
||||||
|
.Size(UIWidgets::Sizes::Inline)
|
||||||
|
.Padding(ImVec2(8.f, 6.f))
|
||||||
|
.Tooltip("Sort items A-Z"))) {
|
||||||
|
std::vector<std::pair<std::string, RandomizerGet>> sorted;
|
||||||
|
for (size_t i = 1; i < itemFilterNames.size(); i++) {
|
||||||
|
sorted.push_back({ itemFilterNames[i], itemFilterList[i] });
|
||||||
|
}
|
||||||
|
std::sort(sorted.begin(), sorted.end(), [](const auto& a, const auto& b) {
|
||||||
|
return a.first < b.first;
|
||||||
|
});
|
||||||
|
itemFilterList.clear();
|
||||||
|
itemFilterNames.clear();
|
||||||
|
itemFilterList.push_back(RG_NONE);
|
||||||
|
itemFilterNames.push_back("All Items");
|
||||||
|
for (const auto& pair : sorted) {
|
||||||
|
itemFilterList.push_back(pair.second);
|
||||||
|
itemFilterNames.push_back(pair.first);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ImGui::SameLine();
|
||||||
if (UIWidgets::Button("Clear Item Filter", UIWidgets::ButtonOptions()
|
if (UIWidgets::Button("Clear Item Filter", UIWidgets::ButtonOptions()
|
||||||
.Color(THEME_COLOR)
|
.Color(THEME_COLOR)
|
||||||
.Size(UIWidgets::Sizes::Inline)
|
.Size(UIWidgets::Sizes::Inline)
|
||||||
.Padding(ImVec2(10.f, 6.f)))) {
|
.Padding(ImVec2(10.f, 6.f)))) {
|
||||||
selectedItemFilterIndex = 0;
|
selectedItemFilterIndex = 0;
|
||||||
|
itemFilterSearch[0] = '\0';
|
||||||
}
|
}
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
if (UIWidgets::Button("Empty All Rewards", UIWidgets::ButtonOptions()
|
if (UIWidgets::Button("Empty All Rewards", UIWidgets::ButtonOptions()
|
||||||
|
|||||||
Reference in New Issue
Block a user