(svn r7638) -Codechange: Remove special window ShowJoinStatusWindowAfterJoin and shuffle around
authorDarkvater
Sat, 30 Dec 2006 01:52:09 +0000
changeset 5683 dca046ba7aa3
parent 5682 eeddbbacd4ac
child 5684 ce630c33116d
(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.
main_gui.c
network.c
network_client.c
network_gui.c
network_gui.h
--- a/main_gui.c	Sat Dec 30 01:17:53 2006 +0000
+++ b/main_gui.c	Sat Dec 30 01:52:09 2006 +0000
@@ -2359,7 +2359,6 @@
 
 
 void ShowSelectGameWindow(void);
-extern void ShowJoinStatusWindowAfterJoin(void);
 
 void SetupColorsAndInitialWindow(void)
 {
@@ -2377,32 +2376,20 @@
 	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;
 	}
 }
 
--- a/network.c	Sat Dec 30 01:17:53 2006 +0000
+++ b/network.c	Sat Dec 30 01:52:09 2006 +0000
@@ -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 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 @@
 	// 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;
--- a/network_client.c	Sat Dec 30 01:17:53 2006 +0000
+++ b/network_client.c	Sat Dec 30 01:52:09 2006 +0000
@@ -497,6 +497,8 @@
 			_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 @@
 
 			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);
 		}
 	}
 
--- a/network_gui.c	Sat Dec 30 01:17:53 2006 +0000
+++ b/network_gui.c	Sat Dec 30 01:52:09 2006 +0000
@@ -1416,8 +1416,7 @@
 
 	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 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 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)
--- a/network_gui.h	Sat Dec 30 01:17:53 2006 +0000
+++ b/network_gui.h	Sat Dec 30 01:52:09 2006 +0000
@@ -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 @@
 
 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 */