Legend hidden by default in smallmap window

This commit is contained in:
pelya
2021-02-06 00:57:11 +02:00
parent 721f61cec9
commit dcacc5850f
3 changed files with 24 additions and 6 deletions

View File

@@ -1078,12 +1078,12 @@ void SmallMapWindow::SetupWidgetData()
SmallMapWindow::SmallMapWindow(WindowDesc *desc, int window_number) :
Window(desc),
row_height(std::max(GetMinSizing(NWST_STEP, FONT_HEIGHT_SMALL) * 2 / 3, uint(FONT_HEIGHT_SMALL))), // Default spacing makes legend too tall - shrink it by 1/3
show_legend(false),
refresh(GUITimer(FORCE_REFRESH_PERIOD))
{
_smallmap_industry_highlight = INVALID_INDUSTRYTYPE;
this->overlay = new LinkGraphOverlay(this, WID_SM_MAP, 0, this->GetOverlayCompanyMask(), 1);
this->InitNested(window_number);
this->LowerWidget(this->map_type + WID_SM_CONTOUR);
this->RebuildColourIndexIfNecessary();
@@ -1458,7 +1458,14 @@ int SmallMapWindow::GetPositionOnLegend(Point pt)
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 (this->map_type == (SmallMapType)(widget - WID_SM_CONTOUR) && this->IsWidgetLowered(widget)) {
this->RaiseWidget(widget);
this->ShowLegend(false);
} else {
this->ShowLegend(true);
this->SwitchMapType((SmallMapType)(widget - WID_SM_CONTOUR));
}
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
break;
@@ -1534,6 +1541,14 @@ int SmallMapWindow::GetPositionOnLegend(Point pt)
}
}
void SmallMapWindow::ShowLegend(bool show)
{
int oldHeight = this->GetLegendHeight(this->min_number_of_columns);
this->show_legend = show;
this->ReInit(0, this->GetLegendHeight(this->min_number_of_columns) - oldHeight);
this->SetDirty();
}
/**
* Some data on this window has become invalid.
* @param data Information about the changed data.
@@ -1783,7 +1798,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(100, 140), SetResize(1, 1), SetPadding(2, 2, 2, 2), EndContainer(),
NWidget(WWT_INSET, COLOUR_BROWN, WID_SM_MAP), SetMinimalSize(346, 140), SetResize(1, 1), SetPadding(2, 2, 2, 2), EndContainer(),
EndContainer(),
};
@@ -1868,7 +1883,7 @@ static const NWidgetPart _nested_smallmap_widgets[] = {
};
static WindowDesc _smallmap_desc(
WDP_AUTO, "smallmap", 180, 180,
WDP_AUTO, "smallmap", 200, 314,
WC_SMALLMAP, WC_NONE,
0,
_nested_smallmap_widgets, lengthof(_nested_smallmap_widgets)

View File

@@ -73,6 +73,7 @@ protected:
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.
const uint row_height; ///< Heigth of each row in the #WID_SM_LEGEND widget.
bool show_legend; ///< Display map legend.
Point lmb_scroll_pt; ///< Starting point for scrolling minimap with left mouse button.
int32 scroll_x; ///< Horizontal world coordinate of the base tile left of the top-left corner of the smallmap display.
@@ -126,6 +127,7 @@ protected:
*/
inline uint GetLegendHeight(uint num_columns) const
{
if (!this->show_legend) return 0;
return WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM +
this->min_number_of_fixed_rows * this->row_height;
}
@@ -177,9 +179,12 @@ public:
*/
inline uint GetMinLegendWidth() const
{
if (!this->show_legend) return 0;
return WD_FRAMERECT_LEFT + this->min_number_of_columns * this->column_width;
}
void ShowLegend(bool show);
void SetStringParameters(int widget) const override;
void OnInit() override;
void OnPaint() override;

View File

@@ -15,8 +15,6 @@
- Cannot click on a depot if scroll mode is set to VSM_VIEWPORT_RMB_FIXED. https://github.com/pelya/openttd-android/issues/3
- Make it possible to hide legend in 'Map of world' window.
- Crash on GRF settings in 'Load game' dialogs and inside the game. https://github.com/pelya/openttd-android/issues/8
- Default tramway button not appearing in vertical toolbar when compact toolbar is disabled. https://github.com/pelya/commandergenius/issues/119