Changeset - r19603:f276b71e816d
[Not reviewed]
master
0 1 0
frosch - 12 years ago 2012-09-19 22:11:26
frosch@openttd.org
(svn r24534) -Feature: Highlight industries on the smallmap when the mouse is over an entry in the legend.
1 file changed with 37 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/smallmap_gui.cpp
Show inline comments
 
@@ -155,12 +155,16 @@ static LegendAndColour _legend_land_owne
 
 */
 
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 and owner mode of smallmap window. */
 
static bool _smallmap_show_heightmap = false;
 
/** Highlight a specific industry type */
 
static IndustryType _smallmap_industry_highlight = INVALID_INDUSTRYTYPE;
 
/** State of highlight blinking */
 
static bool _smallmap_industry_highlight_state;
 
/** For connecting company ID to position in owner list (small map legend) */
 
static uint _company_to_list_pos[MAX_COMPANIES];
 

	
 
/**
 
 * Fills an array for the industries legends.
 
 */
 
@@ -438,14 +442,16 @@ static inline uint32 GetSmallMapVehicles
 
 * @return The colour of tile in the small map in mode "Industries"
 
 */
 
static inline uint32 GetSmallMapIndustriesPixels(TileIndex tile, TileType t)
 
{
 
	if (t == MP_INDUSTRY) {
 
		/* If industry is allowed to be seen, use its colour on the map */
 
		if (_legend_from_industries[_industry_to_list_pos[Industry::GetByTile(tile)->type]].show_on_map) {
 
			return GetIndustrySpec(Industry::GetByTile(tile)->type)->map_colour * 0x01010101;
 
		IndustryType type = Industry::GetByTile(tile)->type;
 
		if (_legend_from_industries[_industry_to_list_pos[type]].show_on_map &&
 
				(_smallmap_industry_highlight_state || type != _smallmap_industry_highlight)) {
 
			return (type == _smallmap_industry_highlight ? PC_WHITE : GetIndustrySpec(Industry::GetByTile(tile)->type)->map_colour) * 0x01010101;
 
		} else {
 
			/* Otherwise, return the colour which will make it disappear */
 
			t = (IsTileOnWater(tile) ? MP_WATER : MP_CLEAR);
 
		}
 
	}
 

	
 
@@ -592,13 +598,14 @@ class SmallMapWindow : public Window {
 

	
 
	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).
 

	
 
	static const uint8 FORCE_REFRESH_PERIOD = 0x1F; ///< map is redrawn after that many ticks
 
	static const uint FORCE_REFRESH_PERIOD = 0x1F; ///< map is redrawn after that many ticks
 
	static const uint BLINK_PERIOD         = 0x0F; ///< highlight blinking interval
 
	uint8 refresh; ///< refresh counter, zeroed every FORCE_REFRESH_PERIOD ticks
 

	
 
	inline Point SmallmapRemapCoords(int x, int y) const
 
	{
 
		Point pt;
 
		pt.x = (y - x) * 2;
 
@@ -1050,12 +1057,13 @@ class SmallMapWindow : public Window {
 

	
 
public:
 
	uint min_number_of_columns;    ///< Minimal number of columns in legends.
 

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

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

	
 
@@ -1199,22 +1207,27 @@ public:
 
						 * (one "row") to the right. */
 
						x += rtl ? -(int)this->column_width : this->column_width;
 
						y = y_org;
 
						i = 1;
 
					}
 

	
 
					uint8 legend_colour = tbl->colour;
 

	
 
					if (this->map_type == SMT_INDUSTRY) {
 
						/* Industry name must be formatted, since it's not in tiny font in the specs.
 
						 * So, draw with a parameter and use the STR_SMALLMAP_INDUSTRY string, which is tiny font */
 
						SetDParam(0, tbl->legend);
 
						SetDParam(1, Industry::GetIndustryTypeCount(tbl->type));
 
						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 */
 
							DrawString(x + text_left, x + text_right, y, STR_SMALLMAP_INDUSTRY, TC_GREY);
 
						} else {
 
							if (tbl->type == _smallmap_industry_highlight) {
 
								legend_colour = _smallmap_industry_highlight_state ? PC_WHITE : PC_BLACK;
 
							}
 
							DrawString(x + text_left, x + text_right, y, STR_SMALLMAP_INDUSTRY, TC_BLACK);
 
							GfxFillRect(x + blob_left, y + 1, x + blob_right, y + row_height - 1, PC_BLACK); // Outer border of the legend colour
 
						}
 
					} else if (this->map_type == SMT_OWNER && tbl->company != INVALID_COMPANY) {
 
						SetDParam(0, tbl->company);
 
						if (!tbl->show_on_map) {
 
@@ -1229,13 +1242,13 @@ public:
 
						if (this->map_type == SMT_CONTOUR) SetDParam(0, tbl->height * TILE_HEIGHT_STEP);
 

	
 
						/* Anything that is not an industry or a company is using normal process */
 
						GfxFillRect(x + blob_left, y + 1, x + blob_right, y + row_height - 1, PC_BLACK);
 
						DrawString(x + text_left, x + text_right, y, tbl->legend);
 
					}
 
					GfxFillRect(x + blob_left + 1, y + 2, x + blob_right - 1, y + row_height - 2, tbl->colour); // Legend colour
 
					GfxFillRect(x + blob_left + 1, y + 2, x + blob_right - 1, y + row_height - 2, legend_colour); // Legend colour
 

	
 
					y += row_height;
 
				}
 
			}
 
		}
 
	}
 
@@ -1273,12 +1286,29 @@ public:
 
		if (rtl) x = wi->current_x - x;
 
		uint column = (x - WD_FRAMERECT_LEFT) / this->column_width;
 

	
 
		return (column * number_of_rows) + line;
 
	}
 

	
 
	virtual void OnMouseOver(Point pt, int widget)
 
	{
 
		IndustryType new_highlight = INVALID_INDUSTRYTYPE;
 
		if (widget == WID_SM_LEGEND && this->map_type == SMT_INDUSTRY) {
 
			int industry_pos = GetPositionOnLegend(pt);
 
			if (industry_pos >= 0 && industry_pos < _smallmap_industry_count) {
 
				new_highlight = _legend_from_industries[industry_pos].type;
 
			}
 
		}
 
		if (new_highlight != _smallmap_industry_highlight) {
 
			_smallmap_industry_highlight = new_highlight;
 
			this->refresh = _smallmap_industry_highlight != INVALID_INDUSTRYTYPE ? BLINK_PERIOD : FORCE_REFRESH_PERIOD;
 
			_smallmap_industry_highlight_state = true;
 
			this->SetDirty();
 
		}
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget, int click_count)
 
	{
 
		/* User clicked something, notify the industry chain window to stop sending newly selected industries. */
 
		InvalidateWindowClassesData(WC_INDUSTRY_CARGOES, NUM_INDUSTRYTYPES);
 

	
 
		switch (widget) {
 
@@ -1486,13 +1516,15 @@ public:
 

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

	
 
		this->refresh = FORCE_REFRESH_PERIOD;
 
		_smallmap_industry_highlight_state = !_smallmap_industry_highlight_state;
 

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

	
 
	/**
 
	 * Set new #scroll_x, #scroll_y, and #subscroll values after limiting them such that the center
 
	 * of the smallmap always contains a part of the map.
0 comments (0 inline, 0 general)