Skip to content

Commit dd4e3de

Browse files
committed
Change: Selecting rail/roadtype updates build toolbar
1 parent ba9d673 commit dd4e3de

2 files changed

Lines changed: 40 additions & 3 deletions

File tree

src/rail_gui.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,14 @@ struct BuildRailToolbarWindow : Window {
475475
{
476476
if (!gui_scope) return;
477477

478+
if (_cur_railtype != this->railtype) {
479+
this->ModifyRailType(_cur_railtype);
480+
481+
/* Update cursor and all sub windows. */
482+
if (_thd.GetCallbackWnd() == this) SetCursor(this->GetCursorForWidget(this->last_user_action), PAL_NONE);
483+
for (WindowClass cls : {WindowClass::BuildStation, WindowClass::BuildSignal, WindowClass::BuildWaypoint, WindowClass::BuildDepot}) SetWindowDirty(cls, TransportType::Rail);
484+
}
485+
478486
if (!ValParamRailType(this->railtype)) {
479487
/* Close toolbar if rail type is not available. */
480488
this->Close();
@@ -965,8 +973,14 @@ Window *ShowBuildRailToolbar(RailType railtype)
965973
if (!Company::IsValidID(_local_company)) return nullptr;
966974
if (!ValParamRailType(railtype)) return nullptr;
967975

968-
CloseWindowByClass(WindowClass::BuildToolbar);
969976
_cur_railtype = railtype;
977+
Window *w = BringWindowToFrontById(WindowClass::BuildToolbar, TransportType::Rail);
978+
if (w != nullptr) {
979+
w->OnInvalidateData();
980+
return w;
981+
}
982+
983+
CloseWindowByClass(WindowClass::BuildToolbar);
970984
_remove_button_clicked = false;
971985
return new BuildRailToolbarWindow(_build_rail_desc, railtype);
972986
}

src/road_gui.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)