1
0
mirror of https://github.com/OpenTTD/OpenTTD.git synced 2025-08-19 12:39:11 +00:00

(svn r24983) -Change: Apply the same name sorting rules to content and NewGRF list as for the server list.

This commit is contained in:
frosch
2013-02-09 17:31:07 +00:00
parent 4e61c1770d
commit 3e02890b73
5 changed files with 24 additions and 19 deletions

View File

@@ -323,7 +323,7 @@ class NetworkContentListWindow : public Window, ContentCallback {
/** Sort content by name. */
static int CDECL NameSorter(const ContentInfo * const *a, const ContentInfo * const *b)
{
return strnatcmp((*a)->name, (*b)->name); // Sort by name (natural sorting).
return strnatcmp((*a)->name, (*b)->name, true); // Sort by name (natural sorting).
}
/** Sort content by type. */

View File

@@ -263,24 +263,10 @@ protected:
this->UpdateListPos();
}
/**
* Skip some of the 'garbage' in the string that we don't want to use
* to sort on. This way the alphabetical sorting will work better as
* we would be actually using those characters instead of some other
* characters such as spaces and tildes at the begin of the name.
* @param str The string to skip the initial garbage of.
* @return The string with the garbage skipped.
*/
static const char *SkipGarbage(const char *str)
{
while (*str != '\0' && (*str < 'A' || IsInsideMM(*str, '[', '`' + 1) || IsInsideMM(*str, '{', '~' + 1))) str++;
return str;
}
/** Sort servers by name. */
static int CDECL NGameNameSorter(NetworkGameList * const *a, NetworkGameList * const *b)
{
int r = strnatcmp(SkipGarbage((*a)->info.server_name), SkipGarbage((*b)->info.server_name)); // Sort by name (natural sorting).
int r = strnatcmp((*a)->info.server_name, (*b)->info.server_name, true); // Sort by name (natural sorting).
return r == 0 ? (*a)->address.CompareTo((*b)->address) : r;
}