# HG changeset patch # User yexo # Date 2009-07-05 16:50:56 # Node ID e6ca8896bfec8fc90e0788931d4588cc05183746 # Parent cb4f3398dff58e02fa3d27a7bfc60df387977a4f (svn r16752) -Codechange: Remove most of the window-changing code from AirportPickerWindow::OnPaint diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp --- a/src/airport_gui.cpp +++ b/src/airport_gui.cpp @@ -207,6 +207,7 @@ public: this->SetWidgetLoweredState(BAW_BTN_DONTHILIGHT, !_settings_client.gui.station_show_coverage); this->SetWidgetLoweredState(BAW_BTN_DOHILIGHT, _settings_client.gui.station_show_coverage); this->LowerWidget(_selected_airport_type + BAW_SMALL_AIRPORT); + this->OnInvalidateData(); if (_settings_game.economy.station_noise_level) { ResizeWindowForWidget(this, BAW_BOTTOMPANEL, 0, 10); @@ -222,27 +223,12 @@ public: virtual void OnPaint() { - int i; // airport enabling loop - uint16 y_noise_offset = 0; - const AirportFTAClass *airport; + this->DrawWidgets(); - this->RaiseWidget(_selected_airport_type + BAW_SMALL_AIRPORT); - if (!GetAirport(AT_SMALL)->IsAvailable() && _selected_airport_type == AT_SMALL) _selected_airport_type = AT_LARGE; - if (!GetAirport(AT_LARGE)->IsAvailable() && _selected_airport_type == AT_LARGE) _selected_airport_type = AT_SMALL; - this->LowerWidget(_selected_airport_type + BAW_SMALL_AIRPORT); - - for (i = 0; i < BAW_AIRPORT_COUNT; i++) this->SetWidgetDisabledState(i + BAW_SMALL_AIRPORT, !GetAirport(i)->IsAvailable()); - - /* select default the coverage area to 'Off' (16) */ - airport = GetAirport(_selected_airport_type); - SetTileSelectSize(airport->size_x, airport->size_y); - + const AirportFTAClass *airport = GetAirport(_selected_airport_type); int rad = _settings_game.station.modified_catchment ? airport->catchment : (uint)CA_UNMODIFIED; - if (_settings_client.gui.station_show_coverage) SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad); - - this->DrawWidgets(); - + uint16 y_noise_offset = 0; /* only show the station (airport) noise, if the noise option is activated */ if (_settings_game.economy.station_noise_level) { /* show the noise of the selected airport */ @@ -261,17 +247,44 @@ public: } } + void SelectOtherAirport(byte airport_id) + { + this->RaiseWidget(_selected_airport_type + BAW_SMALL_AIRPORT); + _selected_airport_type = airport_id; + this->LowerWidget(airport_id + BAW_SMALL_AIRPORT); + + const AirportFTAClass *airport = GetAirport(airport_id); + SetTileSelectSize(airport->size_x, airport->size_y); + + int rad = _settings_game.station.modified_catchment ? airport->catchment : (uint)CA_UNMODIFIED; + if (_settings_client.gui.station_show_coverage) SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad); + + this->SetDirty(); + } + + virtual void OnInvalidateData(int data = 0) + { + if (!GetAirport(_selected_airport_type)->IsAvailable()) { + for (int i = 0; i < BAW_AIRPORT_COUNT; i++) { + if (GetAirport(i)->IsAvailable()) { + this->SelectOtherAirport(i); + break; + } + } + } + for (int i = 0; i < BAW_AIRPORT_COUNT; i++) { + this->SetWidgetDisabledState(i + BAW_SMALL_AIRPORT, !GetAirport(i)->IsAvailable()); + } + } + virtual void OnClick(Point pt, int widget) { switch (widget) { case BAW_SMALL_AIRPORT: case BAW_CITY_AIRPORT: case BAW_HELIPORT: case BAW_METRO_AIRPORT: case BAW_INTERNATIONAL_AIRPORT: case BAW_COMMUTER_AIRPORT: case BAW_HELIDEPOT: case BAW_INTERCONTINENTAL_AIRPORT: case BAW_HELISTATION: - this->RaiseWidget(_selected_airport_type + BAW_SMALL_AIRPORT); - _selected_airport_type = widget - BAW_SMALL_AIRPORT; - this->LowerWidget(_selected_airport_type + BAW_SMALL_AIRPORT); + this->SelectOtherAirport(widget - BAW_SMALL_AIRPORT); SndPlayFx(SND_15_BEEP); - this->SetDirty(); DeleteWindowById(WC_SELECT_STATION, 0); break; diff --git a/src/cheat_gui.cpp b/src/cheat_gui.cpp --- a/src/cheat_gui.cpp +++ b/src/cheat_gui.cpp @@ -98,6 +98,7 @@ static int32 ClickChangeDateCheat(int32 SetDate(ConvertYMDToDate(_cur_year + p2, ymd.month, ymd.day)); EnginesMonthlyLoop(); SetWindowDirty(FindWindowById(WC_STATUS_BAR, 0)); + InvalidateWindowClassesData(WC_BUILD_STATION, 0); ResetSignalVariant(); return _cur_year; } diff --git a/src/date.cpp b/src/date.cpp --- a/src/date.cpp +++ b/src/date.cpp @@ -268,6 +268,7 @@ void IncreaseDate() CompaniesYearlyLoop(); VehiclesYearlyLoop(); TownsYearlyLoop(); + InvalidateWindowClassesData(WC_BUILD_STATION); #ifdef ENABLE_NETWORK if (_network_server) NetworkServerYearlyLoop(); #endif /* ENABLE_NETWORK */