@@ -381,6 +381,19 @@ struct BuildRoadToolbarWindow : Window {
381381 {
382382 if (!gui_scope) return ;
383383
384+ if (_cur_roadtype != this ->roadtype ) {
385+ bool close_build_station = this ->ModifyRoadType (_cur_roadtype);
386+
387+ /* Update cursor and all sub windows. */
388+ if (_thd.GetCallbackWnd () == this ) SetCursor (this ->GetCursorForWidget (this ->last_started_action ), PAL_NONE );
389+ for (WindowClass cls : {WindowClass::BuildBusStation, WindowClass::BuildTruckStation, WindowClass::BuildWaypoint, WindowClass::BuildDepot})
390+ SetWindowDirty (cls, TransportType::Road);
391+ if (close_build_station) {
392+ CloseWindowById (WindowClass::BuildBusStation, TransportType::Road);
393+ CloseWindowById (WindowClass::BuildTruckStation, TransportType::Road);
394+ }
395+ }
396+
384397 if (!ValParamRoadType (this ->roadtype )) {
385398 /* Close toolbar if road type is not available. */
386399 this ->Close ();
@@ -435,11 +448,15 @@ struct BuildRoadToolbarWindow : Window {
435448 /* *
436449 * Switch to another road type.
437450 * @param roadtype New road type.
451+ * @return true if new and old are different varieties.
438452 */
439- void ModifyRoadType (RoadType roadtype)
453+ bool ModifyRoadType (RoadType roadtype)
440454 {
455+ bool result = (RoadTypeIsRoad (this ->roadtype ) != RoadTypeIsRoad (roadtype));
456+
441457 this ->roadtype = roadtype;
442458 this ->ReInit ();
459+ return result;
443460 }
444461
445462 std::string GetWidgetString (WidgetID widget, StringID stringid) const override
@@ -1062,9 +1079,15 @@ Window *ShowBuildRoadToolbar(RoadType roadtype)
10621079 if (!Company::IsValidID (_local_company)) return nullptr ;
10631080 if (!ValParamRoadType (roadtype)) return nullptr ;
10641081
1065- CloseWindowByClass (WindowClass::BuildToolbar);
10661082 _cur_roadtype = roadtype;
1083+ Window *w = BringWindowToFrontById (WindowClass::BuildToolbar, TransportType::Road);
1084+
1085+ if (w != nullptr ) {
1086+ w->OnInvalidateData ();
1087+ return w;
1088+ }
10671089
1090+ CloseWindowByClass (WindowClass::BuildToolbar);
10681091 return AllocateWindowDescFront<BuildRoadToolbarWindow>(RoadTypeIsRoad (_cur_roadtype) ? _build_road_desc : _build_tramway_desc, TransportType::Road);
10691092}
10701093
0 commit comments