Changeset - r16974:f3bbbd7d79ce
[Not reviewed]
master
0 2 0
terkhen - 14 years ago 2011-01-04 20:58:42
terkhen@openttd.org
(svn r21720) -Feature: Allow to toggle visualization of company property in the owner view of the smallmap.
2 files changed with 76 insertions and 6 deletions:
0 comments (0 inline, 0 general)
src/lang/english.txt
Show inline comments
 
@@ -662,12 +662,13 @@ STR_SMALLMAP_TOOLTIP_SHOW_LAND_CONTOURS_
 
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_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_LEGENDA_ROADS                                      :{TINYFONT}{BLACK}Roads
 
STR_SMALLMAP_LEGENDA_RAILROADS                                  :{TINYFONT}{BLACK}Railways
 
STR_SMALLMAP_LEGENDA_STATIONS_AIRPORTS_DOCKS                    :{TINYFONT}{BLACK}Stations/Airports/Docks
 
STR_SMALLMAP_LEGENDA_BUILDINGS_INDUSTRIES                       :{TINYFONT}{BLACK}Buildings/Industries
 
STR_SMALLMAP_LEGENDA_VEHICLES                                   :{TINYFONT}{BLACK}Vehicles
src/smallmap_gui.cpp
Show inline comments
 
@@ -165,12 +165,14 @@ 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 mode of smallmap window. */
 
static bool _smallmap_industry_show_heightmap;
 
/** 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.
 
 */
 
void BuildIndustriesLegend()
 
{
 
@@ -306,12 +308,13 @@ void BuildOwnerLegend()
 
	FOR_ALL_COMPANIES(c) {
 
		_legend_land_owners[i].colour = _colour_gradient[c->colour][5];
 
		_legend_land_owners[i].u.company = c->index;
 
		_legend_land_owners[i].show_on_map = true;
 
		_legend_land_owners[i].col_break = false;
 
		_legend_land_owners[i].end = false;
 
		_company_to_list_pos[c->index] = i;
 
		i++;
 
	}
 

	
 
	/* Terminate the list */
 
	_legend_land_owners[i].end = true;
 

	
 
@@ -536,12 +539,13 @@ static inline uint32 GetSmallMapOwnerPix
 
		/* FIXME: For MP_ROAD there are multiple owners.
 
		 * GetTileOwner returns the rail owner (level crossing) resp. the owner of ROADTYPE_ROAD (normal road),
 
		 * even if there are no ROADTYPE_ROAD bits on the tile.
 
		 */
 
	}
 

	
 
	if (o <= MAX_COMPANIES && !_legend_land_owners[_company_to_list_pos[o]].show_on_map) o = OWNER_NONE;
 
	return _owner_colours[o];
 
}
 

	
 
/** Vehicle colours in #SMT_VEHICLES mode. Indexed by #VehicleTypeByte. */
 
static const byte _vehicle_type_colours[6] = {
 
	184, 191, 152, 15, 215, 184
 
@@ -1000,12 +1004,34 @@ class SmallMapWindow : public Window {
 
		/* Draw map indicators */
 
		this->DrawMapIndicators();
 

	
 
		_cur_dpi = old_dpi;
 
	}
 

	
 
	/**
 
	 * Function to set up widgets depending on the information being shown on the smallmap.
 
	 */
 
	void SetupWidgetData()
 
	{
 
		StringID legend_tooltip;
 
		switch (this->map_type) {
 
			case SMT_INDUSTRY:
 
				legend_tooltip = STR_SMALLMAP_TOOLTIP_INDUSTRY_SELECTION;
 
				break;
 

	
 
			case SMT_OWNER:
 
				legend_tooltip = STR_SMALLMAP_TOOLTIP_COMPANY_SELECTION;
 
				break;
 

	
 
			default:
 
				legend_tooltip = STR_NULL;
 
				break;
 
		}
 
		this->GetWidget<NWidgetCore>(SM_WIDGET_LEGEND)->SetDataTip(STR_NULL, legend_tooltip);
 
	}
 

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

	
 
	SmallMapWindow(const WindowDesc *desc, int window_number) : Window(), refresh(FORCE_REFRESH_PERIOD)
 
	{
 
		this->InitNested(desc, window_number);
 
@@ -1014,14 +1040,14 @@ public:
 
		_smallmap_industry_show_heightmap = false;
 
		BuildLandLegend();
 
		this->SetWidgetLoweredState(SM_WIDGET_SHOW_HEIGHT, _smallmap_industry_show_heightmap);
 

	
 
		this->SetWidgetLoweredState(SM_WIDGET_TOGGLETOWNNAME, this->show_towns);
 
		this->GetWidget<NWidgetStacked>(SM_WIDGET_SELECTINDUSTRIES)->SetDisplayedPlane(this->map_type != SMT_INDUSTRY);
 
		this->GetWidget<NWidgetCore>(SM_WIDGET_LEGEND)->SetDataTip(STR_NULL,
 
				(this->map_type == SMT_INDUSTRY) ? STR_SMALLMAP_TOOLTIP_INDUSTRY_SELECTION : STR_NULL);
 

	
 
		this->SetupWidgetData();
 

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

	
 
	/**
 
@@ -1149,14 +1175,20 @@ public:
 
						} else {
 
							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, 0); // Outer border of the legend colour
 
						}
 
					} else if (this->map_type == SMT_OWNER && tbl->u.company != INVALID_COMPANY) {
 
						SetDParam(0, tbl->u.company);
 
						DrawString(x + text_left, x + text_right, y, STR_SMALLMAP_COMPANY, TC_BLACK);
 
						GfxFillRect(x + blob_left, y + 1, x + blob_right, y + row_height - 1, 0); // Outer border of the legend colour
 
						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_COMPANY, TC_GREY);
 
						} else {
 
							DrawString(x + text_left, x + text_right, y, STR_SMALLMAP_COMPANY, TC_BLACK);
 
							GfxFillRect(x + blob_left, y + 1, x + blob_right, y + row_height - 1, 0); // Outer border of the legend colour
 
						}
 
					} else {
 
						if (this->map_type == SMT_CONTOUR) SetDParam(0, tbl->u.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, 0);
 
						DrawString(x + text_left, x + text_right, y, tbl->legend);
 
@@ -1179,14 +1211,13 @@ public:
 
		this->map_type = map_type;
 
		this->LowerWidget(this->map_type + SM_WIDGET_CONTOUR);
 

	
 
		/* Hide Enable all/Disable all buttons if is not industry type small map */
 
		this->GetWidget<NWidgetStacked>(SM_WIDGET_SELECTINDUSTRIES)->SetDisplayedPlane(this->map_type != SMT_INDUSTRY);
 

	
 
		this->GetWidget<NWidgetCore>(SM_WIDGET_LEGEND)->SetDataTip(STR_NULL,
 
				(this->map_type == SMT_INDUSTRY) ? STR_SMALLMAP_TOOLTIP_INDUSTRY_SELECTION : STR_NULL);
 
		this->SetupWidgetData();
 

	
 
		this->SetDirty();
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget, int click_count)
 
	{
 
@@ -1289,12 +1320,50 @@ public:
 
							}
 
						} else {
 
							_legend_from_industries[industry_pos].show_on_map = !_legend_from_industries[industry_pos].show_on_map;
 
						}
 
					}
 
					this->SetDirty();
 
				} else if (this->map_type == SMT_OWNER) {
 
					/* If click on companies label, find right company and enable/disable it. */
 
					const NWidgetBase *wi = this->GetWidget<NWidgetBase>(SM_WIDGET_LEGEND);
 
					uint line = (pt.y - wi->pos_y - WD_FRAMERECT_TOP) / FONT_HEIGHT_SMALL;
 
					uint columns = this->GetNumberColumnsLegend(wi->current_x);
 
					uint number_of_rows = max(CeilDiv(_smallmap_company_count, columns), this->min_number_of_fixed_rows);
 
					if (line >= number_of_rows) break;
 

	
 
					bool rtl = _current_text_dir == TD_RTL;
 
					int x = pt.x - wi->pos_x;
 
					if (rtl) x = wi->current_x - x;
 
					uint column = (x - WD_FRAMERECT_LEFT) / this->column_width;
 

	
 
					/* Check if click is on company label. */
 
					int company_pos = (column * number_of_rows) + line;
 
					if (company_pos < NUM_NO_COMPANY_ENTRIES) break;
 
					if (company_pos < _smallmap_company_count) {
 
						if (_ctrl_pressed) {
 
							/* Disable all, except the clicked one */
 
							bool changes = false;
 
							for (int i = NUM_NO_COMPANY_ENTRIES; i != _smallmap_company_count; i++) {
 
								bool new_state = i == company_pos;
 
								if (_legend_land_owners[i].show_on_map != new_state) {
 
									changes = true;
 
									_legend_land_owners[i].show_on_map = new_state;
 
								}
 
							}
 
							if (!changes) {
 
								/* Nothing changed? Then show all (again). */
 
								for (int i = NUM_NO_COMPANY_ENTRIES; i != _smallmap_company_count; i++) {
 
									_legend_land_owners[i].show_on_map = true;
 
								}
 
							}
 
						} else {
 
							_legend_land_owners[company_pos].show_on_map = !_legend_land_owners[company_pos].show_on_map;
 
						}
 
					}
 
					this->SetDirty();
 
				}
 
				break;
 

	
 
			case SM_WIDGET_ENABLEINDUSTRIES: // Enable all industries
 
				for (int i = 0; i != _smallmap_industry_count; i++) {
 
					_legend_from_industries[i].show_on_map = true;
0 comments (0 inline, 0 general)