From 61b95ff1fc7b6d80495e226cc28a047cafa65ac9 Mon Sep 17 00:00:00 2001 From: rubidium Date: Thu, 8 Feb 2007 11:03:00 +0000 Subject: [PATCH] (svn r8627) [0.5] -Backport from trunk (8409, 8420 + 8421, 8533, 8612): -Regression: When the latest news was deleted, the news queue wrapped back to the oldest item, showing all news again. -Regression [FS#573]: ShowLastNewsMessage could show an out-of-bounds news item because it did not checked if a previous item actually existed the first time it is called (forced news is INVALID_NEWS). -Codechange: Rename the 'New ' button of the global vehicle lists to 'Available ' as it is a view-only list, not one from which you can purchase (rolling) stock. -Fix: segmentation fault when the toolbar gets removed and you have selected one of the items in a submenu of the toolbar. -Fix [FS#582]: When the currently selected player in the performance details window is no longer active, choose the first active player instead of the first player as that may also be inactive. --- graph_gui.c | 40 ++++++++++++++++++++++++++++++---------- lang/english.txt | 4 ++++ news_gui.c | 10 ++++++---- openttd.h | 3 +++ vehicle_gui.c | 16 ++++++++-------- window.c | 1 + 6 files changed, 52 insertions(+), 22 deletions(-) diff --git a/graph_gui.c b/graph_gui.c index 50eb932d9d..06a9d29d00 100644 --- a/graph_gui.c +++ b/graph_gui.c @@ -906,7 +906,7 @@ void ShowCompanyLeagueTable(void) static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e) { - static PlayerID _performance_rating_detail_player = 0; + static PlayerID _performance_rating_detail_player = INVALID_PLAYER; switch (e->event) { case WE_PAINT: { @@ -919,6 +919,32 @@ static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e) // Draw standard stuff DrawWindowWidgets(w); + /* Check if the currently selected player is still active. */ + if (_performance_rating_detail_player == INVALID_PLAYER || !GetPlayer(_performance_rating_detail_player)->is_active) { + if (_performance_rating_detail_player != INVALID_PLAYER) { + /* Raise and disable the widget for the previous selection. */ + RaiseWindowWidget(w, _performance_rating_detail_player + 13); + DisableWindowWidget(w, _performance_rating_detail_player + 13); + SetWindowDirty(w); + + _performance_rating_detail_player = INVALID_PLAYER; + } + + for (i = PLAYER_FIRST; i < MAX_PLAYERS; i++) { + if (GetPlayer(i)->is_active) { + /* Lower the widget corresponding to this player. */ + LowerWindowWidget(w, i + 13); + SetWindowDirty(w); + + _performance_rating_detail_player = i; + break; + } + } + } + + /* If there are no active players, don't display anything else. */ + if (_performance_rating_detail_player == INVALID_PLAYER) break; + // Paint the player icons for (i = 0; i < MAX_PLAYERS; i++) { if (!GetPlayer(i)->is_active) { @@ -926,16 +952,11 @@ static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e) if (!IsWindowWidgetDisabled(w, i + 13)) { // Bah, player gone :( DisableWindowWidget(w, i + 13); - // Is this player selected? If so, select first player (always save? :s) - if (IsWindowWidgetLowered(w, i + 13)) { - RaiseWindowWidget(w, i + 13); - LowerWindowWidget(w, 13); - _performance_rating_detail_player = 0; - } + // We need a repaint SetWindowDirty(w); } - continue; + continue; } // Check if we have the player marked as inactive @@ -1054,8 +1075,7 @@ static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e) w->custom[0] = DAY_TICKS; w->custom[1] = 5; - _performance_rating_detail_player = 0; - LowerWindowWidget(w, _performance_rating_detail_player + 13); + if (_performance_rating_detail_player != INVALID_PLAYER) LowerWindowWidget(w, _performance_rating_detail_player + 13); SetWindowDirty(w); break; diff --git a/lang/english.txt b/lang/english.txt index 6fb99f1c3d..36b10b228e 100644 --- a/lang/english.txt +++ b/lang/english.txt @@ -394,6 +394,10 @@ STR_ENGINE_SORT_CARGO_CAPACITY :Cargo Capacity STR_NO_WAITING_CARGO :{BLACK}No cargo of any type is waiting STR_SELECT_ALL_FACILITIES :{BLACK}Select all facilities STR_SELECT_ALL_TYPES :{BLACK}Select all cargo types (including no waiting cargo) +STR_AVAILABLE_TRAINS :{BLACK}Available Trains +STR_AVAILABLE_ROAD_VEHICLES :{BLACK}Available Vehicles +STR_AVAILABLE_SHIPS :{BLACK}Available Ships +STR_AVAILABLE_AIRCRAFT :{BLACK}Available Aircraft STR_AVAILABLE_ENGINES_TIP :{BLACK}See a list of available engine designs for this vehicle type. STR_MANAGE_LIST :{BLACK}Manage list STR_MANAGE_LIST_TIP :{BLACK}Send instructions to all vehicles in this list diff --git a/news_gui.c b/news_gui.c index 2f25f894a7..8c521d4c23 100644 --- a/news_gui.c +++ b/news_gui.c @@ -558,7 +558,7 @@ void ShowLastNewsMessage(void) /* Not forced any news yet, show the current one, unless a news window is * open (which can only be the current one), then show the previous item */ const Window *w = FindWindowById(WC_NEWS_WINDOW, 0); - ShowNewsMessage((w == NULL) ? _current_news : decreaseIndex(_current_news)); + ShowNewsMessage((w == NULL || (_current_news == _oldest_news)) ? _current_news : decreaseIndex(_current_news)); } else if (_forced_news == _oldest_news) { /* We have reached the oldest news, start anew with the latest */ ShowNewsMessage(_latest_news); @@ -918,9 +918,11 @@ void DeleteVehicleNews(VehicleID vid, StringID news) for (i = n;; i = decreaseIndex(i)) { _news_items[i] = _news_items[decreaseIndex(i)]; - if (i == _current_news) _current_news = increaseIndex(_current_news); - if (i == _forced_news) _forced_news = increaseIndex(_forced_news); - if (i == visible_news) WP(w, news_d).ni = &_news_items[increaseIndex(visible_news)]; + if (i != _latest_news) { + if (i == _current_news) _current_news = increaseIndex(_current_news); + if (i == _forced_news) _forced_news = increaseIndex(_forced_news); + if (i == visible_news) WP(w, news_d).ni = &_news_items[increaseIndex(visible_news)]; + } if (i == _oldest_news) break; } diff --git a/openttd.h b/openttd.h index 277b3690be..e872a03cbb 100644 --- a/openttd.h +++ b/openttd.h @@ -83,6 +83,9 @@ typedef byte WindowClass; enum { INVALID_YEAR = -1, INVALID_DATE = -1, + + PLAYER_FIRST = 0x00, + INVALID_PLAYER = 0xFF, }; typedef int32 Year; diff --git a/vehicle_gui.c b/vehicle_gui.c index 758791dc37..2ad87d5574 100644 --- a/vehicle_gui.c +++ b/vehicle_gui.c @@ -1400,7 +1400,7 @@ enum VehicleListWindowWidgets { VLW_WIDGET_LIST, VLW_WIDGET_SCROLLBAR, VLW_WIDGET_OTHER_PLAYER_FILLER, - VLW_WIDGET_NEW_VEHICLES, + VLW_WIDGET_AVAILABLE_VEHICLES, VLW_WIDGET_MANAGE_VEHICLES, VLW_WIDGET_MANAGE_VEHICLES_DROPDOWN, VLW_WIDGET_STOP_ALL, @@ -1448,10 +1448,10 @@ static void CreateVehicleListWindow(Window *w) * Some windows contains actions only fit for the owner */ if (player == _local_player) { HideWindowWidget(w, VLW_WIDGET_OTHER_PLAYER_FILLER); - SetWindowWidgetDisabledState(w, VLW_WIDGET_NEW_VEHICLES, window_type != VLW_STANDARD); + SetWindowWidgetDisabledState(w, VLW_WIDGET_AVAILABLE_VEHICLES, window_type != VLW_STANDARD); } else { SetWindowWidgetsHiddenState(w, true, - VLW_WIDGET_NEW_VEHICLES, + VLW_WIDGET_AVAILABLE_VEHICLES, VLW_WIDGET_MANAGE_VEHICLES, VLW_WIDGET_MANAGE_VEHICLES_DROPDOWN, VLW_WIDGET_STOP_ALL, @@ -1464,22 +1464,22 @@ static void CreateVehicleListWindow(Window *w) switch (vl->vehicle_type) { case VEH_Train: w->widget[VLW_WIDGET_LIST].tooltips = STR_883D_TRAINS_CLICK_ON_TRAIN_FOR; - w->widget[VLW_WIDGET_NEW_VEHICLES].data = STR_8815_NEW_VEHICLES; + w->widget[VLW_WIDGET_AVAILABLE_VEHICLES].data = STR_AVAILABLE_TRAINS; break; case VEH_Road: w->widget[VLW_WIDGET_LIST].tooltips = STR_901A_ROAD_VEHICLES_CLICK_ON; - w->widget[VLW_WIDGET_NEW_VEHICLES].data = STR_9004_NEW_VEHICLES; + w->widget[VLW_WIDGET_AVAILABLE_VEHICLES].data = STR_AVAILABLE_ROAD_VEHICLES; break; case VEH_Ship: w->widget[VLW_WIDGET_LIST].tooltips = STR_9823_SHIPS_CLICK_ON_SHIP_FOR; - w->widget[VLW_WIDGET_NEW_VEHICLES].data = STR_9804_NEW_SHIPS; + w->widget[VLW_WIDGET_AVAILABLE_VEHICLES].data = STR_AVAILABLE_SHIPS; break; case VEH_Aircraft: w->widget[VLW_WIDGET_LIST].tooltips = STR_A01F_AIRCRAFT_CLICK_ON_AIRCRAFT; - w->widget[VLW_WIDGET_NEW_VEHICLES].data = STR_A003_NEW_AIRCRAFT; + w->widget[VLW_WIDGET_AVAILABLE_VEHICLES].data = STR_AVAILABLE_AIRCRAFT; break; default: NOT_REACHED(); @@ -1742,7 +1742,7 @@ void PlayerVehWndProc(Window *w, WindowEvent *e) } } break; - case VLW_WIDGET_NEW_VEHICLES: + case VLW_WIDGET_AVAILABLE_VEHICLES: switch (vl->vehicle_type) { case VEH_Train: ShowBuildTrainWindow(0); break; case VEH_Road: ShowBuildRoadVehWindow(0); break; diff --git a/window.c b/window.c index 2dd12169f4..d8fe2c3120 100644 --- a/window.c +++ b/window.c @@ -1870,6 +1870,7 @@ restart_search: /* Delete all always on-top windows to get an empty screen */ void HideVitalWindows(void) { + DeleteWindowById(WC_TOOLBAR_MENU, 0); DeleteWindowById(WC_MAIN_TOOLBAR, 0); DeleteWindowById(WC_STATUS_BAR, 0); }