summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2014-09-27 11:17:54 +0000
committerrubidium <rubidium@openttd.org>2014-09-27 11:17:54 +0000
commit0176ef274f3b4539f43b66a649fc0d0ee0239234 (patch)
treea97dcf3f8a401c4c6e53dc165339e87cf420b402 /src
parentf1920457965d49bc329c0648d030600db38f227a (diff)
downloadopenttd-0176ef274f3b4539f43b66a649fc0d0ee0239234.tar.xz
(svn r26928) -Change: scale the heightmap colours over the whole range of heights (based on patch by ic111)
Diffstat (limited to 'src')
-rw-r--r--src/cheat_gui.cpp4
-rw-r--r--src/smallmap_gui.cpp47
-rw-r--r--src/smallmap_gui.h2
-rw-r--r--src/table/heightmap_colours.h3
4 files changed, 47 insertions, 9 deletions
diff --git a/src/cheat_gui.cpp b/src/cheat_gui.cpp
index 5cc5083f1..4122f8830 100644
--- a/src/cheat_gui.cpp
+++ b/src/cheat_gui.cpp
@@ -141,6 +141,10 @@ static int32 ClickChangeMaxHlCheat(int32 p1, int32 p2) {
/* Execute the change and reload GRF Data */
_settings_game.construction.max_heightlevel = p1;
ReloadNewGRFData();
+
+ /* The smallmap uses an index from heightlevels to colours. Trigger rebuilding it. */
+ InvalidateWindowClassesData(WC_SMALLMAP, 2);
+
return _settings_game.construction.max_heightlevel;
}
diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp
index 16a1d1475..51aae6ba8 100644
--- a/src/smallmap_gui.cpp
+++ b/src/smallmap_gui.cpp
@@ -252,15 +252,17 @@ static const LegendAndColour * const _legend_table[] = {
/** Colour scheme of the smallmap. */
struct SmallMapColourScheme {
- const uint32 *height_colours; ///< Colour of each level in a heightmap.
- uint32 default_colour; ///< Default colour of the land.
+ uint32 *height_colours; ///< Cached colours for each level in a map.
+ const uint32 *height_colours_base; ///< Base table for determining the colours
+ size_t colour_count; ///< The number of colours.
+ uint32 default_colour; ///< Default colour of the land.
};
/** Available colour schemes for height maps. */
-static const SmallMapColourScheme _heightmap_schemes[] = {
- {_green_map_heights, MKCOLOUR_XXXX(0x54)}, ///< Green colour scheme.
- {_dark_green_map_heights, MKCOLOUR_XXXX(0x62)}, ///< Dark green colour scheme.
- {_violet_map_heights, MKCOLOUR_XXXX(0x82)}, ///< Violet colour scheme.
+static SmallMapColourScheme _heightmap_schemes[] = {
+ {NULL, _green_map_heights, lengthof(_green_map_heights), MKCOLOUR_XXXX(0x54)}, ///< Green colour scheme.
+ {NULL, _dark_green_map_heights, lengthof(_dark_green_map_heights), MKCOLOUR_XXXX(0x62)}, ///< Dark green colour scheme.
+ {NULL, _violet_map_heights, lengthof(_violet_map_heights), MKCOLOUR_XXXX(0x82)}, ///< Violet colour scheme.
};
/**
@@ -1021,6 +1023,8 @@ SmallMapWindow::SmallMapWindow(WindowDesc *desc, int window_number) : Window(des
this->InitNested(window_number);
this->LowerWidget(this->map_type + WID_SM_CONTOUR);
+ this->RebuildColourIndexIfNecessary();
+
BuildLandLegend();
this->SetWidgetLoweredState(WID_SM_SHOW_HEIGHT, _smallmap_show_heightmap);
@@ -1033,6 +1037,30 @@ SmallMapWindow::SmallMapWindow(WindowDesc *desc, int window_number) : Window(des
this->SetOverlayCargoMask();
}
+/**
+ * Rebuilds the colour indices used for fast access to the smallmap contour colours based on the heightlevel.
+ */
+void SmallMapWindow::RebuildColourIndexIfNecessary()
+{
+ /* Rebuild colour indices if necessary. */
+ if (SmallMapWindow::max_heightlevel == _settings_game.construction.max_heightlevel) return;
+
+ for (uint n = 0; n < lengthof(_heightmap_schemes); n++) {
+ /* The heights go from 0 up to and including maximum. */
+ int heights = _settings_game.construction.max_heightlevel + 1;
+ _heightmap_schemes[n].height_colours = ReallocT<uint32>(_heightmap_schemes[n].height_colours, heights);
+
+ for (int z = 0; z < heights; z++) {
+ uint access_index = (_heightmap_schemes[n].colour_count * z) / heights;
+
+ /* Choose colour by mapping the range (0..max heightlevel) on the complete colour table. */
+ _heightmap_schemes[n].height_colours[z] = _heightmap_schemes[n].height_colours_base[access_index];
+ }
+ }
+
+ SmallMapWindow::max_heightlevel = _settings_game.construction.max_heightlevel;
+}
+
/* virtual */ void SmallMapWindow::SetStringParameters(int widget) const
{
switch (widget) {
@@ -1458,11 +1486,13 @@ int SmallMapWindow::GetPositionOnLegend(Point pt)
* @param data Information about the changed data.
* - data = 0: Displayed industries at the industry chain window have changed.
* - data = 1: Companies have changed.
+ * - data = 2: Cheat changing the maximum heightlevel has been used, rebuild our heightlevel-to-colour index
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
/* virtual */ void SmallMapWindow::OnInvalidateData(int data, bool gui_scope)
{
if (!gui_scope) return;
+
switch (data) {
case 1:
/* The owner legend has already been rebuilt. */
@@ -1479,6 +1509,10 @@ int SmallMapWindow::GetPositionOnLegend(Point pt)
break;
}
+ case 2:
+ this->RebuildColourIndexIfNecessary();
+ break;
+
default: NOT_REACHED();
}
this->SetDirty();
@@ -1616,6 +1650,7 @@ Point SmallMapWindow::GetStationMiddle(const Station *st) const
SmallMapWindow::SmallMapType SmallMapWindow::map_type = SMT_CONTOUR;
bool SmallMapWindow::show_towns = true;
+int SmallMapWindow::max_heightlevel = -1;
/**
* Custom container class for displaying smallmap with a vertically resizing legend panel.
diff --git a/src/smallmap_gui.h b/src/smallmap_gui.h
index e180fabd1..7a4805841 100644
--- a/src/smallmap_gui.h
+++ b/src/smallmap_gui.h
@@ -63,6 +63,7 @@ protected:
static SmallMapType map_type; ///< Currently displayed legends.
static bool show_towns; ///< Display town names in the smallmap.
+ static int max_heightlevel; ///< Currently used/cached maximum heightlevel.
static const uint LEGEND_BLOB_WIDTH = 8; ///< Width of the coloured blob in front of a line text in the #WID_SM_LEGEND widget.
static const uint INDUSTRY_MIN_NUMBER_OF_COLUMNS = 2; ///< Minimal number of columns in the #WID_SM_LEGEND widget for the #SMT_INDUSTRY legend.
@@ -146,6 +147,7 @@ protected:
return Company::IsValidID(_local_company) ? 1U << _local_company : 0xffffffff;
}
+ void RebuildColourIndexIfNecessary();
uint GetNumberRowsLegend(uint columns) const;
void SelectLegendItem(int click_pos, LegendAndColour *legend, int end_legend_item, int begin_legend_item = 0);
void SwitchMapType(SmallMapType map_type);
diff --git a/src/table/heightmap_colours.h b/src/table/heightmap_colours.h
index 2acbd066c..04336b066 100644
--- a/src/table/heightmap_colours.h
+++ b/src/table/heightmap_colours.h
@@ -30,7 +30,6 @@ static const uint32 _green_map_heights[] = {
MKCOLOUR_XXXX(0x27),
MKCOLOUR_XXXX(0x27),
};
-assert_compile(lengthof(_green_map_heights) == MAX_TILE_HEIGHT + 1);
/** Height map colours for the dark green colour scheme, ordered by height. */
static const uint32 _dark_green_map_heights[] = {
@@ -51,7 +50,6 @@ static const uint32 _dark_green_map_heights[] = {
MKCOLOUR_XXXX(0x67),
MKCOLOUR_XXXX(0x67),
};
-assert_compile(lengthof(_dark_green_map_heights) == MAX_TILE_HEIGHT + 1);
/** Height map colours for the violet colour scheme, ordered by height. */
static const uint32 _violet_map_heights[] = {
@@ -72,4 +70,3 @@ static const uint32 _violet_map_heights[] = {
MKCOLOUR_XXXX(0x87),
MKCOLOUR_XXXX(0x87),
};
-assert_compile(lengthof(_violet_map_heights) == MAX_TILE_HEIGHT + 1);