summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2014-08-15 19:41:57 +0000
committerrubidium <rubidium@openttd.org>2014-08-15 19:41:57 +0000
commit03551d2b354b367f57931a658653a17c51004aed (patch)
tree6efc87199830cc4525c23f0fd7501f8b5f4cb6f7
parentcee3a4861ce9f64bb2b9c495b46b8d8d71bc27f2 (diff)
downloadopenttd-03551d2b354b367f57931a658653a17c51004aed.tar.xz
(svn r26732) -Fix [FS#6083]: do not reset the last selected airport or layout (unless it is really necessary)
-rw-r--r--src/airport_gui.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp
index 761466f1a..b4c056d50 100644
--- a/src/airport_gui.cpp
+++ b/src/airport_gui.cpp
@@ -228,8 +228,27 @@ public:
this->SetWidgetLoweredState(WID_AP_BTN_DOHILIGHT, _settings_client.gui.station_show_coverage);
this->OnInvalidateData();
- this->vscroll->SetCount(AirportClass::Get(_selected_airport_class)->GetSpecCount());
- this->SelectFirstAvailableAirport(true);
+ /* Ensure airport class is valid (changing NewGRFs). */
+ _selected_airport_class = Clamp(_selected_airport_class, APC_BEGIN, (AirportClassID)(AirportClass::GetClassCount() - 1));
+ const AirportClass *ac = AirportClass::Get(_selected_airport_class);
+ this->vscroll->SetCount(ac->GetSpecCount());
+
+ /* Ensure the airport index is valid for this class (changing NewGRFs). */
+ _selected_airport_index = Clamp(_selected_airport_index, -1, ac->GetSpecCount() - 1);
+
+ /* Only when no valid airport was selected, we want to select the first airport. */
+ bool selectFirstAirport = true;
+ if (_selected_airport_index != -1) {
+ const AirportSpec *as = ac->GetSpec(_selected_airport_index);
+ if (as->IsAvailable()) {
+ /* Ensure the airport layout is valid. */
+ _selected_airport_layout = Clamp(_selected_airport_layout, 0, as->num_table - 1);
+ selectFirstAirport = false;
+ this->UpdateSelectSize();
+ }
+ }
+
+ if (selectFirstAirport) this->SelectFirstAvailableAirport(true);
}
virtual ~BuildAirportWindow()