(svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
authormaedhros
Tue, 06 Feb 2007 15:50:15 +0000
changeset 5946 ae3b1567b5d5
parent 5945 fabc2fee32b3
child 5947 159e7039397a
(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.
src/graph_gui.cpp
--- a/src/graph_gui.cpp	Tue Feb 06 15:38:23 2007 +0000
+++ b/src/graph_gui.cpp	Tue Feb 06 15:50:15 2007 +0000
@@ -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;