network_gui.c
changeset 734 018e549265ed
parent 722 d0b031be5232
child 735 5c8bacd9fa7e
--- a/network_gui.c	Mon Dec 20 15:26:19 2004 +0000
+++ b/network_gui.c	Mon Dec 20 16:02:01 2004 +0000
@@ -614,6 +614,21 @@
 	WP(w,querystr_d).buf = _edit_str_buf;
 }
 
+static byte NetworkLobbyFindCompanyIndex(byte pos)
+{
+	byte i;
+	/* Scroll through all _network_player_info and get the 'pos' item
+	    that is not empty */
+	for (i = 0; i < MAX_PLAYERS; i++) {
+		if (_network_player_info[i].company_name[0] != '\0') {
+			if (pos-- == 0)
+				return i;
+		}
+	}
+
+	return 0;
+}
+
 static void NetworkLobbyWindowWndProc(Window *w, WindowEvent *e)
 {
 	switch(e->event) {
@@ -638,10 +653,11 @@
 		GfxFillRect(11, 41, 139, 165, 0xD7);
 		pos = w->vscroll.pos;
 		while (pos < _network_lobby_company_count) {
-			if (_selected_company_item == pos)
+			byte index = NetworkLobbyFindCompanyIndex(pos);
+			if (_selected_company_item == index)
 				GfxFillRect(11, y - 1, 139, y + 10, 155); // show highlighted item with a different colour
 
-			DoDrawString(_network_player_info[pos].company_name, 13, y, 2);
+			DoDrawString(_network_player_info[index].company_name, 13, y, 2);
 
 			pos++;
 			y += NET_PRC__SIZE_OF_ROW_COMPANY;
@@ -728,6 +744,8 @@
 				return;
 			}
 
+			_selected_company_item = NetworkLobbyFindCompanyIndex(_selected_company_item);
+
 			SetWindowDirty(w);
 			break;
 		case 7: /* Join company */