src/network/network_gui.cpp
changeset 7343 9bf495fb4b10
parent 7341 02515d0d4ced
child 7363 2600aa1a6b16
equal deleted inserted replaced
7342:c42f92fe1a60 7343:9bf495fb4b10
   229 	network_d *nd = &WP(w, network_ql_d).n;
   229 	network_d *nd = &WP(w, network_ql_d).n;
   230 	list_d *ld = &WP(w, network_ql_d).l;
   230 	list_d *ld = &WP(w, network_ql_d).l;
   231 
   231 
   232 	switch (e->event) {
   232 	switch (e->event) {
   233 	case WE_CREATE: /* Focus input box */
   233 	case WE_CREATE: /* Focus input box */
       
   234 		w->vscroll.cap = 13;
       
   235 		w->resize.step_height = NET_PRC__SIZE_OF_ROW;
       
   236 
   234 		nd->field = 3;
   237 		nd->field = 3;
   235 		nd->server = NULL;
   238 		nd->server = NULL;
   236 
   239 
   237 		WP(w, network_ql_d).sort_list = NULL;
   240 		WP(w, network_ql_d).sort_list = NULL;
   238 		ld->flags = VL_REBUILD | (_ng_sorting.order ? VL_DESC : VL_NONE);
   241 		ld->flags = VL_REBUILD | (_ng_sorting.order ? VL_DESC : VL_NONE);
   265 		DrawWindowWidgets(w);
   268 		DrawWindowWidgets(w);
   266 
   269 
   267 		DrawEditBox(w, &WP(w, network_ql_d).q, 3);
   270 		DrawEditBox(w, &WP(w, network_ql_d).q, 3);
   268 
   271 
   269 		DrawString(9, 23, STR_NETWORK_CONNECTION, 2);
   272 		DrawString(9, 23, STR_NETWORK_CONNECTION, 2);
   270 		DrawString(210, 23, STR_NETWORK_PLAYER_NAME, 2);
   273 		DrawString(w->widget[3].left - 100, 23, STR_NETWORK_PLAYER_NAME, 2);
   271 
   274 
   272 		/* Sort based on widgets: name, clients, compatibility */
   275 		/* Sort based on widgets: name, clients, compatibility */
   273 		switch (ld->sort_type) {
   276 		switch (ld->sort_type) {
   274 			case 6 - 6: DoDrawString(arrow, w->widget[6].right - 10, 42, 0x10); break;
   277 			case 6 - 6: DoDrawString(arrow, w->widget[6].right - 10, 42, 0x10); break;
   275 			case 7 - 6: DoDrawString(arrow, w->widget[7].right - 10, 42, 0x10); break;
   278 			case 7 - 6: DoDrawString(arrow, w->widget[7].right - 10, 42, 0x10); break;
   297 
   300 
   298 				SetDParam(0, cur_item->info.clients_on);
   301 				SetDParam(0, cur_item->info.clients_on);
   299 				SetDParam(1, cur_item->info.clients_max);
   302 				SetDParam(1, cur_item->info.clients_max);
   300 				SetDParam(2, cur_item->info.companies_on);
   303 				SetDParam(2, cur_item->info.companies_on);
   301 				SetDParam(3, cur_item->info.companies_max);
   304 				SetDParam(3, cur_item->info.companies_max);
   302 				DrawStringCentered(210, y, STR_NETWORK_GENERAL_ONLINE, 2);
   305 				DrawStringCentered(w->widget[7].left + 39, y, STR_NETWORK_GENERAL_ONLINE, 2);
   303 
   306 
   304 				// only draw icons if the server is online
   307 				// only draw icons if the server is online
   305 				if (cur_item->online) {
   308 				if (cur_item->online) {
   306 					// draw a lock if the server is password protected.
   309 					// draw a lock if the server is password protected.
   307 					if (cur_item->info.use_password) DrawSprite(SPR_LOCK, PAL_NONE, w->widget[8].left + 5, y - 1);
   310 					if (cur_item->info.use_password) DrawSprite(SPR_LOCK, PAL_NONE, w->widget[8].left + 5, y - 1);
   318 				if (++n == w->vscroll.cap) break; // max number of games in the window
   321 				if (++n == w->vscroll.cap) break; // max number of games in the window
   319 			}
   322 			}
   320 		}
   323 		}
   321 
   324 
   322 		/* Draw the right menu */
   325 		/* Draw the right menu */
   323 		GfxFillRect(311, 43, 539, 92, 157);
   326 		GfxFillRect(w->widget[15].left + 1, 43, w->widget[15].right - 1, 92, 157);
   324 		if (sel == NULL) {
   327 		if (sel == NULL) {
   325 			DrawStringCentered(425, 58, STR_NETWORK_GAME_INFO, 0);
   328 			DrawStringCentered(w->widget[15].left + 115, 58, STR_NETWORK_GAME_INFO, 0);
   326 		} else if (!sel->online) {
   329 		} else if (!sel->online) {
   327 			SetDParamStr(0, sel->info.server_name);
   330 			SetDParamStr(0, sel->info.server_name);
   328 			DrawStringCentered(425, 68, STR_ORANGE, 0); // game name
   331 			DrawStringCentered(w->widget[15].left + 115, 68, STR_ORANGE, 0); // game name
   329 
   332 
   330 			DrawStringCentered(425, 132, STR_NETWORK_SERVER_OFFLINE, 0); // server offline
   333 			DrawStringCentered(w->widget[15].left + 115, 132, STR_NETWORK_SERVER_OFFLINE, 0); // server offline
   331 		} else { // show game info
   334 		} else { // show game info
   332 			uint16 y = 100;
   335 			uint16 y = 100;
   333 			const uint16 x = w->widget[15].left + 5;
   336 			const uint16 x = w->widget[15].left + 5;
   334 
   337 
   335 			DrawStringCentered(425, 48, STR_NETWORK_GAME_INFO, 0);
   338 			DrawStringCentered(w->widget[15].left + 115, 48, STR_NETWORK_GAME_INFO, 0);
   336 
   339 
   337 
   340 
   338 			SetDParamStr(0, sel->info.server_name);
   341 			SetDParamStr(0, sel->info.server_name);
   339 			DrawStringCenteredTruncated(w->widget[15].left, w->widget[15].right, 62, STR_ORANGE, 16); // game name
   342 			DrawStringCenteredTruncated(w->widget[15].left, w->widget[15].right, 62, STR_ORANGE, 16); // game name
   340 
   343 
   379 			y += 10;
   382 			y += 10;
   380 
   383 
   381 			y += 2;
   384 			y += 2;
   382 
   385 
   383 			if (!sel->info.compatible) {
   386 			if (!sel->info.compatible) {
   384 				DrawStringCentered(425, y, sel->info.version_compatible ? STR_NETWORK_GRF_MISMATCH : STR_NETWORK_VERSION_MISMATCH, 0); // server mismatch
   387 				DrawStringCentered(w->widget[15].left + 115, y, sel->info.version_compatible ? STR_NETWORK_GRF_MISMATCH : STR_NETWORK_VERSION_MISMATCH, 0); // server mismatch
   385 			} else if (sel->info.clients_on == sel->info.clients_max) {
   388 			} else if (sel->info.clients_on == sel->info.clients_max) {
   386 				// Show: server full, when clients_on == clients_max
   389 				// Show: server full, when clients_on == clients_max
   387 				DrawStringCentered(425, y, STR_NETWORK_SERVER_FULL, 0); // server full
   390 				DrawStringCentered(w->widget[15].left + 115, y, STR_NETWORK_SERVER_FULL, 0); // server full
   388 			} else if (sel->info.use_password) {
   391 			} else if (sel->info.use_password) {
   389 				DrawStringCentered(425, y, STR_NETWORK_PASSWORD, 0); // password warning
   392 				DrawStringCentered(w->widget[15].left + 115, y, STR_NETWORK_PASSWORD, 0); // password warning
   390 			}
   393 			}
   391 
   394 
   392 			y += 10;
   395 			y += 10;
   393 		}
   396 		}
   394 	} break;
   397 	} break;
   395 
   398 
   396 	case WE_CLICK:
   399 	case WE_CLICK:
   397 		nd->field = e->we.click.widget;
   400 		nd->field = e->we.click.widget;
   398 		switch (e->we.click.widget) {
   401 		switch (e->we.click.widget) {
   399 		case 0: case 14: /* Close 'X' | Cancel button */
   402 		case 14: // Cancel button
   400 			DeleteWindowById(WC_NETWORK_WINDOW, 0);
   403 			DeleteWindowById(WC_NETWORK_WINDOW, 0);
   401 			break;
   404 			break;
   402 		case 4: case 5:
   405 		case 4: case 5:
   403 			ShowDropDownMenu(w, _lan_internet_types_dropdown, _network_lan_internet, 5, 0, 0); // do it for widget 5
   406 			ShowDropDownMenu(w, _lan_internet_types_dropdown, _network_lan_internet, 5, 0, 0); // do it for widget 5
   404 			break;
   407 			break;
   506 	case WE_ON_EDIT_TEXT:
   509 	case WE_ON_EDIT_TEXT:
   507 		NetworkAddServer(e->we.edittext.str);
   510 		NetworkAddServer(e->we.edittext.str);
   508 		NetworkRebuildHostList();
   511 		NetworkRebuildHostList();
   509 		break;
   512 		break;
   510 
   513 
       
   514 	case WE_RESIZE: {
       
   515 		w->vscroll.cap += e->we.sizing.diff.y / (int)w->resize.step_height;
       
   516 
       
   517 		w->widget[9].data = (w->vscroll.cap << 8) + 1;
       
   518 
       
   519 		int widget_width = w->widget[11].right - w->widget[11].left;
       
   520 		int space = (w->width - 4 * widget_width - 25) / 3;
       
   521 
       
   522 		int offset = 10;
       
   523 		for (uint i = 0; i < 4; i++) {
       
   524 			w->widget[11 + i].left  = offset;
       
   525 			offset += widget_width;
       
   526 			w->widget[11 + i].right = offset;
       
   527 			offset += space;
       
   528 		}
       
   529 	} break;
       
   530 
   511 	case WE_DESTROY: /* Nicely clean up the sort-list */
   531 	case WE_DESTROY: /* Nicely clean up the sort-list */
   512 		free(WP(w, network_ql_d).sort_list);
   532 		free(WP(w, network_ql_d).sort_list);
   513 		break;
   533 		break;
   514 	}
   534 	}
   515 }
   535 }
   516 
   536 
   517 static const Widget _network_game_window_widgets[] = {
   537 static const Widget _network_game_window_widgets[] = {
   518 {   WWT_CLOSEBOX,   RESIZE_NONE,   BGC,     0,    10,     0,    13, STR_00C5,                    STR_018B_CLOSE_WINDOW},
   538 {   WWT_CLOSEBOX,   RESIZE_NONE,   BGC,     0,    10,     0,    13, STR_00C5,                    STR_018B_CLOSE_WINDOW},
   519 {    WWT_CAPTION,   RESIZE_NONE,   BGC,    11,   549,     0,    13, STR_NETWORK_MULTIPLAYER,     STR_NULL},
   539 {    WWT_CAPTION,   RESIZE_RIGHT,  BGC,    11,   449,     0,    13, STR_NETWORK_MULTIPLAYER,     STR_NULL},
   520 {      WWT_PANEL,   RESIZE_NONE,   BGC,     0,   549,    14,   263, 0x0,                         STR_NULL},
   540 {      WWT_PANEL,   RESIZE_RB,     BGC,     0,   449,    14,   263, 0x0,                         STR_NULL},
   521 
   541 
   522 /* LEFT SIDE */
   542 /* LEFT SIDE */
   523 {      WWT_PANEL,   RESIZE_NONE,   BGC,   310,   461,    22,    33, 0x0,                         STR_NETWORK_ENTER_NAME_TIP},
   543 {      WWT_PANEL,   RESIZE_LR,     BGC,   290,   440,    22,    33, 0x0,                         STR_NETWORK_ENTER_NAME_TIP},
   524 
   544 
   525 {      WWT_INSET,   RESIZE_NONE,   BGC,    90,   181,    22,    33, STR_NETWORK_COMBO1,          STR_NETWORK_CONNECTION_TIP},
   545 {      WWT_INSET,   RESIZE_NONE,   BGC,    90,   181,    22,    33, STR_NETWORK_COMBO1,          STR_NETWORK_CONNECTION_TIP},
   526 {    WWT_TEXTBTN,   RESIZE_NONE,   BGC,   170,   180,    23,    32, STR_0225,                    STR_NETWORK_CONNECTION_TIP},
   546 {    WWT_TEXTBTN,   RESIZE_NONE,   BGC,   170,   180,    23,    32, STR_0225,                    STR_NETWORK_CONNECTION_TIP},
   527 
   547 
   528 { WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,    10,   170,    42,    53, STR_NETWORK_GAME_NAME,       STR_NETWORK_GAME_NAME_TIP},
   548 { WWT_PUSHTXTBTN,   RESIZE_RIGHT,  BTC,    10,    70,    42,    53, STR_NETWORK_GAME_NAME,       STR_NETWORK_GAME_NAME_TIP},
   529 { WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   171,   250,    42,    53, STR_NETWORK_CLIENTS_CAPTION, STR_NETWORK_CLIENTS_CAPTION_TIP},
   549 { WWT_PUSHTXTBTN,   RESIZE_LR,     BTC,    71,   150,    42,    53, STR_NETWORK_CLIENTS_CAPTION, STR_NETWORK_CLIENTS_CAPTION_TIP},
   530 { WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   251,   290,    42,    53, STR_EMPTY,                   STR_NETWORK_INFO_ICONS_TIP},
   550 { WWT_PUSHTXTBTN,   RESIZE_LR,     BTC,   151,   190,    42,    53, STR_EMPTY,                   STR_NETWORK_INFO_ICONS_TIP},
   531 
   551 
   532 {     WWT_MATRIX,   RESIZE_NONE,   BGC,    10,   290,    54,   236, (13 << 8) + 1,               STR_NETWORK_CLICK_GAME_TO_SELECT},
   552 {     WWT_MATRIX,   RESIZE_RB,     BGC,    10,   190,    54,   236, (13 << 8) + 1,               STR_NETWORK_CLICK_GAME_TO_SELECT},
   533 {  WWT_SCROLLBAR,   RESIZE_NONE,   BGC,   291,   302,    42,   236, STR_NULL,                    STR_0190_SCROLL_BAR_SCROLLS_LIST},
   553 {  WWT_SCROLLBAR,   RESIZE_LRB,    BGC,   191,   202,    42,   236, STR_NULL,                    STR_0190_SCROLL_BAR_SCROLLS_LIST},
   534 
   554 
   535 { WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,    30,   130,   246,   257, STR_NETWORK_FIND_SERVER,     STR_NETWORK_FIND_SERVER_TIP},
   555 { WWT_PUSHTXTBTN,   RESIZE_TB,     BTC,    10,   110,   246,   257, STR_NETWORK_FIND_SERVER,     STR_NETWORK_FIND_SERVER_TIP},
   536 { WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   180,   280,   246,   257, STR_NETWORK_ADD_SERVER,      STR_NETWORK_ADD_SERVER_TIP},
   556 { WWT_PUSHTXTBTN,   RESIZE_TB,     BTC,   118,   218,   246,   257, STR_NETWORK_ADD_SERVER,      STR_NETWORK_ADD_SERVER_TIP},
   537 
   557 
   538 /* RIGHT SIDE */
   558 /* RIGHT SIDE */
   539 { WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   315,   415,   246,   257, STR_NETWORK_START_SERVER,    STR_NETWORK_START_SERVER_TIP},
   559 { WWT_PUSHTXTBTN,   RESIZE_TB,     BTC,   226,   326,   246,   257, STR_NETWORK_START_SERVER,    STR_NETWORK_START_SERVER_TIP},
   540 { WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   430,   535,   246,   257, STR_012E_CANCEL,             STR_NULL},
   560 { WWT_PUSHTXTBTN,   RESIZE_TB,     BTC,   334,   434,   246,   257, STR_012E_CANCEL,             STR_NULL},
   541 
   561 
   542 {      WWT_PANEL,   RESIZE_NONE,   BGC,   310,   540,    42,   236, 0x0,                         STR_NULL},
   562 {      WWT_PANEL,   RESIZE_LRB,    BGC,   210,   440,    42,   236, 0x0,                         STR_NULL},
   543 
   563 
   544 { WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   315,   415,   215,   226, STR_NETWORK_JOIN_GAME,       STR_NULL},
   564 { WWT_PUSHTXTBTN,   RESIZE_LRTB,   BTC,   215,   315,   215,   226, STR_NETWORK_JOIN_GAME,       STR_NULL},
   545 { WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   430,   535,   215,   226, STR_NETWORK_REFRESH,         STR_NETWORK_REFRESH_TIP},
   565 { WWT_PUSHTXTBTN,   RESIZE_LRTB,   BTC,   330,   435,   215,   226, STR_NETWORK_REFRESH,         STR_NETWORK_REFRESH_TIP},
   546 
   566 
   547 { WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   430,   535,   197,   208, STR_NEWGRF_SETTINGS_BUTTON,  STR_NULL},
   567 { WWT_PUSHTXTBTN,   RESIZE_LRTB,   BTC,   330,   435,   197,   208, STR_NEWGRF_SETTINGS_BUTTON,  STR_NULL},
       
   568 
       
   569 {  WWT_RESIZEBOX,   RESIZE_LRTB,   BGC,   438,   449,   252,   263, 0x0,                         STR_RESIZE_BUTTON },
   548 
   570 
   549 {   WIDGETS_END},
   571 {   WIDGETS_END},
   550 };
   572 };
   551 
   573 
   552 static const WindowDesc _network_game_window_desc = {
   574 static const WindowDesc _network_game_window_desc = {
   553 	WDP_CENTER, WDP_CENTER, 550, 264, 550, 264,
   575 	WDP_CENTER, WDP_CENTER, 450, 264, 550, 264,
   554 	WC_NETWORK_WINDOW, WC_NONE,
   576 	WC_NETWORK_WINDOW, WC_NONE,
   555 	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
   577 	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
   556 	_network_game_window_widgets,
   578 	_network_game_window_widgets,
   557 	NetworkGameWindowWndProc,
   579 	NetworkGameWindowWndProc,
   558 };
   580 };
   559 
   581 
   560 void ShowNetworkGameWindow()
   582 void ShowNetworkGameWindow()
   580 	w = AllocateWindowDesc(&_network_game_window_desc);
   602 	w = AllocateWindowDesc(&_network_game_window_desc);
   581 	if (w != NULL) {
   603 	if (w != NULL) {
   582 		querystr_d *querystr = &WP(w, network_ql_d).q;
   604 		querystr_d *querystr = &WP(w, network_ql_d).q;
   583 
   605 
   584 		ttd_strlcpy(_edit_str_buf, _network_player_name, lengthof(_edit_str_buf));
   606 		ttd_strlcpy(_edit_str_buf, _network_player_name, lengthof(_edit_str_buf));
   585 		w->vscroll.cap = 13;
       
   586 
       
   587 		querystr->afilter = CS_ALPHANUMERAL;
   607 		querystr->afilter = CS_ALPHANUMERAL;
   588 		InitializeTextBuffer(&querystr->text, _edit_str_buf, lengthof(_edit_str_buf), 120);
   608 		InitializeTextBuffer(&querystr->text, _edit_str_buf, lengthof(_edit_str_buf), 120);
   589 
   609 
   590 		UpdateNetworkGameWindow(true);
   610 		UpdateNetworkGameWindow(true);
   591 	}
   611 	}