Changeset - r20255:e962597d7e2b
[Not reviewed]
master
0 6 0
rubidium - 11 years ago 2013-05-19 14:36:35
rubidium@openttd.org
(svn r25262) -Feature: linkgraph overlay for smallmap
6 files changed with 164 insertions and 12 deletions:
0 comments (0 inline, 0 general)
src/lang/english.txt
Show inline comments
 
@@ -659,23 +659,26 @@ STR_HIGHSCORE_PRESIDENT_OF_COMPANY_ACHIE
 
# Smallmap window
 
STR_SMALLMAP_CAPTION                                            :{WHITE}Map - {STRING}
 

	
 
STR_SMALLMAP_TYPE_CONTOURS                                      :Contours
 
STR_SMALLMAP_TYPE_VEHICLES                                      :Vehicles
 
STR_SMALLMAP_TYPE_INDUSTRIES                                    :Industries
 
STR_SMALLMAP_TYPE_ROUTEMAP                                      :Cargo Flow
 
STR_SMALLMAP_TYPE_ROUTES                                        :Routes
 
STR_SMALLMAP_TYPE_VEGETATION                                    :Vegetation
 
STR_SMALLMAP_TYPE_OWNERS                                        :Owners
 
STR_SMALLMAP_TOOLTIP_SHOW_LAND_CONTOURS_ON_MAP                  :{BLACK}Show land contours on map
 
STR_SMALLMAP_TOOLTIP_SHOW_VEHICLES_ON_MAP                       :{BLACK}Show vehicles on map
 
STR_SMALLMAP_TOOLTIP_SHOW_INDUSTRIES_ON_MAP                     :{BLACK}Show industries on map
 
STR_SMALLMAP_TOOLTIP_SHOW_LINK_STATS_ON_MAP                     :{BLACK}Show cargo flow on map
 
STR_SMALLMAP_TOOLTIP_SHOW_TRANSPORT_ROUTES_ON                   :{BLACK}Show transport routes on map
 
STR_SMALLMAP_TOOLTIP_SHOW_VEGETATION_ON_MAP                     :{BLACK}Show vegetation on map
 
STR_SMALLMAP_TOOLTIP_SHOW_LAND_OWNERS_ON_MAP                    :{BLACK}Show land owners on map
 
STR_SMALLMAP_TOOLTIP_INDUSTRY_SELECTION                         :{BLACK}Click on an industry type to toggle displaying it. Ctrl+Click disables all types except the selected one. Ctrl+Click on it again to enable all industry types
 
STR_SMALLMAP_TOOLTIP_COMPANY_SELECTION                          :{BLACK}Click on a company to toggle displaying its property. Ctrl+Click disables all companies except the selected one. Ctrl+Click on it again to enable all companies
 
STR_SMALLMAP_TOOLTIP_CARGO_SELECTION                            :{BLACK}Click on a cargo to toggle displaying its property. Ctrl+Click disables all cargos except the selected one. Ctrl+Click on it again to enable all cargos
 

	
 
STR_SMALLMAP_LEGENDA_ROADS                                      :{TINY_FONT}{BLACK}Roads
 
STR_SMALLMAP_LEGENDA_RAILROADS                                  :{TINY_FONT}{BLACK}Railways
 
STR_SMALLMAP_LEGENDA_STATIONS_AIRPORTS_DOCKS                    :{TINY_FONT}{BLACK}Stations/Airports/Docks
 
STR_SMALLMAP_LEGENDA_BUILDINGS_INDUSTRIES                       :{TINY_FONT}{BLACK}Buildings/Industries
 
STR_SMALLMAP_LEGENDA_VEHICLES                                   :{TINY_FONT}{BLACK}Vehicles
 
@@ -703,22 +706,25 @@ STR_SMALLMAP_LEGENDA_INDUSTRIES         
 
STR_SMALLMAP_LEGENDA_DESERT                                     :{TINY_FONT}{BLACK}Desert
 
STR_SMALLMAP_LEGENDA_SNOW                                       :{TINY_FONT}{BLACK}Snow
 

	
 
STR_SMALLMAP_TOOLTIP_TOGGLE_TOWN_NAMES_ON_OFF                   :{BLACK}Toggle town names on/off on map
 
STR_SMALLMAP_CENTER                                             :{BLACK}Centre the smallmap on the current position
 
STR_SMALLMAP_INDUSTRY                                           :{TINY_FONT}{STRING} ({NUM})
 
STR_SMALLMAP_LINKSTATS                                          :{TINY_FONT}{STRING}
 
STR_SMALLMAP_COMPANY                                            :{TINY_FONT}{COMPANY}
 
STR_SMALLMAP_TOWN                                               :{TINY_FONT}{WHITE}{TOWN}
 
STR_SMALLMAP_DISABLE_ALL                                        :{BLACK}Disable all
 
STR_SMALLMAP_ENABLE_ALL                                         :{BLACK}Enable all
 
STR_SMALLMAP_SHOW_HEIGHT                                        :{BLACK}Show height
 
STR_SMALLMAP_TOOLTIP_DISABLE_ALL_INDUSTRIES                     :{BLACK}Display no industries on the map
 
STR_SMALLMAP_TOOLTIP_ENABLE_ALL_INDUSTRIES                      :{BLACK}Display all industries on the map
 
STR_SMALLMAP_TOOLTIP_SHOW_HEIGHT                                :{BLACK}Toggle display of heightmap
 
STR_SMALLMAP_TOOLTIP_DISABLE_ALL_COMPANIES                      :{BLACK}Display no company property on the map
 
STR_SMALLMAP_TOOLTIP_ENABLE_ALL_COMPANIES                       :{BLACK}Display all company property on the map
 
STR_SMALLMAP_TOOLTIP_DISABLE_ALL_CARGOS                         :{BLACK}Display no cargos on the map
 
STR_SMALLMAP_TOOLTIP_ENABLE_ALL_CARGOS                          :{BLACK}Display all cargos on the map
 

	
 
# Status bar messages
 
STR_STATUSBAR_TOOLTIP_SHOW_LAST_NEWS                            :{BLACK}Show last message or news report
 
STR_STATUSBAR_COMPANY_NAME                                      :{SILVER}- -  {COMPANY}  - -
 
STR_STATUSBAR_PAUSED                                            :{YELLOW}*  *  PAUSED  *  *
 
STR_STATUSBAR_AUTOSAVE                                          :{RED}AUTOSAVE
 
@@ -2155,12 +2161,17 @@ STR_TRANSPARENT_BUILDINGS_TOOLTIP       
 
STR_TRANSPARENT_BRIDGES_TOOLTIP                                 :{BLACK}Toggle transparency for bridges. Ctrl+Click to lock
 
STR_TRANSPARENT_STRUCTURES_TOOLTIP                              :{BLACK}Toggle transparency for structures like lighthouses and antennas. Ctrl+Click to lock
 
STR_TRANSPARENT_CATENARY_TOOLTIP                                :{BLACK}Toggle transparency for catenary. Ctrl+Click to lock
 
STR_TRANSPARENT_LOADING_TOOLTIP                                 :{BLACK}Toggle transparency for loading indicators. Ctrl+Click to lock
 
STR_TRANSPARENT_INVISIBLE_TOOLTIP                               :{BLACK}Set objects invisible instead of transparent
 

	
 
# Linkgraph legend window and linkgraph legend in smallmap
 
STR_LINKGRAPH_LEGEND_UNUSED                                     :{TINY_FONT}{BLACK}unused
 
STR_LINKGRAPH_LEGEND_SATURATED                                  :{TINY_FONT}{BLACK}saturated
 
STR_LINKGRAPH_LEGEND_OVERLOADED                                 :{TINY_FONT}{BLACK}overloaded
 

	
 
# Base for station construction window(s)
 
STR_STATION_BUILD_COVERAGE_AREA_TITLE                           :{BLACK}Coverage area highlight
 
STR_STATION_BUILD_COVERAGE_OFF                                  :{BLACK}Off
 
STR_STATION_BUILD_COVERAGE_ON                                   :{BLACK}On
 
STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP                     :{BLACK}Don't highlight coverage area of proposed site
 
STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP                      :{BLACK}Highlight coverage area of proposed site
src/linkgraph/linkgraph_gui.cpp
Show inline comments
 
@@ -10,14 +10,14 @@
 
/** @file linkgraph_gui.cpp Implementation of linkgraph overlay GUI. */
 

	
 
#include "../stdafx.h"
 
#include "../window_gui.h"
 
#include "../company_base.h"
 
#include "../date_func.h"
 
#include "linkgraph_gui.h"
 
#include "../viewport_func.h"
 
#include "../smallmap_gui.h"
 

	
 
/**
 
 * Colours for the various "load" states of links. Ordered from "unused" to
 
 * "overloaded".
 
 */
 
const uint8 LinkGraphOverlay::LINK_COLOURS[] = {
 
@@ -259,16 +259,15 @@ void LinkGraphOverlay::DrawStationDots(c
 

	
 
/**
 
 * Determine the middle of a station in the current window.
 
 * @param st The station we're looking for.
 
 * @return Middle point of the station in the current window.
 
 */
 
Point LinkGraphOverlay::GetStationMiddle(const Station *st) const {
 
	Point dummy;
 
	dummy.x = dummy.y = 0;
 
	return dummy;
 
Point LinkGraphOverlay::GetStationMiddle(const Station *st) const
 
{
 
	return static_cast<const SmallMapWindow *>(this->window)->GetStationMiddle(st);
 
}
 

	
 
/**
 
 * Set a new cargo mask and rebuild the cache.
 
 * @param cargo_mask New cargo mask.
 
 */
src/newgrf.cpp
Show inline comments
 
@@ -9024,12 +9024,15 @@ static void AfterLoadGRFs()
 
	/* Sort the list of industry types. */
 
	SortIndustryTypes();
 

	
 
	/* Create dynamic list of industry legends for smallmap_gui.cpp */
 
	BuildIndustriesLegend();
 

	
 
	/* Build the routemap legend, based on the available cargos */
 
	BuildLinkStatsLegend();
 

	
 
	/* Add all new airports to the airports array. */
 
	FinaliseAirportsArray();
 
	BindAirportSpecs();
 

	
 
	/* Update the townname generators list */
 
	InitGRFTownGeneratorNames();
src/smallmap_gui.cpp
Show inline comments
 
@@ -27,12 +27,16 @@
 
#include "smallmap_gui.h"
 

	
 
#include "table/strings.h"
 

	
 
static int _smallmap_industry_count; ///< Number of used industries
 
static int _smallmap_company_count;  ///< Number of entries in the owner legend.
 
static int _smallmap_cargo_count;    ///< Number of cargos in the link stats legend.
 

	
 
/** Link stat colours shown in legenda. */
 
static uint8 _linkstat_colours_in_legenda[] = {0, 1, 3, 5, 7, 9, 11};
 

	
 
static const int NUM_NO_COMPANY_ENTRIES = 4; ///< Number of entries in the owner legend that are not companies.
 

	
 
static const uint8 PC_ROUGH_LAND      = 0x52; ///< Dark green palette colour for rough land.
 
static const uint8 PC_GRASS_LAND      = 0x54; ///< Dark green palette colour for grass land.
 
static const uint8 PC_BARE_LAND       = 0x37; ///< Brown palette colour for bare land.
 
@@ -131,12 +135,14 @@ static LegendAndColour _legend_land_owne
 
#undef MC
 
#undef MS
 
#undef MO
 
#undef MOEND
 
#undef MKEND
 

	
 
/** Legend entries for the link stats view. */
 
static LegendAndColour _legend_linkstats[NUM_CARGO + lengthof(_linkstat_colours_in_legenda) + 1];
 
/**
 
 * Allow room for all industries, plus a terminator entry
 
 * This is required in order to have the industry slots all filled up
 
 */
 
static LegendAndColour _legend_from_industries[NUM_INDUSTRYTYPES + 1];
 
/** For connecting industry type to position in industries list(small map legend) */
 
@@ -178,16 +184,50 @@ void BuildIndustriesLegend()
 
	_legend_from_industries[j].end = true;
 

	
 
	/* Store number of enabled industries */
 
	_smallmap_industry_count = j;
 
}
 

	
 
/**
 
 * Populate legend table for the link stat view.
 
 */
 
void BuildLinkStatsLegend()
 
{
 
	/* Clear the legend */
 
	memset(_legend_linkstats, 0, sizeof(_legend_linkstats));
 

	
 
	uint i = 0;
 
	for (; i < _sorted_cargo_specs_size; ++i) {
 
		const CargoSpec *cs = _sorted_cargo_specs[i];
 

	
 
		_legend_linkstats[i].legend = cs->name;
 
		_legend_linkstats[i].colour = cs->legend_colour;
 
		_legend_linkstats[i].type = cs->Index();
 
		_legend_linkstats[i].show_on_map = true;
 
	}
 

	
 
	_legend_linkstats[i].col_break = true;
 
	_smallmap_cargo_count = i;
 

	
 
	for (; i < _smallmap_cargo_count + lengthof(_linkstat_colours_in_legenda); ++i) {
 
		_legend_linkstats[i].legend = STR_EMPTY;
 
		_legend_linkstats[i].colour = LinkGraphOverlay::LINK_COLOURS[_linkstat_colours_in_legenda[i - _smallmap_cargo_count]];
 
		_legend_linkstats[i].show_on_map = true;
 
	}
 

	
 
	_legend_linkstats[_smallmap_cargo_count].legend = STR_LINKGRAPH_LEGEND_UNUSED;
 
	_legend_linkstats[i - 1].legend = STR_LINKGRAPH_LEGEND_OVERLOADED;
 
	_legend_linkstats[(_smallmap_cargo_count + i - 1) / 2].legend = STR_LINKGRAPH_LEGEND_SATURATED;
 
	_legend_linkstats[i].end = true;
 
}
 

	
 
static const LegendAndColour * const _legend_table[] = {
 
	_legend_land_contours,
 
	_legend_vehicles,
 
	_legend_from_industries,
 
	_legend_linkstats,
 
	_legend_routes,
 
	_legend_vegetation,
 
	_legend_land_owners,
 
};
 

	
 
#define MKCOLOUR(x)         TO_LE32X(x)
 
@@ -474,12 +514,23 @@ static inline uint32 GetSmallMapRoutesPi
 

	
 
	/* Ground colour */
 
	const SmallMapColourScheme *cs = &_heightmap_schemes[_settings_client.gui.smallmap_land_colour];
 
	return ApplyMask(cs->default_colour, &_smallmap_contours_andor[t]);
 
}
 

	
 
/**
 
 * Return the colour a tile would be displayed with in the small map in mode "link stats".
 
 *
 
 * @param tile The tile of which we would like to get the colour.
 
 * @param t    Effective tile type of the tile (see #GetEffectiveTileType).
 
 * @return The colour of tile in the small map in mode "link stats"
 
 */
 
static inline uint32 GetSmallMapLinkStatsPixels(TileIndex tile, TileType t)
 
{
 
	return _smallmap_show_heightmap ? GetSmallMapContoursPixels(tile, t) : GetSmallMapRoutesPixels(tile, t);
 
}
 

	
 
static const uint32 _vegetation_clear_bits[] = {
 
	MKCOLOUR_XXXX(PC_GRASS_LAND), ///< full grass
 
	MKCOLOUR_XXXX(PC_ROUGH_LAND), ///< rough land
 
	MKCOLOUR_XXXX(PC_GREY),       ///< rocks
 
	MKCOLOUR_XXXX(PC_FIELDS),     ///< fields
 
@@ -683,12 +734,14 @@ void SmallMapWindow::SetZoomLevel(ZoomLe
 
	if (new_index != cur_index) {
 
		this->zoom = zoomlevels[new_index];
 
		if (cur_index >= 0) {
 
			Point new_tile = this->PixelToTile(zoom_pt->x, zoom_pt->y, &sub);
 
			this->SetNewScroll(this->scroll_x + (tile.x - new_tile.x) * TILE_SIZE,
 
					this->scroll_y + (tile.y - new_tile.y) * TILE_SIZE, sub);
 
		} else if (this->map_type == SMT_LINKSTATS) {
 
			this->overlay->RebuildCache();
 
		}
 
		this->SetWidgetDisabledState(WID_SM_ZOOM_IN,  this->zoom == zoomlevels[MIN_ZOOM_INDEX]);
 
		this->SetWidgetDisabledState(WID_SM_ZOOM_OUT, this->zoom == zoomlevels[MAX_ZOOM_INDEX]);
 
		this->SetDirty();
 
	}
 
}
 
@@ -720,12 +773,15 @@ inline uint32 SmallMapWindow::GetTileCol
 
		case SMT_VEHICLES:
 
			return GetSmallMapVehiclesPixels(tile, et);
 

	
 
		case SMT_INDUSTRY:
 
			return GetSmallMapIndustriesPixels(tile, et);
 

	
 
		case SMT_LINKSTATS:
 
			return GetSmallMapLinkStatsPixels(tile, et);
 

	
 
		case SMT_ROUTES:
 
			return GetSmallMapRoutesPixels(tile, et);
 

	
 
		case SMT_VEGETATION:
 
			return GetSmallMapVegetationPixels(tile, et);
 

	
 
@@ -929,12 +985,15 @@ void SmallMapWindow::DrawSmallMap(DrawPi
 
		x += 2;
 
	}
 

	
 
	/* Draw vehicles */
 
	if (this->map_type == SMT_CONTOUR || this->map_type == SMT_VEHICLES) this->DrawVehicles(dpi, blitter);
 

	
 
	/* Draw link stat overlay */
 
	if (this->map_type == SMT_LINKSTATS) this->overlay->Draw(dpi);
 

	
 
	/* Draw town names */
 
	if (this->show_towns) this->DrawTowns(dpi);
 

	
 
	/* Draw map indicators */
 
	this->DrawMapIndicators();
 

	
 
@@ -962,12 +1021,19 @@ void SmallMapWindow::SetupWidgetData()
 
			legend_tooltip = STR_SMALLMAP_TOOLTIP_COMPANY_SELECTION;
 
			enable_all_tooltip = STR_SMALLMAP_TOOLTIP_ENABLE_ALL_COMPANIES;
 
			disable_all_tooltip = STR_SMALLMAP_TOOLTIP_DISABLE_ALL_COMPANIES;
 
			plane = 0;
 
			break;
 

	
 
		case SMT_LINKSTATS:
 
			legend_tooltip = STR_SMALLMAP_TOOLTIP_CARGO_SELECTION;
 
			enable_all_tooltip = STR_SMALLMAP_TOOLTIP_ENABLE_ALL_CARGOS;
 
			disable_all_tooltip = STR_SMALLMAP_TOOLTIP_DISABLE_ALL_CARGOS;
 
			plane = 0;
 
			break;
 

	
 
		default:
 
			legend_tooltip = STR_NULL;
 
			enable_all_tooltip = STR_NULL;
 
			disable_all_tooltip = STR_NULL;
 
			plane = 1;
 
			break;
 
@@ -979,24 +1045,26 @@ void SmallMapWindow::SetupWidgetData()
 
	this->GetWidget<NWidgetStacked>(WID_SM_SELECT_BUTTONS)->SetDisplayedPlane(plane);
 
}
 

	
 
SmallMapWindow::SmallMapWindow(const WindowDesc *desc, int window_number) : Window(), refresh(FORCE_REFRESH_PERIOD)
 
{
 
	_smallmap_industry_highlight = INVALID_INDUSTRYTYPE;
 
	this->overlay = new LinkGraphOverlay(this, WID_SM_MAP);
 
	this->InitNested(desc, window_number);
 
	this->LowerWidget(this->map_type + WID_SM_CONTOUR);
 

	
 
	BuildLandLegend();
 
	this->SetWidgetLoweredState(WID_SM_SHOW_HEIGHT, _smallmap_show_heightmap);
 

	
 
	this->SetWidgetLoweredState(WID_SM_TOGGLETOWNNAME, this->show_towns);
 

	
 
	this->SetupWidgetData();
 

	
 
	this->SetZoomLevel(ZLC_INITIALIZE, NULL);
 
	this->SmallMapCenterOnCurrentPos();
 
	this->SetOverlayCargoMask();
 
}
 

	
 
/* virtual */ void SmallMapWindow::SetStringParameters(int widget) const
 
{
 
	switch (widget) {
 
		case WID_SM_CAPTION:
 
@@ -1006,22 +1074,25 @@ SmallMapWindow::SmallMapWindow(const Win
 
}
 

	
 
/* virtual */ void SmallMapWindow::OnInit()
 
{
 
	uint min_width = 0;
 
	this->min_number_of_columns = INDUSTRY_MIN_NUMBER_OF_COLUMNS;
 
	this->min_number_of_fixed_rows = 0;
 
	this->min_number_of_fixed_rows = lengthof(_linkstat_colours_in_legenda);
 
	for (uint i = 0; i < lengthof(_legend_table); i++) {
 
		uint height = 0;
 
		uint num_columns = 1;
 
		for (const LegendAndColour *tbl = _legend_table[i]; !tbl->end; ++tbl) {
 
			StringID str;
 
			if (i == SMT_INDUSTRY) {
 
				SetDParam(0, tbl->legend);
 
				SetDParam(1, IndustryPool::MAX_SIZE);
 
				str = STR_SMALLMAP_INDUSTRY;
 
			} else if (i == SMT_LINKSTATS) {
 
				SetDParam(0, tbl->legend);
 
				str = STR_SMALLMAP_LINKSTATS;
 
			} else if (i == SMT_OWNER) {
 
				if (tbl->company != INVALID_COMPANY) {
 
					if (!Company::IsValidID(tbl->company)) {
 
						/* Rebuild the owner legend. */
 
						BuildOwnerLegend();
 
						this->OnInit();
 
@@ -1095,21 +1166,24 @@ SmallMapWindow::SmallMapWindow(const Win
 

	
 
			StringID string = STR_NULL;
 
			switch (this->map_type) {
 
				case SMT_INDUSTRY:
 
					string = STR_SMALLMAP_INDUSTRY;
 
					break;
 
				case SMT_LINKSTATS:
 
					string = STR_SMALLMAP_LINKSTATS;
 
					break;
 
				case SMT_OWNER:
 
					string = STR_SMALLMAP_COMPANY;
 
					break;
 
				default:
 
					break;
 
			}
 

	
 
			for (const LegendAndColour *tbl = _legend_table[this->map_type]; !tbl->end; ++tbl) {
 
				if (tbl->col_break || ((this->map_type == SMT_INDUSTRY || this->map_type == SMT_OWNER) && i++ >= number_of_rows)) {
 
				if (tbl->col_break || ((this->map_type == SMT_INDUSTRY || this->map_type == SMT_OWNER || this->map_type == SMT_LINKSTATS) && i++ >= number_of_rows)) {
 
					/* Column break needed, continue at top, COLUMN_WIDTH pixels
 
					 * (one "row") to the right. */
 
					x += rtl ? -(int)this->column_width : this->column_width;
 
					y = y_org;
 
					i = 1;
 
				}
 
@@ -1123,12 +1197,15 @@ SmallMapWindow::SmallMapWindow(const Win
 
						SetDParam(0, tbl->legend);
 
						SetDParam(1, Industry::GetIndustryTypeCount(tbl->type));
 
						if (tbl->show_on_map && tbl->type == _smallmap_industry_highlight) {
 
							legend_colour = _smallmap_industry_highlight_state ? PC_WHITE : PC_BLACK;
 
						}
 
						/* FALL THROUGH */
 
					case SMT_LINKSTATS:
 
						SetDParam(0, tbl->legend);
 
						/* FALL_THROUGH */
 
					case SMT_OWNER:
 
						if (this->map_type != SMT_OWNER || tbl->company != INVALID_COMPANY) {
 
							if (this->map_type == SMT_OWNER) SetDParam(0, tbl->company);
 
							if (!tbl->show_on_map) {
 
								/* Simply draw the string, not the black border of the legend colour.
 
								 * This will enforce the idea of the disabled item */
 
@@ -1164,12 +1241,13 @@ void SmallMapWindow::SwitchMapType(Small
 
	this->RaiseWidget(this->map_type + WID_SM_CONTOUR);
 
	this->map_type = map_type;
 
	this->LowerWidget(this->map_type + WID_SM_CONTOUR);
 

	
 
	this->SetupWidgetData();
 

	
 
	if (map_type == SMT_LINKSTATS) this->overlay->RebuildCache();
 
	this->SetDirty();
 
}
 

	
 
/**
 
 * Get the number of rows in the legend from the number of columns. Those
 
 * are at least min_number_of_fixed_rows and possibly more if there are so
 
@@ -1177,14 +1255,16 @@ void SmallMapWindow::SwitchMapType(Small
 
 * available space.
 
 * @param columns Number of columns in the legend.
 
 * @return Number of rows needed for everything to fit in.
 
 */
 
inline uint SmallMapWindow::GetNumberRowsLegend(uint columns) const
 
{
 
	uint num_rows = CeilDiv(max(_smallmap_industry_count,_smallmap_company_count), columns);
 
	return max(this->min_number_of_fixed_rows, num_rows);
 
	/* Reserve one column for link colours */
 
	uint num_rows_linkstats = CeilDiv(_smallmap_cargo_count, columns - 1);
 
	uint num_rows_others = CeilDiv(max(_smallmap_industry_count,_smallmap_company_count), columns);
 
	return max(this->min_number_of_fixed_rows, max(num_rows_linkstats, num_rows_others));
 
}
 

	
 
/**
 
 * Select and toggle a legend item. When CTRL is pressed, disable all other
 
 * items in the group defined by begin_legend_item and end_legend_item and
 
 * keep the clicked one enabled even if it was already enabled before. If
 
@@ -1216,12 +1296,25 @@ void SmallMapWindow::SelectLegendItem(in
 
	} else {
 
		legend[click_pos].show_on_map = !legend[click_pos].show_on_map;
 
	}
 
}
 

	
 
/**
 
 * Set the link graph overlay cargo mask from the legend.
 
 */
 
void SmallMapWindow::SetOverlayCargoMask()
 
{
 
	uint32 cargo_mask = 0;
 
	for (int i = 0; i != _smallmap_cargo_count; ++i) {
 
		if (_legend_linkstats[i].show_on_map) SetBit(cargo_mask, _legend_linkstats[i].type);
 
	}
 
	this->overlay->SetCargoMask(cargo_mask);
 
	this->overlay->RebuildCache();
 
}
 

	
 
/**
 
 * Determines the mouse position on the legend.
 
 * @param pt Mouse position.
 
 * @return Legend item under the mouse.
 
 */
 
int SmallMapWindow::GetPositionOnLegend(Point pt)
 
{
 
@@ -1297,12 +1390,13 @@ int SmallMapWindow::GetPositionOnLegend(
 
			break;
 
		}
 

	
 
		case WID_SM_CONTOUR:    // Show land contours
 
		case WID_SM_VEHICLES:   // Show vehicles
 
		case WID_SM_INDUSTRIES: // Show industries
 
		case WID_SM_LINKSTATS:  // Show route map
 
		case WID_SM_ROUTES:     // Show transport routes
 
		case WID_SM_VEGETATION: // Show vegetation
 
		case WID_SM_OWNERS:     // Show land owners
 
			this->SwitchMapType((SmallMapType)(widget - WID_SM_CONTOUR));
 
			if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
 
			break;
 
@@ -1319,20 +1413,25 @@ int SmallMapWindow::GetPositionOnLegend(
 

	
 
			this->SetDirty();
 
			if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
 
			break;
 

	
 
		case WID_SM_LEGEND: // Legend
 
			if (this->map_type == SMT_INDUSTRY || this->map_type == SMT_OWNER) {
 
			if (this->map_type == SMT_INDUSTRY || this->map_type == SMT_LINKSTATS || this->map_type == SMT_OWNER) {
 
				int click_pos = this->GetPositionOnLegend(pt);
 
				/* If industry type small map*/
 
				if (this->map_type == SMT_INDUSTRY) {
 
					/* If click on industries label, find right industry type and enable/disable it. */
 
					if (click_pos >= 0 && click_pos < _smallmap_industry_count) {
 
						this->SelectLegendItem(click_pos, _legend_from_industries, _smallmap_industry_count);
 
					}
 
				} else if (this->map_type == SMT_LINKSTATS) {
 
					if (click_pos < _smallmap_cargo_count) {
 
						this->SelectLegendItem(click_pos, _legend_linkstats, _smallmap_cargo_count);
 
						this->SetOverlayCargoMask();
 
					}
 
				} else if (this->map_type == SMT_OWNER) {
 
					if (click_pos < _smallmap_company_count) {
 
						this->SelectLegendItem(click_pos, _legend_land_owners, _smallmap_company_count, NUM_NO_COMPANY_ENTRIES);
 
					}
 
				}
 
				this->SetDirty();
 
@@ -1347,18 +1446,22 @@ int SmallMapWindow::GetPositionOnLegend(
 
				case SMT_INDUSTRY:
 
					tbl = _legend_from_industries;
 
					break;
 
				case SMT_OWNER:
 
					tbl = &(_legend_land_owners[NUM_NO_COMPANY_ENTRIES]);
 
					break;
 
				case SMT_LINKSTATS:
 
					tbl = _legend_linkstats;
 
					break;
 
				default:
 
					NOT_REACHED();
 
			}
 
			for (;!tbl->end; ++tbl) {
 
			for (;!tbl->end && tbl->legend != STR_LINKGRAPH_LEGEND_UNUSED; ++tbl) {
 
				tbl->show_on_map = (widget == WID_SM_ENABLE_ALL);
 
			}
 
			if (this->map_type == SMT_LINKSTATS) this->SetOverlayCargoMask();
 
			this->SetDirty();
 
			break;
 
		}
 

	
 
		case WID_SM_SHOW_HEIGHT: // Enable/disable showing of heightmap.
 
			_smallmap_show_heightmap = !_smallmap_show_heightmap;
 
@@ -1422,12 +1525,13 @@ int SmallMapWindow::GetPositionOnLegend(
 

	
 
/* virtual */ void SmallMapWindow::OnTick()
 
{
 
	/* Update the window every now and then */
 
	if (--this->refresh != 0) return;
 

	
 
	if (this->map_type == SMT_LINKSTATS) this->overlay->RebuildCache();
 
	_smallmap_industry_highlight_state = !_smallmap_industry_highlight_state;
 

	
 
	this->refresh = _smallmap_industry_highlight != INVALID_INDUSTRYTYPE ? BLINK_PERIOD : FORCE_REFRESH_PERIOD;
 
	this->SetDirty();
 
}
 

	
 
@@ -1462,12 +1566,13 @@ void SmallMapWindow::SetNewScroll(int sx
 
		sub = 0;
 
	}
 

	
 
	this->scroll_x = sx;
 
	this->scroll_y = sy;
 
	this->subscroll = sub;
 
	if (this->map_type == SMT_LINKSTATS) this->overlay->RebuildCache();
 
}
 

	
 
/* virtual */ void SmallMapWindow::OnScroll(Point delta)
 
{
 
	_cursor.fix_at = true;
 

	
 
@@ -1488,12 +1593,30 @@ void SmallMapWindow::SmallMapCenterOnCur
 
	const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_SM_MAP);
 
	Point sxy = this->ComputeScroll(pt.x / TILE_SIZE, pt.y / TILE_SIZE, max(0, (int)wid->current_x / 2 - 2), wid->current_y / 2, &sub);
 
	this->SetNewScroll(sxy.x, sxy.y, sub);
 
	this->SetDirty();
 
}
 

	
 
/**
 
 * Get the center of the given station as point on the screen in the smallmap window.
 
 * @param st Station to find in the smallmap.
 
 * @return Point with coordinates of the station.
 
 */
 
Point SmallMapWindow::GetStationMiddle(const Station *st) const
 
{
 
	int x = (st->rect.right + st->rect.left + 1) / 2;
 
	int y = (st->rect.bottom + st->rect.top + 1) / 2;
 
	Point ret = this->RemapTile(x, y);
 

	
 
	/* Same magic 3 as in DrawVehicles; that's where I got it from.
 
	 * No idea what it is, but without it the result looks bad.
 
	 */
 
	ret.x -= 3 + this->subscroll;
 
	return ret;
 
}
 

	
 
SmallMapWindow::SmallMapType SmallMapWindow::map_type = SMT_CONTOUR;
 
bool SmallMapWindow::show_towns = true;
 

	
 
/**
 
 * Custom container class for displaying smallmap with a vertically resizing legend panel.
 
 * The legend panel has a smallest height that depends on its width. Standard containers cannot handle this case.
 
@@ -1583,12 +1706,14 @@ static const NWidgetPart _nested_smallma
 
				/* Top button row. */
 
				NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
 
					NWidget(WWT_PUSHIMGBTN, COLOUR_BROWN, WID_SM_ZOOM_IN),
 
							SetDataTip(SPR_IMG_ZOOMIN, STR_TOOLBAR_TOOLTIP_ZOOM_THE_VIEW_IN), SetFill(1, 1),
 
					NWidget(WWT_PUSHIMGBTN, COLOUR_BROWN, WID_SM_CENTERMAP),
 
							SetDataTip(SPR_IMG_SMALLMAP, STR_SMALLMAP_CENTER), SetFill(1, 1),
 
					NWidget(WWT_IMGBTN, COLOUR_BROWN, WID_SM_BLANK),
 
							SetDataTip(SPR_DOT_SMALL, STR_NULL), SetFill(1, 1),
 
					NWidget(WWT_IMGBTN, COLOUR_BROWN, WID_SM_CONTOUR),
 
							SetDataTip(SPR_IMG_SHOW_COUNTOURS, STR_SMALLMAP_TOOLTIP_SHOW_LAND_CONTOURS_ON_MAP), SetFill(1, 1),
 
					NWidget(WWT_IMGBTN, COLOUR_BROWN, WID_SM_VEHICLES),
 
							SetDataTip(SPR_IMG_SHOW_VEHICLES, STR_SMALLMAP_TOOLTIP_SHOW_VEHICLES_ON_MAP), SetFill(1, 1),
 
					NWidget(WWT_IMGBTN, COLOUR_BROWN, WID_SM_INDUSTRIES),
 
							SetDataTip(SPR_IMG_INDUSTRY, STR_SMALLMAP_TOOLTIP_SHOW_INDUSTRIES_ON_MAP), SetFill(1, 1),
 
@@ -1596,12 +1721,14 @@ static const NWidgetPart _nested_smallma
 
				/* Bottom button row. */
 
				NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
 
					NWidget(WWT_PUSHIMGBTN, COLOUR_BROWN, WID_SM_ZOOM_OUT),
 
							SetDataTip(SPR_IMG_ZOOMOUT, STR_TOOLBAR_TOOLTIP_ZOOM_THE_VIEW_OUT), SetFill(1, 1),
 
					NWidget(WWT_IMGBTN, COLOUR_BROWN, WID_SM_TOGGLETOWNNAME),
 
							SetDataTip(SPR_IMG_TOWN, STR_SMALLMAP_TOOLTIP_TOGGLE_TOWN_NAMES_ON_OFF), SetFill(1, 1),
 
					NWidget(WWT_IMGBTN, COLOUR_BROWN, WID_SM_LINKSTATS),
 
							SetDataTip(SPR_IMG_GRAPHS, STR_SMALLMAP_TOOLTIP_SHOW_LINK_STATS_ON_MAP), SetFill(1, 1),
 
					NWidget(WWT_IMGBTN, COLOUR_BROWN, WID_SM_ROUTES),
 
							SetDataTip(SPR_IMG_SHOW_ROUTES, STR_SMALLMAP_TOOLTIP_SHOW_TRANSPORT_ROUTES_ON), SetFill(1, 1),
 
					NWidget(WWT_IMGBTN, COLOUR_BROWN, WID_SM_VEGETATION),
 
							SetDataTip(SPR_IMG_PLANTTREES, STR_SMALLMAP_TOOLTIP_SHOW_VEGETATION_ON_MAP), SetFill(1, 1),
 
					NWidget(WWT_IMGBTN, COLOUR_BROWN, WID_SM_OWNERS),
 
							SetDataTip(SPR_IMG_COMPANY_GENERAL, STR_SMALLMAP_TOOLTIP_SHOW_LAND_OWNERS_ON_MAP), SetFill(1, 1),
 
@@ -1647,13 +1774,13 @@ static const NWidgetPart _nested_smallma
 
		EndContainer(),
 
		NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
 
	EndContainer(),
 
};
 

	
 
static const WindowDesc _smallmap_desc(
 
	WDP_AUTO, 446, 314,
 
	WDP_AUTO, 484, 314,
 
	WC_SMALLMAP, WC_NONE,
 
	0,
 
	_nested_smallmap_widgets, lengthof(_nested_smallmap_widgets)
 
);
 

	
 
/**
src/smallmap_gui.h
Show inline comments
 
@@ -13,14 +13,18 @@
 
#define SMALLMAP_GUI_H
 

	
 
#include "industry_type.h"
 
#include "window_gui.h"
 
#include "strings_func.h"
 
#include "blitter/factory.hpp"
 
#include "linkgraph/linkgraph_gui.h"
 
#include "widgets/smallmap_widget.h"
 

	
 
/* set up the cargos to be displayed in the smallmap's route legend */
 
void BuildLinkStatsLegend();
 

	
 
void BuildIndustriesLegend();
 
void ShowSmallMap();
 
void BuildLandLegend();
 
void BuildOwnerLegend();
 

	
 
/** Structure for holding relevant data for legends in small map */
 
@@ -40,12 +44,13 @@ class SmallMapWindow : public Window {
 
protected:
 
	/** Types of legends in the #WID_SM_LEGEND widget. */
 
	enum SmallMapType {
 
		SMT_CONTOUR,
 
		SMT_VEHICLES,
 
		SMT_INDUSTRY,
 
		SMT_LINKSTATS,
 
		SMT_ROUTES,
 
		SMT_VEGETATION,
 
		SMT_OWNER,
 
	};
 

	
 
	/** Available kinds of zoomlevel changes. */
 
@@ -70,12 +75,13 @@ protected:
 
	int32 scroll_x;  ///< Horizontal world coordinate of the base tile left of the top-left corner of the smallmap display.
 
	int32 scroll_y;  ///< Vertical world coordinate of the base tile left of the top-left corner of the smallmap display.
 
	int32 subscroll; ///< Number of pixels (0..3) between the right end of the base tile and the pixel at the top-left corner of the smallmap display.
 
	int zoom;        ///< Zoom level. Bigger number means more zoom-out (further away).
 

	
 
	uint8 refresh;   ///< Refresh counter, zeroed every FORCE_REFRESH_PERIOD ticks.
 
	LinkGraphOverlay *overlay;
 

	
 
	Point SmallmapRemapCoords(int x, int y) const;
 

	
 
	/**
 
	 * Draws vertical part of map indicator
 
	 * @param x X coord of left/right border of main viewport
 
@@ -141,22 +147,26 @@ protected:
 
	void DrawSmallMap(DrawPixelInfo *dpi) const;
 

	
 
	Point RemapTile(int tile_x, int tile_y) const;
 
	Point PixelToTile(int px, int py, int *sub, bool add_sub = true) const;
 
	Point ComputeScroll(int tx, int ty, int x, int y, int *sub);
 
	void SetZoomLevel(ZoomLevelChange change, const Point *zoom_pt);
 
	void SetOverlayCargoMask();
 
	void SetupWidgetData();
 
	uint32 GetTileColours(const TileArea &ta) const;
 

	
 
	int GetPositionOnLegend(Point pt);
 

	
 
public:
 
	friend class NWidgetSmallmapDisplay;
 

	
 
	SmallMapWindow(const WindowDesc *desc, int window_number);
 
	virtual ~SmallMapWindow() { delete this->overlay; }
 

	
 
	void SmallMapCenterOnCurrentPos();
 
	Point GetStationMiddle(const Station *st) const;
 

	
 
	virtual void SetStringParameters(int widget) const;
 
	virtual void OnInit();
 
	virtual void OnPaint();
 
	virtual void DrawWidget(const Rect &r, int widget) const;
 
	virtual void OnClick(Point pt, int widget, int click_count);
src/widgets/smallmap_widget.h
Show inline comments
 
@@ -15,17 +15,19 @@
 
/** Widgets of the #SmallMapWindow class. */
 
enum SmallMapWidgets {
 
	WID_SM_CAPTION,        ///< Caption of the window.
 
	WID_SM_MAP_BORDER,     ///< Border around the smallmap.
 
	WID_SM_MAP,            ///< Panel containing the smallmap.
 
	WID_SM_LEGEND,         ///< Bottom panel to display smallmap legends.
 
	WID_SM_BLANK,          ///< Empty button as placeholder.
 
	WID_SM_ZOOM_IN,        ///< Button to zoom in one step.
 
	WID_SM_ZOOM_OUT,       ///< Button to zoom out one step.
 
	WID_SM_CONTOUR,        ///< Button to select the contour view (height map).
 
	WID_SM_VEHICLES,       ///< Button to select the vehicles view.
 
	WID_SM_INDUSTRIES,     ///< Button to select the industries view.
 
	WID_SM_LINKSTATS,      ///< Button to select the link stats view.
 
	WID_SM_ROUTES,         ///< Button to select the routes view.
 
	WID_SM_VEGETATION,     ///< Button to select the vegetation view.
 
	WID_SM_OWNERS,         ///< Button to select the owners view.
 
	WID_SM_CENTERMAP,      ///< Button to move smallmap center to main window center.
 
	WID_SM_TOGGLETOWNNAME, ///< Toggle button to display town names.
 
	WID_SM_SELECT_BUTTONS, ///< Selection widget for the buttons present in some smallmap modes.
0 comments (0 inline, 0 general)