diff --git a/src/lang/english.txt b/src/lang/english.txt index c26a94acae..5e47b35588 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -706,6 +706,7 @@ STR_SMALLMAP_TOOLTIP_SHOW_LAND_OWNERS_ON_MAP :{BLACK}Show lan 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 cargoes except the selected one. Ctrl+Click on it again to enable all cargoes +STR_SMALLMAP_TOOLTIP_SHOW_LEGEND :{BLACK}Show map legend / description of map symbols STR_SMALLMAP_LEGENDA_ROADS :{TINY_FONT}{BLACK}Roads STR_SMALLMAP_LEGENDA_RAILROADS :{TINY_FONT}{BLACK}Railways diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp index 1d566255d6..82e9ae6cb5 100644 --- a/src/smallmap_gui.cpp +++ b/src/smallmap_gui.cpp @@ -1048,7 +1048,8 @@ void SmallMapWindow::SetupWidgetData() SmallMapWindow::SmallMapWindow(WindowDesc *desc, int window_number) : Window(desc), - row_height(GetMinSizing(NWST_STEP, FONT_HEIGHT_SMALL)), + show_legend(false), + row_height(max(GetMinSizing(NWST_STEP, FONT_HEIGHT_SMALL) * 2 / 3, uint(FONT_HEIGHT_SMALL))), // Default spacing makes legend too tall - shrink it by 1/3 refresh(FORCE_REFRESH_PERIOD) { _smallmap_industry_highlight = INVALID_INDUSTRYTYPE; @@ -1417,6 +1418,14 @@ int SmallMapWindow::GetPositionOnLegend(Point pt) if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); break; + case WID_SM_SHOW_LEGEND: { + int oldHeight = this->GetLegendHeight(this->min_number_of_columns); + this->show_legend = !this->show_legend; + this->SetWidgetLoweredState(WID_SM_SHOW_LEGEND, this->show_legend); + this->ReInit(0, this->GetLegendHeight(this->min_number_of_columns) - oldHeight); + break; + } + case WID_SM_LEGEND: // Legend if (this->map_type == SMT_INDUSTRY || this->map_type == SMT_LINKSTATS || this->map_type == SMT_OWNER) { int click_pos = this->GetPositionOnLegend(pt); @@ -1654,7 +1663,7 @@ public: this->smallmap_window = dynamic_cast(w); assert(this->smallmap_window != NULL); - this->smallest_x = max(display->smallest_x, bar->smallest_x + smallmap_window->GetMinLegendWidth()); + this->smallest_x = max(display->smallest_x, max(bar->smallest_x, smallmap_window->GetMinLegendWidth())); this->smallest_y = display->smallest_y + max(bar->smallest_y, smallmap_window->GetLegendHeight(smallmap_window->min_number_of_columns)); this->fill_x = max(display->fill_x, bar->fill_x); this->fill_y = (display->fill_y == 0 && bar->fill_y == 0) ? 0 : min(display->fill_y, bar->fill_y); @@ -1705,7 +1714,7 @@ public: /** Widget parts of the smallmap display. */ static const NWidgetPart _nested_smallmap_display[] = { NWidget(WWT_PANEL, COLOUR_BROWN, WID_SM_MAP_BORDER), - NWidget(WWT_INSET, COLOUR_BROWN, WID_SM_MAP), SetMinimalSize(346, 140), SetResize(1, 1), SetPadding(2, 2, 2, 2), EndContainer(), + NWidget(WWT_INSET, COLOUR_BROWN, WID_SM_MAP), SetMinimalSize(140, 140), SetResize(1, 1), SetPadding(2, 2, 2, 2), EndContainer(), EndContainer(), }; @@ -1713,27 +1722,23 @@ static const NWidgetPart _nested_smallmap_display[] = { static const NWidgetPart _nested_smallmap_bar[] = { NWidget(WWT_PANEL, COLOUR_BROWN), NWidget(NWID_HORIZONTAL), - NWidget(WWT_EMPTY, INVALID_COLOUR, WID_SM_LEGEND), SetResize(1, 1), - NWidget(NWID_VERTICAL), + NWidget(NWID_HORIZONTAL), /* Top button row. */ NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), + NWidget(WWT_IMGBTN, COLOUR_BROWN, WID_SM_SHOW_LEGEND), + SetDataTip(SPR_IMG_QUERY, STR_SMALLMAP_TOOLTIP_SHOW_LEGEND), SetFill(1, 1), 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_ZOOM_OUT), + SetDataTip(SPR_IMG_ZOOMOUT, STR_TOOLBAR_TOOLTIP_ZOOM_THE_VIEW_OUT), 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), - EndContainer(), - /* 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), @@ -1748,6 +1753,7 @@ static const NWidgetPart _nested_smallmap_bar[] = { NWidget(NWID_SPACER), SetResize(0, 1), EndContainer(), EndContainer(), + NWidget(WWT_EMPTY, INVALID_COLOUR, WID_SM_LEGEND), SetResize(1, 1), EndContainer(), }; @@ -1790,7 +1796,7 @@ static const NWidgetPart _nested_smallmap_widgets[] = { }; static WindowDesc _smallmap_desc( - WDP_AUTO, "smallmap", 484, 314, + WDP_AUTO, "smallmap", 180, 180, WC_SMALLMAP, WC_NONE, 0, _nested_smallmap_widgets, lengthof(_nested_smallmap_widgets) diff --git a/src/smallmap_gui.h b/src/smallmap_gui.h index d54969d915..03769d45d0 100644 --- a/src/smallmap_gui.h +++ b/src/smallmap_gui.h @@ -69,6 +69,7 @@ protected: static const uint FORCE_REFRESH_PERIOD = 0x1F; ///< map is redrawn after that many ticks static const uint BLINK_PERIOD = 0x0F; ///< highlight blinking interval + bool show_legend; ///< Display legend. uint min_number_of_columns; ///< Minimal number of columns in legends. uint min_number_of_fixed_rows; ///< Minimal number of rows in the legends for the fixed layouts only (all except #SMT_INDUSTRY). uint column_width; ///< Width of a column in the #WID_SM_LEGEND widget. @@ -114,7 +115,7 @@ protected: */ inline uint GetMinLegendWidth() const { - return WD_FRAMERECT_LEFT + this->min_number_of_columns * this->column_width; + return show_legend ? WD_FRAMERECT_LEFT + this->min_number_of_columns * this->column_width : 0; } /** @@ -123,7 +124,7 @@ protected: */ inline uint GetNumberColumnsLegend(uint width) const { - return width / this->column_width; + return max(2u, width / this->column_width); } /** @@ -133,8 +134,8 @@ protected: */ inline uint GetLegendHeight(uint num_columns) const { - return WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + - this->GetNumberRowsLegend(num_columns) * this->row_height; + return show_legend ? WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + + this->GetNumberRowsLegend(num_columns) * this->row_height : 0; } /** diff --git a/src/widgets/smallmap_widget.h b/src/widgets/smallmap_widget.h index 0b1daea03f..753dcb74e3 100644 --- a/src/widgets/smallmap_widget.h +++ b/src/widgets/smallmap_widget.h @@ -34,6 +34,7 @@ enum SmallMapWidgets { WID_SM_ENABLE_ALL, ///< Button to enable display of all legend entries. WID_SM_DISABLE_ALL, ///< Button to disable display of all legend entries. WID_SM_SHOW_HEIGHT, ///< Show heightmap toggle button. + WID_SM_SHOW_LEGEND, ///< Show/hide legend area. }; #endif /* WIDGETS_SMALLMAP_WIDGET_H */