Changeset - r8937:f2f32ec9acdd
[Not reviewed]
master
0 4 0
rubidium - 17 years ago 2008-04-14 20:31:21
rubidium@openttd.org
(svn r12709) -Feature: show the last joined server. Heavily based on a patch by Yexo.
4 files changed with 60 insertions and 27 deletions:
0 comments (0 inline, 0 general)
src/lang/english.txt
Show inline comments
 
@@ -1360,12 +1360,14 @@ STR_NETWORK_START_SERVER                
 
STR_NETWORK_START_SERVER_TIP                                    :{BLACK}Start your own server
 

	
 
STR_NETWORK_GAME_NAME                                           :{BLACK}Name
 
STR_NETWORK_GAME_NAME_TIP                                       :{BLACK}Name of the game
 
STR_NETWORK_INFO_ICONS_TIP                                      :{BLACK}Language, server version, etc.
 
STR_NETWORK_CLICK_GAME_TO_SELECT                                :{BLACK}Click a game from the list to select it
 
STR_NETWORK_LAST_JOINED_SERVER                                  :{BLACK}The server you joined last time:
 
STR_NETWORK_CLICK_TO_SELECT_LAST                                :{BLACK}Click to select the server you played last time
 

	
 
STR_NETWORK_FIND_SERVER                                         :{BLACK}Find server
 
STR_NETWORK_FIND_SERVER_TIP                                     :{BLACK}Search network for a server
 
STR_NETWORK_ADD_SERVER                                          :{BLACK}Add server
 
STR_NETWORK_ADD_SERVER_TIP                                      :{BLACK}Adds a server to the list which will always be checked for running games.
 
STR_NETWORK_ENTER_IP                                            :{BLACK}Enter the address of the host
src/network/network_gamelist.cpp
Show inline comments
 
@@ -22,12 +22,14 @@ NetworkGameList *_network_game_list = NU
 
 * return the existing item instead of adding it again
 
 * @param ip the IP-address (inet_addr) of the to-be added item
 
 * @param port the port the server is running on
 
 * @return a point to the newly added or already existing item */
 
NetworkGameList *NetworkGameListAddItem(uint32 ip, uint16 port)
 
{
 
	if (ip == 0) return NULL;
 

	
 
	NetworkGameList *item, *prev_item;
 

	
 
	prev_item = NULL;
 
	for (item = _network_game_list; item != NULL; item = item->next) {
 
		if (item->ip == ip && item->port == port) return item;
 
		prev_item = item;
src/network/network_gui.cpp
Show inline comments
 
@@ -230,24 +230,60 @@ enum NetworkGameWindowWidgets {
 
	NGWW_CLIENTS,       ///< 'Clients' button
 
	NGWW_INFO,          ///< Third button in the game list panel
 

	
 
	NGWW_MATRIX,        ///< Panel with list of games
 
	NGWW_SCROLLBAR,     ///< Scrollbar of matrix
 

	
 
	NGWW_LASTJOINED_LABEL, ///< Label "Last joined server:"
 
	NGWW_LASTJOINED,    ///< Info about the last joined server
 

	
 
	NGWW_DETAILS,       ///< Panel with game details
 
	NGWW_JOIN,          ///< 'Join game' button
 
	NGWW_REFRESH,       ///< 'Refresh server' button
 
	NGWW_NEWGRF,        ///< 'NewGRF Settings' button
 

	
 
	NGWW_FIND,          ///< 'Find server' button
 
	NGWW_ADD,           ///< 'Add server' button
 
	NGWW_START,         ///< 'Start server' button
 
	NGWW_CANCEL,        ///< 'Cancel' button
 
};
 

	
 
/**
 
 * Draw a single server line.
 
 * @param cur_item  the server to draw.
 
 * @param y         from where to draw?
 
 * @param highlight does the line need to be highlighted?
 
 */
 
static void DrawServerLine(const Window *w, const NetworkGameList *cur_item, uint y, bool highlight)
 
{
 
	/* show highlighted item with a different colour */
 
	if (highlight) 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[NGWW_NAME].left + 5, y, STR_02BD, TC_BLACK, w->widget[NGWW_NAME].right - w->widget[NGWW_NAME].left - 5);
 

	
 
	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[NGWW_CLIENTS].left + 39, y, STR_NETWORK_GENERAL_ONLINE, TC_GOLD);
 

	
 
	/* 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[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[NGWW_INFO].left + 15, 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);
 
	}
 
}
 

	
 
/**
 
 * 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
 
@@ -258,13 +294,13 @@ static void NetworkGameWindowWndProc(Win
 
{
 
	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
 
			w->vscroll.cap = 13;
 
			w->vscroll.cap = 11;
 
			w->resize.step_height = NET_PRC__SIZE_OF_ROW;
 

	
 
			nd->field = NGWW_PLAYER;
 
			nd->server = NULL;
 

	
 
			WP(w, network_ql_d).sort_list = NULL;
 
@@ -311,50 +347,31 @@ static void NetworkGameWindowWndProc(Win
 
				case NGWW_INFO    - NGWW_NAME: DrawSortButtonState(w, NGWW_INFO,    arrow); break;
 
			}
 

	
 
			uint16 y = NET_PRC__OFFSET_TOP_WIDGET + 3;
 
			int32 n = 0;
 
			int32 pos = w->vscroll.pos;
 
			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) {
 
				pos--;
 
				cur_item = cur_item->next;
 
			}
 

	
 
			while (cur_item != NULL) {
 
				/* 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[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[NGWW_CLIENTS].left + 39, y, STR_NETWORK_GENERAL_ONLINE, TC_GOLD);
 

	
 
				/* 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[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[NGWW_INFO].left + 15, 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);
 
				}
 
				DrawServerLine(w, cur_item, y, cur_item == sel);
 

	
 
				cur_item = cur_item->next;
 
				y += NET_PRC__SIZE_OF_ROW;
 
				if (++n == w->vscroll.cap) break; // max number of games in the window
 
			}
 

	
 
			const NetworkGameList *last_joined = NetworkGameListAddItem(inet_addr(_network_last_host), _network_last_port);
 
			/* Draw the last joined server, if any */
 
			if (last_joined != NULL) DrawServerLine(w, last_joined, y = w->widget[NGWW_LASTJOINED].top + 3, last_joined == sel);
 

	
 
			/* Draw the right menu */
 
			GfxFillRect(w->widget[NGWW_DETAILS].left + 1, 43, w->widget[NGWW_DETAILS].right - 1, 92, 157);
 
			if (sel == NULL) {
 
				DrawStringCentered(w->widget[NGWW_DETAILS].left + 115, 58, STR_NETWORK_GAME_INFO, TC_FROMSTRING);
 
			} else if (!sel->online) {
 
				SetDParamStr(0, sel->info.server_name);
 
@@ -464,12 +481,20 @@ static void NetworkGameWindowWndProc(Win
 
					for (; id_v > 0 && cur_item != NULL; id_v--) cur_item = cur_item->next;
 

	
 
					nd->server = cur_item;
 
					SetWindowDirty(w);
 
				} break;
 

	
 
				case NGWW_LASTJOINED: {
 
					NetworkGameList *last_joined = NetworkGameListAddItem(inet_addr(_network_last_host), _network_last_port);
 
					if (last_joined != NULL) {
 
						nd->server = last_joined;
 
						SetWindowDirty(w);
 
					}
 
				} break;
 

	
 
				case NGWW_FIND: // Find server automatically
 
					switch (_network_lan_internet) {
 
						case 0: NetworkUDPSearchGame(); break;
 
						case 1: NetworkUDPQueryMasterServer(); break;
 
					}
 
					break;
 
@@ -594,14 +619,16 @@ static const Widget _network_game_window
 

	
 
/* 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_MATRIX,   RESIZE_RB,     BGC,    10,   190,    54,   236, (11 << 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}, // NGWW_SCROLLBAR
 
{     WWT_MATRIX,   RESIZE_RB,     BGC,    10,   190,    54,   208, (11 << 8) + 1,                    STR_NETWORK_CLICK_GAME_TO_SELECT}, // NGWW_MATRIX
 
{  WWT_SCROLLBAR,   RESIZE_LRB,    BGC,   191,   202,    42,   208, 0x0,                              STR_0190_SCROLL_BAR_SCROLLS_LIST}, // NGWW_SCROLLBAR
 
{       WWT_TEXT,   RESIZE_RTB,    BGC,    10,   190,   211,   222, STR_NETWORK_LAST_JOINED_SERVER,   STR_NULL},                         // NGWW_LASTJOINED_LABEL
 
{      WWT_PANEL,   RESIZE_RTB,    BGC,    10,   190,   223,   236, 0x0,                              STR_NETWORK_CLICK_TO_SELECT_LAST}, // NGWW_LASTJOINED
 

	
 
/* RIGHT SIDE */
 
{      WWT_PANEL,   RESIZE_LRB,    BGC,   210,   440,    42,   236, 0x0,                              STR_NULL},                         // NGWW_DETAILS
 

	
 
{ 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
src/settings.cpp
Show inline comments
 
@@ -1336,12 +1336,14 @@ static const SettingDescGlobVarList _net
 
	  SDTG_VAR("max_clients",          SLE_UINT8, S, 0, _network_game_info.clients_max,    10, 2, MAX_CLIENTS, 0, STR_NULL, NULL),
 
	  SDTG_VAR("max_spectators",       SLE_UINT8, S, 0, _network_game_info.spectators_max, 10, 0, MAX_CLIENTS, 0, STR_NULL, NULL),
 
	  SDTG_VAR("restart_game_year",    SLE_INT32, S,D0, _network_restart_game_year,    0, MIN_YEAR, MAX_YEAR, 1, STR_NULL, NULL),
 
	  SDTG_VAR("min_players",          SLE_UINT8, S, 0, _network_min_players,               0, 0, 10,   0, STR_NULL, NULL),
 
	SDTG_OMANY("server_lang",          SLE_UINT8, S, 0, _network_game_info.server_lang,     0, 35, "ANY|ENGLISH|GERMAN|FRENCH|BRAZILIAN|BULGARIAN|CHINESE|CZECH|DANISH|DUTCH|ESPERANTO|FINNISH|HUNGARIAN|ICELANDIC|ITALIAN|JAPANESE|KOREAN|LITHUANIAN|NORWEGIAN|POLISH|PORTUGUESE|ROMANIAN|RUSSIAN|SLOVAK|SLOVENIAN|SPANISH|SWEDISH|TURKISH|UKRAINIAN|AFRIKAANS|CROATIAN|CATALAN|ESTONIAN|GALICIAN|GREEK|LATVIAN", STR_NULL, NULL),
 
	 SDTG_BOOL("reload_cfg",                      S, 0, _network_reload_cfg,           false,              STR_NULL, NULL),
 
	  SDTG_STR("last_host",             SLE_STRB, S, 0, _network_last_host,            "0.0.0.0",          STR_NULL, NULL),
 
	  SDTG_VAR("last_port",           SLE_UINT16, S, 0, _network_last_port,            0, 0, UINT16_MAX, 0, STR_NULL ,NULL),
 
	  SDTG_END()
 
};
 
#endif /* ENABLE_NETWORK */
 

	
 
static const SettingDesc _gameopt_settings[] = {
 
	/* In version 4 a new difficulty setting has been added to the difficulty settings,
0 comments (0 inline, 0 general)