Changeset - r14896:d3c9294e3b17
[Not reviewed]
master
0 1 0
terkhen - 14 years ago 2010-03-23 17:53:33
terkhen@openttd.org
(svn r19503) -Feature: Sort industries alphabetically at the smallmap legend.
1 file changed with 29 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/smallmap_gui.cpp
Show inline comments
 
@@ -23,12 +23,13 @@
 
#include "strings_func.h"
 
#include "core/endian_func.hpp"
 
#include "vehicle_base.h"
 
#include "sound_func.h"
 
#include "window_func.h"
 
#include "company_base.h"
 
#include "core/sort_func.hpp"
 

	
 
#include "table/strings.h"
 
#include "table/sprites.h"
 

	
 
/** Widget numbers of the small map window. */
 
enum SmallMapWindowWidgets {
 
@@ -148,12 +149,39 @@ static const LegendAndColour _legend_lan
 
static LegendAndColour _legend_from_industries[NUM_INDUSTRYTYPES + 1];
 
/* For connecting industry type to position in industries list(small map legend) */
 
static uint _industry_to_list_pos[NUM_INDUSTRYTYPES];
 
/** Show heightmap in industry mode of smallmap window. */
 
static bool _smallmap_industry_show_heightmap;
 

	
 
/** Sort legends by their name. */
 
static int CDECL LegendNameSorter(const LegendAndColour *a, const LegendAndColour *b)
 
{
 
	static char industry_name[2][64];
 

	
 
	SetDParam(0, a->legend);
 
	GetString(industry_name[0], STR_JUST_STRING, lastof(industry_name[0]));
 

	
 
	SetDParam(0, b->legend);
 
	GetString(industry_name[1], STR_JUST_STRING, lastof(industry_name[1]));
 

	
 
	int r = strcmp(industry_name[0], industry_name[1]);
 
	/* If the names are equal, sort by industry type. */
 
	return (r != 0) ? r : (a->type - b->type);
 
}
 

	
 
void SortIndustriesLegend()
 
{
 
	/* Sort industries by name. */
 
	GSortT(_legend_from_industries, _smallmap_industry_count, &LegendNameSorter);
 

	
 
	/* Store widget number for each industry type. */
 
	for (int i = 0; i < _smallmap_industry_count; i++) {
 
		_industry_to_list_pos[_legend_from_industries[i].type] = i;
 
	}
 
}
 

	
 
/**
 
 * Fills an array for the industries legends.
 
 */
 
void BuildIndustriesLegend()
 
{
 
	uint j = 0;
 
@@ -166,14 +194,12 @@ void BuildIndustriesLegend()
 
			_legend_from_industries[j].colour = indsp->map_colour;
 
			_legend_from_industries[j].type = i;
 
			_legend_from_industries[j].show_on_map = true;
 
			_legend_from_industries[j].col_break = false;
 
			_legend_from_industries[j].end = false;
 

	
 
			/* Store widget number for this industry type */
 
			_industry_to_list_pos[i] = j;
 
			j++;
 
		}
 
	}
 
	/* Terminate the list */
 
	_legend_from_industries[j].end = true;
 

	
 
@@ -1021,12 +1047,13 @@ public:
 
				break;
 
		}
 
	}
 

	
 
	virtual void OnInit()
 
	{
 
		SortIndustriesLegend();
 
		uint min_width = 0;
 
		this->min_number_of_columns = INDUSTRY_MIN_NUMBER_OF_COLUMNS;
 
		this->min_number_of_fixed_rows = 0;
 
		for (uint i = 0; i < lengthof(_legend_table); i++) {
 
			uint height = 0;
 
			uint num_columns = 1;
0 comments (0 inline, 0 general)