File diff r4911:1934a0c6e865 → r4912:d420151de4c6
town_gui.c
Show inline comments
 
@@ -357,57 +357,57 @@ static const Widget _town_directory_widg
 
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    13,     0,    98,    14,    25, STR_SORT_BY_NAME,       STR_SORT_ORDER_TIP},
 
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    13,    99,   195,    14,    25, STR_SORT_BY_POPULATION, STR_SORT_ORDER_TIP},
 
{     WWT_IMGBTN, RESIZE_BOTTOM,    13,     0,   195,    26,   189, 0x0,                    STR_200A_TOWN_NAMES_CLICK_ON_NAME},
 
{  WWT_SCROLLBAR, RESIZE_BOTTOM,    13,   196,   207,    14,   189, 0x0,                    STR_0190_SCROLL_BAR_SCROLLS_LIST},
 
{    WWT_PANEL,     RESIZE_TB,      13,     0,   195,   190,   201, 0x0,                    STR_NULL},
 
{  WWT_RESIZEBOX,     RESIZE_TB,    13,   196,   207,   190,   201, 0x0,                    STR_RESIZE_BUTTON},
 
{   WIDGETS_END},
 
};
 

	
 

	
 
// used to get a sorted list of the towns
 
static uint _num_town_sort;
 

	
 
static char _bufcache[64];
 
static const Town* _last_town;
 

	
 
static int CDECL TownNameSorter(const void *a, const void *b)
 
{
 
	const Town* ta = *(const Town**)a;
 
	const Town* tb = *(const Town**)b;
 
	char buf1[64];
 
	int r;
 

	
 
	SetDParam(0, ta->index);
 
	GetString(buf1, STR_TOWN);
 
	GetString(buf1, STR_TOWN, lastof(buf1));
 

	
 
	/* If 'b' is the same town as in the last round, use the cached value
 
	 *  We do this to speed stuff up ('b' is called with the same value a lot of
 
	 *  times after eachother) */
 
	if (tb != _last_town) {
 
		_last_town = tb;
 
		SetDParam(0, tb->index);
 
		GetString(_bufcache, STR_TOWN);
 
		GetString(_bufcache, STR_TOWN, lastof(_bufcache));
 
	}
 

	
 
	r = strcmp(buf1, _bufcache);
 
	if (_town_sort_order & 1) r = -r;
 
	return r;
 
}
 

	
 
static int CDECL TownPopSorter(const void *a, const void *b)
 
{
 
	const Town* ta = *(const Town**)a;
 
	const Town* tb = *(const Town**)b;
 
	int r = ta->population - tb->population;
 
	if (_town_sort_order & 1) r = -r;
 
	return r;
 
}
 

	
 
static void MakeSortedTownList(void)
 
{
 
	const Town* t;
 
	uint n = 0;
 

	
 
	/* Create array for sorting */
 
	_town_sort = realloc((void*)_town_sort, GetTownArraySize() * sizeof(_town_sort[0]));
 
	if (_town_sort == NULL)