Skip to content

Commit

Permalink
Fix alphabetical map name sorting, was reversed.
Browse files Browse the repository at this point in the history
Changed push_front → push_back in src/levels.cpp, rest is a slight refactoring.
  • Loading branch information
Cyp committed May 14, 2016
1 parent 251caba commit c82e091
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
10 changes: 3 additions & 7 deletions src/levels.cpp
Expand Up @@ -1060,8 +1060,7 @@ LEVEL_LIST enumerateMultiMaps(int camToUse, int numPlayers)
{
if (game.type == SKIRMISH)
{
int cam;

int cam = 1;
if (lev->type == MULTI_SKIRMISH2)
{
cam = 2;
Expand All @@ -1070,15 +1069,12 @@ LEVEL_LIST enumerateMultiMaps(int camToUse, int numPlayers)
{
cam = 3;
}
else
{
cam = 1;
}

if ((lev->type == SKIRMISH || lev->type == MULTI_SKIRMISH2 || lev->type == MULTI_SKIRMISH3)
&& (numPlayers == 0 || numPlayers == lev->players)
&& cam == camToUse)
{
list.push_front(lev);
list.push_back(lev);
}
}
}
Expand Down
18 changes: 8 additions & 10 deletions src/multimenu.cpp
Expand Up @@ -341,11 +341,6 @@ static int stringRelevance(std::string const &string, std::string const &search)
return scores[str.size() + sea.size() * strDim];
}

static bool reverseSortByFirst(std::pair<int, W_BUTTON *> const &a, std::pair<int, W_BUTTON *> const &b)
{
return a.first > b.first;
}

/** Searches in the given search directory for files ending with the
* given extension. Then will create a window with buttons for each
* found file.
Expand Down Expand Up @@ -438,7 +433,8 @@ void addMultiRequest(const char *searchDir, const char *fileExtension, UDWORD mo
if (mode == MULTIOP_MAP)
{
LEVEL_LIST levels = enumerateMultiMaps(mapCam, numPlayers);
std::vector<std::pair<int, W_BUTTON *> > buttons;
using Pair = std::pair<int, W_BUTTON *>;
std::vector<Pair> buttons;

for (auto mapData : levels)
{
Expand All @@ -449,14 +445,16 @@ void addMultiRequest(const char *searchDir, const char *fileExtension, UDWORD mo
button->setString(mapData->pName);
button->pUserData = mapData;
button->displayFunction = displayRequestOption;
buttons.push_back(std::make_pair(stringRelevance(mapData->pName, searchString), button));
buttons.push_back({stringRelevance(mapData->pName, searchString), button});

++nextButtonId;
}
std::stable_sort(buttons.begin(), buttons.end(), reverseSortByFirst);
for (std::vector<std::pair<int, W_BUTTON *> >::const_iterator i = buttons.begin(); i != buttons.end(); ++i)
std::stable_sort(buttons.begin(), buttons.end(), [](Pair const &a, Pair const &b) {
return a.first > b.first;
});
for (Pair const &p : buttons)
{
requestList->addWidgetToLayout(i->second);
requestList->addWidgetToLayout(p.second);
}

// if it's map select then add the cam style buttons.
Expand Down

0 comments on commit c82e091

Please sign in to comment.