From 9db1358ca37ec339a6c6c4e844dcd73509d9db72 Mon Sep 17 00:00:00 2001 From: mniip Date: Sun, 15 Dec 2013 22:54:43 +0400 Subject: [PATCH] In element search promote exact and starting position matches (finally possible to access VAC via element search) --- .../elementsearch/ElementSearchActivity.cpp | 102 ++++++++++-------- 1 file changed, 58 insertions(+), 44 deletions(-) diff --git a/src/gui/elementsearch/ElementSearchActivity.cpp b/src/gui/elementsearch/ElementSearchActivity.cpp index 2a277dbed..accaa6aff 100644 --- a/src/gui/elementsearch/ElementSearchActivity.cpp +++ b/src/gui/elementsearch/ElementSearchActivity.cpp @@ -98,55 +98,69 @@ void ElementSearchActivity::searchTools(std::string query) std::string queryLower = std::string(query); std::transform(queryLower.begin(), queryLower.end(), queryLower.begin(), ::tolower); - for(std::vector::iterator iter = tools.begin(), end = tools.end(); iter != end; ++iter) { + std::vector matches; + std::vector frontmatches; + std::vector exactmatches; + + for(std::vector::const_iterator iter = tools.begin(), end = tools.end(); iter != end; ++iter) + { std::string nameLower = std::string((*iter)->GetName()); 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::const_iterator iter = matches.begin(), end = matches.end(); iter != end; ++iter) + { + Tool * tool = *iter; + + if(!firstResult) + firstResult = tool; + + VideoBuffer * tempTexture = tool->GetTexture(26, 14); + ToolButton * tempButton; + + if(tempTexture) + tempButton = new ToolButton(current+viewPosition, ui::Point(30, 18), "", tool->GetDescription()); + else + tempButton = new ToolButton(current+viewPosition, ui::Point(30, 18), tool->GetName(), tool->GetDescription()); + + tempButton->Appearance.SetTexture(tempTexture); + tempButton->Appearance.BackgroundInactive = ui::Colour(tool->colRed, tool->colGreen, tool->colBlue); + tempButton->SetActionCallback(new ToolAction(this, tool)); + + if(gameController->GetActiveTool(0) == tool) { - Tool * tool = *iter; - - if(!firstResult) - firstResult = tool; - - VideoBuffer * tempTexture = tool->GetTexture(26, 14); - ToolButton * tempButton; - - if(tempTexture) - tempButton = new ToolButton(current+viewPosition, ui::Point(30, 18), "", tool->GetDescription()); - else - tempButton = new ToolButton(current+viewPosition, ui::Point(30, 18), tool->GetName(), tool->GetDescription()); - - tempButton->Appearance.SetTexture(tempTexture); - tempButton->Appearance.BackgroundInactive = ui::Colour(tool->colRed, tool->colGreen, tool->colBlue); - tempButton->SetActionCallback(new ToolAction(this, tool)); - - if(gameController->GetActiveTool(0) == tool) - { - tempButton->SetSelectionState(0); //Primary - } - else if(gameController->GetActiveTool(1) == tool) - { - tempButton->SetSelectionState(1); //Secondary - } - else if(gameController->GetActiveTool(2) == tool) - { - tempButton->SetSelectionState(2); //Tertiary - } - - toolButtons.push_back(tempButton); - AddComponent(tempButton); - - current.X += 31; - - if(current.X + 30 > searchField->Size.X) { - current.X = 0; - current.Y += 19; - } - - if(current.Y + viewPosition.Y + 18 > Size.Y-23) - break; + tempButton->SetSelectionState(0); //Primary } + else if(gameController->GetActiveTool(1) == tool) + { + tempButton->SetSelectionState(1); //Secondary + } + else if(gameController->GetActiveTool(2) == tool) + { + tempButton->SetSelectionState(2); //Tertiary + } + + toolButtons.push_back(tempButton); + AddComponent(tempButton); + + current.X += 31; + + if(current.X + 30 > searchField->Size.X) { + current.X = 0; + current.Y += 19; + } + + if(current.Y + viewPosition.Y + 18 > Size.Y-23) + break; } }