changeset 5946:1dc5b0b8fe69 draft

(svn r8612) -Fix (r117) [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.
author maedhros <maedhros@openttd.org>
date Tue, 06 Feb 2007 15:50:15 +0000
parents 3fb7f8a4cadf
children 49d640e2f2a7
files src/graph_gui.cpp
diffstat 1 files changed, 30 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/graph_gui.cpp
+++ b/src/graph_gui.cpp
@@ -911,7 +911,7 @@
 
 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 @@
 			// 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 @@
 					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 @@
 			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;