From 109a5b998564ef4d0758979d8b7d9889d1d3573d Mon Sep 17 00:00:00 2001 From: titiger Date: Sat, 3 Jan 2015 02:03:31 +0100 Subject: [PATCH] sort map lists non case sensitive in menu --- source/glest_game/menu/menu_state_connected_game.cpp | 5 +++-- source/glest_game/menu/menu_state_custom_game.cpp | 5 +++-- source/shared_lib/include/util/util.h | 1 + source/shared_lib/sources/util/util.cpp | 4 ++++ 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index 7325c4c23..1aae3bb83 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -5092,11 +5092,12 @@ int MenuStateConnectedGame::setupMapList(string scenario) { string scenarioDir = Scenario::getScenarioDir(dirList, scenario); vector pathList = config.getPathListForType(ptMaps,scenarioDir); vector allMaps = MapPreview::findAllValidMaps(pathList,scenarioDir,false,true,&invalidMapList); - + // sort map list non case sensitive + std::sort(allMaps.begin(),allMaps.end(),compareNonCaseSensitive); if(scenario != "") { vector 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()) { diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 7a35b1165..8ab491053 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -4912,11 +4912,12 @@ int MenuStateCustomGame::setupMapList(string scenario) { string scenarioDir = Scenario::getScenarioDir(dirList, scenario); vector pathList = config.getPathListForType(ptMaps,scenarioDir); vector allMaps = MapPreview::findAllValidMaps(pathList,scenarioDir,false,true,&invalidMapList); - + // sort map list non case sensitive + std::sort(allMaps.begin(),allMaps.end(),compareNonCaseSensitive); if(scenario != "") { vector 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()) { diff --git a/source/shared_lib/include/util/util.h b/source/shared_lib/include/util/util.h index 5e3c0c7c0..eb7a44047 100644 --- a/source/shared_lib/include/util/util.h +++ b/source/shared_lib/include/util/util.h @@ -229,6 +229,7 @@ string ext(const string &s); string replaceBy(const string &s, char c1, char c2); vector 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 diff --git a/source/shared_lib/sources/util/util.cpp b/source/shared_lib/sources/util/util.cpp index 4aa58f0d3..0cbb76118 100644 --- a/source/shared_lib/sources/util/util.cpp +++ b/source/shared_lib/sources/util/util.cpp @@ -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';