summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorterkhen <terkhen@openttd.org>2010-03-23 17:53:33 +0000
committerterkhen <terkhen@openttd.org>2010-03-23 17:53:33 +0000
commit87e7c013430738180759655d20d9190079c751d7 (patch)
treedc3c4bcd3b613cf1f7ee8e08f7f7a38d1a077b3d
parentd790f3db3a30f8b7c0f987a4d434358cf3695a85 (diff)
downloadopenttd-87e7c013430738180759655d20d9190079c751d7.tar.xz
(svn r19503) -Feature: Sort industries alphabetically at the smallmap legend.
-rw-r--r--src/smallmap_gui.cpp31
1 files changed, 29 insertions, 2 deletions
diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp
index e44957217..226ac6e1d 100644
--- a/src/smallmap_gui.cpp
+++ b/src/smallmap_gui.cpp
@@ -26,6 +26,7 @@
#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"
@@ -151,6 +152,33 @@ 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.
*/
@@ -169,8 +197,6 @@ void BuildIndustriesLegend()
_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++;
}
}
@@ -1024,6 +1050,7 @@ public:
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;