src/network/network_gui.cpp
author rubidium
Fri, 21 Dec 2007 21:50:46 +0000
changeset 8116 8da76dcb3287
parent 8114 dd6d21dc99c1
child 8123 ce31d2843a95
permissions -rw-r--r--
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
4826
6a545d194528 (svn r6750) -Codechange: Juggle around some header includes as they're only used when
Darkvater
parents: 4774
diff changeset
     3
#ifdef ENABLE_NETWORK
5469
7edfc643abbc (svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents: 5432
diff changeset
     4
#include "../stdafx.h"
7edfc643abbc (svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents: 5432
diff changeset
     5
#include "../openttd.h"
7edfc643abbc (svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents: 5432
diff changeset
     6
#include "../string.h"
8114
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8107
diff changeset
     7
#include "../strings_func.h"
5469
7edfc643abbc (svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents: 5432
diff changeset
     8
#include "../table/sprites.h"
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
     9
#include "network.h"
5469
7edfc643abbc (svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents: 5432
diff changeset
    10
#include "../date.h"
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    11
5469
7edfc643abbc (svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents: 5432
diff changeset
    12
#include "../fios.h"
5475
2e6990a8c7c4 (svn r7759) -Merge: makefile rewrite. This merge features:
rubidium
parents: 5469
diff changeset
    13
#include "table/strings.h"
5469
7edfc643abbc (svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents: 5432
diff changeset
    14
#include "../functions.h"
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    15
#include "network_data.h"
4013
53a7dd9a1fbf (svn r5226) Reduce the mess that sending chat messages is
tron
parents: 3860
diff changeset
    16
#include "network_client.h"
4826
6a545d194528 (svn r6750) -Codechange: Juggle around some header includes as they're only used when
Darkvater
parents: 4774
diff changeset
    17
#include "network_gui.h"
738
b96ab9e63d22 (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
    18
#include "network_gamelist.h"
5469
7edfc643abbc (svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents: 5432
diff changeset
    19
#include "../gui.h"
8107
bb7deea89175 (svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents: 8106
diff changeset
    20
#include "../window_gui.h"
bb7deea89175 (svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents: 8106
diff changeset
    21
#include "../textbuf_gui.h"
5469
7edfc643abbc (svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents: 5432
diff changeset
    22
#include "../gfx.h"
7edfc643abbc (svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents: 5432
diff changeset
    23
#include "../variables.h"
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    24
#include "network_server.h"
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    25
#include "network_udp.h"
5469
7edfc643abbc (svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents: 5432
diff changeset
    26
#include "../settings.h"
7edfc643abbc (svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents: 5432
diff changeset
    27
#include "../string.h"
7edfc643abbc (svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents: 5432
diff changeset
    28
#include "../town.h"
7edfc643abbc (svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents: 5432
diff changeset
    29
#include "../newgrf.h"
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
    30
#include "../helpers.hpp"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
#define BGC 5
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
#define BTC 15
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
    34
8107
bb7deea89175 (svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents: 8106
diff changeset
    35
struct chatquerystr_d : public querystr_d {
bb7deea89175 (svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents: 8106
diff changeset
    36
	int dest;
bb7deea89175 (svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents: 8106
diff changeset
    37
};
bb7deea89175 (svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents: 8106
diff changeset
    38
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(chatquerystr_d));
bb7deea89175 (svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents: 8106
diff changeset
    39
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    40
struct network_d {
3692
1d8f5041d437 (svn r4623) - Codechange: s/byte/PlayerID/
Darkvater
parents: 3470
diff changeset
    41
	PlayerID company;        // select company in network lobby
2888
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
    42
	byte field;              // select text-field in start-server and game-listing
7441
161822860e62 (svn r10888) -Fix (r10886): 64 bits alignment made a struct too big.
rubidium
parents: 7439
diff changeset
    43
	byte widget_id;          ///< The widget that has the pop-up input menu
2888
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
    44
	NetworkGameList *server; // selected server in lobby and game-listing
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
    45
	FiosItem *map;           // selected map in start-server
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    46
};
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
    47
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(network_d));
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
    48
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    49
struct network_ql_d {
2888
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
    50
	network_d n;                 // see above; general stuff
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
    51
	querystr_d q;                // text-input in start-server and game-listing
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
    52
	NetworkGameList **sort_list; // list of games (sorted)
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
    53
	list_d l;                    // accompanying list-administration
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    54
};
2888
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
    55
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(network_ql_d));
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
    56
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
    57
/* Global to remember sorting after window has been closed */
4542
f42ecc669275 (svn r6372) -Codechange: static, unneeded decleration in headers, superfluous header includes
Darkvater
parents: 4512
diff changeset
    58
static Listing _ng_sorting;
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
    59
4957
44b747809879 (svn r6956) -Feature: Increase the chatbuffer of chat messages. Messages longer than the allocated
Darkvater
parents: 4948
diff changeset
    60
static char _edit_str_buf[150];
4315
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
    61
static bool _chat_tab_completion_active;
3470
cd704e52732f (svn r4315) Remove MAX_QUERYSTR_LEN, rather use lengthof() the real thing
tron
parents: 3469
diff changeset
    62
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 5916
diff changeset
    63
static void ShowNetworkStartServerWindow();
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
    64
static void ShowNetworkLobbyWindow(NetworkGameList *ngl);
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4299
diff changeset
    65
extern void SwitchMode(int new_mode);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    66
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    67
static const StringID _connection_types_dropdown[] = {
675
9be22ffb4625 (svn r1113) -Add: [Network] Added the GUI part for server advertising. When you go
truelight
parents: 670
diff changeset
    68
	STR_NETWORK_LAN_INTERNET,
9be22ffb4625 (svn r1113) -Add: [Network] Added the GUI part for server advertising. When you go
truelight
parents: 670
diff changeset
    69
	STR_NETWORK_INTERNET_ADVERTISE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    70
	INVALID_STRING_ID
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    71
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    72
764
7e1e17b7c7d4 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
    73
static const StringID _lan_internet_types_dropdown[] = {
7e1e17b7c7d4 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
    74
	STR_NETWORK_LAN,
7e1e17b7c7d4 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
    75
	STR_NETWORK_INTERNET,
7e1e17b7c7d4 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
    76
	INVALID_STRING_ID
7e1e17b7c7d4 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
    77
};
7e1e17b7c7d4 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
    78
6796
ff1875ba196d (svn r10035) -Change: simplified network language string sorting
glx
parents: 6793
diff changeset
    79
static StringID _language_dropdown[NETLANG_COUNT + 1] = {STR_NULL};
6793
05d91fa1c75c (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6780
diff changeset
    80
7321
f91bdca345e8 (svn r10684) -Codechange: some more coding style related changes. Primarily moving { to a new line.
rubidium
parents: 7221
diff changeset
    81
void SortNetworkLanguages()
f91bdca345e8 (svn r10684) -Codechange: some more coding style related changes. Primarily moving { to a new line.
rubidium
parents: 7221
diff changeset
    82
{
6796
ff1875ba196d (svn r10035) -Change: simplified network language string sorting
glx
parents: 6793
diff changeset
    83
	/* Init the strings */
ff1875ba196d (svn r10035) -Change: simplified network language string sorting
glx
parents: 6793
diff changeset
    84
	if (_language_dropdown[0] == STR_NULL) {
ff1875ba196d (svn r10035) -Change: simplified network language string sorting
glx
parents: 6793
diff changeset
    85
		for (int i = 0; i < NETLANG_COUNT; i++) _language_dropdown[i] = STR_NETWORK_LANG_ANY + i;
ff1875ba196d (svn r10035) -Change: simplified network language string sorting
glx
parents: 6793
diff changeset
    86
		_language_dropdown[NETLANG_COUNT] = INVALID_STRING_ID;
ff1875ba196d (svn r10035) -Change: simplified network language string sorting
glx
parents: 6793
diff changeset
    87
	}
6793
05d91fa1c75c (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6780
diff changeset
    88
6796
ff1875ba196d (svn r10035) -Change: simplified network language string sorting
glx
parents: 6793
diff changeset
    89
	/* Sort the strings (we don't move 'any' and the 'invalid' one) */
ff1875ba196d (svn r10035) -Change: simplified network language string sorting
glx
parents: 6793
diff changeset
    90
	qsort(&_language_dropdown[1], NETLANG_COUNT - 1, sizeof(StringID), &StringIDSorter);
6793
05d91fa1c75c (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6780
diff changeset
    91
}
6780
ba49b125d95e (svn r10017) -Add (FS#790): more languages flags for servers
glx
parents: 6531
diff changeset
    92
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
    93
enum {
2881
ade9a553be53 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
    94
	NET_PRC__OFFSET_TOP_WIDGET          = 54,
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
    95
	NET_PRC__OFFSET_TOP_WIDGET_COMPANY  = 52,
2881
ade9a553be53 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
    96
	NET_PRC__SIZE_OF_ROW                = 14,
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
    97
};
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
    98
5035
1bcefcae0ef4 (svn r7077) -Codechange: Send proper message to network window, and handle selection control in
Darkvater
parents: 4957
diff changeset
    99
/** Update the network new window because a new server is
1bcefcae0ef4 (svn r7077) -Codechange: Send proper message to network window, and handle selection control in
Darkvater
parents: 4957
diff changeset
   100
 * found on the network.
1bcefcae0ef4 (svn r7077) -Codechange: Send proper message to network window, and handle selection control in
Darkvater
parents: 4957
diff changeset
   101
 * @param unselect unselect the currently selected item */
897
076a21cc614a (svn r1383) Fix: You can now also delete automatically found servers by pressing "del"
dominik
parents: 893
diff changeset
   102
void UpdateNetworkGameWindow(bool unselect)
076a21cc614a (svn r1383) Fix: You can now also delete automatically found servers by pressing "del"
dominik
parents: 893
diff changeset
   103
{
5035
1bcefcae0ef4 (svn r7077) -Codechange: Send proper message to network window, and handle selection control in
Darkvater
parents: 4957
diff changeset
   104
	SendWindowMessage(WC_NETWORK_WINDOW, 0, unselect, 0, 0);
897
076a21cc614a (svn r1383) Fix: You can now also delete automatically found servers by pressing "del"
dominik
parents: 893
diff changeset
   105
}
076a21cc614a (svn r1383) Fix: You can now also delete automatically found servers by pressing "del"
dominik
parents: 893
diff changeset
   106
2888
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   107
static bool _internal_sort_order; // Used for Qsort order-flipping
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   108
typedef int CDECL NGameNameSortFunction(const void*, const void*);
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   109
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   110
/** Qsort function to sort by name. */
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   111
static int CDECL NGameNameSorter(const void *a, const void *b)
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   112
{
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   113
	const NetworkGameList *cmp1 = *(const NetworkGameList**)a;
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   114
	const NetworkGameList *cmp2 = *(const NetworkGameList**)b;
2889
461c25e6cc1b (svn r3442) - Fix: Only windows has stricmp. So define strcasecmp to stricmp when using MSVC
Darkvater
parents: 2888
diff changeset
   115
	int r = strcasecmp(cmp1->info.server_name, cmp2->info.server_name);
2888
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   116
4880
aac84a9dcd03 (svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents: 4878
diff changeset
   117
	return _internal_sort_order ? -r : r;
2888
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   118
}
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   119
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   120
/** Qsort function to sort by the amount of clients online on a
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   121
 * server. If the two servers have the same amount, the one with the
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   122
 * higher maximum is preferred. */
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   123
static int CDECL NGameClientSorter(const void *a, const void *b)
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   124
{
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   125
	const NetworkGameList *cmp1 = *(const NetworkGameList**)a;
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   126
	const NetworkGameList *cmp2 = *(const NetworkGameList**)b;
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   127
	/* Reverse as per default we are interested in most-clients first */
4195
600bd419c335 (svn r5655) -Fix [SF 1424115]: Reversed arrow-sign in the multiplayer list column headers on sort by name
Darkvater
parents: 4171
diff changeset
   128
	int r = cmp1->info.clients_on - cmp2->info.clients_on;
2888
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   129
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   130
	if (r == 0) r = cmp1->info.clients_max - cmp2->info.clients_max;
2922
9eb5d9c8f78f (svn r3478) - Fix: In the network game list do the default sorting on connectivity (so servers which you can join are on top) and sort on names as a second criteria on clients and connectivity.
Darkvater
parents: 2914
diff changeset
   131
	if (r == 0) r = strcasecmp(cmp1->info.server_name, cmp2->info.server_name);
2888
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   132
4880
aac84a9dcd03 (svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents: 4878
diff changeset
   133
	return _internal_sort_order ? -r : r;
2888
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   134
}
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   135
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   136
/** Qsort function to sort by joinability. If both servers are the
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   137
 * same, prefer the non-passworded server first. */
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   138
static int CDECL NGameAllowedSorter(const void *a, const void *b)
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   139
{
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   140
	const NetworkGameList *cmp1 = *(const NetworkGameList**)a;
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   141
	const NetworkGameList *cmp2 = *(const NetworkGameList**)b;
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   142
5658
1e8be78c0bd7 (svn r8118) -Codechange: change the ordering of the network list a little:
rubidium
parents: 5609
diff changeset
   143
	/* The servers we do not know anything about (the ones that did not reply) should be at the bottom) */
1e8be78c0bd7 (svn r8118) -Codechange: change the ordering of the network list a little:
rubidium
parents: 5609
diff changeset
   144
	int r = StrEmpty(cmp1->info.server_revision) - StrEmpty(cmp2->info.server_revision);
1e8be78c0bd7 (svn r8118) -Codechange: change the ordering of the network list a little:
rubidium
parents: 5609
diff changeset
   145
1e8be78c0bd7 (svn r8118) -Codechange: change the ordering of the network list a little:
rubidium
parents: 5609
diff changeset
   146
	/* Reverse default as we are interested in version-compatible clients first */
1e8be78c0bd7 (svn r8118) -Codechange: change the ordering of the network list a little:
rubidium
parents: 5609
diff changeset
   147
	if (r == 0) r = cmp2->info.version_compatible - cmp1->info.version_compatible;
1e8be78c0bd7 (svn r8118) -Codechange: change the ordering of the network list a little:
rubidium
parents: 5609
diff changeset
   148
	/* The version-compatible ones are then sorted with NewGRF compatible first, incompatible last */
1e8be78c0bd7 (svn r8118) -Codechange: change the ordering of the network list a little:
rubidium
parents: 5609
diff changeset
   149
	if (r == 0) r = cmp2->info.compatible - cmp1->info.compatible;
1e8be78c0bd7 (svn r8118) -Codechange: change the ordering of the network list a little:
rubidium
parents: 5609
diff changeset
   150
	/* Passworded servers should be below unpassworded servers */
2888
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   151
	if (r == 0) r = cmp1->info.use_password - cmp2->info.use_password;
5658
1e8be78c0bd7 (svn r8118) -Codechange: change the ordering of the network list a little:
rubidium
parents: 5609
diff changeset
   152
	/* Finally sort on the name of the server */
2922
9eb5d9c8f78f (svn r3478) - Fix: In the network game list do the default sorting on connectivity (so servers which you can join are on top) and sort on names as a second criteria on clients and connectivity.
Darkvater
parents: 2914
diff changeset
   153
	if (r == 0) r = strcasecmp(cmp1->info.server_name, cmp2->info.server_name);
2888
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   154
4880
aac84a9dcd03 (svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents: 4878
diff changeset
   155
	return _internal_sort_order ? -r : r;
2888
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   156
}
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   157
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   158
/** (Re)build the network game list as its amount has changed because
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   159
 * an item has been added or deleted for example
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   160
 * @param ngl list_d struct that contains all necessary information for sorting */
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   161
static void BuildNetworkGameList(network_ql_d *nqld)
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   162
{
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   163
	NetworkGameList *ngl_temp;
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   164
	uint n = 0;
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   165
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   166
	if (!(nqld->l.flags & VL_REBUILD)) return;
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   167
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   168
	/* Count the number of games in the list */
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   169
	for (ngl_temp = _network_game_list; ngl_temp != NULL; ngl_temp = ngl_temp->next) n++;
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   170
	if (n == 0) return;
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   171
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   172
	/* Create temporary array of games to use for listing */
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   173
	free(nqld->sort_list);
5609
dc6a58930ba4 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5587
diff changeset
   174
	nqld->sort_list = MallocT<NetworkGameList*>(n);
2888
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   175
	nqld->l.list_length = n;
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   176
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   177
	for (n = 0, ngl_temp = _network_game_list; ngl_temp != NULL; ngl_temp = ngl_temp->next) {
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   178
		nqld->sort_list[n++] = ngl_temp;
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   179
	}
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   180
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   181
	/* Force resort */
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   182
	nqld->l.flags &= ~VL_REBUILD;
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   183
	nqld->l.flags |= VL_RESORT;
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   184
}
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   185
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   186
static void SortNetworkGameList(network_ql_d *nqld)
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   187
{
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   188
	static NGameNameSortFunction * const ngame_sorter[] = {
3860
af1e59c127ac (svn r4892) - Fix [FS#162]: SEGV when sorting an empty server list. (glx)
Darkvater
parents: 3692
diff changeset
   189
		&NGameNameSorter,
af1e59c127ac (svn r4892) - Fix [FS#162]: SEGV when sorting an empty server list. (glx)
Darkvater
parents: 3692
diff changeset
   190
		&NGameClientSorter,
af1e59c127ac (svn r4892) - Fix [FS#162]: SEGV when sorting an empty server list. (glx)
Darkvater
parents: 3692
diff changeset
   191
		&NGameAllowedSorter
af1e59c127ac (svn r4892) - Fix [FS#162]: SEGV when sorting an empty server list. (glx)
Darkvater
parents: 3692
diff changeset
   192
	};
af1e59c127ac (svn r4892) - Fix [FS#162]: SEGV when sorting an empty server list. (glx)
Darkvater
parents: 3692
diff changeset
   193
2888
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   194
	NetworkGameList *item;
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   195
	uint i;
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   196
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   197
	if (!(nqld->l.flags & VL_RESORT)) return;
3860
af1e59c127ac (svn r4892) - Fix [FS#162]: SEGV when sorting an empty server list. (glx)
Darkvater
parents: 3692
diff changeset
   198
	if (nqld->l.list_length == 0) return;
2888
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   199
4880
aac84a9dcd03 (svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents: 4878
diff changeset
   200
	_internal_sort_order = !!(nqld->l.flags & VL_DESC);
3860
af1e59c127ac (svn r4892) - Fix [FS#162]: SEGV when sorting an empty server list. (glx)
Darkvater
parents: 3692
diff changeset
   201
	qsort(nqld->sort_list, nqld->l.list_length, sizeof(nqld->sort_list[0]), ngame_sorter[nqld->l.sort_type]);
2888
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   202
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   203
	/* After sorting ngl->sort_list contains the sorted items. Put these back
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   204
	 * into the original list. Basically nothing has changed, we are only
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   205
	 * shuffling the ->next pointers */
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   206
	_network_game_list = nqld->sort_list[0];
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   207
	for (item = _network_game_list, i = 1; i != nqld->l.list_length; i++) {
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   208
		item->next = nqld->sort_list[i];
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   209
		item = item->next;
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   210
	}
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   211
	item->next = NULL;
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   212
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   213
	nqld->l.flags &= ~VL_RESORT;
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   214
}
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   215
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   216
/** Enum for NetworkGameWindow, referring to _network_game_window_widgets */
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   217
enum NetworkGameWindowWidgets {
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   218
	NGWW_CLOSE    = 0,  ///< Close 'X' button
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   219
	NGWW_CONN_TXT = 4,  ///< 'Connection' droplist
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   220
	NGWW_CONN_BTN = 5,  ///< 'Connection' droplist button
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   221
	NGWW_PLAYER   = 6,  ///< Panel with editbox to set player name
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   222
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   223
	NGWW_NAME     = 7,  ///< 'Name' button
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   224
	NGWW_CLIENTS,       ///< 'Clients' button
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   225
	NGWW_INFO,          ///< Third button in the game list panel
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   226
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   227
	NGWW_MATRIX   = 10, ///< Panel with list of games
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   228
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   229
	NGWW_DETAILS  = 12, ///< Panel with game details
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   230
	NGWW_JOIN     = 13, ///< 'Join game' button
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   231
	NGWW_REFRESH  = 14, ///< 'Refresh server' button
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   232
	NGWW_NEWGRF   = 15, ///< 'NewGRF Settings' button
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   233
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   234
	NGWW_FIND     = 16, ///< 'Find server' button
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   235
	NGWW_ADD,           ///< 'Add server' button
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   236
	NGWW_START,         ///< 'Start server' button
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   237
	NGWW_CANCEL,        ///< 'Cancel' button
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   238
};
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   239
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   240
/**
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   241
 * Handler of actions done in the NetworkStartServer window
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   242
 *
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   243
 * @param w pointer to the Window structure
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   244
 * @param e pointer to window event
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   245
 * @note    Uses network_ql_d (network_d, querystr_d and list_d) WP macro
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   246
 * @see     struct _network_game_window_widgets
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   247
 * @see     enum NetworkGameWindowWidgets
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   248
 */
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   249
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   250
static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   251
{
2888
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   252
	network_d *nd = &WP(w, network_ql_d).n;
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   253
	list_d *ld = &WP(w, network_ql_d).l;
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
   254
1653
d2db1ba2abde (svn r2157) - Feature (request): [ 1166978 ] Focus keyboard on input-box in Multiplayer Menu
Darkvater
parents: 1648
diff changeset
   255
	switch (e->event) {
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   256
	case WE_CREATE: // Focus input box
7343
9bf495fb4b10 (svn r10706) -Codechange: allow resizing the multiplayer server list window.
rubidium
parents: 7341
diff changeset
   257
		w->vscroll.cap = 13;
9bf495fb4b10 (svn r10706) -Codechange: allow resizing the multiplayer server list window.
rubidium
parents: 7341
diff changeset
   258
		w->resize.step_height = NET_PRC__SIZE_OF_ROW;
9bf495fb4b10 (svn r10706) -Codechange: allow resizing the multiplayer server list window.
rubidium
parents: 7341
diff changeset
   259
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   260
		nd->field = NGWW_PLAYER;
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
   261
		nd->server = NULL;
2888
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   262
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   263
		WP(w, network_ql_d).sort_list = NULL;
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   264
		ld->flags = VL_REBUILD | (_ng_sorting.order ? VL_DESC : VL_NONE);
2888
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   265
		ld->sort_type = _ng_sorting.criteria;
1653
d2db1ba2abde (svn r2157) - Feature (request): [ 1166978 ] Focus keyboard on input-box in Multiplayer Menu
Darkvater
parents: 1648
diff changeset
   266
		break;
2630
7206058a7e82 (svn r3172) static, const
tron
parents: 2549
diff changeset
   267
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
	case WE_PAINT: {
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
   269
		const NetworkGameList *sel = nd->server;
2888
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   270
		const char *arrow = (ld->flags & VL_DESC) ? DOWNARROW : UPARROW;
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   271
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   272
		if (ld->flags & VL_REBUILD) {
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   273
			BuildNetworkGameList(&WP(w, network_ql_d));
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   274
			SetVScrollCount(w, ld->list_length);
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   275
		}
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   276
		if (ld->flags & VL_RESORT) SortNetworkGameList(&WP(w, network_ql_d));
2071
3083c580f4dc (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   277
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   278
		/* 'Refresh' button invisible if no server selected */
7997
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7966
diff changeset
   279
		w->SetWidgetDisabledState(NGWW_REFRESH, sel == NULL);
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   280
		/* 'Join' button disabling conditions */
7997
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7966
diff changeset
   281
		w->SetWidgetDisabledState(NGWW_JOIN, sel == NULL || // no Selected Server
4709
a81ab800c25b (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4634
diff changeset
   282
				!sel->online || // Server offline
a81ab800c25b (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4634
diff changeset
   283
				sel->info.clients_on >= sel->info.clients_max || // Server full
a81ab800c25b (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4634
diff changeset
   284
				!sel->info.compatible); // Revision mismatch
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   285
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   286
		/* 'NewGRF Settings' button invisible if no NewGRF is used */
7997
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7966
diff changeset
   287
		w->SetWidgetHiddenState(NGWW_NEWGRF, sel == NULL ||
5339
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5247
diff changeset
   288
				!sel->online ||
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5247
diff changeset
   289
				sel->info.grfconfig == NULL);
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5247
diff changeset
   290
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   291
		SetDParam(0, 0x00);
7439
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   292
		SetDParam(1, _lan_internet_types_dropdown[_network_lan_internet]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
		DrawWindowWidgets(w);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   294
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   295
		/* Edit box to set player name */
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   296
		DrawEditBox(w, &WP(w, network_ql_d).q, NGWW_PLAYER);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   297
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   298
		DrawString(w->widget[NGWW_PLAYER].left - 100, 23, STR_NETWORK_PLAYER_NAME, TC_GOLD);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
2888
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   300
		/* Sort based on widgets: name, clients, compatibility */
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   301
		switch (ld->sort_type) {
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   302
			case NGWW_NAME    - NGWW_NAME: DoDrawString(arrow, w->widget[NGWW_NAME].right    - 10, 42, TC_BLACK); break;
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   303
			case NGWW_CLIENTS - NGWW_NAME: DoDrawString(arrow, w->widget[NGWW_CLIENTS].right - 10, 42, TC_BLACK); break;
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   304
			case NGWW_INFO    - NGWW_NAME: DoDrawString(arrow, w->widget[NGWW_INFO].right    - 10, 42, TC_BLACK); break;
2888
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   305
		}
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   306
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   307
		{ // draw list of games
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   308
			uint16 y = NET_PRC__OFFSET_TOP_WIDGET + 3;
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   309
			int32 n = 0;
809
e275914bfd14 (svn r1280) -Codechange: made the last patch a bit more... readable (in other words:
truelight
parents: 808
diff changeset
   310
			int32 pos = w->vscroll.pos;
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   311
			uint max_name_width = w->widget[NGWW_NAME].right - w->widget[NGWW_NAME].left - 5;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   312
			const NetworkGameList *cur_item = _network_game_list;
809
e275914bfd14 (svn r1280) -Codechange: made the last patch a bit more... readable (in other words:
truelight
parents: 808
diff changeset
   313
e275914bfd14 (svn r1280) -Codechange: made the last patch a bit more... readable (in other words:
truelight
parents: 808
diff changeset
   314
			while (pos > 0 && cur_item != NULL) {
e275914bfd14 (svn r1280) -Codechange: made the last patch a bit more... readable (in other words:
truelight
parents: 808
diff changeset
   315
				pos--;
808
ae0f50883ac0 (svn r1279) Fixed the scrollbar in the network gui(server list). It now updates when scrolling (HackyKid)
bjarni
parents: 793
diff changeset
   316
				cur_item = cur_item->next;
ae0f50883ac0 (svn r1279) Fixed the scrollbar in the network gui(server list). It now updates when scrolling (HackyKid)
bjarni
parents: 793
diff changeset
   317
			}
809
e275914bfd14 (svn r1280) -Codechange: made the last patch a bit more... readable (in other words:
truelight
parents: 808
diff changeset
   318
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   319
			while (cur_item != NULL) {
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   320
				/* show highlighted item with a different colour */
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   321
				if (cur_item == sel) GfxFillRect(w->widget[NGWW_NAME].left + 1, y - 2, w->widget[NGWW_INFO].right - 1, y + 9, 10);
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   322
2100
217ea6fdfd18 (svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents: 2071
diff changeset
   323
				SetDParamStr(0, cur_item->info.server_name);
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   324
				DrawStringTruncated(w->widget[NGWW_NAME].left + 5, y, STR_02BD, TC_BLACK, max_name_width);
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   325
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   326
				SetDParam(0, cur_item->info.clients_on);
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   327
				SetDParam(1, cur_item->info.clients_max);
2879
365ecd52f2db (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
   328
				SetDParam(2, cur_item->info.companies_on);
365ecd52f2db (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
   329
				SetDParam(3, cur_item->info.companies_max);
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   330
				DrawStringCentered(w->widget[NGWW_CLIENTS].left + 39, y, STR_NETWORK_GENERAL_ONLINE, TC_GOLD);
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   331
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   332
				/* only draw icons if the server is online */
591
b4c4386318e5 (svn r1012) -Fix: [Network] Endless loop if a server was offline (WizKid)
truelight
parents: 579
diff changeset
   333
				if (cur_item->online) {
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   334
					/* draw a lock if the server is password protected */
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   335
					if (cur_item->info.use_password) DrawSprite(SPR_LOCK, PAL_NONE, w->widget[NGWW_INFO].left + 5, y - 1);
591
b4c4386318e5 (svn r1012) -Fix: [Network] Endless loop if a server was offline (WizKid)
truelight
parents: 579
diff changeset
   336
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   337
					/* draw red or green icon, depending on compatibility with server */
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   338
					DrawSprite(SPR_BLOT, (cur_item->info.compatible ? PALETTE_TO_GREEN : (cur_item->info.version_compatible ? PALETTE_TO_YELLOW : PALETTE_TO_RED)), w->widget[NGWW_INFO].left + 15, y);
591
b4c4386318e5 (svn r1012) -Fix: [Network] Endless loop if a server was offline (WizKid)
truelight
parents: 579
diff changeset
   339
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   340
					/* draw flag according to server language */
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   341
					DrawSprite(SPR_FLAGS_BASE + cur_item->info.server_lang, PAL_NONE, w->widget[NGWW_INFO].left + 25, y);
579
e977d17c89b1 (svn r999) New icons for the network interface, newgrf gui and the tiny euro
dominik
parents: 543
diff changeset
   342
				}
591
b4c4386318e5 (svn r1012) -Fix: [Network] Endless loop if a server was offline (WizKid)
truelight
parents: 579
diff changeset
   343
b4c4386318e5 (svn r1012) -Fix: [Network] Endless loop if a server was offline (WizKid)
truelight
parents: 579
diff changeset
   344
				cur_item = cur_item->next;
b4c4386318e5 (svn r1012) -Fix: [Network] Endless loop if a server was offline (WizKid)
truelight
parents: 579
diff changeset
   345
				y += NET_PRC__SIZE_OF_ROW;
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
   346
				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
   347
			}
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   348
		}
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   349
2881
ade9a553be53 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   350
		/* Draw the right menu */
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   351
		GfxFillRect(w->widget[NGWW_DETAILS].left + 1, 43, w->widget[NGWW_DETAILS].right - 1, 92, 157);
2071
3083c580f4dc (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   352
		if (sel == NULL) {
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   353
			DrawStringCentered(w->widget[NGWW_DETAILS].left + 115, 58, STR_NETWORK_GAME_INFO, TC_FROMSTRING);
2071
3083c580f4dc (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   354
		} else if (!sel->online) {
3083c580f4dc (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   355
			SetDParamStr(0, sel->info.server_name);
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   356
			DrawStringCentered(w->widget[NGWW_DETAILS].left + 115, 68, STR_ORANGE, TC_FROMSTRING); // game name
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   357
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   358
			DrawStringCentered(w->widget[NGWW_DETAILS].left + 115, 132, STR_NETWORK_SERVER_OFFLINE, TC_FROMSTRING); // server offline
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   359
		} else { // show game info
2881
ade9a553be53 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   360
			uint16 y = 100;
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   361
			const uint16 x = w->widget[NGWW_DETAILS].left + 5;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   362
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   363
			DrawStringCentered(w->widget[NGWW_DETAILS].left + 115, 48, STR_NETWORK_GAME_INFO, TC_FROMSTRING);
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   364
2055
4926ed1a7562 (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
   365
2071
3083c580f4dc (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   366
			SetDParamStr(0, sel->info.server_name);
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   367
			DrawStringCenteredTruncated(w->widget[NGWW_DETAILS].left, w->widget[NGWW_DETAILS].right, 62, STR_ORANGE, TC_BLACK); // game name
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   368
2071
3083c580f4dc (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   369
			SetDParamStr(0, sel->info.map_name);
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   370
			DrawStringCenteredTruncated(w->widget[NGWW_DETAILS].left, w->widget[NGWW_DETAILS].right, 74, STR_02BD, TC_BLACK); // map name
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   371
2071
3083c580f4dc (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   372
			SetDParam(0, sel->info.clients_on);
3083c580f4dc (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   373
			SetDParam(1, sel->info.clients_max);
2879
365ecd52f2db (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
   374
			SetDParam(2, sel->info.companies_on);
365ecd52f2db (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
   375
			SetDParam(3, sel->info.companies_max);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
   376
			DrawString(x, y, STR_NETWORK_CLIENTS, TC_GOLD);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   377
			y += 10;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   378
6796
ff1875ba196d (svn r10035) -Change: simplified network language string sorting
glx
parents: 6793
diff changeset
   379
			SetDParam(0, STR_NETWORK_LANG_ANY + sel->info.server_lang);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
   380
			DrawString(x, y, STR_NETWORK_LANGUAGE, TC_GOLD); // server language
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   381
			y += 10;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   382
2775
a18db0ab5e51 (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
   383
			SetDParam(0, STR_TEMPERATE_LANDSCAPE + sel->info.map_set);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
   384
			DrawString(x, y, STR_NETWORK_TILESET, TC_GOLD); // tileset
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   385
			y += 10;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   386
2071
3083c580f4dc (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   387
			SetDParam(0, sel->info.map_width);
3083c580f4dc (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   388
			SetDParam(1, sel->info.map_height);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
   389
			DrawString(x, y, STR_NETWORK_MAP_SIZE, TC_GOLD); // map size
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   390
			y += 10;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   391
2071
3083c580f4dc (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   392
			SetDParamStr(0, sel->info.server_revision);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
   393
			DrawString(x, y, STR_NETWORK_SERVER_VERSION, TC_GOLD); // server version
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   394
			y += 10;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   395
2071
3083c580f4dc (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   396
			SetDParamStr(0, sel->info.hostname);
3083c580f4dc (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   397
			SetDParam(1, sel->port);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
   398
			DrawString(x, y, STR_NETWORK_SERVER_ADDRESS, TC_GOLD); // server address
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   399
			y += 10;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   400
2071
3083c580f4dc (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   401
			SetDParam(0, sel->info.start_date);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
   402
			DrawString(x, y, STR_NETWORK_START_DATE, TC_GOLD); // start date
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   403
			y += 10;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   404
2071
3083c580f4dc (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   405
			SetDParam(0, sel->info.game_date);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
   406
			DrawString(x, y, STR_NETWORK_CURRENT_DATE, TC_GOLD); // current date
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   407
			y += 10;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   408
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   409
			y += 2;
622
19e529637d18 (svn r1052) -Fix: [Network] You can't join a server when revision mismatches.
truelight
parents: 621
diff changeset
   410
2881
ade9a553be53 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   411
			if (!sel->info.compatible) {
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   412
				DrawStringCentered(w->widget[NGWW_DETAILS].left + 115, y, sel->info.version_compatible ? STR_NETWORK_GRF_MISMATCH : STR_NETWORK_VERSION_MISMATCH, TC_FROMSTRING); // server mismatch
2071
3083c580f4dc (svn r2581) Fix: Behave a bit safer if central server sends bogus information about clients.
ludde
parents: 2064
diff changeset
   413
			} else if (sel->info.clients_on == sel->info.clients_max) {
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   414
				/* Show: server full, when clients_on == clients_max */
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   415
				DrawStringCentered(w->widget[NGWW_DETAILS].left + 115, y, STR_NETWORK_SERVER_FULL, TC_FROMSTRING); // server full
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   416
			} else if (sel->info.use_password) {
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   417
				DrawStringCentered(w->widget[NGWW_DETAILS].left + 115, y, STR_NETWORK_PASSWORD, TC_FROMSTRING); // password warning
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   418
			}
659
a9733f856cd0 (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
   419
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   420
			y += 10;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   421
		}
6492
286a52449b54 (svn r9673) -Cleanup: remove spaces before tabs and replace non-indenting tabs with spaces.
rubidium
parents: 6491
diff changeset
   422
	} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   423
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   424
	case WE_CLICK:
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
   425
		nd->field = e->we.click.widget;
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
   426
		switch (e->we.click.widget) {
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   427
		case NGWW_CANCEL: // Cancel button
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   428
			DeleteWindowById(WC_NETWORK_WINDOW, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   429
			break;
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   430
		case NGWW_CONN_TXT: case NGWW_CONN_BTN: // 'Connection' droplist
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   431
			ShowDropDownMenu(w, _lan_internet_types_dropdown, _network_lan_internet, NGWW_CONN_BTN, 0, 0); // do it for widget NSSW_CONN_BTN
764
7e1e17b7c7d4 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   432
			break;
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   433
		case NGWW_NAME: // Sort by name
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   434
		case NGWW_CLIENTS: // Sort by connected clients
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   435
		case NGWW_INFO: // Connectivity (green dot)
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   436
			if (ld->sort_type == e->we.click.widget - NGWW_NAME) ld->flags ^= VL_DESC;
2888
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   437
			ld->flags |= VL_RESORT;
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   438
			ld->sort_type = e->we.click.widget - NGWW_NAME;
2888
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   439
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   440
			_ng_sorting.order = !!(ld->flags & VL_DESC);
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   441
			_ng_sorting.criteria = ld->sort_type;
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   442
			SetWindowDirty(w);
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   443
			break;
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   444
		case NGWW_MATRIX: { // Matrix to show networkgames
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
   445
			NetworkGameList *cur_item;
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
   446
			uint32 id_v = (e->we.click.pt.y - NET_PRC__OFFSET_TOP_WIDGET) / NET_PRC__SIZE_OF_ROW;
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   447
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
   448
			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
   449
			id_v += w->vscroll.pos;
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   450
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
   451
			cur_item = _network_game_list;
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
   452
			for (; id_v > 0 && cur_item != NULL; id_v--) cur_item = cur_item->next;
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   453
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
   454
			nd->server = cur_item;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   455
			SetWindowDirty(w);
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   456
		} break;
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   457
		case NGWW_FIND: // Find server automatically
764
7e1e17b7c7d4 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   458
			switch (_network_lan_internet) {
7e1e17b7c7d4 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   459
				case 0: NetworkUDPSearchGame(); break;
7e1e17b7c7d4 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   460
				case 1: NetworkUDPQueryMasterServer(); break;
7e1e17b7c7d4 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   461
			}
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 206
diff changeset
   462
			break;
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   463
		case NGWW_ADD: { // Add a server
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   464
			ShowQueryString(
2055
4926ed1a7562 (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
   465
				BindCString(_network_default_ip),
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   466
				STR_NETWORK_ENTER_IP,
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   467
				31 | 0x1000,  // maximum number of characters OR
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   468
				250, // characters up to this width pixels, whichever is satisfied first
5431
6e56b4f13dd7 (svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents: 5352
diff changeset
   469
				w, CS_ALPHANUMERAL);
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   470
		} break;
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   471
		case NGWW_START: // Start server
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   472
			ShowNetworkStartServerWindow();
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   473
			break;
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   474
		case NGWW_JOIN: // Join Game
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
   475
			if (nd->server != NULL) {
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
   476
				snprintf(_network_last_host, sizeof(_network_last_host), "%s", inet_ntoa(*(struct in_addr *)&nd->server->ip));
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
   477
				_network_last_port = nd->server->port;
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
   478
				ShowNetworkLobbyWindow(nd->server);
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   479
			}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   480
			break;
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   481
		case NGWW_REFRESH: // Refresh
2888
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   482
			if (nd->server != NULL)
5916
8931f4450f51 (svn r8543) -Codechange: make a real difference between querying the server via UDP and TCP.
rubidium
parents: 5893
diff changeset
   483
				NetworkUDPQueryServer(nd->server->info.hostname, nd->server->port);
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   484
			break;
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   485
		case NGWW_NEWGRF: // NewGRF Settings
5352
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5343
diff changeset
   486
			if (nd->server != NULL) ShowNewGRFSettings(false, false, false, &nd->server->info.grfconfig);
5339
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5247
diff changeset
   487
			break;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   488
6492
286a52449b54 (svn r9673) -Cleanup: remove spaces before tabs and replace non-indenting tabs with spaces.
rubidium
parents: 6491
diff changeset
   489
	} 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
   490
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   491
	case WE_DROPDOWN_SELECT: // we have selected a dropdown item in the list
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
   492
		switch (e->we.dropdown.button) {
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   493
			case NGWW_CONN_BTN:
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
   494
				_network_lan_internet = e->we.dropdown.index;
764
7e1e17b7c7d4 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   495
				break;
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   496
			default:
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   497
				NOT_REACHED();
764
7e1e17b7c7d4 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   498
		}
7e1e17b7c7d4 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   499
7e1e17b7c7d4 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   500
		SetWindowDirty(w);
7e1e17b7c7d4 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   501
		break;
7e1e17b7c7d4 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   502
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   503
	case WE_MOUSELOOP:
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   504
		if (nd->field == NGWW_PLAYER) HandleEditBox(w, &WP(w, network_ql_d).q, NGWW_PLAYER);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   505
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   506
2888
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   507
	case WE_MESSAGE:
5035
1bcefcae0ef4 (svn r7077) -Codechange: Send proper message to network window, and handle selection control in
Darkvater
parents: 4957
diff changeset
   508
		if (e->we.message.msg != 0) nd->server = NULL;
2888
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   509
		ld->flags |= VL_REBUILD;
2881
ade9a553be53 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   510
		SetWindowDirty(w);
2888
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   511
		break;
2881
ade9a553be53 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   512
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   513
	case WE_KEYPRESS:
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   514
		if (nd->field != NGWW_PLAYER) {
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
   515
			if (nd->server != NULL) {
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   516
				if (e->we.keypress.keycode == WKC_DELETE) { // Press 'delete' to remove servers
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
   517
					NetworkGameListRemoveItem(nd->server);
738
b96ab9e63d22 (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
   518
					NetworkRebuildHostList();
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
   519
					nd->server = NULL;
738
b96ab9e63d22 (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
   520
				}
b96ab9e63d22 (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
   521
			}
741
422ce499322b (svn r1197) -Fix: [GUI] in r1194 someone deleted too much code from WE_KEYPRESS. Now
truelight
parents: 738
diff changeset
   522
			break;
422ce499322b (svn r1197) -Fix: [GUI] in r1194 someone deleted too much code from WE_KEYPRESS. Now
truelight
parents: 738
diff changeset
   523
		}
422ce499322b (svn r1197) -Fix: [GUI] in r1194 someone deleted too much code from WE_KEYPRESS. Now
truelight
parents: 738
diff changeset
   524
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   525
		if (HandleEditBoxKey(w, &WP(w, network_ql_d).q, NGWW_PLAYER, e) == 1) break; // enter pressed
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   526
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   527
		/* The name is only allowed when it starts with a letter! */
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   528
		if (_edit_str_buf[0] != '\0' && _edit_str_buf[0] != ' ') {
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   529
			ttd_strlcpy(_network_player_name, _edit_str_buf, lengthof(_network_player_name));
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   530
		} else {
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   531
			ttd_strlcpy(_network_player_name, "Player", lengthof(_network_player_name));
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   532
		}
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   533
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   534
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   535
2881
ade9a553be53 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   536
	case WE_ON_EDIT_TEXT:
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
   537
		NetworkAddServer(e->we.edittext.str);
738
b96ab9e63d22 (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
   538
		NetworkRebuildHostList();
2881
ade9a553be53 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   539
		break;
2888
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   540
7343
9bf495fb4b10 (svn r10706) -Codechange: allow resizing the multiplayer server list window.
rubidium
parents: 7341
diff changeset
   541
	case WE_RESIZE: {
9bf495fb4b10 (svn r10706) -Codechange: allow resizing the multiplayer server list window.
rubidium
parents: 7341
diff changeset
   542
		w->vscroll.cap += e->we.sizing.diff.y / (int)w->resize.step_height;
9bf495fb4b10 (svn r10706) -Codechange: allow resizing the multiplayer server list window.
rubidium
parents: 7341
diff changeset
   543
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   544
		w->widget[NGWW_MATRIX].data = (w->vscroll.cap << 8) + 1;
7343
9bf495fb4b10 (svn r10706) -Codechange: allow resizing the multiplayer server list window.
rubidium
parents: 7341
diff changeset
   545
7966
0c6e2703634c (svn r11522) -Fix: The scrollbar of the network gui could run out of bounds
skidd13
parents: 7963
diff changeset
   546
		SetVScrollCount(w, ld->list_length);
0c6e2703634c (svn r11522) -Fix: The scrollbar of the network gui could run out of bounds
skidd13
parents: 7963
diff changeset
   547
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   548
		int widget_width = w->widget[NGWW_FIND].right - w->widget[NGWW_FIND].left;
7343
9bf495fb4b10 (svn r10706) -Codechange: allow resizing the multiplayer server list window.
rubidium
parents: 7341
diff changeset
   549
		int space = (w->width - 4 * widget_width - 25) / 3;
9bf495fb4b10 (svn r10706) -Codechange: allow resizing the multiplayer server list window.
rubidium
parents: 7341
diff changeset
   550
9bf495fb4b10 (svn r10706) -Codechange: allow resizing the multiplayer server list window.
rubidium
parents: 7341
diff changeset
   551
		int offset = 10;
9bf495fb4b10 (svn r10706) -Codechange: allow resizing the multiplayer server list window.
rubidium
parents: 7341
diff changeset
   552
		for (uint i = 0; i < 4; i++) {
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   553
			w->widget[NGWW_FIND + i].left  = offset;
7343
9bf495fb4b10 (svn r10706) -Codechange: allow resizing the multiplayer server list window.
rubidium
parents: 7341
diff changeset
   554
			offset += widget_width;
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   555
			w->widget[NGWW_FIND + i].right = offset;
7343
9bf495fb4b10 (svn r10706) -Codechange: allow resizing the multiplayer server list window.
rubidium
parents: 7341
diff changeset
   556
			offset += space;
9bf495fb4b10 (svn r10706) -Codechange: allow resizing the multiplayer server list window.
rubidium
parents: 7341
diff changeset
   557
		}
9bf495fb4b10 (svn r10706) -Codechange: allow resizing the multiplayer server list window.
rubidium
parents: 7341
diff changeset
   558
	} break;
9bf495fb4b10 (svn r10706) -Codechange: allow resizing the multiplayer server list window.
rubidium
parents: 7341
diff changeset
   559
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   560
	case WE_DESTROY: // Nicely clean up the sort-list
2888
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   561
		free(WP(w, network_ql_d).sort_list);
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   562
		break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   563
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   564
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   565
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   566
static const Widget _network_game_window_widgets[] = {
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   567
/* TOP */
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   568
{   WWT_CLOSEBOX,   RESIZE_NONE,   BGC,     0,    10,     0,    13, STR_00C5,                       STR_018B_CLOSE_WINDOW},            // NGWW_CLOSE
7439
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   569
{    WWT_CAPTION,   RESIZE_RIGHT,  BGC,    11,   449,     0,    13, STR_NETWORK_MULTIPLAYER,        STR_NULL},
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   570
{      WWT_PANEL,   RESIZE_RB,     BGC,     0,   449,    14,   263, 0x0,                            STR_NULL},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   571
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   572
{       WWT_TEXT,   RESIZE_NONE,   BGC,     9,    85,    23,    35, STR_NETWORK_CONNECTION,         STR_NULL},
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   573
{      WWT_INSET,   RESIZE_NONE,   BGC,    90,   181,    22,    33, STR_NETWORK_LAN_INTERNET_COMBO, STR_NETWORK_CONNECTION_TIP},       // NGWW_CONN_TXT
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   574
{    WWT_TEXTBTN,   RESIZE_NONE,   BGC,   170,   180,    23,    32, STR_0225,                       STR_NETWORK_CONNECTION_TIP},       // NGWW_CONN_BTN
2881
ade9a553be53 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   575
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   576
{      WWT_PANEL,   RESIZE_LR,     BGC,   290,   440,    22,    33, 0x0,                            STR_NETWORK_ENTER_NAME_TIP},       // NGWW_PLAYER
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
   577
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   578
/* LEFT SIDE */
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   579
{ WWT_PUSHTXTBTN,   RESIZE_RIGHT,  BTC,    10,    70,    42,    53, STR_NETWORK_GAME_NAME,          STR_NETWORK_GAME_NAME_TIP},        // NGWW_NAME
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   580
{ WWT_PUSHTXTBTN,   RESIZE_LR,     BTC,    71,   150,    42,    53, STR_NETWORK_CLIENTS_CAPTION,    STR_NETWORK_CLIENTS_CAPTION_TIP},  // NGWW_CLIENTS
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   581
{ WWT_PUSHTXTBTN,   RESIZE_LR,     BTC,   151,   190,    42,    53, STR_EMPTY,                      STR_NETWORK_INFO_ICONS_TIP},       // NGWW_INFO
7439
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   582
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   583
{     WWT_MATRIX,   RESIZE_RB,     BGC,    10,   190,    54,   236, (13 << 8) + 1,                  STR_NETWORK_CLICK_GAME_TO_SELECT}, // NGWW_MATRIX
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   584
{  WWT_SCROLLBAR,   RESIZE_LRB,    BGC,   191,   202,    42,   236, 0x0,                            STR_0190_SCROLL_BAR_SCROLLS_LIST},
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   585
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   586
/* RIGHT SIDE */
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   587
{      WWT_PANEL,   RESIZE_LRB,    BGC,   210,   440,    42,   236, 0x0,                            STR_NULL},                         // NGWW_DETAILS
2881
ade9a553be53 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   588
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   589
{ WWT_PUSHTXTBTN,   RESIZE_LRTB,   BTC,   215,   315,   215,   226, STR_NETWORK_JOIN_GAME,          STR_NULL},                         // NGWW_JOIN
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   590
{ WWT_PUSHTXTBTN,   RESIZE_LRTB,   BTC,   330,   435,   215,   226, STR_NETWORK_REFRESH,            STR_NETWORK_REFRESH_TIP},          // NGWW_REFRESH
5339
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5247
diff changeset
   591
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   592
{ WWT_PUSHTXTBTN,   RESIZE_LRTB,   BTC,   330,   435,   197,   208, STR_NEWGRF_SETTINGS_BUTTON,     STR_NULL},                         // NGWW_NEWGRF
7343
9bf495fb4b10 (svn r10706) -Codechange: allow resizing the multiplayer server list window.
rubidium
parents: 7341
diff changeset
   593
7960
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   594
/* BOTTOM */
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   595
{ WWT_PUSHTXTBTN,   RESIZE_TB,     BTC,    10,   110,   246,   257, STR_NETWORK_FIND_SERVER,        STR_NETWORK_FIND_SERVER_TIP},      // NGWW_FIND
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   596
{ WWT_PUSHTXTBTN,   RESIZE_TB,     BTC,   118,   218,   246,   257, STR_NETWORK_ADD_SERVER,         STR_NETWORK_ADD_SERVER_TIP},       // NGWW_ADD
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   597
{ WWT_PUSHTXTBTN,   RESIZE_TB,     BTC,   226,   326,   246,   257, STR_NETWORK_START_SERVER,       STR_NETWORK_START_SERVER_TIP},     // NGWW_START
b88d72baa45b (svn r11516) -Codechange: cleanup of NetworkGameWindow in network_gui.cpp
smatz
parents: 7959
diff changeset
   598
{ WWT_PUSHTXTBTN,   RESIZE_TB,     BTC,   334,   434,   246,   257, STR_012E_CANCEL,                STR_NULL},                         // NGWW_CANCEL
7439
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   599
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   600
{  WWT_RESIZEBOX,   RESIZE_LRTB,   BGC,   438,   449,   252,   263, 0x0,                            STR_RESIZE_BUTTON },
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   601
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 175
diff changeset
   602
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   603
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   604
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   605
static const WindowDesc _network_game_window_desc = {
7343
9bf495fb4b10 (svn r10706) -Codechange: allow resizing the multiplayer server list window.
rubidium
parents: 7341
diff changeset
   606
	WDP_CENTER, WDP_CENTER, 450, 264, 550, 264,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5669
diff changeset
   607
	WC_NETWORK_WINDOW, WC_NONE,
7343
9bf495fb4b10 (svn r10706) -Codechange: allow resizing the multiplayer server list window.
rubidium
parents: 7341
diff changeset
   608
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   609
	_network_game_window_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   610
	NetworkGameWindowWndProc,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   611
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   612
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 5916
diff changeset
   613
void ShowNetworkGameWindow()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   614
{
2922
9eb5d9c8f78f (svn r3478) - Fix: In the network game list do the default sorting on connectivity (so servers which you can join are on top) and sort on names as a second criteria on clients and connectivity.
Darkvater
parents: 2914
diff changeset
   615
	static bool first = true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   616
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   617
	DeleteWindowById(WC_NETWORK_WINDOW, 0);
105
44e894da0fef (svn r106) New network core (by sign_de)
dominik
parents: 1
diff changeset
   618
764
7e1e17b7c7d4 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   619
	/* Only show once */
2922
9eb5d9c8f78f (svn r3478) - Fix: In the network game list do the default sorting on connectivity (so servers which you can join are on top) and sort on names as a second criteria on clients and connectivity.
Darkvater
parents: 2914
diff changeset
   620
	if (first) {
2885
fc5297214b36 (svn r3435) - Fix a warning, removed unused extern and some comments in network_gamelist.c
Darkvater
parents: 2884
diff changeset
   621
		char* const *srv;
2881
ade9a553be53 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   622
2922
9eb5d9c8f78f (svn r3478) - Fix: In the network game list do the default sorting on connectivity (so servers which you can join are on top) and sort on names as a second criteria on clients and connectivity.
Darkvater
parents: 2914
diff changeset
   623
		first = false;
764
7e1e17b7c7d4 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   624
		// add all servers from the config file to our list
2885
fc5297214b36 (svn r3435) - Fix a warning, removed unused extern and some comments in network_gamelist.c
Darkvater
parents: 2884
diff changeset
   625
		for (srv = &_network_host_list[0]; srv != endof(_network_host_list) && *srv != NULL; srv++) {
2881
ade9a553be53 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2879
diff changeset
   626
			NetworkAddServer(*srv);
764
7e1e17b7c7d4 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   627
		}
2922
9eb5d9c8f78f (svn r3478) - Fix: In the network game list do the default sorting on connectivity (so servers which you can join are on top) and sort on names as a second criteria on clients and connectivity.
Darkvater
parents: 2914
diff changeset
   628
9eb5d9c8f78f (svn r3478) - Fix: In the network game list do the default sorting on connectivity (so servers which you can join are on top) and sort on names as a second criteria on clients and connectivity.
Darkvater
parents: 2914
diff changeset
   629
		_ng_sorting.criteria = 2; // sort default by collectivity (green-dots on top)
9eb5d9c8f78f (svn r3478) - Fix: In the network game list do the default sorting on connectivity (so servers which you can join are on top) and sort on names as a second criteria on clients and connectivity.
Darkvater
parents: 2914
diff changeset
   630
		_ng_sorting.order = 0;    // sort ascending by default
764
7e1e17b7c7d4 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   631
	}
7e1e17b7c7d4 (svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents: 749
diff changeset
   632
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   633
	w = AllocateWindowDesc(&_network_game_window_desc);
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
   634
	if (w != NULL) {
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   635
		querystr_d *querystr = &WP(w, network_ql_d).q;
3470
cd704e52732f (svn r4315) Remove MAX_QUERYSTR_LEN, rather use lengthof() the real thing
tron
parents: 3469
diff changeset
   636
cd704e52732f (svn r4315) Remove MAX_QUERYSTR_LEN, rather use lengthof() the real thing
tron
parents: 3469
diff changeset
   637
		ttd_strlcpy(_edit_str_buf, _network_player_name, lengthof(_edit_str_buf));
4909
955f318a24cd (svn r6879) -Codechange: Remove the superflouos argument CharsetFilter parameter from HandleEditBoxKey
Darkvater
parents: 4906
diff changeset
   638
		querystr->afilter = CS_ALPHANUMERAL;
4948
22ff05c1a3b1 (svn r6937) -Codechange: Add an InitializeTextBuffer() function that handles setting up the
Darkvater
parents: 4945
diff changeset
   639
		InitializeTextBuffer(&querystr->text, _edit_str_buf, lengthof(_edit_str_buf), 120);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   640
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
   641
		UpdateNetworkGameWindow(true);
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
   642
	}
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   643
}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   644
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   645
enum {
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   646
	NSSWND_START = 64,
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   647
	NSSWND_ROWSIZE = 12
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   648
};
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   649
7959
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   650
/** Enum for NetworkStartServerWindow, referring to _network_start_server_window_widgets */
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   651
enum NetworkStartServerWidgets {
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   652
	NSSW_CLOSE           =  0,   ///< Close 'X' button
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   653
	NSSW_GAMENAME        =  4,   ///< Background for editbox to set game name
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   654
	NSSW_SETPWD          =  5,   ///< 'Set password' button
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   655
	NSSW_SELMAP          =  7,   ///< 'Select map' list
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   656
	NSSW_CONNTYPE_TXT    = 10,   ///< 'Connection type' droplist
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   657
	NSSW_CONNTYPE_BTN    = 11,   ///< 'Connection type' droplist button
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   658
	NSSW_CLIENTS_BTND    = 13,   ///< 'Max clients' downarrow
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   659
	NSSW_CLIENTS_TXT     = 14,   ///< 'Max clients' text
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   660
	NSSW_CLIENTS_BTNU    = 15,   ///< 'Max clients' uparrow
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   661
	NSSW_COMPANIES_BTND  = 17,   ///< 'Max companies' downarrow
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   662
	NSSW_COMPANIES_TXT   = 18,   ///< 'Max companies' text
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   663
	NSSW_COMPANIES_BTNU  = 19,   ///< 'Max companies' uparrow
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   664
	NSSW_SPECTATORS_BTND = 21,   ///< 'Max spectators' downarrow
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   665
	NSSW_SPECTATORS_TXT  = 22,   ///< 'Max spectators' text
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   666
	NSSW_SPECTATORS_BTNU = 23,   ///< 'Max spectators' uparrow
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   667
	NSSW_LANGUAGE_TXT    = 25,   ///< 'Language spoken' droplist
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   668
	NSSW_LANGUAGE_BTN    = 26,   ///< 'Language spoken' droplist button
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   669
	NSSW_START           = 27,   ///< 'Start' button
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   670
	NSSW_LOAD            = 28,   ///< 'Load' button
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   671
	NSSW_CANCEL          = 29,   ///< 'Cancel' button
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   672
};
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   673
7961
6d30992b6084 (svn r11517) -Codechange: better cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7960
diff changeset
   674
/**
6d30992b6084 (svn r11517) -Codechange: better cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7960
diff changeset
   675
 * Handler of actions done in the NetworkStartServer window
6d30992b6084 (svn r11517) -Codechange: better cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7960
diff changeset
   676
 *
6d30992b6084 (svn r11517) -Codechange: better cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7960
diff changeset
   677
 * @param w pointer to the Window structure
6d30992b6084 (svn r11517) -Codechange: better cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7960
diff changeset
   678
 * @param e pointer to window event
6d30992b6084 (svn r11517) -Codechange: better cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7960
diff changeset
   679
 * @note    Uses network_ql_d (network_d, querystr_d and list_d) WP macro
6d30992b6084 (svn r11517) -Codechange: better cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7960
diff changeset
   680
 * @see     struct _network_start_server_window_widgets
6d30992b6084 (svn r11517) -Codechange: better cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7960
diff changeset
   681
 * @see     enum NetworkStartServerWidgets
6d30992b6084 (svn r11517) -Codechange: better cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7960
diff changeset
   682
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   683
static void NetworkStartServerWindowWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   684
{
2888
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   685
	network_d *nd = &WP(w, network_ql_d).n;
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
   686
1653
d2db1ba2abde (svn r2157) - Feature (request): [ 1166978 ] Focus keyboard on input-box in Multiplayer Menu
Darkvater
parents: 1648
diff changeset
   687
	switch (e->event) {
7959
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   688
	case WE_CREATE: // focus input box
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   689
		nd->field = NSSW_GAMENAME;
1899
81214598ab45 (svn r2405) Simplify a few '? true : false' and '? false : true', especially the latter is confusing
tron
parents: 1891
diff changeset
   690
		_network_game_info.use_password = (_network_server_password[0] != '\0');
1653
d2db1ba2abde (svn r2157) - Feature (request): [ 1166978 ] Focus keyboard on input-box in Multiplayer Menu
Darkvater
parents: 1648
diff changeset
   691
		break;
d2db1ba2abde (svn r2157) - Feature (request): [ 1166978 ] Focus keyboard on input-box in Multiplayer Menu
Darkvater
parents: 1648
diff changeset
   692
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   693
	case WE_PAINT: {
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   694
		int y = NSSWND_START, pos;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   695
		const FiosItem *item;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   696
7959
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   697
		/* draw basic widgets */
7439
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   698
		SetDParam(1, _connection_types_dropdown[_network_advertise]);
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   699
		SetDParam(2, _network_game_info.clients_max);
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   700
		SetDParam(3, _network_game_info.companies_max);
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   701
		SetDParam(4, _network_game_info.spectators_max);
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   702
		SetDParam(5, STR_NETWORK_LANG_ANY + _network_game_info.server_lang);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   703
		DrawWindowWidgets(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   704
7959
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   705
		/* editbox to set game name */
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   706
		DrawEditBox(w, &WP(w, network_ql_d).q, NSSW_GAMENAME);
2879
365ecd52f2db (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
   707
7959
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   708
		/* if password is set, draw red '*' next to 'Set password' button */
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
   709
		if (_network_game_info.use_password) DoDrawString("*", 408, 23, TC_RED);
1653
d2db1ba2abde (svn r2157) - Feature (request): [ 1166978 ] Focus keyboard on input-box in Multiplayer Menu
Darkvater
parents: 1648
diff changeset
   710
7959
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   711
		/* draw list of maps */
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   712
		GfxFillRect(11, 63, 258, 215, 0xD7);  // black background of maps list
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   713
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   714
		pos = w->vscroll.pos;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   715
		while (pos < _fios_num + 1) {
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   716
			item = _fios_list + pos - 1;
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
   717
			if (item == nd->map || (pos == 0 && nd->map == NULL))
2879
365ecd52f2db (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
   718
				GfxFillRect(11, y - 1, 258, y + 10, 155); // show highlighted item with a different colour
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   719
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4013
diff changeset
   720
			if (pos == 0) {
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
   721
				DrawString(14, y, STR_4010_GENERATE_RANDOM_NEW_GAME, TC_DARK_GREEN);
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4013
diff changeset
   722
			} else {
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4013
diff changeset
   723
				DoDrawString(item->title, 14, y, _fios_colors[item->type] );
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4013
diff changeset
   724
			}
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   725
			pos++;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   726
			y += NSSWND_ROWSIZE;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   727
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   728
			if (y >= w->vscroll.cap * NSSWND_ROWSIZE + NSSWND_START) break;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   729
		}
6492
286a52449b54 (svn r9673) -Cleanup: remove spaces before tabs and replace non-indenting tabs with spaces.
rubidium
parents: 6491
diff changeset
   730
	} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   731
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   732
	case WE_CLICK:
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
   733
		nd->field = e->we.click.widget;
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
   734
		switch (e->we.click.widget) {
7959
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   735
		case NSSW_CLOSE:  // Close 'X'
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   736
		case NSSW_CANCEL: // Cancel button
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   737
			ShowNetworkGameWindow();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   738
			break;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   739
7959
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   740
		case NSSW_SETPWD: // Set password button
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   741
			nd->widget_id = NSSW_SETPWD;
5431
6e56b4f13dd7 (svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents: 5352
diff changeset
   742
			ShowQueryString(BindCString(_network_server_password), STR_NETWORK_SET_PASSWORD, 20, 250, w, CS_ALPHANUMERAL);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   743
			break;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   744
7959
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   745
		case NSSW_SELMAP: { // Select map
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
   746
			int y = (e->we.click.pt.y - NSSWND_START) / NSSWND_ROWSIZE;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   747
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   748
			y += w->vscroll.pos;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   749
			if (y >= w->vscroll.count) return;
2100
217ea6fdfd18 (svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents: 2071
diff changeset
   750
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
   751
			nd->map = (y == 0) ? NULL : _fios_list + y - 1;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   752
			SetWindowDirty(w);
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   753
			} break;
7959
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   754
		case NSSW_CONNTYPE_TXT: case NSSW_CONNTYPE_BTN: // Connection type
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   755
			ShowDropDownMenu(w, _connection_types_dropdown, _network_advertise, NSSW_CONNTYPE_BTN, 0, 0); // do it for widget NSSW_CONNTYPE_BTN
675
9be22ffb4625 (svn r1113) -Add: [Network] Added the GUI part for server advertising. When you go
truelight
parents: 670
diff changeset
   756
			break;
7959
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   757
		case NSSW_CLIENTS_BTND:    case NSSW_CLIENTS_BTNU:    // Click on up/down button for number of clients
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   758
		case NSSW_COMPANIES_BTND:  case NSSW_COMPANIES_BTNU:  // Click on up/down button for number of companies
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   759
		case NSSW_SPECTATORS_BTND: case NSSW_SPECTATORS_BTNU: // Click on up/down button for number of spectators
7439
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   760
			/* Don't allow too fast scrolling */
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   761
			if ((w->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) {
8036
279f4cbf9ec7 (svn r11596) -Codechange: Use the Window member HandleButtonClick and remove its now useless counterpart function
belugas
parents: 8028
diff changeset
   762
				w->HandleButtonClick(e->we.click.widget);
7439
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   763
				SetWindowDirty(w);
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   764
				switch (e->we.click.widget) {
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   765
					default: NOT_REACHED();
7959
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   766
					case NSSW_CLIENTS_BTND: case NSSW_CLIENTS_BTNU:
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   767
						_network_game_info.clients_max    = Clamp(_network_game_info.clients_max    + e->we.click.widget - NSSW_CLIENTS_TXT,    2, MAX_CLIENTS);
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   768
						break;
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   769
					case NSSW_COMPANIES_BTND: case NSSW_COMPANIES_BTNU:
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   770
						_network_game_info.companies_max  = Clamp(_network_game_info.companies_max  + e->we.click.widget - NSSW_COMPANIES_TXT,  1, MAX_PLAYERS);
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   771
						break;
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   772
					case NSSW_SPECTATORS_BTND: case NSSW_SPECTATORS_BTNU:
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   773
						_network_game_info.spectators_max = Clamp(_network_game_info.spectators_max + e->we.click.widget - NSSW_SPECTATORS_TXT, 0, MAX_CLIENTS);
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   774
						break;
7439
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   775
				}
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   776
			}
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   777
			_left_button_clicked = false;
2879
365ecd52f2db (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
   778
			break;
7959
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   779
		case NSSW_CLIENTS_TXT:    // Click on number of players
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   780
			nd->widget_id = NSSW_CLIENTS_TXT;
7439
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   781
			SetDParam(0, _network_game_info.clients_max);
7959
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   782
			ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_NETWORK_NUMBER_OF_CLIENTS,    3, 50, w, CS_NUMERAL);
2879
365ecd52f2db (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
   783
			break;
7959
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   784
		case NSSW_COMPANIES_TXT:  // Click on number of companies
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   785
			nd->widget_id = NSSW_COMPANIES_TXT;
7439
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   786
			SetDParam(0, _network_game_info.companies_max);
7959
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   787
			ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_NETWORK_NUMBER_OF_COMPANIES,  3, 50, w, CS_NUMERAL);
2879
365ecd52f2db (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
   788
			break;
7959
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   789
		case NSSW_SPECTATORS_TXT: // Click on number of spectators
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   790
			nd->widget_id = NSSW_SPECTATORS_TXT;
7439
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   791
			SetDParam(0, _network_game_info.spectators_max);
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   792
			ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_NETWORK_NUMBER_OF_SPECTATORS, 3, 50, w, CS_NUMERAL);
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   793
			break;
7959
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   794
		case NSSW_LANGUAGE_TXT: case NSSW_LANGUAGE_BTN: { // Language
6798
a640d9b85407 (svn r10037) -Fix (r10035, r10036): silence some 'may be used uninitialized' warnings
glx
parents: 6796
diff changeset
   795
			uint sel = 0;
6796
ff1875ba196d (svn r10035) -Change: simplified network language string sorting
glx
parents: 6793
diff changeset
   796
			for (uint i = 0; i < lengthof(_language_dropdown) - 1; i++) {
ff1875ba196d (svn r10035) -Change: simplified network language string sorting
glx
parents: 6793
diff changeset
   797
				if (_language_dropdown[i] == STR_NETWORK_LANG_ANY + _network_game_info.server_lang) {
ff1875ba196d (svn r10035) -Change: simplified network language string sorting
glx
parents: 6793
diff changeset
   798
					sel = i;
ff1875ba196d (svn r10035) -Change: simplified network language string sorting
glx
parents: 6793
diff changeset
   799
					break;
ff1875ba196d (svn r10035) -Change: simplified network language string sorting
glx
parents: 6793
diff changeset
   800
				}
ff1875ba196d (svn r10035) -Change: simplified network language string sorting
glx
parents: 6793
diff changeset
   801
			}
7959
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   802
			ShowDropDownMenu(w, _language_dropdown, sel, NSSW_LANGUAGE_BTN, 0, 0);
2879
365ecd52f2db (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
   803
			break;
6796
ff1875ba196d (svn r10035) -Change: simplified network language string sorting
glx
parents: 6793
diff changeset
   804
		}
7959
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   805
		case NSSW_START: // Start game
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   806
			_is_network_server = true;
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
   807
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
   808
			if (nd->map == NULL) { // start random new game
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4299
diff changeset
   809
				ShowGenerateLandscape();
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   810
			} else { // load a scenario
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
   811
				char *name = FiosBrowseTo(nd->map);
2100
217ea6fdfd18 (svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents: 2071
diff changeset
   812
				if (name != NULL) {
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
   813
					SetFiosType(nd->map->type);
2100
217ea6fdfd18 (svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents: 2071
diff changeset
   814
					ttd_strlcpy(_file_to_saveload.name, name, sizeof(_file_to_saveload.name));
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
   815
					ttd_strlcpy(_file_to_saveload.title, nd->map->title, sizeof(_file_to_saveload.title));
2100
217ea6fdfd18 (svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents: 2071
diff changeset
   816
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   817
					DeleteWindow(w);
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4299
diff changeset
   818
					SwitchMode(SM_START_SCENARIO);
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   819
				}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   820
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   821
			break;
7959
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   822
		case NSSW_LOAD: // Load game
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   823
			_is_network_server = true;
7959
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   824
			/* XXX - WC_NETWORK_WINDOW (this window) should stay, but if it stays, it gets
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   825
			 * copied all the elements of 'load game' and upon closing that, it segfaults */
7959
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   826
			DeleteWindow(w);
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
   827
			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
   828
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   829
		}
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
   830
		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
   831
7959
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   832
	case WE_DROPDOWN_SELECT: // we have selected a dropdown item in the list
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
   833
		switch (e->we.dropdown.button) {
7959
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   834
			case NSSW_CONNTYPE_BTN:
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   835
				_network_advertise = (e->we.dropdown.index != 0);
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   836
				break;
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   837
			case NSSW_LANGUAGE_BTN:
6796
ff1875ba196d (svn r10035) -Change: simplified network language string sorting
glx
parents: 6793
diff changeset
   838
				_network_game_info.server_lang = _language_dropdown[e->we.dropdown.index] - STR_NETWORK_LANG_ANY;
6780
ba49b125d95e (svn r10017) -Add (FS#790): more languages flags for servers
glx
parents: 6531
diff changeset
   839
				break;
7959
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   840
			default:
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   841
				NOT_REACHED();
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   842
		}
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
   843
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
   844
		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
   845
		break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   846
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   847
	case WE_MOUSELOOP:
7959
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   848
		if (nd->field == NSSW_GAMENAME) HandleEditBox(w, &WP(w, network_ql_d).q, NSSW_GAMENAME);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   849
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   850
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   851
	case WE_KEYPRESS:
7959
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   852
		if (nd->field == NSSW_GAMENAME) {
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   853
			if (HandleEditBoxKey(w, &WP(w, network_ql_d).q, NSSW_GAMENAME, e) == 1) break; // enter pressed
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
   854
2888
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
   855
			ttd_strlcpy(_network_server_name, WP(w, network_ql_d).q.text.buf, sizeof(_network_server_name));
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
   856
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   857
		break;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   858
7439
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   859
	case WE_ON_EDIT_TEXT:
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   860
		if (e->we.edittext.str == NULL) break;
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   861
7959
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   862
		if (nd->widget_id == NSSW_SETPWD) {
7439
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   863
			ttd_strlcpy(_network_server_password, e->we.edittext.str, lengthof(_network_server_password));
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   864
			_network_game_info.use_password = (_network_server_password[0] != '\0');
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   865
		} else {
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   866
			int32 value = atoi(e->we.edittext.str);
8028
e578ea22f371 (svn r11588) -Codechange: use the new member introduced in r11551
glx
parents: 8019
diff changeset
   867
			w->InvalidateWidget(nd->widget_id);
7439
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   868
			switch (nd->widget_id) {
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   869
				default: NOT_REACHED();
7959
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   870
				case NSSW_CLIENTS_TXT:    _network_game_info.clients_max    = Clamp(value, 2, MAX_CLIENTS); break;
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   871
				case NSSW_COMPANIES_TXT:  _network_game_info.companies_max  = Clamp(value, 1, MAX_PLAYERS); break;
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   872
				case NSSW_SPECTATORS_TXT: _network_game_info.spectators_max = Clamp(value, 0, MAX_CLIENTS); break;
7439
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   873
			}
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   874
		}
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   875
1653
d2db1ba2abde (svn r2157) - Feature (request): [ 1166978 ] Focus keyboard on input-box in Multiplayer Menu
Darkvater
parents: 1648
diff changeset
   876
		SetWindowDirty(w);
7439
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   877
		break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   878
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   879
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   880
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   881
static const Widget _network_start_server_window_widgets[] = {
7959
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   882
/* Window decoration and background panel */
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   883
{   WWT_CLOSEBOX,   RESIZE_NONE,   BGC,     0,    10,     0,    13, STR_00C5,                         STR_018B_CLOSE_WINDOW },               // NSSW_CLOSE
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   884
{    WWT_CAPTION,   RESIZE_NONE,   BGC,    11,   419,     0,    13, STR_NETWORK_START_GAME_WINDOW,    STR_NULL},
7961
6d30992b6084 (svn r11517) -Codechange: better cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7960
diff changeset
   885
{      WWT_PANEL,   RESIZE_NONE,   BGC,     0,   419,    14,   243, 0x0,                              STR_NULL},
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
   886
7959
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   887
/* Set game name and password widgets */
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   888
{       WWT_TEXT,   RESIZE_NONE,   BGC,    10,    90,    22,    34, STR_NETWORK_NEW_GAME_NAME,        STR_NULL},
7961
6d30992b6084 (svn r11517) -Codechange: better cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7960
diff changeset
   889
{      WWT_PANEL,   RESIZE_NONE,   BGC,   100,   272,    22,    33, 0x0,                              STR_NETWORK_NEW_GAME_NAME_TIP},        // NSSW_GAMENAME
7959
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   890
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   285,   405,    22,    33, STR_NETWORK_SET_PASSWORD,         STR_NETWORK_PASSWORD_TIP},             // NSSW_SETPWD
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
   891
7959
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   892
/* List of playable scenarios */
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   893
{       WWT_TEXT,   RESIZE_NONE,   BGC,    10,   110,    43,    55, STR_NETWORK_SELECT_MAP,           STR_NULL},
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   894
{      WWT_INSET,   RESIZE_NONE,   BGC,    10,   271,    62,   216, STR_NULL,                         STR_NETWORK_SELECT_MAP_TIP},           // NSSW_SELMAP
7961
6d30992b6084 (svn r11517) -Codechange: better cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7960
diff changeset
   895
{  WWT_SCROLLBAR,   RESIZE_NONE,   BGC,   259,   270,    63,   215, 0x0,                              STR_0190_SCROLL_BAR_SCROLLS_LIST},
7959
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   896
7439
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   897
/* Combo/selection boxes to control Connection Type / Max Clients / Max Companies / Max Observers / Language */
7959
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   898
{       WWT_TEXT,   RESIZE_NONE,   BGC,   280,   419,    63,    75, STR_NETWORK_CONNECTION,           STR_NULL},
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   899
{      WWT_INSET,   RESIZE_NONE,   BGC,   280,   410,    77,    88, STR_NETWORK_LAN_INTERNET_COMBO,   STR_NETWORK_CONNECTION_TIP},           // NSSW_CONNTYPE_TXT
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   900
{    WWT_TEXTBTN,   RESIZE_NONE,   BGC,   399,   409,    78,    87, STR_0225,                         STR_NETWORK_CONNECTION_TIP},           // NSSW_CONNTYPE_BTN
7439
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   901
7959
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   902
{       WWT_TEXT,   RESIZE_NONE,   BGC,   280,   419,    95,   107, STR_NETWORK_NUMBER_OF_CLIENTS,    STR_NULL},
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   903
{     WWT_IMGBTN,   RESIZE_NONE,   BGC,   280,   291,   109,   120, SPR_ARROW_DOWN,                   STR_NETWORK_NUMBER_OF_CLIENTS_TIP},    // NSSW_CLIENTS_BTND
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   904
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BGC,   292,   397,   109,   120, STR_NETWORK_CLIENTS_SELECT,       STR_NETWORK_NUMBER_OF_CLIENTS_TIP},    // NSSW_CLIENTS_TXT
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   905
{     WWT_IMGBTN,   RESIZE_NONE,   BGC,   398,   410,   109,   120, SPR_ARROW_UP,                     STR_NETWORK_NUMBER_OF_CLIENTS_TIP},    // NSSW_CLIENTS_BTNU
7439
dfbe1adff313 (svn r10886) -Codechange: modify the "start network server" GUI so it can actually handle more than 10 clients/companies/spectators in a nice way, i.e. without making a combobox with 100 players and add 90 new strings to be able to do so.
rubidium
parents: 7363
diff changeset
   906
7959
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   907
{       WWT_TEXT,   RESIZE_NONE,   BGC,   280,   419,   127,   139, STR_NETWORK_NUMBER_OF_COMPANIES,  STR_NULL},
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   908
{     WWT_IMGBTN,   RESIZE_NONE,   BGC,   280,   291,   141,   152, SPR_ARROW_DOWN,                   STR_NETWORK_NUMBER_OF_COMPANIES_TIP},  // NSSW_COMPANIES_BTND
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   909
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BGC,   292,   397,   141,   152, STR_NETWORK_COMPANIES_SELECT,     STR_NETWORK_NUMBER_OF_COMPANIES_TIP},  // NSSW_COMPANIES_TXT
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   910
{     WWT_IMGBTN,   RESIZE_NONE,   BGC,   398,   410,   141,   152, SPR_ARROW_UP,                     STR_NETWORK_NUMBER_OF_COMPANIES_TIP},  // NSSW_COMPANIES_BTNU
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   911
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   912
{       WWT_TEXT,   RESIZE_NONE,   BGC,   280,   419,   159,   171, STR_NETWORK_NUMBER_OF_SPECTATORS, STR_NULL},
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   913
{     WWT_IMGBTN,   RESIZE_NONE,   BGC,   280,   291,   173,   184, SPR_ARROW_DOWN,                   STR_NETWORK_NUMBER_OF_SPECTATORS_TIP}, // NSSW_SPECTATORS_BTND
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   914
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BGC,   292,   397,   173,   184, STR_NETWORK_SPECTATORS_SELECT,    STR_NETWORK_NUMBER_OF_SPECTATORS_TIP}, // NSSW_SPECTATORS_TXT
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   915
{     WWT_IMGBTN,   RESIZE_NONE,   BGC,   398,   410,   173,   184, SPR_ARROW_UP,                     STR_NETWORK_NUMBER_OF_SPECTATORS_TIP}, // NSSW_SPECTATORS_BTNU
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   916
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   917
{       WWT_TEXT,   RESIZE_NONE,   BGC,   280,   419,   191,   203, STR_NETWORK_LANGUAGE_SPOKEN,      STR_NULL},
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   918
{      WWT_INSET,   RESIZE_NONE,   BGC,   280,   410,   205,   216, STR_NETWORK_LANGUAGE_COMBO,       STR_NETWORK_LANGUAGE_TIP},             // NSSW_LANGUAGE_TXT
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   919
{    WWT_TEXTBTN,   RESIZE_NONE,   BGC,   399,   409,   206,   215, STR_0225,                         STR_NETWORK_LANGUAGE_TIP},             // NSSW_LANGUAGE_BTN
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   920
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   921
/* Buttons Start / Load / Cancel */
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   922
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,    40,   140,   224,   235, STR_NETWORK_START_GAME,           STR_NETWORK_START_GAME_TIP},           // NSSW_START
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   923
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   150,   250,   224,   235, STR_NETWORK_LOAD_GAME,            STR_NETWORK_LOAD_GAME_TIP},            // NSSW_LOAD
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   924
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   260,   360,   224,   235, STR_012E_CANCEL,                  STR_NULL},                             // NSSW_CANCEL
e0476faea1e2 (svn r11515) -Codechange: cleanup of NetworkStartServerWindow in network_gui.cpp
smatz
parents: 7931
diff changeset
   925
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 175
diff changeset
   926
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   927
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   928
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   929
static const WindowDesc _network_start_server_window_desc = {
7341
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7321
diff changeset
   930
	WDP_CENTER, WDP_CENTER, 420, 244, 420, 244,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5669
diff changeset
   931
	WC_NETWORK_WINDOW, WC_NONE,
2064
e6a2b42d0b15 (svn r2573) Codechange: Removed WDF_RESTORE_DPARAM, it's not needed with the new string system.
ludde
parents: 2055
diff changeset
   932
	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
   933
	_network_start_server_window_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   934
	NetworkStartServerWindowWndProc,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   935
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   936
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 5916
diff changeset
   937
static void ShowNetworkStartServerWindow()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   938
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   939
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   940
	DeleteWindowById(WC_NETWORK_WINDOW, 0);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   941
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   942
	w = AllocateWindowDesc(&_network_start_server_window_desc);
3470
cd704e52732f (svn r4315) Remove MAX_QUERYSTR_LEN, rather use lengthof() the real thing
tron
parents: 3469
diff changeset
   943
	ttd_strlcpy(_edit_str_buf, _network_server_name, lengthof(_edit_str_buf));
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   944
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   945
	_saveload_mode = SLD_NEW_GAME;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   946
	BuildFileList();
2943
2e24a1c0a0cd (svn r3499) - Fix: a few gui glitches in the network window:
Darkvater
parents: 2938
diff changeset
   947
	w->vscroll.cap = 12;
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6248
diff changeset
   948
	w->vscroll.count = _fios_num + 1;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   949
4909
955f318a24cd (svn r6879) -Codechange: Remove the superflouos argument CharsetFilter parameter from HandleEditBoxKey
Darkvater
parents: 4906
diff changeset
   950
	WP(w, network_ql_d).q.afilter = CS_ALPHANUMERAL;
4948
22ff05c1a3b1 (svn r6937) -Codechange: Add an InitializeTextBuffer() function that handles setting up the
Darkvater
parents: 4945
diff changeset
   951
	InitializeTextBuffer(&WP(w, network_ql_d).q.text, _edit_str_buf, lengthof(_edit_str_buf), 160);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   952
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   953
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   954
static PlayerID NetworkLobbyFindCompanyIndex(byte pos)
734
f4ad2f5805fd (svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents: 722
diff changeset
   955
{
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   956
	PlayerID i;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   957
734
f4ad2f5805fd (svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents: 722
diff changeset
   958
	/* Scroll through all _network_player_info and get the 'pos' item
f4ad2f5805fd (svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents: 722
diff changeset
   959
	    that is not empty */
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   960
	for (i = PLAYER_FIRST; i < MAX_PLAYERS; i++) {
734
f4ad2f5805fd (svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents: 722
diff changeset
   961
		if (_network_player_info[i].company_name[0] != '\0') {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   962
			if (pos-- == 0) return i;
734
f4ad2f5805fd (svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents: 722
diff changeset
   963
		}
f4ad2f5805fd (svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents: 722
diff changeset
   964
	}
f4ad2f5805fd (svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents: 722
diff changeset
   965
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   966
	return PLAYER_FIRST;
734
f4ad2f5805fd (svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents: 722
diff changeset
   967
}
f4ad2f5805fd (svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents: 722
diff changeset
   968
7963
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
   969
/** Enum for NetworkLobbyWindow, referring to _network_lobby_window_widgets */
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
   970
enum NetworkLobbyWindowWidgets {
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
   971
	NLWW_CLOSE    =  0, ///< Close 'X' button
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
   972
	NLWW_MATRIX   =  5, ///< List of companies
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
   973
	NLWW_DETAILS  =  7, ///< Company details
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
   974
	NLWW_JOIN     =  8, ///< 'Join company' button
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
   975
	NLWW_NEW      =  9, ///< 'New company' button
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
   976
	NLWW_SPECTATE = 10, ///< 'Spectate game' button
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
   977
	NLWW_REFRESH  = 11, ///< 'Refresh server' button
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
   978
	NLWW_CANCEL   = 12, ///< 'Cancel' button
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
   979
};
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
   980
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
   981
/**
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
   982
 * Handler of actions done in the NetworkLobby window
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
   983
 *
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
   984
 * @param w pointer to the Window structure
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
   985
 * @param e pointer to window event
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
   986
 * @note    uses network_d WP macro
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
   987
 * @see     struct _network_lobby_window_widgets
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
   988
 * @see     enum NetworkLobbyWindowWidgets
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
   989
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   990
static void NetworkLobbyWindowWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   991
{
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
   992
	network_d *nd = &WP(w, network_d);
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
   993
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
   994
	switch (e->event) {
2879
365ecd52f2db (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
   995
	case WE_CREATE:
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   996
		nd->company = INVALID_PLAYER;
2879
365ecd52f2db (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
   997
		break;
365ecd52f2db (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
   998
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   999
	case WE_PAINT: {
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
  1000
		const NetworkGameInfo *gi = &nd->server->info;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1001
		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
  1002
7963
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
  1003
		/* Join button is disabled when no company is selected */
7997
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7966
diff changeset
  1004
		w->SetWidgetDisabledState(NLWW_JOIN, nd->company == INVALID_PLAYER);
7963
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
  1005
		/* Cannot start new company if there are too many */
7997
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7966
diff changeset
  1006
		w->SetWidgetDisabledState(NLWW_NEW, gi->companies_on >= gi->companies_max);
7963
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
  1007
		/* Cannot spectate if there are too many spectators */
7997
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7966
diff changeset
  1008
		w->SetWidgetDisabledState(NLWW_SPECTATE, gi->spectators_on >= gi->spectators_max);
621
31b12c30b54c (svn r1051) -Fix: [Network] New Company button is disabled when there is no more
truelight
parents: 618
diff changeset
  1009
7963
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
  1010
		/* Draw window widgets */
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
  1011
		SetDParamStr(0, gi->server_name);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1012
		DrawWindowWidgets(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1013
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
  1014
		/* Draw company list */
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1015
		pos = w->vscroll.pos;
2879
365ecd52f2db (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
  1016
		while (pos < gi->companies_on) {
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
  1017
			byte company = NetworkLobbyFindCompanyIndex(pos);
1011
933efc472c62 (svn r1510) -Add: Improved Network Lobby GUI: (bociusz)
truelight
parents: 1009
diff changeset
  1018
			bool income = false;
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
  1019
			if (nd->company == company)
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
  1020
				GfxFillRect(11, y - 1, 154, y + 10, 10); // 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
  1021
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
  1022
			DoDrawStringTruncated(_network_player_info[company].company_name, 13, y, TC_BLACK, 135 - 13);
5669
631901f52707 (svn r8129) -Codechange: Change data tables to use split off palette map. And
peter1138
parents: 5658
diff changeset
  1023
			if (_network_player_info[company].use_password != 0) DrawSprite(SPR_LOCK, PAL_NONE, 135, y);
1011
933efc472c62 (svn r1510) -Add: Improved Network Lobby GUI: (bociusz)
truelight
parents: 1009
diff changeset
  1024
933efc472c62 (svn r1510) -Add: Improved Network Lobby GUI: (bociusz)
truelight
parents: 1009
diff changeset
  1025
			/* If the company's income was positive puts a green dot else a red dot */
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
  1026
			if (_network_player_info[company].income >= 0) income = true;
5669
631901f52707 (svn r8129) -Codechange: Change data tables to use split off palette map. And
peter1138
parents: 5658
diff changeset
  1027
			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
  1028
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1029
			pos++;
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
  1030
			y += NET_PRC__SIZE_OF_ROW;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1031
			if (pos >= w->vscroll.cap) break;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1032
		}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1033
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
  1034
		/* Draw info about selected company when it is selected in the left window */
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
  1035
		GfxFillRect(174, 39, 403, 75, 157);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
  1036
		DrawStringCentered(290, 50, STR_NETWORK_COMPANY_INFO, TC_FROMSTRING);
7963
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
  1037
		if (nd->company != INVALID_PLAYER) {
1025
f10da46b66f0 (svn r1526) -Fix: [1103027] Minor changes for the lobby GUI (widen window) (bociusz)
darkvater
parents: 1019
diff changeset
  1038
			const uint x = 183;
7963
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
  1039
			const uint trunc_width = w->widget[NLWW_DETAILS].right - x;
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
  1040
			y = 80;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1041
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
  1042
			SetDParam(0, nd->server->info.clients_on);
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
  1043
			SetDParam(1, nd->server->info.clients_max);
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
  1044
			SetDParam(2, nd->server->info.companies_on);
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
  1045
			SetDParam(3, nd->server->info.companies_max);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
  1046
			DrawString(x, y, STR_NETWORK_CLIENTS, TC_GOLD);
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
  1047
			y += 10;
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
  1048
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
  1049
			SetDParamStr(0, _network_player_info[nd->company].company_name);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
  1050
			DrawStringTruncated(x, y, STR_NETWORK_COMPANY_NAME, TC_GOLD, trunc_width);
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1051
			y += 10;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1052
4329
0e6e689f66e7 (svn r6002) -Cleanup: remove the now redundant BASE_YEAR constant.
rubidium
parents: 4319
diff changeset
  1053
			SetDParam(0, _network_player_info[nd->company].inaugurated_year);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
  1054
			DrawString(x, y, STR_NETWORK_INAUGURATION_YEAR, TC_GOLD); // inauguration year
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1055
			y += 10;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1056
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6991
diff changeset
  1057
			SetDParam(0, _network_player_info[nd->company].company_value);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
  1058
			DrawString(x, y, STR_NETWORK_VALUE, TC_GOLD); // company value
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1059
			y += 10;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1060
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6991
diff changeset
  1061
			SetDParam(0, _network_player_info[nd->company].money);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
  1062
			DrawString(x, y, STR_NETWORK_CURRENT_BALANCE, TC_GOLD); // current balance
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1063
			y += 10;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1064
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6991
diff changeset
  1065
			SetDParam(0, _network_player_info[nd->company].income);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
  1066
			DrawString(x, y, STR_NETWORK_LAST_YEARS_INCOME, TC_GOLD); // last year's income
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1067
			y += 10;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1068
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
  1069
			SetDParam(0, _network_player_info[nd->company].performance);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
  1070
			DrawString(x, y, STR_NETWORK_PERFORMANCE, TC_GOLD); // performance
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1071
			y += 10;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1072
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
  1073
			SetDParam(0, _network_player_info[nd->company].num_vehicle[0]);
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
  1074
			SetDParam(1, _network_player_info[nd->company].num_vehicle[1]);
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
  1075
			SetDParam(2, _network_player_info[nd->company].num_vehicle[2]);
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
  1076
			SetDParam(3, _network_player_info[nd->company].num_vehicle[3]);
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
  1077
			SetDParam(4, _network_player_info[nd->company].num_vehicle[4]);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
  1078
			DrawString(x, y, STR_NETWORK_VEHICLES, TC_GOLD); // vehicles
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1079
			y += 10;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1080
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
  1081
			SetDParam(0, _network_player_info[nd->company].num_station[0]);
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
  1082
			SetDParam(1, _network_player_info[nd->company].num_station[1]);
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
  1083
			SetDParam(2, _network_player_info[nd->company].num_station[2]);
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
  1084
			SetDParam(3, _network_player_info[nd->company].num_station[3]);
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
  1085
			SetDParam(4, _network_player_info[nd->company].num_station[4]);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
  1086
			DrawString(x, y, STR_NETWORK_STATIONS, TC_GOLD); // stations
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1087
			y += 10;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1088
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
  1089
			SetDParamStr(0, _network_player_info[nd->company].players);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
  1090
			DrawStringTruncated(x, y, STR_NETWORK_PLAYERS, TC_GOLD, trunc_width); // players
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1091
		}
6492
286a52449b54 (svn r9673) -Cleanup: remove spaces before tabs and replace non-indenting tabs with spaces.
rubidium
parents: 6491
diff changeset
  1092
	} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1093
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1094
	case WE_CLICK:
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
  1095
		switch (e->we.click.widget) {
7963
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
  1096
		case NLWW_CLOSE:    // Close 'X'
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
  1097
		case NLWW_CANCEL:   // Cancel button
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1098
			ShowNetworkGameWindow();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1099
			break;
7963
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
  1100
		case NLWW_MATRIX: { // Company list
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
  1101
			uint32 id_v = (e->we.click.pt.y - NET_PRC__OFFSET_TOP_WIDGET_COMPANY) / NET_PRC__SIZE_OF_ROW;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1102
7963
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
  1103
			if (id_v >= w->vscroll.cap) break;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1104
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
  1105
			id_v += w->vscroll.pos;
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  1106
			nd->company = (id_v >= nd->server->info.companies_on) ? INVALID_PLAYER : NetworkLobbyFindCompanyIndex(id_v);
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1107
			SetWindowDirty(w);
6492
286a52449b54 (svn r9673) -Cleanup: remove spaces before tabs and replace non-indenting tabs with spaces.
rubidium
parents: 6491
diff changeset
  1108
		} break;
7963
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
  1109
		case NLWW_JOIN:     // Join company
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
  1110
			/* Button can be clicked only when it is enabled */
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
  1111
			_network_playas = nd->company;
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
  1112
			NetworkClientConnectGame(_network_last_host, _network_last_port);
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1113
			break;
7963
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
  1114
		case NLWW_NEW:      // New company
4861
2119f5d46e41 (svn r6787) -Codechange: Use PLAYER_NEW_COMPANY as a player identifier wishing to become a
Darkvater
parents: 4848
diff changeset
  1115
			_network_playas = PLAYER_NEW_COMPANY;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1116
			NetworkClientConnectGame(_network_last_host, _network_last_port);
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1117
			break;
7963
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
  1118
		case NLWW_SPECTATE: // Spectate game
4848
45f848b46222 (svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents: 4830
diff changeset
  1119
			_network_playas = PLAYER_SPECTATOR;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1120
			NetworkClientConnectGame(_network_last_host, _network_last_port);
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1121
			break;
7963
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
  1122
		case NLWW_REFRESH:  // Refresh
5916
8931f4450f51 (svn r8543) -Codechange: make a real difference between querying the server via UDP and TCP.
rubidium
parents: 5893
diff changeset
  1123
			NetworkTCPQueryServer(_network_last_host, _network_last_port); // company info
8931f4450f51 (svn r8543) -Codechange: make a real difference between querying the server via UDP and TCP.
rubidium
parents: 5893
diff changeset
  1124
			NetworkUDPQueryServer(_network_last_host, _network_last_port); // general data
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1125
			break;
6492
286a52449b54 (svn r9673) -Cleanup: remove spaces before tabs and replace non-indenting tabs with spaces.
rubidium
parents: 6491
diff changeset
  1126
		} break;
2884
8f00f4e86bf6 (svn r3434) - Correctly update all network information when pressing refresh in the lobby. Also always allow the join button to a server unless all clients are used up (otherwise you can always join an existing company
Darkvater
parents: 2881
diff changeset
  1127
8f00f4e86bf6 (svn r3434) - Correctly update all network information when pressing refresh in the lobby. Also always allow the join button to a server unless all clients are used up (otherwise you can always join an existing company
Darkvater
parents: 2881
diff changeset
  1128
	case WE_MESSAGE:
8f00f4e86bf6 (svn r3434) - Correctly update all network information when pressing refresh in the lobby. Also always allow the join button to a server unless all clients are used up (otherwise you can always join an existing company
Darkvater
parents: 2881
diff changeset
  1129
		SetWindowDirty(w);
8f00f4e86bf6 (svn r3434) - Correctly update all network information when pressing refresh in the lobby. Also always allow the join button to a server unless all clients are used up (otherwise you can always join an existing company
Darkvater
parents: 2881
diff changeset
  1130
		break;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1131
	}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1132
}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1133
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1134
static const Widget _network_lobby_window_widgets[] = {
7963
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
  1135
{   WWT_CLOSEBOX,   RESIZE_NONE,   BGC,     0,    10,     0,    13, STR_00C5,                    STR_018B_CLOSE_WINDOW },           // NLWW_CLOSE
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
  1136
{    WWT_CAPTION,   RESIZE_NONE,   BGC,    11,   419,     0,    13, STR_NETWORK_GAME_LOBBY,      STR_NULL},
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
  1137
{      WWT_PANEL,   RESIZE_NONE,   BGC,     0,   419,    14,   234, 0x0,                         STR_NULL},
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
  1138
{       WWT_TEXT,   RESIZE_NONE,   BGC,    10,   419,    22,    34, STR_NETWORK_PREPARE_TO_JOIN, STR_NULL},
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1139
7963
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
  1140
/* company list */
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
  1141
{      WWT_PANEL,   RESIZE_NONE,   BTC,    10,   155,    38,    49, 0x0,                         STR_NULL},
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
  1142
{     WWT_MATRIX,   RESIZE_NONE,   BGC,    10,   155,    50,   190, (10 << 8) + 1,               STR_NETWORK_COMPANY_LIST_TIP},     // NLWW_MATRIX
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
  1143
{  WWT_SCROLLBAR,   RESIZE_NONE,   BGC,   156,   167,    38,   190, 0x0,                         STR_0190_SCROLL_BAR_SCROLLS_LIST},
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1144
7963
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
  1145
/* company/player info */
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
  1146
{      WWT_PANEL,   RESIZE_NONE,   BGC,   173,   404,    38,   190, 0x0,                         STR_NULL},                         // NLWW_DETAILS
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
  1147
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
  1148
/* buttons */
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
  1149
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,    10,   151,   200,   211, STR_NETWORK_JOIN_COMPANY,    STR_NETWORK_JOIN_COMPANY_TIP},     // NLWW_JOIN
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
  1150
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,    10,   151,   215,   226, STR_NETWORK_NEW_COMPANY,     STR_NETWORK_NEW_COMPANY_TIP},      // NLWW_NEW
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
  1151
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   158,   268,   200,   211, STR_NETWORK_SPECTATE_GAME,   STR_NETWORK_SPECTATE_GAME_TIP},    // NLWW_SPECTATE
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
  1152
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   158,   268,   215,   226, STR_NETWORK_REFRESH,         STR_NETWORK_REFRESH_TIP},          // NLWW_REFRESH
bf9d4e26ea5b (svn r11519) -Codechange: enumerization and cleanup of NetworkLobbyWindow in network_gui.cpp
smatz
parents: 7961
diff changeset
  1153
{ WWT_PUSHTXTBTN,   RESIZE_NONE,   BTC,   278,   388,   200,   211, STR_012E_CANCEL,             STR_NULL},                         // NLWW_CANCEL
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1154
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1155
{   WIDGETS_END},
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1156
};
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1157
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1158
static const WindowDesc _network_lobby_window_desc = {
7341
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7321
diff changeset
  1159
	WDP_CENTER, WDP_CENTER, 420, 235, 420, 235,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5669
diff changeset
  1160
	WC_NETWORK_WINDOW, WC_NONE,
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1161
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1162
	_network_lobby_window_widgets,
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1163
	NetworkLobbyWindowWndProc,
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1164
};
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1165
2888
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
  1166
/* Show the networklobbywindow with the selected server
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
  1167
 * @param ngl Selected game pointer which is passed to the new window */
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
  1168
static void ShowNetworkLobbyWindow(NetworkGameList *ngl)
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1169
{
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1170
	Window *w;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1171
	DeleteWindowById(WC_NETWORK_WINDOW, 0);
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1172
5916
8931f4450f51 (svn r8543) -Codechange: make a real difference between querying the server via UDP and TCP.
rubidium
parents: 5893
diff changeset
  1173
	NetworkTCPQueryServer(_network_last_host, _network_last_port); // company info
8931f4450f51 (svn r8543) -Codechange: make a real difference between querying the server via UDP and TCP.
rubidium
parents: 5893
diff changeset
  1174
	NetworkUDPQueryServer(_network_last_host, _network_last_port); // general data
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1175
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1176
	w = AllocateWindowDesc(&_network_lobby_window_desc);
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
  1177
	if (w != NULL) {
2888
79da960a5372 (svn r3441) - Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending)
Darkvater
parents: 2887
diff changeset
  1178
		WP(w, network_ql_d).n.server = ngl;
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
  1179
		strcpy(_edit_str_buf, "");
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
  1180
		w->vscroll.cap = 10;
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
  1181
	}
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1182
}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1183
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1184
// The window below gives information about the connected clients
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1185
//  and also makes able to give money to them, kick them (if server)
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1186
//  and stuff like that.
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1187
3692
1d8f5041d437 (svn r4623) - Codechange: s/byte/PlayerID/
Darkvater
parents: 3470
diff changeset
  1188
extern void DrawPlayerIcon(PlayerID pid, int x, int y);
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1189
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1190
// Every action must be of this form
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1191
typedef void ClientList_Action_Proc(byte client_no);
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1192
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1193
// Max 10 actions per client
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1194
#define MAX_CLIENTLIST_ACTION 10
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1195
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1196
// Some standard bullshit.. defines variables ;)
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1197
static void ClientListWndProc(Window *w, WindowEvent *e);
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1198
static void ClientListPopupWndProc(Window *w, WindowEvent *e);
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1199
static byte _selected_clientlist_item = 255;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1200
static byte _selected_clientlist_y = 0;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1201
static char _clientlist_action[MAX_CLIENTLIST_ACTION][50];
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1202
static ClientList_Action_Proc *_clientlist_proc[MAX_CLIENTLIST_ACTION];
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1203
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1204
enum {
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1205
	CLNWND_OFFSET = 16,
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1206
	CLNWND_ROWSIZE = 10
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1207
};
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1208
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
  1209
static const Widget _client_list_widgets[] = {
2725
775e3e14ca46 (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
  1210
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                 STR_018B_CLOSE_WINDOW},
7029
7b84f0befa90 (svn r10293) -Add [FS#885]: a sticky button for the client list window (oxygene)
truelight
parents: 7002
diff changeset
  1211
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   237,     0,    13, STR_NETWORK_CLIENT_LIST,  STR_018C_WINDOW_TITLE_DRAG_THIS},
7b84f0befa90 (svn r10293) -Add [FS#885]: a sticky button for the client list window (oxygene)
truelight
parents: 7002
diff changeset
  1212
{  WWT_STICKYBOX,   RESIZE_NONE,    14,   238,   249,     0,    13, STR_NULL,                 STR_STICKY_BUTTON},
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1213
4938
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1214
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   249,    14,    14 + CLNWND_ROWSIZE + 1, 0x0, STR_NULL},
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1215
{   WIDGETS_END},
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1216
};
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1217
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
  1218
static const Widget _client_list_popup_widgets[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4329
diff changeset
  1219
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   99,     0,     0,     0, STR_NULL},
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1220
{   WIDGETS_END},
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1221
};
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1222
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1223
static WindowDesc _client_list_desc = {
7341
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7321
diff changeset
  1224
	WDP_AUTO, WDP_AUTO, 250, 1, 250, 1,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5669
diff changeset
  1225
	WC_CLIENT_LIST, WC_NONE,
7029
7b84f0befa90 (svn r10293) -Add [FS#885]: a sticky button for the client list window (oxygene)
truelight
parents: 7002
diff changeset
  1226
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1227
	_client_list_widgets,
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1228
	ClientListWndProc
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1229
};
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1230
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1231
// Finds the Xth client-info that is active
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
  1232
static const NetworkClientInfo *NetworkFindClientInfo(byte client_no)
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1233
{
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
  1234
	const NetworkClientInfo *ci;
2630
7206058a7e82 (svn r3172) static, const
tron
parents: 2549
diff changeset
  1235
4883
c9c7d15c0b0b (svn r6820) -Codechange: Some more const correctness, coding style.
Darkvater
parents: 4880
diff changeset
  1236
	FOR_ALL_ACTIVE_CLIENT_INFOS(ci) {
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1237
		if (client_no == 0) return ci;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1238
		client_no--;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1239
	}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1240
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1241
	return NULL;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1242
}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1243
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1244
// Here we start to define the options out of the menu
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1245
static void ClientList_Kick(byte client_no)
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1246
{
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1247
	if (client_no < MAX_PLAYERS)
4880
aac84a9dcd03 (svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents: 4878
diff changeset
  1248
		SEND_COMMAND(PACKET_SERVER_ERROR)(DEREF_CLIENT(client_no), NETWORK_ERROR_KICKED);
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1249
}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1250
841
4874b9ce2765 (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
  1251
static void ClientList_Ban(byte client_no)
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1252
{
841
4874b9ce2765 (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
  1253
	uint i;
4874b9ce2765 (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
  1254
	uint32 ip = NetworkFindClientInfo(client_no)->client_ip;
4874b9ce2765 (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
  1255
4874b9ce2765 (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
  1256
	for (i = 0; i < lengthof(_network_ban_list); i++) {
2914
ccfa238c6645 (svn r3469) - Fix: plug a possible memleak with subsequential strdup's without freeing the previous value and make it possible to ban offline clients
Darkvater
parents: 2889
diff changeset
  1257
		if (_network_ban_list[i] == NULL) {
841
4874b9ce2765 (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
  1258
			_network_ban_list[i] = strdup(inet_ntoa(*(struct in_addr *)&ip));
4874b9ce2765 (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
  1259
			break;
4874b9ce2765 (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
  1260
		}
4874b9ce2765 (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
  1261
	}
4874b9ce2765 (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
  1262
4874b9ce2765 (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
  1263
	if (client_no < MAX_PLAYERS)
4880
aac84a9dcd03 (svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents: 4878
diff changeset
  1264
		SEND_COMMAND(PACKET_SERVER_ERROR)(DEREF_CLIENT(client_no), NETWORK_ERROR_KICKED);
841
4874b9ce2765 (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
  1265
}
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1266
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1267
static void ClientList_GiveMoney(byte client_no)
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1268
{
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1269
	if (NetworkFindClientInfo(client_no) != NULL)
4878
4d4f76a898fd (svn r6814) -Codechange: For network games ci->client_playas was always p->index + 1. To
Darkvater
parents: 4861
diff changeset
  1270
		ShowNetworkGiveMoneyWindow(NetworkFindClientInfo(client_no)->client_playas);
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1271
}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1272
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1273
static void ClientList_SpeakToClient(byte client_no)
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1274
{
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1275
	if (NetworkFindClientInfo(client_no) != NULL)
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1276
		ShowNetworkChatQueryWindow(DESTTYPE_CLIENT, NetworkFindClientInfo(client_no)->client_index);
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1277
}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1278
4906
935e6280c093 (svn r6876) -Codechange: Change the naming of _PLAYER in DESTTYPE_PLAYER/NETWORK_ACTION_CHAT_PLAYER
Darkvater
parents: 4895
diff changeset
  1279
static void ClientList_SpeakToCompany(byte client_no)
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1280
{
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1281
	if (NetworkFindClientInfo(client_no) != NULL)
4906
935e6280c093 (svn r6876) -Codechange: Change the naming of _PLAYER in DESTTYPE_PLAYER/NETWORK_ACTION_CHAT_PLAYER
Darkvater
parents: 4895
diff changeset
  1282
		ShowNetworkChatQueryWindow(DESTTYPE_TEAM, NetworkFindClientInfo(client_no)->client_playas);
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1283
}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1284
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1285
static void ClientList_SpeakToAll(byte client_no)
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1286
{
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1287
	ShowNetworkChatQueryWindow(DESTTYPE_BROADCAST, 0);
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1288
}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1289
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1290
static void ClientList_None(byte client_no)
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1291
{
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1292
	// No action ;)
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1293
}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1294
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1295
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1296
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1297
// Help, a action is clicked! What do we do?
7321
f91bdca345e8 (svn r10684) -Codechange: some more coding style related changes. Primarily moving { to a new line.
rubidium
parents: 7221
diff changeset
  1298
static void HandleClientListPopupClick(byte index, byte clientno)
f91bdca345e8 (svn r10684) -Codechange: some more coding style related changes. Primarily moving { to a new line.
rubidium
parents: 7221
diff changeset
  1299
{
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1300
	// A click on the Popup of the ClientList.. handle the command
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1301
	if (index < MAX_CLIENTLIST_ACTION && _clientlist_proc[index] != NULL) {
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1302
		_clientlist_proc[index](clientno);
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1303
	}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1304
}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1305
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1306
// Finds the amount of clients and set the height correct
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1307
static bool CheckClientListHeight(Window *w)
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1308
{
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1309
	int num = 0;
4883
c9c7d15c0b0b (svn r6820) -Codechange: Some more const correctness, coding style.
Darkvater
parents: 4880
diff changeset
  1310
	const NetworkClientInfo *ci;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1311
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1312
	// Should be replaced with a loop through all clients
4883
c9c7d15c0b0b (svn r6820) -Codechange: Some more const correctness, coding style.
Darkvater
parents: 4880
diff changeset
  1313
	FOR_ALL_ACTIVE_CLIENT_INFOS(ci) {
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1314
		num++;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1315
	}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1316
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1317
	num *= CLNWND_ROWSIZE;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1318
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1319
	// If height is changed
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
  1320
	if (w->height != CLNWND_OFFSET + num + 1) {
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1321
		// XXX - magic unfortunately; (num + 2) has to be one bigger than heigh (num + 1)
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
  1322
		SetWindowDirty(w);
7029
7b84f0befa90 (svn r10293) -Add [FS#885]: a sticky button for the client list window (oxygene)
truelight
parents: 7002
diff changeset
  1323
		w->widget[3].bottom = w->widget[3].top + num + 2;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
  1324
		w->height = CLNWND_OFFSET + num + 1;
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
  1325
		SetWindowDirty(w);
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1326
		return false;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1327
	}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1328
	return true;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1329
}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1330
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1331
// Finds the amount of actions in the popup and set the height correct
7321
f91bdca345e8 (svn r10684) -Codechange: some more coding style related changes. Primarily moving { to a new line.
rubidium
parents: 7221
diff changeset
  1332
static uint ClientListPopupHeight()
f91bdca345e8 (svn r10684) -Codechange: some more coding style related changes. Primarily moving { to a new line.
rubidium
parents: 7221
diff changeset
  1333
{
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1334
	int i, num = 0;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1335
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1336
	// Find the amount of actions
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1337
	for (i = 0; i < MAX_CLIENTLIST_ACTION; i++) {
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1338
		if (_clientlist_action[i][0] == '\0') continue;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1339
		if (_clientlist_proc[i] == NULL) continue;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1340
		num++;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1341
	}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1342
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1343
	num *= CLNWND_ROWSIZE;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
  1344
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
  1345
	return num + 1;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1346
}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1347
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1348
// Show the popup (action list)
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1349
static Window *PopupClientList(Window *w, int client_no, int x, int y)
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1350
{
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
  1351
	int i, h;
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
  1352
	const NetworkClientInfo *ci;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1353
	DeleteWindowById(WC_TOOLBAR_MENU, 0);
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1354
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1355
	// Clean the current actions
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1356
	for (i = 0; i < MAX_CLIENTLIST_ACTION; i++) {
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1357
		_clientlist_action[i][0] = '\0';
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1358
		_clientlist_proc[i] = NULL;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1359
	}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1360
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1361
	// Fill the actions this client has
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1362
	// Watch is, max 50 chars long!
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1363
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1364
	ci = NetworkFindClientInfo(client_no);
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1365
	if (ci == NULL) return NULL;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1366
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1367
	i = 0;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1368
	if (_network_own_client_index != ci->client_index) {
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4909
diff changeset
  1369
		GetString(_clientlist_action[i], STR_NETWORK_CLIENTLIST_SPEAK_TO_CLIENT, lastof(_clientlist_action[i]));
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1370
		_clientlist_proc[i++] = &ClientList_SpeakToClient;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1371
	}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1372
4945
d20e68851e70 (svn r6933) -Feature: Allow spectators to speak to eachother (team)
Darkvater
parents: 4943
diff changeset
  1373
	if (IsValidPlayer(ci->client_playas) || ci->client_playas == PLAYER_SPECTATOR) {
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4909
diff changeset
  1374
		GetString(_clientlist_action[i], STR_NETWORK_CLIENTLIST_SPEAK_TO_COMPANY, lastof(_clientlist_action[i]));
4906
935e6280c093 (svn r6876) -Codechange: Change the naming of _PLAYER in DESTTYPE_PLAYER/NETWORK_ACTION_CHAT_PLAYER
Darkvater
parents: 4895
diff changeset
  1375
		_clientlist_proc[i++] = &ClientList_SpeakToCompany;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1376
	}
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4909
diff changeset
  1377
	GetString(_clientlist_action[i], STR_NETWORK_CLIENTLIST_SPEAK_TO_ALL, lastof(_clientlist_action[i]));
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1378
	_clientlist_proc[i++] = &ClientList_SpeakToAll;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1379
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1380
	if (_network_own_client_index != ci->client_index) {
7657
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7441
diff changeset
  1381
		/* We are no spectator and the player we want to give money to is no spectator and money gifts are allowed */
2b55af55cc51 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents: 7441
diff changeset
  1382
		if (IsValidPlayer(_network_playas) && IsValidPlayer(ci->client_playas) && _patches.give_money) {
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4909
diff changeset
  1383
			GetString(_clientlist_action[i], STR_NETWORK_CLIENTLIST_GIVE_MONEY, lastof(_clientlist_action[i]));
4878
4d4f76a898fd (svn r6814) -Codechange: For network games ci->client_playas was always p->index + 1. To
Darkvater
parents: 4861
diff changeset
  1384
			_clientlist_proc[i++] = &ClientList_GiveMoney;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1385
		}
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1386
	}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1387
4880
aac84a9dcd03 (svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents: 4878
diff changeset
  1388
	// A server can kick clients (but not himself)
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1389
	if (_network_server && _network_own_client_index != ci->client_index) {
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4909
diff changeset
  1390
		GetString(_clientlist_action[i], STR_NETWORK_CLIENTLIST_KICK, lastof(_clientlist_action[i]));
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1391
		_clientlist_proc[i++] = &ClientList_Kick;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1392
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4909
diff changeset
  1393
		sprintf(_clientlist_action[i],"Ban"); // XXX GetString?
841
4874b9ce2765 (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 827
diff changeset
  1394
		_clientlist_proc[i++] = &ClientList_Ban;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1395
	}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1396
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1397
	if (i == 0) {
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4909
diff changeset
  1398
		GetString(_clientlist_action[i], STR_NETWORK_CLIENTLIST_NONE, lastof(_clientlist_action[i]));
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1399
		_clientlist_proc[i++] = &ClientList_None;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1400
	}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1401
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
  1402
	/* Calculate the height */
7321
f91bdca345e8 (svn r10684) -Codechange: some more coding style related changes. Primarily moving { to a new line.
rubidium
parents: 7221
diff changeset
  1403
	h = ClientListPopupHeight();
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1404
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1405
	// Allocate the popup
3250
4d19bcd78d22 (svn r3933) - [ 1439907 ] Increase client list window width so at least most languages fit (wikipedian).
Darkvater
parents: 2952
diff changeset
  1406
	w = AllocateWindow(x, y, 150, h + 1, ClientListPopupWndProc, WC_TOOLBAR_MENU, _client_list_popup_widgets);
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
  1407
	w->widget[0].bottom = w->widget[0].top + h;
3250
4d19bcd78d22 (svn r3933) - [ 1439907 ] Increase client list window width so at least most languages fit (wikipedian).
Darkvater
parents: 2952
diff changeset
  1408
	w->widget[0].right = w->widget[0].left + 150;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
  1409
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1410
	w->flags4 &= ~WF_WHITE_BORDER_MASK;
8082
63240e1bd6cc (svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents: 8069
diff changeset
  1411
	WP(w, menu_d).item_count = 0;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1412
	// Save our client
8082
63240e1bd6cc (svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents: 8069
diff changeset
  1413
	WP(w, menu_d).main_button = client_no;
63240e1bd6cc (svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents: 8069
diff changeset
  1414
	WP(w, menu_d).sel_index = 0;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1415
	// We are a popup
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1416
	_popup_menu_active = true;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1417
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1418
	return w;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1419
}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1420
2887
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
  1421
/** Main handle for the client popup list
810e555d5249 (svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents: 2886
diff changeset
  1422
 * uses menu_d WP macro */
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1423
static void ClientListPopupWndProc(Window *w, WindowEvent *e)
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1424
{
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1425
	switch (e->event) {
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1426
	case WE_PAINT: {
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1427
		int i, y, sel;
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
  1428
		TextColour colour;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1429
		DrawWindowWidgets(w);
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1430
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1431
		// Draw the actions
8082
63240e1bd6cc (svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents: 8069
diff changeset
  1432
		sel = WP(w, menu_d).sel_index;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1433
		y = 1;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1434
		for (i = 0; i < MAX_CLIENTLIST_ACTION; i++, y += CLNWND_ROWSIZE) {
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1435
			if (_clientlist_action[i][0] == '\0') continue;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1436
			if (_clientlist_proc[i] == NULL) continue;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1437
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1438
			if (sel-- == 0) { // Selected item, highlight it
3250
4d19bcd78d22 (svn r3933) - [ 1439907 ] Increase client list window width so at least most languages fit (wikipedian).
Darkvater
parents: 2952
diff changeset
  1439
				GfxFillRect(1, y, 150 - 2, y + CLNWND_ROWSIZE - 1, 0);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
  1440
				colour = TC_WHITE;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4013
diff changeset
  1441
			} else {
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
  1442
				colour = TC_BLACK;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4013
diff changeset
  1443
			}
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1444
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1445
			DoDrawString(_clientlist_action[i], 4, y, colour);
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1446
		}
6492
286a52449b54 (svn r9673) -Cleanup: remove spaces before tabs and replace non-indenting tabs with spaces.
rubidium
parents: 6491
diff changeset
  1447
	} break;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1448
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1449
	case WE_POPUPMENU_SELECT: {
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1450
		// We selected an action
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
  1451
		int index = (e->we.popupmenu.pt.y - w->top) / CLNWND_ROWSIZE;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1452
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
  1453
		if (index >= 0 && e->we.popupmenu.pt.y >= w->top)
8082
63240e1bd6cc (svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents: 8069
diff changeset
  1454
			HandleClientListPopupClick(index, WP(w, menu_d).main_button);
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1455
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1456
		DeleteWindowById(WC_TOOLBAR_MENU, 0);
6492
286a52449b54 (svn r9673) -Cleanup: remove spaces before tabs and replace non-indenting tabs with spaces.
rubidium
parents: 6491
diff changeset
  1457
	} break;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1458
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1459
	case WE_POPUPMENU_OVER: {
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1460
		// Our mouse hoovers over an action? Select it!
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
  1461
		int index = (e->we.popupmenu.pt.y - w->top) / CLNWND_ROWSIZE;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1462
8082
63240e1bd6cc (svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents: 8069
diff changeset
  1463
		if (index == -1 || index == WP(w, menu_d).sel_index) return;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1464
8082
63240e1bd6cc (svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents: 8069
diff changeset
  1465
		WP(w, menu_d).sel_index = index;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1466
		SetWindowDirty(w);
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1467
	} break;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1468
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1469
	}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1470
}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1471
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1472
// Main handle for clientlist
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1473
static void ClientListWndProc(Window *w, WindowEvent *e)
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1474
{
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1475
	switch (e->event) {
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1476
	case WE_PAINT: {
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1477
		NetworkClientInfo *ci;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1478
		int y, i = 0;
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
  1479
		TextColour colour;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1480
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1481
		// Check if we need to reset the height
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1482
		if (!CheckClientListHeight(w)) break;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1483
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1484
		DrawWindowWidgets(w);
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1485
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1486
		y = CLNWND_OFFSET;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1487
4883
c9c7d15c0b0b (svn r6820) -Codechange: Some more const correctness, coding style.
Darkvater
parents: 4880
diff changeset
  1488
		FOR_ALL_ACTIVE_CLIENT_INFOS(ci) {
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1489
			if (_selected_clientlist_item == i++) { // Selected item, highlight it
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1490
				GfxFillRect(1, y, 248, y + CLNWND_ROWSIZE - 1, 0);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
  1491
				colour = TC_WHITE;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4013
diff changeset
  1492
			} else {
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
  1493
				colour = TC_BLACK;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4013
diff changeset
  1494
			}
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1495
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1496
			if (ci->client_index == NETWORK_SERVER_INDEX) {
722
f420fa9bd521 (svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents: 716
diff changeset
  1497
				DrawString(4, y, STR_NETWORK_SERVER, colour);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1498
			} else {
722
f420fa9bd521 (svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents: 716
diff changeset
  1499
				DrawString(4, y, STR_NETWORK_CLIENT, colour);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1500
			}
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1501
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1502
			// Filter out spectators
4878
4d4f76a898fd (svn r6814) -Codechange: For network games ci->client_playas was always p->index + 1. To
Darkvater
parents: 4861
diff changeset
  1503
			if (IsValidPlayer(ci->client_playas)) DrawPlayerIcon(ci->client_playas, 64, y + 1);
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1504
3250
4d19bcd78d22 (svn r3933) - [ 1439907 ] Increase client list window width so at least most languages fit (wikipedian).
Darkvater
parents: 2952
diff changeset
  1505
			DoDrawString(ci->client_name, 81, y, colour);
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1506
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1507
			y += CLNWND_ROWSIZE;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1508
		}
6492
286a52449b54 (svn r9673) -Cleanup: remove spaces before tabs and replace non-indenting tabs with spaces.
rubidium
parents: 6491
diff changeset
  1509
	} break;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1510
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1511
	case WE_CLICK:
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1512
		// Show the popup with option
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1513
		if (_selected_clientlist_item != 255) {
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
  1514
			PopupClientList(w, _selected_clientlist_item, e->we.click.pt.x + w->left, e->we.click.pt.y + w->top);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1515
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
  1516
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1517
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1518
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1519
	case WE_MOUSEOVER:
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1520
		// -1 means we left the current window
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
  1521
		if (e->we.mouseover.pt.y == -1) {
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1522
			_selected_clientlist_y = 0;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1523
			_selected_clientlist_item = 255;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1524
			SetWindowDirty(w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1525
			break;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1526
		}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1527
		// It did not change.. no update!
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
  1528
		if (e->we.mouseover.pt.y == _selected_clientlist_y) break;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1529
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1530
		// Find the new selected item (if any)
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
  1531
		_selected_clientlist_y = e->we.mouseover.pt.y;
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
  1532
		if (e->we.mouseover.pt.y > CLNWND_OFFSET) {
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
  1533
			_selected_clientlist_item = (e->we.mouseover.pt.y - CLNWND_OFFSET) / CLNWND_ROWSIZE;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4013
diff changeset
  1534
		} else {
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1535
			_selected_clientlist_item = 255;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4013
diff changeset
  1536
		}
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1537
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1538
		// Repaint
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1539
		SetWindowDirty(w);
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1540
		break;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1541
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1542
	case WE_DESTROY: case WE_CREATE:
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1543
		// When created or destroyed, data is reset
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1544
		_selected_clientlist_item = 255;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1545
		_selected_clientlist_y = 0;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1546
		break;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1547
	}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1548
}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1549
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 5916
diff changeset
  1550
void ShowClientList()
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1551
{
4491
7b74fd94004d (svn r6276) Remove a redundant assignment
tron
parents: 4416
diff changeset
  1552
	AllocateWindowDescFront(&_client_list_desc, 0);
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1553
}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1554
4512
823dfd4aa413 (svn r6297) -Codechange: Disentangle the query window mess a bit: Move the network game password handling somewhere were it belongs to
tron
parents: 4491
diff changeset
  1555
823dfd4aa413 (svn r6297) -Codechange: Disentangle the query window mess a bit: Move the network game password handling somewhere were it belongs to
tron
parents: 4491
diff changeset
  1556
static NetworkPasswordType pw_type;
823dfd4aa413 (svn r6297) -Codechange: Disentangle the query window mess a bit: Move the network game password handling somewhere were it belongs to
tron
parents: 4491
diff changeset
  1557
823dfd4aa413 (svn r6297) -Codechange: Disentangle the query window mess a bit: Move the network game password handling somewhere were it belongs to
tron
parents: 4491
diff changeset
  1558
823dfd4aa413 (svn r6297) -Codechange: Disentangle the query window mess a bit: Move the network game password handling somewhere were it belongs to
tron
parents: 4491
diff changeset
  1559
void ShowNetworkNeedPassword(NetworkPasswordType npt)
823dfd4aa413 (svn r6297) -Codechange: Disentangle the query window mess a bit: Move the network game password handling somewhere were it belongs to
tron
parents: 4491
diff changeset
  1560
{
823dfd4aa413 (svn r6297) -Codechange: Disentangle the query window mess a bit: Move the network game password handling somewhere were it belongs to
tron
parents: 4491
diff changeset
  1561
	StringID caption;
823dfd4aa413 (svn r6297) -Codechange: Disentangle the query window mess a bit: Move the network game password handling somewhere were it belongs to
tron
parents: 4491
diff changeset
  1562
823dfd4aa413 (svn r6297) -Codechange: Disentangle the query window mess a bit: Move the network game password handling somewhere were it belongs to
tron
parents: 4491
diff changeset
  1563
	pw_type = npt;
823dfd4aa413 (svn r6297) -Codechange: Disentangle the query window mess a bit: Move the network game password handling somewhere were it belongs to
tron
parents: 4491
diff changeset
  1564
	switch (npt) {
823dfd4aa413 (svn r6297) -Codechange: Disentangle the query window mess a bit: Move the network game password handling somewhere were it belongs to
tron
parents: 4491
diff changeset
  1565
		default: NOT_REACHED();
4774
f93b1f0a9cf3 (svn r6688) -Fix (r6297): Wrong caption for server password query window (eg put 'break' after switch statements)
Darkvater
parents: 4719
diff changeset
  1566
		case NETWORK_GAME_PASSWORD:    caption = STR_NETWORK_NEED_GAME_PASSWORD_CAPTION; break;
f93b1f0a9cf3 (svn r6688) -Fix (r6297): Wrong caption for server password query window (eg put 'break' after switch statements)
Darkvater
parents: 4719
diff changeset
  1567
		case NETWORK_COMPANY_PASSWORD: caption = STR_NETWORK_NEED_COMPANY_PASSWORD_CAPTION; break;
4512
823dfd4aa413 (svn r6297) -Codechange: Disentangle the query window mess a bit: Move the network game password handling somewhere were it belongs to
tron
parents: 4491
diff changeset
  1568
	}
5431
6e56b4f13dd7 (svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents: 5352
diff changeset
  1569
	ShowQueryString(STR_EMPTY, caption, 20, 180, FindWindowById(WC_NETWORK_STATUS_WINDOW, 0), CS_ALPHANUMERAL);
4512
823dfd4aa413 (svn r6297) -Codechange: Disentangle the query window mess a bit: Move the network game password handling somewhere were it belongs to
tron
parents: 4491
diff changeset
  1570
}
823dfd4aa413 (svn r6297) -Codechange: Disentangle the query window mess a bit: Move the network game password handling somewhere were it belongs to
tron
parents: 4491
diff changeset
  1571
823dfd4aa413 (svn r6297) -Codechange: Disentangle the query window mess a bit: Move the network game password handling somewhere were it belongs to
tron
parents: 4491
diff changeset
  1572
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1573
static void NetworkJoinStatusWindowWndProc(Window *w, WindowEvent *e)
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1574
{
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1575
	switch (e->event) {
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1576
	case WE_PAINT: {
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1577
		uint8 progress; // used for progress bar
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1578
		DrawWindowWidgets(w);
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1579
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
  1580
		DrawStringCentered(125, 35, STR_NETWORK_CONNECTING_1 + _network_join_status, TC_GREY);
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1581
		switch (_network_join_status) {
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1582
			case NETWORK_JOIN_STATUS_CONNECTING: case NETWORK_JOIN_STATUS_AUTHORIZING:
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1583
			case NETWORK_JOIN_STATUS_GETTING_COMPANY_INFO:
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1584
				progress = 10; // first two stages 10%
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1585
				break;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1586
			case NETWORK_JOIN_STATUS_WAITING:
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1587
				SetDParam(0, _network_join_waiting);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
  1588
				DrawStringCentered(125, 46, STR_NETWORK_CONNECTING_WAITING, TC_GREY);
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1589
				progress = 15; // third stage is 15%
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1590
				break;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1591
			case NETWORK_JOIN_STATUS_DOWNLOADING:
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1592
				SetDParam(0, _network_join_kbytes);
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1593
				SetDParam(1, _network_join_kbytes_total);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7657
diff changeset
  1594
				DrawStringCentered(125, 46, STR_NETWORK_CONNECTING_DOWNLOADING, TC_GREY);
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1595
				/* Fallthrough */
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1596
			default: /* Waiting is 15%, so the resting receivement of map is maximum 70% */
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1597
				progress = 15 + _network_join_kbytes * (100 - 15) / _network_join_kbytes_total;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1598
		}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1599
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1600
		/* Draw nice progress bar :) */
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  1601
		DrawFrameRect(20, 18, (int)((w->width - 20) * progress / 100), 28, 10, FR_NONE);
6492
286a52449b54 (svn r9673) -Cleanup: remove spaces before tabs and replace non-indenting tabs with spaces.
rubidium
parents: 6491
diff changeset
  1602
	} break;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1603
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1604
	case WE_CLICK:
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
  1605
		switch (e->we.click.widget) {
5432
5940d6a253c5 (svn r7638) -Codechange: Remove special window ShowJoinStatusWindowAfterJoin and shuffle around
Darkvater
parents: 5431
diff changeset
  1606
			case 2: /* Disconnect button */
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1607
				NetworkDisconnect();
5431
6e56b4f13dd7 (svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents: 5352
diff changeset
  1608
				DeleteWindow(w);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1609
				SwitchMode(SM_MENU);
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1610
				ShowNetworkGameWindow();
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2630
diff changeset
  1611
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1612
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1613
		break;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
  1614
5431
6e56b4f13dd7 (svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents: 5352
diff changeset
  1615
		/* If the server asks for a password, we need to fill it in */
4512
823dfd4aa413 (svn r6297) -Codechange: Disentangle the query window mess a bit: Move the network game password handling somewhere were it belongs to
tron
parents: 4491
diff changeset
  1616
		case WE_ON_EDIT_TEXT_CANCEL:
823dfd4aa413 (svn r6297) -Codechange: Disentangle the query window mess a bit: Move the network game password handling somewhere were it belongs to
tron
parents: 4491
diff changeset
  1617
			NetworkDisconnect();
823dfd4aa413 (svn r6297) -Codechange: Disentangle the query window mess a bit: Move the network game password handling somewhere were it belongs to
tron
parents: 4491
diff changeset
  1618
			ShowNetworkGameWindow();
823dfd4aa413 (svn r6297) -Codechange: Disentangle the query window mess a bit: Move the network game password handling somewhere were it belongs to
tron
parents: 4491
diff changeset
  1619
			break;
823dfd4aa413 (svn r6297) -Codechange: Disentangle the query window mess a bit: Move the network game password handling somewhere were it belongs to
tron
parents: 4491
diff changeset
  1620
823dfd4aa413 (svn r6297) -Codechange: Disentangle the query window mess a bit: Move the network game password handling somewhere were it belongs to
tron
parents: 4491
diff changeset
  1621
		case WE_ON_EDIT_TEXT:
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
  1622
			SEND_COMMAND(PACKET_CLIENT_PASSWORD)(pw_type, e->we.edittext.str);
4512
823dfd4aa413 (svn r6297) -Codechange: Disentangle the query window mess a bit: Move the network game password handling somewhere were it belongs to
tron
parents: 4491
diff changeset
  1623
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1624
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1625
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1626
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1627
static const Widget _network_join_status_window_widget[] = {
5432
5940d6a253c5 (svn r7638) -Codechange: Remove special window ShowJoinStatusWindowAfterJoin and shuffle around
Darkvater
parents: 5431
diff changeset
  1628
{    WWT_CAPTION,   RESIZE_NONE,    14,     0,   249,     0,    13, STR_NETWORK_CONNECTING, STR_018C_WINDOW_TITLE_DRAG_THIS},
4938
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1629
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   249,    14,    84, 0x0,                    STR_NULL},
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 853
diff changeset
  1630
{ 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
  1631
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1632
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1633
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1634
static const WindowDesc _network_join_status_window_desc = {
7341
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7321
diff changeset
  1635
	WDP_CENTER, WDP_CENTER, 250, 85, 250, 85,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5669
diff changeset
  1636
	WC_NETWORK_STATUS_WINDOW, WC_NONE,
5432
5940d6a253c5 (svn r7638) -Codechange: Remove special window ShowJoinStatusWindowAfterJoin and shuffle around
Darkvater
parents: 5431
diff changeset
  1637
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_MODAL,
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1638
	_network_join_status_window_widget,
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1639
	NetworkJoinStatusWindowWndProc,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1640
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1641
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 5916
diff changeset
  1642
void ShowJoinStatusWindow()
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1643
{
5432
5940d6a253c5 (svn r7638) -Codechange: Remove special window ShowJoinStatusWindowAfterJoin and shuffle around
Darkvater
parents: 5431
diff changeset
  1644
	Window *w;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1645
	DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
5432
5940d6a253c5 (svn r7638) -Codechange: Remove special window ShowJoinStatusWindowAfterJoin and shuffle around
Darkvater
parents: 5431
diff changeset
  1646
	w = AllocateWindowDesc(&_network_join_status_window_desc);
5940d6a253c5 (svn r7638) -Codechange: Remove special window ShowJoinStatusWindowAfterJoin and shuffle around
Darkvater
parents: 5431
diff changeset
  1647
	/* Parent the status window to the lobby */
5940d6a253c5 (svn r7638) -Codechange: Remove special window ShowJoinStatusWindowAfterJoin and shuffle around
Darkvater
parents: 5431
diff changeset
  1648
	if (w != NULL) w->parent = FindWindowById(WC_NETWORK_WINDOW, 0);
670
d164965bb35a (svn r1108) -Fix: [Network] Fixed problem around slow clients:
truelight
parents: 659
diff changeset
  1649
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1650
6531
4445b25832c4 (svn r9719) -Fix: in-game private messages did not work for clients with a Client ID > 255.
rubidium
parents: 6492
diff changeset
  1651
static void SendChat(const char *buf, DestType type, int dest)
4013
53a7dd9a1fbf (svn r5226) Reduce the mess that sending chat messages is
tron
parents: 3860
diff changeset
  1652
{
7321
f91bdca345e8 (svn r10684) -Codechange: some more coding style related changes. Primarily moving { to a new line.
rubidium
parents: 7221
diff changeset
  1653
	if (StrEmpty(buf)) return;
4013
53a7dd9a1fbf (svn r5226) Reduce the mess that sending chat messages is
tron
parents: 3860
diff changeset
  1654
	if (!_network_server) {
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  1655
		SEND_COMMAND(PACKET_CLIENT_CHAT)((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf);
4013
53a7dd9a1fbf (svn r5226) Reduce the mess that sending chat messages is
tron
parents: 3860
diff changeset
  1656
	} else {
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  1657
		NetworkServer_HandleChat((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf, NETWORK_SERVER_INDEX);
4013
53a7dd9a1fbf (svn r5226) Reduce the mess that sending chat messages is
tron
parents: 3860
diff changeset
  1658
	}
53a7dd9a1fbf (svn r5226) Reduce the mess that sending chat messages is
tron
parents: 3860
diff changeset
  1659
}
53a7dd9a1fbf (svn r5226) Reduce the mess that sending chat messages is
tron
parents: 3860
diff changeset
  1660
4315
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1661
/**
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1662
 * Find the next item of the list of things that can be auto-completed.
4319
b4c237cf69c1 (svn r5972) -Fix: usr strrchr instead of your own function (tnx Darkvater)
truelight
parents: 4315
diff changeset
  1663
 * @param item The current indexed item to return. This function can, and most
b4c237cf69c1 (svn r5972) -Fix: usr strrchr instead of your own function (tnx Darkvater)
truelight
parents: 4315
diff changeset
  1664
 *     likely will, alter item, to skip empty items in the arrays.
b4c237cf69c1 (svn r5972) -Fix: usr strrchr instead of your own function (tnx Darkvater)
truelight
parents: 4315
diff changeset
  1665
 * @return Returns the char that matched to the index.
4315
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1666
 */
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1667
static const char *ChatTabCompletionNextItem(uint *item)
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1668
{
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1669
	static char chat_tab_temp_buffer[64];
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1670
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1671
	/* First, try clients */
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1672
	if (*item < MAX_CLIENT_INFO) {
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1673
		/* Skip inactive clients */
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1674
		while (_network_client_info[*item].client_index == NETWORK_EMPTY_INDEX && *item < MAX_CLIENT_INFO) (*item)++;
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1675
		if (*item < MAX_CLIENT_INFO) return _network_client_info[*item].client_name;
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1676
	}
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1677
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1678
	/* Then, try townnames */
5247
1f982de55b88 (svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents: 5125
diff changeset
  1679
	/* Not that the following assumes all town indices are adjacent, ie no
1f982de55b88 (svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents: 5125
diff changeset
  1680
	 * towns have been deleted. */
1f982de55b88 (svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents: 5125
diff changeset
  1681
	if (*item <= (uint)MAX_CLIENT_INFO + GetMaxTownIndex()) {
4319
b4c237cf69c1 (svn r5972) -Fix: usr strrchr instead of your own function (tnx Darkvater)
truelight
parents: 4315
diff changeset
  1682
		const Town *t;
4315
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1683
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1684
		FOR_ALL_TOWNS_FROM(t, *item - MAX_CLIENT_INFO) {
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1685
			/* Get the town-name via the string-system */
6956
3579bfc5157b (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 6798
diff changeset
  1686
			SetDParam(0, t->index);
3579bfc5157b (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 6798
diff changeset
  1687
			GetString(chat_tab_temp_buffer, STR_TOWN, lastof(chat_tab_temp_buffer));
4315
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1688
			return &chat_tab_temp_buffer[0];
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1689
		}
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1690
	}
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1691
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1692
	return NULL;
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1693
}
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1694
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1695
/**
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1696
 * Find what text to complete. It scans for a space from the left and marks
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1697
 *  the word right from that as to complete. It also writes a \0 at the
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1698
 *  position of the space (if any). If nothing found, buf is returned.
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1699
 */
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1700
static char *ChatTabCompletionFindText(char *buf)
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1701
{
4880
aac84a9dcd03 (svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents: 4878
diff changeset
  1702
	char *p = strrchr(buf, ' ');
4319
b4c237cf69c1 (svn r5972) -Fix: usr strrchr instead of your own function (tnx Darkvater)
truelight
parents: 4315
diff changeset
  1703
	if (p == NULL) return buf;
4315
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1704
4319
b4c237cf69c1 (svn r5972) -Fix: usr strrchr instead of your own function (tnx Darkvater)
truelight
parents: 4315
diff changeset
  1705
	*p = '\0';
b4c237cf69c1 (svn r5972) -Fix: usr strrchr instead of your own function (tnx Darkvater)
truelight
parents: 4315
diff changeset
  1706
	return p + 1;
4315
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1707
}
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1708
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1709
/**
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1710
 * See if we can auto-complete the current text of the user.
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1711
 */
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1712
static void ChatTabCompletion(Window *w)
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1713
{
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1714
	static char _chat_tab_completion_buf[lengthof(_edit_str_buf)];
6531
4445b25832c4 (svn r9719) -Fix: in-game private messages did not work for clients with a Client ID > 255.
rubidium
parents: 6492
diff changeset
  1715
	Textbuf *tb = &WP(w, chatquerystr_d).text;
4315
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1716
	uint len, tb_len;
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1717
	uint item;
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1718
	char *tb_buf, *pre_buf;
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1719
	const char *cur_name;
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1720
	bool second_scan = false;
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1721
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1722
	item = 0;
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1723
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1724
	/* Copy the buffer so we can modify it without damaging the real data */
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1725
	pre_buf = (_chat_tab_completion_active) ? strdup(_chat_tab_completion_buf) : strdup(tb->buf);
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1726
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1727
	tb_buf  = ChatTabCompletionFindText(pre_buf);
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1728
	tb_len  = strlen(tb_buf);
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1729
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1730
	while ((cur_name = ChatTabCompletionNextItem(&item)) != NULL) {
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1731
		item++;
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1732
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1733
		if (_chat_tab_completion_active) {
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1734
			/* We are pressing TAB again on the same name, is there an other name
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1735
			 *  that starts with this? */
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1736
			if (!second_scan) {
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1737
				uint offset;
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1738
				uint length;
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1739
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1740
				/* If we are completing at the begin of the line, skip the ': ' we added */
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1741
				if (tb_buf == pre_buf) {
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1742
					offset = 0;
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1743
					length = tb->length - 2;
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1744
				} else {
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1745
					/* Else, find the place we are completing at */
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1746
					offset = strlen(pre_buf) + 1;
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1747
					length = tb->length - offset;
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1748
				}
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1749
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1750
				/* Compare if we have a match */
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1751
				if (strlen(cur_name) == length && strncmp(cur_name, tb->buf + offset, length) == 0) second_scan = true;
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1752
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1753
				continue;
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1754
			}
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1755
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1756
			/* Now any match we make on _chat_tab_completion_buf after this, is perfect */
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1757
		}
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1758
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1759
		len = strlen(cur_name);
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1760
		if (tb_len < len && strncasecmp(cur_name, tb_buf, tb_len) == 0) {
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1761
			/* Save the data it was before completion */
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1762
			if (!second_scan) snprintf(_chat_tab_completion_buf, lengthof(_chat_tab_completion_buf), "%s", tb->buf);
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1763
			_chat_tab_completion_active = true;
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1764
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1765
			/* Change to the found name. Add ': ' if we are at the start of the line (pretty) */
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1766
			if (pre_buf == tb_buf) {
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1767
				snprintf(tb->buf, lengthof(_edit_str_buf), "%s: ", cur_name);
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1768
			} else {
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1769
				snprintf(tb->buf, lengthof(_edit_str_buf), "%s %s", pre_buf, cur_name);
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1770
			}
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1771
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1772
			/* Update the textbuffer */
6531
4445b25832c4 (svn r9719) -Fix: in-game private messages did not work for clients with a Client ID > 255.
rubidium
parents: 6492
diff changeset
  1773
			UpdateTextBufferSize(&WP(w, chatquerystr_d).text);
4315
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1774
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1775
			SetWindowDirty(w);
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1776
			free(pre_buf);
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1777
			return;
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1778
		}
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1779
	}
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1780
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1781
	if (second_scan) {
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1782
		/* We walked all posibilities, and the user presses tab again.. revert to original text */
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1783
		strcpy(tb->buf, _chat_tab_completion_buf);
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1784
		_chat_tab_completion_active = false;
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1785
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1786
		/* Update the textbuffer */
6531
4445b25832c4 (svn r9719) -Fix: in-game private messages did not work for clients with a Client ID > 255.
rubidium
parents: 6492
diff changeset
  1787
		UpdateTextBufferSize(&WP(w, chatquerystr_d).text);
4315
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1788
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1789
		SetWindowDirty(w);
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1790
	}
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1791
	free(pre_buf);
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1792
}
4013
53a7dd9a1fbf (svn r5226) Reduce the mess that sending chat messages is
tron
parents: 3860
diff changeset
  1793
6531
4445b25832c4 (svn r9719) -Fix: in-game private messages did not work for clients with a Client ID > 255.
rubidium
parents: 6492
diff changeset
  1794
/*
4445b25832c4 (svn r9719) -Fix: in-game private messages did not work for clients with a Client ID > 255.
rubidium
parents: 6492
diff changeset
  1795
 * uses chatquerystr_d WP macro
4445b25832c4 (svn r9719) -Fix: in-game private messages did not work for clients with a Client ID > 255.
rubidium
parents: 6492
diff changeset
  1796
 * uses chatquerystr_d->caption to store type of chat message (Private/Team/All)
4445b25832c4 (svn r9719) -Fix: in-game private messages did not work for clients with a Client ID > 255.
rubidium
parents: 6492
diff changeset
  1797
 */
649
bc9bdefb76ec (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1798
static void ChatWindowWndProc(Window *w, WindowEvent *e)
bc9bdefb76ec (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1799
{
1648
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1390
diff changeset
  1800
	switch (e->event) {
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1390
diff changeset
  1801
	case WE_CREATE:
8069
59a0fe1af11a (svn r11630) -Fix [FS#1544] (r11556): the chat GUI got broken.
rubidium
parents: 8040
diff changeset
  1802
		SendWindowMessage(WC_NEWS_WINDOW, 0, WE_CREATE, w->height, 0);
59a0fe1af11a (svn r11630) -Fix [FS#1544] (r11556): the chat GUI got broken.
rubidium
parents: 8040
diff changeset
  1803
		SetBit(_no_scroll, SCROLL_CHAT); // do not scroll the game with the arrow-keys
1648
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1390
diff changeset
  1804
		break;
649
bc9bdefb76ec (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1805
4887
71da70810c22 (svn r6824) -Feature: Change the functionality of the chat window. SHIFT+ENTER (SHIFT+T)
Darkvater
parents: 4883
diff changeset
  1806
	case WE_PAINT: {
8069
59a0fe1af11a (svn r11630) -Fix [FS#1544] (r11556): the chat GUI got broken.
rubidium
parents: 8040
diff changeset
  1807
		static const StringID chat_captions[] = {
59a0fe1af11a (svn r11630) -Fix [FS#1544] (r11556): the chat GUI got broken.
rubidium
parents: 8040
diff changeset
  1808
			STR_NETWORK_CHAT_ALL_CAPTION,
59a0fe1af11a (svn r11630) -Fix [FS#1544] (r11556): the chat GUI got broken.
rubidium
parents: 8040
diff changeset
  1809
			STR_NETWORK_CHAT_COMPANY_CAPTION,
59a0fe1af11a (svn r11630) -Fix [FS#1544] (r11556): the chat GUI got broken.
rubidium
parents: 8040
diff changeset
  1810
			STR_NETWORK_CHAT_CLIENT_CAPTION
59a0fe1af11a (svn r11630) -Fix [FS#1544] (r11556): the chat GUI got broken.
rubidium
parents: 8040
diff changeset
  1811
		};
59a0fe1af11a (svn r11630) -Fix [FS#1544] (r11556): the chat GUI got broken.
rubidium
parents: 8040
diff changeset
  1812
		StringID msg;
59a0fe1af11a (svn r11630) -Fix [FS#1544] (r11556): the chat GUI got broken.
rubidium
parents: 8040
diff changeset
  1813
649
bc9bdefb76ec (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1814
		DrawWindowWidgets(w);
4887
71da70810c22 (svn r6824) -Feature: Change the functionality of the chat window. SHIFT+ENTER (SHIFT+T)
Darkvater
parents: 4883
diff changeset
  1815
8069
59a0fe1af11a (svn r11630) -Fix [FS#1544] (r11556): the chat GUI got broken.
rubidium
parents: 8040
diff changeset
  1816
		assert(WP(w, chatquerystr_d).caption < lengthof(chat_captions));
59a0fe1af11a (svn r11630) -Fix [FS#1544] (r11556): the chat GUI got broken.
rubidium
parents: 8040
diff changeset
  1817
		msg = chat_captions[WP(w, chatquerystr_d).caption];
59a0fe1af11a (svn r11630) -Fix [FS#1544] (r11556): the chat GUI got broken.
rubidium
parents: 8040
diff changeset
  1818
		DrawStringRightAligned(w->widget[2].left - 2, w->widget[2].top + 1, msg, TC_BLACK);
6531
4445b25832c4 (svn r9719) -Fix: in-game private messages did not work for clients with a Client ID > 255.
rubidium
parents: 6492
diff changeset
  1819
		DrawEditBox(w, &WP(w, chatquerystr_d), 2);
4887
71da70810c22 (svn r6824) -Feature: Change the functionality of the chat window. SHIFT+ENTER (SHIFT+T)
Darkvater
parents: 4883
diff changeset
  1820
	} break;
649
bc9bdefb76ec (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1821
bc9bdefb76ec (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1822
	case WE_CLICK:
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
  1823
		switch (e->we.click.widget) {
4888
acb34a8e5b13 (svn r6825) -Codechange: Remove two globals from chat-window
Darkvater
parents: 4887
diff changeset
  1824
			case 3: { /* Send */
6531
4445b25832c4 (svn r9719) -Fix: in-game private messages did not work for clients with a Client ID > 255.
rubidium
parents: 6492
diff changeset
  1825
				DestType type = (DestType)WP(w, chatquerystr_d).caption;
4445b25832c4 (svn r9719) -Fix: in-game private messages did not work for clients with a Client ID > 255.
rubidium
parents: 6492
diff changeset
  1826
				int dest = WP(w, chatquerystr_d).dest;
4445b25832c4 (svn r9719) -Fix: in-game private messages did not work for clients with a Client ID > 255.
rubidium
parents: 6492
diff changeset
  1827
				SendChat(WP(w, chatquerystr_d).text.buf, type, dest);
4888
acb34a8e5b13 (svn r6825) -Codechange: Remove two globals from chat-window
Darkvater
parents: 4887
diff changeset
  1828
			} /* FALLTHROUGH */
4887
71da70810c22 (svn r6824) -Feature: Change the functionality of the chat window. SHIFT+ENTER (SHIFT+T)
Darkvater
parents: 4883
diff changeset
  1829
			case 0: /* Cancel */ DeleteWindow(w); break;
649
bc9bdefb76ec (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1830
		}
bc9bdefb76ec (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1831
		break;
bc9bdefb76ec (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1832
4013
53a7dd9a1fbf (svn r5226) Reduce the mess that sending chat messages is
tron
parents: 3860
diff changeset
  1833
	case WE_MOUSELOOP:
6531
4445b25832c4 (svn r9719) -Fix: in-game private messages did not work for clients with a Client ID > 255.
rubidium
parents: 6492
diff changeset
  1834
		HandleEditBox(w, &WP(w, chatquerystr_d), 2);
4013
53a7dd9a1fbf (svn r5226) Reduce the mess that sending chat messages is
tron
parents: 3860
diff changeset
  1835
		break;
649
bc9bdefb76ec (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1836
4013
53a7dd9a1fbf (svn r5226) Reduce the mess that sending chat messages is
tron
parents: 3860
diff changeset
  1837
	case WE_KEYPRESS:
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4542
diff changeset
  1838
		if (e->we.keypress.keycode == WKC_TAB) {
4315
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1839
			ChatTabCompletion(w);
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1840
		} else {
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1841
			_chat_tab_completion_active = false;
6531
4445b25832c4 (svn r9719) -Fix: in-game private messages did not work for clients with a Client ID > 255.
rubidium
parents: 6492
diff changeset
  1842
			switch (HandleEditBoxKey(w, &WP(w, chatquerystr_d), 2, e)) {
4888
acb34a8e5b13 (svn r6825) -Codechange: Remove two globals from chat-window
Darkvater
parents: 4887
diff changeset
  1843
				case 1: { /* Return */
6531
4445b25832c4 (svn r9719) -Fix: in-game private messages did not work for clients with a Client ID > 255.
rubidium
parents: 6492
diff changeset
  1844
				DestType type = (DestType)WP(w, chatquerystr_d).caption;
4445b25832c4 (svn r9719) -Fix: in-game private messages did not work for clients with a Client ID > 255.
rubidium
parents: 6492
diff changeset
  1845
				int dest = WP(w, chatquerystr_d).dest;
4445b25832c4 (svn r9719) -Fix: in-game private messages did not work for clients with a Client ID > 255.
rubidium
parents: 6492
diff changeset
  1846
				SendChat(WP(w, chatquerystr_d).text.buf, type, dest);
4888
acb34a8e5b13 (svn r6825) -Codechange: Remove two globals from chat-window
Darkvater
parents: 4887
diff changeset
  1847
			} /* FALLTHROUGH */
4315
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1848
				case 2: /* Escape */ DeleteWindow(w); break;
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1849
			}
649
bc9bdefb76ec (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1850
		}
4013
53a7dd9a1fbf (svn r5226) Reduce the mess that sending chat messages is
tron
parents: 3860
diff changeset
  1851
		break;
649
bc9bdefb76ec (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1852
bc9bdefb76ec (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1853
	case WE_DESTROY:
1648
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1390
diff changeset
  1854
		SendWindowMessage(WC_NEWS_WINDOW, 0, WE_DESTROY, 0, 0);
7929
6c9b25842b0f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 7922
diff changeset
  1855
		ClrBit(_no_scroll, SCROLL_CHAT);
649
bc9bdefb76ec (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1856
		break;
bc9bdefb76ec (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1857
	}
bc9bdefb76ec (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1858
}
bc9bdefb76ec (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1859
bc9bdefb76ec (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1860
static const Widget _chat_window_widgets[] = {
7363
2600aa1a6b16 (svn r10726) -Codechange: make it possible that the chat window is less than 640 pixels.
rubidium
parents: 7343
diff changeset
  1861
{   WWT_CLOSEBOX, RESIZE_NONE,  14,   0,  10,  0, 13, STR_00C5,         STR_018B_CLOSE_WINDOW},
2600aa1a6b16 (svn r10726) -Codechange: make it possible that the chat window is less than 640 pixels.
rubidium
parents: 7343
diff changeset
  1862
{      WWT_PANEL, RESIZE_RIGHT, 14,  11, 319,  0, 13, 0x0,              STR_NULL}, // background
2600aa1a6b16 (svn r10726) -Codechange: make it possible that the chat window is less than 640 pixels.
rubidium
parents: 7343
diff changeset
  1863
{      WWT_PANEL, RESIZE_RIGHT, 14,  75, 257,  1, 12, 0x0,              STR_NULL}, // text box
2600aa1a6b16 (svn r10726) -Codechange: make it possible that the chat window is less than 640 pixels.
rubidium
parents: 7343
diff changeset
  1864
{ WWT_PUSHTXTBTN, RESIZE_LR,    14, 258, 319,  1, 12, STR_NETWORK_SEND, STR_NULL}, // send button
649
bc9bdefb76ec (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1865
{   WIDGETS_END},
bc9bdefb76ec (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1866
};
bc9bdefb76ec (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1867
bc9bdefb76ec (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1868
static const WindowDesc _chat_window_desc = {
7363
2600aa1a6b16 (svn r10726) -Codechange: make it possible that the chat window is less than 640 pixels.
rubidium
parents: 7343
diff changeset
  1869
	WDP_CENTER, -26, 320, 14, 640, 14, // x, y, width, height
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5669
diff changeset
  1870
	WC_SEND_NETWORK_MSG, WC_NONE,
8019
fc0e94dee165 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8018
diff changeset
  1871
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET,
649
bc9bdefb76ec (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1872
	_chat_window_widgets,
bc9bdefb76ec (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1873
	ChatWindowWndProc
bc9bdefb76ec (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1874
};
bc9bdefb76ec (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1875
6531
4445b25832c4 (svn r9719) -Fix: in-game private messages did not work for clients with a Client ID > 255.
rubidium
parents: 6492
diff changeset
  1876
void ShowNetworkChatQueryWindow(DestType type, int dest)
649
bc9bdefb76ec (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1877
{
bc9bdefb76ec (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1878
	Window *w;
bc9bdefb76ec (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1879
bc9bdefb76ec (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1880
	DeleteWindowById(WC_SEND_NETWORK_MSG, 0);
bc9bdefb76ec (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1881
3464
6e01708de019 (svn r4309) The initial string of the chat box is always the empty string, so don't jump through hoops to check if nothing was entered and simplify the code
tron
parents: 3460
diff changeset
  1882
	_edit_str_buf[0] = '\0';
4315
2e634e3ecd02 (svn r5968) -Feature: add auto-completion in chat-window. It completes Player-Names and
truelight
parents: 4300
diff changeset
  1883
	_chat_tab_completion_active = false;
649
bc9bdefb76ec (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1884
bc9bdefb76ec (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1885
	w = AllocateWindowDesc(&_chat_window_desc);
bc9bdefb76ec (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1886
7997
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7966
diff changeset
  1887
	w->LowerWidget(2);
6531
4445b25832c4 (svn r9719) -Fix: in-game private messages did not work for clients with a Client ID > 255.
rubidium
parents: 6492
diff changeset
  1888
	WP(w, chatquerystr_d).caption = type; // Misuse of caption
4445b25832c4 (svn r9719) -Fix: in-game private messages did not work for clients with a Client ID > 255.
rubidium
parents: 6492
diff changeset
  1889
	WP(w, chatquerystr_d).dest    = dest;
4445b25832c4 (svn r9719) -Fix: in-game private messages did not work for clients with a Client ID > 255.
rubidium
parents: 6492
diff changeset
  1890
	WP(w, chatquerystr_d).afilter = CS_ALPHANUMERAL;
4445b25832c4 (svn r9719) -Fix: in-game private messages did not work for clients with a Client ID > 255.
rubidium
parents: 6492
diff changeset
  1891
	InitializeTextBuffer(&WP(w, chatquerystr_d).text, _edit_str_buf, lengthof(_edit_str_buf), 0);
649
bc9bdefb76ec (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1892
}
bc9bdefb76ec (svn r1082) Feature: Chat toolbar
dominik
parents: 624
diff changeset
  1893
7998
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1894
/** Enum for NetworkGameWindow, referring to _network_game_window_widgets */
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1895
enum NetworkCompanyPasswordWindowWidgets {
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1896
	NCPWW_CLOSE,                    ///< Close 'X' button
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1897
	NCPWW_CAPTION,                  ///< Caption of the whole window
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1898
	NCPWW_BACKGROUND,               ///< The background of the interface
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1899
	NCPWW_LABEL,                    ///< Label in front of the password field
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1900
	NCPWW_PASSWORD,                 ///< Input field for the password
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1901
	NCPWW_SAVE_AS_DEFAULT_PASSWORD, ///< Toggle 'button' for saving the current password as default password
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1902
	NCPWW_CANCEL,                   ///< Close the window without changing anything
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1903
	NCPWW_OK,                       ///< Safe the password etc.
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1904
};
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1905
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1906
static void NetworkCompanyPasswordWindowWndProc(Window *w, WindowEvent *e)
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1907
{
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1908
	switch (e->event) {
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1909
		case WE_PAINT:
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1910
			DrawWindowWidgets(w);
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1911
			DrawEditBox(w, &WP(w, chatquerystr_d), 4);
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1912
			break;
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1913
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1914
		case WE_CLICK:
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1915
			switch (e->we.click.widget) {
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1916
				case NCPWW_OK: {
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1917
					if (w->IsWidgetLowered(NCPWW_SAVE_AS_DEFAULT_PASSWORD)) {
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1918
						snprintf(_network_default_company_pass, lengthof(_network_default_company_pass), "%s", _edit_str_buf);
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1919
					}
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1920
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1921
					/* empty password is a '*' because of console argument */
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1922
					if (StrEmpty(_edit_str_buf)) snprintf(_edit_str_buf, lengthof(_edit_str_buf), "*");
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1923
					char *password = _edit_str_buf;
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1924
					NetworkChangeCompanyPassword(1, &password);
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1925
				}
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1926
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1927
				/* FALL THROUGH */
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1928
				case NCPWW_CANCEL:
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1929
					DeleteWindow(w);
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1930
					break;
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1931
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1932
				case NCPWW_SAVE_AS_DEFAULT_PASSWORD:
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1933
					w->ToggleWidgetLoweredState(NCPWW_SAVE_AS_DEFAULT_PASSWORD);
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1934
					SetWindowDirty(w);
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1935
					break;
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1936
			}
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1937
			break;
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1938
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1939
		case WE_MOUSELOOP:
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1940
			HandleEditBox(w, &WP(w, chatquerystr_d), 4);
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1941
			break;
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1942
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1943
		case WE_KEYPRESS:
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1944
			switch (HandleEditBoxKey(w, &WP(w, chatquerystr_d), 4, e)) {
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1945
				case 1: // Return
8087
25e5cc4a5344 (svn r11648) -Fix [FS#1560]: the company password was not set when one pressed the enter key.
rubidium
parents: 8082
diff changeset
  1946
					e->event = WE_CLICK;
25e5cc4a5344 (svn r11648) -Fix [FS#1560]: the company password was not set when one pressed the enter key.
rubidium
parents: 8082
diff changeset
  1947
					e->we.click.widget = NCPWW_OK;
25e5cc4a5344 (svn r11648) -Fix [FS#1560]: the company password was not set when one pressed the enter key.
rubidium
parents: 8082
diff changeset
  1948
					NetworkCompanyPasswordWindowWndProc(w, e);
25e5cc4a5344 (svn r11648) -Fix [FS#1560]: the company password was not set when one pressed the enter key.
rubidium
parents: 8082
diff changeset
  1949
					break;
25e5cc4a5344 (svn r11648) -Fix [FS#1560]: the company password was not set when one pressed the enter key.
rubidium
parents: 8082
diff changeset
  1950
7998
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1951
				case 2: // Escape
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1952
					DeleteWindow(w);
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1953
					break;
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1954
			}
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1955
			break;
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1956
	}
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1957
}
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1958
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1959
static const Widget _ncp_window_widgets[] = {
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1960
{   WWT_CLOSEBOX, RESIZE_NONE, 14,   0,  10,  0, 13, STR_00C5,                          STR_018B_CLOSE_WINDOW},
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1961
{    WWT_CAPTION, RESIZE_NONE, 14,  11, 299,  0, 13, STR_COMPANY_PASSWORD_CAPTION,      STR_018C_WINDOW_TITLE_DRAG_THIS},
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1962
{      WWT_PANEL, RESIZE_NONE, 14,   0, 299, 14, 50, 0x0,                               STR_NULL},
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1963
{       WWT_TEXT, RESIZE_NONE, 14,   5, 100, 19, 30, STR_COMPANY_PASSWORD,              STR_NULL},
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1964
{      WWT_PANEL, RESIZE_NONE, 14, 101, 294, 19, 30, 0x0,                               STR_NULL},
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1965
{    WWT_TEXTBTN, RESIZE_NONE, 14, 101, 294, 35, 46, STR_MAKE_DEFAULT_COMPANY_PASSWORD, STR_MAKE_DEFAULT_COMPANY_PASSWORD_TIP},
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1966
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14,   0, 149, 51, 62, STR_012E_CANCEL,                   STR_COMPANY_PASSWORD_CANCEL},
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1967
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 150, 299, 51, 62, STR_012F_OK,                       STR_COMPANY_PASSWORD_OK},
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1968
{   WIDGETS_END},
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1969
};
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1970
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1971
static const WindowDesc _ncp_window_desc = {
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1972
	WDP_AUTO, WDP_AUTO, 300, 63, 300, 63,
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1973
	WC_COMPANY_PASSWORD_WINDOW, WC_NONE,
8019
fc0e94dee165 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8018
diff changeset
  1974
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
7998
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1975
	_ncp_window_widgets,
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1976
	NetworkCompanyPasswordWindowWndProc
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1977
};
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1978
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1979
void ShowNetworkCompanyPasswordWindow()
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1980
{
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1981
	DeleteWindowById(WC_COMPANY_PASSWORD_WINDOW, 0);
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1982
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1983
	_edit_str_buf[0] = '\0';
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1984
	Window *w = AllocateWindowDesc(&_ncp_window_desc);
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1985
	WP(w, chatquerystr_d).afilter = CS_ALPHANUMERAL;
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1986
	InitializeTextBuffer(&WP(w, chatquerystr_d).text, _edit_str_buf, min(lengthof(_network_default_company_pass), lengthof(_edit_str_buf)), 0);
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1987
}
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7997
diff changeset
  1988
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1989
#endif /* ENABLE_NETWORK */