From 822c29e6c231fe6e9d09f24b3ad7c3b2e23f554d Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Fri, 2 Dec 2022 19:40:07 +0000 Subject: [PATCH] Road stops: Auto-select an available type on selecting a class Or on opening the road stop window --- src/road_gui.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/road_gui.cpp b/src/road_gui.cpp index e89e114876..112d7777a2 100644 --- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -1327,6 +1327,8 @@ public: _roadstop_gui_settings.roadstop_class = ROADSTOP_CLASS_DFLT; } + this->SelectFirstAvailableTypeIfUnavailable(); + NWidgetMatrix *matrix = this->GetWidget(WID_BROS_MATRIX); matrix->SetScrollbar(this->vscrollMatrix); matrix->SetCount(_roadstop_gui_settings.roadstop_count); @@ -1390,6 +1392,20 @@ public: } } + void SelectFirstAvailableTypeIfUnavailable() + { + const RoadStopClass *rs_class = RoadStopClass::Get(_roadstop_gui_settings.roadstop_class); + StationType st = GetRoadStationTypeByWindowClass(this->window_class); + + if (IsRoadStopAvailable(rs_class->GetSpec(_roadstop_gui_settings.roadstop_type), st)) return; + for (uint i = 0; i < _roadstop_gui_settings.roadstop_count; i++) { + if (IsRoadStopAvailable(rs_class->GetSpec(i), st)) { + _roadstop_gui_settings.roadstop_type = i; + break; + } + } + } + void OnInvalidateData(int data = 0, bool gui_scope = true) override { if (!gui_scope) return; @@ -1629,9 +1645,10 @@ public: RoadStopClassID class_id = this->roadstop_classes[y]; if (_roadstop_gui_settings.roadstop_class != class_id && GetIfClassHasNewStopsByType(RoadStopClass::Get(class_id), roadStopType, _cur_roadtype)) { _roadstop_gui_settings.roadstop_class = class_id; - RoadStopClass *rsclass = RoadStopClass::Get(_roadstop_gui_settings.roadstop_class); + RoadStopClass *rsclass = RoadStopClass::Get(_roadstop_gui_settings.roadstop_class); _roadstop_gui_settings.roadstop_count = rsclass->GetSpecCount(); _roadstop_gui_settings.roadstop_type = std::min((int)_roadstop_gui_settings.roadstop_type, std::max(0, (int)_roadstop_gui_settings.roadstop_count - 1)); + this->SelectFirstAvailableTypeIfUnavailable(); NWidgetMatrix *matrix = this->GetWidget(WID_BROS_MATRIX); matrix->SetCount(_roadstop_gui_settings.roadstop_count);