diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index dcb3280df3..8a9c772df2 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -2748,16 +2748,7 @@ struct IndustryCargoesWindow : public Window { { if (!this->IsWidgetLowered(WID_IC_NOTIFY)) return; - /* Only notify the smallmap window if it exists. In particular, do not - * bring it to the front to prevent messing up any nice layout of the user. */ - InvalidateWindowClassesData(WC_SMALLMAP, 0); - - /* Notify viewports too. */ - for (Window *w : Window::IterateFromBack()) { - if (w->viewport != nullptr) - if (w->viewport->zoom >= ZOOM_LVL_DRAW_MAP && w->viewport->map_type == VPMT_INDUSTRY) - w->InvalidateData(); - } + UpdateSmallMapSelectedIndustries(); } /** diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp index 1026fc3cbc..f4b620abae 100644 --- a/src/smallmap_gui.cpp +++ b/src/smallmap_gui.cpp @@ -165,6 +165,32 @@ static bool _smallmap_industry_highlight_state; /** For connecting company ID to position in owner list (small map legend) */ uint _company_to_list_pos[MAX_COMPANIES]; +static void NotifyAllViewports(ViewportMapType map_type) +{ + for (Window *w : Window::IterateFromBack()) { + if (w->viewport != nullptr) { + if (w->viewport->zoom >= ZOOM_LVL_DRAW_MAP && w->viewport->map_type == map_type) { + ClearViewportLandPixelCache(w->viewport); + w->InvalidateData(); + } + } + } +} + +void UpdateSmallMapSelectedIndustries() +{ + extern std::bitset _displayed_industries; + for (int i = 0; i != _smallmap_industry_count; i++) { + _legend_from_industries[i].show_on_map = _displayed_industries.test(_legend_from_industries[i].type); + } + + NotifyAllViewports(VPMT_INDUSTRY); + + /* Only notify the smallmap window if it exists. In particular, do not + * bring it to the front to prevent messing up any nice layout of the user. */ + InvalidateWindowClassesData(WC_SMALLMAP, 0); +} + /** * Fills an array for the industries legends. */ @@ -592,17 +618,6 @@ static inline uint32 GetSmallMapOwnerPixels(TileIndex tile, TileType t) return MKCOLOUR_XXXX(_legend_land_owners[_company_to_list_pos[o]].colour); } -static void NotifyAllViewports(ViewportMapType map_type) -{ - for (Window *w : Window::IterateFromBack()) { - if (w->viewport != nullptr) - if (w->viewport->zoom >= ZOOM_LVL_DRAW_MAP && w->viewport->map_type == map_type) { - ClearViewportLandPixelCache(w->viewport); - w->InvalidateData(); - } - } -} - /** Vehicle colours in #SMT_VEHICLES mode. Indexed by #VehicleType. */ static const byte _vehicle_type_colours[6] = { PC_RED, PC_YELLOW, PC_LIGHT_BLUE, PC_WHITE, PC_BLACK, PC_RED @@ -1571,12 +1586,7 @@ int SmallMapWindow::GetPositionOnLegend(Point pt) break; case 0: { - extern std::bitset _displayed_industries; if (this->map_type != SMT_INDUSTRY) this->SwitchMapType(SMT_INDUSTRY); - - for (int i = 0; i != _smallmap_industry_count; i++) { - _legend_from_industries[i].show_on_map = _displayed_industries.test(_legend_from_industries[i].type); - } break; } diff --git a/src/smallmap_gui.h b/src/smallmap_gui.h index c76aecc4cf..5a5e13c9e7 100644 --- a/src/smallmap_gui.h +++ b/src/smallmap_gui.h @@ -46,6 +46,7 @@ struct TunnelBridgeToMap { }; typedef std::vector TunnelBridgeToMapVector; +void UpdateSmallMapSelectedIndustries(); void BuildIndustriesLegend(); void ShowSmallMap(); void BuildLandLegend();