| 257 | |
| 258 | public: |
| 259 | BuildAirportWindow(WindowDesc &desc, Window *parent) : PickerWindowBase(desc, parent) |
| 260 | { |
| 261 | this->CreateNestedTree(); |
| 262 | |
| 263 | this->vscroll = this->GetScrollbar(WID_AP_SCROLLBAR); |
| 264 | this->vscroll->SetCapacity(5); |
| 265 | this->vscroll->SetPosition(0); |
| 266 | |
| 267 | this->FinishInitNested(TRANSPORT_AIR); |
| 268 | |
| 269 | this->SetWidgetLoweredState(WID_AP_BTN_DONTHILIGHT, !_settings_client.gui.station_show_coverage); |
| 270 | this->SetWidgetLoweredState(WID_AP_BTN_DOHILIGHT, _settings_client.gui.station_show_coverage); |
| 271 | this->OnInvalidateData(); |
| 272 | |
| 273 | /* Ensure airport class is valid (changing NewGRFs). */ |
| 274 | _selected_airport_class = Clamp(_selected_airport_class, APC_BEGIN, (AirportClassID)(AirportClass::GetClassCount() - 1)); |
| 275 | const AirportClass *ac = AirportClass::Get(_selected_airport_class); |
| 276 | this->vscroll->SetCount(ac->GetSpecCount()); |
| 277 | |
| 278 | /* Ensure the airport index is valid for this class (changing NewGRFs). */ |
| 279 | _selected_airport_index = Clamp(_selected_airport_index, -1, ac->GetSpecCount() - 1); |
| 280 | |
| 281 | /* Only when no valid airport was selected, we want to select the first airport. */ |
| 282 | bool select_first_airport = true; |
| 283 | if (_selected_airport_index != -1) { |
| 284 | const AirportSpec *as = ac->GetSpec(_selected_airport_index); |
| 285 | if (as->IsAvailable()) { |
| 286 | /* Ensure the airport layout is valid. */ |
| 287 | _selected_airport_layout = Clamp(_selected_airport_layout, 0, static_cast<uint8_t>(as->layouts.size() - 1)); |
| 288 | select_first_airport = false; |
| 289 | this->UpdateSelectSize(); |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | if (select_first_airport) this->SelectFirstAvailableAirport(true); |
| 294 | } |
| 295 | |
| 296 | void Close([[maybe_unused]] int data = 0) override |
| 297 | { |
nothing calls this directly
no test coverage detected