Changeset - r214:315143c5d296
[Not reviewed]
master
0 1 0
signde - 20 years ago 2004-09-12 16:03:40
signde@openttd.org
(svn r215) -Feature: direct connect now allows selecting a port and a playername [ip/host]:[port]#[player]
1 file changed with 29 insertions and 3 deletions:
0 comments (0 inline, 0 general)
network_gui.c
Show inline comments
 
@@ -79,195 +79,221 @@ static void NetworkGameWindowWndProc(Win
 
				if (++n == w->vscroll.cap) { break;} // max number of games in the window
 
			}
 
		}
 
	}	break;
 

	
 
	case WE_CLICK:
 
		_selected_field = e->click.widget;
 
		switch(e->click.widget) {
 
		case 0: case 15:  /* Close 'X' | Cancel button */
 
			DeleteWindowById(WC_NETWORK_WINDOW, 0);
 
			NetworkLobbyShutdown();
 
			break;
 
		case 3: { /* Find server automaticaly */
 
			NetworkCoreConnectGame("auto", _network_server_port);
 
		}	break;
 
		case 4: { /* Connect via direct ip */
 
				StringID str;
 
				str = AllocateName((byte*)_decode_parameters, 0);
 

	
 
				ShowQueryString(
 
				str,
 
				STR_NETWORK_ENTER_IP,
 
				50,  // maximum 50 characters OR
 
				250, // characters up to width 250 pixels, whichever is satisfied first
 
				w->window_class,
 
				w->window_number);
 
				DeleteName(str);
 
		} break;
 
		case 5: /* Start server */
 
			ShowNetworkStartServerWindow();
 
			break;
 
		case 7: case 8: /* Connection type */
 
			ShowDropDownMenu(w, _connection_types_dropdown, _network_connection, 8, 0); // do it for widget 8
 
			return;
 
		case 14: { /* Matrix to show networkgames */
 
			uint32 id_v = (e->click.pt.y - NET_PRC__OFFSET_TOP_WIDGET) / NET_PRC__SIZE_OF_ROW;
 

	
 
			if (id_v >= w->vscroll.cap) { return;} // click out of bounds
 

	
 
			id_v += w->vscroll.pos;
 

	
 
			{
 
				NetworkGameList *cur_item = _network_game_list;
 
				int32 n = 0;
 
				while (cur_item != NULL) {
 
					if (n++ == id_v) { break;} // found clicked item
 

	
 
					cur_item = cur_item->_next;
 
				}
 

	
 
				if (cur_item == NULL) { return;} // click out of vehicle bounds
 

	
 
				selected_item = cur_item;
 
			}
 
		} break;
 
		case 16: /* Join Game */
 
			if (selected_item != NULL)
 
				NetworkCoreConnectGameStruct(selected_item);
 
			break;
 
		}
 
		break;
 

	
 
	case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */
 
		_network_connection = e->dropdown.index;
 
		switch (_network_connection) {
 
		case 0: /* LAN */
 
			NetworkGameListFromLAN();
 
			break;
 
		case 1: /* Internet */
 
			NetworkGameListFromInternet();
 
			break;
 
		}
 
		
 
		_network_game_count_last = _network_game_count;
 
		SetWindowDirty(w);
 

	
 
		break;
 

	
 
	case WE_MOUSELOOP:
 
		if (_selected_field == 6)
 
			HandleEditBox(w, 6);
 

	
 
		break;
 

	
 
	case WE_KEYPRESS:
 
		if (_selected_field != 6)
 
			break;
 

	
 
		switch (HandleEditBoxKey(w, 6, e)) {
 
		case 1:
 
			HandleButtonClick(w, 9);
 
			break;
 
		}
 
		break;
 

	
 
	case WE_ON_EDIT_TEXT: {
 
		const byte *b = e->edittext.str;
 
		if (*b != 0)
 
			NetworkCoreConnectGame(b, _network_server_port);
 
		byte *b = e->edittext.str;
 
		if (*b != 0) {
 
			byte * ip = NULL;
 
			byte * port = NULL;
 
			byte * player = NULL;
 
			byte c;
 
			uint16 rport;
 

	
 
			rport = _network_server_port;
 
			c = 0;
 
			ip = b;
 
			
 
			while (b[c] != 0) {
 
				if (((char)b[c]) == '#') {
 
					player = &b[c+1];
 
					b[c] = 0;
 
					}
 
				if (((char)b[c]) == ':') {
 
					port = &b[c+1];
 
					b[c] = 0;
 
					}
 
				c++;
 
				}
 

	
 
			if (player!=NULL) _network_playas = atoi(player);
 
			if (port!=NULL) rport = atoi(port);
 

	
 
			NetworkCoreConnectGame(b, rport);
 
		}
 
	} break;
 

	
 
	case WE_TICK: {
 
		if (_network_game_count_last != _network_game_count)
 
			SetWindowDirty(w);
 
	} break;
 

	
 
	}
 
}
 

	
 
static const Widget _network_game_window_widgets[] = {
 
{   WWT_CLOSEBOX,   BGC,     0,    10,     0,    13, STR_00C5,										STR_018B_CLOSE_WINDOW},
 
{    WWT_CAPTION,   BGC,    10,   399,     0,    13, STR_NETWORK_MULTIPLAYER,			STR_NULL},
 
{     WWT_IMGBTN,   BGC,     0,   399,    14,   199, 0x0,													STR_NULL},
 

	
 
{ WWT_PUSHTXTBTN,   BTC,    20,   130,    22,    33, STR_NETWORK_FIND_SERVER,			STR_NETWORK_FIND_SERVER_TIP},
 
{ WWT_PUSHTXTBTN,   BTC,   145,   255,    22,    33, STR_NETWORK_DIRECT_CONNECT,	STR_NETWORK_DIRECT_CONNECT_TIP},
 
{ WWT_PUSHTXTBTN,   BTC,   270,   380,    22,    33, STR_NETWORK_START_SERVER,		STR_NETWORK_START_SERVER_TIP},
 

	
 
{     WWT_IMGBTN,   BGC,   250,   394,    42,    53, 0x0,													STR_NETWORK_ENTER_NAME_TIP},
 

	
 
{          WWT_6,   BGC,   250,   393,    62,    73, STR_NETWORK_COMBO1,					STR_NETWORK_CONNECTION_TYPE_TIP},
 
{   WWT_CLOSEBOX,   BGC,   382,   392,    63,    72, STR_0225,										STR_NETWORK_CONNECTION_TYPE_TIP},
 

	
 
{  WWT_SCROLLBAR,   BGC,   382,   392,    81,   176, 0x0,													STR_0190_SCROLL_BAR_SCROLLS_LIST},
 

	
 
{     WWT_IMGBTN,   BTC,    10,   231,    81,    92, 0x0,													STR_NETWORK_GAME_NAME_TIP },
 
{     WWT_IMGBTN,   BTC,   232,   281,    81,    92, 0x0,													STR_NETWORK_PLAYERS_TIP },
 
{     WWT_IMGBTN,   BTC,   282,   331,    81,    92, 0x0,													STR_NETWORK_MAP_SIZE_TIP },
 
{     WWT_IMGBTN,   BTC,   332,   381,    81,    92, 0x0,													STR_NETWORK_INFO_ICONS_TIP },
 

	
 
{     WWT_MATRIX,   BGC,    10,   381,    93,   176, 0x601,												STR_NETWORK_CLICK_GAME_TO_SELECT},
 

	
 
{ WWT_PUSHTXTBTN,   BTC,   145,   255,   180,   191, STR_012E_CANCEL,							STR_NULL},
 
{ WWT_PUSHTXTBTN,   BTC,   270,   392,   180,   191, STR_NETWORK_JOIN_GAME,				STR_NULL},
 
{   WIDGETS_END},
 
};
 

	
 
static const WindowDesc _network_game_window_desc = {
 
	WDP_CENTER, WDP_CENTER, 400, 200,
 
	WC_NETWORK_WINDOW,0,
 
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
 
	_network_game_window_widgets,
 
	NetworkGameWindowWndProc,
 
};
 

	
 

	
 
void ShowNetworkGameWindow()
 
{
 
	Window *w;
 
	DeleteWindowById(WC_NETWORK_WINDOW, 0);
 

	
 
	NetworkLobbyInit();
 

	
 
	w = AllocateWindowDesc(&_network_game_window_desc);
 
	strcpy(_edit_str_buf, "Your name");
 
	w->vscroll.cap = 6;
 
	w->disabled_state = (1<<6) | (1<<7) | (1<<8); // disable buttons not yet working
 
	NetworkGameListFromLAN(); // default dropdown item is LAN, so fill that array
 

	
 
	_network_game_count_last = _network_game_count;
 

	
 
	WP(w,querystr_d).caret = 1;
 
	WP(w,querystr_d).maxlen = MAX_QUERYSTR_LEN;
 
	WP(w,querystr_d).maxwidth = 240;
 
	WP(w,querystr_d).buf = _edit_str_buf;
 
}
 

	
 
static const StringID _players_dropdown[] = {
 
	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,
 
	INVALID_STRING_ID
 
};
 

	
 
static void NetworkStartServerWindowWndProc(Window *w, WindowEvent *e)
 
{
 
	switch(e->event) {
 
	case WE_PAINT: {
 

	
 
		SET_DPARAM16(7, STR_NETWORK_2_PLAYERS + _players_max);
 
		DrawWindowWidgets(w);
 

	
 
		GfxFillRect(11, 63, 237, 168, 0xD7);
 

	
 
		DrawEditBox(w, 3);
 
		DrawEditBox(w, 4);
 

	
 
		DrawString(10, 22, STR_NETWORK_NEW_GAME_NAME, 2);
 
		DrawString(210, 22, STR_NETWORK_PASSWORD, 2);
 

	
 
		DrawString(10, 43, STR_NETWORK_SELECT_MAP, 2);
0 comments (0 inline, 0 general)