mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-09-01 12:02:40 +02:00
In element search promote exact and starting position matches (finally possible to access VAC via element search)
This commit is contained in:
@@ -98,11 +98,26 @@ void ElementSearchActivity::searchTools(std::string query)
|
|||||||
std::string queryLower = std::string(query);
|
std::string queryLower = std::string(query);
|
||||||
std::transform(queryLower.begin(), queryLower.end(), queryLower.begin(), ::tolower);
|
std::transform(queryLower.begin(), queryLower.end(), queryLower.begin(), ::tolower);
|
||||||
|
|
||||||
for(std::vector<Tool*>::iterator iter = tools.begin(), end = tools.end(); iter != end; ++iter) {
|
std::vector<Tool *> matches;
|
||||||
|
std::vector<Tool *> frontmatches;
|
||||||
|
std::vector<Tool *> exactmatches;
|
||||||
|
|
||||||
|
for(std::vector<Tool*>::const_iterator iter = tools.begin(), end = tools.end(); iter != end; ++iter)
|
||||||
|
{
|
||||||
std::string nameLower = std::string((*iter)->GetName());
|
std::string nameLower = std::string((*iter)->GetName());
|
||||||
std::transform(nameLower.begin(), nameLower.end(), nameLower.begin(), ::tolower);
|
std::transform(nameLower.begin(), nameLower.end(), nameLower.begin(), ::tolower);
|
||||||
|
if(!strcmp(nameLower.c_str(), queryLower.c_str()))
|
||||||
|
exactmatches.push_back(*iter);
|
||||||
|
else if(!strncmp(nameLower.c_str(), queryLower.c_str(), queryLower.length()))
|
||||||
|
frontmatches.push_back(*iter);
|
||||||
|
else if(!strstr(nameLower.c_str(), queryLower.c_str()))
|
||||||
|
matches.push_back(*iter);
|
||||||
|
}
|
||||||
|
|
||||||
if(strstr(nameLower.c_str(), queryLower.c_str())!=0)
|
matches.insert(matches.begin(), frontmatches.begin(), frontmatches.end());
|
||||||
|
matches.insert(matches.begin(), exactmatches.begin(), exactmatches.end());
|
||||||
|
|
||||||
|
for(std::vector<Tool*>::const_iterator iter = matches.begin(), end = matches.end(); iter != end; ++iter)
|
||||||
{
|
{
|
||||||
Tool * tool = *iter;
|
Tool * tool = *iter;
|
||||||
|
|
||||||
@@ -147,7 +162,6 @@ void ElementSearchActivity::searchTools(std::string query)
|
|||||||
if(current.Y + viewPosition.Y + 18 > Size.Y-23)
|
if(current.Y + viewPosition.Y + 18 > Size.Y-23)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ElementSearchActivity::SetActiveTool(int selectionState, Tool * tool)
|
void ElementSearchActivity::SetActiveTool(int selectionState, Tool * tool)
|
||||||
|
Reference in New Issue
Block a user