Fix industry chain window not always updating map-mode viewports

This commit is contained in:
Jonathan G Rennison
2022-05-10 18:29:06 +01:00
parent 5c2fb5c160
commit 8eb0609541
3 changed files with 28 additions and 26 deletions

View File

@@ -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<NUM_INDUSTRYTYPES> _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<NUM_INDUSTRYTYPES> _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;
}