Changeset - r7439:de9d8b2637aa
[Not reviewed]
master
0 3 0
rubidium - 17 years ago 2007-08-14 10:46:38
rubidium@openttd.org
(svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
3 files changed with 114 insertions and 98 deletions:
0 comments (0 inline, 0 general)
src/lang/english.txt
Show inline comments
 
@@ -1364,52 +1364,41 @@ STR_NETWORK_GRF_MISMATCH                
 

	
 
STR_NETWORK_JOIN_GAME                                           :{BLACK}Join game
 

	
 

	
 
STR_NETWORK_START_GAME_WINDOW                                   :{WHITE}Start new multiplayer game
 

	
 
STR_NETWORK_NEW_GAME_NAME                                       :{BLACK}Game name:
 
STR_NETWORK_NEW_GAME_NAME_TIP                                   :{BLACK}The game name will be displayed to other players in the multiplayer game selection menu
 
STR_NETWORK_SET_PASSWORD                                        :{BLACK}Set password
 
STR_NETWORK_PASSWORD_TIP                                        :{BLACK}Protect your game with a password if you don't want it to be publicly accessible
 
STR_NETWORK_SELECT_MAP                                          :{BLACK}Select a map:
 
STR_NETWORK_SELECT_MAP_TIP                                      :{BLACK}Which map do you want to play?
 
STR_NETWORK_NUMBER_OF_CLIENTS                                   :{BLACK}Max clients:
 
STR_NETWORK_NUMBER_OF_CLIENTS_TIP                               :{BLACK}Choose the maximum number of clients. Not all slots need to be filled
 
STR_NETWORK_COMBO1                                              :{BLACK}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{STRING}
 
STR_NETWORK_LAN_INTERNET_COMBO                                  :{BLACK}{SKIP}{STRING}
 
STR_NETWORK_LAN                                                 :LAN
 
STR_NETWORK_INTERNET                                            :Internet
 
STR_NETWORK_LAN_INTERNET                                        :LAN / Internet
 
STR_NETWORK_INTERNET_ADVERTISE                                  :Internet (advertise)
 
STR_NETWORK_COMBO2                                              :{BLACK}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{STRING}
 
STR_NETWORK_0_PLAYERS                                           :0 players
 
STR_NETWORK_1_PLAYERS                                           :1 player
 
STR_NETWORK_2_PLAYERS                                           :2 players
 
STR_NETWORK_3_PLAYERS                                           :3 players
 
STR_NETWORK_4_PLAYERS                                           :4 players
 
STR_NETWORK_5_PLAYERS                                           :5 players
 
STR_NETWORK_6_PLAYERS                                           :6 players
 
STR_NETWORK_7_PLAYERS                                           :7 players
 
STR_NETWORK_8_PLAYERS                                           :8 players
 
STR_NETWORK_9_PLAYERS                                           :9 players
 
STR_NETWORK_10_PLAYERS                                          :10 players
 
STR_NETWORK_CLIENTS_SELECT                                      :{BLACK}{SKIP}{SKIP}{NUM} client{P "" s}
 
STR_NETWORK_NUMBER_OF_CLIENTS                                   :{BLACK}Max clients:
 
STR_NETWORK_NUMBER_OF_CLIENTS_TIP                               :{BLACK}Choose the maximum number of clients. Not all slots need to be filled
 
STR_NETWORK_COMPANIES_SELECT                                    :{BLACK}{SKIP}{SKIP}{SKIP}{NUM} compan{P y ies}
 
STR_NETWORK_NUMBER_OF_COMPANIES                                 :{BLACK}Max companies:
 
STR_NETWORK_NUMBER_OF_COMPANIES_TIP                             :{BLACK}Limit the server to a certain amount of companies
 
STR_NETWORK_COMBO3                                              :{BLACK}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{STRING}
 
STR_NETWORK_SPECTATORS_SELECT                                   :{BLACK}{SKIP}{SKIP}{SKIP}{SKIP}{NUM} spectator{P "" s}
 
STR_NETWORK_NUMBER_OF_SPECTATORS                                :{BLACK}Max spectators:
 
STR_NETWORK_NUMBER_OF_SPECTATORS_TIP                            :{BLACK}Limit the server to a certain amount of spectators
 
STR_NETWORK_COMBO4                                              :{BLACK}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{STRING}
 
STR_NETWORK_LANGUAGE_SPOKEN                                     :{BLACK}Language spoken:
 
STR_NETWORK_LANGUAGE_TIP                                        :{BLACK}Other players will know which language is spoken on the server
 
STR_NETWORK_COMBO5                                              :{BLACK}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{STRING}
 
STR_NETWORK_LANGUAGE_COMBO                                      :{BLACK}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{STRING}
 
STR_NETWORK_START_GAME                                          :{BLACK}Start Game
 
STR_NETWORK_START_GAME_TIP                                      :{BLACK}Start a new network game from a random map, or scenario
 
STR_NETWORK_LOAD_GAME                                           :{BLACK}Load Game
 
STR_NETWORK_LOAD_GAME_TIP                                       :{BLACK}Resume an earlier saved multiplayer game (be sure to connect as the correct player)
 

	
 
############ Leave those lines in this order!!
 
STR_NETWORK_LANG_ANY                                            :Any
 
STR_NETWORK_LANG_ENGLISH                                        :English
 
STR_NETWORK_LANG_GERMAN                                         :German
 
STR_NETWORK_LANG_FRENCH                                         :French
 
STR_NETWORK_LANG_BRAZILIAN                                      :Brazilian
 
STR_NETWORK_LANG_BULGARIAN                                      :Bulgarian
src/network/network_gui.cpp
Show inline comments
 
@@ -28,24 +28,25 @@
 
#include "../town.h"
 
#include "../newgrf.h"
 
#include "../helpers.hpp"
 

	
 
#define BGC 5
 
#define BTC 15
 

	
 
struct network_d {
 
	PlayerID company;        // select company in network lobby
 
	byte field;              // select text-field in start-server and game-listing
 
	NetworkGameList *server; // selected server in lobby and game-listing
 
	FiosItem *map;           // selected map in start-server
 
	byte widget_id;          ///< The widget that has the pop-up input menu
 
};
 
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(network_d));
 

	
 
struct network_ql_d {
 
	network_d n;                 // see above; general stuff
 
	querystr_d q;                // text-input in start-server and game-listing
 
	NetworkGameList **sort_list; // list of games (sorted)
 
	list_d l;                    // accompanying list-administration
 
};
 
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(network_ql_d));
 

	
 
/* Global to remember sorting after window has been closed */
 
@@ -61,39 +62,24 @@ extern void SwitchMode(int new_mode);
 
static const StringID _connection_types_dropdown[] = {
 
	STR_NETWORK_LAN_INTERNET,
 
	STR_NETWORK_INTERNET_ADVERTISE,
 
	INVALID_STRING_ID
 
};
 

	
 
static const StringID _lan_internet_types_dropdown[] = {
 
	STR_NETWORK_LAN,
 
	STR_NETWORK_INTERNET,
 
	INVALID_STRING_ID
 
};
 

	
 
static const StringID _players_dropdown[] = {
 
	STR_NETWORK_0_PLAYERS,
 
	STR_NETWORK_1_PLAYERS,
 
	STR_NETWORK_2_PLAYERS,
 
	STR_NETWORK_3_PLAYERS,
 
	STR_NETWORK_4_PLAYERS,
 
	STR_NETWORK_5_PLAYERS,
 
	STR_NETWORK_6_PLAYERS,
 
	STR_NETWORK_7_PLAYERS,
 
	STR_NETWORK_8_PLAYERS,
 
	STR_NETWORK_9_PLAYERS,
 
	STR_NETWORK_10_PLAYERS,
 
	INVALID_STRING_ID
 
};
 

	
 
static StringID _language_dropdown[NETLANG_COUNT + 1] = {STR_NULL};
 

	
 
void SortNetworkLanguages()
 
{
 
	/* Init the strings */
 
	if (_language_dropdown[0] == STR_NULL) {
 
		for (int i = 0; i < NETLANG_COUNT; i++) _language_dropdown[i] = STR_NETWORK_LANG_ANY + i;
 
		_language_dropdown[NETLANG_COUNT] = INVALID_STRING_ID;
 
	}
 

	
 
	/* Sort the strings (we don't move 'any' and the 'invalid' one) */
 
	qsort(&_language_dropdown[1], NETLANG_COUNT - 1, sizeof(StringID), &StringIDSorter);
 
@@ -255,25 +241,25 @@ static void NetworkGameWindowWndProc(Win
 
		SetWindowWidgetDisabledState(w, 17, sel == NULL);
 
		/* Join Button disabling conditions */
 
		SetWindowWidgetDisabledState(w, 16, 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 ||
 
				!sel->online ||
 
				sel->info.grfconfig == NULL);
 

	
 
		SetDParam(0, 0x00);
 
		SetDParam(7, _lan_internet_types_dropdown[_network_lan_internet]);
 
		SetDParam(1, _lan_internet_types_dropdown[_network_lan_internet]);
 
		DrawWindowWidgets(w);
 

	
 
		DrawEditBox(w, &WP(w, network_ql_d).q, 3);
 

	
 
		DrawString(9, 23, STR_NETWORK_CONNECTION, 2);
 
		DrawString(w->widget[3].left - 100, 23, STR_NETWORK_PLAYER_NAME, 2);
 

	
 
		/* 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;
 
@@ -526,56 +512,56 @@ static void NetworkGameWindowWndProc(Win
 
			w->widget[11 + i].right = offset;
 
			offset += space;
 
		}
 
	} break;
 

	
 
	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},
 
{    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},
 
{   WWT_CLOSEBOX,   RESIZE_NONE,   BGC,     0,    10,     0,    13, STR_00C5,                       STR_018B_CLOSE_WINDOW},
 
{    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_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_COMBO1,          STR_NETWORK_CONNECTION_TIP},
 
{    WWT_TEXTBTN,   RESIZE_NONE,   BGC,   170,   180,    23,    32, STR_0225,                    STR_NETWORK_CONNECTION_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_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_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_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},
 
{     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},
 

	
 
{ 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_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},
 

	
 
/* 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_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},
 
{      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},
 
{ WWT_PUSHTXTBTN,   RESIZE_LRTB,   BTC,   330,   435,   215,   226, STR_NETWORK_REFRESH,         STR_NETWORK_REFRESH_TIP},
 
{ 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},
 
{ WWT_PUSHTXTBTN,   RESIZE_LRTB,   BTC,   330,   435,   197,   208, STR_NEWGRF_SETTINGS_BUTTON,     STR_NULL},
 

	
 
{  WWT_RESIZEBOX,   RESIZE_LRTB,   BGC,   438,   449,   252,   263, 0x0,                         STR_RESIZE_BUTTON },
 
{  WWT_RESIZEBOX,   RESIZE_LRTB,   BGC,   438,   449,   252,   263, 0x0,                            STR_RESIZE_BUTTON },
 

	
 
{   WIDGETS_END},
 
};
 

	
 
static const WindowDesc _network_game_window_desc = {
 
	WDP_CENTER, WDP_CENTER, 450, 264, 550, 264,
 
	WC_NETWORK_WINDOW, WC_NONE,
 
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
 
	_network_game_window_widgets,
 
	NetworkGameWindowWndProc,
 
};
 

	
 
@@ -622,29 +608,29 @@ static void NetworkStartServerWindowWndP
 
	network_d *nd = &WP(w, network_ql_d).n;
 

	
 
	switch (e->event) {
 
	case WE_CREATE: /* focus input box */
 
		nd->field = 3;
 
		_network_game_info.use_password = (_network_server_password[0] != '\0');
 
		break;
 

	
 
	case WE_PAINT: {
 
		int y = NSSWND_START, pos;
 
		const FiosItem *item;
 

	
 
		SetDParam( 7, _connection_types_dropdown[_network_advertise]);
 
		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, STR_NETWORK_LANG_ANY + _network_game_info.server_lang);
 
		SetDParam(1, _connection_types_dropdown[_network_advertise]);
 
		SetDParam(2, _network_game_info.clients_max);
 
		SetDParam(3, _network_game_info.companies_max);
 
		SetDParam(4, _network_game_info.spectators_max);
 
		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);
 

	
 
		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);
 
@@ -667,82 +653,105 @@ static void NetworkStartServerWindowWndP
 
			}
 
			pos++;
 
			y += NSSWND_ROWSIZE;
 

	
 
			if (y >= w->vscroll.cap * NSSWND_ROWSIZE + NSSWND_START) break;
 
		}
 
	} break;
 

	
 
	case WE_CLICK:
 
		nd->field = e->we.click.widget;
 
		switch (e->we.click.widget) {
 
		case 0: /* Close 'X' */
 
		case 19: /* Cancel button */
 
		case 22: /* Cancel button */
 
			ShowNetworkGameWindow();
 
			break;
 

	
 
		case 4: /* Set password button */
 
			nd->widget_id = 4;
 
			ShowQueryString(BindCString(_network_server_password), STR_NETWORK_SET_PASSWORD, 20, 250, w, CS_ALPHANUMERAL);
 
			break;
 

	
 
		case 5: { /* Select map */
 
			int y = (e->we.click.pt.y - NSSWND_START) / NSSWND_ROWSIZE;
 

	
 
			y += w->vscroll.pos;
 
			if (y >= w->vscroll.count) return;
 

	
 
			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
 
			break;
 
		case 9: case 10: /* Number of Players (hide 0 and 1 players) */
 
			ShowDropDownMenu(w, _players_dropdown, _network_game_info.clients_max, 10, 0, 3);
 
		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
 
			/* 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;
 
				}
 
			}
 
			_left_button_clicked = false;
 
			break;
 
		case 11: case 12: /* Number of Companies (hide 0, 9 and 10 companies; max is 8) */
 
			ShowDropDownMenu(w, _players_dropdown, _network_game_info.companies_max, 12, 0, 1537);
 
		case 10: // Click on number of players
 
			nd->widget_id = 10;
 
			SetDParam(0, _network_game_info.clients_max);
 
			ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_NETWORK_NUMBER_OF_CLIENTS, 3, 50, w, CS_NUMERAL);
 
			break;
 
		case 13: case 14: /* Number of Spectators */
 
			ShowDropDownMenu(w, _players_dropdown, _network_game_info.spectators_max, 14, 0, 0);
 
		case 13: // Click on number of companies
 
			nd->widget_id = 13;
 
			SetDParam(0, _network_game_info.companies_max);
 
			ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_NETWORK_NUMBER_OF_COMPANIES, 3, 50, w, CS_NUMERAL);
 
			break;
 
		case 15: case 16: { /* Language */
 
		case 16: // Click on number of companies
 
			nd->widget_id = 16;
 
			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 */
 
			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) {
 
					sel = i;
 
					break;
 
				}
 
			}
 
			ShowDropDownMenu(w, _language_dropdown, sel, 16, 0, 0);
 
			ShowDropDownMenu(w, _language_dropdown, sel, 19, 0, 0);
 
			break;
 
		}
 
		case 17: /* Start game */
 
		case 20: /* Start game */
 
			_is_network_server = true;
 

	
 
			if (nd->map == NULL) { // start random new game
 
				ShowGenerateLandscape();
 
			} else { // load a scenario
 
				char *name = FiosBrowseTo(nd->map);
 
				if (name != NULL) {
 
					SetFiosType(nd->map->type);
 
					ttd_strlcpy(_file_to_saveload.name, name, sizeof(_file_to_saveload.name));
 
					ttd_strlcpy(_file_to_saveload.title, nd->map->title, sizeof(_file_to_saveload.title));
 

	
 
					DeleteWindow(w);
 
					SwitchMode(SM_START_SCENARIO);
 
				}
 
			}
 
			break;
 
		case 18: /* Load game */
 
		case 21: /* Load game */
 
			_is_network_server = true;
 
			/* XXX - WC_NETWORK_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);
 
			ShowSaveLoadDialog(SLD_LOAD_GAME);
 
			break;
 
		}
 
		break;
 

	
 
	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;
 
@@ -760,57 +769,75 @@ static void NetworkStartServerWindowWndP
 
	case WE_MOUSELOOP:
 
		if (nd->field == 3) HandleEditBox(w, &WP(w, network_ql_d).q, 3);
 
		break;
 

	
 
	case WE_KEYPRESS:
 
		if (nd->field == 3) {
 
			if (HandleEditBoxKey(w, &WP(w, network_ql_d).q, 3, e) == 1) break; // enter pressed
 

	
 
			ttd_strlcpy(_network_server_name, WP(w, network_ql_d).q.text.buf, sizeof(_network_server_name));
 
		}
 
		break;
 

	
 
	case WE_ON_EDIT_TEXT: {
 
		ttd_strlcpy(_network_server_password, e->we.edittext.str, lengthof(_network_server_password));
 
		_network_game_info.use_password = (_network_server_password[0] != '\0');
 
	case WE_ON_EDIT_TEXT:
 
		if (e->we.edittext.str == NULL) break;
 

	
 
		if (nd->widget_id == 4) {
 
			ttd_strlcpy(_network_server_password, e->we.edittext.str, lengthof(_network_server_password));
 
			_network_game_info.use_password = (_network_server_password[0] != '\0');
 
		} else {
 
			int32 value = atoi(e->we.edittext.str);
 
			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;
 
			}
 
		}
 

	
 
		SetWindowDirty(w);
 
	} break;
 
		break;
 
	}
 
}
 

	
 
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},
 
{   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},
 

	
 
{      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},
 
{      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},
 

	
 
{      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},
 
/* Combo boxes to control Connection Type / Max Clients / Max Companies / Max Observers / Language */
 
{      WWT_INSET,   RESIZE_NONE,   BGC,   280,   410,    77,    88, STR_NETWORK_COMBO1,            STR_NETWORK_CONNECTION_TIP},
 
{    WWT_TEXTBTN,   RESIZE_NONE,   BGC,   399,   409,    78,    87, STR_0225,                      STR_NETWORK_CONNECTION_TIP},
 
{      WWT_INSET,   RESIZE_NONE,   BGC,   280,   410,   109,   120, STR_NETWORK_COMBO2,            STR_NETWORK_NUMBER_OF_CLIENTS_TIP},
 
{    WWT_TEXTBTN,   RESIZE_NONE,   BGC,   399,   409,   110,   119, STR_0225,                      STR_NETWORK_NUMBER_OF_CLIENTS_TIP},
 
{      WWT_INSET,   RESIZE_NONE,   BGC,   280,   410,   141,   152, STR_NETWORK_COMBO3,            STR_NETWORK_NUMBER_OF_COMPANIES_TIP},
 
{    WWT_TEXTBTN,   RESIZE_NONE,   BGC,   399,   409,   142,   151, STR_0225,                      STR_NETWORK_NUMBER_OF_COMPANIES_TIP},
 
{      WWT_INSET,   RESIZE_NONE,   BGC,   280,   410,   173,   184, STR_NETWORK_COMBO4,            STR_NETWORK_NUMBER_OF_SPECTATORS_TIP},
 
{    WWT_TEXTBTN,   RESIZE_NONE,   BGC,   399,   409,   174,   183, STR_0225,                      STR_NETWORK_NUMBER_OF_SPECTATORS_TIP},
 
{      WWT_INSET,   RESIZE_NONE,   BGC,   280,   410,   205,   216, STR_NETWORK_COMBO5,            STR_NETWORK_LANGUAGE_TIP},
 
{    WWT_TEXTBTN,   RESIZE_NONE,   BGC,   399,   409,   206,   215, STR_0225,                      STR_NETWORK_LANGUAGE_TIP},
 
{      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},
 
/* 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_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_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_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},
 
{   WIDGETS_END},
 
};
 

	
 
static const WindowDesc _network_start_server_window_desc = {
 
	WDP_CENTER, WDP_CENTER, 420, 244, 420, 244,
 
	WC_NETWORK_WINDOW, WC_NONE,
 
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
 
	_network_start_server_window_widgets,
 
	NetworkStartServerWindowWndProc,
 
};
 

	
 
static void ShowNetworkStartServerWindow()
src/settings.cpp
Show inline comments
 
@@ -1275,27 +1275,27 @@ static const SettingDescGlobVarList _net
 
	  SDTG_VAR("server_port",         SLE_UINT16, S, 0, _network_server_port,          NETWORK_DEFAULT_PORT, 0, 65535, 0, STR_NULL, NULL),
 
	 SDTG_BOOL("server_advertise",                S, 0, _network_advertise,            false,              STR_NULL, NULL),
 
	  SDTG_VAR("lan_internet",         SLE_UINT8, S, 0, _network_lan_internet,           0, 0,     1,   0, STR_NULL, NULL),
 
	  SDTG_STR("player_name",           SLE_STRB, S, 0, _network_player_name,          NULL,               STR_NULL, NULL),
 
	  SDTG_STR("server_password",       SLE_STRB, S, 0, _network_server_password,      NULL,               STR_NULL, NULL),
 
	  SDTG_STR("rcon_password",         SLE_STRB, S, 0, _network_rcon_password,        NULL,               STR_NULL, NULL),
 
	  SDTG_STR("server_name",           SLE_STRB, S, 0, _network_server_name,          NULL,               STR_NULL, NULL),
 
	  SDTG_STR("connect_to_ip",         SLE_STRB, S, 0, _network_default_ip,           NULL,               STR_NULL, NULL),
 
	  SDTG_STR("network_id",            SLE_STRB, S, 0, _network_unique_id,            NULL,               STR_NULL, NULL),
 
	 SDTG_BOOL("autoclean_companies",             S, 0, _network_autoclean_companies,  false,              STR_NULL, NULL),
 
	  SDTG_VAR("autoclean_unprotected",SLE_UINT8, S, 0, _network_autoclean_unprotected,12, 0,     60,   0, STR_NULL, NULL),
 
	  SDTG_VAR("autoclean_protected",  SLE_UINT8, S, 0, _network_autoclean_protected,  36, 0,    180,   0, STR_NULL, NULL),
 
	  SDTG_VAR("max_companies",        SLE_UINT8, S, 0, _network_game_info.companies_max,   8, 0,  8,   0, STR_NULL, NULL),
 
	  SDTG_VAR("max_clients",          SLE_UINT8, S, 0, _network_game_info.clients_max,    10, 0, 10,   0, STR_NULL, NULL),
 
	  SDTG_VAR("max_spectators",       SLE_UINT8, S, 0, _network_game_info.spectators_max, 10, 0, 10,   0, STR_NULL, NULL),
 
	  SDTG_VAR("max_companies",        SLE_UINT8, S, 0, _network_game_info.companies_max,   8, 1, MAX_PLAYERS, 0, STR_NULL, NULL),
 
	  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, 28, "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", 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,
 
	 * town attitude towards demolishing. Needs special handling because some dimwit thought
 
	 * it funny to have the GameDifficulty struct be an array while it is a struct of
 
	 * same-sized members
0 comments (0 inline, 0 general)