diff options
Diffstat (limited to 'src/net_gui.c')
-rw-r--r-- | src/net_gui.c | 115 |
1 files changed, 74 insertions, 41 deletions
diff --git a/src/net_gui.c b/src/net_gui.c index 600b6ee8..7fff33f6 100644 --- a/src/net_gui.c +++ b/src/net_gui.c @@ -24,11 +24,12 @@ // start the game. // +#include <stdio.h> #include <stdlib.h> #include <ctype.h> #include "config.h" -#include "doomstat.h" +#include "doomkeys.h" #include "i_system.h" #include "i_timer.h" @@ -41,8 +42,9 @@ #include "textscreen.h" static txt_window_t *window; -static txt_label_t *player_labels[MAXPLAYERS]; -static txt_label_t *ip_labels[MAXPLAYERS]; +static int old_max_players; +static txt_label_t *player_labels[NET_MAXPLAYERS]; +static txt_label_t *ip_labels[NET_MAXPLAYERS]; static txt_label_t *drone_label; static boolean had_warning; @@ -52,23 +54,38 @@ static void EscapePressed(TXT_UNCAST_ARG(widget), void *unused) I_Quit(); } -static void StartGame(TXT_UNCAST_ARG(widget), void *unused) +static void StartGame(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(settings)) { - NET_CL_StartGame(); + TXT_CAST_ARG(net_gamesettings_t, settings); + + NET_CL_StartGame(settings); } -static void BuildGUI(void) +static void OpenWaitDialog(void) { - char buf[50]; - txt_table_t *table; txt_window_action_t *cancel; - int i; - - had_warning = false; TXT_SetDesktopTitle(PACKAGE_STRING); - + window = TXT_NewWindow("Waiting for game start..."); + + TXT_AddWidget(window, TXT_NewLabel("\nPlease wait...\n\n")); + + cancel = TXT_NewWindowAction(KEY_ESCAPE, "Cancel"); + TXT_SignalConnect(cancel, "pressed", EscapePressed, NULL); + + TXT_SetWindowAction(window, TXT_HORIZ_LEFT, cancel); + + old_max_players = 0; +} + +static void BuildWindow(void) +{ + char buf[50]; + txt_table_t *table; + int i; + + TXT_ClearTable(window); table = TXT_NewTable(3); TXT_AddWidget(window, table); @@ -79,8 +96,8 @@ static void BuildGUI(void) TXT_AddWidget(table, TXT_NewStrut(17, 1)); // Player labels - - for (i=0; i<MAXPLAYERS; ++i) + + for (i = 0; i < net_client_wait_data.max_players; ++i) { sprintf(buf, " %i. ", i + 1); TXT_AddWidget(table, TXT_NewLabel(buf)); @@ -93,24 +110,35 @@ static void BuildGUI(void) drone_label = TXT_NewLabel(""); TXT_AddWidget(window, drone_label); - - cancel = TXT_NewWindowAction(KEY_ESCAPE, "Cancel"); - TXT_SignalConnect(cancel, "pressed", EscapePressed, NULL); - - TXT_SetWindowAction(window, TXT_HORIZ_LEFT, cancel); } -static void UpdateGUI(void) +static void UpdateGUI(net_gamesettings_t *settings) { txt_window_action_t *startgame; char buf[50]; unsigned int i; - for (i=0; i<MAXPLAYERS; ++i) + // If the value of max_players changes, we must rebuild the + // contents of the window. This includes when the first + // waiting data packet is received. + + if (net_client_received_wait_data) + { + if (net_client_wait_data.max_players != old_max_players) + { + BuildWindow(); + } + } + else + { + return; + } + + for (i = 0; i < net_client_wait_data.max_players; ++i) { txt_color_t color = TXT_COLOR_BRIGHT_WHITE; - if ((signed) i == net_player_number) + if ((signed) i == net_client_wait_data.consoleplayer) { color = TXT_COLOR_YELLOW; } @@ -118,10 +146,12 @@ static void UpdateGUI(void) TXT_SetFGColor(player_labels[i], color); TXT_SetFGColor(ip_labels[i], color); - if (i < net_clients_in_game) + if (i < net_client_wait_data.num_players) { - TXT_SetLabel(player_labels[i], net_player_names[i]); - TXT_SetLabel(ip_labels[i], net_player_addresses[i]); + TXT_SetLabel(player_labels[i], + net_client_wait_data.player_names[i]); + TXT_SetLabel(ip_labels[i], + net_client_wait_data.player_addrs[i]); } else { @@ -130,9 +160,10 @@ static void UpdateGUI(void) } } - if (net_drones_in_game > 0) + if (net_client_wait_data.num_drones > 0) { - sprintf(buf, " (+%i observer clients)", net_drones_in_game); + sprintf(buf, " (+%i observer clients)", + net_client_wait_data.num_drones); TXT_SetLabel(drone_label, buf); } else @@ -140,10 +171,10 @@ static void UpdateGUI(void) TXT_SetLabel(drone_label, ""); } - if (net_client_controller) + if (net_client_wait_data.is_controller) { startgame = TXT_NewWindowAction(' ', "Start game"); - TXT_SignalConnect(startgame, "pressed", StartGame, NULL); + TXT_SignalConnect(startgame, "pressed", StartGame, settings); } else { @@ -178,11 +209,13 @@ static void CheckMD5Sums(void) return; } - correct_wad = memcmp(net_local_wad_md5sum, net_server_wad_md5sum, + correct_wad = memcmp(net_local_wad_md5sum, + net_client_wait_data.wad_md5sum, sizeof(md5_digest_t)) == 0; - correct_deh = memcmp(net_local_deh_md5sum, net_server_deh_md5sum, + correct_deh = memcmp(net_local_deh_md5sum, + net_client_wait_data.deh_md5sum, sizeof(md5_digest_t)) == 0; - same_freedoom = net_server_is_freedoom == net_local_is_freedoom; + same_freedoom = net_client_wait_data.is_freedoom == net_local_is_freedoom; if (correct_wad && correct_deh && same_freedoom) { @@ -193,7 +226,7 @@ static void CheckMD5Sums(void) { printf("Warning: WAD MD5 does not match server:\n"); PrintMD5Digest("Local", net_local_wad_md5sum); - PrintMD5Digest("Server", net_server_wad_md5sum); + PrintMD5Digest("Server", net_client_wait_data.wad_md5sum); } if (!same_freedoom) @@ -201,14 +234,14 @@ static void CheckMD5Sums(void) printf("Warning: Mixing Freedoom with non-Freedoom\n"); printf("Local: %i Server: %i\n", net_local_is_freedoom, - net_server_is_freedoom); + net_client_wait_data.is_freedoom); } if (!correct_deh) { printf("Warning: Dehacked MD5 does not match server:\n"); PrintMD5Digest("Local", net_local_deh_md5sum); - PrintMD5Digest("Server", net_server_deh_md5sum); + PrintMD5Digest("Server", net_client_wait_data.deh_md5sum); } window = TXT_NewWindow("WARNING"); @@ -258,7 +291,7 @@ static void CheckMD5Sums(void) had_warning = true; } -void NET_WaitForStart(void) +void NET_WaitForStart(net_gamesettings_t *settings) { if (!TXT_Init()) { @@ -266,14 +299,15 @@ void NET_WaitForStart(void) exit(-1); } - I_SetWindowCaption(); - I_SetWindowIcon(); + I_SetWindowTitle("Waiting for game start"); + //I_SetWindowIcon(); - BuildGUI(); + OpenWaitDialog(); + had_warning = false; while (net_waiting_for_start) { - UpdateGUI(); + UpdateGUI(settings); CheckMD5Sums(); TXT_DispatchEvents(); @@ -292,4 +326,3 @@ void NET_WaitForStart(void) TXT_Shutdown(); } - |