If you start simutrans with multiple pak sets, a dialog for pak set selection appears. The pak sets are displayed randomly from my point of view (I have not read throught the corresponding source code).
It would be nice to have pak sets sorted in some way, e.g. alpabetically. The user would find the desired pak set easily from the menu.
I have several versions of one pak set for testing purposes and it is difficult do find the required one. See the attached screenshot.
The screenshot is from current development version of simutrans - revision 7218.
It's probably listed the way they are stored, which in practice will be more or less in the order they were installed.
I'm using windows and it is sorted alphabetically, regardless of the installation date.
It is sorted alphabetically, but not alpha-numerically. Just need to include the code to sort numbers.
See that pak128 comes first from pak64 because 1<6.
At least on my installations is like this.
Edit:
I'm with Ters, probably as how they are stored/loaded.
Quote from: Leartin on May 18, 2014, 12:30:24 PM
I'm using windows and it is sorted alphabetically, regardless of the installation date.
I am using Linux. (32-bit Debian 7.5) It sound that it is OS-dependent.
Quote from: jk271 on May 18, 2014, 02:06:26 PM
I am using Linux. (32-bit Debian 7.5) It sound that it is OS-dependent.
Actually, it's typically file system dependent.
Problem solved.
I have created a patch sorting alphabetically the items in the pak selector menu. The patch is in the attachech file.
I ask moderator to be so kind and move this discussion to the patch releases.
Great, you added in slist_tpl.h so it may be used in other places. Haven't tested yet but thanks a lot.
As An_dz says, good you added it to the template. In in r7254. Thank you.
Thank you for fast applying of the patch. Having the code in trunk (svn) / master (git) help me lot with testing of generated valleys.
I took the liberty to extend this code to do the sorting alpha-numerically and case insensitive.
What do you think? Can this be in trunk?
personally I would do only do:
int l_diff = atoi(left)-atoi(right);
if( diff==0 ) {
return strcmp( tolower(left), tolower(right) );
}
return diff;
to get essentially the same order. Still tolower does not work correctly on any non-ASCII stufff.
I don't get how this works, tolower is for single character, atoi doesn't work if first char is not a number.
I could reduce to this with your idea:
if (( NULL != l.info ) && ( NULL != r.info )) {
const char *linfo = l.info;
const char *rinfo = r.info;
char left;
char right;
while ( (left = *linfo) && (right = *rinfo) ) {
bool left_is_number = left>='0' && left<='9';
bool right_is_number = right>='0' && right<='9';
if ( left_is_number && right_is_number ) {
int diff = atoi(linfo) - atoi(rinfo);
if( diff != 0 ) {
return diff;
}
}
else {
const int diff = tolower(left) - tolower(right);
if (diff != 0) {
return diff;
}
}
++linfo;
++rinfo;
}
}
If the first character is not a number, then strcmp would return the correct result as well. But you are right, I should use stricmp (when MSC_VER) or strcasecmp (otherwise). And you had a problem with identical strings, there you need to return zero. Anyway, how about:
const char *left = l.info;
const char *right = r.info;
while( *left && *right ) {
int diff = atoi(left)-atoi(right);
if( diff==0 ) {
diff = tolower(left)-tolower(right);
}
if( diff ) {
return diff;
}
left++;
right++;
}
// for equal strings we could use memory location ... (int)(left-right)
return 0;
It doesn't seem to me that that handles strings of different length very well.
Another thing might be to use strtol instead of atoi to compare and skip whole sequences of digits in one go. It might give a better result when comparing "+1b" and "1a", but the result can be somewhat unexpected either way.
There's no problem with identical string, there already is a return 0 after this if in the original code by jk271.
Edit: Your code works, but has to be diff = tolower(*left) - tolower(*right);, or you'll be getting the string and not the char.
I don't get why to use strtoul Ters, atoi seems to work with your example.