diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp index da300fa977..8188414eb3 100644 --- a/src/graph_gui.cpp +++ b/src/graph_gui.cpp @@ -911,7 +911,7 @@ void ShowCompanyLeagueTable(void) static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e) { - static PlayerID _performance_rating_detail_player = PLAYER_FIRST; + static PlayerID _performance_rating_detail_player = INVALID_PLAYER; switch (e->event) { case WE_PAINT: { @@ -923,6 +923,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 (PlayerID 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 (PlayerID i = PLAYER_FIRST; i < MAX_PLAYERS; i++) { if (!GetPlayer(i)->is_active) { @@ -930,16 +956,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 = PLAYER_FIRST; - } + // We need a repaint SetWindowDirty(w); } - continue; + continue; } // Check if we have the player marked as inactive @@ -1058,8 +1079,7 @@ static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e) w->custom[0] = DAY_TICKS; w->custom[1] = 5; - _performance_rating_detail_player = PLAYER_FIRST; - LowerWindowWidget(w, _performance_rating_detail_player + 13); + if (_performance_rating_detail_player != INVALID_PLAYER) LowerWindowWidget(w, _performance_rating_detail_player + 13); SetWindowDirty(w); break;