src/network/network_gui.cpp
branchNewGRF_ports
changeset 6719 4cc327ad39d5
parent 6574 e1d1a12faaf7
child 6720 35756db7e577
--- a/src/network/network_gui.cpp	Tue Mar 27 23:27:27 2007 +0000
+++ b/src/network/network_gui.cpp	Sat Jun 02 19:59:29 2007 +0000
@@ -84,15 +84,73 @@
 	STR_NETWORK_10_PLAYERS,
 	INVALID_STRING_ID
 };
-
+/* The strings are in alphabetical order (in English). */
 static const StringID _language_dropdown[] = {
 	STR_NETWORK_LANG_ANY,
+	STR_NETWORK_LANG_BRAZILIAN,
+	STR_NETWORK_LANG_BULGARIAN,
+	STR_NETWORK_LANG_CHINESE,
+	STR_NETWORK_LANG_CZECH,
+	STR_NETWORK_LANG_DANISH,
+	STR_NETWORK_LANG_DUTCH,
 	STR_NETWORK_LANG_ENGLISH,
+	STR_NETWORK_LANG_ESPERANTO,
+	STR_NETWORK_LANG_FINNISH,
+	STR_NETWORK_LANG_FRENCH,
 	STR_NETWORK_LANG_GERMAN,
-	STR_NETWORK_LANG_FRENCH,
+	STR_NETWORK_LANG_HUNGARIAN,
+	STR_NETWORK_LANG_ICELANDIC,
+	STR_NETWORK_LANG_ITALIAN,
+	STR_NETWORK_LANG_JAPANESE,
+	STR_NETWORK_LANG_KOREAN,
+	STR_NETWORK_LANG_LITHUANIAN,
+	STR_NETWORK_LANG_NORWEGIAN,
+	STR_NETWORK_LANG_POLISH,
+	STR_NETWORK_LANG_PORTUGUESE,
+	STR_NETWORK_LANG_ROMANIAN,
+	STR_NETWORK_LANG_RUSSIAN,
+	STR_NETWORK_LANG_SLOVAK,
+	STR_NETWORK_LANG_SLOVENIAN,
+	STR_NETWORK_LANG_SPANISH,
+	STR_NETWORK_LANG_SWEDISH,
+	STR_NETWORK_LANG_TURKISH,
+	STR_NETWORK_LANG_UKRAINIAN,
 	INVALID_STRING_ID
 };
 
+/* Used to map the _server_lang value to the sorted string. */
+static const int _server_lang_to_string[] = {
+	 0, // Any
+	 7, // English
+	11, // German
+	10, // French
+	 1, // Brazilian
+	 2, // Bulgarian
+	 3, // Chinese
+	 4, // Czech
+	 5, // Danish
+	 6, // Dutch
+	 8, // Esperanto
+	 9, // Finnish
+	12, // Hungarian
+	13, // Icelandic
+	14, // Italian
+	15, // Japanese
+	16, // Korean
+	17, // Lithuanian
+	18, // Norwegian
+	19, // Polish
+	20, // Portuguese
+	21, // Romanian
+	22, // Russian
+	23, // Slovak
+	24, // Slovenian
+	25, // Spanish
+	26, // Swedish
+	27, // Turkish
+	28, // Ukrainian
+};
+
 enum {
 	NET_PRC__OFFSET_TOP_WIDGET          = 54,
 	NET_PRC__OFFSET_TOP_WIDGET_COMPANY  = 52,
@@ -342,7 +400,7 @@
 			DrawString(x, y, STR_NETWORK_CLIENTS, 2);
 			y += 10;
 
-			SetDParam(0, _language_dropdown[sel->info.server_lang]);
+			SetDParam(0, _language_dropdown[_server_lang_to_string[sel->info.server_lang]]);
 			DrawString(x, y, STR_NETWORK_LANGUAGE, 2); // server language
 			y += 10;
 
@@ -385,7 +443,7 @@
 
 			y += 10;
 		}
-	}	break;
+	} break;
 
 	case WE_CLICK:
 		nd->field = e->we.click.widget;
@@ -452,7 +510,7 @@
 			if (nd->server != NULL) ShowNewGRFSettings(false, false, false, &nd->server->info.grfconfig);
 			break;
 
-	}	break;
+	} break;
 
 	case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */
 		switch (e->we.dropdown.button) {
@@ -609,7 +667,7 @@
 		SetDParam( 9, _players_dropdown[_network_game_info.clients_max]);
 		SetDParam(11, _players_dropdown[_network_game_info.companies_max]);
 		SetDParam(13, _players_dropdown[_network_game_info.spectators_max]);
-		SetDParam(15, _language_dropdown[_network_game_info.server_lang]);
+		SetDParam(15, _language_dropdown[_server_lang_to_string[_network_game_info.server_lang]]);
 		DrawWindowWidgets(w);
 
 		GfxFillRect(11, 63, 258, 215, 0xD7);
@@ -644,7 +702,7 @@
 
 			if (y >= w->vscroll.cap * NSSWND_ROWSIZE + NSSWND_START) break;
 		}
-	}	break;
+	} break;
 
 	case WE_CLICK:
 		nd->field = e->we.click.widget;
@@ -680,7 +738,7 @@
 			ShowDropDownMenu(w, _players_dropdown, _network_game_info.spectators_max, 14, 0, 0);
 			break;
 		case 15: case 16: /* Language */
-			ShowDropDownMenu(w, _language_dropdown, _network_game_info.server_lang, 16, 0, 0);
+			ShowDropDownMenu(w, _language_dropdown, _server_lang_to_string[_network_game_info.server_lang], 16, 0, 0);
 			break;
 		case 17: /* Start game */
 			_is_network_server = true;
@@ -715,7 +773,13 @@
 			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: _network_game_info.server_lang    = e->we.dropdown.index;        break;
+			case 16:
+				for (uint i = 0; i < lengthof(_server_lang_to_string); i++) {
+					if (_server_lang_to_string[i] == e->we.dropdown.index) {
+						_network_game_info.server_lang = i;
+					}
+				}
+				break;
 		}
 
 		SetWindowDirty(w);
@@ -789,7 +853,7 @@
 	_saveload_mode = SLD_NEW_GAME;
 	BuildFileList();
 	w->vscroll.cap = 12;
-	w->vscroll.count = _fios_num+1;
+	w->vscroll.count = _fios_num + 1;
 
 	WP(w, network_ql_d).q.afilter = CS_ALPHANUMERAL;
 	InitializeTextBuffer(&WP(w, network_ql_d).q.text, _edit_str_buf, lengthof(_edit_str_buf), 160);
@@ -914,7 +978,7 @@
 			SetDParamStr(0, _network_player_info[nd->company].players);
 			DrawStringTruncated(x, y, STR_NETWORK_PLAYERS, 2, trunc_width); // players
 		}
-	}	break;
+	} break;
 
 	case WE_CLICK:
 		switch (e->we.click.widget) {
@@ -929,7 +993,7 @@
 			id_v += w->vscroll.pos;
 			nd->company = (id_v >= nd->server->info.companies_on) ? INVALID_PLAYER : NetworkLobbyFindCompanyIndex(id_v);
 			SetWindowDirty(w);
-		}	break;
+		} break;
 		case 7: /* Join company */
 			if (nd->company != (byte)-1) {
 				_network_playas = nd->company;
@@ -948,7 +1012,7 @@
 			NetworkTCPQueryServer(_network_last_host, _network_last_port); // company info
 			NetworkUDPQueryServer(_network_last_host, _network_last_port); // general data
 			break;
-		}	break;
+		} break;
 
 	case WE_MESSAGE:
 		SetWindowDirty(w);
@@ -1265,7 +1329,7 @@
 
 			DoDrawString(_clientlist_action[i], 4, y, colour);
 		}
-	}	break;
+	} break;
 
 	case WE_POPUPMENU_SELECT: {
 		// We selected an action
@@ -1275,7 +1339,7 @@
 			HandleClientListPopupClick(index, WP(w,menu_d).main_button);
 
 		DeleteWindowById(WC_TOOLBAR_MENU, 0);
-	}	break;
+	} break;
 
 	case WE_POPUPMENU_OVER: {
 		// Our mouse hoovers over an action? Select it!
@@ -1327,7 +1391,7 @@
 
 			y += CLNWND_ROWSIZE;
 		}
-	}	break;
+	} break;
 
 	case WE_CLICK:
 		// Show the popup with option
@@ -1420,7 +1484,7 @@
 
 		/* Draw nice progress bar :) */
 		DrawFrameRect(20, 18, (int)((w->width - 20) * progress / 100), 28, 10, FR_NONE);
-	}	break;
+	} break;
 
 	case WE_CLICK:
 		switch (e->we.click.widget) {
@@ -1469,7 +1533,7 @@
 	if (w != NULL) w->parent = FindWindowById(WC_NETWORK_WINDOW, 0);
 }
 
-static void SendChat(const char *buf, DestType type, byte dest)
+static void SendChat(const char *buf, DestType type, int dest)
 {
 	if (buf[0] == '\0') return;
 	if (!_network_server) {
@@ -1533,7 +1597,7 @@
 static void ChatTabCompletion(Window *w)
 {
 	static char _chat_tab_completion_buf[lengthof(_edit_str_buf)];
-	Textbuf *tb = &WP(w, querystr_d).text;
+	Textbuf *tb = &WP(w, chatquerystr_d).text;
 	uint len, tb_len;
 	uint item;
 	char *tb_buf, *pre_buf;
@@ -1591,7 +1655,7 @@
 			}
 
 			/* Update the textbuffer */
-			UpdateTextBufferSize(&WP(w, querystr_d).text);
+			UpdateTextBufferSize(&WP(w, chatquerystr_d).text);
 
 			SetWindowDirty(w);
 			free(pre_buf);
@@ -1605,17 +1669,17 @@
 		_chat_tab_completion_active = false;
 
 		/* Update the textbuffer */
-		UpdateTextBufferSize(&WP(w, querystr_d).text);
+		UpdateTextBufferSize(&WP(w, chatquerystr_d).text);
 
 		SetWindowDirty(w);
 	}
 	free(pre_buf);
 }
 
-/* uses querystr_d WP macro
- * uses querystr_d->caption to store
- * - type of chat message (Private/Team/All) in bytes 0-7
- * - destination of chat message in the case of Team/Private in bytes 8-15 */
+/*
+ * uses chatquerystr_d WP macro
+ * uses chatquerystr_d->caption to store type of chat message (Private/Team/All)
+ */
 static void ChatWindowWndProc(Window *w, WindowEvent *e)
 {
 	switch (e->event) {
@@ -1634,25 +1698,25 @@
 
 		DrawWindowWidgets(w);
 
-		assert(GB(WP(w, querystr_d).caption, 0, 8) < lengthof(chat_captions));
-		msg = chat_captions[GB(WP(w, querystr_d).caption, 0, 8)];
+		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, querystr_d), 2);
+		DrawEditBox(w, &WP(w, chatquerystr_d), 2);
 	} break;
 
 	case WE_CLICK:
 		switch (e->we.click.widget) {
 			case 3: { /* Send */
-				DestType type = (DestType)GB(WP(w, querystr_d).caption, 0, 8);
-				byte dest = GB(WP(w, querystr_d).caption, 8, 8);
-				SendChat(WP(w, querystr_d).text.buf, type, dest);
+				DestType type = (DestType)WP(w, chatquerystr_d).caption;
+				int dest = WP(w, chatquerystr_d).dest;
+				SendChat(WP(w, chatquerystr_d).text.buf, type, dest);
 			} /* FALLTHROUGH */
 			case 0: /* Cancel */ DeleteWindow(w); break;
 		}
 		break;
 
 	case WE_MOUSELOOP:
-		HandleEditBox(w, &WP(w, querystr_d), 2);
+		HandleEditBox(w, &WP(w, chatquerystr_d), 2);
 		break;
 
 	case WE_KEYPRESS:
@@ -1660,11 +1724,11 @@
 			ChatTabCompletion(w);
 		} else {
 			_chat_tab_completion_active = false;
-			switch (HandleEditBoxKey(w, &WP(w, querystr_d), 2, e)) {
+			switch (HandleEditBoxKey(w, &WP(w, chatquerystr_d), 2, e)) {
 				case 1: { /* Return */
-				DestType type = (DestType)GB(WP(w, querystr_d).caption, 0, 8);
-				byte dest = GB(WP(w, querystr_d).caption, 8, 8);
-				SendChat(WP(w, querystr_d).text.buf, type, dest);
+				DestType type = (DestType)WP(w, chatquerystr_d).caption;
+				int dest = WP(w, chatquerystr_d).dest;
+				SendChat(WP(w, chatquerystr_d).text.buf, type, dest);
 			} /* FALLTHROUGH */
 				case 2: /* Escape */ DeleteWindow(w); break;
 			}
@@ -1694,7 +1758,7 @@
 	ChatWindowWndProc
 };
 
-void ShowNetworkChatQueryWindow(DestType type, byte dest)
+void ShowNetworkChatQueryWindow(DestType type, int dest)
 {
 	Window *w;
 
@@ -1706,9 +1770,10 @@
 	w = AllocateWindowDesc(&_chat_window_desc);
 
 	LowerWindowWidget(w, 2);
-	WP(w, querystr_d).caption = GB(type, 0, 8) | (dest << 8); // Misuse of caption
-	WP(w, querystr_d).afilter = CS_ALPHANUMERAL;
-	InitializeTextBuffer(&WP(w, querystr_d).text, _edit_str_buf, lengthof(_edit_str_buf), 0);
+	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);
 }
 
 #endif /* ENABLE_NETWORK */