MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / BuildAirportWindow

Method BuildAirportWindow

src/airport_gui.cpp:259–294  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

257
258public:
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 {

Callers

nothing calls this directly

Calls 15

UpdateSelectSizeMethod · 0.95
ClampFunction · 0.85
CreateNestedTreeMethod · 0.80
GetScrollbarMethod · 0.80
SetCapacityMethod · 0.80
SetPositionMethod · 0.80
FinishInitNestedMethod · 0.80
SetWidgetLoweredStateMethod · 0.80
GetSpecCountMethod · 0.80
OnInvalidateDataMethod · 0.45
SetCountMethod · 0.45

Tested by

no test coverage detected