Changeset - r5432:b5c81859a489
[Not reviewed]
master
0 5 0
Darkvater - 17 years ago 2006-12-30 01:52:09
darkvater@openttd.org
(svn r7638) -Codechange: Remove special window ShowJoinStatusWindowAfterJoin and shuffle around
some code for SetupColorsAndInitialWindow. Because we know that after a successful
load all windows are removed we can setup default windows in this function, and
show ShowJoinStatusWindow in PACKET_SERVER_MAP.
-Setup the global _network_join_status for ShowJoinStatusWindow in the only two
places where the function is called, instead of inside it.
-Turn the join status window into a modal window of the network window so it
stays on top.
5 files changed with 26 insertions and 49 deletions:
0 comments (0 inline, 0 general)
main_gui.c
Show inline comments
 
@@ -2359,7 +2359,6 @@ static void MainWindowWndProc(Window *w,
 

	
 

	
 
void ShowSelectGameWindow(void);
 
extern void ShowJoinStatusWindowAfterJoin(void);
 

	
 
void SetupColorsAndInitialWindow(void)
 
{
 
@@ -2377,32 +2376,20 @@ void SetupColorsAndInitialWindow(void)
 
	width = _screen.width;
 
	height = _screen.height;
 

	
 
	w = AllocateWindow(0, 0, width, height, MainWindowWndProc, WC_MAIN_WINDOW, NULL);
 
	AssignWindowViewport(w, 0, 0, width, height, TileXY(32, 32), 0);
 

	
 
	// XXX: these are not done
 
	switch (_game_mode) {
 
	case GM_MENU:
 
		w = AllocateWindow(0, 0, width, height, MainWindowWndProc, WC_MAIN_WINDOW, NULL);
 
		AssignWindowViewport(w, 0, 0, width, height, TileXY(32, 32), 0);
 
		ShowSelectGameWindow();
 
		break;
 
	case GM_NORMAL:
 
		w = AllocateWindow(0, 0, width, height, MainWindowWndProc, WC_MAIN_WINDOW, NULL);
 
		AssignWindowViewport(w, 0, 0, width, height, TileXY(32, 32), 0);
 

	
 
		ShowVitalWindows();
 
		default: NOT_REACHED();
 
		case GM_MENU:
 
			ShowSelectGameWindow();
 
			break;
 

	
 
		/* Bring joining GUI to front till the client is really joined */
 
		if (_networking && !_network_server)
 
			ShowJoinStatusWindowAfterJoin();
 

	
 
		break;
 
	case GM_EDITOR:
 
		w = AllocateWindow(0, 0, width, height, MainWindowWndProc, WC_MAIN_WINDOW, NULL);
 
		AssignWindowViewport(w, 0, 0, width, height, 0, 0);
 

	
 
		ShowVitalWindows();
 
		break;
 
	default:
 
		NOT_REACHED();
 
		case GM_NORMAL:
 
		case GM_EDITOR:
 
			ShowVitalWindows();
 
			break;
 
	}
 
}
 

	
network.c
Show inline comments
 
@@ -29,6 +29,7 @@
 
#include "network_server.h"
 
#include "network_udp.h"
 
#include "network_gamelist.h"
 
#include "network_gui.h"
 
#include "console.h" /* IConsoleCmdExec */
 
#include <stdarg.h> /* va_list */
 
#include "md5.h"
 
@@ -47,7 +48,6 @@ static byte _network_clients_connected =
 
static uint16 _network_client_index = NETWORK_SERVER_INDEX + 1;
 

	
 
/* Some externs / forwards */
 
extern void ShowJoinStatusWindow(void);
 
extern void StateGameLoop(void);
 

	
 
// Function that looks up the CI for a given client-index
 
@@ -689,6 +689,7 @@ static bool NetworkConnect(const char *h
 
	// in client mode, only the first client field is used. it's pointing to the server.
 
	NetworkAllocClient(s);
 

	
 
	_network_join_status = NETWORK_JOIN_STATUS_CONNECTING;
 
	ShowJoinStatusWindow();
 

	
 
	return true;
network_client.c
Show inline comments
 
@@ -497,6 +497,8 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER
 
			_switch_mode_errorstr = STR_NETWORK_ERR_SAVEGAMEERROR;
 
			return NETWORK_RECV_STATUS_SAVEGAME;
 
		}
 
		/* If the savegame has successfully loaded, ALL windows have been removed,
 
		 * only toolbar/statusbar and gamefield are visible */
 

	
 
		_opt_ptr = &_opt; // during a network game you are always in-game
 

	
 
@@ -510,18 +512,16 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER
 

	
 
			SetLocalPlayer(PLAYER_SPECTATOR);
 

	
 
			if (_network_playas == PLAYER_SPECTATOR) {
 
				// The client wants to be a spectator..
 
				DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
 
			} else {
 
			if (_network_playas != PLAYER_SPECTATOR) {
 
				/* We have arrived and ready to start playing; send a command to make a new player;
 
				 * the server will give us a client-id and let us in */
 
				_network_join_status = NETWORK_JOIN_STATUS_REGISTERING;
 
				ShowJoinStatusWindow();
 
				NetworkSend_Command(0, 0, 0, CMD_PLAYER_CTRL, NULL);
 
			}
 
		} else {
 
			// take control over an existing company
 
			SetLocalPlayer(_network_playas);
 
			DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
 
		}
 
	}
 

	
network_gui.c
Show inline comments
 
@@ -1416,8 +1416,7 @@ static void NetworkJoinStatusWindowWndPr
 

	
 
	case WE_CLICK:
 
		switch (e->we.click.widget) {
 
			case 0: /* Close 'X' */
 
			case 3: /* Disconnect button */
 
			case 2: /* Disconnect button */
 
				NetworkDisconnect();
 
				DeleteWindow(w);
 
				SwitchMode(SM_MENU);
 
@@ -1439,8 +1438,7 @@ static void NetworkJoinStatusWindowWndPr
 
}
 

	
 
static const Widget _network_join_status_window_widget[] = {
 
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,               STR_018B_CLOSE_WINDOW},
 
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   249,     0,    13, STR_NETWORK_CONNECTING, STR_018C_WINDOW_TITLE_DRAG_THIS},
 
{    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},
 
@@ -1449,26 +1447,18 @@ static const Widget _network_join_status
 
static const WindowDesc _network_join_status_window_desc = {
 
	WDP_CENTER, WDP_CENTER, 250, 85,
 
	WC_NETWORK_STATUS_WINDOW, 0,
 
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET,
 
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_MODAL,
 
	_network_join_status_window_widget,
 
	NetworkJoinStatusWindowWndProc,
 
};
 

	
 
void ShowJoinStatusWindow(void)
 
{
 
	Window *w;
 
	DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
 
	_network_join_status = NETWORK_JOIN_STATUS_CONNECTING;
 
	AllocateWindowDesc(&_network_join_status_window_desc);
 
}
 

	
 
void ShowJoinStatusWindowAfterJoin(void)
 
{
 
	/* This is a special instant of ShowJoinStatusWindow, because
 
	    it is opened after the map is loaded, but the client maybe is not
 
	    done registering itself to the server */
 
	DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
 
	_network_join_status = NETWORK_JOIN_STATUS_REGISTERING;
 
	AllocateWindowDesc(&_network_join_status_window_desc);
 
	w = AllocateWindowDesc(&_network_join_status_window_desc);
 
	/* Parent the status window to the lobby */
 
	if (w != NULL) w->parent = FindWindowById(WC_NETWORK_WINDOW, 0);
 
}
 

	
 
static void SendChat(const char *buf, DestType type, byte dest)
network_gui.h
Show inline comments
 
@@ -10,7 +10,7 @@
 
void ShowNetworkNeedPassword(NetworkPasswordType npt);
 
void ShowNetworkGiveMoneyWindow(byte player); // PlayerID
 
void ShowNetworkChatQueryWindow(DestType type, byte dest);
 
void ShowJoinStatusWindowAfterJoin(void);
 
void ShowJoinStatusWindow(void);
 
void ShowNetworkGameWindow(void);
 
void ShowClientList(void);
 

	
 
@@ -19,7 +19,6 @@ void ShowClientList(void);
 

	
 
static inline void ShowNetworkChatQueryWindow(byte desttype, byte dest) {}
 
static inline void ShowClientList(void) {}
 
static inline void ShowJoinStatusWindowAfterJoin(void) {}
 
static inline void ShowNetworkGameWindow(void) {}
 

	
 
#endif /* ENABLE_NETWORK */
0 comments (0 inline, 0 general)