network_gui.c
author Darkvater
Wed, 25 Jan 2006 19:14:50 +0000
changeset 2882 54af2e527411
parent 2881 1ffbbdbf1685
child 2884 c100870ea536
permissions -rw-r--r--
(svn r3430) - You can of course not join when there are more companies than the maximum set, not the other way around.
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     3
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1881
diff changeset
     4
#include "openttd.h"
1317
f382f1b439c7 (svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents: 1309
diff changeset
     5
#include "string.h"
1309
dab90d4cbf2d (svn r1813) Declare functions implemented in strings.c in their own shiny new header (though i think some of these function don't belong into strings.c)
tron
parents: 1304
diff changeset
     6
#include "strings.h"
1363
01d3de5d8039 (svn r1867) Include tables/sprites.h only in files which need it
tron
parents: 1344
diff changeset
     7
#include "table/sprites.h"
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
     8
#include "network.h"
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
     9
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    10
#include "hal.h" // for file list
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    11
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    12
#ifdef ENABLE_NETWORK
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    13
507
8aa8100b0b22 (svn r815) Include strings.h only in the files which need it.
tron
parents: 228
diff changeset
    14
#include "table/strings.h"
2163
637ec3c361f5 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2114
diff changeset
    15
#include "functions.h"
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    16
#include "network_data.h"
738
0b2fb79e64fc (svn r1194) Feature: You can now add and remove servers from the server list. Those will be remembered until you delete them by pressing the Delete key.
dominik
parents: 735
diff changeset
    17
#include "network_gamelist.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
#include "window.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
#include "gui.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    20
#include "gfx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
#include "command.h"
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    22
#include "variables.h"
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    23
#include "network_server.h"
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    24
#include "network_udp.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    26
#define BGC 5
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
#define BTC 15
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
#define MAX_QUERYSTR_LEN 64
1323
41397685320a (svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents: 1317
diff changeset
    29
static char _edit_str_buf[MAX_QUERYSTR_LEN*2];
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    30
static void ShowNetworkStartServerWindow(void);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    31
static void ShowNetworkLobbyWindow(void);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
static byte _selected_field;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
static const StringID _connection_types_dropdown[] = {
675
b120ec0b3e39 (svn r1113) -Add: [Network] Added the GUI part for server advertising. When you go
truelight
parents: 670
diff changeset
    36
	STR_NETWORK_LAN_INTERNET,
b120ec0b3e39 (svn r1113) -Add: [Network] Added the GUI part for server advertising. When you go
truelight
parents: 670
diff changeset
    37
	STR_NETWORK_INTERNET_ADVERTISE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
	INVALID_STRING_ID
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    39
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    40
764
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
    41
static const StringID _lan_internet_types_dropdown[] = {
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
    42
	STR_NETWORK_LAN,
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
    43
	STR_NETWORK_INTERNET,
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
    44
	INVALID_STRING_ID
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
    45
};
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
    46
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
    47
static const StringID _players_dropdown[] = {
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
    48
	STR_NETWORK_0_CLIENTS,
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
    49
	STR_NETWORK_1_CLIENTS,
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
    50
	STR_NETWORK_2_CLIENTS,
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
    51
	STR_NETWORK_3_CLIENTS,
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
    52
	STR_NETWORK_4_CLIENTS,
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
    53
	STR_NETWORK_5_CLIENTS,
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
    54
	STR_NETWORK_6_CLIENTS,
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
    55
	STR_NETWORK_7_CLIENTS,
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
    56
	STR_NETWORK_8_CLIENTS,
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
    57
	STR_NETWORK_9_CLIENTS,
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
    58
	STR_NETWORK_10_CLIENTS,
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
    59
	INVALID_STRING_ID
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
    60
};
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
    61
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
    62
static const StringID _language_dropdown[] = {
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
    63
	STR_NETWORK_LANG_ANY,
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
    64
	STR_NETWORK_LANG_ENGLISH,
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
    65
	STR_NETWORK_LANG_GERMAN,
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
    66
	STR_NETWORK_LANG_FRENCH,
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
    67
	INVALID_STRING_ID
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
    68
};
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
    69
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
    70
enum {
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
    71
	NET_PRC__OFFSET_TOP_WIDGET          = 54,
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
    72
	NET_PRC__OFFSET_TOP_WIDGET_COMPANY  = 42,
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
    73
	NET_PRC__SIZE_OF_ROW                = 14,
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
    74
	NET_PRC__SIZE_OF_ROW_COMPANY        = 12,
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
    75
};
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
    76
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    77
static NetworkGameList *_selected_item = NULL;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    78
static int8 _selected_company_item = -1;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    79
659
a98c731921b4 (svn r1093) -Fix: Hopefully fixed windows revision issues once and for all. Removed globalness of _openttd_revision and put all such ifdefs into one place. If server has a revision only the same revisions can join; if the server has no revision everyone can join. I reckon this should be a server-side option to allow people to join or not to join.
darkvater
parents: 656
diff changeset
    80
extern const char _openttd_revision[];
a98c731921b4 (svn r1093) -Fix: Hopefully fixed windows revision issues once and for all. Removed globalness of _openttd_revision and put all such ifdefs into one place. If server has a revision only the same revisions can join; if the server has no revision everyone can join. I reckon this should be a server-side option to allow people to join or not to join.
darkvater
parents: 656
diff changeset
    81
2100
868d62687c9a (svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents: 2071
diff changeset
    82
static FiosItem *_selected_map = NULL; // to highlight slected map
897
42412d5ecc64 (svn r1383) Fix: You can now also delete automatically found servers by pressing "del"
dominik
parents: 893
diff changeset
    83
42412d5ecc64 (svn r1383) Fix: You can now also delete automatically found servers by pressing "del"
dominik
parents: 893
diff changeset
    84
// called when a new server is found on the network
42412d5ecc64 (svn r1383) Fix: You can now also delete automatically found servers by pressing "del"
dominik
parents: 893
diff changeset
    85
void UpdateNetworkGameWindow(bool unselect)
42412d5ecc64 (svn r1383) Fix: You can now also delete automatically found servers by pressing "del"
dominik
parents: 893
diff changeset
    86
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
    87
	Window* w = FindWindowById(WC_NETWORK_WINDOW, 0);
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
    88
897
42412d5ecc64 (svn r1383) Fix: You can now also delete automatically found servers by pressing "del"
dominik
parents: 893
diff changeset
    89
	if (w != NULL) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
    90
		if (unselect) _selected_item = NULL;
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
    91
		SendWindowMessage(WC_NETWORK_WINDOW, 0, true, 0, 0);
897
42412d5ecc64 (svn r1383) Fix: You can now also delete automatically found servers by pressing "del"
dominik
parents: 893
diff changeset
    92
	}
42412d5ecc64 (svn r1383) Fix: You can now also delete automatically found servers by pressing "del"
dominik
parents: 893
diff changeset
    93
}
42412d5ecc64 (svn r1383) Fix: You can now also delete automatically found servers by pressing "del"
dominik
parents: 893
diff changeset
    94
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
    95
/* uses WP(w, querystr_d) */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    96
static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    97
{
1653
3eed36c12b1d (svn r2157) - Feature (request): [ 1166978 ] Focus keyboard on input-box in Multiplayer Menu
Darkvater
parents: 1648
diff changeset
    98
	switch (e->event) {
3eed36c12b1d (svn r2157) - Feature (request): [ 1166978 ] Focus keyboard on input-box in Multiplayer Menu
Darkvater
parents: 1648
diff changeset
    99
	case WE_CREATE: /* focus input box */
3eed36c12b1d (svn r2157) - Feature (request): [ 1166978 ] Focus keyboard on input-box in Multiplayer Menu
Darkvater
parents: 1648
diff changeset
   100
		_selected_field = 3;
3eed36c12b1d (svn r2157) - Feature (request): [ 1166978 ] Focus keyboard on input-box in Multiplayer Menu
Darkvater
parents: 1648
diff changeset
   101
		_selected_item = NULL;
3eed36c12b1d (svn r2157) - Feature (request): [ 1166978 ] Focus keyboard on input-box in Multiplayer Menu
Darkvater
parents: 1648
diff changeset
   102
		break;
2630
35249d2ded3e (svn r3172) static, const
tron
parents: 2549
diff changeset
   103
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
	case WE_PAINT: {
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   105
		const NetworkGameList *sel = _selected_item;
2071
37c57d697d9b (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   106
659
a98c731921b4 (svn r1093) -Fix: Hopefully fixed windows revision issues once and for all. Removed globalness of _openttd_revision and put all such ifdefs into one place. If server has a revision only the same revisions can join; if the server has no revision everyone can join. I reckon this should be a server-side option to allow people to join or not to join.
darkvater
parents: 656
diff changeset
   107
		w->disabled_state = 0;
a98c731921b4 (svn r1093) -Fix: Hopefully fixed windows revision issues once and for all. Removed globalness of _openttd_revision and put all such ifdefs into one place. If server has a revision only the same revisions can join; if the server has no revision everyone can join. I reckon this should be a server-side option to allow people to join or not to join.
darkvater
parents: 656
diff changeset
   108
2071
37c57d697d9b (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   109
		if (sel == NULL) {
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   110
			SETBIT(w->disabled_state, 16); SETBIT(w->disabled_state, 17);
2071
37c57d697d9b (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   111
		} else if (!sel->online) {
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   112
			SETBIT(w->disabled_state, 16); // Server offline, join button disabled
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   113
		} else if (sel->info.clients_on >= sel->info.clients_max) {
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   114
			SETBIT(w->disabled_state, 16); // Server full, join button disabled
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   115
		} else if (sel->info.companies_on >= sel->info.companies_max &&
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   116
			         sel->info.spectators_on >= sel->info.spectators_max) {
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   117
			SETBIT(w->disabled_state, 16);
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   118
		} else if (sel->info.companies_on >= sel->info.companies_max &&
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   119
			         sel->info.spectators_on >= sel->info.spectators_max) {
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   120
			SETBIT(w->disabled_state, 17);
659
a98c731921b4 (svn r1093) -Fix: Hopefully fixed windows revision issues once and for all. Removed globalness of _openttd_revision and put all such ifdefs into one place. If server has a revision only the same revisions can join; if the server has no revision everyone can join. I reckon this should be a server-side option to allow people to join or not to join.
darkvater
parents: 656
diff changeset
   121
a98c731921b4 (svn r1093) -Fix: Hopefully fixed windows revision issues once and for all. Removed globalness of _openttd_revision and put all such ifdefs into one place. If server has a revision only the same revisions can join; if the server has no revision everyone can join. I reckon this should be a server-side option to allow people to join or not to join.
darkvater
parents: 656
diff changeset
   122
			// revisions don't match, check if server has no revision; then allow connection
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   123
		} else if (!sel->info.compatible) {
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   124
			SETBIT(w->disabled_state, 16); // Revision mismatch, join button disabled
622
3da5b736ca84 (svn r1052) -Fix: [Network] You can't join a server when revision mismatches.
truelight
parents: 621
diff changeset
   125
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   126
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   127
		SetDParam(0, 0x00);
764
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   128
		SetDParam(7, _lan_internet_types_dropdown[_network_lan_internet]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   129
		DrawWindowWidgets(w);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   130
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   131
		DrawEditBox(w, 3);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   132
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   133
		DrawString(9, 23, STR_NETWORK_CONNECTION, 2);
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   134
		DrawString(210, 23, STR_NETWORK_PLAYER_NAME, 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   135
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   136
		{ // draw list of games
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   137
			uint16 y = NET_PRC__OFFSET_TOP_WIDGET + 3;
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   138
			int32 n = 0;
809
86cc46f97149 (svn r1280) -Codechange: made the last patch a bit more... readable (in other words:
truelight
parents: 808
diff changeset
   139
			int32 pos = w->vscroll.pos;
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   140
			uint max_name_width = w->widget[6].right - w->widget[6].left - 5;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   141
			const NetworkGameList *cur_item = _network_game_list;
809
86cc46f97149 (svn r1280) -Codechange: made the last patch a bit more... readable (in other words:
truelight
parents: 808
diff changeset
   142
86cc46f97149 (svn r1280) -Codechange: made the last patch a bit more... readable (in other words:
truelight
parents: 808
diff changeset
   143
			while (pos > 0 && cur_item != NULL) {
86cc46f97149 (svn r1280) -Codechange: made the last patch a bit more... readable (in other words:
truelight
parents: 808
diff changeset
   144
				pos--;
808
d4b76579b3d0 (svn r1279) Fixed the scrollbar in the network gui(server list). It now updates when scrolling (HackyKid)
bjarni
parents: 793
diff changeset
   145
				cur_item = cur_item->next;
d4b76579b3d0 (svn r1279) Fixed the scrollbar in the network gui(server list). It now updates when scrolling (HackyKid)
bjarni
parents: 793
diff changeset
   146
			}
809
86cc46f97149 (svn r1280) -Codechange: made the last patch a bit more... readable (in other words:
truelight
parents: 808
diff changeset
   147
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   148
			while (cur_item != NULL) {
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   149
				// show highlighted item with a different colour
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   150
				if (cur_item == sel) GfxFillRect(w->widget[6].left + 1, y - 2, w->widget[8].right - 1, y + 9, 10);
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   151
2100
868d62687c9a (svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents: 2071
diff changeset
   152
				SetDParamStr(0, cur_item->info.server_name);
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   153
				DrawStringTruncated(w->widget[6].left + 5, y, STR_02BD, 16, max_name_width);
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   154
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   155
				SetDParam(0, cur_item->info.clients_on);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   156
				SetDParam(1, cur_item->info.clients_max);
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   157
				SetDParam(2, cur_item->info.companies_on);
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   158
				SetDParam(3, cur_item->info.companies_max);
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   159
				DrawStringCentered(210, y, STR_NETWORK_GENERAL_ONLINE, 2);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   160
579
08ce4c50bd32 (svn r999) New icons for the network interface, newgrf gui and the tiny euro
dominik
parents: 543
diff changeset
   161
				// only draw icons if the server is online
591
dd8f0291652b (svn r1012) -Fix: [Network] Endless loop if a server was offline (WizKid)
truelight
parents: 579
diff changeset
   162
				if (cur_item->online) {
579
08ce4c50bd32 (svn r999) New icons for the network interface, newgrf gui and the tiny euro
dominik
parents: 543
diff changeset
   163
					// draw a lock if the server is password protected.
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   164
					if (cur_item->info.use_password) DrawSprite(SPR_LOCK, w->widget[8].left + 5, y - 1);
591
dd8f0291652b (svn r1012) -Fix: [Network] Endless loop if a server was offline (WizKid)
truelight
parents: 579
diff changeset
   165
579
08ce4c50bd32 (svn r999) New icons for the network interface, newgrf gui and the tiny euro
dominik
parents: 543
diff changeset
   166
					// draw red or green icon, depending on compatibility with server.
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   167
					DrawSprite(SPR_BLOT | (cur_item->info.compatible ? PALETTE_TO_GREEN : PALETTE_TO_RED), w->widget[8].left + 15, y);
591
dd8f0291652b (svn r1012) -Fix: [Network] Endless loop if a server was offline (WizKid)
truelight
parents: 579
diff changeset
   168
579
08ce4c50bd32 (svn r999) New icons for the network interface, newgrf gui and the tiny euro
dominik
parents: 543
diff changeset
   169
					// draw flag according to server language
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   170
					DrawSprite(SPR_FLAGS_BASE + cur_item->info.server_lang, w->widget[8].left + 25, y);
579
08ce4c50bd32 (svn r999) New icons for the network interface, newgrf gui and the tiny euro
dominik
parents: 543
diff changeset
   171
				}
591
dd8f0291652b (svn r1012) -Fix: [Network] Endless loop if a server was offline (WizKid)
truelight
parents: 579
diff changeset
   172
dd8f0291652b (svn r1012) -Fix: [Network] Endless loop if a server was offline (WizKid)
truelight
parents: 579
diff changeset
   173
				cur_item = cur_item->next;
dd8f0291652b (svn r1012) -Fix: [Network] Endless loop if a server was offline (WizKid)
truelight
parents: 579
diff changeset
   174
				y += NET_PRC__SIZE_OF_ROW;
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
   175
				if (++n == w->vscroll.cap) break; // max number of games in the window
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   176
			}
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   177
		}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   178
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   179
		/* Draw the right menu */
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   180
		GfxFillRect(311, 43, 539, 92, 157);
2071
37c57d697d9b (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   181
		if (sel == NULL) {
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   182
			DrawStringMultiCenter(425, 58, STR_NETWORK_GAME_INFO, 0);
2071
37c57d697d9b (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   183
		} else if (!sel->online) {
37c57d697d9b (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   184
			SetDParamStr(0, sel->info.server_name);
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   185
			DrawStringMultiCenter(425, 68, STR_ORANGE, 2); // game name
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   186
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   187
			DrawStringMultiCenter(425, 132, STR_NETWORK_SERVER_OFFLINE, 2); // server offline
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   188
		} else { // show game info
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   189
			uint16 y = 100;
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   190
			const uint16 x = w->widget[15].left + 5;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   191
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   192
			DrawStringMultiCenter(425, 48, STR_NETWORK_GAME_INFO, 0);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   193
2055
9361b56db8ba (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 1916
diff changeset
   194
2071
37c57d697d9b (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   195
			SetDParamStr(0, sel->info.server_name);
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   196
			DrawStringCenteredTruncated(w->widget[15].left, w->widget[15].right, 62, STR_ORANGE, 16); // game name
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   197
2071
37c57d697d9b (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   198
			SetDParamStr(0, sel->info.map_name);
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   199
			DrawStringCenteredTruncated(w->widget[15].left, w->widget[15].right, 74, STR_02BD, 16); // map name
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   200
2071
37c57d697d9b (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   201
			SetDParam(0, sel->info.clients_on);
37c57d697d9b (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   202
			SetDParam(1, sel->info.clients_max);
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   203
			SetDParam(2, sel->info.companies_on);
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   204
			SetDParam(3, sel->info.companies_max);
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   205
			DrawString(x, y, STR_NETWORK_CLIENTS, 2);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   206
			y += 10;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   207
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   208
			SetDParam(0, _language_dropdown[sel->info.server_lang]);
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   209
			DrawString(x, y, STR_NETWORK_LANGUAGE, 2); // server language
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   210
			y += 10;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   211
2775
d3ed38a97250 (svn r3322) - Fix: Network window crash when it receives invalid information for example from the integrated nightly, so validate the network-input when it is received
Darkvater
parents: 2753
diff changeset
   212
			SetDParam(0, STR_TEMPERATE_LANDSCAPE + sel->info.map_set);
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   213
			DrawString(x, y, STR_NETWORK_TILESET, 2); // tileset
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   214
			y += 10;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   215
2071
37c57d697d9b (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   216
			SetDParam(0, sel->info.map_width);
37c57d697d9b (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   217
			SetDParam(1, sel->info.map_height);
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   218
			DrawString(x, y, STR_NETWORK_MAP_SIZE, 2); // map size
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   219
			y += 10;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   220
2071
37c57d697d9b (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   221
			SetDParamStr(0, sel->info.server_revision);
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   222
			DrawString(x, y, STR_NETWORK_SERVER_VERSION, 2); // server version
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   223
			y += 10;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   224
2071
37c57d697d9b (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   225
			SetDParamStr(0, sel->info.hostname);
37c57d697d9b (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   226
			SetDParam(1, sel->port);
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   227
			DrawString(x, y, STR_NETWORK_SERVER_ADDRESS, 2); // server address
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   228
			y += 10;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   229
2071
37c57d697d9b (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   230
			SetDParam(0, sel->info.start_date);
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   231
			DrawString(x, y, STR_NETWORK_START_DATE, 2); // start date
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   232
			y += 10;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   233
2071
37c57d697d9b (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   234
			SetDParam(0, sel->info.game_date);
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   235
			DrawString(x, y, STR_NETWORK_CURRENT_DATE, 2); // current date
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   236
			y += 10;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   237
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   238
			y += 2;
622
3da5b736ca84 (svn r1052) -Fix: [Network] You can't join a server when revision mismatches.
truelight
parents: 621
diff changeset
   239
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   240
			if (!sel->info.compatible) {
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   241
					DrawStringMultiCenter(425, y, STR_NETWORK_VERSION_MISMATCH, 2); // server mismatch
2071
37c57d697d9b (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   242
			} else if (sel->info.clients_on == sel->info.clients_max) {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   243
				// Show: server full, when clients_on == clients_max
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   244
				DrawStringMultiCenter(425, y, STR_NETWORK_SERVER_FULL, 2); // server full
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   245
			} else if (sel->info.use_password) {
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   246
				DrawStringMultiCenter(425, y, STR_NETWORK_PASSWORD, 2); // password warning
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   247
			}
659
a98c731921b4 (svn r1093) -Fix: Hopefully fixed windows revision issues once and for all. Removed globalness of _openttd_revision and put all such ifdefs into one place. If server has a revision only the same revisions can join; if the server has no revision everyone can join. I reckon this should be a server-side option to allow people to join or not to join.
darkvater
parents: 656
diff changeset
   248
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   249
			y += 10;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   250
		}
172
8d8b3383470d (svn r173) -Network: [1023231] Debug Code + ErrorBoxes + Load Game/Scenario. Added some more desync debug code and replaced some of the error() calls with some better error boxes. Hopefully find desyncs easier (sign_de)
darkvater
parents: 105
diff changeset
   251
	}	break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   252
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   253
	case WE_CLICK:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
		_selected_field = e->click.widget;
2775
d3ed38a97250 (svn r3322) - Fix: Network window crash when it receives invalid information for example from the integrated nightly, so validate the network-input when it is received
Darkvater
parents: 2753
diff changeset
   255
		switch (e->click.widget) {
764
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   256
		case 0: case 14: /* Close 'X' | Cancel button */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
			DeleteWindowById(WC_NETWORK_WINDOW, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
			break;
764
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   259
		case 4: case 5:
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 841
diff changeset
   260
			ShowDropDownMenu(w, _lan_internet_types_dropdown, _network_lan_internet, 5, 0, 0); // do it for widget 5
764
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   261
			break;
982
be834034b331 (svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents: 970
diff changeset
   262
		case 9: { /* Matrix to show networkgames */
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   263
			uint32 id_v = (e->click.pt.y - NET_PRC__OFFSET_TOP_WIDGET) / NET_PRC__SIZE_OF_ROW;
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   264
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
   265
			if (id_v >= w->vscroll.cap) return; // click out of bounds
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   266
			id_v += w->vscroll.pos;
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   267
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   268
			{
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   269
				NetworkGameList *cur_item = _network_game_list;
216
1be476b97e32 (svn r217) -Fix: remove warning and simplify loop network_gui.c (Tron)
darkvater
parents: 214
diff changeset
   270
				for (; id_v > 0 && cur_item != NULL; id_v--)
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   271
					cur_item = cur_item->next;
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   272
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   273
				if (cur_item == NULL) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   274
					// click out of vehicle bounds
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   275
					_selected_item = NULL;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   276
					SetWindowDirty(w);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   277
					return;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   278
				}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   279
				_selected_item = cur_item;
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   280
			}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   281
			SetWindowDirty(w);
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   282
		} break;
764
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   283
		case 11: /* Find server automatically */
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   284
			switch (_network_lan_internet) {
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   285
				case 0: NetworkUDPSearchGame(); break;
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   286
				case 1: NetworkUDPQueryMasterServer(); break;
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   287
			}
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   288
			break;
764
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   289
		case 12: { // Add a server
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   290
				ShowQueryString(
2055
9361b56db8ba (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 1916
diff changeset
   291
				BindCString(_network_default_ip),
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   292
				STR_NETWORK_ENTER_IP,
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   293
				31 | 0x1000,  // maximum number of characters OR
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   294
				250, // characters up to this width pixels, whichever is satisfied first
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   295
				w->window_class,
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   296
				w->window_number);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   297
		} break;
764
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   298
		case 13: /* Start server */
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   299
			ShowNetworkStartServerWindow();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   300
			break;
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   301
		case 16: /* Join Game */
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   302
			if (_selected_item != NULL) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   303
				memcpy(&_network_game_info, &_selected_item->info, sizeof(NetworkGameInfo));
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   304
				snprintf(_network_last_host, sizeof(_network_last_host), "%s", inet_ntoa(*(struct in_addr *)&_selected_item->ip));
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   305
				_network_last_port = _selected_item->port;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   306
				ShowNetworkLobbyWindow();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   307
			}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   308
			break;
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   309
		case 17: // Refresh
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   310
			if (_selected_item != NULL) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   311
				NetworkQueryServer(_selected_item->info.hostname, _selected_item->port, true);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   312
			}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   313
			break;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   314
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   315
	}	break;
172
8d8b3383470d (svn r173) -Network: [1023231] Debug Code + ErrorBoxes + Load Game/Scenario. Added some more desync debug code and replaced some of the error() calls with some better error boxes. Hopefully find desyncs easier (sign_de)
darkvater
parents: 105
diff changeset
   316
764
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   317
	case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   318
		switch(e->dropdown.button) {
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   319
			case 5:
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   320
				_network_lan_internet = e->dropdown.index;
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   321
				break;
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   322
		}
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   323
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   324
		SetWindowDirty(w);
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   325
		break;
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   326
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   327
	case WE_MOUSELOOP:
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   328
		if (_selected_field == 3) HandleEditBox(w, 3);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   330
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   331
	case WE_MESSAGE: {
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   332
		const NetworkGameList *nglist;
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   333
		w->vscroll.count = 0;
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   334
		/* Game-count has changed, update scroll-count, scrollbar, and resort */
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   335
		for (nglist = _network_game_list; nglist != NULL; nglist = nglist->next) w->vscroll.count++;
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   336
		if (w->vscroll.count >= w->vscroll.cap && w->vscroll.pos > w->vscroll.count - w->vscroll.cap) w->vscroll.pos--;
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   337
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   338
		SetWindowDirty(w);
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   339
	}	break;
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   340
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   341
	case WE_KEYPRESS:
738
0b2fb79e64fc (svn r1194) Feature: You can now add and remove servers from the server list. Those will be remembered until you delete them by pressing the Delete key.
dominik
parents: 735
diff changeset
   342
		if (_selected_field != 3) {
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   343
			if (_selected_item != NULL) {
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   344
				if (e->keypress.keycode == WKC_DELETE) { /* Press 'delete' to remove servers */
738
0b2fb79e64fc (svn r1194) Feature: You can now add and remove servers from the server list. Those will be remembered until you delete them by pressing the Delete key.
dominik
parents: 735
diff changeset
   345
					NetworkGameListRemoveItem(_selected_item);
0b2fb79e64fc (svn r1194) Feature: You can now add and remove servers from the server list. Those will be remembered until you delete them by pressing the Delete key.
dominik
parents: 735
diff changeset
   346
					NetworkRebuildHostList();
0b2fb79e64fc (svn r1194) Feature: You can now add and remove servers from the server list. Those will be remembered until you delete them by pressing the Delete key.
dominik
parents: 735
diff changeset
   347
					_selected_item = NULL;
0b2fb79e64fc (svn r1194) Feature: You can now add and remove servers from the server list. Those will be remembered until you delete them by pressing the Delete key.
dominik
parents: 735
diff changeset
   348
				}
0b2fb79e64fc (svn r1194) Feature: You can now add and remove servers from the server list. Those will be remembered until you delete them by pressing the Delete key.
dominik
parents: 735
diff changeset
   349
			}
741
39a3958887c1 (svn r1197) -Fix: [GUI] in r1194 someone deleted too much code from WE_KEYPRESS. Now
truelight
parents: 738
diff changeset
   350
			break;
39a3958887c1 (svn r1197) -Fix: [GUI] in r1194 someone deleted too much code from WE_KEYPRESS. Now
truelight
parents: 738
diff changeset
   351
		}
39a3958887c1 (svn r1197) -Fix: [GUI] in r1194 someone deleted too much code from WE_KEYPRESS. Now
truelight
parents: 738
diff changeset
   352
982
be834034b331 (svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents: 970
diff changeset
   353
		if (HandleEditBoxKey(w, 3, e) == 1) break; // enter pressed
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   354
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   355
		// The name is only allowed when it starts with a letter!
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   356
		if (_edit_str_buf[0] != '\0' && _edit_str_buf[0] != ' ') {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   357
			ttd_strlcpy(_network_player_name, _edit_str_buf, lengthof(_network_player_name));
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   358
		} else {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   359
			ttd_strlcpy(_network_player_name, "Player", lengthof(_network_player_name));
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   360
		}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   361
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   364
	case WE_ON_EDIT_TEXT:
716
40a349345f82 (svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents: 710
diff changeset
   365
		NetworkAddServer(e->edittext.str);
738
0b2fb79e64fc (svn r1194) Feature: You can now add and remove servers from the server list. Those will be remembered until you delete them by pressing the Delete key.
dominik
parents: 735
diff changeset
   366
		NetworkRebuildHostList();
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   367
		break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   371
static const Widget _network_game_window_widgets[] = {
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   372
{   WWT_CLOSEBOX,   RESIZE_NONE,   BGC,     0,    10,     0,    13, STR_00C5,                   STR_018B_CLOSE_WINDOW},
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   373
{    WWT_CAPTION,   RESIZE_NONE,   BGC,    11,   549,     0,    13, STR_NETWORK_MULTIPLAYER,    STR_NULL},
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   374
{     WWT_IMGBTN,   RESIZE_NONE,   BGC,     0,   549,    14,   249, STR_NULL,                   STR_NULL},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   375
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   376
/* LEFT SIDE */
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   377
{     WWT_IMGBTN,   RESIZE_NONE,   BGC,   310,   461,    22,    33, STR_NULL,                   STR_NETWORK_ENTER_NAME_TIP},
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
   378
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   379
{          WWT_6,   RESIZE_NONE,   BGC,    90,   181,    22,    33, STR_NETWORK_COMBO1,         STR_NETWORK_CONNECTION_TIP},
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   380
{    WWT_TEXTBTN,   RESIZE_NONE,   BGC,   170,   180,    23,    32, STR_0225,                   STR_NETWORK_CONNECTION_TIP},
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
   381
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   382
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,    10,   170,    42,    53, STR_NETWORK_GAME_NAME,      STR_NETWORK_GAME_NAME_TIP},
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   383
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   171,   250,    42,    53, STR_NETWORK_CLIENTS_CAPTION,STR_NETWORK_CLIENTS_CAPTION_TIP},
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   384
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   251,   290,    42,    53, STR_EMPTY,                          STR_NETWORK_INFO_ICONS_TIP},
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   385
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   386
{     WWT_MATRIX,   RESIZE_NONE,   BGC,    10,   290,    54,   222, (12 << 8) + 1,              STR_NETWORK_CLICK_GAME_TO_SELECT},
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   387
{  WWT_SCROLLBAR,   RESIZE_NONE,   BGC,   291,   302,    42,   222, STR_NULL,                   STR_0190_SCROLL_BAR_SCROLLS_LIST},
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   388
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   389
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,    30,   130,   232,   243, STR_NETWORK_FIND_SERVER,    STR_NETWORK_FIND_SERVER_TIP},
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   390
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   180,   280,   232,   243, STR_NETWORK_ADD_SERVER,     STR_NETWORK_ADD_SERVER_TIP},
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   391
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   392
/* RIGHT SIDE */
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   393
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   315,   415,   232,   243, STR_NETWORK_START_SERVER,   STR_NETWORK_START_SERVER_TIP},
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   394
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   430,   535,   232,   243, STR_012E_CANCEL,            STR_NULL},
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   395
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   396
{      WWT_PANEL,   RESIZE_NONE,   BGC,   310,   540,    42,   222, STR_NULL,                   STR_NULL},
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   397
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   398
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   315,   415,   201,   212, STR_NETWORK_JOIN_GAME,      STR_NULL},
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   399
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   430,   535,   201,   212, STR_NETWORK_REFRESH,        STR_NETWORK_REFRESH_TIP},
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   400
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 175
diff changeset
   401
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   402
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   403
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   404
static const WindowDesc _network_game_window_desc = {
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   405
	WDP_CENTER, WDP_CENTER, 550, 250,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   406
	WC_NETWORK_WINDOW,0,
2064
c889fcc76398 (svn r2573) Codechange: Removed WDF_RESTORE_DPARAM, it's not needed with the new string system.
ludde
parents: 2055
diff changeset
   407
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   408
	_network_game_window_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   409
	NetworkGameWindowWndProc,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   410
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1025
diff changeset
   412
void ShowNetworkGameWindow(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
{
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   414
	static bool _first_time_show_network_game_window = true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   415
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   416
	DeleteWindowById(WC_NETWORK_WINDOW, 0);
105
44e894da0fef (svn r106) New network core (by sign_de)
dominik
parents: 1
diff changeset
   417
764
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   418
	/* Only show once */
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   419
	if (_first_time_show_network_game_window) {
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   420
		const char* const *srv;
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   421
764
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   422
		_first_time_show_network_game_window = false;
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   423
		// add all servers from the config file to our list
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   424
		for (srv = _network_host_list; srv != endof(_network_host_list) && *srv != NULL; srv++) {
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   425
			NetworkAddServer(*srv);
764
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   426
		}
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   427
	}
68b398e2b780 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   428
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   429
	w = AllocateWindowDesc(&_network_game_window_desc);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   430
	ttd_strlcpy(_edit_str_buf, _network_player_name, MAX_QUERYSTR_LEN);
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   431
	w->vscroll.cap = 12;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   432
1390
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1363
diff changeset
   433
	WP(w, querystr_d).text.caret = true;
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1363
diff changeset
   434
	WP(w, querystr_d).text.maxlength = MAX_QUERYSTR_LEN - 1;
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1363
diff changeset
   435
	WP(w, querystr_d).text.maxwidth = 120;
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1363
diff changeset
   436
	WP(w, querystr_d).text.buf = _edit_str_buf;
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1363
diff changeset
   437
	UpdateTextBufferSize(&WP(w, querystr_d).text);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   438
827
2026d158133d (svn r1298) -Fix: [ 1092661 ] On create, the scrollbar of the server-list was not updated
truelight
parents: 809
diff changeset
   439
	UpdateNetworkGameWindow(true);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   440
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   441
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   442
enum {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   443
	NSSWND_START = 64,
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   444
	NSSWND_ROWSIZE = 12
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   445
};
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   446
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   447
static void NetworkStartServerWindowWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
{
1653
3eed36c12b1d (svn r2157) - Feature (request): [ 1166978 ] Focus keyboard on input-box in Multiplayer Menu
Darkvater
parents: 1648
diff changeset
   449
	switch (e->event) {
3eed36c12b1d (svn r2157) - Feature (request): [ 1166978 ] Focus keyboard on input-box in Multiplayer Menu
Darkvater
parents: 1648
diff changeset
   450
	case WE_CREATE: /* focus input box */
3eed36c12b1d (svn r2157) - Feature (request): [ 1166978 ] Focus keyboard on input-box in Multiplayer Menu
Darkvater
parents: 1648
diff changeset
   451
		_selected_field = 3;
1899
98317b840d7b (svn r2405) Simplify a few '? true : false' and '? false : true', especially the latter is confusing
tron
parents: 1891
diff changeset
   452
		_network_game_info.use_password = (_network_server_password[0] != '\0');
1653
3eed36c12b1d (svn r2157) - Feature (request): [ 1166978 ] Focus keyboard on input-box in Multiplayer Menu
Darkvater
parents: 1648
diff changeset
   453
		break;
3eed36c12b1d (svn r2157) - Feature (request): [ 1166978 ] Focus keyboard on input-box in Multiplayer Menu
Darkvater
parents: 1648
diff changeset
   454
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   455
	case WE_PAINT: {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   456
		int y = NSSWND_START, pos;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   457
		const FiosItem *item;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   458
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   459
		SetDParam( 7, _connection_types_dropdown[_network_advertise]);
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   460
		SetDParam( 9, _players_dropdown[_network_game_info.clients_max]);
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   461
		SetDParam(11, _players_dropdown[_network_game_info.companies_max]);
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   462
		SetDParam(13, _players_dropdown[_network_game_info.spectators_max]);
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   463
		SetDParam(15, _language_dropdown[_network_game_info.server_lang]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   464
		DrawWindowWidgets(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   465
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   466
		GfxFillRect(11, 63, 258, 215, 0xD7);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   467
		DrawEditBox(w, 3);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   468
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   469
		DrawString(10, 22, STR_NETWORK_NEW_GAME_NAME, 2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   470
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   471
		DrawString(10, 43, STR_NETWORK_SELECT_MAP, 2);
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   472
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   473
		DrawString(280,  63, STR_NETWORK_CONNECTION, 2);
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   474
		DrawString(280,  95, STR_NETWORK_NUMBER_OF_CLIENTS, 2);
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   475
		DrawString(280, 127, STR_NETWORK_NUMBER_OF_COMPANIES, 2);
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   476
		DrawString(280, 159, STR_NETWORK_NUMBER_OF_SPECTATORS, 2);
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   477
		DrawString(280, 191, STR_NETWORK_LANGUAGE_SPOKEN, 2);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   478
1653
3eed36c12b1d (svn r2157) - Feature (request): [ 1166978 ] Focus keyboard on input-box in Multiplayer Menu
Darkvater
parents: 1648
diff changeset
   479
		if (_network_game_info.use_password) DoDrawString("*", 408, 23, 3);
3eed36c12b1d (svn r2157) - Feature (request): [ 1166978 ] Focus keyboard on input-box in Multiplayer Menu
Darkvater
parents: 1648
diff changeset
   480
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   481
		// draw list of maps
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   482
		pos = w->vscroll.pos;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   483
		while (pos < _fios_num + 1) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   484
			item = _fios_list + pos - 1;
2100
868d62687c9a (svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents: 2071
diff changeset
   485
			if (item == _selected_map || (pos == 0 && _selected_map == NULL))
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   486
				GfxFillRect(11, y - 1, 258, y + 10, 155); // show highlighted item with a different colour
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   487
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   488
			if (pos == 0) DrawString(14, y, STR_4010_GENERATE_RANDOM_NEW_GAME, 9);
2100
868d62687c9a (svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents: 2071
diff changeset
   489
			else DoDrawString(item->title, 14, y, _fios_colors[item->type] );
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   490
			pos++;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   491
			y += NSSWND_ROWSIZE;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   492
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   493
			if (y >= w->vscroll.cap * NSSWND_ROWSIZE + NSSWND_START) break;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   494
		}
172
8d8b3383470d (svn r173) -Network: [1023231] Debug Code + ErrorBoxes + Load Game/Scenario. Added some more desync debug code and replaced some of the error() calls with some better error boxes. Hopefully find desyncs easier (sign_de)
darkvater
parents: 105
diff changeset
   495
	}	break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   496
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   497
	case WE_CLICK:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   498
		_selected_field = e->click.widget;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   499
		switch (e->click.widget) {
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   500
		case 0: /* Close 'X' */
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   501
		case 19: /* Cancel button */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   502
			ShowNetworkGameWindow();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   503
			break;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   504
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   505
		case 4: /* Set password button */
2055
9361b56db8ba (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 1916
diff changeset
   506
			ShowQueryString(BindCString(_network_server_password),
9361b56db8ba (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 1916
diff changeset
   507
				STR_NETWORK_SET_PASSWORD, 20, 250, w->window_class, w->window_number);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   508
			break;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   509
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   510
		case 5: { /* Select map */
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   511
			int y = (e->click.pt.y - NSSWND_START) / NSSWND_ROWSIZE;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   512
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   513
			y += w->vscroll.pos;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   514
			if (y >= w->vscroll.count) return;
2100
868d62687c9a (svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents: 2071
diff changeset
   515
868d62687c9a (svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents: 2071
diff changeset
   516
			_selected_map = (y == 0) ? NULL : _fios_list + y - 1;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   517
			SetWindowDirty(w);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   518
			} break;
675
b120ec0b3e39 (svn r1113) -Add: [Network] Added the GUI part for server advertising. When you go
truelight
parents: 670
diff changeset
   519
		case 7: case 8: /* Connection type */
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 841
diff changeset
   520
			ShowDropDownMenu(w, _connection_types_dropdown, _network_advertise, 8, 0, 0); // do it for widget 8
675
b120ec0b3e39 (svn r1113) -Add: [Network] Added the GUI part for server advertising. When you go
truelight
parents: 670
diff changeset
   521
			break;
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   522
		case 9: case 10: /* Number of Players (hide 0 and 1 players) */
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   523
			ShowDropDownMenu(w, _players_dropdown, _network_game_info.clients_max, 10, 0, 3);
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   524
			break;
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   525
		case 11: case 12: /* Number of Companies (hide 0, 9 and 10 companies; max is 8) */
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   526
			ShowDropDownMenu(w, _players_dropdown, _network_game_info.companies_max, 12, 0, 1537);
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   527
			break;
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   528
		case 13: case 14: /* Number of Spectators */
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   529
			ShowDropDownMenu(w, _players_dropdown, _network_game_info.spectators_max, 14, 0, 0);
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   530
			break;
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   531
		case 15: case 16: /* Language */
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   532
			ShowDropDownMenu(w, _language_dropdown, _network_game_info.server_lang, 16, 0, 0);
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   533
			break;
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   534
		case 17: /* Start game */
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   535
			_is_network_server = true;
1390
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1363
diff changeset
   536
			ttd_strlcpy(_network_server_name, WP(w, querystr_d).text.buf, sizeof(_network_server_name));
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1363
diff changeset
   537
			UpdateTextBufferSize(&WP(w, querystr_d).text);
2100
868d62687c9a (svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents: 2071
diff changeset
   538
			if (_selected_map == NULL) { // start random new game
1794
44f9deff97ed (svn r2298) - CodeChange: removed CmdAbuses: CmdSetTownNameType(), CmdStartNewGame(), CmdCreateScenario(), CmdSetNewLandscapeType() and CmdGenRandomNewGame().
Darkvater
parents: 1748
diff changeset
   539
				GenRandomNewGame(Random(), InteractiveRandom());
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   540
			} else { // load a scenario
2100
868d62687c9a (svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents: 2071
diff changeset
   541
				char *name = FiosBrowseTo(_selected_map);
868d62687c9a (svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents: 2071
diff changeset
   542
				if (name != NULL) {
868d62687c9a (svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents: 2071
diff changeset
   543
					SetFiosType(_selected_map->type);
868d62687c9a (svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents: 2071
diff changeset
   544
					ttd_strlcpy(_file_to_saveload.name, name, sizeof(_file_to_saveload.name));
868d62687c9a (svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents: 2071
diff changeset
   545
					ttd_strlcpy(_file_to_saveload.title, _selected_map->title, sizeof(_file_to_saveload.title));
868d62687c9a (svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents: 2071
diff changeset
   546
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   547
					DeleteWindow(w);
1796
cae31916ae54 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1794
diff changeset
   548
					StartScenarioEditor(Random(), InteractiveRandom());
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   549
				}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   550
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   551
			break;
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   552
		case 18: /* Load game */
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   553
			_is_network_server = true;
1390
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1363
diff changeset
   554
			ttd_strlcpy(_network_server_name, WP(w, querystr_d).text.buf, sizeof(_network_server_name));
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1363
diff changeset
   555
			UpdateTextBufferSize(&WP(w, querystr_d).text);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   556
			/* XXX - WC_NETWORK_WINDOW should stay, but if it stays, it gets
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   557
			 * copied all the elements of 'load game' and upon closing that, it segfaults */
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   558
			DeleteWindowById(WC_NETWORK_WINDOW, 0);
172
8d8b3383470d (svn r173) -Network: [1023231] Debug Code + ErrorBoxes + Load Game/Scenario. Added some more desync debug code and replaced some of the error() calls with some better error boxes. Hopefully find desyncs easier (sign_de)
darkvater
parents: 105
diff changeset
   559
			ShowSaveLoadDialog(SLD_LOAD_GAME);
8d8b3383470d (svn r173) -Network: [1023231] Debug Code + ErrorBoxes + Load Game/Scenario. Added some more desync debug code and replaced some of the error() calls with some better error boxes. Hopefully find desyncs easier (sign_de)
darkvater
parents: 105
diff changeset
   560
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   561
		}
172
8d8b3383470d (svn r173) -Network: [1023231] Debug Code + ErrorBoxes + Load Game/Scenario. Added some more desync debug code and replaced some of the error() calls with some better error boxes. Hopefully find desyncs easier (sign_de)
darkvater
parents: 105
diff changeset
   562
		break;
8d8b3383470d (svn r173) -Network: [1023231] Debug Code + ErrorBoxes + Load Game/Scenario. Added some more desync debug code and replaced some of the error() calls with some better error boxes. Hopefully find desyncs easier (sign_de)
darkvater
parents: 105
diff changeset
   563
8d8b3383470d (svn r173) -Network: [1023231] Debug Code + ErrorBoxes + Load Game/Scenario. Added some more desync debug code and replaced some of the error() calls with some better error boxes. Hopefully find desyncs easier (sign_de)
darkvater
parents: 105
diff changeset
   564
	case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   565
		switch(e->dropdown.button) {
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   566
			case  8: _network_advertise = (e->dropdown.index != 0); break;
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   567
			case 10: _network_game_info.clients_max = e->dropdown.index; break;
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   568
			case 12: _network_game_info.companies_max = e->dropdown.index; break;
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   569
			case 14: _network_game_info.spectators_max = e->dropdown.index; break;
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   570
			case 16: _network_game_info.server_lang = e->dropdown.index; break;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   571
		}
172
8d8b3383470d (svn r173) -Network: [1023231] Debug Code + ErrorBoxes + Load Game/Scenario. Added some more desync debug code and replaced some of the error() calls with some better error boxes. Hopefully find desyncs easier (sign_de)
darkvater
parents: 105
diff changeset
   572
8d8b3383470d (svn r173) -Network: [1023231] Debug Code + ErrorBoxes + Load Game/Scenario. Added some more desync debug code and replaced some of the error() calls with some better error boxes. Hopefully find desyncs easier (sign_de)
darkvater
parents: 105
diff changeset
   573
		SetWindowDirty(w);
8d8b3383470d (svn r173) -Network: [1023231] Debug Code + ErrorBoxes + Load Game/Scenario. Added some more desync debug code and replaced some of the error() calls with some better error boxes. Hopefully find desyncs easier (sign_de)
darkvater
parents: 105
diff changeset
   574
		break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   575
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   576
	case WE_MOUSELOOP:
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   577
		if (_selected_field == 3) HandleEditBox(w, 3);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   578
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   579
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   580
	case WE_KEYPRESS:
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   581
		if (_selected_field == 3) HandleEditBoxKey(w, 3, e);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   582
		break;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   583
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   584
	case WE_ON_EDIT_TEXT: {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   585
		ttd_strlcpy(_network_server_password, e->edittext.str, lengthof(_network_server_password));
1899
98317b840d7b (svn r2405) Simplify a few '? true : false' and '? false : true', especially the latter is confusing
tron
parents: 1891
diff changeset
   586
		_network_game_info.use_password = (_network_server_password[0] != '\0');
1653
3eed36c12b1d (svn r2157) - Feature (request): [ 1166978 ] Focus keyboard on input-box in Multiplayer Menu
Darkvater
parents: 1648
diff changeset
   587
		SetWindowDirty(w);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   588
	} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   589
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   590
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   591
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   592
static const Widget _network_start_server_window_widgets[] = {
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   593
{   WWT_CLOSEBOX,   RESIZE_NONE,   BGC,     0,    10,     0,    13, STR_00C5,                     STR_018B_CLOSE_WINDOW },
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   594
{    WWT_CAPTION,   RESIZE_NONE,   BGC,    11,   419,     0,    13, STR_NETWORK_START_GAME_WINDOW,  STR_NULL},
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   595
{     WWT_IMGBTN,   RESIZE_NONE,   BGC,     0,   419,    14,   243, 0x0,                            STR_NULL},
749
ddf820fc3c53 (svn r1205) Fix: Made the network window a bit wider, so that other languages don't have overlapping strings
dominik
parents: 741
diff changeset
   596
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   597
{     WWT_IMGBTN,   RESIZE_NONE,   BGC,   100,   272,    22,    33, 0x0,                            STR_NETWORK_NEW_GAME_NAME_TIP},
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   598
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   285,   405,    22,    33, STR_NETWORK_SET_PASSWORD,     STR_NETWORK_PASSWORD_TIP},
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
   599
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   600
{          WWT_6,   RESIZE_NONE,   BGC,    10,   271,    62,   216, 0x0,                            STR_NETWORK_SELECT_MAP_TIP},
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   601
{  WWT_SCROLLBAR,   RESIZE_NONE,   BGC,   259,   270,    63,   215, 0x0,                            STR_0190_SCROLL_BAR_SCROLLS_LIST},
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   602
/* Combo boxes to control Connection Type / Max Clients / Max Companies / Max Observers / Language */
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   603
{          WWT_6,   RESIZE_NONE,   BGC,   280,   410,    77,    88, STR_NETWORK_COMBO1,           STR_NETWORK_CONNECTION_TIP},
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   604
{    WWT_TEXTBTN,   RESIZE_NONE,   BGC,   399,   409,    78,    87, STR_0225,                     STR_NETWORK_CONNECTION_TIP},
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   605
{          WWT_6,   RESIZE_NONE,   BGC,   280,   410,   109,   120, STR_NETWORK_COMBO2,           STR_NETWORK_NUMBER_OF_CLIENTS_TIP},
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   606
{    WWT_TEXTBTN,   RESIZE_NONE,   BGC,   399,   409,   110,   119, STR_0225,                     STR_NETWORK_NUMBER_OF_CLIENTS_TIP},
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   607
{          WWT_6,   RESIZE_NONE,   BGC,   280,   410,   141,   152, STR_NETWORK_COMBO3,           STR_NETWORK_NUMBER_OF_COMPANIES_TIP},
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   608
{    WWT_TEXTBTN,   RESIZE_NONE,   BGC,   399,   409,   142,   151, STR_0225,                     STR_NETWORK_NUMBER_OF_COMPANIES_TIP},
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   609
{          WWT_6,   RESIZE_NONE,   BGC,   280,   410,   173,   184, STR_NETWORK_COMBO4,           STR_NETWORK_NUMBER_OF_SPECTATORS_TIP},
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   610
{    WWT_TEXTBTN,   RESIZE_NONE,   BGC,   399,   409,   174,   183, STR_0225,                     STR_NETWORK_NUMBER_OF_SPECTATORS_TIP},
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   611
{          WWT_6,   RESIZE_NONE,   BGC,   280,   410,   205,   216, STR_NETWORK_COMBO5,           STR_NETWORK_LANGUAGE_TIP},
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   612
{    WWT_TEXTBTN,   RESIZE_NONE,   BGC,   399,   409,   206,   215, STR_0225,                     STR_NETWORK_LANGUAGE_TIP},
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
   613
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   614
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,    40,   140,   224,   235, STR_NETWORK_START_GAME,       STR_NETWORK_START_GAME_TIP},
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   615
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   150,   250,   224,   235, STR_NETWORK_LOAD_GAME,          STR_NETWORK_LOAD_GAME_TIP},
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   616
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   260,   360,   224,   235, STR_012E_CANCEL,                STR_NULL},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 175
diff changeset
   617
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   618
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   619
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   620
static const WindowDesc _network_start_server_window_desc = {
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   621
	WDP_CENTER, WDP_CENTER, 420, 244,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   622
	WC_NETWORK_WINDOW,0,
2064
c889fcc76398 (svn r2573) Codechange: Removed WDF_RESTORE_DPARAM, it's not needed with the new string system.
ludde
parents: 2055
diff changeset
   623
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   624
	_network_start_server_window_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   625
	NetworkStartServerWindowWndProc,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   626
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   627
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   628
static void ShowNetworkStartServerWindow(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   629
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   630
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   631
	DeleteWindowById(WC_NETWORK_WINDOW, 0);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   632
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   633
	w = AllocateWindowDesc(&_network_start_server_window_desc);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   634
	ttd_strlcpy(_edit_str_buf, _network_server_name, MAX_QUERYSTR_LEN);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   635
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   636
	_saveload_mode = SLD_NEW_GAME;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   637
	BuildFileList();
853
6d38ea6bf4ce (svn r1334) Fix: [ 1093466 ] no more glitches with many maps in the scenario list when creating server
dominik
parents: 842
diff changeset
   638
	w->vscroll.cap = 9;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   639
	w->vscroll.count = _fios_num+1;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   640
1390
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1363
diff changeset
   641
	WP(w, querystr_d).text.caret = true;
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1363
diff changeset
   642
	WP(w, querystr_d).text.maxlength = MAX_QUERYSTR_LEN - 1;
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1363
diff changeset
   643
	WP(w, querystr_d).text.maxwidth = 160;
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1363
diff changeset
   644
	WP(w, querystr_d).text.buf = _edit_str_buf;
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1363
diff changeset
   645
	UpdateTextBufferSize(&WP(w, querystr_d).text);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   646
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   647
734
018e549265ed (svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents: 722
diff changeset
   648
static byte NetworkLobbyFindCompanyIndex(byte pos)
018e549265ed (svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents: 722
diff changeset
   649
{
018e549265ed (svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents: 722
diff changeset
   650
	byte i;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   651
734
018e549265ed (svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents: 722
diff changeset
   652
	/* Scroll through all _network_player_info and get the 'pos' item
018e549265ed (svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents: 722
diff changeset
   653
	    that is not empty */
018e549265ed (svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents: 722
diff changeset
   654
	for (i = 0; i < MAX_PLAYERS; i++) {
018e549265ed (svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents: 722
diff changeset
   655
		if (_network_player_info[i].company_name[0] != '\0') {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   656
			if (pos-- == 0) return i;
734
018e549265ed (svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents: 722
diff changeset
   657
		}
018e549265ed (svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents: 722
diff changeset
   658
	}
018e549265ed (svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents: 722
diff changeset
   659
018e549265ed (svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents: 722
diff changeset
   660
	return 0;
018e549265ed (svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents: 722
diff changeset
   661
}
018e549265ed (svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents: 722
diff changeset
   662
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   663
static void NetworkLobbyWindowWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   664
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   665
	switch (e->event) {
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   666
	case WE_CREATE:
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   667
		_selected_company_item = -1;
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   668
		break;
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   669
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   670
	case WE_PAINT: {
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   671
		const NetworkGameInfo *gi = &_network_game_info;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   672
		int y = NET_PRC__OFFSET_TOP_WIDGET_COMPANY, pos;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   673
1025
882be6e4ad19 (svn r1526) -Fix: [1103027] Minor changes for the lobby GUI (widen window) (bociusz)
darkvater
parents: 1019
diff changeset
   674
		w->disabled_state = (_selected_company_item == -1) ? 1 << 7 : 0;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   675
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   676
		if (gi->companies_on == gi->companies_max) SETBIT(w->disabled_state, 8);
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   677
		if (gi->spectators_on == gi->spectators_max) SETBIT(w->disabled_state, 9);
735
5c8bacd9fa7e (svn r1187) -Fix: [Network] You can no longer join as spectator a game with no
truelight
parents: 734
diff changeset
   678
		/* You can not join a server as spectator when it has no companies active..
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   679
		 * it causes some nasty crashes */
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   680
		if (gi->companies_on == 0) SETBIT(w->disabled_state, 9);
621
334872f978c3 (svn r1051) -Fix: [Network] New Company button is disabled when there is no more
truelight
parents: 618
diff changeset
   681
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   682
		DrawWindowWidgets(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   683
2064
c889fcc76398 (svn r2573) Codechange: Removed WDF_RESTORE_DPARAM, it's not needed with the new string system.
ludde
parents: 2055
diff changeset
   684
		SetDParamStr(0, _selected_item->info.server_name);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   685
		DrawString(10, 22, STR_NETWORK_PREPARE_TO_JOIN, 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   686
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   687
		// draw company list
1025
882be6e4ad19 (svn r1526) -Fix: [1103027] Minor changes for the lobby GUI (widen window) (bociusz)
darkvater
parents: 1019
diff changeset
   688
		GfxFillRect(11, 41, 154, 165, 0xD7);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   689
		pos = w->vscroll.pos;
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   690
		while (pos < gi->companies_on) {
734
018e549265ed (svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents: 722
diff changeset
   691
			byte index = NetworkLobbyFindCompanyIndex(pos);
1011
2587838541bf (svn r1510) -Add: Improved Network Lobby GUI: (bociusz)
truelight
parents: 1009
diff changeset
   692
			bool income = false;
734
018e549265ed (svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents: 722
diff changeset
   693
			if (_selected_company_item == index)
1025
882be6e4ad19 (svn r1526) -Fix: [1103027] Minor changes for the lobby GUI (widen window) (bociusz)
darkvater
parents: 1019
diff changeset
   694
				GfxFillRect(11, y - 1, 154, y + 10, 155); // show highlighted item with a different colour
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   695
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   696
			DoDrawStringTruncated(_network_player_info[index].company_name, 13, y, 2, 135 - 13);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   697
			if (_network_player_info[index].use_password != 0)
1025
882be6e4ad19 (svn r1526) -Fix: [1103027] Minor changes for the lobby GUI (widen window) (bociusz)
darkvater
parents: 1019
diff changeset
   698
				DrawSprite(SPR_LOCK, 135, y);
1011
2587838541bf (svn r1510) -Add: Improved Network Lobby GUI: (bociusz)
truelight
parents: 1009
diff changeset
   699
2587838541bf (svn r1510) -Add: Improved Network Lobby GUI: (bociusz)
truelight
parents: 1009
diff changeset
   700
			/* If the company's income was positive puts a green dot else a red dot */
1025
882be6e4ad19 (svn r1526) -Fix: [1103027] Minor changes for the lobby GUI (widen window) (bociusz)
darkvater
parents: 1019
diff changeset
   701
			if ((_network_player_info[index].income) >= 0)
1011
2587838541bf (svn r1510) -Add: Improved Network Lobby GUI: (bociusz)
truelight
parents: 1009
diff changeset
   702
				income = true;
1025
882be6e4ad19 (svn r1526) -Fix: [1103027] Minor changes for the lobby GUI (widen window) (bociusz)
darkvater
parents: 1019
diff changeset
   703
			DrawSprite(SPR_BLOT | (income ? PALETTE_TO_GREEN : PALETTE_TO_RED), 145, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   704
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   705
			pos++;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   706
			y += NET_PRC__SIZE_OF_ROW_COMPANY;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   707
			if (pos >= w->vscroll.cap) break;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   708
		}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   709
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   710
		// draw info about selected company
1025
882be6e4ad19 (svn r1526) -Fix: [1103027] Minor changes for the lobby GUI (widen window) (bociusz)
darkvater
parents: 1019
diff changeset
   711
		DrawStringMultiCenter(290, 48, STR_NETWORK_COMPANY_INFO, 0);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   712
		if (_selected_company_item != -1) { // if a company is selected...
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   713
			// show company info
1025
882be6e4ad19 (svn r1526) -Fix: [1103027] Minor changes for the lobby GUI (widen window) (bociusz)
darkvater
parents: 1019
diff changeset
   714
			const uint x = 183;
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   715
			const uint trunc_width = w->widget[6].right - x;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   716
			y = 65;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   717
2055
9361b56db8ba (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 1916
diff changeset
   718
			SetDParamStr(0, _network_player_info[_selected_company_item].company_name);
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   719
			DrawStringTruncated(x, y, STR_NETWORK_COMPANY_NAME, 2, trunc_width);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   720
			y += 10;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   721
970
492ca84ecc6c (svn r1465) -Fix: [1099101] starting year patch goes out of range. Clamped year between 1920-2090 as wel as adding defines for it.
darkvater
parents: 897
diff changeset
   722
			SetDParam(0, _network_player_info[_selected_company_item].inaugurated_year + MAX_YEAR_BEGIN_REAL);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   723
			DrawString(x, y, STR_NETWORK_INAUGURATION_YEAR, 2); // inauguration year
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   724
			y += 10;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   725
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   726
			SetDParam64(0, _network_player_info[_selected_company_item].company_value);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   727
			DrawString(x, y, STR_NETWORK_VALUE, 2); // company value
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   728
			y += 10;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   729
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   730
			SetDParam64(0, _network_player_info[_selected_company_item].money);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   731
			DrawString(x, y, STR_NETWORK_CURRENT_BALANCE, 2); // current balance
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   732
			y += 10;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   733
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   734
			SetDParam64(0, _network_player_info[_selected_company_item].income);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   735
			DrawString(x, y, STR_NETWORK_LAST_YEARS_INCOME, 2); // last year's income
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   736
			y += 10;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   737
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   738
			SetDParam(0, _network_player_info[_selected_company_item].performance);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   739
			DrawString(x, y, STR_NETWORK_PERFORMANCE, 2); // performance
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   740
			y += 10;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   741
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   742
			SetDParam(0, _network_player_info[_selected_company_item].num_vehicle[0]);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   743
			SetDParam(1, _network_player_info[_selected_company_item].num_vehicle[1]);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   744
			SetDParam(2, _network_player_info[_selected_company_item].num_vehicle[2]);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   745
			SetDParam(3, _network_player_info[_selected_company_item].num_vehicle[3]);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   746
			SetDParam(4, _network_player_info[_selected_company_item].num_vehicle[4]);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   747
			DrawString(x, y, STR_NETWORK_VEHICLES, 2); // vehicles
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   748
			y += 10;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   749
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   750
			SetDParam(0, _network_player_info[_selected_company_item].num_station[0]);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   751
			SetDParam(1, _network_player_info[_selected_company_item].num_station[1]);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   752
			SetDParam(2, _network_player_info[_selected_company_item].num_station[2]);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   753
			SetDParam(3, _network_player_info[_selected_company_item].num_station[3]);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   754
			SetDParam(4, _network_player_info[_selected_company_item].num_station[4]);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   755
			DrawString(x, y, STR_NETWORK_STATIONS, 2); // stations
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   756
			y += 10;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   757
2055
9361b56db8ba (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 1916
diff changeset
   758
			SetDParamStr(0, _network_player_info[_selected_company_item].players);
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   759
			DrawStringTruncated(x, y, STR_NETWORK_PLAYERS, 2, trunc_width); // players
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   760
			y += 10;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   761
		}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   762
	}	break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   763
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   764
	case WE_CLICK:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   765
		switch(e->click.widget) {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   766
		case 0: case 11: /* Close 'X' | Cancel button */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   767
			ShowNetworkGameWindow();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   768
			break;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   769
		case 3: /* Company list */
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   770
			_selected_company_item = (e->click.pt.y - NET_PRC__OFFSET_TOP_WIDGET_COMPANY) / NET_PRC__SIZE_OF_ROW_COMPANY;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   771
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   772
			if (_selected_company_item >= w->vscroll.cap) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   773
				// click out of bounds
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   774
				_selected_company_item = -1;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   775
				SetWindowDirty(w);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   776
				return;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   777
			}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   778
			_selected_company_item += w->vscroll.pos;
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2788
diff changeset
   779
			if (_selected_company_item >= _network_game_info.companies_on) {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   780
				_selected_company_item = -1;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   781
				SetWindowDirty(w);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   782
				return;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   783
			}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   784
734
018e549265ed (svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents: 722
diff changeset
   785
			_selected_company_item = NetworkLobbyFindCompanyIndex(_selected_company_item);
018e549265ed (svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents: 722
diff changeset
   786
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   787
			SetWindowDirty(w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   788
			break;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   789
		case 7: /* Join company */
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   790
			if (_selected_company_item != -1) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   791
				_network_playas = _selected_company_item + 1;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   792
				NetworkClientConnectGame(_network_last_host, _network_last_port);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   793
			}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   794
			break;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   795
		case 8: /* New company */
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   796
			_network_playas = 0;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   797
			NetworkClientConnectGame(_network_last_host, _network_last_port);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   798
			break;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   799
		case 9: /* Spectate game */
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   800
			_network_playas = OWNER_SPECTATOR;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   801
			NetworkClientConnectGame(_network_last_host, _network_last_port);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   802
			break;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   803
		case 10: /* Refresh */
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   804
			NetworkQueryServer(_network_last_host, _network_last_port, false);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   805
			break;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   806
		}	break;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   807
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   808
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   809
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   810
static const Widget _network_lobby_window_widgets[] = {
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
   811
{   WWT_CLOSEBOX,   RESIZE_NONE,   BGC,     0,    10,     0,    13, STR_00C5,									STR_018B_CLOSE_WINDOW },
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
   812
{    WWT_CAPTION,   RESIZE_NONE,   BGC,    11,   419,     0,    13, STR_NETWORK_GAME_LOBBY,		STR_NULL},
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
   813
{     WWT_IMGBTN,   RESIZE_NONE,   BGC,     0,   419,    14,   209, 0x0,												STR_NULL},
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   814
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   815
// company list
1025
882be6e4ad19 (svn r1526) -Fix: [1103027] Minor changes for the lobby GUI (widen window) (bociusz)
darkvater
parents: 1019
diff changeset
   816
{          WWT_6,   RESIZE_NONE,   BGC,    10,   167,    40,   166, 0x0,												STR_NETWORK_COMPANY_LIST_TIP},
882be6e4ad19 (svn r1526) -Fix: [1103027] Minor changes for the lobby GUI (widen window) (bociusz)
darkvater
parents: 1019
diff changeset
   817
{  WWT_SCROLLBAR,   RESIZE_NONE,   BGC,   155,   166,    41,   165, 0x1,												STR_0190_SCROLL_BAR_SCROLLS_LIST},
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   818
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   819
// company/player info
1025
882be6e4ad19 (svn r1526) -Fix: [1103027] Minor changes for the lobby GUI (widen window) (bociusz)
darkvater
parents: 1019
diff changeset
   820
{     WWT_IMGBTN,   RESIZE_NONE,   BGC,   173,   404,    38,   166, 0x0,					STR_NULL},
882be6e4ad19 (svn r1526) -Fix: [1103027] Minor changes for the lobby GUI (widen window) (bociusz)
darkvater
parents: 1019
diff changeset
   821
{          WWT_6,   RESIZE_NONE,   BGC,   174,   403,    39,   165, 0x0,					STR_NULL},
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   822
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   823
// buttons
893
d9e69e5060ba (svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents: 867
diff changeset
   824
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,    10,   151,   175,   186, STR_NETWORK_JOIN_COMPANY,	STR_NETWORK_JOIN_COMPANY_TIP},
d9e69e5060ba (svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents: 867
diff changeset
   825
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,    10,   151,   190,   201, STR_NETWORK_NEW_COMPANY,		STR_NETWORK_NEW_COMPANY_TIP},
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
   826
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   158,   268,   175,   186, STR_NETWORK_SPECTATE_GAME,	STR_NETWORK_SPECTATE_GAME_TIP},
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
   827
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   158,   268,   190,   201, STR_NETWORK_REFRESH,				STR_NETWORK_REFRESH_TIP},
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
   828
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   278,   388,   175,   186, STR_012E_CANCEL,						STR_NULL},
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   829
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   830
{   WIDGETS_END},
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   831
};
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   832
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   833
static const WindowDesc _network_lobby_window_desc = {
749
ddf820fc3c53 (svn r1205) Fix: Made the network window a bit wider, so that other languages don't have overlapping strings
dominik
parents: 741
diff changeset
   834
	WDP_CENTER, WDP_CENTER, 420, 210,
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   835
	WC_NETWORK_WINDOW,0,
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   836
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   837
	_network_lobby_window_widgets,
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   838
	NetworkLobbyWindowWndProc,
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   839
};
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   840
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   841
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   842
static void ShowNetworkLobbyWindow(void)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   843
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   844
	Window *w;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   845
	DeleteWindowById(WC_NETWORK_WINDOW, 0);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   846
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   847
	NetworkQueryServer(_network_last_host, _network_last_port, false);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   848
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   849
	w = AllocateWindowDesc(&_network_lobby_window_desc);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   850
	strcpy(_edit_str_buf, "");
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   851
	w->vscroll.pos = 0;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   852
	w->vscroll.cap = 8;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   853
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   854
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   855
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   856
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   857
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   858
// The window below gives information about the connected clients
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   859
//  and also makes able to give money to them, kick them (if server)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   860
//  and stuff like that.
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   861
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   862
extern void DrawPlayerIcon(int p, int x, int y);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   863
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   864
// Every action must be of this form
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   865
typedef void ClientList_Action_Proc(byte client_no);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   866
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   867
// Max 10 actions per client
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   868
#define MAX_CLIENTLIST_ACTION 10
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   869
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   870
// Some standard bullshit.. defines variables ;)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   871
static void ClientListWndProc(Window *w, WindowEvent *e);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   872
static void ClientListPopupWndProc(Window *w, WindowEvent *e);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   873
static byte _selected_clientlist_item = 255;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   874
static byte _selected_clientlist_y = 0;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   875
static char _clientlist_action[MAX_CLIENTLIST_ACTION][50];
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   876
static ClientList_Action_Proc *_clientlist_proc[MAX_CLIENTLIST_ACTION];
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   877
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   878
enum {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   879
	CLNWND_OFFSET = 16,
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   880
	CLNWND_ROWSIZE = 10
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   881
};
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   882
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
   883
static const Widget _client_list_widgets[] = {
2725
5c632bc5be28 (svn r3270) Correct all (mis)uses of WWT_CLOSEBOX / WWT_TEXTBTN to reflect their actual use, and add "Close Window" tooltip where missing.
peter1138
parents: 2669
diff changeset
   884
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                 STR_018B_CLOSE_WINDOW},
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
   885
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   249,     0,    13, STR_NETWORK_CLIENT_LIST,  STR_018C_WINDOW_TITLE_DRAG_THIS},
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   886
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
   887
{     WWT_IMGBTN,   RESIZE_NONE,    14,     0,   249,    14,    14 + CLNWND_ROWSIZE + 1, 0x0, STR_NULL},
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   888
{   WIDGETS_END},
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   889
};
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   890
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
   891
static const Widget _client_list_popup_widgets[] = {
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
   892
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   99,     0,     0,     0,	STR_NULL},
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   893
{   WIDGETS_END},
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   894
};
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   895
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   896
static WindowDesc _client_list_desc = {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   897
	-1, -1, 250, 1,
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   898
	WC_CLIENT_LIST,0,
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   899
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   900
	_client_list_widgets,
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   901
	ClientListWndProc
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   902
};
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   903
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   904
// Finds the Xth client-info that is active
2630
35249d2ded3e (svn r3172) static, const
tron
parents: 2549
diff changeset
   905
static const NetworkClientInfo* NetworkFindClientInfo(byte client_no)
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   906
{
2630
35249d2ded3e (svn r3172) static, const
tron
parents: 2549
diff changeset
   907
	const NetworkClientInfo* ci;
35249d2ded3e (svn r3172) static, const
tron
parents: 2549
diff changeset
   908
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   909
	for (ci = _network_client_info; ci != &_network_client_info[MAX_CLIENT_INFO]; ci++) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   910
		// Skip non-active items
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   911
		if (ci->client_index == NETWORK_EMPTY_INDEX) continue;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   912
		if (client_no == 0) return ci;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   913
		client_no--;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   914
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   915
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   916
	return NULL;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   917
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   918
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   919
// Here we start to define the options out of the menu
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   920
static void ClientList_Kick(byte client_no)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   921
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   922
	if (client_no < MAX_PLAYERS)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   923
		SEND_COMMAND(PACKET_SERVER_ERROR)(&_clients[client_no], NETWORK_ERROR_KICKED);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   924
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   925
841
8f0a68c6f43b (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
   926
static void ClientList_Ban(byte client_no)
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   927
{
841
8f0a68c6f43b (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
   928
	uint i;
8f0a68c6f43b (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
   929
	uint32 ip = NetworkFindClientInfo(client_no)->client_ip;
8f0a68c6f43b (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
   930
8f0a68c6f43b (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
   931
	for (i = 0; i < lengthof(_network_ban_list); i++) {
8f0a68c6f43b (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
   932
		if (_network_ban_list[i] == NULL || _network_ban_list[i][0] == '\0') {
8f0a68c6f43b (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
   933
			_network_ban_list[i] = strdup(inet_ntoa(*(struct in_addr *)&ip));
8f0a68c6f43b (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
   934
			break;
8f0a68c6f43b (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
   935
		}
8f0a68c6f43b (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
   936
	}
8f0a68c6f43b (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
   937
8f0a68c6f43b (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
   938
	if (client_no < MAX_PLAYERS)
8f0a68c6f43b (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
   939
		SEND_COMMAND(PACKET_SERVER_ERROR)(&_clients[client_no], NETWORK_ERROR_KICKED);
8f0a68c6f43b (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
   940
}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   941
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   942
static void ClientList_GiveMoney(byte client_no)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   943
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   944
	if (NetworkFindClientInfo(client_no) != NULL)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   945
		ShowNetworkGiveMoneyWindow(NetworkFindClientInfo(client_no)->client_playas - 1);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   946
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   947
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   948
static void ClientList_SpeakToClient(byte client_no)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   949
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   950
	if (NetworkFindClientInfo(client_no) != NULL)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   951
		ShowNetworkChatQueryWindow(DESTTYPE_CLIENT, NetworkFindClientInfo(client_no)->client_index);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   952
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   953
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   954
static void ClientList_SpeakToPlayer(byte client_no)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   955
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   956
	if (NetworkFindClientInfo(client_no) != NULL)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   957
		ShowNetworkChatQueryWindow(DESTTYPE_PLAYER, NetworkFindClientInfo(client_no)->client_playas);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   958
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   959
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   960
static void ClientList_SpeakToAll(byte client_no)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   961
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   962
	ShowNetworkChatQueryWindow(DESTTYPE_BROADCAST, 0);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   963
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   964
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   965
static void ClientList_None(byte client_no)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   966
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   967
	// No action ;)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   968
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   969
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   970
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   971
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   972
// Help, a action is clicked! What do we do?
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   973
static void HandleClientListPopupClick(byte index, byte clientno) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   974
	// A click on the Popup of the ClientList.. handle the command
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   975
	if (index < MAX_CLIENTLIST_ACTION && _clientlist_proc[index] != NULL) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   976
		_clientlist_proc[index](clientno);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   977
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   978
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   979
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   980
// Finds the amount of clients and set the height correct
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   981
static bool CheckClientListHeight(Window *w)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   982
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   983
	int num = 0;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   984
	NetworkClientInfo *ci;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   985
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   986
	// Should be replaced with a loop through all clients
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   987
	for (ci = _network_client_info; ci != &_network_client_info[MAX_CLIENT_INFO]; ci++) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   988
		// Skip non-active items
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   989
		if (ci->client_index == NETWORK_EMPTY_INDEX) continue;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   990
		num++;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   991
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   992
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   993
	num *= CLNWND_ROWSIZE;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   994
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   995
	// If height is changed
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
   996
	if (w->height != CLNWND_OFFSET + num + 1) {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   997
		// XXX - magic unfortunately; (num + 2) has to be one bigger than heigh (num + 1)
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
   998
		SetWindowDirty(w);
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
   999
		w->widget[2].bottom = w->widget[2].top + num + 2;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
  1000
		w->height = CLNWND_OFFSET + num + 1;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
  1001
		SetWindowDirty(w);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1002
		return false;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1003
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1004
	return true;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1005
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1006
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1007
// Finds the amount of actions in the popup and set the height correct
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
  1008
static uint ClientListPopupHeigth(void) {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1009
	int i, num = 0;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1010
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1011
	// Find the amount of actions
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1012
	for (i = 0; i < MAX_CLIENTLIST_ACTION; i++) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1013
		if (_clientlist_action[i][0] == '\0') continue;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1014
		if (_clientlist_proc[i] == NULL) continue;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1015
		num++;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1016
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1017
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1018
	num *= CLNWND_ROWSIZE;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
  1019
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
  1020
	return num + 1;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1021
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1022
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1023
// Show the popup (action list)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1024
static Window *PopupClientList(Window *w, int client_no, int x, int y)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1025
{
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
  1026
	int i, h;
2630
35249d2ded3e (svn r3172) static, const
tron
parents: 2549
diff changeset
  1027
	const NetworkClientInfo* ci;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1028
	DeleteWindowById(WC_TOOLBAR_MENU, 0);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1029
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1030
	// Clean the current actions
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1031
	for (i = 0; i < MAX_CLIENTLIST_ACTION; i++) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1032
		_clientlist_action[i][0] = '\0';
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1033
		_clientlist_proc[i] = NULL;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1034
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1035
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1036
	// Fill the actions this client has
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1037
	// Watch is, max 50 chars long!
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1038
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1039
	ci = NetworkFindClientInfo(client_no);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1040
	if (ci == NULL) return NULL;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1041
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1042
	i = 0;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1043
	if (_network_own_client_index != ci->client_index) {
722
d0b031be5232 (svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents: 716
diff changeset
  1044
		GetString(_clientlist_action[i], STR_NETWORK_CLIENTLIST_SPEAK_TO_CLIENT);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1045
		_clientlist_proc[i++] = &ClientList_SpeakToClient;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1046
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1047
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1048
	if (ci->client_playas >= 1 && ci->client_playas <= MAX_PLAYERS) {
722
d0b031be5232 (svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents: 716
diff changeset
  1049
		GetString(_clientlist_action[i], STR_NETWORK_CLIENTLIST_SPEAK_TO_COMPANY);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1050
		_clientlist_proc[i++] = &ClientList_SpeakToPlayer;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1051
	}
722
d0b031be5232 (svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents: 716
diff changeset
  1052
	GetString(_clientlist_action[i], STR_NETWORK_CLIENTLIST_SPEAK_TO_ALL);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1053
	_clientlist_proc[i++] = &ClientList_SpeakToAll;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1054
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1055
	if (_network_own_client_index != ci->client_index) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1056
		if (_network_playas >= 1 && _network_playas <= MAX_PLAYERS) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1057
			// We are no spectator
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1058
			if (ci->client_playas >= 1 && ci->client_playas <= MAX_PLAYERS) {
722
d0b031be5232 (svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents: 716
diff changeset
  1059
				GetString(_clientlist_action[i], STR_NETWORK_CLIENTLIST_GIVE_MONEY);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1060
				_clientlist_proc[i++] = &ClientList_GiveMoney;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1061
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1062
		}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1063
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1064
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1065
	// A server can kick clients (but not hisself)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1066
	if (_network_server && _network_own_client_index != ci->client_index) {
722
d0b031be5232 (svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents: 716
diff changeset
  1067
		GetString(_clientlist_action[i], STR_NETWORK_CLIENTLIST_KICK);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1068
		_clientlist_proc[i++] = &ClientList_Kick;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1069
841
8f0a68c6f43b (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
  1070
		sprintf(_clientlist_action[i],"Ban");
8f0a68c6f43b (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
  1071
		_clientlist_proc[i++] = &ClientList_Ban;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1072
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1073
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1074
	if (i == 0) {
722
d0b031be5232 (svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents: 716
diff changeset
  1075
		GetString(_clientlist_action[i], STR_NETWORK_CLIENTLIST_NONE);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1076
		_clientlist_proc[i++] = &ClientList_None;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1077
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1078
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
  1079
	/* Calculate the height */
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
  1080
	h = ClientListPopupHeigth();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1081
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1082
	// Allocate the popup
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
  1083
	w = AllocateWindow(x, y, 100, h + 1, ClientListPopupWndProc, WC_TOOLBAR_MENU, _client_list_popup_widgets);
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
  1084
	w->widget[0].bottom = w->widget[0].top + h;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
  1085
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1086
	w->flags4 &= ~WF_WHITE_BORDER_MASK;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1087
	WP(w,menu_d).item_count = 0;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1088
	// Save our client
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1089
	WP(w,menu_d).main_button = client_no;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1090
	WP(w,menu_d).sel_index = 0;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1091
	// We are a popup
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1092
	_popup_menu_active = true;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1093
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1094
	return w;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1095
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1096
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1097
// Main handle for the popup
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1098
static void ClientListPopupWndProc(Window *w, WindowEvent *e)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1099
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1100
	switch (e->event) {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1101
	case WE_PAINT: {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1102
		int i, y, sel;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1103
		byte colour;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1104
		DrawWindowWidgets(w);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1105
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1106
		// Draw the actions
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1107
		sel = WP(w,menu_d).sel_index;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1108
		y = 1;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1109
		for (i = 0; i < MAX_CLIENTLIST_ACTION; i++, y += CLNWND_ROWSIZE) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1110
			if (_clientlist_action[i][0] == '\0') continue;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1111
			if (_clientlist_proc[i] == NULL) continue;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1112
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1113
			if (sel-- == 0) { // Selected item, highlight it
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1114
				GfxFillRect(1, y, 98, y + CLNWND_ROWSIZE - 1, 0);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1115
				colour = 0xC;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1116
			} else colour = 0x10;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1117
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1118
			DoDrawString(_clientlist_action[i], 4, y, colour);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1119
		}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1120
	}	break;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1121
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1122
	case WE_POPUPMENU_SELECT: {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1123
		// We selected an action
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1124
		int index = (e->popupmenu.pt.y - w->top) / CLNWND_ROWSIZE;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1125
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1126
		if (index >= 0 && e->popupmenu.pt.y >= w->top)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1127
			HandleClientListPopupClick(index, WP(w,menu_d).main_button);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1128
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1129
		// Sometimes, because of the bad DeleteWindow-proc, the 'w' pointer is
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1130
		//  invalid after the last functions (mostly because it kills a window
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1131
		//  that is in front of 'w', and because of a silly memmove, the address
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1132
		//  'w' was pointing to becomes invalid), so we need to refetch
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1133
		//  the right address...
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1134
		DeleteWindowById(WC_TOOLBAR_MENU, 0);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1135
	}	break;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1136
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1137
	case WE_POPUPMENU_OVER: {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1138
		// Our mouse hoovers over an action? Select it!
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1139
		int index = (e->popupmenu.pt.y - w->top) / CLNWND_ROWSIZE;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1140
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1141
		if (index == -1 || index == WP(w,menu_d).sel_index)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1142
			return;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1143
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1144
		WP(w,menu_d).sel_index = index;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1145
		SetWindowDirty(w);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1146
	} break;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1147
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1148
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1149
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1150
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1151
// Main handle for clientlist
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1152
static void ClientListWndProc(Window *w, WindowEvent *e)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1153
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1154
	switch (e->event) {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1155
	case WE_PAINT: {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1156
		NetworkClientInfo *ci;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1157
		int y, i = 0;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1158
		byte colour;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1159
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1160
		// Check if we need to reset the height
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1161
		if (!CheckClientListHeight(w)) break;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1162
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1163
		DrawWindowWidgets(w);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1164
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1165
		y = CLNWND_OFFSET;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1166
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1167
		for (ci = _network_client_info; ci != &_network_client_info[MAX_CLIENT_INFO]; ci++) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1168
			// Skip non-active items
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1169
			if (ci->client_index == NETWORK_EMPTY_INDEX) continue;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1170
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1171
			if (_selected_clientlist_item == i++) { // Selected item, highlight it
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1172
				GfxFillRect(1, y, 248, y + CLNWND_ROWSIZE - 1, 0);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1173
				colour = 0xC;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1174
			} else
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1175
				colour = 0x10;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1176
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1177
			if (ci->client_index == NETWORK_SERVER_INDEX) {
722
d0b031be5232 (svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents: 716
diff changeset
  1178
				DrawString(4, y, STR_NETWORK_SERVER, colour);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1179
			} else {
722
d0b031be5232 (svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents: 716
diff changeset
  1180
				DrawString(4, y, STR_NETWORK_CLIENT, colour);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1181
			}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1182
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1183
			// Filter out spectators
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1184
			if (ci->client_playas > 0 && ci->client_playas <= MAX_PLAYERS)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1185
				DrawPlayerIcon(ci->client_playas - 1, 44, y + 1);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1186
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1187
			DoDrawString(ci->client_name, 61, y, colour);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1188
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1189
			y += CLNWND_ROWSIZE;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1190
		}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1191
	}	break;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1192
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1193
	case WE_CLICK:
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1194
		// Show the popup with option
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1195
		if (_selected_clientlist_item != 255) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1196
			PopupClientList(w, _selected_clientlist_item, e->click.pt.x + w->left, e->click.pt.y + w->top);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1197
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
  1198
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1199
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1200
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1201
	case WE_MOUSEOVER:
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1202
		// -1 means we left the current window
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1203
		if (e->mouseover.pt.y == -1) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1204
			_selected_clientlist_y = 0;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1205
			_selected_clientlist_item = 255;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1206
			SetWindowDirty(w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1207
			break;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1208
		}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1209
		// It did not change.. no update!
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1210
		if (e->mouseover.pt.y == _selected_clientlist_y) break;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1211
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1212
		// Find the new selected item (if any)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1213
		_selected_clientlist_y = e->mouseover.pt.y;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1214
		if (e->mouseover.pt.y > CLNWND_OFFSET) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1215
			_selected_clientlist_item = (e->mouseover.pt.y - CLNWND_OFFSET) / CLNWND_ROWSIZE;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1216
		} else
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1217
			_selected_clientlist_item = 255;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1218
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1219
		// Repaint
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1220
		SetWindowDirty(w);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1221
		break;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1222
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1223
	case WE_DESTROY: case WE_CREATE:
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1224
		// When created or destroyed, data is reset
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1225
		_selected_clientlist_item = 255;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1226
		_selected_clientlist_y = 0;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1227
		break;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1228
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1229
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1230
1003
5ce43e332bab (svn r1502) -Fix: [1101889] Crash under windows... stupid typo in player_gui.c ^ should've been &
darkvater
parents: 982
diff changeset
  1231
void ShowClientList(void)
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1232
{
1003
5ce43e332bab (svn r1502) -Fix: [1101889] Crash under windows... stupid typo in player_gui.c ^ should've been &
darkvater
parents: 982
diff changeset
  1233
	Window *w = AllocateWindowDescFront(&_client_list_desc, 0);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1234
	if (w != NULL) w->window_number = 0;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1235
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1236
685
2c5718e78773 (svn r1126) -Fix: [Network] Pressing Disconnect on the GUI puts you back to the
truelight
parents: 675
diff changeset
  1237
extern void SwitchMode(int new_mode);
2c5718e78773 (svn r1126) -Fix: [Network] Pressing Disconnect on the GUI puts you back to the
truelight
parents: 675
diff changeset
  1238
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1239
static void NetworkJoinStatusWindowWndProc(Window *w, WindowEvent *e)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1240
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1241
	switch (e->event) {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1242
	case WE_PAINT: {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1243
		uint8 progress; // used for progress bar
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1244
		DrawWindowWidgets(w);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1245
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1246
		DrawStringCentered(125, 35, STR_NETWORK_CONNECTING_1 + _network_join_status, 14);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1247
		switch (_network_join_status) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1248
			case NETWORK_JOIN_STATUS_CONNECTING: case NETWORK_JOIN_STATUS_AUTHORIZING:
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1249
			case NETWORK_JOIN_STATUS_GETTING_COMPANY_INFO:
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1250
				progress = 10; // first two stages 10%
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1251
				break;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1252
			case NETWORK_JOIN_STATUS_WAITING:
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1253
				SetDParam(0, _network_join_waiting);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1254
				DrawStringCentered(125, 46, STR_NETWORK_CONNECTING_WAITING, 14);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1255
				progress = 15; // third stage is 15%
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1256
				break;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1257
			case NETWORK_JOIN_STATUS_DOWNLOADING:
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1258
				SetDParam(0, _network_join_kbytes);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1259
				SetDParam(1, _network_join_kbytes_total);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1260
				DrawStringCentered(125, 46, STR_NETWORK_CONNECTING_DOWNLOADING, 14);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1261
				/* Fallthrough */
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1262
			default: /* Waiting is 15%, so the resting receivement of map is maximum 70% */
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1263
				progress = 15 + _network_join_kbytes * (100 - 15) / _network_join_kbytes_total;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1264
		}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1265
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1266
		/* Draw nice progress bar :) */
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1267
		DrawFrameRect(20, 18, (int)((w->width - 20) * progress / 100), 28, 10, 0);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1268
	}	break;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1269
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1270
	case WE_CLICK:
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1271
		switch (e->click.widget) {
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1272
			case 0: /* Close 'X' */
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1273
			case 3: /* Disconnect button */
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1274
				NetworkDisconnect();
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1275
				DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1276
				SwitchMode(SM_MENU);
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1277
				ShowNetworkGameWindow();
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1278
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1279
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1280
		break;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
  1281
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1282
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1283
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1284
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1285
static const Widget _network_join_status_window_widget[] = {
2725
5c632bc5be28 (svn r3270) Correct all (mis)uses of WWT_CLOSEBOX / WWT_TEXTBTN to reflect their actual use, and add "Close Window" tooltip where missing.
peter1138
parents: 2669
diff changeset
  1286
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5, STR_018B_CLOSE_WINDOW},
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
  1287
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   249,     0,    13, STR_NETWORK_CONNECTING, STR_018C_WINDOW_TITLE_DRAG_THIS},
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
  1288
{     WWT_IMGBTN,   RESIZE_NONE,    14,     0,   249,    14,    84, 0x0,STR_NULL},
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
  1289
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,    75,   175,    69,    80, STR_NETWORK_DISCONNECT, STR_NULL},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 175
diff changeset
  1290
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1291
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1292
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1293
static const WindowDesc _network_join_status_window_desc = {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1294
	WDP_CENTER, WDP_CENTER, 250, 85,
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1295
	WC_NETWORK_STATUS_WINDOW, 0,
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1296
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET,
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1297
	_network_join_status_window_widget,
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1298
	NetworkJoinStatusWindowWndProc,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1299
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1300
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1025
diff changeset
  1301
void ShowJoinStatusWindow(void)
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1302
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1303
	DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1304
	_network_join_status = NETWORK_JOIN_STATUS_CONNECTING;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1305
	AllocateWindowDesc(&_network_join_status_window_desc);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1306
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1307
774
258c11431acb (svn r1240) -Fix: OpenTTD once again compiles if ENABLE_NETWORK is disabled.
darkvater
parents: 764
diff changeset
  1308
void ShowJoinStatusWindowAfterJoin(void)
670
7c58dc46609c (svn r1108) -Fix: [Network] Fixed problem around slow clients:
truelight
parents: 659
diff changeset
  1309
{
7c58dc46609c (svn r1108) -Fix: [Network] Fixed problem around slow clients:
truelight
parents: 659
diff changeset
  1310
	/* This is a special instant of ShowJoinStatusWindow, because
7c58dc46609c (svn r1108) -Fix: [Network] Fixed problem around slow clients:
truelight
parents: 659
diff changeset
  1311
	    it is opened after the map is loaded, but the client maybe is not
7c58dc46609c (svn r1108) -Fix: [Network] Fixed problem around slow clients:
truelight
parents: 659
diff changeset
  1312
	    done registering itself to the server */
7c58dc46609c (svn r1108) -Fix: [Network] Fixed problem around slow clients:
truelight
parents: 659
diff changeset
  1313
	DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
7c58dc46609c (svn r1108) -Fix: [Network] Fixed problem around slow clients:
truelight
parents: 659
diff changeset
  1314
	_network_join_status = NETWORK_JOIN_STATUS_REGISTERING;
7c58dc46609c (svn r1108) -Fix: [Network] Fixed problem around slow clients:
truelight
parents: 659
diff changeset
  1315
	AllocateWindowDesc(&_network_join_status_window_desc);
7c58dc46609c (svn r1108) -Fix: [Network] Fixed problem around slow clients:
truelight
parents: 659
diff changeset
  1316
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1317
649
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1318
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1319
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1320
#define MAX_QUERYSTR_LEN 64
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1321
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1322
static void ChatWindowWndProc(Window *w, WindowEvent *e)
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1323
{
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1324
	static bool closed = false;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1325
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1390
diff changeset
  1326
	switch (e->event) {
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1390
diff changeset
  1327
	case WE_CREATE:
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1390
diff changeset
  1328
		SendWindowMessage(WC_NEWS_WINDOW, 0, WE_CREATE, w->height, 0);
1843
733f83b6483a (svn r2348) - Fix: Do not scroll the game with the arrow keys when the chatbox is open
Darkvater
parents: 1796
diff changeset
  1329
		SETBIT(_no_scroll, SCROLL_CHAT); // do not scroll the game with the arrow-keys
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1390
diff changeset
  1330
		closed = false;
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1390
diff changeset
  1331
		break;
649
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1332
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1390
diff changeset
  1333
	case WE_PAINT:
649
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1334
		DrawWindowWidgets(w);
1748
63104c477e40 (svn r2252) - ReFix: Redo r2251. Just remove the 'default widget handler', WDF_STD_BTN, instead of doing the "workaround" of the previous commit
Darkvater
parents: 1747
diff changeset
  1335
		DrawEditBox(w, 1);
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1390
diff changeset
  1336
		break;
649
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1337
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1338
	case WE_CLICK:
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1339
		switch (e->click.widget) {
1748
63104c477e40 (svn r2252) - ReFix: Redo r2251. Just remove the 'default widget handler', WDF_STD_BTN, instead of doing the "workaround" of the previous commit
Darkvater
parents: 1747
diff changeset
  1340
		case 3: DeleteWindow(w); break; // Cancel
63104c477e40 (svn r2252) - ReFix: Redo r2251. Just remove the 'default widget handler', WDF_STD_BTN, instead of doing the "workaround" of the previous commit
Darkvater
parents: 1747
diff changeset
  1341
		case 2: // Send
649
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1342
press_ok:;
1390
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1363
diff changeset
  1343
			if (strcmp(WP(w, querystr_d).text.buf, WP(w, querystr_d).text.buf + MAX_QUERYSTR_LEN) == 0) {
649
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1344
				DeleteWindow(w);
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1345
			} else {
1390
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1363
diff changeset
  1346
				char *buf = WP(w, querystr_d).text.buf;
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1363
diff changeset
  1347
				WindowClass wnd_class = WP(w, querystr_d).wnd_class;
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1363
diff changeset
  1348
				WindowNumber wnd_num = WP(w, querystr_d).wnd_num;
649
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1349
				Window *parent;
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1350
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1351
				// Mask the edit-box as closed, so we don't send out a CANCEL
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1352
				closed = true;
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1353
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1354
				DeleteWindow(w);
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1355
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1356
				parent = FindWindowById(wnd_class, wnd_num);
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1357
				if (parent != NULL) {
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1358
					WindowEvent e;
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1359
					e.event = WE_ON_EDIT_TEXT;
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1360
					e.edittext.str = buf;
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1361
					parent->wndproc(parent, &e);
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1362
				}
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1363
			}
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1364
			break;
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1365
		}
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1366
		break;
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1367
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1368
	case WE_MOUSELOOP: {
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1369
		if (!FindWindowById(WP(w,querystr_d).wnd_class, WP(w,querystr_d).wnd_num)) {
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1370
			DeleteWindow(w);
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1371
			return;
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1372
		}
1748
63104c477e40 (svn r2252) - ReFix: Redo r2251. Just remove the 'default widget handler', WDF_STD_BTN, instead of doing the "workaround" of the previous commit
Darkvater
parents: 1747
diff changeset
  1373
		HandleEditBox(w, 1);
649
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1374
	} break;
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1375
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1376
	case WE_KEYPRESS: {
1748
63104c477e40 (svn r2252) - ReFix: Redo r2251. Just remove the 'default widget handler', WDF_STD_BTN, instead of doing the "workaround" of the previous commit
Darkvater
parents: 1747
diff changeset
  1377
		switch(HandleEditBoxKey(w, 1, e)) {
649
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1378
		case 1: // Return
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1379
			goto press_ok;
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1380
		case 2: // Escape
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1381
			DeleteWindow(w);
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1382
			break;
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1383
		}
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1384
	} break;
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1385
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1386
	case WE_DESTROY:
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1390
diff changeset
  1387
		SendWindowMessage(WC_NEWS_WINDOW, 0, WE_DESTROY, 0, 0);
1843
733f83b6483a (svn r2348) - Fix: Do not scroll the game with the arrow keys when the chatbox is open
Darkvater
parents: 1796
diff changeset
  1388
		CLRBIT(_no_scroll, SCROLL_CHAT);
649
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1389
		// If the window is not closed yet, it means it still needs to send a CANCEL
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1390
		if (!closed) {
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1391
			Window *parent = FindWindowById(WP(w,querystr_d).wnd_class, WP(w,querystr_d).wnd_num);
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1392
			if (parent != NULL) {
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1393
				WindowEvent e;
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1394
				e.event = WE_ON_EDIT_TEXT_CANCEL;
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1395
				parent->wndproc(parent, &e);
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1396
			}
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1397
		}
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1398
		break;
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1399
	}
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1400
}
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1401
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1402
static const Widget _chat_window_widgets[] = {
1747
5fb41ff71c6c (svn r2251) - Fix: [ 1193945 ] Clicking on the chat text box causes an assertion failure
Darkvater
parents: 1653
diff changeset
  1403
{     WWT_IMGBTN,   RESIZE_NONE,    14,     0,   639,     0,    13, STR_NULL,         STR_NULL}, // background
5fb41ff71c6c (svn r2251) - Fix: [ 1193945 ] Clicking on the chat text box causes an assertion failure
Darkvater
parents: 1653
diff changeset
  1404
{     WWT_IMGBTN,   RESIZE_NONE,    14,     2,   399,     1,    12, STR_NULL,         STR_NULL}, // text box
5fb41ff71c6c (svn r2251) - Fix: [ 1193945 ] Clicking on the chat text box causes an assertion failure
Darkvater
parents: 1653
diff changeset
  1405
{    WWT_TEXTBTN,   RESIZE_NONE,    14,   400,   519,     1,    12, STR_NETWORK_SEND, STR_NULL}, // send button
5fb41ff71c6c (svn r2251) - Fix: [ 1193945 ] Clicking on the chat text box causes an assertion failure
Darkvater
parents: 1653
diff changeset
  1406
{    WWT_TEXTBTN,   RESIZE_NONE,    14,   520,   639,     1,    12, STR_012E_CANCEL,  STR_NULL}, // cancel button
649
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1407
{   WIDGETS_END},
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1408
};
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1409
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1410
static const WindowDesc _chat_window_desc = {
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1411
	WDP_CENTER, -26, 640, 14, // x, y, width, height
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1412
	WC_SEND_NETWORK_MSG,0,
1748
63104c477e40 (svn r2252) - ReFix: Redo r2251. Just remove the 'default widget handler', WDF_STD_BTN, instead of doing the "workaround" of the previous commit
Darkvater
parents: 1747
diff changeset
  1413
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET,
649
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1414
	_chat_window_widgets,
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1415
	ChatWindowWndProc
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1416
};
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1417
2788
db2896482939 (svn r3336) byte -> WindowClass, uint16 -> WindowNumber
tron
parents: 2775
diff changeset
  1418
void ShowChatWindow(StringID str, StringID caption, int maxlen, int maxwidth, WindowClass window_class, WindowNumber window_number)
649
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1419
{
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1420
	Window *w;
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1421
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1422
#define _orig_edit_str_buf (_edit_str_buf+MAX_QUERYSTR_LEN)
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1423
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1424
	DeleteWindowById(WC_SEND_NETWORK_MSG, 0);
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1425
1344
53e040e3990d (svn r1848) Remove the obscure feature of initialising the edit box with the contents of str_buffr - it was unused anyway.
tron
parents: 1328
diff changeset
  1426
	GetString(_orig_edit_str_buf, str);
649
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1427
1390
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1363
diff changeset
  1428
	_orig_edit_str_buf[maxlen] = '\0';
649
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1429
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1430
	memcpy(_edit_str_buf, _orig_edit_str_buf, MAX_QUERYSTR_LEN);
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1431
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1432
	w = AllocateWindowDesc(&_chat_window_desc);
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1433
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1434
	w->click_state = 1 << 1;
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1435
	WP(w,querystr_d).caption = caption;
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1436
	WP(w,querystr_d).wnd_class = window_class;
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1437
	WP(w,querystr_d).wnd_num = window_number;
1390
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1363
diff changeset
  1438
	WP(w,querystr_d).text.caret = false;
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1363
diff changeset
  1439
	WP(w,querystr_d).text.maxlength = maxlen - 1;
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1363
diff changeset
  1440
	WP(w,querystr_d).text.maxwidth = maxwidth;
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1363
diff changeset
  1441
	WP(w,querystr_d).text.buf = _edit_str_buf;
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1363
diff changeset
  1442
	UpdateTextBufferSize(&WP(w, querystr_d).text);
649
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1443
}
5b5f9ae5115f (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1444
774
258c11431acb (svn r1240) -Fix: OpenTTD once again compiles if ENABLE_NETWORK is disabled.
darkvater
parents: 764
diff changeset
  1445
#else
258c11431acb (svn r1240) -Fix: OpenTTD once again compiles if ENABLE_NETWORK is disabled.
darkvater
parents: 764
diff changeset
  1446
void ShowJoinStatusWindowAfterJoin(void) {}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1447
#endif /* ENABLE_NETWORK */