sort map lists non case sensitive in menu

This commit is contained in:
titiger 2015-01-03 02:03:31 +01:00
parent f4529566fa
commit 109a5b9985
4 changed files with 11 additions and 4 deletions

View File

@ -5092,11 +5092,12 @@ int MenuStateConnectedGame::setupMapList(string scenario) {
string scenarioDir = Scenario::getScenarioDir(dirList, scenario);
vector<string> pathList = config.getPathListForType(ptMaps,scenarioDir);
vector<string> allMaps = MapPreview::findAllValidMaps(pathList,scenarioDir,false,true,&invalidMapList);
// sort map list non case sensitive
std::sort(allMaps.begin(),allMaps.end(),compareNonCaseSensitive);
if(scenario != "") {
vector<string> allMaps2 = MapPreview::findAllValidMaps(config.getPathListForType(ptMaps,""),"",false,true,&invalidMapList);
copy(allMaps2.begin(), allMaps2.end(), std::inserter(allMaps, allMaps.begin()));
std::sort(allMaps.begin(),allMaps.end());
std::sort(allMaps.begin(),allMaps.end(),compareNonCaseSensitive);
}
if (allMaps.empty()) {

View File

@ -4912,11 +4912,12 @@ int MenuStateCustomGame::setupMapList(string scenario) {
string scenarioDir = Scenario::getScenarioDir(dirList, scenario);
vector<string> pathList = config.getPathListForType(ptMaps,scenarioDir);
vector<string> allMaps = MapPreview::findAllValidMaps(pathList,scenarioDir,false,true,&invalidMapList);
// sort map list non case sensitive
std::sort(allMaps.begin(),allMaps.end(),compareNonCaseSensitive);
if(scenario != "") {
vector<string> allMaps2 = MapPreview::findAllValidMaps(config.getPathListForType(ptMaps,""),"",false,true,&invalidMapList);
copy(allMaps2.begin(), allMaps2.end(), std::inserter(allMaps, allMaps.begin()));
std::sort(allMaps.begin(),allMaps.end());
std::sort(allMaps.begin(),allMaps.end(),compareNonCaseSensitive);
}
if (allMaps.empty()) {

View File

@ -229,6 +229,7 @@ string ext(const string &s);
string replaceBy(const string &s, char c1, char c2);
vector<string> split(string s,string d);
string toLower(const string &s);
bool compareNonCaseSensitive(const string a, const string b);
void copyStringToBuffer(char *buffer, int bufferSize, const string& s);
//numeric fcs

View File

@ -735,6 +735,10 @@ string toLower(const string &s){
return rs;
}
bool compareNonCaseSensitive(const string a, const string b) {
return (toLower(a) < toLower(b));
}
void copyStringToBuffer(char *buffer, int bufferSize, const string& s){
strncpy(buffer, s.c_str(), bufferSize-1);
buffer[bufferSize-1]= '\0';