src/network/network_gui.cpp
branchNewGRF_ports
changeset 6871 5a9dc001e1ad
parent 6870 ca3fd1fbe311
child 6872 1c4a4a609f85
--- a/src/network/network_gui.cpp	Sat Oct 06 21:16:00 2007 +0000
+++ b/src/network/network_gui.cpp	Mon Dec 03 23:39:38 2007 +0000
@@ -209,18 +209,51 @@
 	nqld->l.flags &= ~VL_RESORT;
 }
 
-/* Uses network_ql_d (network_d, querystr_d and list_d) WP macro */
+/** Enum for NetworkGameWindow, referring to _network_game_window_widgets */
+enum NetworkGameWindowWidgets {
+	NGWW_CLOSE    = 0,  ///< Close 'X' button
+	NGWW_CONN_TXT = 4,  ///< 'Connection' droplist
+	NGWW_CONN_BTN = 5,  ///< 'Connection' droplist button
+	NGWW_PLAYER   = 6,  ///< Panel with editbox to set player name
+
+	NGWW_NAME     = 7,  ///< 'Name' button
+	NGWW_CLIENTS,       ///< 'Clients' button
+	NGWW_INFO,          ///< Third button in the game list panel
+
+	NGWW_MATRIX   = 10, ///< Panel with list of games
+
+	NGWW_DETAILS  = 12, ///< Panel with game details
+	NGWW_JOIN     = 13, ///< 'Join game' button
+	NGWW_REFRESH  = 14, ///< 'Refresh server' button
+	NGWW_NEWGRF   = 15, ///< 'NewGRF Settings' button
+
+	NGWW_FIND     = 16, ///< 'Find server' button
+	NGWW_ADD,           ///< 'Add server' button
+	NGWW_START,         ///< 'Start server' button
+	NGWW_CANCEL,        ///< 'Cancel' button
+};
+
+/**
+ * Handler of actions done in the NetworkStartServer window
+ *
+ * @param w pointer to the Window structure
+ * @param e pointer to window event
+ * @note    Uses network_ql_d (network_d, querystr_d and list_d) WP macro
+ * @see     struct _network_game_window_widgets
+ * @see     enum NetworkGameWindowWidgets
+ */
+
 static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
 {
 	network_d *nd = &WP(w, network_ql_d).n;
 	list_d *ld = &WP(w, network_ql_d).l;
 
 	switch (e->event) {
-	case WE_CREATE: /* Focus input box */
+	case WE_CREATE: // Focus input box
 		w->vscroll.cap = 13;
 		w->resize.step_height = NET_PRC__SIZE_OF_ROW;
 
-		nd->field = 3;
+		nd->field = NGWW_PLAYER;
 		nd->server = NULL;
 
 		WP(w, network_ql_d).sort_list = NULL;
@@ -238,14 +271,16 @@
 		}
 		if (ld->flags & VL_RESORT) SortNetworkGameList(&WP(w, network_ql_d));
 
-		SetWindowWidgetDisabledState(w, 17, sel == NULL);
-		/* Join Button disabling conditions */
-		SetWindowWidgetDisabledState(w, 16, sel == NULL || // no Selected Server
+		/* 'Refresh' button invisible if no server selected */
+		w->SetWidgetDisabledState(NGWW_REFRESH, sel == NULL);
+		/* 'Join' button disabling conditions */
+		w->SetWidgetDisabledState(NGWW_JOIN, sel == NULL || // no Selected Server
 				!sel->online || // Server offline
 				sel->info.clients_on >= sel->info.clients_max || // Server full
 				!sel->info.compatible); // Revision mismatch
 
-		SetWindowWidgetHiddenState(w, 18, sel == NULL ||
+		/* 'NewGRF Settings' button invisible if no NewGRF is used */
+		w->SetWidgetHiddenState(NGWW_NEWGRF, sel == NULL ||
 				!sel->online ||
 				sel->info.grfconfig == NULL);
 
@@ -253,23 +288,23 @@
 		SetDParam(1, _lan_internet_types_dropdown[_network_lan_internet]);
 		DrawWindowWidgets(w);
 
-		DrawEditBox(w, &WP(w, network_ql_d).q, 3);
+		/* Edit box to set player name */
+		DrawEditBox(w, &WP(w, network_ql_d).q, NGWW_PLAYER);
 
-		DrawString(9, 23, STR_NETWORK_CONNECTION, 2);
-		DrawString(w->widget[3].left - 100, 23, STR_NETWORK_PLAYER_NAME, 2);
+		DrawString(w->widget[NGWW_PLAYER].left - 100, 23, STR_NETWORK_PLAYER_NAME, TC_GOLD);
 
 		/* Sort based on widgets: name, clients, compatibility */
 		switch (ld->sort_type) {
-			case 6 - 6: DoDrawString(arrow, w->widget[6].right - 10, 42, 0x10); break;
-			case 7 - 6: DoDrawString(arrow, w->widget[7].right - 10, 42, 0x10); break;
-			case 8 - 6: DoDrawString(arrow, w->widget[8].right - 10, 42, 0x10); break;
+			case NGWW_NAME    - NGWW_NAME: DoDrawString(arrow, w->widget[NGWW_NAME].right    - 10, 42, TC_BLACK); break;
+			case NGWW_CLIENTS - NGWW_NAME: DoDrawString(arrow, w->widget[NGWW_CLIENTS].right - 10, 42, TC_BLACK); break;
+			case NGWW_INFO    - NGWW_NAME: DoDrawString(arrow, w->widget[NGWW_INFO].right    - 10, 42, TC_BLACK); break;
 		}
 
 		{ // draw list of games
 			uint16 y = NET_PRC__OFFSET_TOP_WIDGET + 3;
 			int32 n = 0;
 			int32 pos = w->vscroll.pos;
-			uint max_name_width = w->widget[6].right - w->widget[6].left - 5;
+			uint max_name_width = w->widget[NGWW_NAME].right - w->widget[NGWW_NAME].left - 5;
 			const NetworkGameList *cur_item = _network_game_list;
 
 			while (pos > 0 && cur_item != NULL) {
@@ -278,28 +313,28 @@
 			}
 
 			while (cur_item != NULL) {
-				// show highlighted item with a different colour
-				if (cur_item == sel) GfxFillRect(w->widget[6].left + 1, y - 2, w->widget[8].right - 1, y + 9, 10);
+				/* show highlighted item with a different colour */
+				if (cur_item == sel) GfxFillRect(w->widget[NGWW_NAME].left + 1, y - 2, w->widget[NGWW_INFO].right - 1, y + 9, 10);
 
 				SetDParamStr(0, cur_item->info.server_name);
-				DrawStringTruncated(w->widget[6].left + 5, y, STR_02BD, 16, max_name_width);
+				DrawStringTruncated(w->widget[NGWW_NAME].left + 5, y, STR_02BD, TC_BLACK, max_name_width);
 
 				SetDParam(0, cur_item->info.clients_on);
 				SetDParam(1, cur_item->info.clients_max);
 				SetDParam(2, cur_item->info.companies_on);
 				SetDParam(3, cur_item->info.companies_max);
-				DrawStringCentered(w->widget[7].left + 39, y, STR_NETWORK_GENERAL_ONLINE, 2);
+				DrawStringCentered(w->widget[NGWW_CLIENTS].left + 39, y, STR_NETWORK_GENERAL_ONLINE, TC_GOLD);
 
-				// only draw icons if the server is online
+				/* only draw icons if the server is online */
 				if (cur_item->online) {
-					// draw a lock if the server is password protected.
-					if (cur_item->info.use_password) DrawSprite(SPR_LOCK, PAL_NONE, w->widget[8].left + 5, y - 1);
+					/* draw a lock if the server is password protected */
+					if (cur_item->info.use_password) DrawSprite(SPR_LOCK, PAL_NONE, w->widget[NGWW_INFO].left + 5, y - 1);
 
-					// draw red or green icon, depending on compatibility with server.
-					DrawSprite(SPR_BLOT, (cur_item->info.compatible ? PALETTE_TO_GREEN : (cur_item->info.version_compatible ? PALETTE_TO_YELLOW : PALETTE_TO_RED)), w->widget[8].left + 15, y);
+					/* draw red or green icon, depending on compatibility with server */
+					DrawSprite(SPR_BLOT, (cur_item->info.compatible ? PALETTE_TO_GREEN : (cur_item->info.version_compatible ? PALETTE_TO_YELLOW : PALETTE_TO_RED)), w->widget[NGWW_INFO].left + 15, y);
 
-					// draw flag according to server language
-					DrawSprite(SPR_FLAGS_BASE + cur_item->info.server_lang, PAL_NONE, w->widget[8].left + 25, y);
+					/* draw flag according to server language */
+					DrawSprite(SPR_FLAGS_BASE + cur_item->info.server_lang, PAL_NONE, w->widget[NGWW_INFO].left + 25, y);
 				}
 
 				cur_item = cur_item->next;
@@ -309,73 +344,73 @@
 		}
 
 		/* Draw the right menu */
-		GfxFillRect(w->widget[15].left + 1, 43, w->widget[15].right - 1, 92, 157);
+		GfxFillRect(w->widget[NGWW_DETAILS].left + 1, 43, w->widget[NGWW_DETAILS].right - 1, 92, 157);
 		if (sel == NULL) {
-			DrawStringCentered(w->widget[15].left + 115, 58, STR_NETWORK_GAME_INFO, 0);
+			DrawStringCentered(w->widget[NGWW_DETAILS].left + 115, 58, STR_NETWORK_GAME_INFO, TC_FROMSTRING);
 		} else if (!sel->online) {
 			SetDParamStr(0, sel->info.server_name);
-			DrawStringCentered(w->widget[15].left + 115, 68, STR_ORANGE, 0); // game name
+			DrawStringCentered(w->widget[NGWW_DETAILS].left + 115, 68, STR_ORANGE, TC_FROMSTRING); // game name
 
-			DrawStringCentered(w->widget[15].left + 115, 132, STR_NETWORK_SERVER_OFFLINE, 0); // server offline
+			DrawStringCentered(w->widget[NGWW_DETAILS].left + 115, 132, STR_NETWORK_SERVER_OFFLINE, TC_FROMSTRING); // server offline
 		} else { // show game info
 			uint16 y = 100;
-			const uint16 x = w->widget[15].left + 5;
+			const uint16 x = w->widget[NGWW_DETAILS].left + 5;
 
-			DrawStringCentered(w->widget[15].left + 115, 48, STR_NETWORK_GAME_INFO, 0);
+			DrawStringCentered(w->widget[NGWW_DETAILS].left + 115, 48, STR_NETWORK_GAME_INFO, TC_FROMSTRING);
 
 
 			SetDParamStr(0, sel->info.server_name);
-			DrawStringCenteredTruncated(w->widget[15].left, w->widget[15].right, 62, STR_ORANGE, 16); // game name
+			DrawStringCenteredTruncated(w->widget[NGWW_DETAILS].left, w->widget[NGWW_DETAILS].right, 62, STR_ORANGE, TC_BLACK); // game name
 
 			SetDParamStr(0, sel->info.map_name);
-			DrawStringCenteredTruncated(w->widget[15].left, w->widget[15].right, 74, STR_02BD, 16); // map name
+			DrawStringCenteredTruncated(w->widget[NGWW_DETAILS].left, w->widget[NGWW_DETAILS].right, 74, STR_02BD, TC_BLACK); // map name
 
 			SetDParam(0, sel->info.clients_on);
 			SetDParam(1, sel->info.clients_max);
 			SetDParam(2, sel->info.companies_on);
 			SetDParam(3, sel->info.companies_max);
-			DrawString(x, y, STR_NETWORK_CLIENTS, 2);
+			DrawString(x, y, STR_NETWORK_CLIENTS, TC_GOLD);
 			y += 10;
 
 			SetDParam(0, STR_NETWORK_LANG_ANY + sel->info.server_lang);
-			DrawString(x, y, STR_NETWORK_LANGUAGE, 2); // server language
+			DrawString(x, y, STR_NETWORK_LANGUAGE, TC_GOLD); // server language
 			y += 10;
 
 			SetDParam(0, STR_TEMPERATE_LANDSCAPE + sel->info.map_set);
-			DrawString(x, y, STR_NETWORK_TILESET, 2); // tileset
+			DrawString(x, y, STR_NETWORK_TILESET, TC_GOLD); // tileset
 			y += 10;
 
 			SetDParam(0, sel->info.map_width);
 			SetDParam(1, sel->info.map_height);
-			DrawString(x, y, STR_NETWORK_MAP_SIZE, 2); // map size
+			DrawString(x, y, STR_NETWORK_MAP_SIZE, TC_GOLD); // map size
 			y += 10;
 
 			SetDParamStr(0, sel->info.server_revision);
-			DrawString(x, y, STR_NETWORK_SERVER_VERSION, 2); // server version
+			DrawString(x, y, STR_NETWORK_SERVER_VERSION, TC_GOLD); // server version
 			y += 10;
 
 			SetDParamStr(0, sel->info.hostname);
 			SetDParam(1, sel->port);
-			DrawString(x, y, STR_NETWORK_SERVER_ADDRESS, 2); // server address
+			DrawString(x, y, STR_NETWORK_SERVER_ADDRESS, TC_GOLD); // server address
 			y += 10;
 
 			SetDParam(0, sel->info.start_date);
-			DrawString(x, y, STR_NETWORK_START_DATE, 2); // start date
+			DrawString(x, y, STR_NETWORK_START_DATE, TC_GOLD); // start date
 			y += 10;
 
 			SetDParam(0, sel->info.game_date);
-			DrawString(x, y, STR_NETWORK_CURRENT_DATE, 2); // current date
+			DrawString(x, y, STR_NETWORK_CURRENT_DATE, TC_GOLD); // current date
 			y += 10;
 
 			y += 2;
 
 			if (!sel->info.compatible) {
-				DrawStringCentered(w->widget[15].left + 115, y, sel->info.version_compatible ? STR_NETWORK_GRF_MISMATCH : STR_NETWORK_VERSION_MISMATCH, 0); // server mismatch
+				DrawStringCentered(w->widget[NGWW_DETAILS].left + 115, y, sel->info.version_compatible ? STR_NETWORK_GRF_MISMATCH : STR_NETWORK_VERSION_MISMATCH, TC_FROMSTRING); // server mismatch
 			} else if (sel->info.clients_on == sel->info.clients_max) {
-				// Show: server full, when clients_on == clients_max
-				DrawStringCentered(w->widget[15].left + 115, y, STR_NETWORK_SERVER_FULL, 0); // server full
+				/* Show: server full, when clients_on == clients_max */
+				DrawStringCentered(w->widget[NGWW_DETAILS].left + 115, y, STR_NETWORK_SERVER_FULL, TC_FROMSTRING); // server full
 			} else if (sel->info.use_password) {
-				DrawStringCentered(w->widget[15].left + 115, y, STR_NETWORK_PASSWORD, 0); // password warning
+				DrawStringCentered(w->widget[NGWW_DETAILS].left + 115, y, STR_NETWORK_PASSWORD, TC_FROMSTRING); // password warning
 			}
 
 			y += 10;
@@ -385,24 +420,24 @@
 	case WE_CLICK:
 		nd->field = e->we.click.widget;
 		switch (e->we.click.widget) {
-		case 14: // Cancel button
+		case NGWW_CANCEL: // Cancel button
 			DeleteWindowById(WC_NETWORK_WINDOW, 0);
 			break;
-		case 4: case 5:
-			ShowDropDownMenu(w, _lan_internet_types_dropdown, _network_lan_internet, 5, 0, 0); // do it for widget 5
+		case NGWW_CONN_TXT: case NGWW_CONN_BTN: // 'Connection' droplist
+			ShowDropDownMenu(w, _lan_internet_types_dropdown, _network_lan_internet, NGWW_CONN_BTN, 0, 0); // do it for widget NSSW_CONN_BTN
 			break;
-		case 6: /* Sort by name */
-		case 7: /* Sort by connected clients */
-		case 8: /* Connectivity (green dot) */
-			if (ld->sort_type == e->we.click.widget - 6) ld->flags ^= VL_DESC;
+		case NGWW_NAME: // Sort by name
+		case NGWW_CLIENTS: // Sort by connected clients
+		case NGWW_INFO: // Connectivity (green dot)
+			if (ld->sort_type == e->we.click.widget - NGWW_NAME) ld->flags ^= VL_DESC;
 			ld->flags |= VL_RESORT;
-			ld->sort_type = e->we.click.widget - 6;
+			ld->sort_type = e->we.click.widget - NGWW_NAME;
 
 			_ng_sorting.order = !!(ld->flags & VL_DESC);
 			_ng_sorting.criteria = ld->sort_type;
 			SetWindowDirty(w);
 			break;
-		case 9: { /* Matrix to show networkgames */
+		case NGWW_MATRIX: { // Matrix to show networkgames
 			NetworkGameList *cur_item;
 			uint32 id_v = (e->we.click.pt.y - NET_PRC__OFFSET_TOP_WIDGET) / NET_PRC__SIZE_OF_ROW;
 
@@ -415,52 +450,54 @@
 			nd->server = cur_item;
 			SetWindowDirty(w);
 		} break;
-		case 11: /* Find server automatically */
+		case NGWW_FIND: // Find server automatically
 			switch (_network_lan_internet) {
 				case 0: NetworkUDPSearchGame(); break;
 				case 1: NetworkUDPQueryMasterServer(); break;
 			}
 			break;
-		case 12: { // Add a server
-				ShowQueryString(
+		case NGWW_ADD: { // Add a server
+			ShowQueryString(
 				BindCString(_network_default_ip),
 				STR_NETWORK_ENTER_IP,
 				31 | 0x1000,  // maximum number of characters OR
 				250, // characters up to this width pixels, whichever is satisfied first
 				w, CS_ALPHANUMERAL);
 		} break;
-		case 13: /* Start server */
+		case NGWW_START: // Start server
 			ShowNetworkStartServerWindow();
 			break;
-		case 16: /* Join Game */
+		case NGWW_JOIN: // Join Game
 			if (nd->server != NULL) {
 				snprintf(_network_last_host, sizeof(_network_last_host), "%s", inet_ntoa(*(struct in_addr *)&nd->server->ip));
 				_network_last_port = nd->server->port;
 				ShowNetworkLobbyWindow(nd->server);
 			}
 			break;
-		case 17: // Refresh
+		case NGWW_REFRESH: // Refresh
 			if (nd->server != NULL)
 				NetworkUDPQueryServer(nd->server->info.hostname, nd->server->port);
 			break;
-		case 18: // NewGRF Settings
+		case NGWW_NEWGRF: // NewGRF Settings
 			if (nd->server != NULL) ShowNewGRFSettings(false, false, false, &nd->server->info.grfconfig);
 			break;
 
 	} break;
 
-	case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */
+	case WE_DROPDOWN_SELECT: // we have selected a dropdown item in the list
 		switch (e->we.dropdown.button) {
-			case 5:
+			case NGWW_CONN_BTN:
 				_network_lan_internet = e->we.dropdown.index;
 				break;
+			default:
+				NOT_REACHED();
 		}
 
 		SetWindowDirty(w);
 		break;
 
 	case WE_MOUSELOOP:
-		if (nd->field == 3) HandleEditBox(w, &WP(w, network_ql_d).q, 3);
+		if (nd->field == NGWW_PLAYER) HandleEditBox(w, &WP(w, network_ql_d).q, NGWW_PLAYER);
 		break;
 
 	case WE_MESSAGE:
@@ -470,9 +507,9 @@
 		break;
 
 	case WE_KEYPRESS:
-		if (nd->field != 3) {
+		if (nd->field != NGWW_PLAYER) {
 			if (nd->server != NULL) {
-				if (e->we.keypress.keycode == WKC_DELETE) { /* Press 'delete' to remove servers */
+				if (e->we.keypress.keycode == WKC_DELETE) { // Press 'delete' to remove servers
 					NetworkGameListRemoveItem(nd->server);
 					NetworkRebuildHostList();
 					nd->server = NULL;
@@ -481,9 +518,9 @@
 			break;
 		}
 
-		if (HandleEditBoxKey(w, &WP(w, network_ql_d).q, 3, e) == 1) break; // enter pressed
+		if (HandleEditBoxKey(w, &WP(w, network_ql_d).q, NGWW_PLAYER, e) == 1) break; // enter pressed
 
-		// The name is only allowed when it starts with a letter!
+		/* The name is only allowed when it starts with a letter! */
 		if (_edit_str_buf[0] != '\0' && _edit_str_buf[0] != ' ') {
 			ttd_strlcpy(_network_player_name, _edit_str_buf, lengthof(_network_player_name));
 		} else {
@@ -500,57 +537,61 @@
 	case WE_RESIZE: {
 		w->vscroll.cap += e->we.sizing.diff.y / (int)w->resize.step_height;
 
-		w->widget[9].data = (w->vscroll.cap << 8) + 1;
+		w->widget[NGWW_MATRIX].data = (w->vscroll.cap << 8) + 1;
 
-		int widget_width = w->widget[11].right - w->widget[11].left;
+		SetVScrollCount(w, ld->list_length);
+
+		int widget_width = w->widget[NGWW_FIND].right - w->widget[NGWW_FIND].left;
 		int space = (w->width - 4 * widget_width - 25) / 3;
 
 		int offset = 10;
 		for (uint i = 0; i < 4; i++) {
-			w->widget[11 + i].left  = offset;
+			w->widget[NGWW_FIND + i].left  = offset;
 			offset += widget_width;
-			w->widget[11 + i].right = offset;
+			w->widget[NGWW_FIND + i].right = offset;
 			offset += space;
 		}
 	} break;
 
-	case WE_DESTROY: /* Nicely clean up the sort-list */
+	case WE_DESTROY: // Nicely clean up the sort-list
 		free(WP(w, network_ql_d).sort_list);
 		break;
 	}
 }
 
 static const Widget _network_game_window_widgets[] = {
-{   WWT_CLOSEBOX,   RESIZE_NONE,   BGC,     0,    10,     0,    13, STR_00C5,                       STR_018B_CLOSE_WINDOW},
+/* TOP */
+{   WWT_CLOSEBOX,   RESIZE_NONE,   BGC,     0,    10,     0,    13, STR_00C5,                       STR_018B_CLOSE_WINDOW},            // NGWW_CLOSE
 {    WWT_CAPTION,   RESIZE_RIGHT,  BGC,    11,   449,     0,    13, STR_NETWORK_MULTIPLAYER,        STR_NULL},
 {      WWT_PANEL,   RESIZE_RB,     BGC,     0,   449,    14,   263, 0x0,                            STR_NULL},
 
-/* LEFT SIDE */
-{      WWT_PANEL,   RESIZE_LR,     BGC,   290,   440,    22,    33, 0x0,                            STR_NETWORK_ENTER_NAME_TIP},
-
-{      WWT_INSET,   RESIZE_NONE,   BGC,    90,   181,    22,    33, STR_NETWORK_LAN_INTERNET_COMBO, STR_NETWORK_CONNECTION_TIP},
-{    WWT_TEXTBTN,   RESIZE_NONE,   BGC,   170,   180,    23,    32, STR_0225,                       STR_NETWORK_CONNECTION_TIP},
+{       WWT_TEXT,   RESIZE_NONE,   BGC,     9,    85,    23,    35, STR_NETWORK_CONNECTION,         STR_NULL},
+{      WWT_INSET,   RESIZE_NONE,   BGC,    90,   181,    22,    33, STR_NETWORK_LAN_INTERNET_COMBO, STR_NETWORK_CONNECTION_TIP},       // NGWW_CONN_TXT
+{    WWT_TEXTBTN,   RESIZE_NONE,   BGC,   170,   180,    23,    32, STR_0225,                       STR_NETWORK_CONNECTION_TIP},       // NGWW_CONN_BTN
 
-{ WWT_PUSHTXTBTN,   RESIZE_RIGHT,  BTC,    10,    70,    42,    53, STR_NETWORK_GAME_NAME,          STR_NETWORK_GAME_NAME_TIP},
-{ WWT_PUSHTXTBTN,   RESIZE_LR,     BTC,    71,   150,    42,    53, STR_NETWORK_CLIENTS_CAPTION,    STR_NETWORK_CLIENTS_CAPTION_TIP},
-{ WWT_PUSHTXTBTN,   RESIZE_LR,     BTC,   151,   190,    42,    53, STR_EMPTY,                      STR_NETWORK_INFO_ICONS_TIP},
+{      WWT_PANEL,   RESIZE_LR,     BGC,   290,   440,    22,    33, 0x0,                            STR_NETWORK_ENTER_NAME_TIP},       // NGWW_PLAYER
 
-{     WWT_MATRIX,   RESIZE_RB,     BGC,    10,   190,    54,   236, (13 << 8) + 1,                  STR_NETWORK_CLICK_GAME_TO_SELECT},
-{  WWT_SCROLLBAR,   RESIZE_LRB,    BGC,   191,   202,    42,   236, STR_NULL,                       STR_0190_SCROLL_BAR_SCROLLS_LIST},
+/* LEFT SIDE */
+{ WWT_PUSHTXTBTN,   RESIZE_RIGHT,  BTC,    10,    70,    42,    53, STR_NETWORK_GAME_NAME,          STR_NETWORK_GAME_NAME_TIP},        // NGWW_NAME
+{ WWT_PUSHTXTBTN,   RESIZE_LR,     BTC,    71,   150,    42,    53, STR_NETWORK_CLIENTS_CAPTION,    STR_NETWORK_CLIENTS_CAPTION_TIP},  // NGWW_CLIENTS
+{ WWT_PUSHTXTBTN,   RESIZE_LR,     BTC,   151,   190,    42,    53, STR_EMPTY,                      STR_NETWORK_INFO_ICONS_TIP},       // NGWW_INFO
 
-{ WWT_PUSHTXTBTN,   RESIZE_TB,     BTC,    10,   110,   246,   257, STR_NETWORK_FIND_SERVER,        STR_NETWORK_FIND_SERVER_TIP},
-{ WWT_PUSHTXTBTN,   RESIZE_TB,     BTC,   118,   218,   246,   257, STR_NETWORK_ADD_SERVER,         STR_NETWORK_ADD_SERVER_TIP},
+{     WWT_MATRIX,   RESIZE_RB,     BGC,    10,   190,    54,   236, (13 << 8) + 1,                  STR_NETWORK_CLICK_GAME_TO_SELECT}, // NGWW_MATRIX
+{  WWT_SCROLLBAR,   RESIZE_LRB,    BGC,   191,   202,    42,   236, 0x0,                            STR_0190_SCROLL_BAR_SCROLLS_LIST},
 
 /* RIGHT SIDE */
-{ WWT_PUSHTXTBTN,   RESIZE_TB,     BTC,   226,   326,   246,   257, STR_NETWORK_START_SERVER,       STR_NETWORK_START_SERVER_TIP},
-{ WWT_PUSHTXTBTN,   RESIZE_TB,     BTC,   334,   434,   246,   257, STR_012E_CANCEL,                STR_NULL},
+{      WWT_PANEL,   RESIZE_LRB,    BGC,   210,   440,    42,   236, 0x0,                            STR_NULL},                         // NGWW_DETAILS
 
-{      WWT_PANEL,   RESIZE_LRB,    BGC,   210,   440,    42,   236, 0x0,                            STR_NULL},
+{ WWT_PUSHTXTBTN,   RESIZE_LRTB,   BTC,   215,   315,   215,   226, STR_NETWORK_JOIN_GAME,          STR_NULL},                         // NGWW_JOIN
+{ WWT_PUSHTXTBTN,   RESIZE_LRTB,   BTC,   330,   435,   215,   226, STR_NETWORK_REFRESH,            STR_NETWORK_REFRESH_TIP},          // NGWW_REFRESH
 
-{ WWT_PUSHTXTBTN,   RESIZE_LRTB,   BTC,   215,   315,   215,   226, STR_NETWORK_JOIN_GAME,          STR_NULL},
-{ WWT_PUSHTXTBTN,   RESIZE_LRTB,   BTC,   330,   435,   215,   226, STR_NETWORK_REFRESH,            STR_NETWORK_REFRESH_TIP},
+{ WWT_PUSHTXTBTN,   RESIZE_LRTB,   BTC,   330,   435,   197,   208, STR_NEWGRF_SETTINGS_BUTTON,     STR_NULL},                         // NGWW_NEWGRF
 
-{ WWT_PUSHTXTBTN,   RESIZE_LRTB,   BTC,   330,   435,   197,   208, STR_NEWGRF_SETTINGS_BUTTON,     STR_NULL},
+/* BOTTOM */
+{ WWT_PUSHTXTBTN,   RESIZE_TB,     BTC,    10,   110,   246,   257, STR_NETWORK_FIND_SERVER,        STR_NETWORK_FIND_SERVER_TIP},      // NGWW_FIND
+{ WWT_PUSHTXTBTN,   RESIZE_TB,     BTC,   118,   218,   246,   257, STR_NETWORK_ADD_SERVER,         STR_NETWORK_ADD_SERVER_TIP},       // NGWW_ADD
+{ WWT_PUSHTXTBTN,   RESIZE_TB,     BTC,   226,   326,   246,   257, STR_NETWORK_START_SERVER,       STR_NETWORK_START_SERVER_TIP},     // NGWW_START
+{ WWT_PUSHTXTBTN,   RESIZE_TB,     BTC,   334,   434,   246,   257, STR_012E_CANCEL,                STR_NULL},                         // NGWW_CANCEL
 
 {  WWT_RESIZEBOX,   RESIZE_LRTB,   BGC,   438,   449,   252,   263, 0x0,                            STR_RESIZE_BUTTON },
 
@@ -602,14 +643,46 @@
 	NSSWND_ROWSIZE = 12
 };
 
-/* Uses network_ql_d (network_d, querystr_d and list_d) WP macro */
+/** Enum for NetworkStartServerWindow, referring to _network_start_server_window_widgets */
+enum NetworkStartServerWidgets {
+	NSSW_CLOSE           =  0,   ///< Close 'X' button
+	NSSW_GAMENAME        =  4,   ///< Background for editbox to set game name
+	NSSW_SETPWD          =  5,   ///< 'Set password' button
+	NSSW_SELMAP          =  7,   ///< 'Select map' list
+	NSSW_CONNTYPE_TXT    = 10,   ///< 'Connection type' droplist
+	NSSW_CONNTYPE_BTN    = 11,   ///< 'Connection type' droplist button
+	NSSW_CLIENTS_BTND    = 13,   ///< 'Max clients' downarrow
+	NSSW_CLIENTS_TXT     = 14,   ///< 'Max clients' text
+	NSSW_CLIENTS_BTNU    = 15,   ///< 'Max clients' uparrow
+	NSSW_COMPANIES_BTND  = 17,   ///< 'Max companies' downarrow
+	NSSW_COMPANIES_TXT   = 18,   ///< 'Max companies' text
+	NSSW_COMPANIES_BTNU  = 19,   ///< 'Max companies' uparrow
+	NSSW_SPECTATORS_BTND = 21,   ///< 'Max spectators' downarrow
+	NSSW_SPECTATORS_TXT  = 22,   ///< 'Max spectators' text
+	NSSW_SPECTATORS_BTNU = 23,   ///< 'Max spectators' uparrow
+	NSSW_LANGUAGE_TXT    = 25,   ///< 'Language spoken' droplist
+	NSSW_LANGUAGE_BTN    = 26,   ///< 'Language spoken' droplist button
+	NSSW_START           = 27,   ///< 'Start' button
+	NSSW_LOAD            = 28,   ///< 'Load' button
+	NSSW_CANCEL          = 29,   ///< 'Cancel' button
+};
+
+/**
+ * Handler of actions done in the NetworkStartServer window
+ *
+ * @param w pointer to the Window structure
+ * @param e pointer to window event
+ * @note    Uses network_ql_d (network_d, querystr_d and list_d) WP macro
+ * @see     struct _network_start_server_window_widgets
+ * @see     enum NetworkStartServerWidgets
+ */
 static void NetworkStartServerWindowWndProc(Window *w, WindowEvent *e)
 {
 	network_d *nd = &WP(w, network_ql_d).n;
 
 	switch (e->event) {
-	case WE_CREATE: /* focus input box */
-		nd->field = 3;
+	case WE_CREATE: // focus input box
+		nd->field = NSSW_GAMENAME;
 		_network_game_info.use_password = (_network_server_password[0] != '\0');
 		break;
 
@@ -617,6 +690,7 @@
 		int y = NSSWND_START, pos;
 		const FiosItem *item;
 
+		/* draw basic widgets */
 		SetDParam(1, _connection_types_dropdown[_network_advertise]);
 		SetDParam(2, _network_game_info.clients_max);
 		SetDParam(3, _network_game_info.companies_max);
@@ -624,22 +698,15 @@
 		SetDParam(5, STR_NETWORK_LANG_ANY + _network_game_info.server_lang);
 		DrawWindowWidgets(w);
 
-		GfxFillRect(11, 63, 258, 215, 0xD7);
-		DrawEditBox(w, &WP(w, network_ql_d).q, 3);
-
-		DrawString(10, 22, STR_NETWORK_NEW_GAME_NAME, 2);
-
-		DrawString(10, 43, STR_NETWORK_SELECT_MAP, 2);
+		/* editbox to set game name */
+		DrawEditBox(w, &WP(w, network_ql_d).q, NSSW_GAMENAME);
 
-		DrawString(280,  63, STR_NETWORK_CONNECTION, 2);
-		DrawString(280,  95, STR_NETWORK_NUMBER_OF_CLIENTS, 2);
-		DrawString(280, 127, STR_NETWORK_NUMBER_OF_COMPANIES, 2);
-		DrawString(280, 159, STR_NETWORK_NUMBER_OF_SPECTATORS, 2);
-		DrawString(280, 191, STR_NETWORK_LANGUAGE_SPOKEN, 2);
+		/* if password is set, draw red '*' next to 'Set password' button */
+		if (_network_game_info.use_password) DoDrawString("*", 408, 23, TC_RED);
 
-		if (_network_game_info.use_password) DoDrawString("*", 408, 23, 3);
+		/* draw list of maps */
+		GfxFillRect(11, 63, 258, 215, 0xD7);  // black background of maps list
 
-		// draw list of maps
 		pos = w->vscroll.pos;
 		while (pos < _fios_num + 1) {
 			item = _fios_list + pos - 1;
@@ -647,7 +714,7 @@
 				GfxFillRect(11, y - 1, 258, y + 10, 155); // show highlighted item with a different colour
 
 			if (pos == 0) {
-				DrawString(14, y, STR_4010_GENERATE_RANDOM_NEW_GAME, 9);
+				DrawString(14, y, STR_4010_GENERATE_RANDOM_NEW_GAME, TC_DARK_GREEN);
 			} else {
 				DoDrawString(item->title, 14, y, _fios_colors[item->type] );
 			}
@@ -661,17 +728,17 @@
 	case WE_CLICK:
 		nd->field = e->we.click.widget;
 		switch (e->we.click.widget) {
-		case 0: /* Close 'X' */
-		case 22: /* Cancel button */
+		case NSSW_CLOSE:  // Close 'X'
+		case NSSW_CANCEL: // Cancel button
 			ShowNetworkGameWindow();
 			break;
 
-		case 4: /* Set password button */
-			nd->widget_id = 4;
+		case NSSW_SETPWD: // Set password button
+			nd->widget_id = NSSW_SETPWD;
 			ShowQueryString(BindCString(_network_server_password), STR_NETWORK_SET_PASSWORD, 20, 250, w, CS_ALPHANUMERAL);
 			break;
 
-		case 5: { /* Select map */
+		case NSSW_SELMAP: { // Select map
 			int y = (e->we.click.pt.y - NSSWND_START) / NSSWND_ROWSIZE;
 
 			y += w->vscroll.pos;
@@ -680,41 +747,47 @@
 			nd->map = (y == 0) ? NULL : _fios_list + y - 1;
 			SetWindowDirty(w);
 			} break;
-		case 7: case 8: /* Connection type */
-			ShowDropDownMenu(w, _connection_types_dropdown, _network_advertise, 8, 0, 0); // do it for widget 8
+		case NSSW_CONNTYPE_TXT: case NSSW_CONNTYPE_BTN: // Connection type
+			ShowDropDownMenu(w, _connection_types_dropdown, _network_advertise, NSSW_CONNTYPE_BTN, 0, 0); // do it for widget NSSW_CONNTYPE_BTN
 			break;
-		case  9: case 11: // Click on up/down button for number of players
-		case 12: case 14: // Click on up/down button for number of companies
-		case 15: case 17: // Click on up/down button for number of spectators
+		case NSSW_CLIENTS_BTND:    case NSSW_CLIENTS_BTNU:    // Click on up/down button for number of clients
+		case NSSW_COMPANIES_BTND:  case NSSW_COMPANIES_BTNU:  // Click on up/down button for number of companies
+		case NSSW_SPECTATORS_BTND: case NSSW_SPECTATORS_BTNU: // Click on up/down button for number of spectators
 			/* Don't allow too fast scrolling */
 			if ((w->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) {
 				HandleButtonClick(w, e->we.click.widget);
 				SetWindowDirty(w);
 				switch (e->we.click.widget) {
 					default: NOT_REACHED();
-					case  9: case 11: _network_game_info.clients_max    = clamp(_network_game_info.clients_max    + e->we.click.widget - 10, 2, MAX_CLIENTS); break;
-					case 12: case 14: _network_game_info.companies_max  = clamp(_network_game_info.companies_max  + e->we.click.widget - 13, 1, MAX_PLAYERS); break;
-					case 15: case 17: _network_game_info.spectators_max = clamp(_network_game_info.spectators_max + e->we.click.widget - 16, 0, MAX_CLIENTS); break;
+					case NSSW_CLIENTS_BTND: case NSSW_CLIENTS_BTNU:
+						_network_game_info.clients_max    = Clamp(_network_game_info.clients_max    + e->we.click.widget - NSSW_CLIENTS_TXT,    2, MAX_CLIENTS);
+						break;
+					case NSSW_COMPANIES_BTND: case NSSW_COMPANIES_BTNU:
+						_network_game_info.companies_max  = Clamp(_network_game_info.companies_max  + e->we.click.widget - NSSW_COMPANIES_TXT,  1, MAX_PLAYERS);
+						break;
+					case NSSW_SPECTATORS_BTND: case NSSW_SPECTATORS_BTNU:
+						_network_game_info.spectators_max = Clamp(_network_game_info.spectators_max + e->we.click.widget - NSSW_SPECTATORS_TXT, 0, MAX_CLIENTS);
+						break;
 				}
 			}
 			_left_button_clicked = false;
 			break;
-		case 10: // Click on number of players
-			nd->widget_id = 10;
+		case NSSW_CLIENTS_TXT:    // Click on number of players
+			nd->widget_id = NSSW_CLIENTS_TXT;
 			SetDParam(0, _network_game_info.clients_max);
-			ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_NETWORK_NUMBER_OF_CLIENTS, 3, 50, w, CS_NUMERAL);
+			ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_NETWORK_NUMBER_OF_CLIENTS,    3, 50, w, CS_NUMERAL);
 			break;
-		case 13: // Click on number of companies
-			nd->widget_id = 13;
+		case NSSW_COMPANIES_TXT:  // Click on number of companies
+			nd->widget_id = NSSW_COMPANIES_TXT;
 			SetDParam(0, _network_game_info.companies_max);
-			ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_NETWORK_NUMBER_OF_COMPANIES, 3, 50, w, CS_NUMERAL);
+			ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_NETWORK_NUMBER_OF_COMPANIES,  3, 50, w, CS_NUMERAL);
 			break;
-		case 16: // Click on number of companies
-			nd->widget_id = 16;
+		case NSSW_SPECTATORS_TXT: // Click on number of spectators
+			nd->widget_id = NSSW_SPECTATORS_TXT;
 			SetDParam(0, _network_game_info.spectators_max);
 			ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_NETWORK_NUMBER_OF_SPECTATORS, 3, 50, w, CS_NUMERAL);
 			break;
-		case 18: case 19: { /* Language */
+		case NSSW_LANGUAGE_TXT: case NSSW_LANGUAGE_BTN: { // Language
 			uint sel = 0;
 			for (uint i = 0; i < lengthof(_language_dropdown) - 1; i++) {
 				if (_language_dropdown[i] == STR_NETWORK_LANG_ANY + _network_game_info.server_lang) {
@@ -722,10 +795,10 @@
 					break;
 				}
 			}
-			ShowDropDownMenu(w, _language_dropdown, sel, 19, 0, 0);
+			ShowDropDownMenu(w, _language_dropdown, sel, NSSW_LANGUAGE_BTN, 0, 0);
 			break;
 		}
-		case 20: /* Start game */
+		case NSSW_START: // Start game
 			_is_network_server = true;
 
 			if (nd->map == NULL) { // start random new game
@@ -742,37 +815,38 @@
 				}
 			}
 			break;
-		case 21: /* Load game */
+		case NSSW_LOAD: // Load game
 			_is_network_server = true;
-			/* XXX - WC_NETWORK_WINDOW should stay, but if it stays, it gets
+			/* XXX - WC_NETWORK_WINDOW (this window) should stay, but if it stays, it gets
 			 * copied all the elements of 'load game' and upon closing that, it segfaults */
-			DeleteWindowById(WC_NETWORK_WINDOW, 0);
+			DeleteWindow(w);
 			ShowSaveLoadDialog(SLD_LOAD_GAME);
 			break;
 		}
 		break;
 
-	case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */
+	case WE_DROPDOWN_SELECT: // we have selected a dropdown item in the list
 		switch (e->we.dropdown.button) {
-			case  8: _network_advertise                = (e->we.dropdown.index != 0); break;
-			case 10: _network_game_info.clients_max    = e->we.dropdown.index;        break;
-			case 12: _network_game_info.companies_max  = e->we.dropdown.index;        break;
-			case 14: _network_game_info.spectators_max = e->we.dropdown.index;        break;
-			case 16:
+			case NSSW_CONNTYPE_BTN:
+				_network_advertise = (e->we.dropdown.index != 0);
+				break;
+			case NSSW_LANGUAGE_BTN:
 				_network_game_info.server_lang = _language_dropdown[e->we.dropdown.index] - STR_NETWORK_LANG_ANY;
 				break;
+			default:
+				NOT_REACHED();
 		}
 
 		SetWindowDirty(w);
 		break;
 
 	case WE_MOUSELOOP:
-		if (nd->field == 3) HandleEditBox(w, &WP(w, network_ql_d).q, 3);
+		if (nd->field == NSSW_GAMENAME) HandleEditBox(w, &WP(w, network_ql_d).q, NSSW_GAMENAME);
 		break;
 
 	case WE_KEYPRESS:
-		if (nd->field == 3) {
-			if (HandleEditBoxKey(w, &WP(w, network_ql_d).q, 3, e) == 1) break; // enter pressed
+		if (nd->field == NSSW_GAMENAME) {
+			if (HandleEditBoxKey(w, &WP(w, network_ql_d).q, NSSW_GAMENAME, e) == 1) break; // enter pressed
 
 			ttd_strlcpy(_network_server_name, WP(w, network_ql_d).q.text.buf, sizeof(_network_server_name));
 		}
@@ -781,7 +855,7 @@
 	case WE_ON_EDIT_TEXT:
 		if (e->we.edittext.str == NULL) break;
 
-		if (nd->widget_id == 4) {
+		if (nd->widget_id == NSSW_SETPWD) {
 			ttd_strlcpy(_network_server_password, e->we.edittext.str, lengthof(_network_server_password));
 			_network_game_info.use_password = (_network_server_password[0] != '\0');
 		} else {
@@ -789,9 +863,9 @@
 			InvalidateWidget(w, nd->widget_id);
 			switch (nd->widget_id) {
 				default: NOT_REACHED();
-				case 10: _network_game_info.clients_max    = clamp(value, 2, MAX_CLIENTS); break;
-				case 13: _network_game_info.companies_max  = clamp(value, 1, MAX_PLAYERS); break;
-				case 16: _network_game_info.spectators_max = clamp(value, 0, MAX_CLIENTS); break;
+				case NSSW_CLIENTS_TXT:    _network_game_info.clients_max    = Clamp(value, 2, MAX_CLIENTS); break;
+				case NSSW_COMPANIES_TXT:  _network_game_info.companies_max  = Clamp(value, 1, MAX_PLAYERS); break;
+				case NSSW_SPECTATORS_TXT: _network_game_info.spectators_max = Clamp(value, 0, MAX_CLIENTS); break;
 			}
 		}
 
@@ -801,34 +875,50 @@
 }
 
 static const Widget _network_start_server_window_widgets[] = {
-{   WWT_CLOSEBOX,   RESIZE_NONE,   BGC,     0,    10,     0,    13, STR_00C5,                       STR_018B_CLOSE_WINDOW },
-{    WWT_CAPTION,   RESIZE_NONE,   BGC,    11,   419,     0,    13, STR_NETWORK_START_GAME_WINDOW,  STR_NULL},
-{      WWT_PANEL,   RESIZE_NONE,   BGC,     0,   419,    14,   243, 0x0,                            STR_NULL},
+/* Window decoration and background panel */
+{   WWT_CLOSEBOX,   RESIZE_NONE,   BGC,     0,    10,     0,    13, STR_00C5,                         STR_018B_CLOSE_WINDOW },               // NSSW_CLOSE
+{    WWT_CAPTION,   RESIZE_NONE,   BGC,    11,   419,     0,    13, STR_NETWORK_START_GAME_WINDOW,    STR_NULL},
+{      WWT_PANEL,   RESIZE_NONE,   BGC,     0,   419,    14,   243, 0x0,                              STR_NULL},
 
-{      WWT_PANEL,   RESIZE_NONE,   BGC,   100,   272,    22,    33, 0x0,                            STR_NETWORK_NEW_GAME_NAME_TIP},
-{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   285,   405,    22,    33, STR_NETWORK_SET_PASSWORD,       STR_NETWORK_PASSWORD_TIP},
+/* Set game name and password widgets */
+{       WWT_TEXT,   RESIZE_NONE,   BGC,    10,    90,    22,    34, STR_NETWORK_NEW_GAME_NAME,        STR_NULL},
+{      WWT_PANEL,   RESIZE_NONE,   BGC,   100,   272,    22,    33, 0x0,                              STR_NETWORK_NEW_GAME_NAME_TIP},        // NSSW_GAMENAME
+{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   285,   405,    22,    33, STR_NETWORK_SET_PASSWORD,         STR_NETWORK_PASSWORD_TIP},             // NSSW_SETPWD
 
-{      WWT_INSET,   RESIZE_NONE,   BGC,    10,   271,    62,   216, 0x0,                            STR_NETWORK_SELECT_MAP_TIP},
-{  WWT_SCROLLBAR,   RESIZE_NONE,   BGC,   259,   270,    63,   215, 0x0,                            STR_0190_SCROLL_BAR_SCROLLS_LIST},
+/* List of playable scenarios */
+{       WWT_TEXT,   RESIZE_NONE,   BGC,    10,   110,    43,    55, STR_NETWORK_SELECT_MAP,           STR_NULL},
+{      WWT_INSET,   RESIZE_NONE,   BGC,    10,   271,    62,   216, STR_NULL,                         STR_NETWORK_SELECT_MAP_TIP},           // NSSW_SELMAP
+{  WWT_SCROLLBAR,   RESIZE_NONE,   BGC,   259,   270,    63,   215, 0x0,                              STR_0190_SCROLL_BAR_SCROLLS_LIST},
+
 /* Combo/selection boxes to control Connection Type / Max Clients / Max Companies / Max Observers / Language */
-{      WWT_INSET,   RESIZE_NONE,   BGC,   280,   410,    77,    88, STR_NETWORK_LAN_INTERNET_COMBO, STR_NETWORK_CONNECTION_TIP},
-{    WWT_TEXTBTN,   RESIZE_NONE,   BGC,   399,   409,    78,    87, STR_0225,                       STR_NETWORK_CONNECTION_TIP},
-{     WWT_IMGBTN,   RESIZE_NONE,   BGC,   280,   291,   109,   120, SPR_ARROW_DOWN,                 STR_NETWORK_NUMBER_OF_CLIENTS_TIP},
-{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BGC,   292,   397,   109,   120, STR_NETWORK_CLIENTS_SELECT,     STR_NETWORK_NUMBER_OF_CLIENTS_TIP},
-{     WWT_IMGBTN,   RESIZE_NONE,   BGC,   398,   410,   109,   120, SPR_ARROW_UP,                   STR_NETWORK_NUMBER_OF_CLIENTS_TIP},
-{     WWT_IMGBTN,   RESIZE_NONE,   BGC,   280,   291,   141,   152, SPR_ARROW_DOWN,                 STR_NETWORK_NUMBER_OF_COMPANIES_TIP},
-{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BGC,   292,   397,   141,   152, STR_NETWORK_COMPANIES_SELECT,   STR_NETWORK_NUMBER_OF_COMPANIES_TIP},
-{     WWT_IMGBTN,   RESIZE_NONE,   BGC,   398,   410,   141,   152, SPR_ARROW_UP,                   STR_NETWORK_NUMBER_OF_COMPANIES_TIP},
-{     WWT_IMGBTN,   RESIZE_NONE,   BGC,   280,   291,   173,   184, SPR_ARROW_DOWN,                 STR_NETWORK_NUMBER_OF_SPECTATORS_TIP},
-{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BGC,   292,   397,   173,   184, STR_NETWORK_SPECTATORS_SELECT,  STR_NETWORK_NUMBER_OF_SPECTATORS_TIP},
-{     WWT_IMGBTN,   RESIZE_NONE,   BGC,   398,   410,   173,   184, SPR_ARROW_UP,                   STR_NETWORK_NUMBER_OF_SPECTATORS_TIP},
+{       WWT_TEXT,   RESIZE_NONE,   BGC,   280,   419,    63,    75, STR_NETWORK_CONNECTION,           STR_NULL},
+{      WWT_INSET,   RESIZE_NONE,   BGC,   280,   410,    77,    88, STR_NETWORK_LAN_INTERNET_COMBO,   STR_NETWORK_CONNECTION_TIP},           // NSSW_CONNTYPE_TXT
+{    WWT_TEXTBTN,   RESIZE_NONE,   BGC,   399,   409,    78,    87, STR_0225,                         STR_NETWORK_CONNECTION_TIP},           // NSSW_CONNTYPE_BTN
 
-{      WWT_INSET,   RESIZE_NONE,   BGC,   280,   410,   205,   216, STR_NETWORK_LANGUAGE_COMBO,     STR_NETWORK_LANGUAGE_TIP},
-{    WWT_TEXTBTN,   RESIZE_NONE,   BGC,   399,   409,   206,   215, STR_0225,                       STR_NETWORK_LANGUAGE_TIP},
+{       WWT_TEXT,   RESIZE_NONE,   BGC,   280,   419,    95,   107, STR_NETWORK_NUMBER_OF_CLIENTS,    STR_NULL},
+{     WWT_IMGBTN,   RESIZE_NONE,   BGC,   280,   291,   109,   120, SPR_ARROW_DOWN,                   STR_NETWORK_NUMBER_OF_CLIENTS_TIP},    // NSSW_CLIENTS_BTND
+{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BGC,   292,   397,   109,   120, STR_NETWORK_CLIENTS_SELECT,       STR_NETWORK_NUMBER_OF_CLIENTS_TIP},    // NSSW_CLIENTS_TXT
+{     WWT_IMGBTN,   RESIZE_NONE,   BGC,   398,   410,   109,   120, SPR_ARROW_UP,                     STR_NETWORK_NUMBER_OF_CLIENTS_TIP},    // NSSW_CLIENTS_BTNU
 
-{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,    40,   140,   224,   235, STR_NETWORK_START_GAME,         STR_NETWORK_START_GAME_TIP},
-{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   150,   250,   224,   235, STR_NETWORK_LOAD_GAME,          STR_NETWORK_LOAD_GAME_TIP},
-{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   260,   360,   224,   235, STR_012E_CANCEL,                STR_NULL},
+{       WWT_TEXT,   RESIZE_NONE,   BGC,   280,   419,   127,   139, STR_NETWORK_NUMBER_OF_COMPANIES,  STR_NULL},
+{     WWT_IMGBTN,   RESIZE_NONE,   BGC,   280,   291,   141,   152, SPR_ARROW_DOWN,                   STR_NETWORK_NUMBER_OF_COMPANIES_TIP},  // NSSW_COMPANIES_BTND
+{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BGC,   292,   397,   141,   152, STR_NETWORK_COMPANIES_SELECT,     STR_NETWORK_NUMBER_OF_COMPANIES_TIP},  // NSSW_COMPANIES_TXT
+{     WWT_IMGBTN,   RESIZE_NONE,   BGC,   398,   410,   141,   152, SPR_ARROW_UP,                     STR_NETWORK_NUMBER_OF_COMPANIES_TIP},  // NSSW_COMPANIES_BTNU
+
+{       WWT_TEXT,   RESIZE_NONE,   BGC,   280,   419,   159,   171, STR_NETWORK_NUMBER_OF_SPECTATORS, STR_NULL},
+{     WWT_IMGBTN,   RESIZE_NONE,   BGC,   280,   291,   173,   184, SPR_ARROW_DOWN,                   STR_NETWORK_NUMBER_OF_SPECTATORS_TIP}, // NSSW_SPECTATORS_BTND
+{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BGC,   292,   397,   173,   184, STR_NETWORK_SPECTATORS_SELECT,    STR_NETWORK_NUMBER_OF_SPECTATORS_TIP}, // NSSW_SPECTATORS_TXT
+{     WWT_IMGBTN,   RESIZE_NONE,   BGC,   398,   410,   173,   184, SPR_ARROW_UP,                     STR_NETWORK_NUMBER_OF_SPECTATORS_TIP}, // NSSW_SPECTATORS_BTNU
+
+{       WWT_TEXT,   RESIZE_NONE,   BGC,   280,   419,   191,   203, STR_NETWORK_LANGUAGE_SPOKEN,      STR_NULL},
+{      WWT_INSET,   RESIZE_NONE,   BGC,   280,   410,   205,   216, STR_NETWORK_LANGUAGE_COMBO,       STR_NETWORK_LANGUAGE_TIP},             // NSSW_LANGUAGE_TXT
+{    WWT_TEXTBTN,   RESIZE_NONE,   BGC,   399,   409,   206,   215, STR_0225,                         STR_NETWORK_LANGUAGE_TIP},             // NSSW_LANGUAGE_BTN
+
+/* Buttons Start / Load / Cancel */
+{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,    40,   140,   224,   235, STR_NETWORK_START_GAME,           STR_NETWORK_START_GAME_TIP},           // NSSW_START
+{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   150,   250,   224,   235, STR_NETWORK_LOAD_GAME,            STR_NETWORK_LOAD_GAME_TIP},            // NSSW_LOAD
+{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   260,   360,   224,   235, STR_012E_CANCEL,                  STR_NULL},                             // NSSW_CANCEL
+
 {   WIDGETS_END},
 };
 
@@ -872,7 +962,27 @@
 	return PLAYER_FIRST;
 }
 
-/* uses network_d WP macro */
+/** Enum for NetworkLobbyWindow, referring to _network_lobby_window_widgets */
+enum NetworkLobbyWindowWidgets {
+	NLWW_CLOSE    =  0, ///< Close 'X' button
+	NLWW_MATRIX   =  5, ///< List of companies
+	NLWW_DETAILS  =  7, ///< Company details
+	NLWW_JOIN     =  8, ///< 'Join company' button
+	NLWW_NEW      =  9, ///< 'New company' button
+	NLWW_SPECTATE = 10, ///< 'Spectate game' button
+	NLWW_REFRESH  = 11, ///< 'Refresh server' button
+	NLWW_CANCEL   = 12, ///< 'Cancel' button
+};
+
+/**
+ * Handler of actions done in the NetworkLobby window
+ *
+ * @param w pointer to the Window structure
+ * @param e pointer to window event
+ * @note    uses network_d WP macro
+ * @see     struct _network_lobby_window_widgets
+ * @see     enum NetworkLobbyWindowWidgets
+ */
 static void NetworkLobbyWindowWndProc(Window *w, WindowEvent *e)
 {
 	network_d *nd = &WP(w, network_d);
@@ -886,18 +996,17 @@
 		const NetworkGameInfo *gi = &nd->server->info;
 		int y = NET_PRC__OFFSET_TOP_WIDGET_COMPANY, pos;
 
-		SetWindowWidgetDisabledState(w, 7, nd->company == (byte)-1);
-		SetWindowWidgetDisabledState(w, 8, gi->companies_on >= gi->companies_max);
-		/* You can not join a server as spectator when it has no companies active..
-		 * it causes some nasty crashes */
-		SetWindowWidgetDisabledState(w, 9, gi->spectators_on >= gi->spectators_max ||
-				gi->companies_on == 0);
+		/* Join button is disabled when no company is selected */
+		w->SetWidgetDisabledState(NLWW_JOIN, nd->company == INVALID_PLAYER);
+		/* Cannot start new company if there are too many */
+		w->SetWidgetDisabledState(NLWW_NEW, gi->companies_on >= gi->companies_max);
+		/* Cannot spectate if there are too many spectators */
+		w->SetWidgetDisabledState(NLWW_SPECTATE, gi->spectators_on >= gi->spectators_max);
 
+		/* Draw window widgets */
+		SetDParamStr(0, gi->server_name);
 		DrawWindowWidgets(w);
 
-		SetDParamStr(0, gi->server_name);
-		DrawString(10, 22, STR_NETWORK_PREPARE_TO_JOIN, 2);
-
 		/* Draw company list */
 		pos = w->vscroll.pos;
 		while (pos < gi->companies_on) {
@@ -906,7 +1015,7 @@
 			if (nd->company == company)
 				GfxFillRect(11, y - 1, 154, y + 10, 10); // show highlighted item with a different colour
 
-			DoDrawStringTruncated(_network_player_info[company].company_name, 13, y, 16, 135 - 13);
+			DoDrawStringTruncated(_network_player_info[company].company_name, 13, y, TC_BLACK, 135 - 13);
 			if (_network_player_info[company].use_password != 0) DrawSprite(SPR_LOCK, PAL_NONE, 135, y);
 
 			/* If the company's income was positive puts a green dot else a red dot */
@@ -920,41 +1029,41 @@
 
 		/* Draw info about selected company when it is selected in the left window */
 		GfxFillRect(174, 39, 403, 75, 157);
-		DrawStringCentered(290, 50, STR_NETWORK_COMPANY_INFO, 0);
-		if (nd->company != (byte)-1) {
+		DrawStringCentered(290, 50, STR_NETWORK_COMPANY_INFO, TC_FROMSTRING);
+		if (nd->company != INVALID_PLAYER) {
 			const uint x = 183;
-			const uint trunc_width = w->widget[6].right - x;
+			const uint trunc_width = w->widget[NLWW_DETAILS].right - x;
 			y = 80;
 
 			SetDParam(0, nd->server->info.clients_on);
 			SetDParam(1, nd->server->info.clients_max);
 			SetDParam(2, nd->server->info.companies_on);
 			SetDParam(3, nd->server->info.companies_max);
-			DrawString(x, y, STR_NETWORK_CLIENTS, 2);
+			DrawString(x, y, STR_NETWORK_CLIENTS, TC_GOLD);
 			y += 10;
 
 			SetDParamStr(0, _network_player_info[nd->company].company_name);
-			DrawStringTruncated(x, y, STR_NETWORK_COMPANY_NAME, 2, trunc_width);
+			DrawStringTruncated(x, y, STR_NETWORK_COMPANY_NAME, TC_GOLD, trunc_width);
 			y += 10;
 
 			SetDParam(0, _network_player_info[nd->company].inaugurated_year);
-			DrawString(x, y, STR_NETWORK_INAUGURATION_YEAR, 2); // inauguration year
+			DrawString(x, y, STR_NETWORK_INAUGURATION_YEAR, TC_GOLD); // inauguration year
 			y += 10;
 
 			SetDParam(0, _network_player_info[nd->company].company_value);
-			DrawString(x, y, STR_NETWORK_VALUE, 2); // company value
+			DrawString(x, y, STR_NETWORK_VALUE, TC_GOLD); // company value
 			y += 10;
 
 			SetDParam(0, _network_player_info[nd->company].money);
-			DrawString(x, y, STR_NETWORK_CURRENT_BALANCE, 2); // current balance
+			DrawString(x, y, STR_NETWORK_CURRENT_BALANCE, TC_GOLD); // current balance
 			y += 10;
 
 			SetDParam(0, _network_player_info[nd->company].income);
-			DrawString(x, y, STR_NETWORK_LAST_YEARS_INCOME, 2); // last year's income
+			DrawString(x, y, STR_NETWORK_LAST_YEARS_INCOME, TC_GOLD); // last year's income
 			y += 10;
 
 			SetDParam(0, _network_player_info[nd->company].performance);
-			DrawString(x, y, STR_NETWORK_PERFORMANCE, 2); // performance
+			DrawString(x, y, STR_NETWORK_PERFORMANCE, TC_GOLD); // performance
 			y += 10;
 
 			SetDParam(0, _network_player_info[nd->company].num_vehicle[0]);
@@ -962,7 +1071,7 @@
 			SetDParam(2, _network_player_info[nd->company].num_vehicle[2]);
 			SetDParam(3, _network_player_info[nd->company].num_vehicle[3]);
 			SetDParam(4, _network_player_info[nd->company].num_vehicle[4]);
-			DrawString(x, y, STR_NETWORK_VEHICLES, 2); // vehicles
+			DrawString(x, y, STR_NETWORK_VEHICLES, TC_GOLD); // vehicles
 			y += 10;
 
 			SetDParam(0, _network_player_info[nd->company].num_station[0]);
@@ -970,43 +1079,43 @@
 			SetDParam(2, _network_player_info[nd->company].num_station[2]);
 			SetDParam(3, _network_player_info[nd->company].num_station[3]);
 			SetDParam(4, _network_player_info[nd->company].num_station[4]);
-			DrawString(x, y, STR_NETWORK_STATIONS, 2); // stations
+			DrawString(x, y, STR_NETWORK_STATIONS, TC_GOLD); // stations
 			y += 10;
 
 			SetDParamStr(0, _network_player_info[nd->company].players);
-			DrawStringTruncated(x, y, STR_NETWORK_PLAYERS, 2, trunc_width); // players
+			DrawStringTruncated(x, y, STR_NETWORK_PLAYERS, TC_GOLD, trunc_width); // players
 		}
 	} break;
 
 	case WE_CLICK:
 		switch (e->we.click.widget) {
-		case 0: case 11: /* Close 'X' | Cancel button */
+		case NLWW_CLOSE:    // Close 'X'
+		case NLWW_CANCEL:   // Cancel button
 			ShowNetworkGameWindow();
 			break;
-		case 4: { /* Company list */
+		case NLWW_MATRIX: { // Company list
 			uint32 id_v = (e->we.click.pt.y - NET_PRC__OFFSET_TOP_WIDGET_COMPANY) / NET_PRC__SIZE_OF_ROW;
 
-			if (id_v >= w->vscroll.cap) return;
+			if (id_v >= w->vscroll.cap) break;
 
 			id_v += w->vscroll.pos;
 			nd->company = (id_v >= nd->server->info.companies_on) ? INVALID_PLAYER : NetworkLobbyFindCompanyIndex(id_v);
 			SetWindowDirty(w);
 		} break;
-		case 7: /* Join company */
-			if (nd->company != (byte)-1) {
-				_network_playas = nd->company;
-				NetworkClientConnectGame(_network_last_host, _network_last_port);
-			}
+		case NLWW_JOIN:     // Join company
+			/* Button can be clicked only when it is enabled */
+			_network_playas = nd->company;
+			NetworkClientConnectGame(_network_last_host, _network_last_port);
 			break;
-		case 8: /* New company */
+		case NLWW_NEW:      // New company
 			_network_playas = PLAYER_NEW_COMPANY;
 			NetworkClientConnectGame(_network_last_host, _network_last_port);
 			break;
-		case 9: /* Spectate game */
+		case NLWW_SPECTATE: // Spectate game
 			_network_playas = PLAYER_SPECTATOR;
 			NetworkClientConnectGame(_network_last_host, _network_last_port);
 			break;
-		case 10: /* Refresh */
+		case NLWW_REFRESH:  // Refresh
 			NetworkTCPQueryServer(_network_last_host, _network_last_port); // company info
 			NetworkUDPQueryServer(_network_last_host, _network_last_port); // general data
 			break;
@@ -1019,24 +1128,25 @@
 }
 
 static const Widget _network_lobby_window_widgets[] = {
-{   WWT_CLOSEBOX,   RESIZE_NONE,   BGC,     0,    10,     0,    13, STR_00C5,                  STR_018B_CLOSE_WINDOW },
-{    WWT_CAPTION,   RESIZE_NONE,   BGC,    11,   419,     0,    13, STR_NETWORK_GAME_LOBBY,    STR_NULL},
-{      WWT_PANEL,   RESIZE_NONE,   BGC,     0,   419,    14,   234, 0x0,                       STR_NULL},
-
-// company list
-{      WWT_PANEL,   RESIZE_NONE,   BTC,    10,   155,    38,    49, 0x0,                       STR_NULL},
-{     WWT_MATRIX,   RESIZE_NONE,   BGC,    10,   155,    50,   190, (10 << 8) + 1,             STR_NETWORK_COMPANY_LIST_TIP},
-{  WWT_SCROLLBAR,   RESIZE_NONE,   BGC,   156,   167,    38,   190, STR_NULL,                  STR_0190_SCROLL_BAR_SCROLLS_LIST},
+{   WWT_CLOSEBOX,   RESIZE_NONE,   BGC,     0,    10,     0,    13, STR_00C5,                    STR_018B_CLOSE_WINDOW },           // NLWW_CLOSE
+{    WWT_CAPTION,   RESIZE_NONE,   BGC,    11,   419,     0,    13, STR_NETWORK_GAME_LOBBY,      STR_NULL},
+{      WWT_PANEL,   RESIZE_NONE,   BGC,     0,   419,    14,   234, 0x0,                         STR_NULL},
+{       WWT_TEXT,   RESIZE_NONE,   BGC,    10,   419,    22,    34, STR_NETWORK_PREPARE_TO_JOIN, STR_NULL},
 
-// company/player info
-{      WWT_PANEL,   RESIZE_NONE,   BGC,   173,   404,    38,   190, 0x0,                       STR_NULL},
+/* company list */
+{      WWT_PANEL,   RESIZE_NONE,   BTC,    10,   155,    38,    49, 0x0,                         STR_NULL},
+{     WWT_MATRIX,   RESIZE_NONE,   BGC,    10,   155,    50,   190, (10 << 8) + 1,               STR_NETWORK_COMPANY_LIST_TIP},     // NLWW_MATRIX
+{  WWT_SCROLLBAR,   RESIZE_NONE,   BGC,   156,   167,    38,   190, 0x0,                         STR_0190_SCROLL_BAR_SCROLLS_LIST},
 
-// buttons
-{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,    10,   151,   200,   211, STR_NETWORK_JOIN_COMPANY,  STR_NETWORK_JOIN_COMPANY_TIP},
-{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,    10,   151,   215,   226, STR_NETWORK_NEW_COMPANY,   STR_NETWORK_NEW_COMPANY_TIP},
-{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   158,   268,   200,   211, STR_NETWORK_SPECTATE_GAME, STR_NETWORK_SPECTATE_GAME_TIP},
-{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   158,   268,   215,   226, STR_NETWORK_REFRESH,       STR_NETWORK_REFRESH_TIP},
-{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   278,   388,   200,   211, STR_012E_CANCEL,           STR_NULL},
+/* company/player info */
+{      WWT_PANEL,   RESIZE_NONE,   BGC,   173,   404,    38,   190, 0x0,                         STR_NULL},                         // NLWW_DETAILS
+
+/* buttons */
+{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,    10,   151,   200,   211, STR_NETWORK_JOIN_COMPANY,    STR_NETWORK_JOIN_COMPANY_TIP},     // NLWW_JOIN
+{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,    10,   151,   215,   226, STR_NETWORK_NEW_COMPANY,     STR_NETWORK_NEW_COMPANY_TIP},      // NLWW_NEW
+{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   158,   268,   200,   211, STR_NETWORK_SPECTATE_GAME,   STR_NETWORK_SPECTATE_GAME_TIP},    // NLWW_SPECTATE
+{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   158,   268,   215,   226, STR_NETWORK_REFRESH,         STR_NETWORK_REFRESH_TIP},          // NLWW_REFRESH
+{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   278,   388,   200,   211, STR_012E_CANCEL,             STR_NULL},                         // NLWW_CANCEL
 
 {   WIDGETS_END},
 };
@@ -1311,7 +1421,7 @@
 	switch (e->event) {
 	case WE_PAINT: {
 		int i, y, sel;
-		byte colour;
+		TextColour colour;
 		DrawWindowWidgets(w);
 
 		// Draw the actions
@@ -1323,9 +1433,9 @@
 
 			if (sel-- == 0) { // Selected item, highlight it
 				GfxFillRect(1, y, 150 - 2, y + CLNWND_ROWSIZE - 1, 0);
-				colour = 0xC;
+				colour = TC_WHITE;
 			} else {
-				colour = 0x10;
+				colour = TC_BLACK;
 			}
 
 			DoDrawString(_clientlist_action[i], 4, y, colour);
@@ -1362,7 +1472,7 @@
 	case WE_PAINT: {
 		NetworkClientInfo *ci;
 		int y, i = 0;
-		byte colour;
+		TextColour colour;
 
 		// Check if we need to reset the height
 		if (!CheckClientListHeight(w)) break;
@@ -1374,9 +1484,9 @@
 		FOR_ALL_ACTIVE_CLIENT_INFOS(ci) {
 			if (_selected_clientlist_item == i++) { // Selected item, highlight it
 				GfxFillRect(1, y, 248, y + CLNWND_ROWSIZE - 1, 0);
-				colour = 0xC;
+				colour = TC_WHITE;
 			} else {
-				colour = 0x10;
+				colour = TC_BLACK;
 			}
 
 			if (ci->client_index == NETWORK_SERVER_INDEX) {
@@ -1463,7 +1573,7 @@
 		uint8 progress; // used for progress bar
 		DrawWindowWidgets(w);
 
-		DrawStringCentered(125, 35, STR_NETWORK_CONNECTING_1 + _network_join_status, 14);
+		DrawStringCentered(125, 35, STR_NETWORK_CONNECTING_1 + _network_join_status, TC_GREY);
 		switch (_network_join_status) {
 			case NETWORK_JOIN_STATUS_CONNECTING: case NETWORK_JOIN_STATUS_AUTHORIZING:
 			case NETWORK_JOIN_STATUS_GETTING_COMPANY_INFO:
@@ -1471,13 +1581,13 @@
 				break;
 			case NETWORK_JOIN_STATUS_WAITING:
 				SetDParam(0, _network_join_waiting);
-				DrawStringCentered(125, 46, STR_NETWORK_CONNECTING_WAITING, 14);
+				DrawStringCentered(125, 46, STR_NETWORK_CONNECTING_WAITING, TC_GREY);
 				progress = 15; // third stage is 15%
 				break;
 			case NETWORK_JOIN_STATUS_DOWNLOADING:
 				SetDParam(0, _network_join_kbytes);
 				SetDParam(1, _network_join_kbytes_total);
-				DrawStringCentered(125, 46, STR_NETWORK_CONNECTING_DOWNLOADING, 14);
+				DrawStringCentered(125, 46, STR_NETWORK_CONNECTING_DOWNLOADING, TC_GREY);
 				/* Fallthrough */
 			default: /* Waiting is 15%, so the resting receivement of map is maximum 70% */
 				progress = 15 + _network_join_kbytes * (100 - 15) / _network_join_kbytes_total;
@@ -1685,23 +1795,11 @@
 {
 	switch (e->event) {
 	case WE_CREATE:
-		SendWindowMessage(WC_NEWS_WINDOW, 0, WE_CREATE, w->height, 0);
-		SETBIT(_no_scroll, SCROLL_CHAT); // do not scroll the game with the arrow-keys
 		break;
 
 	case WE_PAINT: {
-		static const StringID chat_captions[] = {
-			STR_NETWORK_CHAT_ALL_CAPTION,
-			STR_NETWORK_CHAT_COMPANY_CAPTION,
-			STR_NETWORK_CHAT_CLIENT_CAPTION
-		};
-		StringID msg;
-
 		DrawWindowWidgets(w);
 
-		assert(WP(w, chatquerystr_d).caption < lengthof(chat_captions));
-		msg = chat_captions[WP(w, chatquerystr_d).caption];
-		DrawStringRightAligned(w->widget[2].left - 2, w->widget[2].top + 1, msg, 16);
 		DrawEditBox(w, &WP(w, chatquerystr_d), 2);
 	} break;
 
@@ -1738,7 +1836,7 @@
 
 	case WE_DESTROY:
 		SendWindowMessage(WC_NEWS_WINDOW, 0, WE_DESTROY, 0, 0);
-		CLRBIT(_no_scroll, SCROLL_CHAT);
+		ClrBit(_no_scroll, SCROLL_CHAT);
 		break;
 	}
 }
@@ -1770,11 +1868,102 @@
 
 	w = AllocateWindowDesc(&_chat_window_desc);
 
-	LowerWindowWidget(w, 2);
+	w->LowerWidget(2);
 	WP(w, chatquerystr_d).caption = type; // Misuse of caption
 	WP(w, chatquerystr_d).dest    = dest;
 	WP(w, chatquerystr_d).afilter = CS_ALPHANUMERAL;
 	InitializeTextBuffer(&WP(w, chatquerystr_d).text, _edit_str_buf, lengthof(_edit_str_buf), 0);
 }
 
+/** Enum for NetworkGameWindow, referring to _network_game_window_widgets */
+enum NetworkCompanyPasswordWindowWidgets {
+	NCPWW_CLOSE,                    ///< Close 'X' button
+	NCPWW_CAPTION,                  ///< Caption of the whole window
+	NCPWW_BACKGROUND,               ///< The background of the interface
+	NCPWW_LABEL,                    ///< Label in front of the password field
+	NCPWW_PASSWORD,                 ///< Input field for the password
+	NCPWW_SAVE_AS_DEFAULT_PASSWORD, ///< Toggle 'button' for saving the current password as default password
+	NCPWW_CANCEL,                   ///< Close the window without changing anything
+	NCPWW_OK,                       ///< Safe the password etc.
+};
+
+static void NetworkCompanyPasswordWindowWndProc(Window *w, WindowEvent *e)
+{
+	switch (e->event) {
+		case WE_PAINT:
+			DrawWindowWidgets(w);
+			DrawEditBox(w, &WP(w, chatquerystr_d), 4);
+			break;
+
+		case WE_CLICK:
+			switch (e->we.click.widget) {
+				case NCPWW_OK: {
+					if (w->IsWidgetLowered(NCPWW_SAVE_AS_DEFAULT_PASSWORD)) {
+						snprintf(_network_default_company_pass, lengthof(_network_default_company_pass), "%s", _edit_str_buf);
+					}
+
+					/* empty password is a '*' because of console argument */
+					if (StrEmpty(_edit_str_buf)) snprintf(_edit_str_buf, lengthof(_edit_str_buf), "*");
+					char *password = _edit_str_buf;
+					NetworkChangeCompanyPassword(1, &password);
+				}
+
+				/* FALL THROUGH */
+				case NCPWW_CANCEL:
+					DeleteWindow(w);
+					break;
+
+				case NCPWW_SAVE_AS_DEFAULT_PASSWORD:
+					w->ToggleWidgetLoweredState(NCPWW_SAVE_AS_DEFAULT_PASSWORD);
+					SetWindowDirty(w);
+					break;
+			}
+			break;
+
+		case WE_MOUSELOOP:
+			HandleEditBox(w, &WP(w, chatquerystr_d), 4);
+			break;
+
+		case WE_KEYPRESS:
+			switch (HandleEditBoxKey(w, &WP(w, chatquerystr_d), 4, e)) {
+				case 1: // Return
+					/* FALLTHROUGH */
+				case 2: // Escape
+					DeleteWindow(w);
+					break;
+			}
+			break;
+	}
+}
+
+static const Widget _ncp_window_widgets[] = {
+{   WWT_CLOSEBOX, RESIZE_NONE, 14,   0,  10,  0, 13, STR_00C5,                          STR_018B_CLOSE_WINDOW},
+{    WWT_CAPTION, RESIZE_NONE, 14,  11, 299,  0, 13, STR_COMPANY_PASSWORD_CAPTION,      STR_018C_WINDOW_TITLE_DRAG_THIS},
+{      WWT_PANEL, RESIZE_NONE, 14,   0, 299, 14, 50, 0x0,                               STR_NULL},
+{       WWT_TEXT, RESIZE_NONE, 14,   5, 100, 19, 30, STR_COMPANY_PASSWORD,              STR_NULL},
+{      WWT_PANEL, RESIZE_NONE, 14, 101, 294, 19, 30, 0x0,                               STR_NULL},
+{    WWT_TEXTBTN, RESIZE_NONE, 14, 101, 294, 35, 46, STR_MAKE_DEFAULT_COMPANY_PASSWORD, STR_MAKE_DEFAULT_COMPANY_PASSWORD_TIP},
+{ WWT_PUSHTXTBTN, RESIZE_NONE, 14,   0, 149, 51, 62, STR_012E_CANCEL,                   STR_COMPANY_PASSWORD_CANCEL},
+{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 150, 299, 51, 62, STR_012F_OK,                       STR_COMPANY_PASSWORD_OK},
+{   WIDGETS_END},
+};
+
+static const WindowDesc _ncp_window_desc = {
+	WDP_AUTO, WDP_AUTO, 300, 63, 300, 63,
+	WC_COMPANY_PASSWORD_WINDOW, WC_NONE,
+	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
+	_ncp_window_widgets,
+	NetworkCompanyPasswordWindowWndProc
+};
+
+void ShowNetworkCompanyPasswordWindow()
+{
+	DeleteWindowById(WC_COMPANY_PASSWORD_WINDOW, 0);
+
+	_edit_str_buf[0] = '\0';
+	Window *w = AllocateWindowDesc(&_ncp_window_desc);
+	WP(w, chatquerystr_d).afilter = CS_ALPHANUMERAL;
+	InitializeTextBuffer(&WP(w, chatquerystr_d).text, _edit_str_buf, min(lengthof(_network_default_company_pass), lengthof(_edit_str_buf)), 0);
+}
+
 #endif /* ENABLE_NETWORK */