Changeset - r9269:58c968498b46
[Not reviewed]
master
0 1 0
rubidium - 17 years ago 2008-05-17 08:00:13
rubidium@openttd.org
(svn r13135) -Codechange: make a class of the NetworkJoinStatusWindow.
1 file changed with 50 insertions and 48 deletions:
0 comments (0 inline, 0 general)
src/network/network_gui.cpp
Show inline comments
 
@@ -1594,62 +1594,66 @@ void ShowNetworkNeedPassword(NetworkPass
 
		case NETWORK_GAME_PASSWORD:    caption = STR_NETWORK_NEED_GAME_PASSWORD_CAPTION; break;
 
		case NETWORK_COMPANY_PASSWORD: caption = STR_NETWORK_NEED_COMPANY_PASSWORD_CAPTION; break;
 
	}
 
	ShowQueryString(STR_EMPTY, caption, 20, 180, FindWindowById(WC_NETWORK_STATUS_WINDOW, 0), CS_ALPHANUMERAL);
 
}
 

	
 
struct NetworkJoinStatusWindow : Window {
 
	NetworkJoinStatusWindow(const WindowDesc *desc) : Window(desc)
 
	{
 
		this->parent = FindWindowById(WC_NETWORK_WINDOW, 0);
 
	}
 

	
 
static void NetworkJoinStatusWindowWndProc(Window *w, WindowEvent *e)
 
{
 
	switch (e->event) {
 
		case WE_PAINT: {
 
			uint8 progress; // used for progress bar
 
			DrawWindowWidgets(w);
 
	virtual void OnPaint()
 
	{
 
		uint8 progress; // used for progress bar
 
		DrawWindowWidgets(this);
 

	
 
			DrawStringCentered(125, 35, STR_NETWORK_CONNECTING_1 + _network_join_status, TC_GREY);
 
			switch (_network_join_status) {
 
				case NETWORK_JOIN_STATUS_CONNECTING: case NETWORK_JOIN_STATUS_AUTHORIZING:
 
				case NETWORK_JOIN_STATUS_GETTING_COMPANY_INFO:
 
					progress = 10; // first two stages 10%
 
					break;
 
				case NETWORK_JOIN_STATUS_WAITING:
 
					SetDParam(0, _network_join_waiting);
 
					DrawStringCentered(125, 46, STR_NETWORK_CONNECTING_WAITING, TC_GREY);
 
					progress = 15; // third stage is 15%
 
					break;
 
				case NETWORK_JOIN_STATUS_DOWNLOADING:
 
					SetDParam(0, _network_join_kbytes);
 
					SetDParam(1, _network_join_kbytes_total);
 
					DrawStringCentered(125, 46, STR_NETWORK_CONNECTING_DOWNLOADING, TC_GREY);
 
					/* Fallthrough */
 
				default: /* Waiting is 15%, so the resting receivement of map is maximum 70% */
 
					progress = 15 + _network_join_kbytes * (100 - 15) / _network_join_kbytes_total;
 
			}
 
		DrawStringCentered(125, 35, STR_NETWORK_CONNECTING_1 + _network_join_status, TC_GREY);
 
		switch (_network_join_status) {
 
			case NETWORK_JOIN_STATUS_CONNECTING: case NETWORK_JOIN_STATUS_AUTHORIZING:
 
			case NETWORK_JOIN_STATUS_GETTING_COMPANY_INFO:
 
				progress = 10; // first two stages 10%
 
				break;
 
			case NETWORK_JOIN_STATUS_WAITING:
 
				SetDParam(0, _network_join_waiting);
 
				DrawStringCentered(125, 46, STR_NETWORK_CONNECTING_WAITING, TC_GREY);
 
				progress = 15; // third stage is 15%
 
				break;
 
			case NETWORK_JOIN_STATUS_DOWNLOADING:
 
				SetDParam(0, _network_join_kbytes);
 
				SetDParam(1, _network_join_kbytes_total);
 
				DrawStringCentered(125, 46, STR_NETWORK_CONNECTING_DOWNLOADING, TC_GREY);
 
				/* Fallthrough */
 
			default: /* Waiting is 15%, so the resting receivement of map is maximum 70% */
 
				progress = 15 + _network_join_kbytes * (100 - 15) / _network_join_kbytes_total;
 
		}
 

	
 
			/* Draw nice progress bar :) */
 
			DrawFrameRect(20, 18, (int)((w->width - 20) * progress / 100), 28, 10, FR_NONE);
 
		} break;
 
		/* Draw nice progress bar :) */
 
		DrawFrameRect(20, 18, (int)((this->width - 20) * progress / 100), 28, 10, FR_NONE);
 
	}
 

	
 
		case WE_CLICK:
 
			if (e->we.click.widget == 2) { //Disconnect button
 
				NetworkDisconnect();
 
				SwitchMode(SM_MENU);
 
				ShowNetworkGameWindow();
 
			}
 
			break;
 
	virtual void OnClick(Point pt, int widget)
 
	{
 
		if (widget == 2) { //Disconnect button
 
			NetworkDisconnect();
 
			SwitchMode(SM_MENU);
 
			ShowNetworkGameWindow();
 
		}
 
	}
 

	
 
		case WE_ON_EDIT_TEXT:
 
			if (StrEmpty(e->we.edittext.str)) {
 
				NetworkDisconnect();
 
				ShowNetworkGameWindow();
 
			} else {
 
				SEND_COMMAND(PACKET_CLIENT_PASSWORD)(pw_type, e->we.edittext.str);
 
			}
 
			break;
 
	virtual void OnQueryTextFinished(char *str)
 
	{
 
		if (StrEmpty(str)) {
 
			NetworkDisconnect();
 
			ShowNetworkGameWindow();
 
		} else {
 
			SEND_COMMAND(PACKET_CLIENT_PASSWORD)(pw_type, str);
 
		}
 
	}
 
}
 
};
 

	
 
static const Widget _network_join_status_window_widget[] = {
 
{    WWT_CAPTION,   RESIZE_NONE,    14,     0,   249,     0,    13, STR_NETWORK_CONNECTING, STR_018C_WINDOW_TITLE_DRAG_THIS},
 
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   249,    14,    84, 0x0,                    STR_NULL},
 
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,    75,   175,    69,    80, STR_NETWORK_DISCONNECT, STR_NULL},
 
{   WIDGETS_END},
 
@@ -1657,21 +1661,19 @@ static const Widget _network_join_status
 

	
 
static const WindowDesc _network_join_status_window_desc = {
 
	WDP_CENTER, WDP_CENTER, 250, 85, 250, 85,
 
	WC_NETWORK_STATUS_WINDOW, WC_NONE,
 
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_MODAL,
 
	_network_join_status_window_widget,
 
	NetworkJoinStatusWindowWndProc,
 
	NULL,
 
};
 

	
 
void ShowJoinStatusWindow()
 
{
 
	DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
 
	Window *w = new Window(&_network_join_status_window_desc);
 
	/* Parent the status window to the lobby */
 
	if (w != NULL) w->parent = FindWindowById(WC_NETWORK_WINDOW, 0);
 
	new NetworkJoinStatusWindow(&_network_join_status_window_desc);
 
}
 

	
 
static void SendChat(const char *buf, DestType type, int dest)
 
{
 
	if (StrEmpty(buf)) return;
 
	if (!_network_server) {
0 comments (0 inline, 0 general)